|
|
|
@ -229,6 +229,7 @@ class SystemAnnouncementManager |
|
|
|
|
* @param int Whether the announcement should be visible to anonymous users (1) or not (0) |
|
|
|
|
* @param string The language for which the announvement should be shown. Leave null for all langages |
|
|
|
|
* @param int Whether to send an e-mail to all users (1) or not (0) |
|
|
|
|
* @return bool True on success, false on failure |
|
|
|
|
*/ |
|
|
|
|
public static function add_announcement($title, $content, $date_start, $date_end, $visible_teacher = 0, $visible_student = 0, $visible_guest = 0, $lang = null, $send_mail=0) |
|
|
|
|
{ |
|
|
|
@ -271,7 +272,12 @@ class SystemAnnouncementManager |
|
|
|
|
if ($send_mail==1) { |
|
|
|
|
SystemAnnouncementManager::send_system_announcement_by_email($title, $content,$visible_teacher, $visible_student); |
|
|
|
|
} |
|
|
|
|
return Database::query($sql); |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
if ($res === false) { |
|
|
|
|
Debug::log_s(mysql_error()); |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Updates an announcement to the database |
|
|
|
@ -280,6 +286,7 @@ class SystemAnnouncementManager |
|
|
|
|
* @param string $content : content of the announcement |
|
|
|
|
* @param array $date_start: start date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
|
|
|
* @param array $date_end : end date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
|
|
|
* @return bool True on success, false on failure |
|
|
|
|
*/ |
|
|
|
|
public static function update_announcement($id, $title, $content, $date_start, $date_end, $visible_teacher = 0, $visible_student = 0, $visible_guest = 0,$lang=null, $send_mail=0) |
|
|
|
|
{ |
|
|
|
@ -322,18 +329,28 @@ class SystemAnnouncementManager |
|
|
|
|
if ($send_mail==1) { |
|
|
|
|
SystemAnnouncementManager::send_system_announcement_by_email($title, $content,$visible_teacher, $visible_student); |
|
|
|
|
} |
|
|
|
|
return Database::query($sql); |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
if ($res === false) { |
|
|
|
|
Debug::log_s(mysql_error()); |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Deletes an announcement |
|
|
|
|
* @param int $id The identifier of the announcement that should be |
|
|
|
|
* @return resource |
|
|
|
|
* @return bool True on success, false on failure |
|
|
|
|
*/ |
|
|
|
|
public static function delete_announcement($id) { |
|
|
|
|
$db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
|
|
|
$id = intval($id); |
|
|
|
|
$sql = "DELETE FROM ".$db_table." WHERE id='".$id."'"; |
|
|
|
|
return Database::query($sql); |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
if ($res === false) { |
|
|
|
|
Debug::log_s(mysql_error()); |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Gets an announcement |
|
|
|
@ -351,7 +368,7 @@ class SystemAnnouncementManager |
|
|
|
|
* Change the visibility of an announcement |
|
|
|
|
* @param int $announcement_id |
|
|
|
|
* @param int $user For who should the visibility be changed (possible values are VISIBLE_TEACHER, VISIBLE_STUDENT, VISIBLE_GUEST) |
|
|
|
|
* @return resource |
|
|
|
|
* @return bool True on success, false on failure |
|
|
|
|
*/ |
|
|
|
|
public static function set_visibility($announcement_id, $user, $visible) { |
|
|
|
|
$db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
|
|
@ -360,9 +377,21 @@ class SystemAnnouncementManager |
|
|
|
|
|
|
|
|
|
$field = ($user == VISIBLE_TEACHER ? 'visible_teacher' : ($user == VISIBLE_STUDENT ? 'visible_student' : 'visible_guest')); |
|
|
|
|
$sql = "UPDATE ".$db_table." SET ".$field." = '".$visible."' WHERE id='".$announcement_id."'"; |
|
|
|
|
return Database::query($sql); |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
if ($res === false) { |
|
|
|
|
Debug::log_s(mysql_error()); |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 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) |
|
|
|
|
*/ |
|
|
|
|
public static function send_system_announcement_by_email($title, $content, $teacher, $student) { |
|
|
|
|
global $_user; |
|
|
|
|
global $_setting; |
|
|
|
@ -382,8 +411,11 @@ class SystemAnnouncementManager |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
if ($result === false) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
while($row = Database::fetch_array($result,'ASSOC')) { |
|
|
|
|
@api_mail_html(api_get_person_name($row['firstname'], $row['lastname'], null, PERSON_NAME_EMAIL_ADDRESS), $row['email'], api_html_entity_decode(stripslashes($title), ENT_QUOTES, $charset), api_html_entity_decode(stripslashes(str_replace(array('\r\n', '\n', '\r'),'',$content)), ENT_QUOTES, $charset), api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS), api_get_setting('emailAdministrator')); |
|
|
|
|
$res = @api_mail_html(api_get_person_name($row['firstname'], $row['lastname'], null, PERSON_NAME_EMAIL_ADDRESS), $row['email'], api_html_entity_decode(stripslashes($title), ENT_QUOTES, $charset), api_html_entity_decode(stripslashes(str_replace(array('\r\n', '\n', '\r'),'',$content)), ENT_QUOTES, $charset), api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS), api_get_setting('emailAdministrator')); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|