parent
							
								
									bfd5f3bc9f
								
							
						
					
					
						commit
						8694ff7c03
					
				
									
										
											File diff suppressed because it is too large
											Load Diff
										
									
								
							
						@ -1,283 +0,0 @@ | 
				
			||||
<?php // $id: $
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
/** | 
				
			||||
*	@package chamilo.admin | 
				
			||||
*	@author Carlos Vargas | 
				
			||||
*	This file is the calendar/agenda.php | 
				
			||||
*/ | 
				
			||||
// resetting the course id | 
				
			||||
$cidReset=true; | 
				
			||||
// including some necessary files | 
				
			||||
require_once '../inc/global.inc.php'; | 
				
			||||
 | 
				
			||||
$this_section = SECTION_PLATFORM_ADMIN; | 
				
			||||
$_SESSION['this_section']=$this_section; | 
				
			||||
 | 
				
			||||
// Access restrictions | 
				
			||||
api_protect_admin_script(true); | 
				
			||||
 | 
				
			||||
// setting breadcrumbs | 
				
			||||
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); | 
				
			||||
 | 
				
			||||
// setting the name of the tool | 
				
			||||
$tool_name= get_lang('SubscribeCoursesToSession'); | 
				
			||||
 | 
				
			||||
$id_session=intval($_GET['id_session']); | 
				
			||||
 | 
				
			||||
