Remove unused calendar code.

1.10.x
Julio Montoya 11 years ago
parent bfd5f3bc9f
commit 8694ff7c03
  1. 2543
      main/admin/calendar.lib.php
  2. 283
      main/admin/calendar.php
  3. 133
      main/admin/calendar_ical_export.php
  4. 23
      main/admin/user_list.php
  5. 3851
      main/calendar/agenda.inc.php
  6. 2
      main/calendar/agenda.php
  7. 1
      main/calendar/agenda_js.php
  8. 1
      main/calendar/agenda_list.php
  9. 379
      main/calendar/allagendas.php
  10. 2
      main/calendar/download.php
  11. 789
      main/calendar/myagenda.inc.php
  12. 251
      main/calendar/myagenda.php
  13. 12
      main/inc/ajax/agenda.ajax.php
  14. 634
      main/inc/lib/agenda.lib.php
  15. 15
      main/inc/lib/system_announcements.lib.php
  16. 3
      main/webservices/user_info.soap.php
  17. 1
      main/work/work.lib.php
  18. 247
      tests/main/admin/calendar.lib.test.php
  19. 1
      tests/test_manager.inc.php

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">&nbsp;</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 "&nbsp;</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();
}
?>

@ -1,5 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
@author Bart Mollet @author Bart Mollet
@author Julio Montoya <gugli100@gmail.com> BeezNest 2011 @author Julio Montoya <gugli100@gmail.com> BeezNest 2011
@ -123,25 +124,6 @@ $(document).ready(function() {
document.getElementById(\'extra_data_text\').style.display="none"; document.getElementById(\'extra_data_text\').style.display="none";
} }
} }
$(".agenda_opener").live("click", function() {
var url = this.href;
var dialog = $("#dialog");
if ($("#dialog").length == 0) {
dialog = $(\'<div id="dialog" style="display:hidden"></div> \').appendTo(\'body\');
}
// load remote content
dialog.load(
url,
{},
function(responseText, textStatus, XMLHttpRequest) {
dialog.dialog({width:720, height:550, modal:true});
}
);
//prevent the browser to follow the link
return false;
});
}); });
//Load user calendar //Load user calendar
@ -627,7 +609,8 @@ function modify_filter($user_id, $url_params, $row) {
} }
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$result .= ' <a href="'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&amp;user_id='.$user_id.'" class="agenda_opener">'.Display::return_icon('month.png', get_lang('FreeBusyCalendar'), array(), ICON_SIZE_SMALL).'</a>'; $result .= ' <a href="'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&amp;user_id='.$user_id.'" class="agenda_opener">'.
Display::return_icon('month.png', get_lang('FreeBusyCalendar'), array(), ICON_SIZE_SMALL).'</a>';
if ($delete_user_available) { if ($delete_user_available) {
if ($user_id != api_get_user_id() && if ($user_id != api_get_user_id() &&
!$user_is_anonymous && !$user_is_anonymous &&

File diff suppressed because it is too large Load Diff

@ -240,10 +240,10 @@ if (api_is_allowed_to_edit(false, true) OR
exit; exit;
} else { } else {
$content = $form->return_form(); $content = $form->return_form();
} }
break; break;
case 'importical': case 'importical':
$actionName = get_lang('Import');
$form = $agenda->getImportCalendarForm(); $form = $agenda->getImportCalendarForm();
$content = $form->return_form(); $content = $form->return_form();

@ -18,7 +18,6 @@ if ($type == 'personal') {
$cidReset = true; // fixes #5162 $cidReset = true; // fixes #5162
} }
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
require_once 'agenda.inc.php';
$current_course_tool = TOOL_CALENDAR_EVENT; $current_course_tool = TOOL_CALENDAR_EVENT;
$this_section = SECTION_MYAGENDA; $this_section = SECTION_MYAGENDA;

@ -5,7 +5,6 @@
*/ */
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
require_once 'agenda.inc.php';
$interbreadcrumb[] = array( $interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH) . "calendar/agenda_js.php", 'url' => api_get_path(WEB_CODE_PATH) . "calendar/agenda_js.php",

@ -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)."&amp;session=".Security::remove_XSS($session_id)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
$forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;session=".Security::remove_XSS($session_id)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
echo "<table class=\"data_table\">\n", "<tr>\n", "<th width=\"10%\"><a href=\"", $backwardsURL, "\">&#171;</a></th>\n", "<th width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>\n", "<th width=\"10%\"><a href=\"", $forewardsURL, "\">&#187;</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>&nbsp;</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)."&amp;sort=asc&amp;view=list&amp;day=$agendaday&amp;month=$month&amp;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')."&nbsp;<i>".$time."</i>"."&nbsp;-&nbsp;".get_lang("EndTimeWindow")."&nbsp;<i>".$end_time."</i>&nbsp;";
$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\">&nbsp;</td>";
echo "<td width=\"20\">&nbsp;</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();

@ -17,8 +17,6 @@ session_cache_limiter('public');
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
require_once 'agenda.inc.php';
// IMPORTANT to avoid caching of documents // IMPORTANT to avoid caching of documents
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT'); header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
header('Cache-Control: public'); header('Cache-Control: public');

@ -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)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=".$next_month."&amp;year=".$next_year);
$next_url = Display::url($next_icon, api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=".$prev_month."&amp;year=".$prev_year);
} else {
$back_url = Display::url($prev_icon, '', array('onclick'=>"load_calendar('".$user_id."','".$next_month."', '".$next_year."'); "));
$next_url = Display::url($next_icon, '', array('onclick'=>"load_calendar('".$user_id."','".$prev_month."', '".$prev_year."'); "));
}
echo '<table id="agenda_list"><tr>';
echo '<th width="10%">'.$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 = '-&nbsp;<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>&nbsp;'.$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)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
$forewardsURL = api_get_self()."?coursePath=".Security::remove_XSS($course_path)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;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&amp;view=day&amp;day=".$curday."&amp;month=".$month."&amp;year=".$year."\">".$dayheader."</a>";
} else {
echo $dayheader;
}
// "a".$dayheader." <span class=\"agendaitem\">".$agendaitems[$curday]."</span>";
echo "</td>";
$curday ++;
}
else
{
echo "<td>&nbsp;</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'])."&amp;day=$day&amp;month=$month&amp;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&amp;view=personal&amp;day=$day&amp;month=$month&amp;year=$year&amp;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&amp;view=personal&amp;day=$day&amp;month=$month&amp;year=$year&amp;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"]))."&nbsp;";*/
$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&amp;id=".$myrow['id']."\">".Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL)."</a> ";
echo "<a href=\"".api_get_self()."?action=delete&amp;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"]))."&nbsp;";
$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"])."&amp;day=$agendaday&amp;month=$month&amp;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&amp;view=month\">".Display::return_icon('month.png', get_lang('MonthView'),'',ICON_SIZE_MEDIUM)."</a>";
echo "<a href=\"".api_get_self()."?action=view&amp;view=week\">".Display::return_icon('7days.png', get_lang('WeekView'),'',ICON_SIZE_MEDIUM)."</a> ";
echo "<a href=\"".api_get_self()."?action=view&amp;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&amp;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\">&nbsp;</td>";
echo "<td width=\"8\">&nbsp;</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();

