diff --git a/main/calendar/agenda.inc.php b/main/calendar/agenda.inc.php index e94906fe14..039a5eae83 100755 --- a/main/calendar/agenda.inc.php +++ b/main/calendar/agenda.inc.php @@ -3386,13 +3386,14 @@ function get_day_agendaitems($courses_dbs, $month, $year, $day) { foreach ($courses_dbs as $key => $array_course_info) { //echo $array_course_info['db']; //databases of the courses - $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info['db']); - $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info['db']); + $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info['db_name']); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info['db_name']); // getting all the groups of the user for the current course - $group_memberships = GroupManager :: get_group_ids($array_course_info['db'], $_user['user_id']); + $group_memberships = GroupManager :: get_group_ids($array_course_info['db_name'], api_get_user_id()); + $course_user_status = CourseManager::get_user_in_course_status(api_get_user_id(), $array_course_info['code']); // if the user is administrator of that course we show all the agenda items - if ($array_course_info['status'] == '1') { + if ($course_user_status == '1') { //echo "course admin"; $sqlquery = "SELECT DISTINCT agenda.*, item_property.* @@ -3461,7 +3462,7 @@ function get_day_agendaitems($courses_dbs, $month, $year, $day) { //$URL = $_configuration['root_web'].$mycours["dir"]."/"; $URL = api_get_path(WEB_PATH).'main/calendar/agenda.php?cidReq='.urlencode($array_course_info["code"])."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item - $items[$halfhour][] .= "".$hours.":".$minutes." ".$agenda_link." ".$item['title']."
"; + $items[$halfhour][] .= "".$hours.":".$minutes." ".$agenda_link." ".$item['title']."
"; } } @@ -3504,14 +3505,16 @@ function get_week_agendaitems($courses_dbs, $month, $year, $week = '') { // get agenda-items for every course foreach ($courses_dbs as $key => $array_course_info) { //databases of the courses - $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]); - $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]); + $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db_name"]); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db_name"]); // getting all the groups of the user for the current course - $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); + $group_memberships = GroupManager :: get_group_ids($array_course_info["db_name"], api_get_user_id()); + + $user_course_status = CourseManager::get_user_in_course_status(api_get_user_id(),$array_course_info["code"]); // if the user is administrator of that course we show all the agenda items - if ($array_course_info['status'] == '1') { + if ($user_course_status == '1') { //echo "course admin"; $sqlquery = "SELECT DISTINCT a.*, i.* @@ -3571,7 +3574,7 @@ function get_week_agendaitems($courses_dbs, $month, $year, $week = '') { $URL = $_configuration['root_web']."main/calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item //Display the events in agenda - $items[$agendaday][$item['start_date']] .= "$time ".$agenda_link.""; + $items[$agendaday][$item['start_date']] .= "$time ".$agenda_link.""; $items[$agendaday][$item['start_date']] .= "
".$item['title']."

"; } } diff --git a/main/calendar/myagenda.inc.php b/main/calendar/myagenda.inc.php index 1a0e0242f5..70a22001fd 100755 --- a/main/calendar/myagenda.inc.php +++ b/main/calendar/myagenda.inc.php @@ -47,20 +47,20 @@ $setting_agenda_link = 'coursecode'; // valid values are coursecode and icon * This function retrieves all the agenda items of all the courses the user is subscribed to */ function get_myagendaitems($courses_dbs, $month, $year) { - global $_user; global $_configuration; global $setting_agenda_link; - $items = array (); + $items = array(); // get agenda-items for every course foreach ($courses_dbs as $key => $array_course_info) { //databases of the courses - $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]); - $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]); + $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db_name"]); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db_name"]); - $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); + $group_memberships = GroupManager :: get_group_ids($array_course_info["db_name"], api_get_user_id()); + $course_user_status = CourseManager::get_user_in_course_status(api_get_user_id(), $array_course_info["code"]); // if the user is administrator of that course we show all the agenda items - if ($array_course_info['status'] == '1') { + if ($course_user_status == '1') { //echo "course admin"; $sqlquery = "SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref FROM ".$TABLEAGENDA." agenda, @@ -84,7 +84,7 @@ function get_myagendaitems($courses_dbs, $month, $year) { AND MONTH(agenda.start_date)='".$month."' AND YEAR(agenda.start_date)='".$year."' AND ip.tool='".TOOL_CALENDAR_EVENT."' - AND ( ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) + AND ( ip.to_user_id='".api_get_user_id()."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) AND ip.visibility='1' ORDER BY start_date "; } else { @@ -95,21 +95,20 @@ function get_myagendaitems($courses_dbs, $month, $year) { AND MONTH(agenda.start_date)='".$month."' AND YEAR(agenda.start_date)='".$year."' AND ip.tool='".TOOL_CALENDAR_EVENT."' - AND ( ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0') + AND ( ip.to_user_id='".api_get_user_id()."' OR ip.to_group_id='0') AND ip.visibility='1' ORDER BY start_date "; } } - $result = Database::query($sqlquery); while ($item = Database::fetch_array($result)) { $agendaday = date("j",strtotime($item['start_date'])); if(!isset($items[$agendaday])) { $items[$agendaday]=array(); } - $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT, date_default_timezone_get()); + $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT, date_default_timezone_get()); $end_time = api_convert_and_format_date($item['end_date'], TIME_NO_SEC_FORMAT, date_default_timezone_get()); - $URL = api_get_path(WEB_PATH)."main/calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item + $URL = api_get_path(WEB_PATH)."main/calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item if ($setting_agenda_link == 'coursecode') { $title=$array_course_info['title']; $agenda_link = api_substr($title, 0, 14); @@ -125,6 +124,7 @@ function get_myagendaitems($courses_dbs, $month, $year) { $items[$agendaday][$item['start_date']] .= '
'; } } + // sorting by hour for every day $agendaitems = array (); while (list ($agendaday, $tmpitems) = each($items)) { @@ -136,9 +136,6 @@ function get_myagendaitems($courses_dbs, $month, $year) { $agendaitems[$agendaday] .= $val; } } - - - //print_r($agendaitems); return $agendaitems; } /** @@ -164,7 +161,7 @@ function display_mymonthcalendar($agendaitems, $month, $year, $weekdaynames=arra $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($g_cc)."&action=view&view=month&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year); $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($g_cc)."&action=view&view=month&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year); - echo ''.''; + echo '
'; echo ''; echo ''; echo ''; @@ -190,7 +187,7 @@ function display_mymonthcalendar($agendaitems, $month, $year, $weekdaynames=arra $dayheader = "$curday
"; $class = "class=\"days_today\" style=\"width:10%;\""; } - echo "
'.Display::return_icon('action_prev.png',get_lang('Previous')).'