if (!api_is_platform_admin()) { | 
				
			||||
	$sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session; | 
				
			||||
	$rs = Database::query($sql); | 
				
			||||
	if(Database::result($rs,0,0)!= api_get_user_id()) { | 
				
			||||
		api_not_allowed(true); | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
 | 
				
			||||
/* | 
				
			||||
	Libraries | 
				
			||||
*/ | 
				
			||||
// containing the functions for the agenda tool | 
				
			||||
require_once 'calendar.lib.php'; | 
				
			||||
 | 
				
			||||
/* | 
				
			||||
  			TREATING THE PARAMETERS | 
				
			||||
			1. viewing month only or everything | 
				
			||||
			2. sort ascending or descending | 
				
			||||
			3. showing or hiding the send-to-specific-groups-or-users form | 
				
			||||
			4. filter user or group | 
				
			||||
 */ | 
				
			||||
// 1. show all or show current month? | 
				
			||||
if (!$_SESSION['show_all_admin']) { | 
				
			||||
	$_SESSION['show_all_admin']="showall"; | 
				
			||||
} | 
				
			||||
if (!empty($_GET['action']) and $_GET['action']=="showcurrent") | 
				
			||||
{ | 
				
			||||
	$_SESSION['show_all_admin']='showcurrent'; | 
				
			||||
} | 
				
			||||
if (!empty($_GET['action']) and $_GET['action']=="showall") | 
				
			||||
{ | 
				
			||||
	$_SESSION['show_all_admin']='showall'; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
// 2. sorting order (ASC or DESC) | 
				
			||||
if (empty($_GET['sort']) and empty($_SESSION['sort'])) | 
				
			||||
{ | 
				
			||||
	$_SESSION['sort']="DESC"; | 
				
			||||
} | 
				
			||||
if (!empty($_GET['sort']) and $_GET['sort']=="asc") | 
				
			||||
{ | 
				
			||||
	$_SESSION['sort']="ASC"; | 
				
			||||
} | 
				
			||||
if (!empty($_GET['sort']) and $_GET['sort']=="desc") | 
				
			||||
{ | 
				
			||||
	$_SESSION['sort']="DESC"; | 
				
			||||
} | 
				
			||||
if (!empty($_GET['view'])) | 
				
			||||
{ | 
				
			||||
	$_SESSION['view'] = $_GET['view']; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
// 3. showing or hiding the send-to-specific-groups-or-users form | 
				
			||||
$setting_allow_individual_calendar=true; | 
				
			||||
if (empty($_POST['To']) and empty($_SESSION['allow_individual_calendar'])) | 
				
			||||
{ | 
				
			||||
	$_SESSION['allow_individual_calendar']="hide"; | 
				
			||||
} | 
				
			||||
$allow_individual_calendar_status=$_SESSION['allow_individual_calendar']; | 
				
			||||
if (!empty($_POST['To']) and ($allow_individual_calendar_status=="hide")) | 
				
			||||
{ | 
				
			||||
	$_SESSION['allow_individual_calendar']="show"; | 
				
			||||
} | 
				
			||||
if (!empty($_GET['sort']) and ($allow_individual_calendar_status=="show")) | 
				
			||||
{ | 
				
			||||
	$_SESSION['allow_individual_calendar']="hide"; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$htmlHeadXtra[] = to_javascript(); | 
				
			||||
 | 
				
			||||
// this loads the javascript that is needed for the date popup selection | 
				
			||||
$htmlHeadXtra[] = "<script src=\"calendar_tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>"; | 
				
			||||
 | 
				
			||||
// setting the name of the tool | 
				
			||||
$nameTools = get_lang('GlobalAgenda'); // language variable in trad4all.inc.php | 
				
			||||
 | 
				
			||||
// showing the header if we are not in the learning path, if we are in | 
				
			||||
// the learning path, we do not include the banner so we have to explicitly | 
				
			||||
// include the stylesheet, which is normally done in the header | 
				
			||||
Display::display_header($nameTools,'Agenda'); | 
				
			||||
 | 
				
			||||
/* SETTING SOME VARIABLES */ | 
				
			||||
// Variable definitions | 
				
			||||
// Defining the shorts for the days. We use camelcase because these are arrays of language variables | 
				
			||||
$DaysShort = api_get_week_days_short(); | 
				
			||||
// Defining the days of the week to allow translation of the days. We use camelcase because these are arrays of language variables | 
				
			||||
$DaysLong = api_get_week_days_long(); | 
				
			||||
// Defining the months of the year to allow translation of the months. We use camelcase because these are arrays of language variables | 
				
			||||
$MonthsLong = api_get_months_long(); | 
				
			||||
 | 
				
			||||
// Database table definitions | 
				
			||||
$TABLEAGENDA 			= Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); | 
				
			||||
$tbl_user       		= Database::get_main_table(TABLE_MAIN_USER); | 
				
			||||
$tbl_courseUser 		= Database::get_main_table(TABLE_MAIN_COURSE_USER); | 
				
			||||
 | 
				
			||||
/*  | 
				
			||||
  			ACCESS RIGHTS | 
				
			||||
*/ | 
				
			||||
// permission stuff - also used by loading from global in agenda.inc.php | 
				
			||||
$is_allowed_to_edit = api_is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()); | 
				
			||||
 | 
				
			||||
// insert an anchor (top) so one can jump back to the top of the page | 
				
			||||
echo "<a name=\"top\"></a>"; | 
				
			||||
 | 
				
			||||
/* | 
				
			||||
		MAIN SECTION | 
				
			||||
*/ | 
				
			||||
 | 
				
			||||
//setting the default year and month | 
				
			||||
$select_year = ''; | 
				
			||||
$select_month = ''; | 
				
			||||
if(!empty($_GET['year'])) { | 
				
			||||
	$select_year = (int)$_GET['year']; | 
				
			||||
} | 
				
			||||
if(!empty($_GET['month'])) { | 
				
			||||
	$select_month = (int)$_GET['month']; | 
				
			||||
} | 
				
			||||
if (empty($select_year) && empty($select_month)) { | 
				
			||||
	$today = getdate(); | 
				
			||||
	$select_year = $today['year']; | 
				
			||||
	$select_month = $today['mon']; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
echo '<div class="actions">'; | 
				
			||||
if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) { | 
				
			||||
	display_student_links(); | 
				
			||||
    // Deprecated since 2014-10-31 | 
				
			||||
	//display_courseadmin_links(); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
echo '</div><br /><br />'; | 
				
			||||
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>'; | 
				
			||||
 | 
				
			||||
// THE LEFT PART | 
				
			||||
if (empty($_GET['origin']) or $_GET['origin']!='learnpath') { | 
				
			||||
	echo '<td width="220" height="19" valign="top">'; | 
				
			||||
	// the small calendar | 
				
			||||
	$MonthName = $MonthsLong[$select_month -1]; | 
				
			||||
	$agenda_items=get_calendar_items($select_month,$select_year); | 
				
			||||
	if (api_get_setting('display_mini_month_calendar') == 'true') { | 
				
			||||
		display_minimonthcalendar($agenda_items, $select_month,$select_year, $MonthName); | 
				
			||||
	} | 
				
			||||
	if (api_get_setting('display_upcoming_events') == 'true') { | 
				
			||||
		display_upcoming_events(); | 
				
			||||
	} | 
				
			||||
	echo '</td>'; | 
				
			||||
	echo '<td width="20" background="../img/verticalruler.gif"> </td>'; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
 | 
				
			||||
// THE RIGHT PART | 
				
			||||
echo '<td valign="top">'; | 
				
			||||
echo '<div class="sort" style="float:right">'; | 
				
			||||
 | 
				
			||||
echo '</div>'; | 
				
			||||
if (api_is_allowed_to_edit(false,true)) { | 
				
			||||
	switch ($_GET['action']) { | 
				
			||||
		case "add":             | 
				
			||||
            if ($_POST['submit_event']) {		         | 
				
			||||
			    $event_start    = (int) $_POST['fyear'].'-'.(int) $_POST['fmonth'].'-'.(int) $_POST['fday'].' '.(int) $_POST['fhour'].':'.(int) $_POST['fminute'].':00'; | 
				
			||||
                $event_stop     = (int) $_POST['end_fyear'].'-'.(int) $_POST['end_fmonth'].'-'.(int) $_POST['end_fday'].' '.(int) $_POST['end_fhour'].':'.(int) $_POST['end_fminute'].':00'; | 
				
			||||
                 | 
				
			||||
				$id = agenda_add_item($_POST['title'],$_POST['content'],$event_start,$event_stop);            | 
				
			||||
				display_agenda_items(); | 
				
			||||
			} else { | 
				
			||||
				show_add_form(); | 
				
			||||
			} | 
				
			||||
			break; | 
				
			||||
 | 
				
			||||
		case "edit": | 
				
			||||
			if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id']) ) ) ) | 
				
			||||
			{ // a coach can only delete an element belonging to his session | 
				
			||||
				if ($_POST['submit_event']) {		 | 
				
			||||
			        $my_id_attach = (int)$_REQUEST['id_attach']; | 
				
			||||
					$my_file_comment = Database::escape_string($_REQUEST['file_comment']); | 
				
			||||
					store_edited_agenda_item($my_id_attach,$my_file_comment); | 
				
			||||
					display_agenda_items(); | 
				
			||||
				} else { | 
				
			||||
					$id=(int)$_GET['id']; | 
				
			||||
					show_add_form($id); | 
				
			||||
				} | 
				
			||||
			} else { | 
				
			||||
				display_agenda_items(); | 
				
			||||
			} | 
				
			||||
			break; | 
				
			||||
 | 
				
			||||
		case "delete": | 
				
			||||
			$id=(int)$_GET['id']; | 
				
			||||
			if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) ) | 
				
			||||
			{ // a coach can only delete an element belonging to his session | 
				
			||||
				if (api_is_allowed_to_edit()  && !api_is_anonymous()) { | 
				
			||||
					if (!empty($id)) { | 
				
			||||
						$res_del = delete_agenda_item($id); | 
				
			||||
						if ($res_del) { | 
				
			||||
							Display::display_normal_message(get_lang("AgendaDeleteSuccess")); | 
				
			||||
						} | 
				
			||||
					} | 
				
			||||
				} | 
				
			||||
			} | 
				
			||||
			display_agenda_items(); | 
				
			||||
			break; | 
				
			||||
 | 
				
			||||
		case "showhide": | 
				
			||||
			$id=(int)$_GET['id']; | 
				
			||||
			if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) ) | 
				
			||||
			{ // a coach can only delete an element belonging to his session | 
				
			||||
				showhide_agenda_item($id); | 
				
			||||
			} | 
				
			||||
			display_agenda_items(); | 
				
			||||
			break; | 
				
			||||
		case "announce": //copying the agenda item into an announcement | 
				
			||||
			$id=(int)$_GET['id']; | 
				
			||||
			if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) ) | 
				
			||||
			{ // a coach can only delete an element belonging to his session | 
				
			||||
				$ann_id = store_agenda_item_as_announcement($id); | 
				
			||||
				$tool_group_link = (isset($_SESSION['toolgroup'])?'&toolgroup='.$_SESSION['toolgroup']:''); | 
				
			||||
				echo '<br />'; | 
				
			||||
				Display::display_normal_message(get_lang('CopiedAsAnnouncement').'<a href="../announcements/announcements.php?id='.$ann_id.$tool_group_link.'">'.get_lang('NewAnnouncement').'</a>', false); | 
				
			||||
			} | 
				
			||||
			display_agenda_items(); | 
				
			||||
			break; | 
				
			||||
		case "delete_attach": //delete attachment file | 
				
			||||
			$id_attach = (int)$_GET['id_attach']; | 
				
			||||
			if (!empty($id_attach)) { | 
				
			||||
				delete_attachment_file($id_attach); | 
				
			||||
			} | 
				
			||||
			display_agenda_items(); | 
				
			||||
			break; | 
				
			||||
 | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
 | 
				
			||||
// this is for students and whenever the courseaministrator has not chosen any action. It is in fact the default behaviour | 
				
			||||
if (!$_GET['action'] OR $_GET['action']=="showall"  OR $_GET['action']=="showcurrent" OR $_GET['action']=="view") { | 
				
			||||
	if ($_GET['origin'] != 'learnpath') { | 
				
			||||
		if (!$_SESSION['view'] OR $_SESSION['view'] <> 'month') { | 
				
			||||
            if(!empty($_GET['agenda_id'])) { | 
				
			||||
                 display_one_agenda_item((int)$_GET['agenda_id']); | 
				
			||||
            } else { | 
				
			||||
			     display_agenda_items(); | 
				
			||||
            } | 
				
			||||
		} else { | 
				
			||||
			display_monthcalendar($select_month, $select_year); | 
				
			||||
		} | 
				
			||||
	} else { | 
				
			||||
		display_one_agenda_item((int)$_GET['agenda_id']); | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
echo " </td></tr></table>"; | 
				
			||||
 | 
				
			||||
/* | 
				
			||||
		FOOTER | 
				
			||||
*/ | 
				
			||||
// The footer is displayed only if we are not in the learnpath | 
				
			||||
if ($_GET['origin'] != 'learnpath') { | 
				
			||||
	Display::display_footer(); | 
				
			||||
} | 
				
			||||
@ -1,133 +0,0 @@ | 
				
			||||
<?php // $id: $
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
/** | 
				
			||||
*	@package chamilo.admin | 
				
			||||
*	@author Carlos Vargas | 
				
			||||
*	This file is the calendar/ical_export.php | 
				
			||||
*/ | 
				
			||||
/** | 
				
			||||
 * Initialisation | 
				
			||||
 */ | 
				
			||||
// we are not inside a course, so we reset the course id | 
				
			||||
$cidReset = true; | 
				
			||||
// setting the global file that gets the general configuration, the databases, the languages, ... | 
				
			||||
require_once '../inc/global.inc.php'; | 
				
			||||
$this_section = SECTION_MYAGENDA; | 
				
			||||
api_block_anonymous_users(); | 
				
			||||
 | 
				
			||||
// setting the name of the tool | 
				
			||||
$nameTools = get_lang('MyAgenda'); | 
				
			||||
 | 
				
			||||
// the variables for the days and the months | 
				
			||||
// Defining the shorts for the days | 
				
			||||
$DaysShort = api_get_week_days_short(); | 
				
			||||
// Defining the days of the week to allow translation of the days | 
				
			||||
$DaysLong = api_get_week_days_long(); | 
				
			||||
// Defining the months of the year to allow translation of the months | 
				
			||||
$MonthsLong = api_get_months_long(); | 
				
			||||
 | 
				
			||||
if(!empty($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) | 
				
			||||
{ | 
				
			||||
	define('ICAL_LANG',api_get_language_isocode()); | 
				
			||||
	if(!empty($_GET['type'])) | 
				
			||||
	{ | 
				
			||||
		$ical = new vcalendar(); | 
				
			||||
		$ical->setConfig('unique_id',api_get_path(WEB_PATH)); | 
				
			||||
		$ical->setProperty( 'method', 'PUBLISH' ); | 
				
			||||
		$ical->setConfig('url',api_get_path(WEB_PATH)); | 
				
			||||
		$vevent = new vevent(); | 
				
			||||
		switch($_GET['class']) | 
				
			||||
		{ | 
				
			||||
			case 'public': | 
				
			||||
				$vevent->setClass('PUBLIC'); | 
				
			||||
				break; | 
				
			||||
			case 'private': | 
				
			||||
				$vevent->setClass('PRIVATE'); | 
				
			||||
				break; | 
				
			||||
			case 'confidential': | 
				
			||||
				$vevent->setClass('CONFIDENTIAL'); | 
				
			||||
				break; | 
				
			||||
			default: | 
				
			||||
				$vevent->setClass('PRIVATE'); | 
				
			||||
				break; | 
				
			||||
		} | 
				
			||||
 | 
				
			||||
		switch($_GET['type']) | 
				
			||||
		{ | 
				
			||||
			case 'personal': | 
				
			||||
				//require_once (api_get_path(SYS_CODE_PATH).'calendar/myagenda.inc.php'); | 
				
			||||
				$ai = get_personal_agenda_item($_GET['id']); | 
				
			||||
                $vevent->setProperty( 'summary', api_convert_encoding($ai['title'],'UTF-8',$charset)); | 
				
			||||
				if(empty($ai['date'])){header('location:'.$_SERVER['REFERER_URI']);} | 
				
			||||
				list($y,$m,$d,$h,$M,$s) = preg_split('/[\s:-]/',$ai['date']); | 
				
			||||
				$vevent->setProperty('dtstart',array('year'=>$y,'month'=>$m,'day'=>$d,'hour'=>$h,'min'=>$M,'sec'=>$s)); | 
				
			||||
				if(empty($ai['enddate'])) | 
				
			||||
				{ | 
				
			||||
					$y2=$y;$m2=$m;$d2=$d;$h2=$h;$M2=$M+15;$s2=$s; | 
				
			||||
					if($M2>60){$M2=$M2-60;$h2+=1;} | 
				
			||||
				} | 
				
			||||
				else | 
				
			||||
				{ | 
				
			||||
					list($y2,$m2,$d2,$h2,$M2,$s2) = preg_split('/[\s:-]/',$ai['enddate']); | 
				
			||||
				} | 
				
			||||
				$vevent->setProperty('dtend',array('year'=>$y2,'month'=>$m2,'day'=>$d2,'hour'=>$h2,'min'=>$M2,'sec'=>$s2)); | 
				
			||||
				//$vevent->setProperty( 'LOCATION', get_lang('Unknown') ); // property name - case independent | 
				
			||||
				$vevent->setProperty( 'description', api_convert_encoding($ai['text'],'UTF-8',$charset)); | 
				
			||||
				//$vevent->setProperty( 'comment', 'This is a comment' ); | 
				
			||||
				$user = api_get_user_info($ai['user']); | 
				
			||||
				$vevent->setProperty('organizer',$user['mail']); | 
				
			||||
				$vevent->setProperty('attendee',$user['mail']); | 
				
			||||
				//$vevent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// occurs also four next weeks | 
				
			||||
				$ical->setConfig('filename',$y.$m.$d.$h.$M.$s.'-'.rand(1,1000).'.ics'); | 
				
			||||
				$ical->setComponent ($vevent); // add event to calendar | 
				
			||||
				$ical->returnCalendar(); | 
				
			||||
				break; | 
				
			||||
			case 'course': | 
				
			||||
				$TABLEAGENDA 			=Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); | 
				
			||||
				require_once api_get_path(SYS_CODE_PATH).'admin/calendar.lib.php'; | 
				
			||||
				$ai = get_agenda_item($_GET['id']); | 
				
			||||
		        $vevent->setProperty( 'summary', api_convert_encoding($ai['title'],'UTF-8',$charset)); | 
				
			||||
        		if(empty($ai['start_date'])){header('location:'.$_SERVER['REFERER_URI']);} | 
				
			||||
				list($y,$m,$d,$h,$M,$s) = preg_split('/[\s:-]/',$ai['start_date']); | 
				
			||||
				$vevent->setProperty('dtstart',array('year'=>$y,'month'=>$m,'day'=>$d,'hour'=>$h,'min'=>$M,'sec'=>$s)); | 
				
			||||
				if(empty($ai['end_date'])) | 
				
			||||
				{ | 
				
			||||
					$y2=$y;$m2=$m;$d2=$d;$h2=$h;$M2=$M+15;$s2=$s; | 
				
			||||
					if($M2>60){$M2=$M2-60;$h2+=1;} | 
				
			||||
				} | 
				
			||||
				else | 
				
			||||
				{ | 
				
			||||
					list($y2,$m2,$d2,$h2,$M2,$s2) = preg_split('/[\s:-]/',$ai['end_date']); | 
				
			||||
				} | 
				
			||||
				$vevent->setProperty('dtend',array('year'=>$y2,'month'=>$m2,'day'=>$d2,'hour'=>$h2,'min'=>$M2,'sec'=>$s2)); | 
				
			||||
				$vevent->setProperty( 'description', api_convert_encoding($ai['content'],'UTF-8',$charset)); | 
				
			||||
				//$vevent->setProperty( 'comment', 'This is a comment' ); | 
				
			||||
				$user = api_get_user_info($ai['user']); | 
				
			||||
				$vevent->setProperty('organizer',$user['mail']); | 
				
			||||
				//$vevent->setProperty('attendee',$user['mail']); | 
				
			||||
				$course = api_get_course_info(); | 
				
			||||
				$vevent->setProperty('location', $course['name']); // property name - case independent | 
				
			||||
                if($ai['repeat']) | 
				
			||||
                { | 
				
			||||
                	$trans = array('daily'=>'DAILY','weekly'=>'WEEKLY','monthlyByDate'=>'MONTHLY','yearly'=>'YEARLY'); | 
				
			||||
                    $freq = $trans[$ai['repeat_type']]; | 
				
			||||
                    list($e_y,$e_m,$e_d) = split('/',date('Y/m/d',$ai['repeat_end'])); | 
				
			||||
                	$vevent->setProperty('rrule',array('FREQ'=>$freq,'UNTIL'=>array('year'=>$e_y,'month'=>$e_m,'day'=>$e_d),'INTERVAL'=>'1')); | 
				
			||||
                } | 
				
			||||
				//$vevent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// occurs also four next weeks | 
				
			||||
				$ical->setConfig('filename',$y.$m.$d.$h.$M.$s.'-'.rand(1,1000).'.ics'); | 
				
			||||
				$ical->setComponent ($vevent); // add event to calendar | 
				
			||||
				$ical->returnCalendar(); | 
				
			||||
				break; | 
				
			||||
			default: | 
				
			||||
				header('location:'.$_SERVER['REFERER_URI']); | 
				
			||||
				die(); | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
else | 
				
			||||
{ | 
				
			||||
	header('location:'.$_SERVER['REFERER_URI']); | 
				
			||||
	die(); | 
				
			||||
} | 
				
			||||
?> | 
				
			||||
									
										
											File diff suppressed because it is too large
											Load Diff
										
									
								
							
						@ -1,379 +0,0 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * | 
				
			||||
 * Get the all events by session/course | 
				
			||||
 * @author Julio Montoya cleaning code, chamilo code style changes, | 
				
			||||
 * all agenda feature work with courses and sessions, | 
				
			||||
 * only admins and rrhh users can see this page | 
				
			||||
 * @author Carlos Brolo First code submittion | 
				
			||||
 */ | 
				
			||||
 | 
				
			||||
// we are not inside a course, so we reset the course id | 
				
			||||
$cidReset = true; | 
				
			||||
// setting the global file that gets the general configuration, the databases, the languages, ... | 
				
			||||
require_once '../inc/global.inc.php'; | 
				
			||||
$this_section = SECTION_MYAGENDA; | 
				
			||||
 | 
				
			||||
require_once 'agenda.inc.php'; | 
				
			||||
require_once 'myagenda.inc.php'; | 
				
			||||
 | 
				
			||||
//This code is not yet stable | 
				
			||||
//Blocking the access | 
				
			||||
api_not_allowed(); | 
				
			||||
 | 
				
			||||
api_block_anonymous_users(); | 
				
			||||
 | 
				
			||||
// setting the name of the tool | 
				
			||||
$nameTools = get_lang('MyAgenda'); | 
				
			||||
 | 
				
			||||
$is_platform_admin = api_is_platform_admin(); | 
				
			||||
 | 
				
			||||
$is_drh = api_is_drh(); | 
				
			||||
if (!($is_platform_admin || $is_drh)) { | 
				
			||||
	api_not_allowed(); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
// if we come from inside a course and click on the 'My Agenda' link we show a link back to the course | 
				
			||||
// in the breadcrumbs | 
				
			||||
//remove this if cause it was showing in agenda general | 
				
			||||
/*if(!empty($_GET['coursePath'])) { | 
				
			||||
	$course_path = api_htmlentities(strip_tags($_GET['coursePath']),ENT_QUOTES,$charset); | 
				
			||||
	$course_path = str_replace(array('../','..\\'),array('',''),$course_path); | 
				
			||||
} | 
				
			||||
*/ | 
				
			||||
if (!empty ($course_path)) { | 
				
			||||
	$interbreadcrumb[] = array ('url' => api_get_path(WEB_COURSE_PATH).urlencode($course_path).'/index.php', 'name' => Security::remove_XSS($_GET['courseCode'])); | 
				
			||||
} | 
				
			||||
// this loads the javascript that is needed for the date popup selection | 
				
			||||
//$htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>"; | 
				
			||||
 | 
				
			||||
// showing the header | 
				
			||||
Display::display_header(get_lang('MyAgenda')); | 
				
			||||
 | 
				
			||||
function display_mymonthcalendar_2($agendaitems, $month, $year, $weekdaynames=array(), $monthName, $session_id) { | 
				
			||||
	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)) | 
				
			||||
		$numberofdays[2] = 29; | 
				
			||||
	//Get the first day of the month | 
				
			||||
	$dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); | 
				
			||||
	//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)."&session=".Security::remove_XSS($session_id)."&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)."&session=".Security::remove_XSS($session_id)."&courseCode=".Security::remove_XSS($g_cc)."&action=view&view=month&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year); | 
				
			||||
 | 
				
			||||
	echo "<table class=\"data_table\">\n", "<tr>\n", "<th width=\"10%\"><a href=\"", $backwardsURL, "\">«</a></th>\n", "<th width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>\n", "<th width=\"10%\"><a href=\"", $forewardsURL, "\">»</a></th>\n", "</tr>\n"; | 
				
			||||
 | 
				
			||||
	echo "<tr>\n"; | 
				
			||||
	for ($ii = 1; $ii < 8; $ii ++) | 
				
			||||
	{ | 
				
			||||
		echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>\n"; | 
				
			||||
	} | 
				
			||||
	echo "</tr>\n"; | 
				
			||||
	$curday = -1; | 
				
			||||
	$today = getdate(); | 
				
			||||
	while ($curday <= $numberofdays[$month]) { | 
				
			||||
		echo "<tr>\n"; | 
				
			||||
		for ($ii = 0; $ii < 7; $ii ++) { | 
				
			||||
			if (($curday == -1) && ($ii == $startdayofweek)) { | 
				
			||||
				$curday = 1; | 
				
			||||
			} | 
				
			||||
			if (($curday > 0) && ($curday <= $numberofdays[$month])) { | 
				
			||||
				$bgcolor = $ii < 5 ? $class = "class=\"days_week\" style=\"width:10%;\"" : $class = "class=\"days_weekend\" style=\"width:10%;\""; | 
				
			||||
				$dayheader = "<b>$curday</b><br />"; | 
				
			||||
				if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) { | 
				
			||||
					$dayheader = "<b>$curday - ".get_lang("Today")."</b><br />"; | 
				
			||||
					$class = "class=\"days_today\" style=\"width:10%;\""; | 
				
			||||
				} | 
				
			||||
				echo "<td ".$class.">", "".$dayheader; | 
				
			||||
				if (!empty($agendaitems[$curday])) { | 
				
			||||
					echo "<span class=\"agendaitem\">".$agendaitems[$curday]."</span>"; | 
				
			||||
				} | 
				
			||||
				echo "</td>\n"; | 
				
			||||
				$curday ++; | 
				
			||||
			} else { | 
				
			||||
				echo "<td> </td>\n"; | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
		echo "</tr>\n"; | 
				
			||||
	} | 
				
			||||
	echo "</table>\n"; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
function get_agenda_items_by_course_list($course_list, $month, $year, $session_id = 0) { | 
				
			||||
	global $setting_agenda_link; | 
				
			||||
	//echo $sql  = 'SELECT name FROM chamilo_main.class WHERE name = "'.$grado.'" ORDER BY name ASC'; | 
				
			||||
	//$result = Database::query($sql); | 
				
			||||
	//while ($row = Database::fetch_array($result, 'ASSOC')) { | 
				
			||||
 | 
				
			||||
	$agendaitems = array (); | 
				
			||||
	$course_name_list = array(); | 
				
			||||
	foreach ($course_list as $course) { | 
				
			||||
 | 
				
			||||
		$db_name		= $course['db_name']; | 
				
			||||
		$code			= $course['code']; | 
				
			||||
		$title			= $course['title']; | 
				
			||||
		$course_name_list[] = $title; | 
				
			||||
		//$sql2  = 'SELECT code, db_name, title FROM chamilo_main.course WHERE category_code = "'.$course_name.'" '; | 
				
			||||
//		$courses_dbs = Database::query($sql2); | 
				
			||||
 | 
				
			||||
		$items = array (); | 
				
			||||
		// $courses_dbs = array(); | 
				
			||||
		// get agenda-items for every course | 
				
			||||
		//while($row2 = Database::fetch_array($courses_dbs, 'ASSOC')) { | 
				
			||||
		//$db_name 	= $row2['db_name']; | 
				
			||||
		//$code 		= $row2['code']; | 
				
			||||
		//$title 		= $row2['title']; | 
				
			||||
		//echo "<center><h2>".$db_name."</h2></center>"; | 
				
			||||
 | 
				
			||||
		//databases of the courses | 
				
			||||
		$TABLEAGENDA 		= Database :: get_course_table(TABLE_AGENDA, $db_name); | 
				
			||||
		$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $db_name); | 
				
			||||
 | 
				
			||||
		//$group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); | 
				
			||||
		// if the user is administrator of that course we show all the agenda items | 
				
			||||
		$session_condition = ''; | 
				
			||||
		if ($session_id != 0) { | 
				
			||||
			$session_id = intval($session_id); | 
				
			||||
			$session_condition = "AND session_id = $session_id"; | 
				
			||||
		} | 
				
			||||
 | 
				
			||||
		$sqlquery = "SELECT	DISTINCT agenda.*, item_property.* | 
				
			||||
						FROM ".$TABLEAGENDA." agenda, | 
				
			||||
							 ".$TABLE_ITEMPROPERTY." item_property | 
				
			||||
						WHERE agenda.id = item_property.ref | 
				
			||||
						AND MONTH(agenda.start_date)='".$month."' | 
				
			||||
						AND YEAR(agenda.start_date)='".$year."' | 
				
			||||
						AND item_property.tool='".TOOL_CALENDAR_EVENT."' | 
				
			||||
						AND item_property.visibility='1' $session_condition | 
				
			||||
						GROUP BY agenda.id | 
				
			||||
						ORDER BY start_date "; | 
				
			||||
		$result = Database::query($sqlquery); | 
				
			||||
		while ($item = Database::fetch_array($result,'ASSOC')) { | 
				
			||||
			//taking the day | 
				
			||||
			$agendaday = date("j",strtotime($item['start_date'])); | 
				
			||||
			if(!isset($items[$agendaday])){$items[$agendaday]=array();} | 
				
			||||
			//taking the time | 
				
			||||
			$time = date("H:i",strtotime($item['start_date'])); | 
				
			||||
			$end_time= date("H:i",strtotime($item['end_date'])); | 
				
			||||
			$URL = api_get_path(WEB_PATH)."main/calendar/allagendas.php?cidReq=".urlencode($code)."&sort=asc&view=list&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); | 
				
			||||
			} 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']] .= "".get_lang('StartTimeWindow')." <i>".$time."</i>"." - ".get_lang("EndTimeWindow")." <i>".$end_time."</i> "; | 
				
			||||
			$items[$agendaday][$item['start_date']] .= '<br />'."<b><a href=\"$URL\" title=\"".Security::remove_XSS($title)."\">".$agenda_link."</a> </b> ".Security::remove_XSS($item['title'])."<br /> "; | 
				
			||||
			$items[$agendaday][$item['start_date']] .= '<br/>'; | 
				
			||||
		} | 
				
			||||
 | 
				
			||||
		if (is_array($items) && count($items) > 0) { | 
				
			||||
			while (list ($agendaday, $tmpitems) = each($items)) { | 
				
			||||
				if(!isset($agendaitems[$agendaday])) { | 
				
			||||
					$agendaitems[$agendaday] = ''; | 
				
			||||
				} | 
				
			||||
				sort($tmpitems); | 
				
			||||
				while (list ($key, $val) = each($tmpitems)) { | 
				
			||||
					$agendaitems[$agendaday] .= $val; | 
				
			||||
				} | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	echo "<h1>Courses:</h1> <h3>".implode(', ',$course_name_list)."</h3>"; | 
				
			||||
	return $agendaitems; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
/* 		SETTING SOME VARIABLES		*/ | 
				
			||||
 | 
				
			||||
// the variables for the days and the months | 
				
			||||
// Defining the shorts for the days | 
				
			||||
$DaysShort = api_get_week_days_short(); | 
				
			||||
// Defining the days of the week to allow translation of the days | 
				
			||||
$DaysLong = api_get_week_days_long(); | 
				
			||||
// Defining the months of the year to allow translation of the months | 
				
			||||
$MonthsLong = api_get_months_long(); | 
				
			||||
 | 
				
			||||
/* | 
				
			||||
  			TREATING THE URL PARAMETERS | 
				
			||||
			1. The default values | 
				
			||||
			2. storing it in the session | 
				
			||||
			3. possible view | 
				
			||||
				3.a Month view | 
				
			||||
				3.b Week view | 
				
			||||
				3.c day view | 
				
			||||
				3.d personal view (only the personal agenda items) | 
				
			||||
*/ | 
				
			||||
// 1. The default values. if there is no session yet, we have by default the month view | 
				
			||||
if (empty($_SESSION['view'])) { | 
				
			||||
	$_SESSION['view'] = 'month'; | 
				
			||||
} | 
				
			||||
// 2. Storing it in the session. If we change the view by clicking on the links left, we change the session | 
				
			||||
if (!empty($_GET['view'])) { | 
				
			||||
	$_SESSION['view'] = Security::remove_XSS($_GET['view']); | 
				
			||||
 | 
				
			||||
} | 
				
			||||
// 3. The views: (month, week, day, personal) | 
				
			||||
if ($_SESSION['view']) { | 
				
			||||
	switch ($_SESSION['view'])	{ | 
				
			||||
		// 3.a Month view | 
				
			||||
		case "month" : | 
				
			||||
			$process = "month_view"; | 
				
			||||
			break; | 
				
			||||
			// 3.a Week view | 
				
			||||
		case "week" : | 
				
			||||
			$process = "week_view"; | 
				
			||||
			break; | 
				
			||||
			// 3.a Day view | 
				
			||||
		case "day" : | 
				
			||||
			$process = "day_view"; | 
				
			||||
			break; | 
				
			||||
			// 3.a Personal view | 
				
			||||
		case "personal" : | 
				
			||||
			$process = "personal_view"; | 
				
			||||
			break; | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$my_course_id  = intval($_GET['course']); | 
				
			||||
$my_session_id = intval($_GET['session']); | 
				
			||||
 | 
				
			||||
$my_course_list = array(); | 
				
			||||
 | 
				
			||||
if(!empty($my_session_id)) { | 
				
			||||
	$_SESSION['my_course_list'] = array(); | 
				
			||||
	$my_course_list = array(); | 
				
			||||
} else { | 
				
			||||
	$my_course_list = $_SESSION['my_course_list']; | 
				
			||||
	$my_course_list_keys = array_keys($my_course_list); | 
				
			||||
	if (!in_array($my_course_id, $my_course_list_keys)) { | 
				
			||||
		$course_info = api_get_course_info_by_id($my_course_id); | 
				
			||||
		$_SESSION['my_course_list'][$my_course_id] = $course_info; | 
				
			||||
		$my_course_list = $_SESSION['my_course_list']; | 
				
			||||
		//echo $my_course_id.'added '; | 
				
			||||
	} | 
				
			||||
 | 
				
			||||
	if (isset($_GET['delete_course_option'])) { | 
				
			||||
		$course_id_to_delete = intval($_GET['delete_course_option']); | 
				
			||||
		unset($_SESSION['my_course_list'][$course_id_to_delete]); | 
				
			||||
		$my_course_list = $_SESSION['my_course_list']; | 
				
			||||
	} | 
				
			||||
	//clean the array | 
				
			||||
	$my_course_list = array_filter($my_course_list); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
/* 	OUTPUT	*/ | 
				
			||||
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)) { | 
				
			||||
		// this is for the special case if the user has no courses (otherwise you get an error) | 
				
			||||
		$courses_dbs = array (); | 
				
			||||
	} | 
				
			||||
	// setting and/or getting the year, month, day, week | 
				
			||||
	$today = getdate(); | 
				
			||||
	$year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL); | 
				
			||||
	if ($year == NULL) | 
				
			||||
	{ | 
				
			||||
		$year = $today['year']; | 
				
			||||
	} | 
				
			||||
	$month = (!empty($_GET['month'])? (int)$_GET['month']:NULL); | 
				
			||||
	if ($month == NULL) | 
				
			||||
	{ | 
				
			||||
		$month = $today['mon']; | 
				
			||||
	} | 
				
			||||
	$day = (!empty($_GET['day']) ? (int)$_GET['day']:NULL); | 
				
			||||
	if ($day == NULL) | 
				
			||||
	{ | 
				
			||||
		$day = $today['mday']; | 
				
			||||
	} | 
				
			||||
	$week = (!empty($_GET['week']) ?(int)$_GET['week']:NULL); | 
				
			||||
	if ($week == NULL) | 
				
			||||
	{ | 
				
			||||
		$week = date("W"); | 
				
			||||
	} | 
				
			||||
	// The name of the current Month | 
				
			||||
	$monthName = $MonthsLong[$month -1]; | 
				
			||||
 | 
				
			||||
	if (api_is_platform_admin()) { | 
				
			||||
		$courses  = array(); | 
				
			||||
		$sessions = SessionManager::get_sessions_list(); | 
				
			||||
 | 
				
			||||
	} elseif(api_is_drh()) { | 
				
			||||
		$courses  = CourseManager::get_courses_followed_by_drh(api_get_user_id()); | 
				
			||||
		$sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id()); | 
				
			||||
	} | 
				
			||||
 | 
				
			||||
	echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">'; | 
				
			||||
	echo '<tr>'; | 
				
			||||
 | 
				
			||||
	// output: the small calendar item on the left and the view / add links | 
				
			||||
	echo '<td width="220" valign="top">'; | 
				
			||||
 | 
				
			||||
		echo '<br />'; | 
				
			||||
		if (count($courses) > 0) { | 
				
			||||
			echo '<h1>'.get_lang('SelectACourse').'</h1>'; | 
				
			||||
 | 
				
			||||
			foreach ($courses as $row_course) { | 
				
			||||
				$course_code = $row_course['id']; | 
				
			||||
				$title = $row_course['title']; | 
				
			||||
				$my_course_list_keys = array_keys($my_course_list); | 
				
			||||
				if (!in_array($course_code, $my_course_list_keys)) { | 
				
			||||
					echo '<a href="allagendas.php?course='.$course_code.'">'.$title.'</a><br />'; | 
				
			||||
				} else { | 
				
			||||
					echo ''.$title.' <a href="allagendas.php?delete_course_option='.$course_code.'">Delete</a><br />'; | 
				
			||||
				} | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
		if (count($sessions) > 0) { | 
				
			||||
			echo '<h1>'.get_lang('SelectASession').'</h1>'; | 
				
			||||
			foreach ($sessions as $session) { | 
				
			||||
				$id = $session['id']; | 
				
			||||
				$name = $session['name']; | 
				
			||||
				echo '<a href="allagendas.php?session='.$id.'">'.$name.'</a><br />'; | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
	echo '</td>'; | 
				
			||||
 | 
				
			||||
	// the divider | 
				
			||||
	// OlivierB : the image has a white background, which causes trouble if the portal has another background color. Image should be transparent. ----> echo "<td width=\"20\" background=\"../img/verticalruler.gif\"> </td>"; | 
				
			||||
	echo "<td width=\"20\"> </td>"; | 
				
			||||
	// the main area: day, week, month view | 
				
			||||
	echo '<td valign="top">'; | 
				
			||||
 | 
				
			||||
	//@todo hardcoding option | 
				
			||||
	$process = 'month_view'; | 
				
			||||
 | 
				
			||||
	switch ($process) { | 
				
			||||
		case "month_view" : | 
				
			||||
			$session_id = 0; | 
				
			||||
			//By courses | 
				
			||||
			if (is_array($my_course_list) && count($my_course_list) > 0) { | 
				
			||||
				$course_list = $my_course_list; | 
				
			||||
			} else { | 
				
			||||
				//session | 
				
			||||
				$course_list = SessionManager::get_course_list_by_session_id($my_session_id); | 
				
			||||
				$session_id = $my_session_id; | 
				
			||||
				echo '<h1>'.$sessions[$session_id]['name'].'</h1>'; | 
				
			||||
			} | 
				
			||||
			if (is_array($course_list) && count($course_list) > 0) { | 
				
			||||
 | 
				
			||||
				$agendaitems = get_agenda_items_by_course_list($course_list, $month, $year, $session_id); | 
				
			||||
				//$agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view"); | 
				
			||||
				display_mymonthcalendar_2($agendaitems, $month, $year, array(), $monthName, $session_id); | 
				
			||||
			} else { | 
				
			||||
				Display::display_warning_message(get_lang('PleaseSelectACourseOrASessionInTheLeftColumn')); | 
				
			||||
			} | 
				
			||||
			break; | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
echo "</td></tr></table>"; | 
				
			||||
Display :: display_footer(); | 
				
			||||
@ -1,789 +0,0 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
/** | 
				
			||||
    @author: Julio Montoya <gugli100@gmail.com> BeezNest 2011 Bugfixes | 
				
			||||
 | 
				
			||||
    //Original code found in Dok€os | 
				
			||||
	@author: Patrick Cool <patrick.cool@UGent.be>, Ghent University | 
				
			||||
	@author: Toon Van Hoecke <toon.vanhoecke@ugent.be>, Ghent University | 
				
			||||
	@author: Eric Remy (initial version) | 
				
			||||
 | 
				
			||||
	@todo create a class and merge with the agenda.inc.php | 
				
			||||
*/ | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Settings (you may alter this at will | 
				
			||||
 */ | 
				
			||||
$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($user_id, $courses_dbs, $month, $year) { | 
				
			||||
	global $setting_agenda_link; | 
				
			||||
	$user_id = intval($user_id); | 
				
			||||
 | 
				
			||||
	$items = array(); | 
				
			||||
	$my_list = 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); | 
				
			||||
		$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); | 
				
			||||
 | 
				
			||||
		$group_memberships = GroupManager :: get_group_ids($array_course_info["real_id"], $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"; | 
				
			||||
			$sqlquery = "SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref | 
				
			||||
							FROM ".$TABLEAGENDA." agenda, | 
				
			||||
								 ".$TABLE_ITEMPROPERTY." ip | 
				
			||||
							WHERE agenda.id = ip.ref | 
				
			||||
							AND MONTH(agenda.start_date)='".$month."' | 
				
			||||
							AND YEAR(agenda.start_date)='".$year."' | 
				
			||||
							AND ip.tool='".TOOL_CALENDAR_EVENT."' | 
				
			||||
							AND ip.visibility='1' | 
				
			||||
							GROUP BY agenda.id | 
				
			||||
							ORDER BY start_date "; | 
				
			||||
		} else { | 
				
			||||
			// if the user is not an administrator of that course | 
				
			||||
			if (is_array($group_memberships) && count($group_memberships)>0) { | 
				
			||||
				$sqlquery = "SELECT	agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref | 
				
			||||
								FROM ".$TABLEAGENDA." agenda, | 
				
			||||
									".$TABLE_ITEMPROPERTY." ip | 
				
			||||
								WHERE agenda.id = ip.ref | 
				
			||||
								AND MONTH(agenda.start_date)='".$month."' | 
				
			||||
								AND YEAR(agenda.start_date)='".$year."' | 
				
			||||
								AND ip.tool='".TOOL_CALENDAR_EVENT."' | 
				
			||||
								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 { | 
				
			||||
				$sqlquery = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref | 
				
			||||
								FROM ".$TABLEAGENDA." agenda, | 
				
			||||
									".$TABLE_ITEMPROPERTY." ip | 
				
			||||
								WHERE agenda.id = ip.ref | 
				
			||||
								AND MONTH(agenda.start_date)='".$month."' | 
				
			||||
								AND YEAR(agenda.start_date)='".$year."' | 
				
			||||
								AND ip.tool='".TOOL_CALENDAR_EVENT."' | 
				
			||||
								AND ( ip.to_user_id='".$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, 'ASSOC')) { | 
				
			||||
			$agendaday = -1; | 
				
			||||
			if ($item['start_date'] != '0000-00-00 00:00:00') { | 
				
			||||
				$item['start_date'] = api_get_local_time($item['start_date']); | 
				
			||||
				$item['start_date_tms']  = api_strtotime($item['start_date']); | 
				
			||||
				$agendaday = date("j", $item['start_date_tms']); | 
				
			||||
			} | 
				
			||||
			if ($item['end_date'] != '0000-00-00 00:00:00') { | 
				
			||||
				$item['end_date'] = api_get_local_time($item['end_date']); | 
				
			||||
			} | 
				
			||||
 | 
				
			||||
			$url  = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; | 
				
			||||
 | 
				
			||||
			$item['url'] = $url; | 
				
			||||
			$item['course_name'] = $array_course_info['title']; | 
				
			||||
			$item['calendar_type'] = 'course'; | 
				
			||||
			$item['course_id'] = $array_course_info['course_id']; | 
				
			||||
 | 
				
			||||
			$my_list[$agendaday][] = $item; | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
 | 
				
			||||
	// sorting by hour for every day | 
				
			||||
	$agendaitems = array (); | 
				
			||||
	while (list ($agendaday, $tmpitems) = each($items)) { | 
				
			||||
		if(!isset($agendaitems[$agendaday])) { | 
				
			||||
			$agendaitems[$agendaday] = ''; | 
				
			||||
		} | 
				
			||||
		sort($tmpitems); | 
				
			||||
		while (list ($key, $val) = each($tmpitems)) { | 
				
			||||
			$agendaitems[$agendaday] .= $val; | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	return $my_list; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Show the monthcalender of the given month | 
				
			||||
 * @param	array	Agendaitems | 
				
			||||
 * @param	int	Month number | 
				
			||||
 * @param	int	Year number | 
				
			||||
 * @param	array	Array of strings containing long week day names (deprecated, you can send an empty array instead) | 
				
			||||
 * @param	string	The month name | 
				
			||||
 * @return	void	Direct output | 
				
			||||
 */ | 
				
			||||
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)) | 
				
			||||
		$numberofdays[2] = 29; | 
				
			||||
	//Get the first day of the month | 
				
			||||
	$dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); | 
				
			||||
	//Start the week on monday | 
				
			||||
	$startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6; | 
				
			||||
	$g_cc = (isset($_GET['courseCode'])?$_GET['courseCode']:''); | 
				
			||||
 | 
				
			||||
	$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)."&courseCode=".Security::remove_XSS($g_cc)."&action=view&view=month&month=".$next_month."&year=".$next_year); | 
				
			||||
	    $next_url = Display::url($next_icon, api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($g_cc)."&action=view&view=month&month=".$prev_month."&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%">'.$back_url.'</th>'; | 
				
			||||
	echo '<th width="80%" colspan="5"><br /><h3>'.$monthName." ".$year.'</h3></th>'; | 
				
			||||
	echo '<th width="10%">'.$next_url.'</th>'; | 
				
			||||
 | 
				
			||||
	echo '</tr>'; | 
				
			||||
 | 
				
			||||
	echo '<tr>'; | 
				
			||||
	for ($ii = 1; $ii < 8; $ii ++) { | 
				
			||||
		echo '<td class="weekdays">'.$DaysShort[$ii % 7].'</td>'; | 
				
			||||
	} | 
				
			||||
	echo '</tr>'; | 
				
			||||
 | 
				
			||||
	$curday = -1; | 
				
			||||
	$today = getdate(); | 
				
			||||
	while ($curday <= $numberofdays[$month]) { | 
				
			||||
		echo "<tr>"; | 
				
			||||
		for ($ii = 0; $ii < 7; $ii ++) { | 
				
			||||
			if (($curday == -1) && ($ii == $startdayofweek)) { | 
				
			||||
				$curday = 1; | 
				
			||||
			} | 
				
			||||
			if (($curday > 0) && ($curday <= $numberofdays[$month])) { | 
				
			||||
				$bgcolor = $class = 'class="days_week"'; | 
				
			||||
				$dayheader = Display::div($curday, array('class'=>'agenda_day')); | 
				
			||||
				if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) { | 
				
			||||
					$class = "class=\"days_today\" style=\"width:10%;\""; | 
				
			||||
				} | 
				
			||||
 | 
				
			||||
				echo "<td ".$class.">".$dayheader; | 
				
			||||
 | 
				
			||||
				if (!empty($agendaitems[$curday])) { | 
				
			||||
				   $items =  $agendaitems[$curday]; | 
				
			||||
				   $items =  msort($items, 'start_date_tms'); | 
				
			||||
 | 
				
			||||
				   foreach($items  as $value) { | 
				
			||||
				        $value['title'] = Security::remove_XSS($value['title']); | 
				
			||||
                        $start_time = api_format_date($value['start_date'], TIME_NO_SEC_FORMAT); | 
				
			||||
                        $end_time = ''; | 
				
			||||
 | 
				
			||||
                        if (!empty($value['end_date']) && $value['end_date'] != '0000-00-00 00:00:00') { | 
				
			||||
                           $end_time    = '- <i>'.api_format_date($value['end_date'], DATE_TIME_FORMAT_LONG).'</i>'; | 
				
			||||
                        } | 
				
			||||
                        $complete_time = '<i>'.api_format_date($value['start_date'], DATE_TIME_FORMAT_LONG).'</i> '.$end_time; | 
				
			||||
                        $time = '<i>'.$start_time.'</i>'; | 
				
			||||
 | 
				
			||||
				        switch($value['calendar_type']) { | 
				
			||||
                            case 'personal': | 
				
			||||
                                $bg_color = '#D0E7F4'; | 
				
			||||
                                $icon = Display::return_icon('user.png', get_lang('MyAgenda'), array(), ICON_SIZE_SMALL); | 
				
			||||
                                break; | 
				
			||||
                            case 'global': | 
				
			||||
                                $bg_color = '#FFBC89'; | 
				
			||||
                                $icon = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), ICON_SIZE_SMALL); | 
				
			||||
                                break; | 
				
			||||
                            case 'course': | 
				
			||||
                                $bg_color = '#CAFFAA'; | 
				
			||||
                                $icon_name = 'course.png'; | 
				
			||||
                                if (!empty($value['session_id'])) { | 
				
			||||
                                	$icon_name = 'session.png'; | 
				
			||||
                                } | 
				
			||||
                                if ($show_content) { | 
				
			||||
                                    $icon = Display::url(Display::return_icon($icon_name, $value['course_name'].' '.get_lang('Course'), array(), ICON_SIZE_SMALL), $value['url']); | 
				
			||||
                                } else { | 
				
			||||
                                    $icon = Display::return_icon($icon_name, $value['course_name'].' '.get_lang('Course'), array(), ICON_SIZE_SMALL); | 
				
			||||
                                } | 
				
			||||
                                break; | 
				
			||||
                            default: | 
				
			||||
                                break; | 
				
			||||
                        } | 
				
			||||
 | 
				
			||||
                        $result = '<div class="rounded_div_agenda" style="background-color:'.$bg_color.';">'; | 
				
			||||
 | 
				
			||||
                        if ($show_content) { | 
				
			||||
 | 
				
			||||
                            //Setting a personal event to green | 
				
			||||
                            $icon = Display::div($icon, array('style'=>'float:right')); | 
				
			||||
 | 
				
			||||
                            $link = $value['calendar_type'].'_'.$value['id'].'_'.$value['course_id'].'_'.$value['session_id']; | 
				
			||||
 | 
				
			||||
                            //Link to bubble | 
				
			||||
                            $url = Display::url(cut($value['title'], 40), '#', array('id'=>$link, 'class'=>'opener')); | 
				
			||||
                            $result .= $time.' '.$icon.' '.Display::div($url); | 
				
			||||
 | 
				
			||||
                            //Hidden content | 
				
			||||
                            $content = Display::div($icon.Display::tag('h2', $value['course_name']).'<hr />'.Display::tag('h3', $value['title']).$complete_time.'<hr />'.Security::remove_XSS($value['content'])); | 
				
			||||
 | 
				
			||||
                            //Main div | 
				
			||||
                            $result .= Display::div($content, array('id'=>'main_'.$link, 'class' => 'dialog', 'style' => 'display:none')); | 
				
			||||
                            $result .= '</div>'; | 
				
			||||
                            echo $result; | 
				
			||||
                            //echo Display::div($content, array('id'=>'main_'.$value['calendar_type'].'_'.$value['id'], 'class' => 'dialog')); | 
				
			||||
                        } else { | 
				
			||||
                            echo $result .= $icon.'</div>'; | 
				
			||||
                        } | 
				
			||||
				   } | 
				
			||||
				} | 
				
			||||
				echo "</td>"; | 
				
			||||
				$curday ++; | 
				
			||||
			} else { | 
				
			||||
				echo "<td></td>"; | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
		echo "</tr>"; | 
				
			||||
	} | 
				
			||||
	echo "</table>"; | 
				
			||||
} | 
				
			||||
/** | 
				
			||||
 * Show the mini calender of the given month | 
				
			||||
 */ | 
				
			||||
function display_myminimonthcalendar($agendaitems, $month, $year, $monthName) { | 
				
			||||
	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)) | 
				
			||||
		$numberofdays[2] = 29; | 
				
			||||
	//Get the first day of the month | 
				
			||||
	$dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); | 
				
			||||
	//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=".Security::remove_XSS($course_path)."&courseCode=".Security::remove_XSS($g_cc)."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year); | 
				
			||||
	$forewardsURL = api_get_self()."?coursePath=".Security::remove_XSS($course_path)."&courseCode=".Security::remove_XSS($g_cc)."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year); | 
				
			||||
 | 
				
			||||
	echo "<table class=\"data_table\">", "<tr>", "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png',get_lang('Previous'))."</a></th>"; | 
				
			||||
	echo "<th width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>", "<th width=\"10%\"><a href=\"", $forewardsURL, "\">".Display::return_icon('action_next.png',get_lang('Next'))."</a></th>", "</tr>"; | 
				
			||||
 | 
				
			||||
	echo "<tr>"; | 
				
			||||
	for ($ii = 1; $ii < 8; $ii ++) | 
				
			||||
	{ | 
				
			||||
		echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>"; | 
				
			||||
	} | 
				
			||||
	echo "</tr>"; | 
				
			||||
	$curday = -1; | 
				
			||||
	$today = getdate(); | 
				
			||||
	while ($curday <= $numberofdays[$month]) | 
				
			||||
	{ | 
				
			||||
		echo "<tr>"; | 
				
			||||
		for ($ii = 0; $ii < 7; $ii ++) { | 
				
			||||
			if (($curday == -1) && ($ii == $startdayofweek)) | 
				
			||||
			{ | 
				
			||||
				$curday = 1; | 
				
			||||
			} | 
				
			||||
			if (($curday > 0) && ($curday <= $numberofdays[$month])) { | 
				
			||||
				$bgcolor = $ii < 5 ? $class = 'class="days_week"' : $class = 'class="days_weekend"'; | 
				
			||||
				$dayheader = "$curday"; | 
				
			||||
				if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) { | 
				
			||||
					$dayheader = "$curday"; | 
				
			||||
					$class = "class=\"days_today\""; | 
				
			||||
				} | 
				
			||||
				echo "<td ".$class.">"; | 
				
			||||
				if (!empty($agendaitems[$curday])) { | 
				
			||||
					echo "<a href=\"".api_get_self()."?action=view&view=day&day=".$curday."&month=".$month."&year=".$year."\">".$dayheader."</a>"; | 
				
			||||
				} else { | 
				
			||||
					echo $dayheader; | 
				
			||||
				} | 
				
			||||
				// "a".$dayheader." <span class=\"agendaitem\">".$agendaitems[$curday]."</span>"; | 
				
			||||
				echo "</td>"; | 
				
			||||
				$curday ++; | 
				
			||||
			} | 
				
			||||
			else | 
				
			||||
			{ | 
				
			||||
				echo "<td> </td>"; | 
				
			||||
			} | 
				
			||||
		} | 
				
			||||
		echo "</tr>"; | 
				
			||||
	} | 
				
			||||
	echo "</table>"; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * This function shows all the forms that are needed form adding/editing a new personal agenda item | 
				
			||||
 * @param date is the time in day | 
				
			||||
 * @param date is the time in month | 
				
			||||
 * @param date is the time in year | 
				
			||||
 * @param date is the time in hour | 
				
			||||
 * @param date is the time in minute | 
				
			||||
 * @param string is the agenda title | 
				
			||||
 * @param string is the content | 
				
			||||
 * @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 = "") { | 
				
			||||
 | 
				
			||||
	$tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); | 
				
			||||
 | 
				
			||||
	//constructing the date | 
				
			||||
	$date = $year."-".$month."-".$day." ".$hour.":".$minute.":00"; | 
				
			||||
 | 
				
			||||
    if (!empty($date)) { | 
				
			||||
        $date = api_get_utc_datetime($date); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
	$date = Database::escape_string($date); | 
				
			||||
	$title = Database::escape_string($title); | 
				
			||||
	$content = Database::escape_string($content); | 
				
			||||
	$id = intval($id); | 
				
			||||
 | 
				
			||||
	if (!empty($id)) { | 
				
			||||
	    // we are updating | 
				
			||||
		$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 ('".api_get_user_id()."','$title', '$content', '$date')"; | 
				
			||||
	} | 
				
			||||
	$result = Database::query($sql); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * 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 <noel.dieschburg@dokeos.com> | 
				
			||||
 * @todo remove this function and use the CourseManager get_courses_list_by_user_id | 
				
			||||
 */ | 
				
			||||
 | 
				
			||||
function get_all_courses_of_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); | 
				
			||||
        $tbl_session_course_user= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); | 
				
			||||
        $tbl_session                    = Database :: get_main_table(TABLE_MAIN_SESSION); | 
				
			||||
        $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='".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='".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']); | 
				
			||||
        } | 
				
			||||
        return $courses; | 
				
			||||
 } | 
				
			||||
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * This function finds all the courses of the user and returns an array containing the | 
				
			||||
 * database name of the courses. | 
				
			||||
 */ | 
				
			||||
function get_courses_of_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, | 
				
			||||
									course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status | 
				
			||||
			                        FROM    $TABLECOURS       course, | 
				
			||||
											$TABLECOURSUSER   course_rel_user | 
				
			||||
			                        WHERE course.code = course_rel_user.course_code | 
				
			||||
			                        AND   course_rel_user.user_id = '".api_get_user_id()."'"; | 
				
			||||
	$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']); | 
				
			||||
	} | 
				
			||||
	return $courses; | 
				
			||||
} | 
				
			||||
/** | 
				
			||||
 * 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($user_id, $agendaitems, $day = "", $month = "", $year = "", $week = "", $type) { | 
				
			||||
	$tbl_personal_agenda = Database :: get_main_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='".$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 | 
				
			||||
	if ($type == "week_view") { | 
				
			||||
		$start_end_day_of_week = calculate_start_end_of_week($week, $year); | 
				
			||||
		$start_day = $start_end_day_of_week['start']['day']; | 
				
			||||
		$start_month = $start_end_day_of_week['start']['month']; | 
				
			||||
		$start_year = $start_end_day_of_week['start']['year']; | 
				
			||||
		$end_day = $start_end_day_of_week['end']['day']; | 
				
			||||
		$end_month = $start_end_day_of_week['end']['month']; | 
				
			||||
		$end_year = $start_end_day_of_week['end']['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"; | 
				
			||||
		$start_filter  = api_get_utc_datetime($start_filter); | 
				
			||||
		$end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59"; | 
				
			||||
		$end_filter  = api_get_utc_datetime($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 | 
				
			||||
		// we could use mysql date() function but this is only available from 4.1 and higher | 
				
			||||
		$start_filter = $year."-".$month."-".$day." 00:00:00"; | 
				
			||||
		$start_filter  = api_get_utc_datetime($start_filter); | 
				
			||||
		$end_filter = $year."-".$month."-".$day." 23:59:59"; | 
				
			||||
		$end_filter  = api_get_utc_datetime($end_filter); | 
				
			||||
		$sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'"; | 
				
			||||
	} | 
				
			||||
 | 
				
			||||
	$result = Database::query($sql); | 
				
			||||
	while ($item = Database::fetch_array($result, 'ASSOC')) { | 
				
			||||
 | 
				
			||||
		$time_minute 	= api_convert_and_format_date($item['date'], TIME_NO_SEC_FORMAT); | 
				
			||||
		$item['date']   = api_get_local_time($item['date']); | 
				
			||||
		$item['start_date_tms']  = api_strtotime($item['date']); | 
				
			||||
	    $item['content'] = $item['text']; | 
				
			||||
 | 
				
			||||
		// we break the date field in the database into a date and a time part | 
				
			||||
		$agenda_db_date = explode(" ", $item['date']); | 
				
			||||
		$date = $agenda_db_date[0]; | 
				
			||||
		$time = $agenda_db_date[1]; | 
				
			||||
		// we divide the date part into a day, a month and a year | 
				
			||||
		$agendadate = explode("-", $item['date']); | 
				
			||||
		$year = intval($agendadate[0]); | 
				
			||||
		$month = intval($agendadate[1]); | 
				
			||||
		$day = intval($agendadate[2]); | 
				
			||||
		// we divide the time part into hour, minutes, seconds | 
				
			||||
		$agendatime = explode(":", $time); | 
				
			||||
 | 
				
			||||
		$hour = $agendatime[0]; | 
				
			||||
		$minute = $agendatime[1]; | 
				
			||||
		$second = $agendatime[2]; | 
				
			||||
 | 
				
			||||
        if ($type == 'month_view') { | 
				
			||||
            $item['calendar_type']  = 'personal'; | 
				
			||||
            $item['start_date']  	= $item['date']; | 
				
			||||
            $agendaitems[$day][] 	= $item; | 
				
			||||
            continue; | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
		// if the student has specified a course we a add a link to that course | 
				
			||||
		if ($item['course'] <> "") { | 
				
			||||
			$url = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=".urlencode($item['course'])."&day=$day&month=$month&year=$year#$day"; // RH  //Patrick Cool: to highlight the relevant agenda item | 
				
			||||
			$course_link = "<a href=\"$url\" title=\"".$item['course']."\">".$item['course']."</a>"; | 
				
			||||
		} else { | 
				
			||||
			$course_link = ""; | 
				
			||||
		} | 
				
			||||
		// Creating the array that will be returned. If we have week or month view we have an array with the date as the key | 
				
			||||
		// if we have a day_view we use a half hour as index => key 33 = 16h30 | 
				
			||||
		if ($type !== "day_view") { | 
				
			||||
			// This is the array construction for the WEEK or MONTH view | 
				
			||||
 | 
				
			||||
			//Display events in agenda | 
				
			||||
			$agendaitems[$day] .= "<div><i>$time_minute</i> $course_link <a href=\"myagenda.php?action=view&view=personal&day=$day&month=$month&year=$year&id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div><br />"; | 
				
			||||
 | 
				
			||||
		} else { | 
				
			||||
			// this is the array construction for the DAY view | 
				
			||||
			$halfhour = 2 * $agendatime['0']; | 
				
			||||
			if ($agendatime['1'] >= '30') { | 
				
			||||
				$halfhour = $halfhour +1; | 
				
			||||
			} | 
				
			||||
 | 
				
			||||
			//Display events by list | 
				
			||||
			$agendaitems[$halfhour] .= "<div><i>$time_minute</i> $course_link <a href=\"myagenda.php?action=view&view=personal&day=$day&month=$month&year=$year&id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div>"; | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	return $agendaitems; | 
				
			||||
} | 
				
			||||
/** | 
				
			||||
 * This function retrieves one personal agenda item returns it. | 
				
			||||
 * @param	int	The agenda item ID | 
				
			||||
 * @return 	array	The results of the database query, or null if not found | 
				
			||||
 */ | 
				
			||||
function get_personal_agenda_item($id) { | 
				
			||||
	$tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); | 
				
			||||
	$id = intval($id); | 
				
			||||
	// make sure events of the personal agenda can only be seen by the user himself | 
				
			||||
	$user = api_get_user_id(); | 
				
			||||
	$sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE id=".$id." AND user = ".$user; | 
				
			||||
	$result = Database::query($sql); | 
				
			||||
	if(Database::num_rows($result)==1) { | 
				
			||||
		$item = Database::fetch_array($result); | 
				
			||||
	} else { | 
				
			||||
		$item = null; | 
				
			||||
	} | 
				
			||||
	return $item; | 
				
			||||
} | 
				
			||||
/** | 
				
			||||
 * This function retrieves all the personal agenda items of the user and shows | 
				
			||||
 * these items in one list (ordered by date and grouped by month (the month_bar) | 
				
			||||
 */ | 
				
			||||
function show_personal_agenda() { | 
				
			||||
	global $MonthsLong, $charset; | 
				
			||||
 | 
				
			||||
	$tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); | 
				
			||||
 | 
				
			||||
	// The SQL statement that retrieves all the personal agenda items of this user | 
				
			||||
	$sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' ORDER BY date DESC"; | 
				
			||||
	$result = Database::query($sql); | 
				
			||||
	// variable initialisation | 
				
			||||
	$month_bar = ""; | 
				
			||||
	// setting the default day, month and year | 
				
			||||
	if (!isset($_GET['day']) AND !isset($_GET['month']) AND !isset($_GET['year'])) { | 
				
			||||
		$today = getdate(); | 
				
			||||
		$year = $today['year']; | 
				
			||||
		$month = $today['mon']; | 
				
			||||
		$day = $today['mday']; | 
				
			||||
	} | 
				
			||||
	$export_icon = 'export.png'; | 
				
			||||
	$export_icon_low = 'export_low_fade.png'; | 
				
			||||
	$export_icon_high = 'export_high_fade.png'; | 
				
			||||
 | 
				
			||||
	// starting the table output | 
				
			||||
	echo '<table class="data_table">'; | 
				
			||||
 | 
				
			||||
	$th = Display::tag('th', get_lang('Title')); | 
				
			||||
    $th .= Display::tag('th', get_lang('Content')); | 
				
			||||
    $th .= Display::tag('th', get_lang('StartTimeWindow')); | 
				
			||||
    $th .= Display::tag('th', get_lang('Modify')); | 
				
			||||
 | 
				
			||||
    echo Display::tag('tr', $th); | 
				
			||||
 | 
				
			||||
	if (Database::num_rows($result) > 0) { | 
				
			||||
	    $counter = 0; | 
				
			||||
		while ($myrow = Database::fetch_array($result)) { | 
				
			||||
			/* 	display: the month bar		*/ | 
				
			||||
			if ($month_bar != date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]))) { | 
				
			||||
				$month_bar = date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"])); | 
				
			||||
				//echo "<tr><th class=\"title\" colspan=\"2\" class=\"month\" valign=\"top\">".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."</th></tr>"; | 
				
			||||
			} | 
				
			||||
			// highlight: if a date in the small calendar is clicked we highlight the relevant items | 
				
			||||
			$db_date = (int) date("d", strtotime($myrow["date"])).date("n", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"])); | 
				
			||||
			/* | 
				
			||||
			if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date) { | 
				
			||||
				$style = "data"; | 
				
			||||
				$text_style = "text"; | 
				
			||||
			} else { | 
				
			||||
				$style = "datanow"; | 
				
			||||
				$text_style = "text"; | 
				
			||||
			}*/ | 
				
			||||
 | 
				
			||||
		    $class = 'row_even'; | 
				
			||||
            if ($counter % 2) { | 
				
			||||
                $class = 'row_odd'; | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
			echo '<tr class="'.$class.'">'; | 
				
			||||
			echo '<td>'; | 
				
			||||
			/*   display: the title  */ | 
				
			||||
			echo $myrow['title']; | 
				
			||||
			echo "</td>"; | 
				
			||||
 | 
				
			||||
			// display: the content | 
				
			||||
            $content = $myrow['text']; | 
				
			||||
            echo "<td>"; | 
				
			||||
            echo $content; | 
				
			||||
            echo "</td>"; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
            //display: date and time | 
				
			||||
			echo '<td>'; | 
				
			||||
			// adding an internal anchor | 
				
			||||
			/*echo "<a name=\"".$myrow["id"]."\"></a>"; | 
				
			||||
			echo date("d", strtotime($myrow["date"]))." ".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))." ";*/ | 
				
			||||
 | 
				
			||||
			$myrow["date"] = api_get_local_time($myrow["date"]); | 
				
			||||
			echo api_format_date($myrow["date"], DATE_TIME_FORMAT_LONG); | 
				
			||||
			echo "</td>"; | 
				
			||||
			//echo '<td></td>'; //remove when enabling ical | 
				
			||||
            //echo '<td class="'.$style.'">'; | 
				
			||||
			//echo '<a class="ical_export" href="ical_export.php?type=personal&id='.$myrow['id'].'&class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a>'; | 
				
			||||
			//echo '<a class="ical_export" href="ical_export.php?type=personal&id='.$myrow['id'].'&class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a>'; | 
				
			||||
			//echo '<a class="ical_export" href="ical_export.php?type=personal&id='.$myrow['id'].'&class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a>'; | 
				
			||||
			//echo "</td>"; | 
				
			||||
			//echo "</tr>"; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
			/* display: the edit / delete icons */ | 
				
			||||
			echo "<td>"; | 
				
			||||
			echo "<a href=\"myagenda.php?action=edit_personal_agenda_item&id=".$myrow['id']."\">".Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL)."</a> "; | 
				
			||||
			echo "<a href=\"".api_get_self()."?action=delete&id=".$myrow['id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset))."')) return false;\">".Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL)."</a>"; | 
				
			||||
			echo "</td></tr>"; | 
				
			||||
			$counter++; | 
				
			||||
		} | 
				
			||||
	} else { | 
				
			||||
		echo '<tr><td colspan="2">'.get_lang('NoAgendaItems').'</td></tr>'; | 
				
			||||
	} | 
				
			||||
	echo "</table>"; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * This function retrieves all the personal agenda items of the given user_id and shows | 
				
			||||
 * these items in one list (ordered by date and grouped by month (the month_bar) | 
				
			||||
 * @param int user id | 
				
			||||
 */ | 
				
			||||
function show_simple_personal_agenda($user_id) { | 
				
			||||
	global $MonthsLong, $charset; | 
				
			||||
 | 
				
			||||
	$tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); | 
				
			||||
 | 
				
			||||
	// The SQL statement that retrieves all the personal agenda items of this user | 
				
			||||
	$sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' ORDER BY date DESC"; | 
				
			||||
	$result = Database::query($sql); | 
				
			||||
	// variable initialisation | 
				
			||||
	$month_bar = ""; | 
				
			||||
	// setting the default day, month and year | 
				
			||||
	if (!$_GET['day'] AND !$_GET['month'] AND !$_GET['year']) { | 
				
			||||
		$today = getdate(); | 
				
			||||
		$year = $today['year']; | 
				
			||||
		$month = $today['mon']; | 
				
			||||
		$day = $today['mday']; | 
				
			||||
	} | 
				
			||||
	$export_icon = 'export.png'; | 
				
			||||
	$export_icon_low = 'export_low_fade.png'; | 
				
			||||
	$export_icon_high = 'export_high_fade.png'; | 
				
			||||
	$content = ''; | 
				
			||||
	// starting the table output | 
				
			||||
	if (Database::num_rows($result) > 0) { | 
				
			||||
		while ($myrow = Database::fetch_array($result)) { | 
				
			||||
			/*-------------------------------------------------- | 
				
			||||
					display: the month bar | 
				
			||||
			  --------------------------------------------------*/ | 
				
			||||
			if ($month_bar != date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]))) { | 
				
			||||
				$month_bar = date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"])); | 
				
			||||
				$content.= $MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"])); | 
				
			||||
			} | 
				
			||||
			// highlight: if a date in the small calendar is clicked we highlight the relevant items | 
				
			||||
			$db_date = (int) date("d", strtotime($myrow["date"])).date("n", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"])); | 
				
			||||
			if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date) { | 
				
			||||
				$style = "data"; | 
				
			||||
				$text_style = "text"; | 
				
			||||
			} else { | 
				
			||||
				$style = "datanow"; | 
				
			||||
				$text_style = "text"; | 
				
			||||
			} | 
				
			||||
 | 
				
			||||
			// adding an internal anchor | 
				
			||||
			$content.= date("d", strtotime($myrow["date"]))." ".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))." "; | 
				
			||||
			$content.= strftime(get_lang("timeNoSecFormat"), strtotime($myrow["date"])); | 
				
			||||
 | 
				
			||||
			$content.= '<br />'; | 
				
			||||
			$content.= $myrow['title']; | 
				
			||||
			$content.= '<br />'; | 
				
			||||
 | 
				
			||||
			return $content; | 
				
			||||
		} | 
				
			||||
	} else { | 
				
			||||
		return $content; | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Get personal agenda items between two dates (=all events from all registered courses) | 
				
			||||
 * @param	int		user ID of the user | 
				
			||||
 * @param	string	Optional start date in datetime format (if no start date is given, uses today) | 
				
			||||
 * @param	string	Optional end date in datetime format (if no date is given, uses one year from now) | 
				
			||||
 * @return	array	Array of events ordered by start date, in [0]('datestart','dateend','title'),[1]('datestart','dateend','title','link','coursetitle') format, where datestart and dateend are in yyyyMMddhhmmss format. | 
				
			||||
 * @TODO Implement really personal events (from user DB) and global events (from main DB) | 
				
			||||
 */ | 
				
			||||
function get_personal_agenda_items_between_dates($user_id, $date_start='', $date_end='') { | 
				
			||||
	$items = array (); | 
				
			||||
	if ($user_id != strval(intval($user_id))) { return $items; } | 
				
			||||
	if (empty($date_start)) { $date_start = date('Y-m-d H:i:s');} | 
				
			||||
	if (empty($date_end))   { $date_end = date('Y-m-d H:i:s',mktime(0, 0, 0, date("m"),   date("d"),   date("Y")+1));} | 
				
			||||
	$expr = '/\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}/'; | 
				
			||||
	if(!preg_match($expr,$date_start)) { return $items; } | 
				
			||||
	if(!preg_match($expr,$date_end)) { return $items; } | 
				
			||||
 | 
				
			||||
	// get agenda-items for every course | 
				
			||||
	$courses = api_get_user_courses($user_id,false); | 
				
			||||
	foreach ($courses as $id => $course) { | 
				
			||||
		$c = api_get_course_info($course['code']); | 
				
			||||
		//databases of the courses | 
				
			||||
		$t_a = Database :: get_course_table(TABLE_AGENDA, $course['db']); | 
				
			||||
		$t_ip = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course['db']); | 
				
			||||
        // get the groups to which the user belong | 
				
			||||
		$group_memberships = GroupManager :: get_group_ids($course['db'], $user_id); | 
				
			||||
		// if the user is administrator of that course we show all the agenda items | 
				
			||||
		if ($course['status'] == '1') { | 
				
			||||
			//echo "course admin"; | 
				
			||||
			$sqlquery = "SELECT ". | 
				
			||||
						" DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ". | 
				
			||||
						" FROM ".$t_a." agenda, ". | 
				
			||||
						$t_ip." ip ". | 
				
			||||
                        " WHERE agenda.id = ip.ref ". | 
				
			||||
						" AND agenda.start_date>='$date_start' ". | 
				
			||||
						" AND agenda.end_date<='$date_end' ". | 
				
			||||
						" AND ip.tool='".TOOL_CALENDAR_EVENT."' ". | 
				
			||||
						" AND ip.visibility='1' ". | 
				
			||||
						" GROUP BY agenda.id ". | 
				
			||||
						" ORDER BY start_date "; | 
				
			||||
		} else { | 
				
			||||
            // if the user is not an administrator of that course, then... | 
				
			||||
			if (is_array($group_memberships) && count($group_memberships)>0) | 
				
			||||
			{ | 
				
			||||
				$sqlquery = "SELECT " . | 
				
			||||
							"DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ". | 
				
			||||
                            " FROM ".$t_a." agenda, ". | 
				
			||||
			                $t_ip." ip ". | 
				
			||||
                            " WHERE agenda.id = ip.ref ". | 
				
			||||
							" AND agenda.start_date>='$date_start' ". | 
				
			||||
							" AND agenda.end_date<='$date_end' ". | 
				
			||||
							" AND ip.tool='".TOOL_CALENDAR_EVENT."' ". | 
				
			||||
							" 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 { | 
				
			||||
				$sqlquery = "SELECT ". | 
				
			||||
							"DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ". | 
				
			||||
							" FROM ".$t_a." agenda, ". | 
				
			||||
							$t_ip." ip ". | 
				
			||||
							" WHERE agenda.id = ip.ref ". | 
				
			||||
							" AND agenda.start_date>='$date_start' ". | 
				
			||||
							" AND agenda.end_date<='$date_end' ". | 
				
			||||
							" AND ip.tool='".TOOL_CALENDAR_EVENT."' ". | 
				
			||||
							" AND ( ip.to_user_id='".$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'])); | 
				
			||||
			$month = date("n",strtotime($item['start_date'])); | 
				
			||||
			$year = date("Y",strtotime($item['start_date'])); | 
				
			||||
			$URL = api_get_path(WEB_PATH)."main/calendar/agenda.php?cidReq=".urlencode($course["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; | 
				
			||||
			list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['start_date']); | 
				
			||||
			$start_date = $year.$month.$day.$hour.$min; | 
				
			||||
			list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['end_date']); | 
				
			||||
			$end_date = $year.$month.$day.$hour.$min; | 
				
			||||
 | 
				
			||||
			$items[] = array( | 
				
			||||
				'datestart'=>$start_date, | 
				
			||||
				'dateend'=>$end_date, | 
				
			||||
				'title'=>$item['title'], | 
				
			||||
				'link'=>$URL, | 
				
			||||
				'coursetitle'=>$c['name'], | 
				
			||||
			); | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	return $items; | 
				
			||||
} | 
				
			||||
@ -1,251 +0,0 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
// we are not inside a course, so we reset the course id | 
				
			||||
$cidReset = true; | 
				
			||||
// setting the global file that gets the general configuration, the databases, the languages | 
				
			||||
require_once '../inc/global.inc.php'; | 
				
			||||
$this_section = SECTION_MYAGENDA; | 
				
			||||
unset($_SESSION['this_section']);//for hmtl editor repository | 
				
			||||
 | 
				
			||||
api_block_anonymous_users(); | 
				
			||||
require_once 'agenda.inc.php'; | 
				
			||||
require_once 'myagenda.inc.php'; | 
				
			||||
// setting the name of the tool | 
				
			||||
$nameTools = get_lang('MyAgenda'); | 
				
			||||
 | 
				
			||||
// if we come from inside a course and click on the 'My Agenda' link we show a link back to the course | 
				
			||||
// in the breadcrumbs | 
				
			||||
//remove this if cause it was showing in agenda general | 
				
			||||
/*if(!empty($_GET['coursePath'])) { | 
				
			||||
	$course_path = api_htmlentities(strip_tags($_GET['coursePath']),ENT_QUOTES,$charset); | 
				
			||||
	$course_path = str_replace(array('../','..\\'),array('',''),$course_path); | 
				
			||||
} | 
				
			||||
*/ | 
				
			||||
if (!empty ($course_path)) { | 
				
			||||
	$interbreadcrumb[] = array ('url' => api_get_path(WEB_COURSE_PATH).urlencode($course_path).'/index.php', 'name' => Security::remove_XSS($_GET['courseCode'])); | 
				
			||||
} | 
				
			||||
// this loads the javascript that is needed for the date popup selection | 
				
			||||
$htmlHeadXtra[] = to_javascript(); | 
				
			||||
$htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>"; | 
				
			||||
$htmlHeadXtra[] = "<script> | 
				
			||||
$(function() { | 
				
			||||
    $(\".dialog\").dialog(\"destroy\"); | 
				
			||||
    $(\".dialog\").dialog({ | 
				
			||||
            autoOpen: false, | 
				
			||||
            show: \"blind\", | 
				
			||||
            resizable: false, | 
				
			||||
            height:300, | 
				
			||||
            width:550, | 
				
			||||
            modal: true | 
				
			||||
     }); | 
				
			||||
    $(\".opener\").click(function() { | 
				
			||||
        var my_id = $(this).attr('id'); | 
				
			||||
        var big_image = '#main_' + my_id; | 
				
			||||
        $( big_image ).dialog(\"open\"); | 
				
			||||
        return false; | 
				
			||||
    }); | 
				
			||||
}); | 
				
			||||
</script> | 
				
			||||
"; | 
				
			||||
 | 
				
			||||
// showing the header | 
				
			||||
Display::display_header(get_lang('MyAgenda')); | 
				
			||||
 | 
				
			||||
 | 
				
			||||
//	SETTING SOME VARIABLES | 
				
			||||
 | 
				
			||||
// setting the database variables | 
				
			||||
$TABLECOURS 		= Database :: get_main_table(TABLE_MAIN_COURSE); | 
				
			||||
$TABLECOURSUSER 	= Database :: get_main_table(TABLE_MAIN_COURSE_USER); | 
				
			||||
$TABLEAGENDA 		= Database :: get_course_table(TABLE_AGENDA); | 
				
			||||
$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); | 
				
			||||
$tbl_personal_agenda= Database :: get_main_table(TABLE_PERSONAL_AGENDA); | 
				
			||||
 | 
				
			||||
// the variables for the days and the months | 
				
			||||
// Defining the shorts for the days | 
				
			||||
$DaysShort = api_get_week_days_short(); | 
				
			||||
// Defining the days of the week to allow translation of the days | 
				
			||||
$DaysLong = api_get_week_days_long(); | 
				
			||||
// Defining the months of the year to allow translation of the months | 
				
			||||
$MonthsLong = api_get_months_long(); | 
				
			||||
 | 
				
			||||
/* | 
				
			||||
	TREATING THE URL PARAMETERS | 
				
			||||
	1. The default values | 
				
			||||
	2. storing it in the session | 
				
			||||
	3. possible view | 
				
			||||
		3.a Month view | 
				
			||||
		3.b Week view | 
				
			||||
		3.c day view | 
				
			||||
		3.d personal view (only the personal agenda items) | 
				
			||||
	4. add personal agenda | 
				
			||||
	5. edit personal agenda | 
				
			||||
	6. delete personal agenda | 
				
			||||
*/ | 
				
			||||
 | 
				
			||||
// 1. The default values. if there is no session yet, we have by default the month view | 
				
			||||
if (empty($_SESSION['view'])) { | 
				
			||||
	$_SESSION['view'] = 'month'; | 
				
			||||
} | 
				
			||||
// 2. Storing it in the session. If we change the view by clicking on the links left, we change the session | 
				
			||||
if (!empty($_GET['view'])) { | 
				
			||||
	$_SESSION['view'] = Security::remove_XSS($_GET['view']); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
// 3. The views: (month, week, day, personal) | 
				
			||||
if ($_SESSION['view']) { | 
				
			||||
	switch ($_SESSION['view']) { | 
				
			||||
		// 3.a Month view | 
				
			||||
		case "month" : | 
				
			||||
			$process = 'month_view'; | 
				
			||||
			break; | 
				
			||||
			// 3.a Week view | 
				
			||||
		case "week" : | 
				
			||||
			$process = 'week_view'; | 
				
			||||
			break; | 
				
			||||
			// 3.a Day view | 
				
			||||
		case "day" : | 
				
			||||
			$process = 'day_view'; | 
				
			||||
			break; | 
				
			||||
			// 3.a Personal view | 
				
			||||
		case "personal" : | 
				
			||||
			$process = 'personal_view'; | 
				
			||||
			break; | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
// 4. add personal agenda | 
				
			||||
if (!empty($_GET['action']) && $_GET['action'] == 'add_personal_agenda_item' and !$_POST['Submit']) { | 
				
			||||
	$process = "add_personal_agenda_item"; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
if (!empty($_REQUEST['action']) && $_REQUEST['action'] == "add_personal_agenda_item" and $_POST['Submit']) { | 
				
			||||
	$process = "store_personal_agenda_item"; | 
				
			||||
} | 
				
			||||
// 5. edit personal agenda | 
				
			||||
if (!empty($_GET['action']) && $_GET['action'] == 'edit_personal_agenda_item' and !$_POST['Submit']) { | 
				
			||||
	$process = "edit_personal_agenda_item"; | 
				
			||||
} | 
				
			||||
if (!empty($_GET['action']) && $_GET['action'] == 'edit_personal_agenda_item'  and $_POST['Submit']) { | 
				
			||||
	$process = "store_personal_agenda_item"; | 
				
			||||
} | 
				
			||||
// 6. delete personal agenda | 
				
			||||
if (!empty($_GET['action']) && $_GET['action'] == "delete" AND $_GET['id']) { | 
				
			||||
	$process = "delete_personal_agenda_item"; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
// OUTPUT | 
				
			||||
if (isset($_user['user_id'])) { | 
				
			||||
	// getting all the courses that this user is subscribed to | 
				
			||||
	//$courses_dbs = get_all_courses_of_user(); | 
				
			||||
	$my_course_list = CourseManager::get_courses_list_by_user_id(api_get_user_id(), true); | 
				
			||||
 | 
				
			||||
	if (!is_array($my_course_list)) { | 
				
			||||
		// this is for the special case if the user has no courses (otherwise you get an error) | 
				
			||||
		$my_course_list = array(); | 
				
			||||
	} | 
				
			||||
	// setting and/or getting the year, month, day, week | 
				
			||||
	$today = getdate(); | 
				
			||||
	$year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL); | 
				
			||||
	if ($year == NULL) { | 
				
			||||
		$year = $today['year']; | 
				
			||||
	} | 
				
			||||
	$month = (!empty($_GET['month'])? (int)$_GET['month']:NULL); | 
				
			||||
	if ($month == NULL) { | 
				
			||||
		$month = $today['mon']; | 
				
			||||
	} | 
				
			||||
	$day = (!empty($_GET['day']) ? (int)$_GET['day']:NULL); | 
				
			||||
	if ($day == NULL) { | 
				
			||||
		$day = $today['mday']; | 
				
			||||
	} | 
				
			||||
	$week = (!empty($_GET['week']) ?(int)$_GET['week']:NULL); | 
				
			||||
	if ($week == NULL) { | 
				
			||||
		$week = date("W"); | 
				
			||||
	} | 
				
			||||
	// The name of the current Month | 
				
			||||
	$monthName = $MonthsLong[$month -1]; | 
				
			||||
	// Starting the output | 
				
			||||
 | 
				
			||||
	echo "<div class=\"actions\">"; | 
				
			||||
	echo "<a href=\"".api_get_self()."?action=view&view=month\">".Display::return_icon('month.png', get_lang('MonthView'),'',ICON_SIZE_MEDIUM)."</a>"; | 
				
			||||
	echo "<a href=\"".api_get_self()."?action=view&view=week\">".Display::return_icon('7days.png', get_lang('WeekView'),'',ICON_SIZE_MEDIUM)."</a> "; | 
				
			||||
	echo "<a href=\"".api_get_self()."?action=view&view=day\">".Display::return_icon('1day.png', get_lang('DayView'),'',ICON_SIZE_MEDIUM)."</a> "; | 
				
			||||
	if (api_get_setting('allow_personal_agenda') == 'true') { | 
				
			||||
		echo "<a href=\"".api_get_self()."?action=add_personal_agenda_item\">".Display::return_icon('new_user_event.png', get_lang('AddPersonalItem'),'',ICON_SIZE_MEDIUM)."</a> "; | 
				
			||||
		echo "<a href=\"".api_get_self()."?action=view&view=personal\">".Display::return_icon('personal_calendar.png', get_lang('ViewPersonalItem'),'',ICON_SIZE_MEDIUM)."</a> "; | 
				
			||||
	} | 
				
			||||
	echo "</div>"; | 
				
			||||
 | 
				
			||||
	$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(api_get_user_id(), $agendaitems, $day, $month, $year, $week, "month_view"); | 
				
			||||
	} | 
				
			||||
 | 
				
			||||
	if ($process != 'month_view') { | 
				
			||||
	    echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; | 
				
			||||
    	echo "<tr>"; | 
				
			||||
    	// output: the small calendar item on the left and the view / add links | 
				
			||||
    	echo "<td width=\"220\" valign=\"top\">"; | 
				
			||||
	    display_myminimonthcalendar($agendaitems, $month, $year, $monthName); | 
				
			||||
	    echo "</td>"; | 
				
			||||
    	// the divider | 
				
			||||
    	// OlivierB : the image has a white background, which causes trouble if the portal has another background color. Image should be transparent. ----> echo "<td width=\"20\" background=\"../img/verticalruler.gif\"> </td>"; | 
				
			||||
    	echo "<td width=\"8\"> </td>"; | 
				
			||||
    	// the main area: day, week, month view | 
				
			||||
    	echo "<td valign=\"top\">"; | 
				
			||||
	} | 
				
			||||
 | 
				
			||||
	switch ($process) { | 
				
			||||
		case 'month_view' : | 
				
			||||
			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(api_get_user_id(), $agendaitems, $day, $month, $year, $week, "week_view"); | 
				
			||||
			} | 
				
			||||
			display_weekcalendar($agendaitems, $month, $year, array(), $monthName); | 
				
			||||
			break; | 
				
			||||
		case 'day_view' : | 
				
			||||
			$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(api_get_user_id(), $agendaitems, $day, $month, $year, $week, "day_view"); | 
				
			||||
			} | 
				
			||||
			display_daycalendar($agendaitems, $day, $month, $year, array(), $monthName); | 
				
			||||
			break; | 
				
			||||
		case 'personal_view' : | 
				
			||||
			show_personal_agenda(); | 
				
			||||
			break; | 
				
			||||
		case 'add_personal_agenda_item' : | 
				
			||||
			//show_new_personal_item_form(); | 
				
			||||
			break; | 
				
			||||
		case 'store_personal_agenda_item' : | 
				
			||||
			store_personal_item($_POST['frm_day'], $_POST['frm_month'], $_POST['frm_year'], $_POST['frm_hour'], $_POST['frm_minute'], $_POST['frm_title'], $_POST['frm_content'], $_GET['id']); | 
				
			||||
			if ($_GET['id']) { | 
				
			||||
				echo '<br />'; | 
				
			||||
				Display :: display_normal_message(get_lang("PeronalAgendaItemEdited")); | 
				
			||||
			} else { | 
				
			||||
				echo '<br />'; | 
				
			||||
				Display :: display_normal_message(get_lang("PeronalAgendaItemAdded")); | 
				
			||||
			} | 
				
			||||
			show_personal_agenda(); | 
				
			||||
			break; | 
				
			||||
		case 'edit_personal_agenda_item' : | 
				
			||||
			//show_new_personal_item_form($_GET['id']); | 
				
			||||
			break; | 
				
			||||
		case 'delete_personal_agenda_item' : | 
				
			||||
			//delete_personal_agenda($_GET['id']); | 
				
			||||
			echo '<br />'; | 
				
			||||
			Display :: display_normal_message(get_lang('PeronalAgendaItemDeleted')); | 
				
			||||
			show_personal_agenda(); | 
				
			||||
			break; | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
if ($process != 'month_view') { | 
				
			||||
    echo '</td></tr></table>'; | 
				
			||||
} | 
				
			||||
Display :: display_footer(); | 
				
			||||
					Loading…
					
					
				
		Reference in new issue