BeezNest 2011 - Lots of fixes - UI improvements, security fixes,
* @author: Patrick Cool, patrick.cool@UGent.be
* @todo this code should be clean as well as the myagenda.inc.php - jmontoya
* @package chamilo.calendar
*/
/**
* Code
*/
// 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();
$htmlHeadXtra[] = to_javascript();
$htmlHeadXtra[] = '';
/**
* Retrieves all the agenda items from the table
* @author: Patrick Cool , Ghent University
* @author Yannick Warnier - cleanup
* @author Julio Montoya - Refactoring
* @param integer $month: the integer value of the month we are viewing
* @param integer $year: the 4-digit year indication e.g. 2005
* @return array
*/
function get_calendar_items($select_month, $select_year, $select_day = false)
{
$course_info = api_get_course_info();
$select_month = intval($select_month);
$select_year = intval($select_year);
if ($select_day) {
$select_day = intval($select_day);
}
if (!empty($select_month) && !empty($select_year)) {
$show_all_current = " AND MONTH(start_date) = $select_month AND year(start_date) = $select_year";
if ($select_day) {
$show_all_current .= ' AND DAY(start_date) = '.$select_day;
}
$show_all_current_personal = " AND MONTH(date) = $select_month AND year(date) = $select_year";
if ($select_day) {
$show_all_current_personal .= ' AND DAY(date) = '.$select_day;
}
} else {
$show_all_current = '';
$show_all_current_personal = '';
}
// database variables
$TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
$TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$group_memberships = GroupManager::get_group_ids($course_info['real_id'], api_get_user_id());
$repeats = array();
/* CONSTRUCT THE SQL STATEMENT */
// by default we use the id of the current user. The course administrator can see the agenda of other users by using the user / group filter
$user_id = api_get_user_id();
if (isset($_SESSION['user'])) {
$user_id = intval($_SESSION['user']);
}
$group_id = api_get_group_id();
$session_condition = api_get_session_condition(api_get_session_id());
if (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())
) {
// A.1. you are a course admin with a USER filter
// => see only the messages of this specific user + the messages of the group (s)he is member of.
if (!empty($_SESSION['user'])) {
$group_memberships = GroupManager::get_group_ids($course_info['real_id'], $_SESSION['user']);
$show_user = true;
$new_group_memberships = array();
foreach ($group_memberships as $id) {
// did i have access to the same
$has_access = GroupManager::user_has_access(api_get_user_id(), $id, GroupManager::GROUP_TOOL_CALENDAR);
$result = GroupManager::get_group_properties($id);
if ($has_access && $result['calendar_state'] != '0') {
$new_group_memberships[] = $id;
}
}
$group_memberships = $new_group_memberships;
if (is_array($group_memberships) && count($group_memberships) > 0) {
$sql = "SELECT
agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
WHERE agenda.id = ip.ref ".$show_all_current."
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'
$session_condition";
} else {
//AND ( ip.to_user_id=$user_id OR ip.to_group_id='0')
$sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
WHERE agenda.id = ip.ref ".$show_all_current."
AND ip.tool='".TOOL_CALENDAR_EVENT."'
AND ( ip.to_user_id = $user_id )
AND ip.visibility='1'
$session_condition";
}
}
// A.2. you are a course admin with a GROUP filter
// => see only the messages of this specific group
elseif (!empty($_SESSION['group'])) {
if (!empty($group_id)) {
$result = GroupManager::get_group_properties($group_id);
$has_access = GroupManager::user_has_access(
api_get_user_id(),
$group_id,
GroupManager::GROUP_TOOL_CALENDAR
);
//echo '
';print_R($result);
// lastedit
if (!$has_access || $result['calendar_state'] == '0') {
$group_id = 0;
}
}
$sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
WHERE agenda.id = ip.ref ".$show_all_current."
AND ip.tool='".TOOL_CALENDAR_EVENT."'
AND ( ip.to_group_id=$group_id)
AND ip.lastedit_type<>'CalendareventDeleted'
$session_condition
GROUP BY ip.ref";
//removed - > AND toolitemproperties.visibility='1'
}
// A.3 you are a course admin without any group or user filter
else {
// A.3.a you are a course admin without user or group filter but WITH studentview
// => see all the messages of all the users and groups without editing possibilities
if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
$sql = "SELECT
agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
WHERE agenda.id = ip.ref ".$show_all_current."
AND ip.tool='".TOOL_CALENDAR_EVENT."'
AND ip.visibility='1'
$session_condition
GROUP BY ip.ref
ORDER $sort_item $sort";
}
// A.3.b you are a course admin or a student
else {
// A.3.b.1 you are a course admin without user or group filter and WITHOUT studentview (= the normal course admin view)
// => see all the messages of all the users and groups with editing possibilities
if (api_is_course_admin()) {
$sql = "SELECT
agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
WHERE agenda.id = ip.ref ".$show_all_current."
AND ip.tool='".TOOL_CALENDAR_EVENT."'
AND ( ip.visibility='0' OR ip.visibility='1')
$session_condition
GROUP BY ip.ref";
} else {
// A.3.b.2 you are a student with no group filter possibly showall
//when showing all the events we do not show the group events
//todo showing ALL events including the groups events that are available
$sql = "SELECT
agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
WHERE agenda.id = ip.ref ".$show_all_current."
AND ip.tool='".TOOL_CALENDAR_EVENT."'
AND ( ip.visibility='0' OR ip.visibility='1')
$session_condition
GROUP BY ip.ref";
/*
if (is_array($group_memberships) && count($group_memberships)>0)
{
echo $sql="SELECT
agenda.*, toolitemproperties.*
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).")
$session_condition
GROUP BY toolitemproperties.ref
ORDER BY start_date ".$sort;
}
else
{
$sql="SELECT
agenda.*, toolitemproperties.*
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id='0'
$session_condition
GROUP BY toolitemproperties.ref
ORDER BY start_date ".$sort;
}
*/
}
}
}
} //if (is_allowed_to_edit() OR( api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
// B. you are a student
else {
if (is_array($group_memberships) && count($group_memberships) > 0) {
$sql = "SELECT
agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
WHERE agenda.id = ip.ref ".$show_all_current."
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'
$session_condition";
} else {
if (api_get_user_id()) {
$sql = "SELECT
agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
WHERE agenda.id = ip.ref ".$show_all_current."
AND ip.tool='".TOOL_CALENDAR_EVENT."'
AND ( ip.to_user_id=$user_id OR ip.to_group_id='0')
AND ip.visibility='1'
$session_condition";
} else {
$sql = "SELECT
agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
WHERE agenda.id = ip.ref ".$show_all_current."
AND ip.tool='".TOOL_CALENDAR_EVENT."'
AND ip.to_group_id='0'
AND ip.visibility='1'
$session_condition";
}
}
} // you are a student
$my_events = array();
$avoid_doubles = array();
$result = Database::query($sql);
//Course venets
while ($row = Database::fetch_array($result, 'ASSOC')) {
$row['calendar_type'] = 'course';
if (!in_array($row['id'], $avoid_doubles)) {
if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
$row['start_date'] = api_get_local_time($row['start_date']);
$row['start_date_tms'] = api_strtotime($row['start_date']);
}
if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
$row['end_date'] = api_get_local_time($row['end_date']);
$row['end_date_tms'] = api_strtotime($row['end_date']);
}
$my_events[] = $row;
$avoid_doubles[] = $row['id'];
}
}
//Check my personal calendar items
if (api_get_setting('allow_personal_agenda') == 'true' && empty($_SESSION['user']) && empty($_SESSION['group'])) {
$tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA);
// 1. creating the SQL statement for getting the personal agenda items in MONTH view
$sql = "SELECT id, title, text as content , date as start_date, enddate as end_date, parent_event_id FROM ".$tbl_personal_agenda."
WHERE user='".api_get_user_id()."' ".$show_all_current_personal;
$result = Database::query($sql);
while ($row = Database::fetch_array($result, 'ASSOC')) {
$row['calendar_type'] = 'personal';
if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
$row['start_date'] = api_get_local_time($row['start_date']);
$row['start_date_tms'] = api_strtotime($row['start_date']);
}
if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
$row['end_date'] = api_get_local_time($row['end_date']);
$row['end_date_tms'] = api_strtotime($row['end_date']);
}
$my_events[] = $row;
}
}
//Check global agenda events
if (empty($_SESSION['user']) && empty($_SESSION['group'])) {
$table_agenda_system = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
$current_access_url_id = api_get_current_access_url_id();
$sql = "SELECT DISTINCT id, title, content , start_date, end_date FROM ".$table_agenda_system."
WHERE 1=1 ".$show_all_current." AND access_url_id = $current_access_url_id";
$result = Database::query($sql);
while ($row = Database::fetch_array($result, 'ASSOC')) {
if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
$row['start_date'] = api_get_local_time($row['start_date']);
$row['start_date_tms'] = api_strtotime($row['start_date']);
}
if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
$row['end_date'] = api_get_local_time($row['end_date']);
$row['end_date_tms'] = api_strtotime($row['end_date']);
}
$row['calendar_type'] = 'global';
$my_events[] = $row;
}
}
return $my_events;
}
/**
* show the mini calender of the given month
* @author: Patrick Cool , Ghent University
* @param array an array containing all the agenda items for the given month
* @param integer $month: the integer value of the month we are viewing
* @param integer $year: the 4-digit year indication e.g. 2005
* @param string $monthName: the language variable for the mont name
* @return html code
* @todo refactor this so that $monthName is no longer needed as a parameter
*/
function display_minimonthcalendar($agenda_items, $month, $year)
{
global $DaysShort, $MonthsLong;
if (empty($month)) {
$month = intval(date('m'));
}
if (empty($year)) {
$month = date('Y');
}
$month_name = $MonthsLong[$month - 1];
//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;
$backwardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath']) ? '' : Security::remove_XSS($_GET['coursePath']))."&courseCode=".(empty($_GET['courseCode']) ? '' : Security::remove_XSS($_GET['courseCode']))."&month=".($month == 1 ? 12 : $month - 1)."&year=".($month == 1 ? $year - 1 : $year);
$forewardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath']) ? '' : Security::remove_XSS($_GET['coursePath']))."&courseCode=".(empty($_GET['courseCode']) ? '' : Security::remove_XSS($_GET['courseCode']))."&month=".($month == 12 ? 1 : $month + 1)."&year=".($month == 12 ? $year + 1 : $year);
$month_link = Display::url($month_name." ".$year, api_get_self()."?".api_get_cidreq()."&month=".($month)."&year=".$year);
$new_items = array();
foreach ($agenda_items as $item) {
$day = intval(substr($item["start_date"], 8, 2));
$my_month = intval(substr($item["start_date"], 5, 2));
if ($my_month == $month) {
$new_items[$day][] = 1;
}
}
$agenda_items = $new_items;
echo "
';
}
/**
* returns all the javascript that is required for easily selecting the target people/groups this goes into the $htmlHeadXtra[] array
* @author: Patrick Cool , Ghent University
* @return javascript code
*/
function to_javascript()
{
$showImg = Display::return_icon('div_show.gif');
$hideImg = Display::return_icon('div_hide.gif');
return "";
}
/**
* returns the javascript for setting a filter. This is a jump menu
* @author: Patrick Cool , Ghent University
* @return javascript code
*/
function user_group_filter_javascript()
{
return "";
}
/**
* this function gets all the users of the current course
* @author Patrick Cool , Ghent University
* @return array: associative array where the key is the id of the user and the value is an array containing
the first name, the last name, the user id
*/
function get_course_users()
{
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
// not 100% if this is necessary, this however prevents a notice
if (!isset($courseadmin_filter)) {
$courseadmin_filter = '';
}
//
$order_clause = api_sort_by_first_name(
) ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname';
$sql = "SELECT u.user_id uid, u.lastname lastName, u.firstname firstName, u.username
FROM $tbl_user as u, $tbl_courseUser as cu
WHERE cu.c_id = '".api_get_course_int_id()."'
AND cu.user_id = u.user_id $courseadmin_filter".$order_clause;
$result = Database::query($sql);
while ($user = Database::fetch_array($result)) {
$users[$user[0]] = $user;
}
$session_id = api_get_session_id();
if (!empty($session_id)) {
$users = array();
$sql = "SELECT u.user_id uid, u.lastname lastName, u.firstName firstName, u.username
FROM $tbl_session_course_user AS session_course_user
INNER JOIN $tbl_user u ON u.user_id = session_course_user.id_user
WHERE id_session = ".$session_id."
AND c_id = '".api_get_course_int_id()."'";
$result = Database::query($sql);
while ($user = Database::fetch_array($result)) {
$users[$user[0]] = $user;
}
}
return $users;
}
/**
* this function gets all the groups of the course
* @author Patrick Cool , Ghent University
* @return array
*/
function get_course_groups()
{
$group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
return $group_list;
}
/**
* this function shows the form for sending a message to a specific group or user.
* @author: Patrick Cool , Ghent University
*
* @return html code
*/
function show_to_form($to_already_selected)
{
$order = 'lastname';
if (api_is_western_name_order()) {
$order = 'firstname';
}
$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
$group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
construct_not_selected_select_form($group_list, $user_list, $to_already_selected);
}
/**
* this function shows the form with the user that were not selected
* @author: Patrick Cool , Ghent University
* @return html code
*/
function construct_not_selected_select_form($group_list = null, $user_list = null, $to_already_selected = array())
{
echo '";
}
function show_to($filter = 0, $id = null)
{
$order = 'lastname';
if (api_is_western_name_order()) {
$order = 'firstname';
}
$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
$group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
return construct_to_select_form($group_list, $user_list, $filter, $id);
}
function construct_to_select_form($group_list = null, $user_list = null, $filter = 0, $id = null)
{
$result = '";
return $result;
}
/**
* This function shows the form with the user that were selected
* @author: Patrick Cool , Ghent University
* @return html code
*/
function construct_selected_select_form($group_list = null, $user_list = null, $to_already_selected)
{
// we separate the $to_already_selected array (containing groups AND users into
// two separate arrays
if (is_array($to_already_selected)) {
$groupuser = separate_users_groups($to_already_selected);
}
$groups_to_already_selected = $groupuser['groups'];
$users_to_already_selected = $groupuser['users'];
// we load all the groups and all the users into a reference array that we use to search the name of the group / user
$ref_array_groups = get_course_groups();
$ref_array_users = get_course_users();
// we construct the form of the already selected groups / users
echo "";
}
/**
* This function stores the Agenda Item in the table calendar_event and updates the item_property table also
* @author: Patrick Cool , Ghent University
* @return integer the id of the last added agenda item
*/
function store_new_agenda_item()
{
$_course = api_get_course_info();
$TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
$t_agenda_repeat = Database::get_course_Table(TABLE_AGENDA_REPEAT);
$course_id = api_get_course_int_id();
// some filtering of the input data
$title = trim($_POST['title']); // no html allowed in the title
$content = trim($_POST['content']);
$start_date = (int) $_POST['fyear']."-".(int) $_POST['fmonth']."-".(int) $_POST['fday']." ".(int) $_POST['fhour'].":".(int) $_POST['fminute'].":00";
$end_date = (int) $_POST['end_fyear']."-".(int) $_POST['end_fmonth']."-".(int) $_POST['end_fday']." ".(int) $_POST['end_fhour'].":".(int) $_POST['end_fminute'].":00";
$title = Database::escape_string($title);
$content = Database::escape_string($content);
$start_date = Database::escape_string($start_date);
$end_date = Database::escape_string($end_date);
if ($_POST['empty_end_date'] == 'on') {
$end_date = "0000-00-00 00:00:00";
}
// store in the table calendar_event
$sql = "INSERT INTO ".$TABLEAGENDA." (c_id, title,content, start_date, end_date)
VALUES ($course_id, '".$title."','".$content."', '".$start_date."','".$end_date."')";
$result = Database::query($sql);
$last_id = Database::insert_id();
// store in last_tooledit (first the groups, then the users
$to = $_POST['selectedform'];
if ((!is_null($to)) || (!empty($_SESSION['toolgroup']))) { // !is_null($to): when no user is selected we send it to everyone
//$send_to=separate_users_groups($to);
$send_to = separate_users_groups(explode('|', $to));
// storing the selected groups
if (is_array($send_to['groups'])) {
foreach ($send_to['groups'] as $group) {
api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), $group, '', $start_date, $end_date);
}
}
// storing the selected users
if (is_array($send_to['users'])) {
foreach ($send_to['users'] as $user) {
api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), '', $user, $start_date, $end_date);
}
}
} else { // the message is sent to everyone, so we set the group to 0
api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), '', '', $start_date, $end_date);
}
// storing the resources
store_resources($_SESSION['source_type'], $last_id);
$course_id = api_get_course_int_id();
//if repetitive, insert element into agenda_repeat table
if (!empty($_POST['repeat']) && !empty($_POST['repeat_type'])) {
if (!empty($_POST['repeat_end_year']) && !empty($_POST['repeat_end_month']) && !empty($_POST['repeat_end_day'])) {
$end_y = intval($_POST['repeat_end_year']);
$end_m = intval($_POST['repeat_end_month']);
$end_d = intval($_POST['repeat_end_day']);
$end = mktime((int) $_POST['fhour'], (int) $_POST['fminute'], 0, $end_m, $end_d, $end_y);
$now = time();
$type = Database::escape_string($_POST['repeat_type']);
if ($end > $now && in_array($type, array('daily', 'weekly', 'monthlyByDate', 'monthlyByDay', 'monthlyByDayR', 'yearly'))) {
$sql = "INSERT INTO $t_agenda_repeat (c_id, cal_id, cal_type, cal_end)".
" VALUES ($course_id, $last_id,'$type',$end)";
$res = Database::query($sql);
}
}
}
return $last_id;
}
/**
* Stores the given agenda item as an announcement (unlinked copy)
* @param integer Agenda item's ID
* @return integer New announcement item's ID
*/
function store_agenda_item_as_announcement($item_id)
{
$table_agenda = Database::get_course_table(TABLE_AGENDA);
$table_ann = Database::get_course_table(TABLE_ANNOUNCEMENT);
//check params
if (empty($item_id) or $item_id != strval(intval($item_id))) {
return -1;
}
//get the agenda item
$item_id = Database::escape_string($item_id);
$sql = "SELECT * FROM $table_agenda WHERE id = ".$item_id;
$res = Database::query($sql);
$course_id = api_get_course_int_id();
if (Database::num_rows($res) > 0) {
$row = Database::fetch_array($res);
//we have the agenda event, copy it
//get the maximum value for display order in announcement table
$sql_max = "SELECT MAX(display_order) FROM $table_ann WHERE c_id = $course_id ";
$res_max = Database::query($sql_max);
$row_max = Database::fetch_array($res_max);
$max = intval($row_max[0]) + 1;
//build the announcement text
$content = $row['content'];
//insert announcement
$session_id = api_get_session_id();
$sql_ins = "INSERT INTO $table_ann (c_id, title,content,end_date,display_order,session_id) ".
"VALUES ($course_id, '".Database::escape_string($row['title'])."','".Database::escape_string($content)."','".Database::escape_string($row['end_date'])."','$max','$session_id')";
$res_ins = Database::query($sql_ins);
if ($res > 0) {
$ann_id = Database::insert_id();
//Now also get the list of item_properties rows for this agenda_item (calendar_event)
//and copy them into announcement item_properties
$table_props = Database::get_course_table(TABLE_ITEM_PROPERTY);
$sql_props = "SELECT * FROM $table_props WHERE tool = 'calendar_event' AND ref='$item_id'";
$res_props = Database::query($sql_props);
if (Database::num_rows($res_props) > 0) {
while ($row_props = Database::fetch_array($res_props)) {
//insert into announcement item_property
$time = api_get_utc_datetime();
$sql_ins_props = "INSERT INTO $table_props ".
"(c_id, tool, insert_user_id, insert_date, ".
"lastedit_date, ref, lastedit_type,".
"lastedit_user_id, to_group_id, to_user_id, ".
"visibility, start_visible, end_visible)".
" VALUES ".
"($course_id, 'announcement','".$row_props['insert_user_id']."','".$time."',".
"'$time','$ann_id','AnnouncementAdded',".
"'".$row_props['last_edit_user_id']."','".$row_props['to_group_id']."','".$row_props['to_user_id']."',".
"'".$row_props['visibility']."','".$row_props['start_visible']."','".$row_props['end_visible']."')";
$res_ins_props = Database::query($sql_ins_props);
if ($res_ins_props <= 0) {
return -1;
} else {
//copy was a success
return $ann_id;
}
}
}
} else {
return -1;
}
}
return -1;
}
/**
* This function separates the users from the groups
* users have a value USER:XXX (with XXX the dokeos id
* groups have a value GROUP:YYY (with YYY the group id)
* @author: Patrick Cool , Ghent University
* @return array
*/
function separate_users_groups($to)
{
$grouplist = array();
$userlist = array();
$send_to = null;
$send_to['everyone'] = false;
if (is_array($to) && count($to) > 0) {
foreach ($to as $to_item) {
list($type, $id) = explode(':', $to_item);
switch ($type) {
case 'everyone':
$send_to['everyone'] = true;
case 'GROUP':
$grouplist[] = $id;
break;
case 'USER':
$userlist[] = $id;
break;
}
}
$send_to['groups'] = $grouplist;
$send_to['users'] = $userlist;
}
return $send_to;
}
/**
* returns all the users and all the groups a specific Agenda item has been sent to
* @author: Patrick Cool , Ghent University
* @return array
*/
function sent_to($tool, $id)
{
$TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$tool = Database::escape_string($tool);
$id = Database::escape_string($id);
$sql = "SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".$tool."' AND ref='".$id."'";
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
// if to_group_id is null then it is sent to a specific user
// if to_group_id = 0 then it is sent to everybody
if (!is_null($row['to_group_id'])) {
$sent_to_group[] = $row['to_group_id'];
//echo $row['to_group_id'];
}
// if to_user_id <> 0 then it is sent to a specific user
if ($row['to_user_id'] <> 0) {
$sent_to_user[] = $row['to_user_id'];
}
}
if (isset($sent_to_group)) {
$sent_to['groups'] = $sent_to_group;
}
if (isset($sent_to_user)) {
$sent_to['users'] = $sent_to_user;
}
return $sent_to;
}
/**
* constructs the form to display all the groups and users the message has been sent to
* @author: Patrick Cool , Ghent University
* @param array $sent_to_array: a 2 dimensional array containing the groups and the users
* the first level is a distinction between groups and users: $sent_to_array['groups'] and $sent_to_array['users']
* $sent_to_array['groups'] (resp. $sent_to_array['users']) is also an array containing all the id's of the
* groups (resp. users) who have received this message.
* @return html
*/
function sent_to_form($sent_to_array)
{
// we find all the names of the groups
$group_names = get_course_groups();
// we count the number of users and the number of groups
if (isset($sent_to_array['users'])) {
$number_users = count($sent_to_array['users']);
} else {
$number_users = 0;
}
if (isset($sent_to_array['groups'])) {
$number_groups = count($sent_to_array['groups']);
} else {
$number_groups = 0;
}
$total_numbers = $number_users + $number_groups;
$output = array();
// starting the form if there is more than one user/group
if ($total_numbers > 1) {
//$output.="";
// outputting the name of the groups
if (is_array($sent_to_array['groups'])) {
foreach ($sent_to_array['groups'] as $group_id) {
if (isset($group_names[$group_id]['name'])) {
$output[] = $group_names[$group_id]['name'];
}
}
}
if (isset($sent_to_array['users'])) {
if (is_array($sent_to_array['users'])) {
foreach ($sent_to_array['users'] as $user_id) {
// @todo add username as tooltip - is this fucntion still used ?
// $user_info= api_get_user_info($user_id);
// $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
$output[] = api_get_person_name($user_info['firstName'], $user_info['lastName']);
}
}
}
} else {
// there is only one user/group
if (is_array($sent_to_array['users'])) {
// @todo add username as tooltip - is this fucntion still used ?
// $user_info = api_get_user_info($sent_to_array['users'][0]);
// $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
$output[] = api_get_person_name($user_info['firstName'], $user_info['lastName']);
}
if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0] !== 0) {
$group_id = $sent_to_array['groups'][0];
$output[] = $group_names[$group_id]['name'];
}
if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0] == 0) {
$output[] = get_lang("Everybody");
}
}
if (!empty($output)) {
$output = array_filter($output);
if (count($output) > 0) {
$output = implode(', ', $output);
}
return $output;
}
}
/**
* This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
* @author: Patrick Cool , Ghent University
*/
function show_group_filter_form()
{
$group_list = get_course_groups();
echo "";
}
/**
* This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
* @author: Patrick Cool , Ghent University
*/
function show_user_filter_form()
{
$user_list = get_course_users();
echo "";
}
/**
* This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
* @author: Patrick Cool , Ghent University
*/
function show_user_group_filter_form()
{
echo "";
}
/**
* This tools loads all the users and all the groups who have received a specific item (in this case an agenda item)
* @author: Patrick Cool , Ghent University
*/
function load_edit_users($tool, $id)
{
$tool = Database::escape_string($tool);
$id = Database::escape_string($id);
$TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$course_id = api_get_course_int_id();
$sql = "SELECT * FROM $TABLE_ITEM_PROPERTY WHERE c_id = $course_id AND tool='$tool' AND ref='$id'";
$result = Database::query($sql) or die(Database::error());
$to = array();
while ($row = Database::fetch_array($result)) {
$to_group = $row['to_group_id'];
switch ($to_group) {
// it was send to one specific user
case null:
$to[] = "USER:".$row['to_user_id'];
break;
// it was sent to everyone
case 0:
return "everyone";
exit;
break;
default:
$to[] = "GROUP:".$row['to_group_id'];
}
}
return $to;
}
/**
* This functions swithes the visibility a course resource using the visible field in 'last_tooledit' values: 0 = invisible
* @author: Patrick Cool , Ghent University
*/
function change_visibility($tool, $id, $visibility)
{
$_course = api_get_course_info();
$TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$tool = Database::escape_string($tool);
$id = Database::escape_string($id);
/*
$sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".TOOL_CALENDAR_EVENT."' AND ref='$id'";
$result=Database::query($sql) or die (Database::error());
$row=Database::fetch_array($result);
*/
if ($visibility == 0) {
$sql_visibility = "UPDATE $TABLE_ITEM_PROPERTY SET visibility='0' WHERE tool='$tool' AND ref='$id'";
api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "invisible", api_get_user_id());
} else {
$sql_visibility = "UPDATE $TABLE_ITEM_PROPERTY SET visibility='1' WHERE tool='$tool' AND ref='$id'";
api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "visible", api_get_user_id());
}
}
/**
* The links that allows the course administrator to add a new agenda item, to filter on groups or users
* @author Patrick Cool , Ghent University
*/
function display_courseadmin_links($filter = 0)
{
if (!api_get_course_int_id()) {
$type = isset($_REQUEST['type']) ? Security::remove_XSS($_REQUEST['type']) : 'personal';
if ($type == 'platform') {
$type = 'admin';
}
return "".Display::return_icon('calendar.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."";
}
$form = null;
if (!isset($_GET['action'])) {
$form = show_to($filter, 'selected_form_id_search');
$actions = "".Display::return_icon('calendar_na.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."";
} else {
$actions = "".Display::return_icon('calendar.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."";
}
$actions .= "".Display::return_icon('new_event.png', get_lang('AgendaAdd'), '', ICON_SIZE_MEDIUM)."";
$actions .= "".Display::return_icon('import_calendar.png', get_lang('ICalFileImport'), '', ICON_SIZE_MEDIUM)."";
$actions .= $form;
return $actions;
}
/**
* The links that allows the student AND course administrator to show all agenda items and sort up/down
* @author Patrick Cool , Ghent University
* @author Julio Montoya removing options, changing to a simple agenda tool
*/
function display_student_links()
{
global $show;
$month = isset($_GET['month']) ? intval($_GET['month']) : null;
$year = isset($_GET['year']) ? intval($_GET['year']) : null;
$day_url = '&month='.$month.'&year='.$year;
if ($_SESSION['view'] <> 'month') {
echo "".Display::return_icon('month_empty.png', get_lang('MonthView'), '', ICON_SIZE_MEDIUM)." ";
} else {
echo "".Display::return_icon('week.png', get_lang('ListView'), '', ICON_SIZE_MEDIUM)." ";
}
$day_url = '&month='.date('m').'&year='.date('Y').'&view='.Security::remove_XSS($_GET['view']);
$today_url = api_get_self()."?action=view".$day_url."&toolgroup=".api_get_group_id();
echo Display::url(get_lang('Today'), $today_url, array('class' => 'btn'));
}
/**
* get all the information of the agenda_item from the database
* @author Patrick Cool , Ghent University
* @param integer the id of the agenda item we are getting all the information of
* @return array an associative array that contains all the information of the agenda item. The keys are the database fields
*/
function get_agenda_item($id)
{
global $TABLEAGENDA;
$t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT);
$id = Database::escape_string($id);
$item = array();
if (empty($id)) {
$id = intval(Database::escape_string(($_GET['id'])));
} else {
$id = (int) $id;
}
$course_id = api_get_course_int_id();
if (empty($id)) {
return $item;
}
$sql = "SELECT * FROM ".$TABLEAGENDA." WHERE id='".$id."' AND c_id = $course_id ";
$result = Database::query($sql);
$entry_to_edit = Database::fetch_array($result);
$item['title'] = $entry_to_edit["title"];
$item['content'] = $entry_to_edit["content"];
$item['start_date'] = $entry_to_edit["start_date"];
$item['end_date'] = $entry_to_edit["end_date"];
$item['to'] = load_edit_users(TOOL_CALENDAR_EVENT, $id);
// if the item has been sent to everybody then we show the compact to form
if ($item['to'] == "everyone") {
$_SESSION['allow_individual_calendar'] = "hide";
} else {
$_SESSION['allow_individual_calendar'] = "show";
}
$item['repeat'] = false;
$sql = "SELECT * FROM $t_agenda_repeat WHERE c_id = $course_id AND cal_id = $id";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
//this event is repetitive
$row = Database::fetch_array($res);
$item['repeat'] = true;
$item['repeat_type'] = $row['cal_type'];
$item['repeat_end'] = $row['cal_end'];
$item['repeat_frequency'] = $row['cal_frequency']; //unused in 1.8.5 RC1 - will be used later to say if once every 2 or 3 weeks, for example
$item['repeat_days'] = $row['cal_days']; //unused in 1.8.5 RC1 - will be used later
}
//TODO - add management of repeat exceptions
return $item;
}
/**
* This is the function that updates an agenda item. It does 3 things
* 1. storethe start_date, end_date, title and message in the calendar_event table
* 2. store the groups/users who this message is meant for in the item_property table
* 3. modify the attachments (if needed)
* @author Patrick Cool , Ghent University
* @author Julio Montoya Adding UTC support
*/
function store_edited_agenda_item($event_id, $id_attach, $file_comment)
{
// STEP 1: editing the calendar_event table
// 1.a. some filtering of the input data
$id = $event_id;
$title = strip_tags(trim($_POST['title'])); // no html allowed in the title
$content = trim($_POST['content']);
$start_date = (int) $_POST['fyear']."-".(int) $_POST['fmonth']."-".(int) $_POST['fday']." ".(int) $_POST['fhour'].":".(int) $_POST['fminute'].":00";
$end_date = (int) $_POST['end_fyear']."-".(int) $_POST['end_fmonth']."-".(int) $_POST['end_fday']." ".(int) $_POST['end_fhour'].":".(int) $_POST['end_fminute'].":00";
$to = $_POST['selectedform'];
if ($_POST['empty_end_date'] == 'on') {
$end_date = "0000-00-00 00:00:00";
}
$course_info = api_get_course_info();
$agendaObj = new Agenda();
if (empty($course_info)) {
$agendaObj->type = 'personal';
} else {
$agendaObj->set_course($course_info);
$agendaObj->type = 'course';
if (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id)) {
return false;
}
if (!api_is_allowed_to_edit(null, true)) {
return false;
}
}
$all_day = isset($_REQUEST['all_day']) && !empty($_REQUEST['all_day']) ? 1 : 0;
$agendaObj->edit_event($id, $start_date, $end_date, $all_day, null, $title, $content);
if (empty($id_attach)) {
add_agenda_attachment_file($file_comment, $id);
} else {
edit_agenda_attachment_file($file_comment, $id, $id_attach);
}
// step 2: editing the item_property table (=delete all and add the new destination users/groups)
/*if ($edit_result = true) {
// 2.a. delete everything for the users
$sql_delete = "DELETE FROM ".$TABLE_ITEM_PROPERTY." WHERE c_id = $course_id AND ref='$id' AND tool='".TOOL_CALENDAR_EVENT."'";
$result = Database::query($sql_delete) or die(Database::error());
// 2.b. storing the new users/groups
if (!is_null($to)) { // !is_null($to): when no user is selected we send it to everyone
$send_to = separate_users_groups($to);
// storing the selected groups
if (is_array($send_to['groups'])) {
foreach ($send_to['groups'] as $group) {
api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "AgendaModified", api_get_user_id(), $group, '', $start_date, $end_date);
}
}
// storing the selected users
if (is_array($send_to['users'])) {
foreach ($send_to['users'] as $user) {
api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "AgendaModified", api_get_user_id(), '', $user, $start_date, $end_date);
}
}
} else {
// the message is sent to everyone, so we set the group to 0
api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "AgendaModified", api_get_user_id(), '', '', $start_date, $end_date);
}
}*/
// step 3: update the attachments (=delete all and add those in the session
update_added_resources("Agenda", $id);
// return the message;
Display::display_confirmation_message(get_lang("EditSuccess"));
}
/**
* This function stores the Agenda Item in the table calendar_event and updates the item_property table also (after an edit)
* @author: Patrick Cool , Ghent University
*/
function save_edit_agenda_item($id, $title, $content, $start_date, $end_date)
{
$TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
$id = Database::escape_string($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);
// store the modifications in the table calendar_event
$sql = "UPDATE ".$TABLEAGENDA."
SET title ='".$title."',
content ='".$content."',
start_date ='".$start_date."',
end_date ='".$end_date."'
WHERE id='".$id."'";
$result = Database::query($sql);
return true;
}
/**
* This is the function that deletes an agenda item.
* The agenda item is no longer physically deleted but the visibility in the item_property table is set to 2
* which means that it is invisible for the student AND course admin. Only the platform administrator can see it.
* This will in a later stage allow the platform administrator to recover resources that were mistakenly deleted
* by the course administrator
* @author Patrick Cool , Ghent University
* @param integer the id of the agenda item wa are deleting
*/
function delete_agenda_item($id)
{
$_course = api_get_course_info();
$id = Database::escape_string($id);
if (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())
) {
if (!empty($_GET['id']) && isset($_GET['action']) && $_GET['action'] == "delete") {
$t_agenda = Database::get_course_table(TABLE_AGENDA);
$t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT);
$id = intval($_GET['id']);
$sql = "SELECT * FROM $t_agenda_r WHERE cal_id = $id";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
$sql_children = "SELECT * FROM $t_agenda WHERE parent_event_id = $id";
$res_children = Database::query($sql_children);
if (Database::num_rows($res_children) > 0) {
while ($row_child = Database::fetch_array($res_children)) {
api_item_property_update($_course, TOOL_CALENDAR_EVENT, $row_child['id'], 'delete', api_get_user_id());
}
}
$sql_del = "DELETE FROM $t_agenda_r WHERE cal_id = $id";
$res_del = Database::query($sql_del);
}
//$sql = "DELETE FROM ".$TABLEAGENDA." WHERE id='$id'";
//$sql= "UPDATE ".$TABLE_ITEM_PROPERTY." SET visibility='2' WHERE tool='Agenda' and ref='$id'";
//$result = Database::query($sql) or die (Database::error());
api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, 'delete', api_get_user_id());
// delete the resources that were added to this agenda item
// 2DO: as we no longer fysically delete the agenda item (to make it possible to 'restore'
// deleted items, we should not delete the added resources either.
// delete_added_resource("Agenda", $id); // -> this is no longer needed as the message is not really deleted but only visibility=2 (only platform admin can see it)
//resetting the $id;
$id = null;
// displaying the result message in the yellow box
Display::display_confirmation_message(get_lang("AgendaDeleteSuccess"));
} // if (isset($id)&&$id&&isset($action)&&$action=="delete")
} // if ($is_allowed_to_edit)
}
/**
* Makes an agenda item visible or invisible for a student
* @author Patrick Cool , Ghent University
* @param integer id the id of the agenda item we are changing the visibility of
*/
function showhide_agenda_item($id)
{
global $nameTools;
/*
SHOW / HIDE A CALENDAR ITEM
*/
// and $_GET['isStudentView']<>"false" is added to prevent that the visibility is changed after you do the following:
// change visibility -> studentview -> course manager view
if ((api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) and $_GET['isStudentView'] <> "false") {
if (isset($_GET['id']) && isset($_GET['action']) && $_GET['action'] == "showhide") {
$id = (int) addslashes($_GET['id']);
if (isset($_GET['next_action']) && $_GET['next_action'] == strval(intval($_GET['next_action']))) {
$visibility = $_GET['next_action'];
change_visibility($nameTools, $id, $visibility);
Display::display_confirmation_message(get_lang("VisibilityChanged"));
}
}
}
}
/**
* Displays all the agenda items
* @author Patrick Cool , Ghent University
* @author Yannick Warnier - cleanup
* @author Julio Montoya - Refactoring
*/
function display_agenda_items($agenda_items, $day = false)
{
global $charset;
if (isset($day) && $day) {
$new_items = array();
foreach ($agenda_items as $item) {
if (substr($item['start_date'], 8, 2) == $day) {
$new_items[] = $item;
}
}
$agenda_items = $new_items;
}
if (isset($_GET['sort']) && $_GET['sort'] == 'asc') {
$sort_inverse = 'desc';
$sort = 'asc';
} else {
$sort_inverse = 'asc';
$sort = 'desc';
}
if (isset($_GET['col']) && $_GET['col'] == 'end') {
$sort_item = 'end_date_tms';
$col = 'end';
} else {
$sort_item = 'start_date_tms';
$col = 'start';
}
$agenda_items = ArrayClass::msort($agenda_items, $sort_item, $sort);
//DISPLAY: NO ITEMS
if (empty($agenda_items)) {
echo Display::display_warning_message(get_lang('NoAgendaItems'));
} else {
echo '
";
} // end while ($myrow=Database::fetch_array($result))
echo "
";
}
if (!empty($event_list)) {
$event_list = api_substr($event_list, 0, -1);
} else {
$event_list = '0';
}
echo "";
// closing the layout table
echo "",
"",
"";
}
/**
* Show a list with all the attachments according to the post's id
* @param the post's id
* @return array with the post info
* @author Christian Fasanando
* @version November 2008, dokeos 1.8.6
*/
function get_attachment($agenda_id, $course_id = null)
{
$agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
if (empty($course_id)) {
$course_id = api_get_course_int_id();
} else {
$course_id = intval($course_id);
}
$agenda_id = Database::escape_string($agenda_id);
$row = array();
$sql = 'SELECT id,path, filename,comment FROM '.$agenda_table_attachment.' WHERE c_id = '.$course_id.' AND agenda_id = '.(int) $agenda_id.'';
$result = Database::query($sql);
if (Database::num_rows($result) != 0) {
$row = Database::fetch_array($result);
}
return $row;
}
/**
* Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
* @author Patrick Cool , Ghent University
*/
function display_one_agenda_item($agenda_id)
{
global $TABLEAGENDA;
global $TABLE_ITEM_PROPERTY;
global $select_month, $select_year;
global $DaysShort, $DaysLong, $MonthsLong;
global $dateFormatLong, $timeNoSecFormat, $charset;
// getting the name of the groups
$group_names = get_course_groups();
$agenda_id = intval($agenda_id);
if (!(api_is_allowed_to_edit(false, true) || (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous(
)))
) {
$visibility_condition = " AND ip.visibility='1' ";
}
$sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
WHERE agenda.id = ip.ref
AND ip.tool='".TOOL_CALENDAR_EVENT."'
$visibility_condition
AND agenda.id='$agenda_id'";
$result = Database::query($sql);
$number_items = Database::num_rows($result);
$myrow = Database::fetch_array($result, 'ASSOC'); // there should be only one item so no need for a while loop
$sql_rep = "SELECT * FROM $TABLEAGENDA WHERE id = $agenda_id AND parent_event_id IS NOT NULL AND parent_event_id !=0";
$res_rep = Database::query($sql_rep);
$repeat = false;
$repeat_id = 0;
if (Database::num_rows($res_rep) > 0) {
$repeat = true;
$row_rep = Database::fetch_array($res_rep);
$repeat_id = $row_rep['parent_event_id'];
}
// DISPLAY: NO ITEMS
if ($number_items == 0) {
Display::display_warning_message(get_lang("NoAgendaItems"));
return false;
}
// DISPLAY: THE ITEMS
echo "
";
// DISPLAY : the icon, title, destinees of the item
$myrow["start_date"] = api_get_local_time($myrow["start_date"]);
// highlight: if a date in the small calendar is clicked we highlight the relevant items
$db_date = (int) api_format_date($myrow["start_date"], "%d").intval(api_format_date($myrow["start_date"], "%m")).api_format_date($myrow["start_date"], "%Y");
if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date) {
if ($myrow['visibility'] == '0') {
$style = "data_hidden";
$stylenotbold = "datanotbold_hidden";
$text_style = "text_hidden";
} else {
$style = "data";
$stylenotbold = "datanotbold";
$text_style = "text";
}
} else {
$style = "datanow";
$stylenotbold = "datanotboldnow";
$text_style = "textnow";
}
echo Display::tag('h2', $myrow['title']);
echo "
";
if (api_is_allowed_to_edit(false, true)) {
if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) {
// a coach can only delete an element belonging to his session
// DISPLAY: edit delete button (course admin only)
$export_icon = '../img/export.png';
$export_icon_low = '../img/export_low_fade.png';
$export_icon_high = '../img/export_high_fade.png';
echo '
";
}
/**
* 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.
* @author Patrick Cool , Ghent University
* @param integer id, the id of the agenda item we are editing. By default this is empty which means that we are adding an
* agenda item.
*/
function show_add_form($id = '', $type = null)
{
$showImg = Display::return_icon('div_show.gif');
$hideImg = Display::return_icon('div_hide.gif');
$MonthsLong = api_get_months_long();
$htmlHeadXtra[] = to_javascript();
// the default values for the forms
//if (isset(!$_GET['originalresource']) && $_GET['originalresource'] !== 'no') {
if (!isset($_GET['originalresource'])) {
$day = date('d');
$month = date('m');
$year = date('Y');
$hours = 9;
$minutes = '00';
$title = null;
$content = null;
$end_day = date('d');
$end_month = date('m');
$end_year = date('Y');
$end_hours = 17;
$end_minutes = '00';
$repeat = false;
} else {
// we are coming from the resource linker so there might already have been some information in the form.
// When we clicked on the button to add resources we stored every form information into a session and now we
// are doing the opposite thing: getting the information out of the session and putting it into variables to
// display it in the forms.
$form_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null;
$day = $form_elements['day'];
$month = $form_elements['month'];
$year = $form_elements['year'];
$hours = $form_elements['hour'];
$minutes = $form_elements['minutes'];
$end_day = $form_elements['end_day'];
$end_month = $form_elements['end_month'];
$end_year = $form_elements['end_year'];
$end_hours = $form_elements['end_hours'];
$end_minutes = $form_elements['end_minutes'];
$title = $form_elements['title'];
$content = $form_elements['content'];
$id = $form_elements['id'];
$to = $form_elements['to'];
$repeat = $form_elements['repeat'];
}
// switching the send to all/send to groups/send to users
if (isset($_POST['To']) && $_POST['To']) {
$day = $_POST['fday'];
$month = $_POST['fmonth'];
$year = $_POST['fyear'];
$hours = $_POST['fhour'];
$minutes = $_POST['fminute'];
$end_day = $_POST['end_fday'];
$end_month = $_POST['end_fmonth'];
$end_year = $_POST['end_fyear'];
$end_hours = $_POST['end_fhour'];
$end_minutes = $_POST['end_fminute'];
$title = $_POST['title'];
$content = $_POST['content'];
// the invisible fields
$action = $_POST['action'];
$id = $_POST['id'];
$repeat = !empty($_POST['repeat']) ? true : false;
}
$default_no_empty_end_date = 0;
$course_info = null;
// if the id is set then we are editing an agenda item
if (!empty($id)) {
$course_info = api_get_course_info();
$agendaObj = new Agenda();
if (!empty($course_info)) {
$agendaObj->set_course($course_info);
$agendaObj->type = 'course';
} else {
if (api_is_platform_admin() && $type == 'platform') {
$agendaObj->type = 'admin';
} else {
$agendaObj->type = 'personal';
}
}
$agendaItem = $agendaObj->get_event($id);
$title = $agendaItem['title'];
$content = $agendaItem['description'];
// start date
if ($agendaItem['start_date'] != '0000-00-00 00:00:00') {
$agendaItem['start_date'] = api_get_local_time($agendaItem['start_date']);
list($datepart, $timepart) = explode(" ", $agendaItem['start_date']);
list($year, $month, $day) = explode("-", $datepart);
list($hours, $minutes, $seconds) = explode(":", $timepart);
}
// end date
if (!empty($agendaItem['end_date']) && $agendaItem['end_date'] != '0000-00-00 00:00:00') {
$agendaItem['end_date'] = api_get_local_time($agendaItem['end_date']);
list($datepart, $timepart) = explode(" ", $agendaItem['end_date']);
list($end_year, $end_month, $end_day) = explode("-", $datepart);
list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart);
} else {
if ($agendaItem['all_day']) {
$end_year = $year;
$end_month = $month;
$end_day = $day;
$end_hours = $hours;
$end_minutes = $minutes;
$end_seconds = $seconds;
}
}
// attachments
//edit_added_resources("Agenda", $id);
//$to = $item_2_edit['to'];
} else {
$to = load_edit_users(TOOL_CALENDAR_EVENT, $id);
}
$content = stripslashes($content);
$title = stripslashes($title);
// we start a completely new item, we do not come from the resource linker
if (isset($_GET['originalresource']) && $_GET['originalresource'] !== "no" and $_GET['action'] == "add") {
$_SESSION["formelements"] = null;
unset_session_resources();
}
$origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null;
$course_url = empty($course_info) ? null : api_get_cidreq();
?>