');
- $form->addElement('checkbox', 'repeat', null, get_lang('RepeatEvent'));
-
- $repeat_events = array(
- 'daily' => get_lang('RepeatDaily'),
- 'weekly' => get_lang('RepeatWeekly'),
- 'monthlyByDate' => get_lang('RepeatMonthlyByDate'),
- 'yearly' => get_lang('RepeatYearly')
- );
+ if ($this->type == 'course') {
+ $repeat = $form->addElement('checkbox', 'repeat', null, get_lang('RepeatEvent'), array('onclick' => 'return plus_repeated_event();'));
+ $form->addElement('html', '
');
+ $form->addElement('select', 'repeat_type', get_lang('RepeatType'), self::getRepeatTypes());
+ $form->addElement('date_picker', 'repeat_end_day', get_lang('RepeatEnd'), array('id' => 'repeat_end_date_form'));
- $form->addElement('select', 'repeat_type', get_lang('RepeatType'), $repeat_events);
- $form->addElement('text', 'repeat_end_day', get_lang('RepeatEnd'));
+ if ($isSubEventEdition || $isParentFromSerie) {
+ if ($isSubEventEdition) {
+ $parentEvent = $params['parent_info'];
+ $repeatInfo = $parentEvent['repeat_info'];
+ } else {
+ $repeatInfo = $params['repeat_info'];
+ }
+ $params['repeat'] = 1;
+ $params['repeat_type'] = $repeatInfo['cal_type'];
+ $params['repeat_end_day'] = substr(api_get_local_time($repeatInfo['cal_end']), 0, 10);
+
+ $form->freeze(array('repeat_type', 'repeat_end_day'));
+ $repeat->_attributes['disabled'] = 'disabled';
+ }
$form->addElement('html', '
');
+ }
- if (!api_is_allowed_to_edit(null, true)) {
- $toolbar = 'AgendaStudent';
- } else {
- $toolbar = 'Agenda';
+ if (!empty($id)) {
+ if (empty($params['end_date'])) {
+ $params['date_range'] = $params['end_date'];
}
- //$form->addElement('html_editor', 'content', get_lang('Description'), null, array('ToolbarSet' => $toolbar, 'Width' => '100%', 'Height' => '200'));
+
+ $params['date_range'] =
+ substr(api_get_local_time($params['start_date']), 0, 16).' / '.
+ substr(api_get_local_time($params['end_date']), 0, 16);
+ }
+
+ if (!api_is_allowed_to_edit(null, true)) {
+ $toolbar = 'AgendaStudent';
+ } else {
+ $toolbar = 'Agenda';
+ }
+
+ $form->addElement(
+ 'html_editor',
+ 'content',
+ get_lang('Description'),
+ null,
+ array('ToolbarSet' => $toolbar, 'Width' => '100%', 'Height' => '200')
+ );
+
+ if ($this->type == 'course') {
$form->addElement('file', 'user_upload', get_lang('AddAnAttachment'));
- $form->addElement('text', 'file_comment', get_lang('Comment'));
+ if ($showAttachmentForm) {
+ if (isset($params['attachment']) && !empty($params['attachment'])) {
+ $attachment = $params['attachment'];
+ $params['file_comment'] = $attachment['comment'];
+ if (!empty($attachment['path'])) {
+ $form->addElement(
+ 'checkbox',
+ 'delete_attachment',
+ null,
+ get_lang('DeleteAttachment').' '.$attachment['filename']
+ );
+ }
+ }
+ }
+
+ $form->addElement('textarea', 'file_comment', get_lang('Comment'));
+ }
+
+ if (empty($id)) {
+ $form->addElement(
+ 'checkbox',
+ 'add_announcement',
+ null,
+ get_lang('AddAnnouncement').' ('.get_lang('SendMail').')'
+ );
}
$form->addElement('button', 'submit', $button);
- $form->display();
+ $form->setDefaults($params);
+
+ $form->addRule('date_range', get_lang('ThisFieldIsRequired'), 'required');
+ $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
+
+ return $form;
}
/**
- * @param array $form
- * @param $to_already_selected
+ * @param FormValidator $form
+ * @param array $sendTo array('everyone' => false, 'users' => [1, 2], 'groups' => [3, 4])
+ * @param array $attributes
+ * @param bool $addOnlyItemsInSendTo
+ * @return bool
*/
- public static function show_to_form($form, $to_already_selected)
- {
+ public function showToForm(
+ $form,
+ $sendTo = array(),
+ $attributes = array(),
+ $addOnlyItemsInSendTo = false
+ ) {
+ if ($this->type != 'course') {
+ return false;
+ }
+
$order = 'lastname';
if (api_is_western_name_order()) {
$order = 'firstname';
}
- $user_list = CourseManager::get_user_list_from_course_code(
+
+ $userList = 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());
+ $groupList = CourseManager::get_group_list_of_course(
+ api_get_course_id(),
+ api_get_session_id()
+ );
- self::construct_not_selected_select_form_validator($form, $group_list, $user_list, $to_already_selected);
- }
+ $this->setSendToSelect(
+ $form,
+ $groupList,
+ $userList,
+ $sendTo,
+ $attributes,
+ $addOnlyItemsInSendTo
+ );
+ return true;
+ }
/**
- * 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 $userList
- * @param string a comment about a attachment file into agenda
- * @return boolean False if error, True otherwise
+ * @param int $id
+ * @param int $visibility 0= invisible, 1 visible
+ * @param array $courseInfo
+ * @param int $userId
*/
- private function addRepeatItem($course_info, $orig_id, $type, $end, $userList, $file_comment = '')
+ public static function changeVisibility($id, $visibility, $courseInfo, $userId = null)
{
- $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;
+ $id = Database::escape_string($id);
+ if (empty($userId)) {
+ $userId = api_get_user_id();
+ } else {
+ $userId = intval($userId);
}
- $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 = $this->addWeek($orig_start, $end);
- break;
- case 'monthlyByDate':
- $end = $this->addMonth($orig_start, $end);
- break;
- case 'monthlyByDay':
- //TODO
- break;
- case 'monthlyByDayR':
- //TODO
- break;
- case 'yearly':
- $end = $this->addYear($orig_start, $end);
- break;
- }
+ if ($visibility == 0) {
+ api_item_property_update($courseInfo, TOOL_CALENDAR_EVENT, $id, "invisible", $userId);
+ } else {
+ api_item_property_update($courseInfo, TOOL_CALENDAR_EVENT, $id, "visible", $userId);
}
+ }
- 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)";
- Database::query($sql);
- switch ($type) {
- case 'daily':
- for ($i = $orig_start + 86400; ($i <= $end); $i += 86400) {
- $this->add_event(date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i + $diff), false, null, $orig_title, $orig_content, $userList, false, $orig_id);
- }
- break;
- case 'weekly':
- for ($i = $orig_start + 604800; ($i <= $end); $i += 604800) {
- $this->add_event(date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i + $diff), false, null, $orig_title, $orig_content, $userList, false, $orig_id);
- //$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), $userList, $orig_id, $file_comment);
- }
- break;
- case 'monthlyByDate':
- $next_start = $this->addMonth($orig_start);
- while ($next_start <= $end) {
- $this->add_event(date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start + $diff), false, null, $orig_title, $orig_content, $userList, false, $orig_id);
- //$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), $userList, $orig_id, $file_comment);
- $next_start = $this->addMonth($next_start);
- }
- break;
- case 'monthlyByDay':
- //not yet implemented
- break;
- case 'monthlyByDayR':
- //not yet implemented
- break;
- case 'yearly':
- $next_start = $this->addYear($orig_start);
- while ($next_start <= $end) {
- $this->add_event(date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start + $diff), false, null, $orig_title, $orig_content, $userList, false, $orig_id);
- //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), $userList, $orig_id, $file_comment);
- $next_start = $this->addYear($next_start);
- }
- break;
- }
- }
- return true;
+ /**
+ * Get repeat types
+ * @return array
+ */
+ public static function getRepeatTypes()
+ {
+ return array(
+ 'daily' => get_lang('RepeatDaily'),
+ 'weekly' => get_lang('RepeatWeekly'),
+ 'monthlyByDate' => get_lang('RepeatMonthlyByDate'),
+ //monthlyByDay"> get_lang('RepeatMonthlyByDay');
+ //monthlyByDayR' => get_lang('RepeatMonthlyByDayR'),
+ 'yearly' => get_lang('RepeatYearly')
+ );
}
/**
+ * Show a list with all the attachments according to the post's id
* @param int $eventId
- * @param array $settings = array('comment' => $comment, 'file' => $file
- * @return bool
+ * @param array $courseInfo
+ * @return array with the post info
*/
- private function addAttachment($eventId, $settings)
+ public function getAttachment($eventId, $courseInfo)
{
- $table = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
-
- if (!isset($settings['file'])) {
- return false;
+ $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
+ $courseId = intval($courseInfo['real_id']);
+ $eventId = Database::escape_string($eventId);
+ $row = array();
+ $sql = "SELECT id, path, filename, comment
+ FROM $tableAttachment
+ WHERE
+ c_id = $courseId AND
+ agenda_id = $eventId";
+ $result = Database::query($sql);
+ if (Database::num_rows($result) != 0) {
+ $row = Database::fetch_array($result, 'ASSOC');
}
- $file = $settings['file'];
-
- if (!empty($file['name'])) {
- $upload_ok = FileManager::process_uploaded_file($file);
- }
+ return $row;
+ }
- $_course = api_get_course_info();
+ /**
+ * Add an attachment file into agenda
+ * @param int $eventId
+ * @param array $fileUserUpload ($_FILES['user_upload'])
+ * @param string comment about file
+ * @param array $courseInfo
+ * @return string
+ */
+ public function addAttachment($eventId, $fileUserUpload, $comment, $courseInfo)
+ {
+ $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
+ $eventId = intval($eventId);
+ // Storing the attachments
+ $upload_ok = false;
+ if (!empty($fileUserUpload['name'])) {
+ $upload_ok = process_uploaded_file($fileUserUpload);
+ }
if (!empty($upload_ok)) {
- $courseDir = $_course['path'].'/upload/calendar';
+
+ $courseDir = $courseInfo['directory'].'/upload/calendar';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$courseDir;
+ $uploadDir = $sys_course_path.$courseDir;
// Try to add an extension to the file if it hasn't one
- $new_file_name = FileManager::add_ext_on_mime(
- stripslashes($_FILES['user_upload']['name']),
- $_FILES['user_upload']['type']
+ $new_file_name = add_ext_on_mime(
+ stripslashes($fileUserUpload['name']),
+ $fileUserUpload['type']
);
// user's file name
- $file_name = $_FILES['user_upload']['name'];
+ $file_name = $fileUserUpload['name'];
- if (!FileManager::filter_extension($new_file_name)) {
- Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
+ if (!filter_extension($new_file_name)) {
+ return Display::return_message(
+ get_lang('UplUnableToSaveFileFilteredExtension'),
+ 'error'
+ );
} else {
$new_file_name = uniqid('');
- $new_path = $updir.'/'.$new_file_name;
- $result = move_uploaded_file($file['tmp_name'], $new_path);
- $safe_file_comment = Database::escape_string($settings['comment']);
- $safe_file_name = Database::escape_string($file_name);
- $safe_new_file_name = Database::escape_string($new_file_name);
+ $new_path = $uploadDir.'/'.$new_file_name;
+ $result = @move_uploaded_file($fileUserUpload['tmp_name'], $new_path);
+ $comment = Database::escape_string($comment);
+ $file_name = Database::escape_string($file_name);
$course_id = api_get_course_int_id();
+ $size = intval($fileUserUpload['size']);
// Storing the attachments if any
if ($result) {
- $sql = 'INSERT INTO '.$table.'(c_id, filename,comment, path,agenda_id,size) '.
- "VALUES ($course_id, '".$safe_file_name."', '".$safe_file_comment."', '".$safe_new_file_name."' , '".$eventId."', '".intval($file['size'])."' )";
+ $sql = 'INSERT INTO '.$agenda_table_attachment.'(c_id, filename, comment, path, agenda_id, size) '.
+ "VALUES ($course_id, '".$file_name."', '".$comment."', '".$new_file_name."' , '".$eventId."', '".$size."' )";
Database::query($sql);
- $last_id_file = Database::insert_id();
- api_item_property_update($_course, 'calendar_event_attachment', $last_id_file, 'AgendaAttachmentAdded', api_get_user_id());
+ $id = Database::insert_id();
+ api_item_property_update(
+ $courseInfo,
+ 'calendar_event_attachment',
+ $id,
+ 'AgendaAttachmentAdded',
+ api_get_user_id()
+ );
}
}
}
}
/**
- * @param $timestamp
- * @param int $num
- * @return int
+ * @param int $eventId
+ * @param array $fileUserUpload
+ * @param string $comment
+ * @param array $courseInfo
+ */
+ public function updateAttachment($eventId, $fileUserUpload, $comment, $courseInfo)
+ {
+ $attachment = $this->getAttachment($eventId, $courseInfo);
+ if (!empty($attachment)) {
+ $this->deleteAttachmentFile($attachment['id'], $courseInfo);
+ }
+ $this->addAttachment($eventId, $fileUserUpload, $comment, $courseInfo);
+ }
+
+ /**
+ * This function delete a attachment file by id
+ * @param int $attachmentId
+ * @param array $courseInfo
+ * @return string
*/
- private function addMonth($timestamp, $num = 1)
+ public function deleteAttachmentFile($attachmentId, $courseInfo)
{
- list($y, $m, $d, $h, $n, $s) = explode('/', date('Y/m/d/h/i/s', $timestamp));
+ $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
+ $attachmentId = intval($attachmentId);
+ $courseId = $courseInfo['real_id'];
+
+ if (empty($courseId) || empty($attachmentId)) {
+ return false;
+ }
+
+ $sql = "DELETE FROM $agenda_table_attachment
+ WHERE c_id = $courseId AND id = ".$attachmentId;
+ $result = Database::query($sql);
+
+ // update item_property
+ api_item_property_update(
+ $courseInfo,
+ 'calendar_event_attachment',
+ $attachmentId,
+ 'AgendaAttachmentDeleted',
+ api_get_user_id()
+ );
+
+ if (!empty($result)) {
+ return Display::return_message(get_lang("AttachmentFileDeleteSuccess"), 'confirmation');
+ }
+ }
+
+ /**
+ * Adds x weeks to a UNIX timestamp
+ * @param int The timestamp
+ * @param int The number of weeks to add
+ * @return int The new timestamp
+ */
+ function addWeek($timestamp, $num = 1)
+ {
+ return $timestamp + $num * 604800;
+ }
+
+ /**
+ * Adds x months to a UNIX timestamp
+ * @param int The timestamp
+ * @param int The number of years to add
+ * @return int The new timestamp
+ */
+ function addMonth($timestamp, $num = 1)
+ {
+ list($y, $m, $d, $h, $n, $s) = split('/', date('Y/m/d/h/i/s', $timestamp));
if ($m + $num > 12) {
$y += floor($num / 12);
$m += $num % 12;
@@ -1298,25 +2021,268 @@ class Agenda
}
/**
- * @param $timestamp
- * @param int $num
- * @return int
+ * Adds x years to a UNIX timestamp
+ * @param int The timestamp
+ * @param int The number of years to add
+ * @return int The new timestamp
*/
- private function addYear($timestamp, $num = 1)
+ function addYear($timestamp, $num = 1)
{
- list($y, $m, $d, $h, $n, $s) = explode('/', date('Y/m/d/h/i/s', $timestamp));
+ list($y, $m, $d, $h, $n, $s) = split('/', date('Y/m/d/h/i/s', $timestamp));
return mktime($h, $n, $s, $m, $d, $y + $num);
}
/**
- * Adds x weeks to a UNIX timestamp
- * @param int The timestamp
- * @param int The number of weeks to add
- * @return int The new timestamp
+ * @param int $eventId
+ * @return array
*/
- private function addWeek($timestamp, $num = 1)
+ public function getAllRepeatEvents($eventId)
{
- return $timestamp + $num * 604800;
+ $events = array();
+ switch ($this->type) {
+ case 'personal':
+ break;
+ case 'course':
+ if (!empty($this->course['real_id'])) {
+ $sql = "SELECT * FROM ".$this->tbl_course_agenda."
+ WHERE
+ c_id = ".$this->course['real_id']." AND
+ parent_event_id = ".$eventId;
+ $result = Database::query($sql);
+ if (Database::num_rows($result)) {
+ while ($row = Database::fetch_array($result, 'ASSOC')) {
+ $events[] = $row;
+ }
+ }
+ }
+ break;
+ }
+
+ return $events;
+ }
+
+ /**
+ * @param int $eventId
+ * @param int $courseId
+ *
+ * @return bool
+ */
+ public function hasChildren($eventId, $courseId)
+ {
+ $eventId = intval($eventId);
+ $courseId = intval($courseId);
+
+ $sql = "SELECT count(DISTINCT(id)) as count
+ FROM ".$this->tbl_course_agenda."
+ WHERE
+ c_id = ".$courseId." AND
+ parent_event_id = ".$eventId;
+ $result = Database::query($sql);
+ if (Database::num_rows($result)) {
+ $row = Database::fetch_array($result, 'ASSOC');
+ return $row['count'] > 0;
+ }
+ return false;
+ }
+
+ /**
+ * @param int $filter
+ * @param string $view
+ * @return string
+ */
+ public function displayActions($view, $filter = 0)
+ {
+ $actions = "
".
+ Display::return_icon('calendar.png', get_lang('Calendar'), '', ICON_SIZE_MEDIUM)."";
+
+ $actions .= "
".
+ Display::return_icon('week.png', get_lang('AgendaList'), '', ICON_SIZE_MEDIUM)."";
+
+ if (api_is_allowed_to_edit(false, true) OR
+ (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false, true) OR
+ GroupManager::user_has_access(api_get_user_id(), api_get_group_id(), GroupManager::GROUP_TOOL_CALENDAR) &&
+ GroupManager::is_tutor_of_group(api_get_user_id(), api_get_group_id())
+ ) {
+ if ($this->type == 'course') {
+ $form = null;
+ if (!isset($_GET['action'])) {
+ $form = new FormValidator('form-search');
+ $attributes = array(
+ 'multiple' => false,
+ 'id' => 'select_form_id_search'
+ );
+ $selectedValues = $this->parseAgendaFilter($filter);
+ $this->showToForm($form, $selectedValues, $attributes);
+ $form = $form->return_form();
+
+ }
+ $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)."";
+ if ($view == 'calendar') {
+ $actions .= $form;
+ }
+ }
+ }
+ return $actions;
+ }
+
+ /**
+ * @return FormValidator
+ */
+ public function getImportCalendarForm()
+ {
+ $form = new FormValidator(
+ 'frm_import_ical',
+ 'post',
+ api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&type='.$this->type,
+ array('enctype' => 'multipart/form-data')
+ );
+ $form->addElement('header', get_lang('ICalFileImport'));
+ $form->addElement('file', 'ical_import', get_lang('ICalFileImport'));
+ $form->addRule('ical_import', get_lang('ThisFieldIsRequired'), 'required');
+ $form->addElement('button', 'ical_submit', get_lang('Import'));
+
+ return $form;
}
+ /**
+ * @param array $courseInfo
+ * @param $file
+ * @return array|bool|string
+ */
+ public function importEventFile($courseInfo, $file)
+ {
+ $charset = api_get_system_encoding();
+ $filepath = api_get_path(SYS_ARCHIVE_PATH).$file['name'];
+ $messages = array();
+
+ if (!@move_uploaded_file($file['tmp_name'], $filepath)) {
+ error_log('Problem moving uploaded file: '.$file['error'].' in '.__FILE__.' line '.__LINE__);
+ return false;
+ }
+
+ $data = file_get_contents($filepath);
+
+ require_once api_get_path(SYS_PATH).'vendor/autoload.php';
+
+ $trans = array(
+ 'DAILY' => 'daily',
+ 'WEEKLY' => 'weekly',
+ 'MONTHLY' => 'monthlyByDate',
+ 'YEARLY' => 'yearly'
+ );
+ $sentTo = array('everyone' => true);
+ $calendar = Sabre\VObject\Reader::read($data);
+ $currentTimeZone = _api_get_timezone();
+ if (!empty($calendar->VEVENT)) {
+ foreach ($calendar->VEVENT as $event) {
+ $start = $event->DTSTART->getDateTime();
+ $end = $event->DTEND->getDateTime();
+ //Sabre\VObject\DateTimeParser::parseDateTime(string $dt, \Sabre\VObject\DateTimeZone $tz)
+
+ $startDateTime = api_get_local_time($start->format('Y-m-d H:i:s'), $currentTimeZone, $start->format('e'));
+ $endDateTime = api_get_local_time($end->format('Y-m-d H:i'), $currentTimeZone, $end->format('e'));
+ $title = api_convert_encoding((string)$event->summary, $charset, 'UTF-8');
+ $description = api_convert_encoding((string)$event->description, $charset, 'UTF-8');
+
+ $id = $this->add_event(
+ $startDateTime,
+ $endDateTime,
+ 'false',
+ $title,
+ $description,
+ $sentTo
+ );
+
+ $messages[] = " $title - ".$startDateTime." - ".$endDateTime;
+
+ //$attendee = (string)$event->attendee;
+ /** @var Sabre\VObject\Property\ICalendar\Recur $repeat */
+ $repeat = $event->RRULE;
+ if ($id && !empty($repeat)) {
+
+ $repeat = $repeat->getParts();
+ $freq = $trans[$repeat['FREQ']];
+
+ if (isset($repeat['UNTIL']) && !empty($repeat['UNTIL'])) {
+ $until = Sabre\VObject\DateTimeParser::parseDateTime($repeat['UNTIL'], new DateTimeZone($currentTimeZone));
+ $until = $until->format('Y-m-d H:i');
+ //$res = agenda_add_repeat_item($courseInfo, $id, $freq, $until, $attendee);
+ $this->addRepeatedItem(
+ $id,
+ $freq,
+ $until,
+ $sentTo
+ );
+ }
+
+ if (!empty($repeat['COUNT'])) {
+ /*$count = $repeat['COUNT'];
+ $interval = $repeat['INTERVAL'];
+ $endDate = null;
+ switch($freq) {
+ case 'daily':
+ $start = api_strtotime($startDateTime);
+ $date = new DateTime($startDateTime);
+ $days = $count * $interval;
+ var_dump($days);
+ $date->add(new DateInterval("P".$days."D"));
+ $endDate = $date->format('Y-m-d H:i');
+ //$endDate = $count *
+ for ($i = 0; $i < $count; $i++) {
+ $days = 86400 * 7
+ }
+ }
+ }*/
+ //$res = agenda_add_repeat_item($courseInfo, $id, $freq, $count, $attendee);
+ /*$this->addRepeatedItem(
+ $id,
+ $freq,
+ $endDate,
+ $sentTo
+ );*/
+ }
+ }
+ }
+ }
+
+ if (!empty($messages)) {
+ $messages = implode('
', $messages);
+ }
+
+ return $messages;
+ }
+
+ /**
+ * Parse filter turns USER:12 to ['users' => [12])] or G:1 ['groups' => [1]]
+ * @param $filter
+ * @return array
+ */
+ public function parseAgendaFilter($filter)
+ {
+ $everyone = false;
+ $groupId = null;
+ $userId = null;
+
+ if ($filter == 'everyone') {
+ $everyone = true;
+ } else {
+ if (substr($filter, 0, 1) == 'G') {
+ $groupId = str_replace('GROUP:', '', $filter);
+ } else {
+ $userId = str_replace('USER:', '', $filter);
+ }
+ }
+ if (empty($userId) && empty($groupId)) {
+ $everyone = true;
+ }
+
+ return array(
+ 'everyone' => $everyone,
+ 'users' => array($userId),
+ 'groups' => array($groupId)
+ );
+ }
}
diff --git a/main/inc/lib/course_home.lib.php b/main/inc/lib/course_home.lib.php
index adca5c26d9..865cda6714 100644
--- a/main/inc/lib/course_home.lib.php
+++ b/main/inc/lib/course_home.lib.php
@@ -430,7 +430,12 @@ class CourseHome
$col_link ="##003399";
break;
case TOOL_AUTHORING:
- $sql = "SELECT * FROM $course_tool_table WHERE category = 'authoring' AND c_id = $course_id $condition_session ORDER BY id";
+ $sql = "SELECT * FROM $course_tool_table
+ WHERE
+ category = 'authoring' AND
+ c_id = $course_id
+ $condition_session
+ ORDER BY id";
$result = Database::query($sql);
$col_link ="##003399";
diff --git a/main/inc/lib/pear/HTML/QuickForm/select.php b/main/inc/lib/pear/HTML/QuickForm/select.php
index cad163ced3..2a14432dc1 100644
--- a/main/inc/lib/pear/HTML/QuickForm/select.php
+++ b/main/inc/lib/pear/HTML/QuickForm/select.php
@@ -26,7 +26,6 @@
/**
* Base class for form elements
*/
-//require_once 'HTML/QuickForm/element.php';
/**
* Class to dynamically create an HTML SELECT
@@ -116,7 +115,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element {
function setSelected($values)
{
if (is_string($values) && $this->getMultiple()) {
- $values = @split("[ ]?,[ ]?", $values);
+ $values = split("[ ]?,[ ]?", $values);
}
if (is_array($values)) {
$this->_values = array_values($values);
@@ -326,7 +325,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element {
} // end func addOption
- /**
+ /**
* Adds a new OPTION to the SELECT
*
* @param string $text Display text for the OPTION
@@ -339,14 +338,11 @@ class HTML_QuickForm_select extends HTML_QuickForm_element {
*/
function addOptGroup($options, $label)
{
- foreach ($options as &$option) {
- $option[] = $this->addOption($option['text'], $option['value'], null, true);
+ foreach ($options as $option) {
+ $this->addOption($option['text'], $option['value'], $option, true);
}
$this->_optgroups[] = array('label' => $label, 'options' => $options);
- } // end func addOption
-
- // }}}
- // {{{ loadArray()
+ }
/**
* Loads the options from an associative array
@@ -428,7 +424,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element {
function loadQuery(&$conn, $sql, $textCol=null, $valueCol=null, $values=null)
{
if (is_string($conn)) {
- //require_once('DB.php');
+ require_once('DB.php');
$dbConn = &DB::connect($conn, true);
if (DB::isError($dbConn)) {
return $dbConn;
@@ -520,11 +516,8 @@ class HTML_QuickForm_select extends HTML_QuickForm_element {
$attrString = $this->_getAttrString($this->_attributes);
$this->setName($myName);
}
- $strHtml .= $tabs . '