Julio Montoya 15 years ago
parent
commit
8115cbdb64

+ 1 - 0
documentation/changelog.html

@@ -82,6 +82,7 @@
   <li>Added hidden debugging feature that marks all right answers (for matching, multiple and single choice questions) (private BT#914)</li>
   <li>Adding javascript library for the Pear HTML_QuickForm_advmultiselect class (see CT#883)</li>
   <li>Assignment tool: Fixed problem with work/assignment tool whereby a moved work lost the ability to be scored</li>
+  <li>Announcement tool: display images inside content of announcement sent by email (now the attachment images are embedded inside content) - private BT#925</li>
 </ul>
 <h3>CSS changes</h3>
 <ul>

+ 2 - 2
documentation/installation_guide_es_ES.html

@@ -45,7 +45,7 @@ no son requeridos para usar Chamilo LMS. &nbsp;Por favor, lea completamente este
 
 <ol>
 
-  <li><a href="#1._Pre-requisites">Prerequisitos</a></li>
+  <li><a href="#1._Pre-requisites">Prerrequisitos</a></li>
   <li><a href="#2._Installation_of_Chamilo_LMS">Instalación de Chamilo LMS</a></li>
   <li><a href="#3._Upgrade_from_a_previous_version_of">Actualizar desde una versión previa de Chamilo o Dokeos</a></li>
   <li><a href="#4._Troubleshooting">Solución de Problemas</a></li>
@@ -58,7 +58,7 @@ no son requeridos para usar Chamilo LMS. &nbsp;Por favor, lea completamente este
 <br />
 
 <hr style="width: 100%; height: 2px;" />
-<h2><a name="1._Pre-requisites"></a>1. Prerequisitos</h2>
+<h2><a name="1._Pre-requisites"></a>1. Prerrequisitos</h2>
 
 
 Chamilo puede ser instalado indiferentemente en servidores Windows, Linux, Mac OS X y UNIX.

+ 18 - 19
main/announcements/announcements.php

@@ -663,35 +663,34 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
 								@api_mail('',$myrow["email"],stripslashes($emailTitle),$message,$sender_name,$email);
 	                        } else {
 	                            // intro of the email: receiver name and subject
-								$mail_body = api_get_person_name($myrow["lastname"], $myrow["firstname"], null, PERSON_NAME_EMAIL_ADDRESS)."<br />\n".stripslashes($emailTitle)."<br />";
-								// make a change for absolute url
-	        					$newContent = str_replace('src=\"../../','src=\"'.api_get_path(WEB_PATH).'', $newContent);
+                                    $mail_body = api_get_person_name($myrow["lastname"], $myrow["firstname"], null, PERSON_NAME_EMAIL_ADDRESS)."<br />\n".stripslashes($emailTitle)."<br />";
+
 	                            // main part of the email
 	                            $mail_body .= trim(stripslashes($newContent));
-	                            // signature of email: sender name and course URL after -- line
+                                    // signature of email: sender name and course URL after -- line
 	                            $mail_body .= "<br />-- <br />";
 	                            $mail_body .= api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS)." \n";
 	                            $mail_body .= "<br /> \n<a href=\"".api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq()."\">";
 	                            $mail_body .= $_course['official_code'].' '.$_course['name'] . "</a>";
 
-								$recipient_name	= api_get_person_name($myrow["firstname"], $myrow["lastname"], null, PERSON_NAME_EMAIL_ADDRESS);
-		                        $mailid = $myrow["email"];
+                                    $recipient_name	= api_get_person_name($myrow["firstname"], $myrow["lastname"], null, PERSON_NAME_EMAIL_ADDRESS);
+                                    $mailid = $myrow["email"];
 
-		                        $sender_name = api_get_person_name($_SESSION['_user']['firstName'], $_SESSION['_user']['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
-		                        $sender_email = $_SESSION['_user']['mail'];
+                                    $sender_name = api_get_person_name($_SESSION['_user']['firstName'], $_SESSION['_user']['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
+                                    $sender_email = $_SESSION['_user']['mail'];
 
-								// send attachment file
-								$data_file = array();
-								$sql = 'SELECT path, filename FROM '.$tbl_announcement_attachment.' WHERE announcement_id = "'.$insert_id.'"';
-								$rs_attach = Database::query($sql);
-								if (Database::num_rows($rs_attach) > 0) {
-									$row_attach  = Database::fetch_array($rs_attach);
-									$path_attach = api_get_path(SYS_COURSE_PATH).$_course['path'].'/upload/announcements/'.$row_attach['path'];
-									$filename_attach = $row_attach['filename'];
-									$data_file = array('path' => $path_attach,'filename' => $filename_attach);
-								}
+                                    // send attachment file
+                                    $data_file = array();
+                                    $sql = 'SELECT path, filename FROM '.$tbl_announcement_attachment.' WHERE announcement_id = "'.$insert_id.'"';
+                                    $rs_attach = Database::query($sql);
+                                    if (Database::num_rows($rs_attach) > 0) {
+                                            $row_attach  = Database::fetch_array($rs_attach);
+                                            $path_attach = api_get_path(SYS_COURSE_PATH).$_course['path'].'/upload/announcements/'.$row_attach['path'];
+                                            $filename_attach = $row_attach['filename'];
+                                            $data_file = array('path' => $path_attach,'filename' => $filename_attach);
+                                    }
 
-								@api_mail_html($recipient_name, $mailid, stripslashes($emailSubject), $mail_body, $sender_name, $sender_email, null, $data_file);
+                                    @api_mail_html($recipient_name, $mailid, stripslashes($emailSubject), $mail_body, $sender_name, $sender_email, null, $data_file, true);
 	                        }
 
 							$sql_date="SELECT * FROM $db_name WHERE survey_id='$surveyid'";

+ 48 - 23
main/inc/lib/mail.lib.inc.php

@@ -105,18 +105,20 @@ function api_mail($recipient_name, $recipient_email, $subject, $message, $sender
  * @author Bert Vanderkimpen ICT&O UGent
  * @author Yannick Warnier <yannick.warnier@dokeos.com>
  *
- * @param string		   	name of recipient
- * @param string		  	email of recipient
- * @param string            email subject
- * @param string			email body
- * @param string			sender name
- * @param string			sender e-mail
- * @param array				data file (path and filename)
- * @param array				extra headers in form $headers = array($name => $value) to allow parsing
- * @return                  returns true if mail was sent
- * @see                     class.phpmailer.php
+ * @param string    name of recipient
+ * @param string    email of recipient
+ * @param string    email subject
+ * @param string    email body
+ * @param string    sender name
+ * @param string    sender e-mail
+ * @param array     data file (path and filename)
+ * @param array     extra headers in form $headers = array($name => $value) to allow parsing
+ * @param array     data to attach a file (optional)
+ * @param bool      True for attaching a embedded file inside content html (optional)
+ * @return          returns true if mail was sent
+ * @see             class.phpmailer.php
  */
-function api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name = "", $sender_email = "", $extra_headers = null, $data_file = array()) {
+function api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name = "", $sender_email = "", $extra_headers = null, $data_file = array(), $embedded_image = false) {
 
 	global $regexp_rfc3696;
 	global $platform_email;
@@ -128,8 +130,7 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s
 	$mail->CharSet = $platform_email['SMTP_CHARSET'];
 	$mail->WordWrap = 200; // stay far below SMTP protocol 980 chars limit
 
-	if($platform_email['SMTP_AUTH'])
-	{
+	if ($platform_email['SMTP_AUTH']) {
 		$mail->SMTPAuth = 1;
 		$mail->Username = $platform_email['SMTP_USER'];
 		$mail->Password = $platform_email['SMTP_PASS'];
@@ -148,30 +149,54 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s
 	// $mail->AddAttachment($path);
 	// $mail->AddAttachment($path,$filename);
 
-	if ($sender_email!="")
-	{
+	if ($sender_email!="") {
 		$mail->From         = $sender_email;
 		$mail->Sender       = $sender_email;
 		//$mail->ConfirmReadingTo = $sender_email; //Disposition-Notification
-	}
-	else
-	{
+	} else {
 		$mail->From         = $platform_email['SMTP_FROM_EMAIL'];
 		$mail->Sender       = $platform_email['SMTP_FROM_EMAIL'];
 		//$mail->ConfirmReadingTo = $platform_email['SMTP_FROM_EMAIL']; //Disposition-Notification
 	}
 
-	if ($sender_name!="")
-	{
+	if ($sender_name!="") {
 		$mail->FromName = $sender_name;
-	}
-	else
-	{
+	} else {
 		$mail->FromName = $platform_email['SMTP_FROM_NAME'];
 	}
 	$mail->Subject = $subject;
 
 	$mail->AltBody = strip_tags(str_replace('<br />',"\n", api_html_entity_decode($message)));
+
+        // send embedded image
+        if ($embedded_image) {
+           // get all images html inside content
+           preg_match_all("/<img\s+.*?src=[\"\']?([^\"\' >]*)[\"\']?[^>]*>/i",$message,$m);
+           // prepare new tag images
+           $new_images_html = array();
+           $i = 1;
+           if (!empty($m[1])) {
+               foreach ($m[1] as $image_path) {
+                   $real_path = realpath($image_path);
+                   $filename  = basename($image_path);
+                   $image_cid = $filename.'_'.$i;
+                   $encoding = 'base64';
+                   $image_type = mime_content_type($real_path);
+                   $mail->AddEmbeddedImage($real_path, $image_cid, $filename, $encoding, $image_type);
+                   $new_images_html[] = '<img src="cid:'.$image_cid.'" />';
+                   $i++;
+               }
+           }
+           // replace origin image for new embedded image html
+           $x = 0;
+           if (!empty($m[0])) {
+               foreach ($m[0] as $orig_img) {
+                   $message = str_replace($orig_img, $new_images_html[$x], $message);
+                   $x++;
+               }
+           }
+        }
+
 	$mail->Body = '<html><head></head><body>'.$message.'</body></html>';
 
 	// attachment ...