'.$monthName." ".$year.'

'.Display::return_icon('action_next.png',get_lang('Next')).'", "".$dayheader; + echo "".$dayheader; if (!empty($agendaitems[$curday])) { echo "".$agendaitems[$curday].""; } @@ -275,7 +272,6 @@ function display_myminimonthcalendar($agendaitems, $month, $year, $monthName) { */ function show_new_personal_item_form($id = "") { global $year, $MonthsLong; - global $_user; $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA); @@ -297,7 +293,7 @@ function show_new_personal_item_form($id = "") { } if ($id != "") { - $sql = "SELECT date, title, text FROM ".$tbl_personal_agenda." WHERE user='".intval($_user['user_id'])."' AND id='".$id."'"; + $sql = "SELECT date, title, text FROM ".$tbl_personal_agenda." WHERE user='".intval(api_get_user_id())."' AND id='".$id."'"; $result = Database::query($sql); $aantal = Database::num_rows($result); if ($aantal != 0) { @@ -473,7 +469,6 @@ function show_new_personal_item_form($id = "") { * @param int is the id this param is optional, but is necessary if the item require be edited */ function store_personal_item($day, $month, $year, $hour, $minute, $title, $content, $id = "") { - global $_user; $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA); @@ -490,11 +485,11 @@ function store_personal_item($day, $month, $year, $hour, $minute, $title, $conte if ($id != "") { // we are updating - $sql = "UPDATE ".$tbl_personal_agenda." SET user='".$_user['user_id']."', title='".$title."', text='".$content."', date='".$date."' WHERE id='".$id."'"; + $sql = "UPDATE ".$tbl_personal_agenda." SET user='".api_get_user_id()."', title='".$title."', text='".$content."', date='".$date."' WHERE id='".$id."'"; } else { // we are adding a new item - $sql = "INSERT INTO $tbl_personal_agenda (user, title, text, date) VALUES ('".$_user['user_id']."','$title', '$content', '$date')"; + $sql = "INSERT INTO $tbl_personal_agenda (user, title, text, date) VALUES ('".api_get_user_id()."','$title', '$content', '$date')"; } $result = Database::query($sql); } @@ -502,11 +497,10 @@ function store_personal_item($day, $month, $year, $hour, $minute, $title, $conte * This function finds all the courses (also those of sessions) of the user and returns an array containing the * database name of the courses. * Xritten by Noel Dieschburg + * @todo remove this function and use the CourseManager get_courses_list_by_user_id */ function get_all_courses_of_user() { - global $_user; - $TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE); $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER); $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE); @@ -515,19 +509,18 @@ function get_all_courses_of_user() { $sql_select_courses = "SELECT c.code k, c.visual_code vc, c.title i, c.tutor_name t, c.db_name db, c.directory dir, '5' as status FROM $TABLECOURS c, $tbl_session_course_user srcu - WHERE srcu.id_user='".$_user['user_id']."' + WHERE srcu.id_user='".api_get_user_id()."' AND c.code=srcu.course_code UNION SELECT c.code k, c.visual_code vc, c.title i, c.tutor_name t, c.db_name db, c.directory dir, cru.status status FROM $TABLECOURS c, $TABLECOURSUSER cru - WHERE cru.user_id='".$_user['user_id']."' + WHERE cru.user_id='".api_get_user_id()."' AND c.code=cru.course_code"; $result = Database::query($sql_select_courses); - while ($row = Database::fetch_array($result)) - { - // we only need the database name of the course - $courses[] = array ("db" => $row['db'], "code" => $row['k'], "visual_code" => $row['vc'], "title" => $row['i'], "directory" => $row['dir'], "status" => $row['status']); + while ($row = Database::fetch_array($result)) { + // we only need the database name of the course + $courses[] = array ("db" => $row['db'], "code" => $row['k'], "visual_code" => $row['vc'], "title" => $row['i'], "directory" => $row['dir'], "status" => $row['status']); } return $courses; } @@ -540,8 +533,6 @@ function get_all_courses_of_user() { * database name of the courses. */ function get_courses_of_user() { - global $_user; - $TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE); $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER); $sql_select_courses = "SELECT course.code k, course.visual_code vc, @@ -549,7 +540,7 @@ function get_courses_of_user() { FROM $TABLECOURS course, $TABLECOURSUSER course_rel_user WHERE course.code = course_rel_user.course_code - AND course_rel_user.user_id = '".$_user['user_id']."'"; + AND course_rel_user.user_id = '".api_get_user_id()."'"; $result = Database::query($sql_select_courses); while ($row = Database::fetch_array($result)) { @@ -562,14 +553,13 @@ function get_courses_of_user() { * This function retrieves all the personal agenda items and add them to the agenda items found by the other functions. */ function get_personal_agenda_items($agendaitems, $day = "", $month = "", $year = "", $week = "", $type) { - global $_user; global $_configuration; $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA); // 1. creating the SQL statement for getting the personal agenda items in MONTH view if ($type == "month_view" or $type == "") // we are in month view { - $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."' ORDER BY date ASC"; + $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."' ORDER BY date ASC"; } // 2. creating the SQL statement for getting the personal agenda items in WEEK view // we are in week view @@ -584,7 +574,7 @@ function get_personal_agenda_items($agendaitems, $day = "", $month = "", $year = // in sql statements you have to use year-month-day for date calculations $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00"; $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59"; - $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' + $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' AND date>='".$start_filter."' AND date<='".$end_filter."'"; } // 3. creating the SQL statement for getting the personal agenda items in DAY view @@ -593,7 +583,7 @@ function get_personal_agenda_items($agendaitems, $day = "", $month = "", $year = // we could use mysql date() function but this is only available from 4.1 and higher $start_filter = $year."-".$month."-".$day." 00:00:00"; $end_filter = $year."-".$month."-".$day." 23:59:59"; - $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' AND date>='".$start_filter."' AND date<='".$end_filter."'"; + $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' AND date>='".$start_filter."' AND date<='".$end_filter."'"; } //echo "day:".$day."/"; //echo "month:".$month."/"; @@ -654,7 +644,6 @@ function get_personal_agenda_items($agendaitems, $day = "", $month = "", $year = } } - //print_r($agendaitems); return $agendaitems; } /** @@ -855,8 +844,6 @@ function show_simple_personal_agenda($user_id) { * does not belong to him/her */ function delete_personal_agenda($id) { - global $_user; - $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA); if ($id != strval(intval($id))) { @@ -865,12 +852,12 @@ function delete_personal_agenda($id) { if ($id <> '') { - $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' AND id='".$id."'"; + $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' AND id='".$id."'"; $result = Database::query($sql); $aantal = Database::num_rows($result); if ($aantal <> 0) { - $sql = "DELETE FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' AND id='".$id."'"; + $sql = "DELETE FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' AND id='".$id."'"; $result = Database::query($sql); } } diff --git a/main/calendar/myagenda.php b/main/calendar/myagenda.php index 37b585b36b..f85c7ffc38 100755 --- a/main/calendar/myagenda.php +++ b/main/calendar/myagenda.php @@ -115,12 +115,15 @@ if (!empty($_GET['action']) && $_GET['action'] == "delete" AND $_GET['id']) { } // OUTPUT -if (isset ($_user['user_id'])) { +if (isset($_user['user_id'])) { // getting all the courses that this user is subscribed to - $courses_dbs = get_all_courses_of_user(); - if (!is_array($courses_dbs)) { + //$courses_dbs = get_all_courses_of_user(); + $my_course_list = CourseManager::get_courses_list_by_user_id(api_get_user_id(), true); + + print_r($course_list); + if (!is_array($my_course_list)) { // this is for the special case if the user has no courses (otherwise you get an error) - $courses_dbs = array (); + $my_course_list = array(); } // setting and/or getting the year, month, day, week $today = getdate(); @@ -156,8 +159,7 @@ if (isset ($_user['user_id'])) { } echo ""; - - $agendaitems = get_myagendaitems($courses_dbs, $month, $year); + $agendaitems = get_myagendaitems($my_course_list, $month, $year); $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view"); if (api_get_setting('allow_personal_agenda') == 'true') { $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "month_view"); @@ -178,7 +180,7 @@ if (isset ($_user['user_id'])) { switch ($process) { case 'month_view' : - $agendaitems = get_myagendaitems($courses_dbs, $month, $year); + $agendaitems = get_myagendaitems($my_course_list, $month, $year); $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view"); if (api_get_setting("allow_personal_agenda") == "true") { @@ -187,7 +189,7 @@ if (isset ($_user['user_id'])) { display_mymonthcalendar($agendaitems, $month, $year, array(), $monthName); break; case 'week_view' : - $agendaitems = get_week_agendaitems($courses_dbs, $month, $year, $week); + $agendaitems = get_week_agendaitems($my_course_list, $month, $year, $week); $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "week_view"); if (api_get_setting("allow_personal_agenda") == "true") { $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "week_view"); @@ -195,7 +197,7 @@ if (isset ($_user['user_id'])) { display_weekcalendar($agendaitems, $month, $year, array(), $monthName); break; case 'day_view' : - $agendaitems = get_day_agendaitems($courses_dbs, $month, $year, $day); + $agendaitems = get_day_agendaitems($my_course_list, $month, $year, $day); $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "day_view"); if (api_get_setting('allow_personal_agenda') == 'true') { $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "day_view"); diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 8f51fca9a6..8433e7dfee 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -220,7 +220,7 @@ class CourseManager { */ public static function get_user_in_course_status($user_id, $course_code) { $result = Database::fetch_array(Database::query( - "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)." + "SELECT status FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)." WHERE course_code = '".Database::escape_string($course_code)."' AND user_id = ".Database::escape_string($user_id)) ); return $result['status'];