|
|
|
@ -347,15 +347,17 @@ class SystemAnnouncementManager |
|
|
|
|
Display :: display_normal_message(get_lang('InvalidEndDate')); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (strlen(trim($title)) == 0) { |
|
|
|
|
Display::display_normal_message(get_lang('InvalidTitle')); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$start = api_get_utc_datetime($date_start); |
|
|
|
|
$end = api_get_utc_datetime($date_end); |
|
|
|
|
|
|
|
|
|
//Fixing urls that are sent by email |
|
|
|
|
// Fixing urls that are sent by email |
|
|
|
|
$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); |
|
|
|
|
$content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); |
|
|
|
|
|
|
|
|
@ -381,7 +383,6 @@ class SystemAnnouncementManager |
|
|
|
|
$resultId = Database::insert($db_table, $params); |
|
|
|
|
|
|
|
|
|
if ($resultId) { |
|
|
|
|
|
|
|
|
|
if ($sendEmailTest) { |
|
|
|
|
SystemAnnouncementManager::send_system_announcement_by_email( |
|
|
|
|
$title, |
|
|
|
@ -505,6 +506,12 @@ class SystemAnnouncementManager |
|
|
|
|
$sendEmailTest = false |
|
|
|
|
) { |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
$announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id); |
|
|
|
|
|
|
|
|
|
if (!$announcement) { |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$a_dateS = explode(' ',$date_start); |
|
|
|
|
$a_arraySD = explode('-',$a_dateS[0]); |
|
|
|
@ -520,6 +527,7 @@ class SystemAnnouncementManager |
|
|
|
|
|
|
|
|
|
if (!checkdate($date_start_to_compare[1], $date_start_to_compare[2], $date_start_to_compare[0])) { |
|
|
|
|
Display :: display_normal_message(get_lang('InvalidStartDate')); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -529,23 +537,23 @@ class SystemAnnouncementManager |
|
|
|
|
!checkdate($date_end_to_compare[1], $date_end_to_compare[2], $date_end_to_compare[0]) |
|
|
|
|
) { |
|
|
|
|
Display :: display_normal_message(get_lang('InvalidEndDate')); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (strlen(trim($title)) == 0) { |
|
|
|
|
Display::display_normal_message(get_lang('InvalidTitle')); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$start = api_get_utc_datetime($date_start); |
|
|
|
|
$end = api_get_utc_datetime($date_end); |
|
|
|
|
$start = api_get_utc_datetime($date_start); |
|
|
|
|
$end = api_get_utc_datetime($date_end); |
|
|
|
|
|
|
|
|
|
//Fixing urls that are sent by email |
|
|
|
|
// Fixing urls that are sent by email |
|
|
|
|
$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); |
|
|
|
|
$content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); |
|
|
|
|
|
|
|
|
|
$id = intval($id); |
|
|
|
|
|
|
|
|
|
if ($sendEmailTest) { |
|
|
|
|
SystemAnnouncementManager::send_system_announcement_by_email( |
|
|
|
|
$title, |
|
|
|
@ -567,12 +575,6 @@ class SystemAnnouncementManager |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id); |
|
|
|
|
|
|
|
|
|
if (!$announcement) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$dateStart = new DateTime($start, new DateTimeZone('UTC')); |
|
|
|
|
$dateEnd = new DateTime($end, new DateTimeZone('UTC')); |
|
|
|
|
|
|
|
|
@ -658,20 +660,28 @@ class SystemAnnouncementManager |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Send a system announcement by e-mail to all teachers/students depending on parameters |
|
|
|
|
* @param string Title |
|
|
|
|
* @param string Content |
|
|
|
|
* @param int Whether to send to all teachers (1) or not (0) |
|
|
|
|
* @param int Whether to send to all students (1) or not (0) |
|
|
|
|
* @param string Language (optional, considered for all languages if left empty) |
|
|
|
|
* @return bool True if the message was sent or there was no destination matching. False on database or e-mail sending error. |
|
|
|
|
* @param string $title |
|
|
|
|
* @param string $content |
|
|
|
|
* @param int $teacher Whether to send to all teachers (1) or not (0) |
|
|
|
|
* @param int $student Whether to send to all students (1) or not (0) |
|
|
|
|
* @param string $language Language (optional, considered for all languages if left empty) |
|
|
|
|
* @param bool $sendEmailTest |
|
|
|
|
* @return bool True if the message was sent or there was no destination matching. False on database or e-mail sending error. |
|
|
|
|
*/ |
|
|
|
|
public static function send_system_announcement_by_email($title, $content, $teacher, $student, $language = null, $sendEmailTest = false) |
|
|
|
|
{ |
|
|
|
|
public static function send_system_announcement_by_email( |
|
|
|
|
$title, |
|
|
|
|
$content, |
|
|
|
|
$teacher, |
|
|
|
|
$student, |
|
|
|
|
$language = null, |
|
|
|
|
$sendEmailTest = false |
|
|
|
|
) { |
|
|
|
|
$content = str_replace(array('\r\n', '\n', '\r'),'', $content); |
|
|
|
|
$now = api_get_utc_datetime(); |
|
|
|
|
|
|
|
|
|
if ($sendEmailTest) { |
|
|
|
|
MessageManager::send_message_simple(api_get_user_id(), $title, $content); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -713,16 +723,17 @@ class SystemAnnouncementManager |
|
|
|
|
$sql .= " AND (expiration_date = '' OR expiration_date IS NULL OR expiration_date > '$now') "; |
|
|
|
|
|
|
|
|
|
if ((empty($teacher) || $teacher == '0') && (empty($student) || $student == '0')) { |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
if ($result === false) { |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$message_sent = false; |
|
|
|
|
|
|
|
|
|
while ($row = Database::fetch_array($result,'ASSOC')) { |
|
|
|
|
MessageManager::send_message_simple($row['user_id'], $title, $content); |
|
|
|
|
$message_sent = true; |
|
|
|
|