From 2dcc167b56992fae0aa225e2a380c8ec3e320de8 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 10 Feb 2012 13:56:47 +0100 Subject: [PATCH] Fixing agenda sent_to select --- main/calendar/agenda.inc.php | 193 +++++++++++++++-------------------- main/calendar/agenda.lib.php | 4 +- main/calendar/agenda.php | 9 +- 3 files changed, 87 insertions(+), 119 deletions(-) diff --git a/main/calendar/agenda.inc.php b/main/calendar/agenda.inc.php index 5d94fdd871..a2614dbfd1 100644 --- a/main/calendar/agenda.inc.php +++ b/main/calendar/agenda.inc.php @@ -936,42 +936,10 @@ function get_course_groups() { * @author: Patrick Cool , Ghent University * @return html code */ -function show_to_form($to_already_selected) -{ +function show_to_form($to_already_selected) { $user_list = get_course_users(); $group_list = get_course_groups(); - - echo ""; - echo ""; - // the form containing all the groups and all the users of the course - echo ""; - // the buttons for adding or removing groups/users - echo ""; - echo ""; - echo "
"; - echo "".get_lang('Users')."
"; - construct_not_selected_select_form($group_list, $user_list, $to_already_selected); - echo "
"; - /* echo "", - - "

 

", - - ""; -*/ -?> - -

- -"; - echo "
"; - echo "".get_lang('DestinationUsers')."
"; - construct_selected_select_form($group_list,$user_list,$to_already_selected); - echo "
"; + construct_not_selected_select_form($group_list, $user_list, $to_already_selected); } @@ -981,21 +949,20 @@ function show_to_form($to_already_selected) * @author: Patrick Cool , Ghent University * @return html code */ -function construct_not_selected_select_form($group_list=null, $user_list=null,$to_already_selected=array()) { - - echo "'; // adding the groups to the select form - - if (isset($to_already_selected) && $to_already_selected==='everyone') { - echo ""; + echo ''; + + if (isset($to_already_selected) && $to_already_selected==='everyone') { } else { if (is_array($group_list)) { - + echo ''; foreach($group_list as $this_group) { //api_display_normal_message("group " . $thisGroup[id] . $thisGroup[name]); - if (!is_array($to_already_selected) || !in_array("GROUP:".$this_group['id'],$to_already_selected)) // $to_already_selected is the array containing the groups (and users) that are already selected - { + if (!is_array($to_already_selected) || !in_array("GROUP:".$this_group['id'],$to_already_selected)) { + // $to_already_selected is the array containing the groups (and users) that are already selected echo ""; @@ -1003,18 +970,22 @@ function construct_not_selected_select_form($group_list=null, $user_list=null,$t } // a divider } - echo ""; + echo ""; // adding the individual users to the select form - foreach($user_list as $this_user) { - // $to_already_selected is the array containing the users (and groups) that are already selected - if (!is_array($to_already_selected) || !in_array("USER:".$this_user['uid'],$to_already_selected)) { - $username = api_htmlentities(sprintf(get_lang('LoginX'), $this_user['username']), ENT_QUOTES); - $user_info = api_get_person_name($this_user['firstName'], $this_user['lastName']); - echo ""; - } - } + if (!empty($user_list)) { + echo ''; + foreach($user_list as $this_user) { + // $to_already_selected is the array containing the users (and groups) that are already selected + if (!is_array($to_already_selected) || !in_array("USER:".$this_user['uid'],$to_already_selected)) { + $username = api_htmlentities(sprintf(get_lang('LoginX'), $this_user['username']), ENT_QUOTES); + $user_info = api_get_person_name($this_user['firstName'], $this_user['lastName']).' ('.$this_user['username'].')'; + echo ""; + } + } + echo ""; + } } - echo ""; + echo ""; } /** @@ -1026,19 +997,17 @@ function construct_selected_select_form($group_list=null, $user_list=null,$to_al { // we separate the $to_already_selected array (containing groups AND users into // two separate arrays - if (is_array($to_already_selected)) - { + if (is_array($to_already_selected)) { $groupuser=separate_users_groups($to_already_selected); } $groups_to_already_selected=$groupuser['groups']; $users_to_already_selected=$groupuser['users']; // we load all the groups and all the users into a reference array that we use to search the name of the group / user - $ref_array_groups=get_course_groups(); - - $ref_array_users=get_course_users(); + $ref_array_groups = get_course_groups(); + $ref_array_users = get_course_users(); // we construct the form of the already selected groups / users - echo ""; if(is_array($to_already_selected)) { $select_options_group = array(); @@ -1110,8 +1079,7 @@ function store_new_agenda_item() { $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); $t_agenda_repeat = Database::get_course_Table(TABLE_AGENDA_REPEAT); - $course_id = api_get_course_int_id(); - + $course_id = api_get_course_int_id(); // some filtering of the input data $title = trim($_POST['title']); // no html allowed in the title @@ -1266,23 +1234,26 @@ function separate_users_groups($to) { $grouplist = array(); $userlist = array(); $send_to = null; - if(is_array($to) && count($to)>0) - { - foreach($to as $to_item) - { - list($type, $id) = explode(':', $to_item); - switch($type) - { - case 'GROUP': - $grouplist[] =$id; - break; - case 'USER': - $userlist[] =$id; - break; - } - } - $send_to['groups']=$grouplist; - $send_to['users']=$userlist; + + $send_to['everyone'] = false; + + if (is_array($to) && count($to)>0) { + foreach ($to as $to_item) { + + list($type, $id) = explode(':', $to_item); + switch($type) { + case 'everyone': + $send_to['everyone'] = true; + case 'GROUP': + $grouplist[] =$id; + break; + case 'USER': + $userlist[] =$id; + break; + } + } + $send_to['groups'] = $grouplist; + $send_to['users'] = $userlist; } return $send_to; } @@ -2298,8 +2269,7 @@ function show_add_form($id = '') { // if the id is set then we are editing an agenda item if (!empty($id)) { //echo "before get_agenda_item".$_SESSION['allow_individual_calendar']; - $item_2_edit = get_agenda_item($id); - + $item_2_edit = get_agenda_item($id); $title = $item_2_edit['title']; $content= $item_2_edit['content']; @@ -2371,22 +2341,23 @@ function show_add_form($id = '') { // selecting the users / groups - if (isset ($_SESSION['toolgroup'])) { - echo '' ; + $group_id = api_get_group_id(); + if (isset ($group_id) && !empty($group_id)) { + echo '' ; echo '' ; } else { echo '
- '.Display::return_icon('group.png', get_lang('SentTo'), array ('align' => 'absmiddle'),22).' '.get_lang('SentTo').' + '.Display::return_icon('group.png', get_lang('To'), array ('align' => 'absmiddle'),22).' '.get_lang('To').'
'; - if ((isset($_GET['id']) && $to=='everyone') || !isset($_GET['id'])) { + /*if ((isset($_GET['id']) && $to=='everyone') || !isset($_GET['id'])) { echo get_lang('Everybody').' '; - } + }*/ show_to_form($to); - if (isset($_GET['id']) && $to!='everyone') { + /*if (isset($_GET['id']) && $to!='everyone') { echo ''; - } + }*/ echo '
'; } @@ -4053,39 +4024,39 @@ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end $user_id = api_get_user_id(); // database table definitions - $t_agenda = Database::get_course_table(TABLE_AGENDA,$course_info['dbName']); - $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); + $t_agenda = Database::get_course_table(TABLE_AGENDA); $item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); // some filtering of the input data - $title = Database::escape_string($title); - $content = Database::escape_string($content); - $db_start_date = api_get_utc_datetime($db_start_date); - $start_date = Database::escape_string($db_start_date); + $title = Database::escape_string($title); + $content = Database::escape_string($content); + $db_start_date = api_get_utc_datetime($db_start_date); + $start_date = Database::escape_string($db_start_date); if (!empty($db_end_date)) { $db_end_date = api_get_utc_datetime($db_end_date); } - $end_date = Database::escape_string($db_end_date); - $id_session = api_get_session_id(); - $course_id = api_get_course_int_id(); + $end_date = Database::escape_string($db_end_date); + $id_session = api_get_session_id(); + $course_id = api_get_course_int_id(); + $group_id = api_get_group_id(); // check if exists in calendar_event table and if it is not deleted! $sql = "SELECT * FROM $t_agenda agenda, $item_property item_property WHERE - agenda.c_id = $course_id AND - item_property.c_id = $course_id AND - agenda.title = '$title' + agenda.c_id = $course_id AND + item_property.c_id = $course_id AND + agenda.title = '$title' AND agenda.content = '$content' AND agenda.start_date = '$start_date' AND agenda.end_date = '$end_date' ".(!empty($parent_id)? " AND agenda.parent_event_id = '$parent_id'":"")." AND agenda.session_id = '$id_session' AND item_property.tool = '".TOOL_CALENDAR_EVENT."' - AND item_property.ref = agenda.id + AND item_property.ref = agenda.id AND item_property.visibility <> 2"; $result = Database::query($sql); - $count = Database::num_rows($result); + $count = Database::num_rows($result); if ($count > 0) { return false; } @@ -4099,17 +4070,16 @@ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end // add a attachment file in agenda - add_agenda_attachment_file($file_comment,$last_id); + add_agenda_attachment_file($file_comment, $last_id); // store in last_tooledit (first the groups, then the users - $done = false; - if ((!is_null($to))or (!empty($_SESSION['toolgroup']))) { - // !is_null($to): when no user is selected we send it to everyone - $send_to = separate_users_groups($to); + + if (!empty($to)) { + $send_to = separate_users_groups($to); // storing the selected groups if (is_array($send_to['groups'])) { foreach ($send_to['groups'] as $group) { - api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, $group,0,$start_date, $end_date); + api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, $group, 0, $start_date, $end_date); $done = true; } } @@ -4120,15 +4090,14 @@ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end $done = true; } } + if (isset($send_to['everyone']) && $send_to['everyone']) { + api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, 0, 0, $start_date, $end_date); + } } - if(!$done) { - // the message is sent to everyone, so we set the group to 0 - api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id,0,0, $start_date,$end_date); - } // storing the resources if (!empty($_SESSION['source_type']) && !empty($last_id)) { - store_resources($_SESSION['source_type'],$last_id); + store_resources($_SESSION['source_type'], $last_id); } return $last_id; } diff --git a/main/calendar/agenda.lib.php b/main/calendar/agenda.lib.php index 90eac5dea6..4d777cf0b2 100644 --- a/main/calendar/agenda.lib.php +++ b/main/calendar/agenda.lib.php @@ -655,7 +655,7 @@ class Agenda { * @return html code */ function construct_not_selected_select_form($group_list=null, $user_list=null,$to_already_selected=array()) { - $html = ''; // adding the groups to the select form @@ -688,7 +688,7 @@ class Agenda { $username = api_htmlentities(sprintf(get_lang('LoginX'), $this_user['username']), ENT_QUOTES); // @todo : add title attribute $username in the jqdialog window. wait for a chosen version to inherit title attribute // from