From 8f45ba47f6af497ce3476927eade1f5f84fce1f1 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Tue, 16 Oct 2007 20:27:53 +0200 Subject: [PATCH] [svn r13487] Various fixes, including one fix to enable filtering by group (had been lost in previous code updates) --- main/calendar/agenda.inc.php | 141 ++++++++++++++++++----------------- main/calendar/agenda.php | 19 +++-- 2 files changed, 82 insertions(+), 78 deletions(-) diff --git a/main/calendar/agenda.inc.php b/main/calendar/agenda.inc.php index 2882a9e738..d1b4e4bf7a 100644 --- a/main/calendar/agenda.inc.php +++ b/main/calendar/agenda.inc.php @@ -1,4 +1,4 @@ -, Ghent University +* @author Yannick Warnier - cleanup * @param integer $month: the integer value of the month we are viewing * @param integer $year: the 4-digit year indication e.g. 2005 * @return array */ -function get_kalender_items($month, $year) +function get_calendar_items($month, $year) { global $_user, $_course; - global $is_allowedToEdit; + global $is_allowed_to_edit; // database variables $TABLEAGENDA=Database::get_course_table(TABLE_AGENDA); @@ -74,16 +75,18 @@ function get_kalender_items($month, $year) if (is_allowed_to_edit() OR api_get_course_setting('allow_user_edit_agenda')) { //echo "course admin"; - // added GROUP BY `agenda`.`id` to prevent double display of a message that has been sent to two groups + // added GROUP BY agenda.id to prevent double display of a message that has been sent to two groups $sql="SELECT DISTINCT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current." - AND MONTH(`agenda`.`start_date`)='".$month."' AND YEAR(`agenda`.`start_date`)='".$year."' - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND `toolitemproperties`.`visibility`='1' - GROUP BY `agenda`.`id` - ORDER BY start_date ".$sort; + WHERE agenda.id = toolitemproperties.ref ". + //$show_all_current. + " AND MONTH(agenda.start_date)='".$month."' AND YEAR(agenda.start_date)='".$year."' + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND toolitemproperties.visibility='1' + GROUP BY agenda.id ". + "ORDER BY start_date "; + //.$sort; } // if the user is not an administrator of that course else @@ -94,24 +97,28 @@ function get_kalender_items($month, $year) $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current." - AND MONTH(`agenda`.`start_date`)='".$month."' - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND ( `toolitemproperties`.`to_user_id`='".$_user['user_id']."' OR `toolitemproperties`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") ) - AND `toolitemproperties`.`visibility`='1' - ORDER BY start_date ".$sort; + WHERE agenda.id = toolitemproperties.ref ". + //$show_all_current. + " AND MONTH(agenda.start_date)='".$month."' + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND ( toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") ) + AND toolitemproperties.visibility='1'" + ."ORDER BY start_date "; + //.$sort; } else { $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current." - AND MONTH(`agenda`.`start_date`)='".$month."' - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND ( `toolitemproperties`.`to_user_id`='".$_user['user_id']."' OR `toolitemproperties`.`to_group_id`='0') - AND `toolitemproperties`.`visibility`='1' - ORDER BY start_date ".$sort; + WHERE agenda.id = toolitemproperties.ref ". + //$show_all_current. + " AND MONTH(agenda.start_date)='".$month."' + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND ( toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0') + AND toolitemproperties.visibility='1' ". + "ORDER BY start_date "; + //.$sort; } } $result=api_sql_query($sql,__FILE__,__LINE__); @@ -216,12 +223,11 @@ function display_minimonthcalendar($agendaitems, $month, $year, $monthName) function display_monthcalendar($month, $year) { global $MonthsLong; - global $datakalenderitems; global $DaysShort; global $origin; - // grabbing all the kalender items for this year and storing it in a array - $data=get_kalender_items($month,$year); + // grabbing all the calendar items for this year and storing it in a array + $data=get_calendar_items($month,$year); //Handle leap year @@ -1223,7 +1229,7 @@ function delete_agenda_item($id) // displaying the result message in the yellow box Display::display_normal_message(get_lang("AgendaDeleteSuccess")); } // if (isset($id)&&$id&&isset($action)&&$action=="delete") - } // if ($is_allowedToEdit) + } // if ($is_allowed_to_edit) } /** @@ -1251,6 +1257,7 @@ function showhide_agenda_item($id) /** * Displays all the agenda items * @author Patrick Cool , Ghent University +* @author Yannick Warnier - cleanup */ function display_agenda_items() { @@ -1259,8 +1266,7 @@ function display_agenda_items() global $select_month, $select_year; global $DaysShort, $DaysLong, $MonthsLong; global $is_courseAdmin; - global $dateFormatLong, $timeNoSecFormat,$charset; - global $_user; + global $dateFormatLong, $timeNoSecFormat,$charset, $_user, $_course; // getting the group memberships $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']); @@ -1304,7 +1310,7 @@ function display_agenda_items() { // A.1. you are a course admin with a USER filter // => see only the messages of this specific user + the messages of the group (s)he is member of. - if ($_SESSION['user']!==null) + if (!empty($_SESSION['user'])) { $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_SESSION['user']); if (is_array($group_memberships)) @@ -1312,10 +1318,10 @@ function display_agenda_items() $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current." - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND ( `toolitemproperties`.`to_user_id`=$user_id OR `toolitemproperties`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") ) - AND `toolitemproperties`.`visibility`='1' + WHERE agenda.id = toolitemproperties.ref ".$show_all_current." + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND ( toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") ) + AND toolitemproperties.visibility='1' ORDER BY start_date ".$_SESSION['sort']; } else @@ -1323,10 +1329,10 @@ function display_agenda_items() $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current." - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND ( `toolitemproperties`.`to_user_id`=$user_id OR `toolitemproperties`.`to_group_id`='0') - AND `toolitemproperties`.`visibility`='1' + WHERE agenda.id = toolitemproperties.ref ".$show_all_current." + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND ( toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id='0') + AND toolitemproperties.visibility='1' ORDER BY start_date ".$_SESSION['sort']; } } @@ -1337,13 +1343,12 @@ function display_agenda_items() $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current." - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND ( `toolitemproperties`.`to_group_id`=$group_id OR `toolitemproperties`.`to_group_id`='0') - AND `toolitemproperties`.`visibility`='1' - GROUP BY `toolitemproperties`.`ref` + WHERE agenda.id = toolitemproperties.ref ".$show_all_current." + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND ( toolitemproperties.to_group_id=$group_id OR toolitemproperties.to_group_id='0') + AND toolitemproperties.visibility='1' + GROUP BY toolitemproperties.ref ORDER BY start_date ".$_SESSION['sort']; - } // A.3 you are a course admin without any group or user filter else @@ -1355,10 +1360,10 @@ function display_agenda_items() $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current." - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND `toolitemproperties`.`visibility`='1' - GROUP BY `toolitemproperties`.`ref` + WHERE agenda.id = toolitemproperties.ref ".$show_all_current." + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND toolitemproperties.visibility='1' + GROUP BY toolitemproperties.ref ORDER BY start_date ".$_SESSION['sort']; } @@ -1369,10 +1374,10 @@ function display_agenda_items() $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current." - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND ( `toolitemproperties`.`visibility`='0' or `toolitemproperties`.`visibility`='1') - GROUP BY `toolitemproperties`.`ref` + WHERE agenda.id = toolitemproperties.ref ".$show_all_current." + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND ( toolitemproperties.visibility='0' or toolitemproperties.visibility='1') + GROUP BY toolitemproperties.ref ORDER BY start_date ".$_SESSION['sort']; } } @@ -1387,10 +1392,10 @@ function display_agenda_items() $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current." - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND ( `toolitemproperties`.`to_user_id`=$user_id OR `toolitemproperties`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") ) - AND `toolitemproperties`.`visibility`='1' + WHERE agenda.id = toolitemproperties.ref ".$show_all_current." + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND ( toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") ) + AND toolitemproperties.visibility='1' ORDER BY start_date ".$_SESSION['sort']; } else @@ -1400,10 +1405,10 @@ function display_agenda_items() $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current." - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND ( `toolitemproperties`.`to_user_id`=$user_id OR `toolitemproperties`.`to_group_id`='0') - AND `toolitemproperties`.`visibility`='1' + WHERE agenda.id = toolitemproperties.ref ".$show_all_current." + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND ( toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id='0') + AND toolitemproperties.visibility='1' ORDER BY start_date ".$_SESSION['sort']; } else @@ -1411,10 +1416,10 @@ function display_agenda_items() $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current." - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND `toolitemproperties`.`to_group_id`='0' - AND `toolitemproperties`.`visibility`='1' + WHERE agenda.id = toolitemproperties.ref ".$show_all_current." + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND toolitemproperties.to_group_id='0' + AND toolitemproperties.visibility='1' ORDER BY start_date ".$_SESSION['sort']; } } @@ -1638,10 +1643,10 @@ function display_one_agenda_item($agenda_id) $sql="SELECT agenda.*, toolitemproperties.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties - WHERE `agenda`.`id` = `toolitemproperties`.`ref` - AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."' - AND `toolitemproperties`.`visibility`='1' - AND `agenda`.`id`='$agenda_id'"; + WHERE agenda.id = toolitemproperties.ref + AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."' + AND toolitemproperties.visibility='1' + AND agenda.id='$agenda_id'"; $result=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error()); $number_items=mysql_num_rows($result); $myrow=mysql_fetch_array($result); // there should be only one item so no need for a while loop diff --git a/main/calendar/agenda.php b/main/calendar/agenda.php index ad35395a59..4f5ee22511 100644 --- a/main/calendar/agenda.php +++ b/main/calendar/agenda.php @@ -1,4 +1,4 @@ -" - . ""; +echo '' + . ''; // THE LEFT PART if ($_GET['origin']!='learnpath') @@ -252,18 +251,18 @@ if ($_GET['origin']!='learnpath') echo '"; - echo ""; + echo ''; + echo ''; + echo ''; } $fck_attribute['Width'] = '600';
'; // the small calendar $MonthName = $MonthsLong[$select_month -1]; - $agenda_items=get_kalender_items($select_month,$select_year); + $agenda_items=get_calendar_items($select_month,$select_year); display_minimonthcalendar($agenda_items, $select_month,$select_year, $MonthName); // the links for adding, filtering, showall, ... - echo "
    "; + echo '
      '; if (is_allowed_to_edit()) { display_courseadmin_links(); } display_student_links(); - echo "
    "; - echo "