Pārlūkot izejas kodu

Adding month calendar in user_list only for admins BT#2719

Julio Montoya 13 gadi atpakaļ
vecāks
revīzija
06f7d2ea1d

+ 36 - 2
main/admin/user_list.php

@@ -1,7 +1,8 @@
-<?php // $Id: user_list.php 22292 2009-07-22 18:32:32Z herodoto $
+<?php
 /* For licensing terms, see /license.txt */
 /**
 	@author Bart Mollet
+	@author Julio Montoya <gugli100@gmail.com> BeezNest 2011
 *	@package chamilo.admin
 */
 
@@ -22,6 +23,8 @@ if (isset($_configuration['deny_delete_users']) &&  $_configuration['deny_delete
 	$delete_user_available = false;
 }
 
+$htmlHeadXtra[] = api_get_jquery_ui_js();
+
 $htmlHeadXtra[] = '<script type="text/javascript">
 function load_course_list (div_course,my_user_id) {
 	 $.ajax({
@@ -103,8 +106,36 @@ $(document).ready(function() {
             document.getElementById(\'extra_data_text\').style.display="none";
         }
     }
+    
+    
+    $(".agenda_opener").live("click", function() {
+        var url = this.href;
+        var dialog = $("#dialog");
+                
+        if ($("#dialog").length == 0) {
+            dialog = $(\'<div id="dialog" style="display:hidden"></div> \').appendTo(\'body\');
+        }     
+        // load remote content
+        dialog.load(
+                url,
+                {},
+                function(responseText, textStatus, XMLHttpRequest) {
+                    dialog.dialog({width:720, height:550, modal:true});
+                }
+            );
+        //prevent the browser to follow the link
+        return false;
+    });    
 });
 
+//Load user calendar
+function load_calendar(user_id, month, year) {  
+ 	var url = "'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&user_id=" +user_id + "&month="+month+"&year="+year;
+	$("#dialog").load( url    	 	
+	);    	
+}
+    
+
 </script>';
 $htmlHeadXtra[] = '<style type="text/css" media="screen, projection">
 .blackboard_show {
@@ -623,6 +654,9 @@ function modify_filter($user_id,$url_params,$row) {
 	}
 	
     if (api_is_platform_admin()) {
+        
+        $result .= ' <a href="'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&user_id='.$user_id.'" class="agenda_opener">'.Display::return_icon('month.png', get_lang('Calendar'), array(), 22).'</a>';
+        
        if ($delete_user_available) {
             if ($row[0] != $_user['user_id'] && !$user_is_anonymous) {
                 // you cannot lock yourself out otherwise you could disable all the accounts including your own => everybody is locked out and nobody can change it anymore.
@@ -630,7 +664,7 @@ function modify_filter($user_id,$url_params,$row) {
             } else {
                 $result .= Display::return_icon('delete_na.png', get_lang('Delete'), array(), 22);
             }
-        }
+        }       
     }
     
 

+ 4 - 2
main/calendar/agenda.inc.php

@@ -26,6 +26,9 @@ $(document).ready(function () {
 });
 </script>';
 
+require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
+
+
 /**
 * Retrieves all the agenda items from the table
 * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
@@ -4339,8 +4342,7 @@ function agenda_import_ical($course_info,$file) {
  * @return 	array	The results of the database query, or null if not found
  */
 function get_global_agenda_items($agendaitems, $day = "", $month = "", $year = "", $week = "", $type) {
-	$tbl_global_agenda= Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
-
+	$tbl_global_agenda= Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);    
 	$month = Database::escape_string($month);
 	$year  = Database::escape_string($year);
 	$week  = Database::escape_string($week);

+ 1 - 34
main/calendar/allagendas.php

@@ -387,41 +387,8 @@ if (isset ($_user['user_id'])) {
 			} else {
 				Display::display_warning_message(get_lang('PleaseSelectACourseOrASessionInTheLeftColumn'));
 			}
-			
-/*			$agendaitems = get_allagendaitems($grado2, $month, $year);
-			$agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
-			display_mymonthcalendar_2($agendaitems, $month, $year, array(), $monthName, $gradoo);
-
-			
-			$agendaitems = get_allagendaitems($grado3, $month, $year);
-			$agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
-			display_mymonthcalendar_2($agendaitems, $month, $year, array(), $monthName, $gradoo);			
-*/
-			break;
-			/*
-		case "week_view" :
-			$agendaitems = get_week_agendaitems($courses_dbs, $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");
-			}
-			display_weekcalendar($agendaitems, $month, $year, array(), $monthName);
-			break;
-		case "day_view" :
-			$agendaitems = get_day_agendaitems($courses_dbs, $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");
-			}
-			display_daycalendar($agendaitems, $day, $month, $year, array(), $monthName);
 			break;
-		case "personal_view" :
-			show_personal_agenda();
-			break;*/
 	}
 }
 echo "</td></tr></table>";
-Display :: display_footer();
-?>
+Display :: display_footer();

+ 66 - 55
main/calendar/myagenda.inc.php

@@ -46,11 +46,15 @@
  */
 $setting_agenda_link = 'coursecode'; // valid values are coursecode and icon
 
+require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
+
+
 /**
  *	This function retrieves all the agenda items of all the courses the user is subscribed to
  */
-function get_myagendaitems($courses_dbs, $month, $year) {	
+function get_myagendaitems($user_id, $courses_dbs, $month, $year) {	
 	global $setting_agenda_link;
+	$user_id = intval($user_id);
 
 	$items = array();
 	$my_list = array();
@@ -61,8 +65,8 @@ function get_myagendaitems($courses_dbs, $month, $year) {
 		$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_name"], api_get_user_id());
-		$course_user_status = CourseManager::get_user_in_course_status(api_get_user_id(), $array_course_info["code"]);
+		$group_memberships = GroupManager :: get_group_ids($array_course_info["db_name"], $user_id);
+		$course_user_status = CourseManager::get_user_in_course_status($user_id, $array_course_info["code"]);
 		// if the user is administrator of that course we show all the agenda items
 		if ($course_user_status == '1') {
 			//echo "course admin";
@@ -88,7 +92,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='".api_get_user_id()."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
+								AND	( ip.to_user_id='".$user_id."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
 								AND ip.visibility='1'
 								ORDER BY start_date ";
 			} else {
@@ -99,7 +103,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='".api_get_user_id()."' OR ip.to_group_id='0')
+								AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0')
 								AND ip.visibility='1'
 								ORDER BY start_date ";
 				}
@@ -115,31 +119,7 @@ function get_myagendaitems($courses_dbs, $month, $year) {
 			$item['url'] = $url;
 			$item['course_name'] = $array_course_info['title'];	
 			$item['calendar_type'] = 'course';
-			$my_list[$agendaday][] = $item;
-			/*
-			
-			if(!isset($items[$agendaday])) {
-				$items[$agendaday]=array();
-			}
-			$time     = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
-			$end_time = '';
-			if ($item['end_date'] != '0000-00-00 00:00:00') {
-                $end_time = '&nbsp;-&nbsp;<i>'.api_convert_and_format_date($item['end_date'], DATE_TIME_FORMAT_LONG).'</i>';
-			}
-			
-			if ($setting_agenda_link == 'coursecode') {
-				$title=$array_course_info['title'];
-				$agenda_link = api_substr($title, 0, 14);
-			} else {
-				$agenda_link = Display::return_icon('course_home.gif');
-			}
-			if(!isset($items[$agendaday][$item['start_date']])) {
-				$items[$agendaday][$item['start_date']] = '';
-			}
-			$items[$agendaday][$item['start_date']] .= "<i>$time</i> $end_time &nbsp;";
-			$item['title'] = '<strong>'.$item['title'].'</strong>';
-			$items[$agendaday][$item['start_date']] .= '<br />'."<a href=\"$URL\" title=\"".Security::remove_XSS($array_course_info['title'])."\">".$agenda_link."</a>  ".Security::remove_XSS($item['title'])."<br /> ";
-			$items[$agendaday][$item['start_date']] .= '<br/>';*/					
+			$my_list[$agendaday][] = $item;					
 		}
 	}
 
@@ -167,8 +147,8 @@ function get_myagendaitems($courses_dbs, $month, $year) {
  * @param	string	The month name
  * @return	void	Direct output
  */
-function display_mymonthcalendar($agendaitems, $month, $year, $weekdaynames=array(), $monthName) {
-	global $DaysShort,$course_path;
+function display_mymonthcalendar($user_id, $agendaitems, $month, $year, $weekdaynames = array(), $monthName, $show_content = true) {    
+	global $DaysShort, $course_path;	
 	//Handle leap year
 	$numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
 	if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
@@ -178,13 +158,29 @@ function display_mymonthcalendar($agendaitems, $month, $year, $weekdaynames=arra
 	//Start the week on monday
 	$startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
 	$g_cc = (isset($_GET['courseCode'])?$_GET['courseCode']:'');
-	$backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
-	$forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
+	
+	$prev_icon = Display::return_icon('action_prev.png',get_lang('Previous'));
+	$next_icon = Display::return_icon('action_next.png',get_lang('Next'));
+	
+	$next_month = ($month == 1 ? 12 : $month -1);
+	$prev_month = ($month == 12 ? 1 : $month +1);
+	
+	$next_year = ($month == 1 ? $year -1 : $year);
+	$prev_year = ($month == 12 ? $year +1 : $year);
+	
+	if ($show_content)  {
+	    $back_url = Display::url($prev_icon, api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=".$next_month."&amp;year=".$next_year);	    
+	    $next_url = Display::url($next_icon, api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=".$prev_month."&amp;year=".$prev_year);
+	} else {
+        $back_url = Display::url($prev_icon, '', array('onclick'=>"load_calendar('".$user_id."','".$next_month."', '".$next_year."'); "));	    
+	    $next_url = Display::url($next_icon, '', array('onclick'=>"load_calendar('".$user_id."','".$prev_month."', '".$prev_year."'); "));	    
+	}
 
 	echo '<table id="agenda_list"><tr>';
-	echo '<th width="10%"><a href="'.$backwardsURL.'">'.Display::return_icon('action_prev.png',get_lang('Previous')).'</a></th>';
+	echo '<th width="10%">'.$back_url.'</th>';
 	echo '<th width="80%" colspan="5"><br /><h3>'.$monthName." ".$year.'</h3></th>';
-	echo '<th width="10%"><a href="'.$forewardsURL.'">'.Display::return_icon('action_next.png',get_lang('Next')).'</a></th>';
+	echo '<th width="10%">'.$next_url.'</th>';
+		
 	echo '</tr>';
 
 	echo '<tr>';
@@ -232,26 +228,39 @@ function display_mymonthcalendar($agendaitems, $month, $year, $weekdaynames=arra
                                 break;
                             case 'course':
                                 $bg_color = '#CAFFAA';
-                                $icon = Display::url(Display::return_icon('course.png', $value['course_name'].' '.get_lang('Course'), array(), 22), $value['url']);                                                                                  
+                                if ($show_content) {
+                                    $icon = Display::url(Display::return_icon('course.png', $value['course_name'].' '.get_lang('Course'), array(), 22), $value['url']);
+                                } else {
+                                    $icon = Display::return_icon('course.png', $value['course_name'].' '.get_lang('Course'), array(), 22);
+                                }                                                                                  
                                 break;              
                             default:
-                                break;                          
-                        }                        		       
-				        $icon = Display::div($icon, array('style'=>'float:right'));
-                        //Setting a personal event to green
-                        $result = '<div class="rounded_div_agenda" style="background-color:'.$bg_color.';">';
+                                break;
+                        }   
                         
-                        //Link to bubble                                                
-                        $url = Display::url(cut($value['title'], 40), '#', array('id'=>$value['calendar_type'].'_'.$value['id'],'class'=>'opener'));                                 
-                        $result .= $time.' '.$icon.' '.Display::div($url);
+                        $result = '<div class="rounded_div_agenda" style="background-color:'.$bg_color.';">';
                         
-                        //Main div
-                        $result .= '</div>';                                                
-                        echo $result;
+                        if ($show_content) {
+    				        
+                            //Setting a personal event to green
+                            $icon = Display::div($icon, array('style'=>'float:right'));                            
+                            
+                            //Link to bubble                                                
+                            $url = Display::url(cut($value['title'], 40), '#', array('id'=>$value['calendar_type'].'_'.$value['id'],'class'=>'opener'));                                 
+                            $result .= $time.' '.$icon.' '.Display::div($url);
+                            
+                            //Main div
+                            $result .= '</div>';                        
+                            echo $result;
+                            
+                            //Hidden content
+                            $content = Display::div($icon.Display::tag('h1', $value['title']).$complete_time.Security::remove_XSS($value['content']));
+                            
+                            //echo Display::div($content, array('id'=>'main_'.$value['calendar_type'].'_'.$value['id'], 'class' => 'dialog'));
+                        } else {
+                            echo $result .= $icon;
+                        }
                         
-                        //Hidden content
-                        $content = Display::div($icon.Display::tag('h1', $value['title']).$complete_time.Security::remove_XSS($value['content']));
-                        echo Display::div($content, array('id'=>'main_'.$value['calendar_type'].'_'.$value['id'], 'class' => 'dialog'));
 				   }
 				}
 				echo "</td>";
@@ -611,12 +620,14 @@ 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) {
+function get_personal_agenda_items($user_id, $agendaitems, $day = "", $month = "", $year = "", $week = "", $type) {
 	$tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
+	$user_id = intval($user_id);
+	
 	// 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='".api_get_user_id()."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."'  ORDER BY date ASC";
+		$sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$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
@@ -631,7 +642,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='".api_get_user_id()."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
+		$sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
 	}
 	// 3. creating the SQL statement for getting the personal agenda items in DAY view
 	if ($type == "day_view") // we are in day view
@@ -639,7 +650,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='".api_get_user_id()."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
+		$sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
 	}	  	
 
 	$result = Database::query($sql);

+ 6 - 8
main/calendar/myagenda.php

@@ -11,7 +11,6 @@ $this_section = SECTION_MYAGENDA;
 unset($_SESSION['this_section']);//for hmtl editor repository
 
 api_block_anonymous_users();
-require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
 require_once 'agenda.inc.php';
 require_once 'myagenda.inc.php';
 // setting the name of the tool
@@ -151,8 +150,7 @@ if (isset($_user['user_id'])) {
 	// setting and/or getting the year, month, day, week
 	$today = getdate();
 	$year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL);
-	if ($year == NULL)
-	{
+	if ($year == NULL) {
 		$year = $today['year'];
 	}
 	$month = (!empty($_GET['month'])? (int)$_GET['month']:NULL);
@@ -181,11 +179,11 @@ if (isset($_user['user_id'])) {
 	}
 	echo "</div>";
 
-	$agendaitems = get_myagendaitems($my_course_list, $month, $year);	
+	$agendaitems = get_myagendaitems(api_get_user_id(), $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");
+		$agendaitems = get_personal_agenda_items(api_get_user_id(), $agendaitems, $day, $month, $year, $week, "month_view");
 	}
 	
 	if ($process != 'month_view') {
@@ -204,13 +202,13 @@ if (isset($_user['user_id'])) {
 	
 	switch ($process) {
 		case 'month_view' :
-			display_mymonthcalendar($agendaitems, $month, $year, array(), $monthName);
+			display_mymonthcalendar(api_get_user_id(), $agendaitems, $month, $year, array(), $monthName);
 			break;
 		case 'week_view' :
 			$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");
+				$agendaitems = get_personal_agenda_items(api_get_user_id(), $agendaitems, $day, $month, $year, $week, "week_view");
 			}
 			display_weekcalendar($agendaitems, $month, $year, array(), $monthName);
 			break;
@@ -218,7 +216,7 @@ if (isset($_user['user_id'])) {
 			$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");
+				$agendaitems = get_personal_agenda_items(api_get_user_id(), $agendaitems, $day, $month, $year, $week, "day_view");
 			}
 			display_daycalendar($agendaitems, $day, $month, $year, array(), $monthName);
 			break;

+ 1 - 1
main/css/base.css

@@ -424,7 +424,7 @@ a.personal_agenda:hover, a.personal_agenda:hover {
     height: auto;
     margin: 2px 4px 15px;
     padding: 8px;
-    width: 85%;
+    width: 75%;
 }
 
 .agenda_day {