diff --git a/main/admin/system_announcements.php b/main/admin/system_announcements.php index f51106a450..21b5154e44 100644 --- a/main/admin/system_announcements.php +++ b/main/admin/system_announcements.php @@ -20,6 +20,7 @@ require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; require_once api_get_path(LIBRARY_PATH).'system_announcements.lib.php'; require_once api_get_path(LIBRARY_PATH).'WCAG/WCAG_rendering.php'; require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; +require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php'; // setting the section (for the tabs) $this_section=SECTION_PLATFORM_ADMIN; @@ -121,6 +122,8 @@ if (isset ($_GET['action']) && $_GET['action'] == 'edit') { $values['visible_guest'] = $announcement->visible_guest ; $values['lang'] = $announcement->lang; $values['action'] = 'edit'; + $groups = SystemAnnouncementManager :: get_announcement_groups($announcement->id); + $values['group'] = isset($groups[0]['group_id']) ? $groups[0]['group_id'] : 0; $action_todo = true; } @@ -152,6 +155,12 @@ if ($action_todo) { $form->addElement('checkbox', 'visible_student', null, get_lang('Student')); $form->addElement('checkbox', 'visible_guest', null, get_lang('Guest')); $form->addElement('hidden', 'id'); + + $group_list = GroupPortalManager::get_groups_list(); + $group_list[0] = get_lang('AllGroups'); + $form->addElement('select', 'group',get_lang('AnnouncementForGroup'),$group_list); + $values['group'] = isset($values['group']) ? $values['group'] : '0'; + $form->addElement('checkbox', 'send_mail', get_lang('SendMail')); if (isset($_REQUEST['action']) && $_REQUEST['action']=='add') { @@ -197,8 +206,10 @@ if ($action_todo) { switch($values['action']) { case 'add': - if(SystemAnnouncementManager::add_announcement($values['title'],$values['content'],$values['start'],$values['end'],$values['visible_teacher'],$values['visible_student'],$values['visible_guest'], $values['lang'],$values['send_mail'])) + $announcement_id = SystemAnnouncementManager::add_announcement($values['title'],$values['content'],$values['start'],$values['end'],$values['visible_teacher'],$values['visible_student'],$values['visible_guest'], $values['lang'],$values['send_mail']); + if ($announcement_id !== false ) { + SystemAnnouncementManager::announcement_for_groups($announcement_id, array($values['group'])); Display :: display_confirmation_message(get_lang('AnnouncementAdded')); } else { $show_announcement_list = false; @@ -208,6 +219,7 @@ if ($action_todo) { case 'edit': if (SystemAnnouncementManager::update_announcement($values['id'],$values['title'],$values['content'],$values['start'],$values['end'],$values['visible_teacher'],$values['visible_student'],$values['visible_guest'], $values['lang'],$values['send_mail'])) { + SystemAnnouncementManager::announcement_for_groups($values['id'], array($values['group'])); Display :: display_confirmation_message(get_lang('AnnouncementUpdated')); } else @@ -274,4 +286,4 @@ if ($show_announcement_list) FOOTER */ Display :: display_footer(); -?> \ No newline at end of file +?> diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index ad44b2bda8..6df6cdab88 100644 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -26,6 +26,7 @@ define('TABLE_MAIN_CLASS_USER', 'class_user'); define('TABLE_MAIN_CATEGORY', 'course_category'); define('TABLE_MAIN_COURSE_MODULE', 'course_module'); define('TABLE_MAIN_SYSTEM_ANNOUNCEMENTS', 'sys_announcement'); +define('TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS', 'announcement_rel_group'); define('TABLE_MAIN_LANGUAGE', 'language'); define('TABLE_MAIN_SETTINGS_OPTIONS', 'settings_options'); define('TABLE_MAIN_SETTINGS_CURRENT', 'settings_current'); diff --git a/main/inc/lib/group_portal_manager.lib.php b/main/inc/lib/group_portal_manager.lib.php index ba984548a0..7734083eb4 100644 --- a/main/inc/lib/group_portal_manager.lib.php +++ b/main/inc/lib/group_portal_manager.lib.php @@ -235,21 +235,15 @@ class GroupPortalManager $toreturn = array(); while ($item = Database::fetch_assoc($res)) { - echo "
"; - print_r($item); - echo ""; - foreach ($item as $key => $value ){ if ($key == 'id_1') { $toreturn[$value]['name'] = $item['name_1']; } else { $temp = explode('_',$key); - echo "ppp : $index_key - $string_key ppp"; $index_key = $temp[1]; $string_key = $temp[0]; $previous_key = $string_key.'_'.$index_key-1; if ( $string_key == 'id' && isset($item[$key]) ) { - echo $previous_key; $toreturn[$item[$previous_key]]['hrms'][$index_key]['name'] = $item['name_'.$index_id]; } } @@ -257,6 +251,35 @@ class GroupPortalManager } return $toreturn; } + public static function get_parent_groups($group_id){ + $t_rel_group = Database :: get_main_table(TABLE_MAIN_GROUP_REL_GROUP); + $max_level = 10; + $select_part = "SELECT "; + $cond_part=''; + for ($i=1; $i <= $max_level; $i++) { + $g_number=$i; + $rg_number=$i-1; + if ( $i == $max_level) { + $select_part .= "rg$rg_number.group_id as id_$rg_number "; + } else { + $select_part .="rg$rg_number.group_id as id_$rg_number, "; + } + if ($i == 1){ + $cond_part .= "FROM $t_rel_group rg0 LEFT JOIN $t_rel_group rg$i on rg$rg_number.group_id = rg$i.subgroup_id "; + }else { + $cond_part .= " LEFT JOIN $t_rel_group rg$i on rg$rg_number.group_id = rg$i.subgroup_id "; + } + } + $sql = $select_part.' '. $cond_part . "WHERE rg0.subgroup_id='$group_id'"; + $res = Database::query($sql); + $temp_arr = Database::fetch_array($res, 'NUM'); + $toreturn = array(); + foreach ($temp_arr as $elt) { + if (isset($elt)) + $toreturn[] = $elt; + } + return $toreturn; + } /** * Gets the tags from a given group diff --git a/main/inc/lib/system_announcements.lib.php b/main/inc/lib/system_announcements.lib.php index 918693d7c3..232a55c2a7 100644 --- a/main/inc/lib/system_announcements.lib.php +++ b/main/inc/lib/system_announcements.lib.php @@ -1,4 +1,5 @@ \ No newline at end of file +?> diff --git a/main/install/db_main.sql b/main/install/db_main.sql index b8f87538a8..b0687da303 100644 --- a/main/install/db_main.sql +++ b/main/install/db_main.sql @@ -2431,6 +2431,12 @@ CREATE TABLE group_rel_group ( ALTER TABLE group_rel_group ADD INDEX ( group_id ); ALTER TABLE group_rel_group ADD INDEX ( subgroup_id ); ALTER TABLE group_rel_group ADD INDEX ( relation_type ); + +CREATE TABLE announcement_rel_group ( + group_id int NOT NULL, + announcement_id int NOT NULL, + PRIMARY KEY (group_id, announcement_id) +); -- -- Table structure for table message attachment -- diff --git a/main/install/migrate-db-1.8.6.2-1.8.7-pre.sql b/main/install/migrate-db-1.8.6.2-1.8.7-pre.sql index 3aa52b7076..5c3b887e8f 100644 --- a/main/install/migrate-db-1.8.6.2-1.8.7-pre.sql +++ b/main/install/migrate-db-1.8.6.2-1.8.7-pre.sql @@ -134,6 +134,8 @@ CREATE TABLE `event_type_message` (`id` int(11) NOT NULL AUTO_INCREMENT, `event_ CREATE TABLE `user_rel_event_type` (`id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `event_type_id` int(11) NOT NULL, PRIMARY KEY (`id`)); INSERT INTO `event_type` VALUES (1, 'course_deleted','courseDeletedTitle','courseDeletedComment'),(2,'course_created','courseCreatedTitle','courseCreatedComment'),(3,'user_deleted','userDeletedTitle','userDeletedComment'),(4,'user_created','userCreatedTitle','userCreatedComment'), (5, 'session_created','sessionCreatedTitle','sessionCreatedComment'), (6,'session_deleted','sessionDeletedTitle','sessionDeletedComment'), (7,'session_category_created','sessionCategoryCreatedTitle','sessionCategoryCreatedComment'),(8,'session_category_deleted','sessionCategoryDeletedTitle','sessionCategoryDeletedComment'),(9,'settings_changed','settingsChangedTitle','settingsChangedComment'),(10,'user_subscribed','userSubscribedTitle','userSubscribedComment'), (11,'user_unsubscribed','userUnsubscribedTitle','userUnsubscribedComment'); INSERT INTO `event_type_message` (`id`,`event_type_id`, `language_id`, `message`,`subject`) VALUES (1,4,10,'Bonjour, \r\n\r\nL\'utilisateur %username% (%firstname% %lastname%) a été créé.\r\nEmail : %mail%\r\n\r\nBien à vous.',''),(2,1,10,'Delete formation',''),(3,2,10,'Create formation',''),(4,3,10,'Bonjour, \r\n\r\nL\'utilisateur %username% (%firstname% %lastname%) a été supprimé.\r\n\r\nBien à vous.',''),(6,5,10,'Create session test',''),(7,6,10,'Delete session',''),(8,7,10,'Create category session',''),(9,8,10,'Delete category session',''),(10,9,10,'Change setting',''),(11,10,10,'Subscribe',''),(12,11,10,'Unsubscribe',''); +CREATE TABLE announcement_rel_group (group_id int NOT NULL, announcement_id int NOT NULL, PRIMARY KEY (group_id, announcement_id)); + -- -- Table structure for LP custom storage API -- diff --git a/main/lang/english/agenda.inc.php b/main/lang/english/agenda.inc.php old mode 100755 new mode 100644 index 30e64555b5..84578ba741 --- a/main/lang/english/agenda.inc.php +++ b/main/lang/english/agenda.inc.php @@ -77,4 +77,6 @@ $IsNotiCalFormatFile = "This file is not in iCal format"; $RepeatEvent = "Repeat event"; $RepeatDate = "Repeat date"; $EndDateMustBeMoreThanStartDate = "End date must be more than the start date"; -?> \ No newline at end of file +$AnnouncementForGroup = "Only for group"; +$AllGroups = "All the groups"; +?> diff --git a/main/lang/french/agenda.inc.php b/main/lang/french/agenda.inc.php old mode 100755 new mode 100644 index 18bc3b346c..4ac394de8d --- a/main/lang/french/agenda.inc.php +++ b/main/lang/french/agenda.inc.php @@ -77,4 +77,6 @@ $IsNotiCalFormatFile = "Ce fichier n'est pas au format iCal"; $RepeatEvent = "Évènement répétitif"; $RepeatDate = "Répéter la date"; $EndDateMustBeMoreThanStartDate = "La date de fin doit être supérieure à la date de début"; -?> \ No newline at end of file +$AnnouncementForGroup = "Seulement visible pour le groupe"; +$AllGroups = "Tous les groupes"; +?> diff --git a/main/reports/index.php b/main/reports/index.php index bbb14488e4..7189867acd 100644 --- a/main/reports/index.php +++ b/main/reports/index.php @@ -102,9 +102,18 @@ $htmlHeadXtra[] = '