@ -12,9 +12,6 @@ if ($type == 'personal') {
require_once '../global.inc.php'; require_once '../global.inc.php';
require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.inc.php';
require_once api_get_path(SYS_CODE_PATH).'calendar/myagenda.inc.php';
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
$group_id = api_get_group_id(); $group_id = api_get_group_id();
@ -142,14 +139,15 @@ switch ($action) {
$day = $today['mday']; $day = $today['mday'];
} }
$monthName = $MonthsLong[$month - 1]; $monthName = $MonthsLong[$month - 1];
$week = null;
$agendaitems = get_myagendaitems( $agendaitems = Agenda::get_myagendaitems(
$user_id, $user_id,
$my_course_list, $my_course_list,
$month, $month,
$year $year
); );
$agendaitems = get_global_agenda_items( $agendaitems = Agenda::get_global_agenda_items(
$agendaitems, $agendaitems,
$day, $day,
$month, $month,
@ -159,7 +157,7 @@ switch ($action) {
); );
if (api_get_setting('allow_personal_agenda') == 'true') { if (api_get_setting('allow_personal_agenda') == 'true') {
$agendaitems = get_personal_agenda_items( $agendaitems = Agenda::get_personal_agenda_items(
$user_id, $user_id,
$agendaitems, $agendaitems,
$day, $day,
@ -169,7 +167,7 @@ switch ($action) {
"month_view" "month_view"
); );
} }
display_mymonthcalendar( Agenda::display_mymonthcalendar(
$user_id, $user_id,
$agendaitems, $agendaitems,
$month, $month,

@ -2433,4 +2433,638 @@ class Agenda
'groups' => array($groupId) 'groups' => array($groupId)
); );
} }
/**
* This function retrieves all the agenda items of all the courses the user is subscribed to
*/
public static function get_myagendaitems($user_id, $courses_dbs, $month, $year)
{
$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;
}
/**
* This function retrieves one personal agenda item returns it.
* @param array The array containing existing events. We add to this array.
* @param int Day
* @param int Month
* @param int Year (4 digits)
* @param int Week number
* @param string Type of view (month_view, week_view, day_view)
* @return array The results of the database query, or null if not found
*/
public static function get_global_agenda_items($agendaitems, $day = "", $month = "", $year = "", $week = "", $type)
{
$tbl_global_agenda = Database::get_main_table(
TABLE_MAIN_SYSTEM_CALENDAR
);
$month = intval($month);
$year = intval($year);
$week = intval($week);
$day = intval($day);
// 1. creating the SQL statement for getting the personal agenda items in MONTH view
$current_access_url_id = api_get_current_access_url_id();
if ($type == "month_view" or $type == "") {
// We are in month view
$sql = "SELECT * FROM ".$tbl_global_agenda." WHERE MONTH(start_date) = ".$month." AND YEAR(start_date) = ".$year." AND access_url_id = $current_access_url_id ORDER BY start_date ASC";
}
// 2. creating the SQL statement for getting the personal agenda items in WEEK view
if ($type == "week_view") { // we are in week view
$start_end_day_of_week = self::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_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id ";
}
// 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_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id";
}
$result = Database::query($sql);
while ($item = Database::fetch_array($result)) {
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']);
}
if ($item['end_date'] != '0000-00-00 00:00:00') {
$item['end_date'] = api_get_local_time($item['end_date']);
}
// we break the date field in the database into a date and a time part
$agenda_db_date = explode(" ", $item['start_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("-", $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'] = 'global';
$agendaitems[$day][] = $item;
continue;
}
$start_time = api_format_date(
$item['start_date'],
TIME_NO_SEC_FORMAT
);
$end_time = '';
if ($item['end_date'] != '0000-00-00 00:00:00') {
$end_time = ' - '.api_format_date(
$item['end_date'],
DATE_TIME_FORMAT_LONG
);
}
// 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
)."admin/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 the Agenda global in the tab agenda (administrator)
$agendaitems[$day] .= "<i>$start_time $end_time</i>&nbsp;-&nbsp;";
$agendaitems[$day] .= "<b>".get_lang('GlobalEvent')."</b>";
$agendaitems[$day] .= "<div>".$item['title']."</div><br>";
} else {
// this is the array construction for the DAY view
$halfhour = 2 * $agendatime['0'];
if ($agendatime['1'] >= '30') {
$halfhour = $halfhour + 1;
}
if (!is_array($agendaitems[$halfhour])) {
$content = $agendaitems[$halfhour];
}
$agendaitems[$halfhour] = $content."<div><i>$hour:$minute</i> <b>".get_lang(
'GlobalEvent'
).": </b>".$item['title']."</div>";
}
}
return $agendaitems;
}
/**
* This function retrieves all the personal agenda items and add them to the agenda items found by the other functions.
*/
public static 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 = self::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'])."&amp;day=$day&amp;month=$month&amp;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&amp;view=personal&amp;day=$day&amp;month=$month&amp;year=$year&amp;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&amp;view=personal&amp;day=$day&amp;month=$month&amp;year=$year&amp;id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div>";
}
}
return $agendaitems;
}
/**
* 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
*/
public static 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)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=".$next_month."&amp;year=".$next_year);
$next_url = Display::url($next_icon, api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=".$prev_month."&amp;year=".$prev_year);
} else {
$back_url = Display::url($prev_icon, '', array('onclick'=>"load_calendar('".$user_id."','".$next_month."', '".$next_year."'); "));
$next_url = Display::url($next_icon, '', array('onclick'=>"load_calendar('".$user_id."','".$prev_month."', '".$prev_year."'); "));
}
echo '<table id="agenda_list"><tr>';
echo '<th width="10%">'.$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 = '-&nbsp;<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>&nbsp;'.$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>";
}
/**
* 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)
*/
public static 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"])."&amp;day=$agendaday&amp;month=$month&amp;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;
}
/**
* 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
*/
public static 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 calculates the startdate of the week (monday)
* and the enddate of the week (sunday)
* and returns it as an array
*/
public static function calculate_start_end_of_week($week_number, $year)
{
// determine the start and end date
// step 1: we calculate a timestamp for a day in this week
$random_day_in_week = mktime(0, 0, 0, 1, 1, $year) + ($week_number) * (7 * 24 * 60 * 60); // we calculate a random day in this week
// step 2: we which day this is (0=sunday, 1=monday, ...)
$number_day_in_week = date('w', $random_day_in_week);
// step 3: we calculate the timestamp of the monday of the week we are in
$start_timestamp = $random_day_in_week - (($number_day_in_week -1) * 24 * 60 * 60);
// step 4: we calculate the timestamp of the sunday of the week we are in
$end_timestamp = $random_day_in_week + ((7 - $number_day_in_week +1) * 24 * 60 * 60) - 3600;
// step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year
$start_day = date('j', $start_timestamp);
$start_month = date('n', $start_timestamp);
$start_year = date('Y', $start_timestamp);
$end_day = date('j', $end_timestamp);
$end_month = date('n', $end_timestamp);
$end_year = date('Y', $end_timestamp);
$start_end_array['start']['day'] = $start_day;
$start_end_array['start']['month'] = $start_month;
$start_end_array['start']['year'] = $start_year;
$start_end_array['end']['day'] = $end_day;
$start_end_array['end']['month'] = $end_month;
$start_end_array['end']['year'] = $end_year;
return $start_end_array;
}
} }

