display_upcoming_events(); } echo '</td>'; echo '<td width="20" background="../img/verticalruler.gif"> </td>'; } // THE RIGHT PART echo '<td valign="top">'; echo '<div class="sort" style="float:right">'; echo '</div>'; if (api_is_allowed_to_edit(false, true)) { switch ($_GET['action']) { case "add": if ($_POST['submit_event']) { $event_start = (int) $_POST['fyear'] . '-' . (int) $_POST['fmonth'] . '-' . (int) $_POST['fday'] . ' ' . (int) $_POST['fhour'] . ':' . (int) $_POST['fminute'] . ':00'; $event_stop = (int) $_POST['end_fyear'] . '-' . (int) $_POST['end_fmonth'] . '-' . (int) $_POST['end_fday'] . ' ' . (int) $_POST['end_fhour'] . ':' . (int) $_POST['end_fminute'] . ':00'; $id = agenda_add_item($_POST['title'], $_POST['content'], $event_start, $event_stop); display_agenda_items(); } else { show_add_form(); } break; case "edit": if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id'])))) { // a coach can only delete an element belonging to his session if ($_POST['submit_event']) { $my_id_attach = (int) $_REQUEST['id_attach']; $my_file_comment = Database::escape_string($_REQUEST['file_comment']); store_edited_agenda_item($my_id_attach, $my_file_comment); display_agenda_items(); } else { $id = (int) $_GET['id'];
// Insert into agenda $agenda_id = 0; $end_date = ''; if (isset($_POST['add_to_calendar']) && $_POST['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'; // Setting today date $date = $end_date = $time; $title = sprintf(get_lang('HandingOverOfTaskX'), $_POST['new_dir']); if (!empty($_POST['type1'])) { $end_date = get_date_from_select('expires'); $date = $end_date; } $description = isset($_POST['description']) ? $_POST['description'] : ''; $content = '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&curdirpath=' . api_substr($dir_name_sql, 1) . '" >' . $_POST['new_dir'] . '</a>' . $description; $agenda_id = agenda_add_item($course_info, $title, $content, $date, $end_date, array('GROUP:' . $group_id), 0); } } //Folder created api_item_property_update($course_info, 'work', $id, 'DirectoryCreated', $user_id, $group_id); Display::display_confirmation_message(get_lang('DirectoryCreated'), false); // insert into student_publication_assignment //return something like this: 2008-02-45 00:00:00 $enable_calification = isset($_POST['qualification_value']) && !empty($_POST['qualification_value']) ? 1 : 0; if (!empty($_POST['type1']) || !empty($_POST['type2'])) { $sql_add_homework = "INSERT INTO {$TSTDPUBASG} SET\n c_id = {$course_id} ,\n expires_on \t\t= '" . (isset($_POST['type1']) && $_POST['type1'] == 1 ? api_get_utc_datetime(get_date_from_select('expires')) : '0000-00-00 00:00:00') . "',\n ends_on \t \t\t= '" . (isset($_POST['type2']) && $_POST['type2'] == 1 ? api_get_utc_datetime(get_date_from_select('ends')) : '0000-00-00 00:00:00') . "',\n add_to_calendar \t\t= '{$agenda_id}',\n enable_qualification \t= '{$enable_calification}',\n publication_id \t\t\t= '{$id}'"; Database::query($sql_add_homework); $my_last_id = Database::insert_id(); $sql_add_publication = "UPDATE {$work_table} SET has_properties = {$my_last_id} , view_properties = 1 WHERE c_id = {$course_id} AND id = {$id}"; Database::query($sql_add_publication); } else {
/** * Adds an announcement to the database * @param string Title of the announcement * @param string Content of the announcement * @param string Start date (YYYY-MM-DD HH:II: SS) * @param string End date (YYYY-MM-DD HH:II: SS) * @param int Whether the announcement should be visible to teachers (1) or not (0) * @param int Whether the announcement should be visible to students (1) or not (0) * @param int Whether the announcement should be visible to anonymous users (1) or not (0) * @param string The language for which the announvement should be shown. Leave null for all langages * @param int Whether to send an e-mail to all users (1) or not (0) * @return mixed insert_id on success, false on failure */ public static function add_announcement( $title, $content, $date_start, $date_end, $visible_teacher = 0, $visible_student = 0, $visible_guest = 0, $lang = null, $send_mail = 0, $add_to_calendar = false, $sendEmailTest = false ) { $original_content = $content; $a_dateS = explode(' ',$date_start); $a_arraySD = explode('-',$a_dateS[0]); $a_arraySH = explode(':',$a_dateS[1]); $date_start_to_compare = array_merge($a_arraySD,$a_arraySH); $a_dateE = explode(' ',$date_end); $a_arrayED = explode('-',$a_dateE[0]); $a_arrayEH = explode(':',$a_dateE[1]); $date_end_to_compare = array_merge($a_arrayED,$a_arrayEH); $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); if (!checkdate($date_start_to_compare[1], $date_start_to_compare[2], $date_start_to_compare[0])) { Display :: display_normal_message(get_lang('InvalidStartDate')); return false; } if (($date_end_to_compare[1] || $date_end_to_compare[2] || $date_end_to_compare[0]) && !checkdate($date_end_to_compare[1], $date_end_to_compare[2], $date_end_to_compare[0])) { Display :: display_normal_message(get_lang('InvalidEndDate')); return false; } if (strlen(trim($title)) == 0) { Display::display_normal_message(get_lang('InvalidTitle')); return false; } $start = api_get_utc_datetime($date_start); $end = api_get_utc_datetime($date_end); $title = Database::escape_string($title); $content = Database::escape_string($content); //Fixing urls that are sent by email $content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); $content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); $langsql = is_null($lang) ? 'NULL' : "'".Database::escape_string($lang)."'"; global $_configuration; $current_access_url_id = 1; if ($_configuration['multiple_access_urls']) { $current_access_url_id = api_get_current_access_url_id(); } $sql = "INSERT INTO ".$db_table." (title,content,date_start,date_end,visible_teacher,visible_student,visible_guest, lang, access_url_id) VALUES ('".$title."','".$content."','".$start."','".$end."','".$visible_teacher."','".$visible_student."','".$visible_guest."',".$langsql.", ".$current_access_url_id.")"; if ($sendEmailTest) { SystemAnnouncementManager::send_system_announcement_by_email($title, $content,$visible_teacher, $visible_student, $lang, true); } else { if ($send_mail == 1) { SystemAnnouncementManager::send_system_announcement_by_email($title, $content,$visible_teacher, $visible_student, $lang); } } $res = Database::query($sql); if ($res === false) { Debug::log_s(mysql_error()); return false; } if ($add_to_calendar) { require_once 'calendar.lib.php'; $agenda_id = agenda_add_item($title, $original_content, $date_start, $date_end); } return Database::insert_id(); }
/** * COMMANDS SECTION */ $display_form = false; if ($is_allowedToEdit) { $id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0; $title = isset($_REQUEST['title']) ? trim($_REQUEST['title']) : ''; $content = isset($_REQUEST['content']) ? trim($_REQUEST['content']) : ''; $lasting = isset($_REQUEST['lasting']) ? trim($_REQUEST['lasting']) : ''; $speakers = isset($_REQUEST['speakers']) ? trim($_REQUEST['speakers']) : ''; $location = isset($_REQUEST['location']) ? trim($_REQUEST['location']) : ''; $autoExportRefresh = false; if ('exAdd' == $cmd) { $date_selection = $_REQUEST['fyear'] . '-' . $_REQUEST['fmonth'] . '-' . $_REQUEST['fday']; $hour = $_REQUEST['fhour'] . ':' . $_REQUEST['fminute'] . ':00'; $entryId = agenda_add_item($title, $content, $date_selection, $hour, $lasting, $speakers, $location); if ($entryId != false) { $dialogBox->success(get_lang('Event added to the agenda')); $currentLocator = ResourceLinker::$Navigator->getCurrentLocator(array('id' => (int) $entryId)); $resourceList = isset($_REQUEST['resourceList']) ? $_REQUEST['resourceList'] : array(); ResourceLinker::updateLinkList($currentLocator, $resourceList); if (CONFVAL_LOG_CALENDAR_INSERT) { $claroline->log('CALENDAR', array('ADD_ENTRY' => $entryId)); } // notify that a new agenda event has been posted $eventNotifier->notifyCourseEvent('agenda_event_added', claro_get_current_course_id(), claro_get_current_tool_id(), $entryId, claro_get_current_group_id(), '0'); $autoExportRefresh = true; } else { $dialogBox->error(get_lang('Unable to add the event to the agenda')); } }
/** * Adds a repetitive item to the database * @param array Course info * @param int The original event's id * @param string Type of repetition * @param int Timestamp of end of repetition (repeating until that date) * @param array Original event's destination (users list) * @param string a comment about a attachment file into agenda * @return boolean False if error, True otherwise */ function agenda_add_repeat_item($course_info, $orig_id, $type, $end, $orig_dest, $file_comment = '') { $t_agenda = Database::get_course_table(TABLE_AGENDA); $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT); $course_id = $course_info['real_id']; $sql = 'SELECT title, content, start_date as sd, end_date as ed FROM ' . $t_agenda . ' WHERE c_id = ' . $course_id . ' AND id ="' . intval($orig_id) . '" '; $res = Database::query($sql); if (Database::num_rows($res) !== 1) { return false; } $row = Database::fetch_array($res); $orig_start = api_strtotime(api_get_local_time($row['sd'])); $orig_end = api_strtotime(api_get_local_time($row['ed'])); $diff = $orig_end - $orig_start; $orig_title = $row['title']; $orig_content = $row['content']; $now = time(); $type = Database::escape_string($type); $end = intval($end); if (1 <= $end && $end <= 500) { //we assume that, with this type of value, the user actually gives a count of repetitions //and that he wants us to calculate the end date with that (particularly in case of imports from ical) switch ($type) { case 'daily': $end = $orig_start + 86400 * $end; break; case 'weekly': $end = add_week($orig_start, $end); break; case 'monthlyByDate': $end = add_month($orig_start, $end); break; case 'monthlyByDay': //TODO break; case 'monthlyByDayR': //TODO break; case 'yearly': $end = add_year($orig_start, $end); break; } } if ($end > $now && in_array($type, array('daily', 'weekly', 'monthlyByDate', 'monthlyByDay', 'monthlyByDayR', 'yearly'))) { $sql = "INSERT INTO {$t_agenda_r} (c_id, cal_id, cal_type, cal_end) VALUES ({$course_id}, '{$orig_id}','{$type}',{$end})"; $res = Database::query($sql); switch ($type) { case 'daily': for ($i = $orig_start + 86400; $i <= $end; $i += 86400) { $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i + $diff), $orig_dest, $orig_id, $file_comment); } break; case 'weekly': for ($i = $orig_start + 604800; $i <= $end; $i += 604800) { $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i + $diff), $orig_dest, $orig_id, $file_comment); } break; case 'monthlyByDate': $next_start = add_month($orig_start); while ($next_start <= $end) { $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start + $diff), $orig_dest, $orig_id, $file_comment); $next_start = add_month($next_start); } break; case 'monthlyByDay': //not yet implemented break; case 'monthlyByDayR': //not yet implemented break; case 'yearly': $next_start = add_year($orig_start); while ($next_start <= $end) { $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start + $diff), $orig_dest, $orig_id, $file_comment); $next_start = add_year($next_start); } break; } } return true; }
/** * Import an iCal file into the database * @param array Course info * @return boolean True on success, false otherwise */ function agenda_import_ical($course_info, $file) { require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'; $charset = api_get_system_encoding(); $filepath = api_get_path(SYS_ARCHIVE_PATH) . $file['name']; if (!@move_uploaded_file($file['tmp_name'], $filepath)) { error_log('Problem moving uploaded file: ' . $file['error'] . ' in ' . __FILE__ . ' line ' . __LINE__); return false; } require_once api_get_path(LIBRARY_PATH) . 'icalcreator/iCalcreator.class.php'; $ical = new vcalendar(); $ical->setConfig('directory', dirname($filepath)); $ical->setConfig('filename', basename($filepath)); $ical->parse(); //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name), // rrule $ve = $ical->getComponent(VEVENT); //print_r($ve); $ttitle = $ve->getProperty('summary'); //print_r($ttitle); $title = api_convert_encoding($ttitle, $charset, 'UTF-8'); $tdesc = $ve->getProperty('description'); $desc = api_convert_encoding($tdesc, $charset, 'UTF-8'); $ts = $ve->getProperty('dtstart'); $start_date = $ts['year'] . '-' . $ts['month'] . '-' . $ts['day'] . ' ' . $ts['hour'] . ':' . $ts['min'] . ':' . $ts['sec']; $ts = $ve->getProperty('dtend'); $end_date = $ts['year'] . '-' . $ts['month'] . '-' . $ts['day'] . ' ' . $ts['hour'] . ':' . $ts['min'] . ':' . $ts['sec']; //echo $start_date.' - '.$end_date; $organizer = $ve->getProperty('organizer'); $attendee = $ve->getProperty('attendee'); $course_name = $ve->getProperty('location'); //insert the event in our database $id = agenda_add_item($course_info, $title, $desc, $start_date, $end_date, $_POST['selectedform']); $repeat = $ve->getProperty('rrule'); if (is_array($repeat) && !empty($repeat['FREQ'])) { $trans = array('DAILY' => 'daily', 'WEEKLY' => 'weekly', 'MONTHLY' => 'monthlyByDate', 'YEARLY' => 'yearly'); $freq = $trans[$repeat['FREQ']]; $interval = $repeat['INTERVAL']; if (isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) { $until = mktime(23, 59, 59, $repeat['UNTIL']['month'], $repeat['UNTIL']['day'], $repeat['UNTIL']['year']); $res = agenda_add_repeat_item($course_info, $id, $freq, $until, $_POST['selectedform']); } //TODO: deal with count if (!empty($repeat['COUNT'])) { $count = $repeat['COUNT']; $res = agenda_add_repeat_item($course_info, $id, $freq, $count, $_POST['selectedform']); } } return true; }