@@ -10,12 +10,12 @@ discard block |
||
10 | 10 | const VISIBLE_STUDENT = 2; |
11 | 11 | const VISIBLE_TEACHER = 3; |
12 | 12 | |
13 | - /** |
|
14 | - * Displays all announcements |
|
15 | - * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER |
|
16 | - * @param int $id The identifier of the announcement to display |
|
17 | - */ |
|
18 | - public static function display_announcements($visible, $id = -1) |
|
13 | + /** |
|
14 | + * Displays all announcements |
|
15 | + * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER |
|
16 | + * @param int $id The identifier of the announcement to display |
|
17 | + */ |
|
18 | + public static function display_announcements($visible, $id = -1) |
|
19 | 19 | { |
20 | 20 | $user_selected_language = api_get_interface_language(); |
21 | 21 | $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
@@ -423,10 +423,10 @@ discard block |
||
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
426 | - * Makes the announcement id visible only for groups in groups_array |
|
427 | - * @param int $announcement_id |
|
428 | - * @param array $group_array array of group id |
|
429 | - **/ |
|
426 | + * Makes the announcement id visible only for groups in groups_array |
|
427 | + * @param int $announcement_id |
|
428 | + * @param array $group_array array of group id |
|
429 | + **/ |
|
430 | 430 | public static function announcement_for_groups($announcement_id, $group_array) |
431 | 431 | { |
432 | 432 | $tbl_announcement_group = Database:: get_main_table( |
@@ -459,10 +459,10 @@ discard block |
||
459 | 459 | } |
460 | 460 | |
461 | 461 | /** |
462 | - * Gets the groups of this announce |
|
463 | - * @param int announcement id |
|
464 | - * @return array array of group id |
|
465 | - **/ |
|
462 | + * Gets the groups of this announce |
|
463 | + * @param int announcement id |
|
464 | + * @return array array of group id |
|
465 | + **/ |
|
466 | 466 | public static function get_announcement_groups($announcement_id) |
467 | 467 | { |
468 | 468 | $tbl_announcement_group = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS); |
@@ -482,15 +482,15 @@ discard block |
||
482 | 482 | return $groups; |
483 | 483 | } |
484 | 484 | |
485 | - /** |
|
486 | - * Updates an announcement to the database |
|
487 | - * @param integer $id : id of the announcement |
|
488 | - * @param string $title : title of the announcement |
|
489 | - * @param string $content : content of the announcement |
|
490 | - * @param array $date_start: start date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
491 | - * @param array $date_end : end date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
492 | - * @return bool True on success, false on failure |
|
493 | - */ |
|
485 | + /** |
|
486 | + * Updates an announcement to the database |
|
487 | + * @param integer $id : id of the announcement |
|
488 | + * @param string $title : title of the announcement |
|
489 | + * @param string $content : content of the announcement |
|
490 | + * @param array $date_start: start date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
491 | + * @param array $date_end : end date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
492 | + * @return bool True on success, false on failure |
|
493 | + */ |
|
494 | 494 | public static function update_announcement( |
495 | 495 | $id, |
496 | 496 | $title, |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | $sendEmailTest = false |
506 | 506 | ) { |
507 | 507 | $em = Database::getManager(); |
508 | - $announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id); |
|
508 | + $announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id); |
|
509 | 509 | |
510 | 510 | if (!$announcement) { |
511 | 511 | return false; |
@@ -529,28 +529,28 @@ discard block |
||
529 | 529 | return false; |
530 | 530 | } |
531 | 531 | |
532 | - if (($date_end_to_compare[1] || |
|
532 | + if (($date_end_to_compare[1] || |
|
533 | 533 | $date_end_to_compare[2] || |
534 | 534 | $date_end_to_compare[0]) && |
535 | 535 | !checkdate($date_end_to_compare[1], $date_end_to_compare[2], $date_end_to_compare[0]) |
536 | 536 | ) { |
537 | - Display :: display_normal_message(get_lang('InvalidEndDate')); |
|
537 | + Display :: display_normal_message(get_lang('InvalidEndDate')); |
|
538 | 538 | |
539 | - return false; |
|
540 | - } |
|
539 | + return false; |
|
540 | + } |
|
541 | 541 | |
542 | - if (strlen(trim($title)) == 0) { |
|
543 | - Display::display_normal_message(get_lang('InvalidTitle')); |
|
542 | + if (strlen(trim($title)) == 0) { |
|
543 | + Display::display_normal_message(get_lang('InvalidTitle')); |
|
544 | 544 | |
545 | - return false; |
|
546 | - } |
|
545 | + return false; |
|
546 | + } |
|
547 | 547 | |
548 | 548 | $start = api_get_utc_datetime($date_start); |
549 | 549 | $end = api_get_utc_datetime($date_end); |
550 | 550 | |
551 | - //Fixing urls that are sent by email |
|
552 | - //$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); |
|
553 | - //$content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); |
|
551 | + //Fixing urls that are sent by email |
|
552 | + //$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); |
|
553 | + //$content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); |
|
554 | 554 | $content = str_replace('src=\"'.api_get_path(REL_HOME_PATH), 'src=\"'.api_get_path(WEB_PATH).api_get_path(REL_HOME_PATH), $content); |
555 | 555 | $content = str_replace('file='.api_get_path(REL_HOME_PATH), 'file='.api_get_path(WEB_PATH).api_get_path(REL_HOME_PATH), $content); |
556 | 556 | |
@@ -592,81 +592,81 @@ discard block |
||
592 | 592 | $em->merge($announcement); |
593 | 593 | $em->flush(); |
594 | 594 | |
595 | - return true; |
|
596 | - } |
|
595 | + return true; |
|
596 | + } |
|
597 | 597 | |
598 | - /** |
|
599 | - * Deletes an announcement |
|
600 | - * @param int $id The identifier of the announcement that should be |
|
601 | - * @return bool True on success, false on failure |
|
602 | - */ |
|
603 | - public static function delete_announcement($id) |
|
598 | + /** |
|
599 | + * Deletes an announcement |
|
600 | + * @param int $id The identifier of the announcement that should be |
|
601 | + * @return bool True on success, false on failure |
|
602 | + */ |
|
603 | + public static function delete_announcement($id) |
|
604 | 604 | { |
605 | - $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
606 | - $id = intval($id); |
|
607 | - $sql = "DELETE FROM ".$db_table." WHERE id =".$id; |
|
608 | - $res = Database::query($sql); |
|
605 | + $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
606 | + $id = intval($id); |
|
607 | + $sql = "DELETE FROM ".$db_table." WHERE id =".$id; |
|
608 | + $res = Database::query($sql); |
|
609 | 609 | if ($res === false) { |
610 | - return false; |
|
611 | - } |
|
612 | - return true; |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Gets an announcement |
|
617 | - * @param int $id The identifier of the announcement that should be |
|
618 | - * @return object Object of class StdClass or the required class, containing the query result row |
|
619 | - */ |
|
620 | - public static function get_announcement($id) |
|
610 | + return false; |
|
611 | + } |
|
612 | + return true; |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Gets an announcement |
|
617 | + * @param int $id The identifier of the announcement that should be |
|
618 | + * @return object Object of class StdClass or the required class, containing the query result row |
|
619 | + */ |
|
620 | + public static function get_announcement($id) |
|
621 | 621 | { |
622 | - $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
623 | - $id = intval($id); |
|
624 | - $sql = "SELECT * FROM ".$db_table." WHERE id = ".$id; |
|
625 | - $announcement = Database::fetch_object(Database::query($sql)); |
|
626 | - |
|
627 | - return $announcement; |
|
628 | - } |
|
629 | - |
|
630 | - /** |
|
631 | - * Change the visibility of an announcement |
|
632 | - * @param int $announcement_id |
|
633 | - * @param int $user For who should the visibility be changed |
|
622 | + $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
623 | + $id = intval($id); |
|
624 | + $sql = "SELECT * FROM ".$db_table." WHERE id = ".$id; |
|
625 | + $announcement = Database::fetch_object(Database::query($sql)); |
|
626 | + |
|
627 | + return $announcement; |
|
628 | + } |
|
629 | + |
|
630 | + /** |
|
631 | + * Change the visibility of an announcement |
|
632 | + * @param int $announcement_id |
|
633 | + * @param int $user For who should the visibility be changed |
|
634 | 634 | * (possible values are VISIBLE_TEACHER, VISIBLE_STUDENT, VISIBLE_GUEST) |
635 | - * @return bool True on success, false on failure |
|
636 | - */ |
|
637 | - public static function set_visibility($announcement_id, $user, $visible) |
|
635 | + * @return bool True on success, false on failure |
|
636 | + */ |
|
637 | + public static function set_visibility($announcement_id, $user, $visible) |
|
638 | 638 | { |
639 | - $db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
640 | - $visible = intval($visible); |
|
641 | - $announcement_id = intval($announcement_id); |
|
639 | + $db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
640 | + $visible = intval($visible); |
|
641 | + $announcement_id = intval($announcement_id); |
|
642 | 642 | |
643 | 643 | if (!in_array($user, array(self::VISIBLE_GUEST, self::VISIBLE_STUDENT, self::VISIBLE_TEACHER))) { |
644 | 644 | return false; |
645 | 645 | } |
646 | 646 | |
647 | - $field = ($user == self::VISIBLE_TEACHER ? 'visible_teacher' : ($user == self::VISIBLE_STUDENT ? 'visible_student' : 'visible_guest')); |
|
647 | + $field = ($user == self::VISIBLE_TEACHER ? 'visible_teacher' : ($user == self::VISIBLE_STUDENT ? 'visible_student' : 'visible_guest')); |
|
648 | 648 | |
649 | - $sql = "UPDATE ".$db_table." SET ".$field." = '".$visible."' |
|
649 | + $sql = "UPDATE ".$db_table." SET ".$field." = '".$visible."' |
|
650 | 650 | WHERE id='".$announcement_id."'"; |
651 | - $res = Database::query($sql); |
|
652 | - |
|
653 | - if ($res === false) { |
|
654 | - return false; |
|
655 | - } |
|
656 | - |
|
657 | - return true; |
|
658 | - } |
|
659 | - |
|
660 | - /** |
|
661 | - * Send a system announcement by e-mail to all teachers/students depending on parameters |
|
662 | - * @param string $title |
|
663 | - * @param string $content |
|
664 | - * @param int $teacher Whether to send to all teachers (1) or not (0) |
|
665 | - * @param int $student Whether to send to all students (1) or not (0) |
|
666 | - * @param string $language Language (optional, considered for all languages if left empty) |
|
651 | + $res = Database::query($sql); |
|
652 | + |
|
653 | + if ($res === false) { |
|
654 | + return false; |
|
655 | + } |
|
656 | + |
|
657 | + return true; |
|
658 | + } |
|
659 | + |
|
660 | + /** |
|
661 | + * Send a system announcement by e-mail to all teachers/students depending on parameters |
|
662 | + * @param string $title |
|
663 | + * @param string $content |
|
664 | + * @param int $teacher Whether to send to all teachers (1) or not (0) |
|
665 | + * @param int $student Whether to send to all students (1) or not (0) |
|
666 | + * @param string $language Language (optional, considered for all languages if left empty) |
|
667 | 667 | * @param bool $sendEmailTest |
668 | 668 | * @return bool True if the message was sent or there was no destination matching. False on database or e-mail sending error. |
669 | - */ |
|
669 | + */ |
|
670 | 670 | public static function send_system_announcement_by_email( |
671 | 671 | $title, |
672 | 672 | $content, |
@@ -692,26 +692,26 @@ discard block |
||
692 | 692 | } |
693 | 693 | |
694 | 694 | if ($teacher <> 0 && $student == 0) { |
695 | - $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
695 | + $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
696 | 696 | WHERE status = '1' "; |
697 | - } |
|
697 | + } |
|
698 | 698 | |
699 | - if ($teacher == 0 && $student <> 0) { |
|
700 | - $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
699 | + if ($teacher == 0 && $student <> 0) { |
|
700 | + $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
701 | 701 | WHERE status = '5' "; |
702 | - } |
|
702 | + } |
|
703 | 703 | |
704 | - if ($teacher<> 0 && $student <> 0) { |
|
705 | - $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
704 | + if ($teacher<> 0 && $student <> 0) { |
|
705 | + $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
706 | 706 | WHERE 1 = 1 "; |
707 | - } |
|
707 | + } |
|
708 | 708 | |
709 | - if (!empty($language)) { |
|
710 | - //special condition because language was already treated for SQL insert before |
|
711 | - $sql .= " AND language = '".Database::escape_string($language)."' "; |
|
712 | - } |
|
709 | + if (!empty($language)) { |
|
710 | + //special condition because language was already treated for SQL insert before |
|
711 | + $sql .= " AND language = '".Database::escape_string($language)."' "; |
|
712 | + } |
|
713 | 713 | |
714 | - if (api_is_multiple_url_enabled()) { |
|
714 | + if (api_is_multiple_url_enabled()) { |
|
715 | 715 | $sql .= " AND access_url_id = '".$current_access_url_id."' "; |
716 | 716 | } |
717 | 717 | |
@@ -721,36 +721,36 @@ discard block |
||
721 | 721 | // Expiration date |
722 | 722 | $sql .= " AND (expiration_date = '' OR expiration_date IS NULL OR expiration_date > '$now') "; |
723 | 723 | |
724 | - if ((empty($teacher) || $teacher == '0') && (empty($student) || $student == '0')) { |
|
724 | + if ((empty($teacher) || $teacher == '0') && (empty($student) || $student == '0')) { |
|
725 | 725 | |
726 | - return true; |
|
727 | - } |
|
726 | + return true; |
|
727 | + } |
|
728 | 728 | |
729 | - $result = Database::query($sql); |
|
730 | - if ($result === false) { |
|
729 | + $result = Database::query($sql); |
|
730 | + if ($result === false) { |
|
731 | 731 | |
732 | - return false; |
|
733 | - } |
|
732 | + return false; |
|
733 | + } |
|
734 | 734 | |
735 | 735 | $message_sent = false; |
736 | 736 | |
737 | - while ($row = Database::fetch_array($result,'ASSOC')) { |
|
737 | + while ($row = Database::fetch_array($result,'ASSOC')) { |
|
738 | 738 | MessageManager::send_message_simple($row['user_id'], $title, $content); |
739 | 739 | $message_sent = true; |
740 | - } |
|
740 | + } |
|
741 | 741 | |
742 | - // Minor validation to clean up the attachment files in the announcement |
|
743 | - if (!empty($_FILES)) { |
|
744 | - $attachments = $_FILES; |
|
745 | - foreach ($attachments as $attachment) { |
|
746 | - unlink($attachment['tmp_name']); |
|
747 | - } |
|
748 | - } |
|
749 | - |
|
750 | - return $message_sent; //true if at least one e-mail was sent |
|
751 | - } |
|
752 | - |
|
753 | - /** |
|
742 | + // Minor validation to clean up the attachment files in the announcement |
|
743 | + if (!empty($_FILES)) { |
|
744 | + $attachments = $_FILES; |
|
745 | + foreach ($attachments as $attachment) { |
|
746 | + unlink($attachment['tmp_name']); |
|
747 | + } |
|
748 | + } |
|
749 | + |
|
750 | + return $message_sent; //true if at least one e-mail was sent |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | 754 | * Displays announcements as an slideshow |
755 | 755 | * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER |
756 | 756 | * @param int $id The identifier of the announcement to display |