@ -378,11 +378,20 @@ class SystemAnnouncementManager
Debug::log_s(mysql_error()); Debug::log_s(mysql_error());
return false; return false;
} }
$id = null;
if ($add_to_calendar) { if ($add_to_calendar) {
require_once 'calendar.lib.php'; $agenda = new Agenda();
$agenda_id = agenda_add_item($title, $original_content, $date_start, $date_end); $agenda->setType('admin');
$id = $agenda->add_event(
$date_start,
$date_end,
false,
$title,
$original_content
);
} }
return Database::insert_id();
return $id;
} }
/** /**

@ -171,10 +171,9 @@ function WSEventsList($username, $signature, $datestart = 0, $dateend = 0) {
$user_id = UserManager::get_user_id_from_username($username); $user_id = UserManager::get_user_id_from_username($username);
if ($user_id === false) { return $events_list; } // Error in user id recovery. if ($user_id === false) { return $events_list; } // Error in user id recovery.
require_once '../calendar/myagenda.inc.php';
$ds = substr($datestart,0,4).'-'.substr($datestart,4,2).'-'.substr($datestart,6,2).' 00:00:00'; $ds = substr($datestart,0,4).'-'.substr($datestart,4,2).'-'.substr($datestart,6,2).' 00:00:00';
$de = substr($dateend,0,4).'-'.substr($dateend,4,2).'-'.substr($dateend,6,2).' 00:00:00'; $de = substr($dateend,0,4).'-'.substr($dateend,4,2).'-'.substr($dateend,6,2).' 00:00:00';
$events_list = get_personal_agenda_items_between_dates($user_id, $ds, $de); $events_list = Agenda::get_personal_agenda_items_between_dates($user_id, $ds, $de);
return $events_list; return $events_list;
} }

@ -4132,7 +4132,6 @@ function updatePublicationAssignment($workId, $params, $courseInfo, $groupId)
$agendaId = 0; $agendaId = 0;
if (isset($params['add_to_calendar']) && $params['add_to_calendar'] == 1) { if (isset($params['add_to_calendar']) && $params['add_to_calendar'] == 1) {
require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.inc.php';
require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php'; require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php';
// Setting today date // Setting today date

@ -12,30 +12,6 @@ class TestCalendar extends UnitTestCase
//var_dump($res); //var_dump($res);
} }
/**
* Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters
* @param array Course info
* @param string Event title
* @param string Event content/description
* @param string Start date
* @param string End date
* @param array List of groups to which this event is added
* @param int Parent id (optional)
* @return int The new item's DB ID
*/
public function testAgendaAddItem(){
global $_course;
$course_code=$_course;
$course_info = '';
$title='test';
$content='test function';
$db_start_date='07/11/2009';
$db_end_date='07/20/2009';
$res = agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to=array(), $parent_id=null);
$this->assertTrue($res>0,'Global agenda item could not be inserted');
delete_agenda_item($res);
//var_dump($res);
}
public function testStoreNewAgendaItem(){ public function testStoreNewAgendaItem(){
global $_user; global $_user;
@ -49,16 +25,6 @@ class TestCalendar extends UnitTestCase
} }
} }
public function testShowAddForm(){
ob_start();
global $MonthsLong;
$id='';
$res= show_add_form($id);
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testAddWeek(){ public function testAddWeek(){
$timestamp=12; $timestamp=12;
$num=1; $num=1;
@ -98,57 +64,6 @@ class TestCalendar extends UnitTestCase
//this function is not used or deprecated //this function is not used or deprecated
} }
public function testGetCalendarItems(){
global $_course;
$month=01;
$year=2010;
$res = get_calendar_items($month, $year);
$this->assertTrue(is_array($res));
//var_dump($res);
}
//This funtion need a path where will copy to the other folder.
/*
public function testAgendaImportIcal() {
global $_course;
$course_info = $_course;
$file = api_get_path(SYS_PATH).'tests/main/admin/icals/test.ics';
$res = agenda_import_ical($course_info, $file);
if(is_bool($res)){
$this->assertTrue(is_bool($res));
$this->assertTrue($res===false || $res === true);
}else{
$this->assertTrue($res);
}
}
*/
public function testStoreEditedAgendaItem(){
ob_start();
$id=1;
$title='';
$content='';
$start_date= 21;
$end_date=25;
$res = store_edited_agenda_item();
$edit_result=save_edit_agenda_item($id,$title,$content,$start_date,$end_date);
ob_end_clean();
$this->assertTrue($edit_result);
//var_dump($edit_result);
}
public function testSaveEditAgendaItem(){
$id=intval($id);
$title=Database::escape_string($title);
$content=Database::escape_string($content);
$start_date=Database::escape_string($start_date);
$end_date=Database::escape_string($end_date);
$res = save_edit_agenda_item($id,$title,$content,$start_date,$end_date);
$this->assertTrue($res);
$this->assertTrue(is_bool($res));
//var_dump($res);
}
public function testCalculateStartEndOfWeek(){ public function testCalculateStartEndOfWeek(){
$week_number=4; $week_number=4;
$year=2011; $year=2011;
@ -158,44 +73,6 @@ class TestCalendar extends UnitTestCase
//var_dump($res); //var_dump($res);
} }
/**
* Displays all the agenda items
*/
public function testDisplayAgendaItems() {
global $is_courseAdmin;
ob_start();
$TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
$res = display_agenda_items();
ob_end_clean();
$this->assertTrue(is_null($res));
}
public function testDisplayDaycalendar(){
ob_start();
$agendaitems='';
$day='';
$month='';
$year='';
$weekdaynames='';
$monthName='';
$res = display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName);
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testDisplayWeekcalendar() {
ob_start();
$agendaitems='';
$month=10;
$year=2011;
$weekdaynames='';
$monthName='';
$res = display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName);
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testGetDayAgendaitems() { public function testGetDayAgendaitems() {
$courses_dbs=array(); $courses_dbs=array();
@ -204,50 +81,8 @@ class TestCalendar extends UnitTestCase
$day='1'; $day='1';
$res = get_day_agendaitems($courses_dbs, $month, $year, $day); $res = get_day_agendaitems($courses_dbs, $month, $year, $day);
$this->assertTrue(is_array($res)); $this->assertTrue(is_array($res));
//var_dump($res);
} }
public function testGetWeekAgendaitems() {
$courses_dbs=array();
$month=01;
$year=2010;
$res = get_week_agendaitems($courses_dbs, $month, $year);
$this->assertTrue(is_array($res));
}
/* public function testGetRepeatedEventsDayView(){
global $_course;
$start = 0;
$end = 0;
$params = array();
$course_code = 'COURSETEST';
$course_info = api_get_course_info($course_code);
$resul = get_repeated_events_day_view($course_info,$start,$end,$params);
$this->assertTrue(is_array($resul));
}
*/
public function testGetRepeatedEventsWeekView(){
$course_info = 'COURSETEST';
$resul = get_repeated_events_week_view($course_info, 0, 0, '');
$this->assertTrue(is_array($resul));
}
/*
public function testGetRepeatedEventsMonthView(){
$course_code='COURSETEST';
$course_info = api_get_course_info($course_code);
$resul= get_repeated_events_month_view($course_info,0,0,'');
$this->assertTrue(is_array($resul));
//var_dump($resul);
}
public function testGetRepeatedEventsListView(){
$course_code='COURSETEST';
$course_info = api_get_course_info($course_code);
$resul = get_repeated_events_list_view($course_info,0,0,'');
$this->assertTrue(is_array($resul));
//var_dump($resul);
}
*/
public function testDeleteAgendaItem(){ public function testDeleteAgendaItem(){
$id=1; $id=1;
$res = delete_agenda_item($id); $res = delete_agenda_item($id);
@ -266,81 +101,6 @@ class TestCalendar extends UnitTestCase
//var_dump($res); //var_dump($res);
} }
public function testUserGroupFilterJavascript(){
$res = user_group_filter_javascript();
$this->assertTrue($res);
$this->assertTrue(is_string($res));
//var_dump($res);
}
public function testDisplayMonthcalendar(){
ob_start();
global $MonthsLong;
global $DaysShort;
global $origin;
$month=05;
$year=2010;
$res = display_monthcalendar($month, $year);
ob_end_clean();
$this->assertTrue(is_null($res));
$this->assertNull($res);
//var_dump($res);
}
public function testGetAgendaItem(){
$id=4;
$res = get_agenda_item($id);
if(is_array($res)) {
$this->assertTrue(is_array($res));
}
}
/**
* Makes an agenda item visible or invisible for a student
* @param integer id the id of the agenda item we are changing the visibility of
*/
public function testShowhideAgendaItem(){
ob_start();
$id=1;
global $nameTools;
$res = showhide_agenda_item($id);
//Show the message when the visibility was changed
$real_show = Display::display_normal_message(get_lang("VisibilityChanged"));
ob_end_clean();
if(!empty($res)){
$this->assertTrue($res);
$this->assertTrue($real_show);
} else {
$this->assertNull($res);
}
//var_dump($res);
}
/**
* Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
*/
public function testDisplayOneAgendaItem(){
ob_start();
$agenda_id=1;
$res = display_one_agenda_item($agenda_id);
ob_end_clean();
$this->assertTrue(is_null($res));
}
/**
* Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
* agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
* we have to retrieve the information that is in the database and use this information in the forms.
*/
public function testShowGroupFilterForm(){
ob_start();
$res = show_group_filter_form();
ob_end_clean();
$this->assertTrue(is_null($res));
}
public function testShowUserFilterForm(){ public function testShowUserFilterForm(){
ob_start(); ob_start();
$res = show_user_filter_form(); $res = show_user_filter_form();
@ -348,13 +108,6 @@ class TestCalendar extends UnitTestCase
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
} }
public function testDisplayUpcomingEvents(){
ob_start();
$res = display_upcoming_events();
ob_end_clean();
$this->assertNull($res);
}
public function testIsRepeatedEvent() { public function testIsRepeatedEvent() {
//This is deprecated or not used //This is deprecated or not used
} }

@ -35,7 +35,6 @@ $libdir = dirname(__FILE__).'/../main/inc/lib/';
/**Files inside '/../main' */ /**Files inside '/../main' */
require_once $maindir.'permissions/permissions_functions.inc.php'; require_once $maindir.'permissions/permissions_functions.inc.php';
require_once $maindir.'admin/calendar.lib.php';
require_once $maindir.'dropbox/dropbox_class.inc.php'; require_once $maindir.'dropbox/dropbox_class.inc.php';
require_once $maindir.'dropbox/dropbox_functions.inc.php'; require_once $maindir.'dropbox/dropbox_functions.inc.php';
require_once $maindir.'survey/survey.lib.php'; require_once $maindir.'survey/survey.lib.php';

Loading…
Cancel
Save