Add CCalendarEventAttachment as a resource

pull/3124/head
Julio Montoya 5 years ago
parent 43f231ebdf
commit adf0b52e44
  1. 24
      public/main/calendar/agenda.php
  2. 6
      public/main/calendar/agenda_js.php
  3. 32
      public/main/calendar/agenda_list.php
  4. 86
      public/main/calendar/download.php
  5. 2
      public/main/inc/ajax/agenda.ajax.php
  6. 316
      public/main/inc/lib/agenda.lib.php
  7. 2
      public/main/template/default/agenda/event_list.html.twig
  8. 829
      public/main/template/default/agenda/month.html.twig
  9. 9
      src/CoreBundle/Framework/Container.php
  10. 35
      src/CourseBundle/Entity/CCalendarEvent.php
  11. 88
      src/CourseBundle/Entity/CCalendarEventAttachment.php
  12. 11
      src/CourseBundle/Repository/CCalendarEventAttachmentRepository.php
  13. 4
      src/CourseBundle/Resources/config/services.yml

@ -2,7 +2,10 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
// use anonymous mode when accessing this course tool
$use_anonymous = true;
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_CALENDAR_EVENT;
@ -28,8 +31,6 @@ if (empty($action)) {
$logInfo = [
'tool' => TOOL_CALENDAR_EVENT,
'tool_id' => 0,
'tool_id_detail' => 0,
'action' => $action,
];
Event::registerLog($logInfo);
@ -126,13 +127,22 @@ if ($allowToEdit) {
$sendEmail = isset($values['add_announcement']) ? true : false;
$allDay = isset($values['all_day']) ? 'true' : 'false';
$sendAttachment = isset($_FILES) && !empty($_FILES) ? true : false;
$attachmentList = $sendAttachment ? $_FILES : null;
$attachmentCommentList = isset($values['legend']) ? $values['legend'] : null;
$comment = isset($values['comment']) ? $values['comment'] : null;
$usersToSend = isset($values['users_to_send']) ? $values['users_to_send'] : '';
$startDate = $values['date_range_start'];
$endDate = $values['date_range_end'];
$attachmentList = [];
if ($sendAttachment) {
$request = Container::getRequest();
foreach ($_FILES as $name => $file) {
if ($request->files->has($name)) {
$attachmentList[] = $request->files->get($name);
}
}
}
$eventId = $agenda->addEvent(
$startDate,
$endDate,
@ -145,7 +155,7 @@ if ($allowToEdit) {
$attachmentList,
$attachmentCommentList,
$comment
);
);exit;
if (!empty($values['repeat']) && !empty($eventId)) {
// End date is always set as 23:59:59
@ -157,6 +167,7 @@ if ($allowToEdit) {
$values['users_to_send']
);
}
$message = Display::return_message(get_lang('Event added'), 'confirmation');
if ($sendEmail) {
$message .= Display::return_message(
@ -284,13 +295,12 @@ if ($allowToEdit) {
$message = Display::return_message(get_lang('This file is not in iCal format'), 'error');
}
Display::addFlash($message);
$url = api_get_self().'?action=importical&type='.$agenda->type;
header("Location: $url");
header("Location: $agendaUrl");
exit;
}
$content = $form->returnForm();
break;
case "delete":
case 'delete':
if (!(api_is_session_general_coach() &&
!api_is_element_in_the_session(TOOL_AGENDA, $eventId))
) {

@ -156,7 +156,7 @@ $tpl->assign('type', $type);
$type_event_class = $type.'_event';
$type_label = get_lang(ucfirst($type).'Calendar');
if ('course' == $type && !empty($group_id)) {
if ('course' === $type && !empty($group_id)) {
$type_event_class = 'group_event';
$type_label = get_lang('Agenda');
}
@ -170,7 +170,7 @@ if (empty($defaultView)) {
/* month, basicWeek, agendaWeek, agendaDay */
$tpl->assign('default_view', $defaultView);
if ('course' == $type && !empty($session_id)) {
if ('course' === $type && !empty($session_id)) {
$type_event_class = 'session_event';
$type_label = get_lang('Session calendar');
}
@ -219,7 +219,7 @@ if (!empty($userId)) {
$agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type;
}
if ('course' == $type && !empty($courseId)) {
if ('course' === $type && !empty($courseId)) {
$agenda_ajax_url .= '&'.api_get_cidreq();
}

@ -26,11 +26,11 @@ if (!empty($groupId)) {
$groupProperties = GroupManager::get_group_properties($groupId);
$groupId = $groupProperties['iid'];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH)."group/group_space.php?".api_get_cidreq(),
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
'name' => get_lang('Group area').' '.$groupProperties['name'],
];
}
@ -88,21 +88,21 @@ $tpl->assign('show_action', in_array($type, ['course', 'session']));
$tpl->assign('agenda_actions', $actions);
$tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
if (api_is_allowed_to_edit()) {
if ('change_visibility' === $action) {
$courseInfo = api_get_course_info();
$courseCondition = '';
// This happens when list agenda is not inside a course
if (('course' === $type || 'session' === $type && !empty($courseInfo))) {
// For course and session event types
// Just needs course ID
$agenda->changeVisibility($_GET['id'], $_GET['visibility'], $courseInfo);
} else {
$courseCondition = '&'.api_get_cidreq();
}
header('Location: '.api_get_self().'?type='.$agenda->type.$courseCondition);
exit;
if ('change_visibility' === $action && api_is_allowed_to_edit()) {
$courseInfo = api_get_course_info();
$courseCondition = '';
// This happens when list agenda is not inside a course
if (!empty($courseInfo) && ('course' === $type || 'session' === $type)) {
// For course and session event types
// Just needs course ID
$courseCondition = '&'.api_get_cidreq();
}
$agenda->changeVisibility($_GET['id'], $_GET['visibility'], $courseInfo);
Display::addFlash(Display::return_message(get_lang('Updated')));
header('Location: '.api_get_self().'?type='.$agenda->type.$courseCondition);
exit;
}
$templateName = $tpl->get_template('agenda/event_list.tpl');

@ -1,86 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file is responsible for passing requested documents to the browser.
* Html files are parsed to fix a few problems with URLs,
* but this code will hopefully be replaced soon by an Apache URL
* rewrite mechanism.
*/
session_cache_limiter('public');
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
// IMPORTANT to avoid caching of documents
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
header('Cache-Control: public');
header('Pragma: no-cache');
$course_id = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : api_get_course_int_id();
$user_id = api_get_user_id();
$course_info = api_get_course_info_by_id($course_id);
$doc_url = $_REQUEST['file'];
if (empty($course_id) || empty($doc_url)) {
api_not_allowed();
}
$session_id = api_get_session_id();
$is_user_is_subscribed = CourseManager::is_user_subscribed_in_course(
$user_id,
$course_info['code'],
true,
$session_id
);
if (!api_is_allowed_to_edit() && !$is_user_is_subscribed) {
api_not_allowed();
}
//change the '&' that got rewritten to '///' by mod_rewrite back to '&'
$doc_url = str_replace('///', '&', $doc_url);
//still a space present? it must be a '+' (that got replaced by mod_rewrite)
$doc_url = str_replace(' ', '+', $doc_url);
$doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
$full_file_name = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/upload/calendar/'.$doc_url;
//if the rewrite rule asks for a directory, we redirect to the document explorer
if (is_dir($full_file_name)) {
while ('/' == $doc_url[$dul = strlen($doc_url) - 1]) {
$doc_url = substr($doc_url, 0, $dul);
}
// create the path
$document_explorer = api_get_path(WEB_COURSE_PATH).$course_info['path']; // home course path
// redirect
header('Location: '.$document_explorer);
exit;
}
$tbl_agenda_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
// launch event
Event::event_download($doc_url);
$sql = 'SELECT filename FROM '.$tbl_agenda_attachment.'
WHERE
c_id = '.$course_id.' AND
path LIKE BINARY "'.Database::escape_string($doc_url).'"';
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_array($result);
$title = str_replace(' ', '_', $row['filename']);
if (Security::check_abs_path(
$full_file_name,
api_get_path(SYS_COURSE_PATH).$course_info['path'].'/upload/calendar/'
)) {
$result = DocumentManager::file_send_for_download($full_file_name, true, $title);
if (false === $result) {
api_not_allowed(true);
}
}
}
api_not_allowed();

@ -109,7 +109,7 @@ switch ($action) {
$start = isset($_REQUEST['start']) ? api_strtotime($_REQUEST['start']) : null;
$end = isset($_REQUEST['end']) ? api_strtotime($_REQUEST['end']) : null;
if ('personal' == $type && !empty($sessionId)) {
if ('personal' === $type && !empty($sessionId)) {
$agenda->setSessionId($sessionId);
}

@ -7,6 +7,8 @@ use Chamilo\CoreBundle\Entity\Resource\ResourceLink;
use Chamilo\CoreBundle\Entity\SysCalendar;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CCalendarEvent;
use Chamilo\CourseBundle\Entity\CCalendarEventAttachment;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Class Agenda.
@ -230,7 +232,7 @@ class Agenda
* @param array $usersToSend array('everyone') or a list of user/group ids
* @param bool $addAsAnnouncement event as a *course* announcement
* @param int $parentEventId
* @param array $attachmentArray array of $_FILES['']
* @param UploadedFile[] $attachmentArray array of $_FILES['']
* @param array $attachmentCommentList
* @param string $eventComment
* @param string $color
@ -429,7 +431,7 @@ class Agenda
}
$em->flush();
$id = $event->getId();
$id = $event->getIid();
if ($id) {
$sql = "UPDATE ".$this->tbl_course_agenda." SET id = iid WHERE iid = $id";
@ -437,18 +439,15 @@ class Agenda
// Add announcement.
if ($addAsAnnouncement) {
$this->storeAgendaEventAsAnnouncement(
$id,
$usersToSend
);
$this->storeAgendaEventAsAnnouncement($id, $usersToSend);
}
// Add attachment.
if (isset($attachmentArray) && !empty($attachmentArray)) {
if (!empty($attachmentArray)) {
$counter = 0;
foreach ($attachmentArray as $attachmentItem) {
$this->addAttachment(
$id,
$event,
$attachmentItem,
$attachmentCommentList[$counter],
$this->course
@ -1109,9 +1108,7 @@ class Agenda
Getting siblings and delete 'Em all + the father! */
if (isset($eventInfo['parent_event_id']) && !empty($eventInfo['parent_event_id'])) {
// Removing items.
$events = $this->getAllRepeatEvents(
$eventInfo['parent_event_id']
);
$events = $this->getAllRepeatEvents($eventInfo['parent_event_id']);
if (!empty($events)) {
foreach ($events as $event) {
$this->deleteEvent($event['id']);
@ -1130,38 +1127,46 @@ class Agenda
}
}
// Removing from events.
Database::delete(
$this->tbl_course_agenda,
['id = ? AND c_id = ?' => [$id, $courseId]]
);
$repo = Container::getCalendarEventRepository();
$event = $repo->find($id);
api_item_property_update(
$this->course,
TOOL_CALENDAR_EVENT,
$id,
'delete',
api_get_user_id()
);
if ($event) {
$repo->getEntityManager()->remove($event);
$repo->getEntityManager()->flush();
// Removing from series.
Database::delete(
$this->table_repeat,
[
'cal_id = ? AND c_id = ?' => [
$id,
$courseId,
],
]
);
// Removing from events.
/*Database::delete(
$this->tbl_course_agenda,
['id = ? AND c_id = ?' => [$id, $courseId]]
);*/
if (isset($eventInfo['attachment']) && !empty($eventInfo['attachment'])) {
foreach ($eventInfo['attachment'] as $attachment) {
self::deleteAttachmentFile(
$attachment['id'],
$this->course
);
}
/*api_item_property_update(
$this->course,
TOOL_CALENDAR_EVENT,
$id,
'delete',
api_get_user_id()
);*/
// Removing from series.
Database::delete(
$this->table_repeat,
[
'cal_id = ? AND c_id = ?' => [
$id,
$courseId,
],
]
);
// Attachments are already deleted using the doctrine remove() function.
/*if (isset($eventInfo['attachment']) && !empty($eventInfo['attachment'])) {
foreach ($eventInfo['attachment'] as $attachment) {
self::deleteAttachmentFile(
$attachment['id'],
$this->course
);
}
}*/
}
}
break;
@ -1535,10 +1540,7 @@ class Agenda
);
}
$event['attachment'] = $this->getAttachmentList(
$id,
$this->course
);
$event['attachment'] = $this->getAttachmentList($id, $this->course);
}
}
break;
@ -1652,6 +1654,42 @@ class Agenda
$courseId = (int) $courseId;
$sessionId = (int) $sessionId;
$repo = Container::getCalendarEventRepository();
/** @var CCalendarEvent $event */
$event = $repo->find($eventId);
if (null === $event) {
return [];
}
$course = api_get_course_entity($courseId);
$session = api_get_session_entity($sessionId);
$users = [];
$groups = [];
$everyone = false;
$links = $event->getResourceNode()->getResourceLinks();
foreach ($links as $link) {
if ($link->getUser()) {
$users[] = $link->getUser()->getId();
}
if ($link->getGroup()) {
$groups[] = $link->getGroup()->getId();
}
}
if (empty($users) && empty($groups)) {
$everyone = true;
}
return [
'everyone' => $everyone,
'users' => $users,
'groups' => $groups,
];
exit;
$sessionCondition = "ip.session_id = $sessionId";
if (empty($sessionId)) {
$sessionCondition = " (ip.session_id = 0 OR ip.session_id IS NULL) ";
@ -1765,12 +1803,14 @@ class Agenda
if (empty($courseInfo)) {
return [];
}
$courseId = $courseInfo['real_id'];
if (empty($courseId)) {
return [];
}
$userId = api_get_user_id();
$sessionId = (int) $sessionId;
$user_id = (int) $user_id;
@ -1792,7 +1832,7 @@ class Agenda
$isAllowToEdit = true;
} else {
$isAllowToEdit = CourseManager::is_course_teacher(
api_get_user_id(),
$userId,
$courseInfo['code']
);
}
@ -1801,7 +1841,7 @@ class Agenda
if (!empty($sessionId)) {
$allowDhrToEdit = api_get_configuration_value('allow_agenda_edit_for_hrm');
if ($allowDhrToEdit) {
$isHrm = SessionManager::isUserSubscribedAsHRM($sessionId, api_get_user_id());
$isHrm = SessionManager::isUserSubscribedAsHRM($sessionId, $userId);
if ($isHrm) {
$isAllowToEdit = $isAllowToEditByHrm = true;
}
@ -1820,17 +1860,13 @@ class Agenda
}
} else {
// get only related groups from user
$groupMemberships = GroupManager::get_group_ids(
$courseId,
api_get_user_id()
);
$groupMemberships = GroupManager::get_group_ids($courseId, $userId);
}
}
$repo = Container::getCalendarEventRepository();
$courseEntity = api_get_course_entity($courseId);
$session = api_get_session_entity($sessionId);
$qb = $repo->getResourcesByCourseOnly($courseEntity, $courseEntity->getResourceNode());
$userCondition = '';
@ -1874,7 +1910,6 @@ class Agenda
if (empty($groupId)) {
// Show events sent to everyone and no group
$userCondition = ' ( (links.user is NULL) AND (links.group IS NULL) ';
// Show events sent to selected groups
if (!empty($groupMemberships)) {
$userCondition .= " OR (links.user is NULL) AND (links.group IN (".implode(", ", $groupMemberships)."))) ";
@ -1993,13 +2028,11 @@ class Agenda
$sql .= $dateCondition;
$result = Database::query($sql);*/
$coachCanEdit = false;
if (!empty($sessionId)) {
$coachCanEdit = api_is_coach($sessionId, $courseId) || api_is_platform_admin();
}
//var_dump($courseId); echo $qb->getQuery()->getSQL();exit;
//var_dump($groupMemberships, $courseId); echo $qb->getQuery()->getSQL();exit;
$events = $qb->getQuery()->getResult();
//$eventsAdded = array_column($this->events, 'unique_id');
/** @var CCalendarEvent $row */
@ -2022,22 +2055,24 @@ class Agenda
);
$group_to_array = $items['groups'];
$user_to_array = $items['users'];*/
$attachmentList = $this->getAttachmentList(
/*$attachmentList = $this->getAttachmentList(
$eventId,
$courseInfo
);
);*/
$attachmentList = $row->getAttachments();
$event['attachment'] = '';
if (!empty($attachmentList)) {
$icon = Display::returnFontAwesomeIcon(
'paperclip',
'1'
);
$repo = Container::getCalendarEventAttachmentRepository();
foreach ($attachmentList as $attachment) {
$has_attachment = Display::return_icon(
'attachment.gif',
get_lang('Attachment')
);
$user_filename = $attachment['filename'];
$url = api_get_path(WEB_CODE_PATH).'calendar/download.php?file='.$attachment['path'].'&course_id='.$courseId.'&'.api_get_cidreq();
$event['attachment'] .= $has_attachment.
//$url = api_get_path(WEB_CODE_PATH).'calendar/download.php?file='.$attachment['path'].'&course_id='.$courseId.'&'.api_get_cidreq();
$url = $repo->getResourceFileDownloadUrl($attachment);
$event['attachment'] .= $icon.
Display::url(
$user_filename,
$attachment->getFilename(),
$url
).'<br />';
}
@ -2150,9 +2185,8 @@ class Agenda
/*if (empty($event['sent_to'])) {
$event['sent_to'] = '<div class="label_tag notice">'.get_lang('Everyone').'</div>';
}*/
$event['description'] = $row->getContent();
$event['visibility'] = 1;
$event['visibility'] = $row->isVisible($courseEntity, $session) ? 1 : 0;
$event['real_id'] = $eventId;
$event['allDay'] = $row->getAllDay();
$event['parent_event_id'] = $row->getParentEventId();
@ -2699,14 +2733,30 @@ class Agenda
$courseInfo,
$userId = null
) {
$id = intval($id);
$id = (int) $id;
$repo = Container::getCalendarEventRepository();
/** @var CCalendarEvent $event */
$event = $repo->find($id);
$visibility = (int) $visibility;
if ($event) {
if (0 === $visibility) {
$repo->setVisibilityDraft($event);
} else {
$repo->setVisibilityPublished($event);
}
}
return true;
if (empty($userId)) {
$userId = api_get_user_id();
} else {
$userId = intval($userId);
$userId = (int) $userId;
}
if (0 == $visibility) {
if (0 === $visibility) {
api_item_property_update(
$courseInfo,
TOOL_CALENDAR_EVENT,
@ -2727,10 +2777,8 @@ class Agenda
/**
* Get repeat types.
*
* @return array
*/
public static function getRepeatTypes()
public static function getRepeatTypes(): array
{
return [
'daily' => get_lang('Daily'),
@ -2809,82 +2857,90 @@ class Agenda
/**
* Add an attachment file into agenda.
*
* @param int $eventId
* @param array $fileUserUpload ($_FILES['user_upload'])
* @param string $comment about file
* @param array $courseInfo
* @param CCalendarEvent $event
* @param UploadedFile $file
* @param string $comment
* @param array $courseInfo
*
* @return string
*/
public function addAttachment(
$eventId,
$fileUserUpload,
$event,
$file,
$comment,
$courseInfo
) {
$agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
$eventId = (int) $eventId;
// Storing the attachments
$upload_ok = false;
if (!empty($fileUserUpload['name'])) {
$upload_ok = process_uploaded_file($fileUserUpload);
$valid = false;
if ($file) {
$valid = process_uploaded_file($file);
}
if (!empty($upload_ok)) {
$courseDir = $courseInfo['directory'].'/upload/calendar';
if ($valid) {
/*$courseDir = $courseInfo['directory'].'/upload/calendar';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$uploadDir = $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 = add_ext_on_mime(
/*$new_file_name = add_ext_on_mime(
stripslashes($fileUserUpload['name']),
$fileUserUpload['type']
);
);*/
// user's file name
$file_name = $fileUserUpload['name'];
$fileName = $file->getClientOriginalName();
$courseId = api_get_course_int_id();
/*$new_file_name = uniqid('');
$new_path = $uploadDir.'/'.$new_file_name;
$result = @move_uploaded_file(
$fileUserUpload['tmp_name'],
$new_path
);
$courseId = api_get_course_int_id();
$size = intval($fileUserUpload['size']);*/
// Storing the attachments if any
//if ($result) {
$attachment = new CCalendarEventAttachment();
$attachment
->setCId($courseId)
->setFilename($fileName)
->setComment($comment)
->setPath($fileName)
->setEvent($event)
->setSize($file->getSize())
;
$repo = Container::getCalendarEventAttachmentRepository();
$repo->addResourceToCourseWithParent(
$attachment,
$event->getResourceNode(),
ResourceLink::VISIBILITY_PUBLISHED,
api_get_user_entity(api_get_user_id()),
api_get_course_entity(),
api_get_session_entity(),
api_get_group_entity(),
$file
);
if (!filter_extension($new_file_name)) {
return Display::return_message(
get_lang('File upload failed: this file extension or file type is prohibited'),
'error'
);
} else {
$new_file_name = uniqid('');
$new_path = $uploadDir.'/'.$new_file_name;
$result = @move_uploaded_file(
$fileUserUpload['tmp_name'],
$new_path
);
$courseId = api_get_course_int_id();
$size = intval($fileUserUpload['size']);
// Storing the attachments if any
if ($result) {
$params = [
'c_id' => $courseId,
'filename' => $file_name,
'comment' => $comment,
'path' => $new_file_name,
'agenda_id' => $eventId,
'size' => $size,
];
$id = Database::insert($agenda_table_attachment, $params);
if ($id) {
$sql = "UPDATE $agenda_table_attachment
SET id = iid WHERE iid = $id";
Database::query($sql);
api_item_property_update(
$courseInfo,
'calendar_event_attachment',
$id,
'AgendaAttachmentAdded',
api_get_user_id()
);
}
}
$repo->getEntityManager()->flush();
$id = $attachment->getIid();
if ($id) {
$table = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
$sql = "UPDATE $table
SET id = iid WHERE iid = $id";
Database::query($sql);
/*api_item_property_update(
$courseInfo,
'calendar_event_attachment',
$id,
'AgendaAttachmentAdded',
api_get_user_id()
);*/
}
}
}

@ -35,7 +35,7 @@
&dash;
{% if event.allDay %}
{{ 'AllDay' | get_lang }}
{{ 'All day' | trans }}
{% else %}
{{ event.end_date_localtime }}
{% endif %}

@ -1,72 +1,71 @@
{% autoescape false %}
<script>
function checkLength( o, n, min, max ) {
if ( o.val().length > max || o.val().length < min ) {
o.addClass( "ui-state-error" );
/*updateTips( "Length of " + n + " must be between " +
min + " and " + max + "." );*/
return false;
} else {
return true;
function checkLength( o, n, min, max ) {
if ( o.val().length > max || o.val().length < min ) {
o.addClass( "ui-state-error" );
/*updateTips( "Length of " + n + " must be between " +
min + " and " + max + "." );*/
return false;
} else {
return true;
}
}
}
function clean_user_select() {
//Cleans the selected attr
$("#users_to_send").val('').trigger("chosen:updated");
}
var region_value = '{{ region_value }}';
$(function() {
var cookieData = Cookies.getJSON('agenda_cookies');
var defaultView = (cookieData && cookieData.view) || '{{ default_view }}';
var defaultStartDate = (cookieData && cookieData.start) || moment.now();
// Reset button.
$("button[type=reset]").click(function() {
$("#session_id").find('option').removeAttr("selected");
});
function loadColors(calEvent){
$("#calendarModal #color_calendar").removeClass();
$("#calendarModal #color_calendar").html('{{ type_label | escape('js') }}');
$("#calendarModal #color_calendar").addClass('label_tag');
$("#calendarModal #color_calendar").addClass(calEvent.type+'_event');
function clean_user_select() {
//Cleans the selected attr
$("#users_to_send").val('').trigger("chosen:updated");
}
var title = $("#title"),
content = $("#content"),
allFields = $([]).add( title ).add( content ), tips = $(".validateTips");
var region_value = '{{ region_value }}';
$("#select_form_id_search").change(function() {
var temp ="&user_id="+$("#select_form_id_search").val();
var position =String(window.location).indexOf("&user");
var url = String(window.location).substring(0,position)+temp;
if (position > 0) {
window.location.replace(url);
} else {
url = String(window.location)+temp;
window.location.replace(url);
$(function() {
var cookieData = Cookies.getJSON('agenda_cookies');
var defaultView = (cookieData && cookieData.view) || '{{ default_view }}';
var defaultStartDate = (cookieData && cookieData.start) || moment.now();
// Reset button.
$("button[type=reset]").click(function() {
$("#session_id").find('option').removeAttr("selected");
});
function loadColors(calEvent){
$("#calendarModal #color_calendar").removeClass();
$("#calendarModal #color_calendar").html('{{ type_label | escape('js') }}');
$("#calendarModal #color_calendar").addClass('label_tag');
$("#calendarModal #color_calendar").addClass(calEvent.type+'_event');
}
});
var calendar = $('#calendar').fullCalendar({
themeSystem: 'bootstrap4',
contentHeight: 650,
handleWindowResize: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listMonth'
},
views: {
/*listDay: { buttonText: 'list day' },
listWeek: { buttonText: 'list week' },*/
listMonth: { buttonText: 'list month' },
},
locale: region_value,
{% if use_google_calendar == 1 %}
var title = $("#title"),
content = $("#content"),
allFields = $([]).add( title ).add( content ), tips = $(".validateTips");
$("#select_form_id_search").change(function() {
var temp ="&user_id="+$("#select_form_id_search").val();
var position =String(window.location).indexOf("&user");
var url = String(window.location).substring(0,position)+temp;
if (position > 0) {
window.location.replace(url);
} else {
url = String(window.location)+temp;
window.location.replace(url);
}
});
var calendar = $('#calendar').fullCalendar({
themeSystem: 'bootstrap4',
contentHeight: 650,
handleWindowResize: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listMonth'
},
views: {
/*listDay: { buttonText: 'list day' },
listWeek: { buttonText: 'list week' },*/
listMonth: { buttonText: 'list month' },
},
locale: region_value,
{% if use_google_calendar == 1 %}
eventSources: [
// if you want to add more just add URL in this array
'{{ google_calendar_url }}',
@ -74,391 +73,397 @@ $(function() {
className: 'gcal-event' // an option!
}
],
{% endif %}
defaultView: defaultView,
defaultDate: defaultStartDate,
firstHour: 8,
firstDay: 1,
selectable : true,
selectHelper: true,
viewRender: function(view, element) {
var data = {
'view': view.name,
'start': view.intervalStart.format("YYYY-MM-DD")
};
Cookies.set('agenda_cookies', data, 1); // Expires 1 day
},
// Add event
select: function(start, end, jsEvent, view) {
//var start_date = start.format("YYYY-MM-DD h:mm");
//var end_date = end.format("YYYY-MM-DD h:mm");
var diffDays = moment(end).diff(start, 'days');
var allDay = true;
if (end.hasTime()) {
allDay = false;
}
$('#visible_to_input').show();
$('#add_as_announcement_div').show();
$('#visible_to_read_only').hide();
// Cleans the selected attr
clean_user_select();
// Sets the 1st item selected by default
$('#users_to_send option').eq(0).attr('selected', 'selected');
// Update chz-select
//$("#users_to_send").trigger("chosen:updated");
if ({{ can_add_events }} == 1) {
var url = '{{ web_agenda_ajax_url }}&a=add_event&start='+start.format("YYYY-MM-DD HH:mm:00")+'&end='+end.format("YYYY-MM-DD HH:mm:00")+'&all_day='+allDay+'&view='+view.name;
var start_date_value = start.format('{{ js_format_date }}');
$('#start_date').html(start_date_value);
if (diffDays > 1) {
$('#start_date').html('');
var end_date_value = '';
if (end) {
var clone = end.clone();
end_date_value = clone.subtract(1, 'days').format('{{ js_format_date }}');
}
$('#end_date').html(start_date_value + " - " + end_date_value);
} else if (diffDays == 0) {
var start_date_value = start.format('ll');
var startTime = start.format('LT');
var endTime = end.format('LT');
$('#start_date').html('');
$('#end_date').html(start_date_value + " (" + startTime + " - " + endTime+") ");
} else {
$('#end_date').html('');
{% endif %}
defaultView: defaultView,
defaultDate: defaultStartDate,
firstHour: 8,
firstDay: 1,
selectable : true,
selectHelper: true,
viewRender: function(view, element) {
var data = {
'view': view.name,
'start': view.intervalStart.format("YYYY-MM-DD")
};
Cookies.set('agenda_cookies', data, 1); // Expires 1 day
},
// Add event
select: function(start, end, jsEvent, view) {
//var start_date = start.format("YYYY-MM-DD h:mm");
//var end_date = end.format("YYYY-MM-DD h:mm");
var diffDays = moment(end).diff(start, 'days');
var allDay = true;
if (end.hasTime()) {
allDay = false;
}
$('#color_calendar')
.html('{{ type_label | escape('js')}}')
.removeClass('group_event')
.addClass('label_tag')
.addClass('{{ type_event_class | escape('js') }}')
.css('background-color', '{{ type_event_color }}');
//It shows the CKEDITOR while Adding an Event
$('#cke_content').show();
//Reset the CKEditor content that persist in memory
CKEDITOR.instances['content'].setData('');
allFields.removeClass("ui-state-error");
$("#modalDialogForm").modal();
var btnSave = '<button id="btnSave" type="button" class="btn btn-primary">{{ "Add" | get_lang }}</button>';
$("#modalDialogForm #modalFooter").html(btnSave);
$("#btnSave").click( function() {
var bValid = true;
bValid = bValid && checkLength(title, "title", 1, 255);
//Update the CKEditor Instance to the remplaced textarea, ready to be serializable
for ( instance in CKEDITOR.instances ) {
CKEDITOR.instances[instance].updateElement();
$('#visible_to_input').show();
$('#add_as_announcement_div').show();
$('#visible_to_read_only').hide();
// Cleans the selected attr
clean_user_select();
// Sets the 1st item selected by default
$('#users_to_send option').eq(0).attr('selected', 'selected');
// Update chz-select
//$("#users_to_send").trigger("chosen:updated");
if ({{ can_add_events }} == 1) {
var url = '{{ web_agenda_ajax_url }}&a=add_event&start='+start.format("YYYY-MM-DD HH:mm:00")+'&end='+end.format("YYYY-MM-DD HH:mm:00")+'&all_day='+allDay+'&view='+view.name;
var start_date_value = start.format('{{ js_format_date }}');
$('#start_date').html(start_date_value);
if (diffDays > 1) {
$('#start_date').html('');
var end_date_value = '';
if (end) {
var clone = end.clone();
end_date_value = clone.subtract(1, 'days').format('{{ js_format_date }}');
}
$('#end_date').html(start_date_value + " - " + end_date_value);
} else if (diffDays == 0) {
var start_date_value = start.format('ll');
var startTime = start.format('LT');
var endTime = end.format('LT');
$('#start_date').html('');
$('#end_date').html(start_date_value + " (" + startTime + " - " + endTime+") ");
} else {
$('#end_date').html('');
}
var params = $("#add_event_form").serialize();
$.ajax({
url: url+'&'+params,
success:function(data) {
var user = $('#users_to_send').val();
if (user) {
if (user.length > 1) {
user = 0;
} else {
user = user[0];
}
var user_length = String(user).length;
if (String(user).substring(0,1) == 'G') {
var user_id = String(user).substring(6,user_length);
var user_id = "G:"+user_id;
} else {
var user_id = String(user).substring(5,user_length);
$('#color_calendar')
.html('{{ type_label | escape('js')}}')
.removeClass('group_event')
.addClass('label_tag')
.addClass('{{ type_event_class | escape('js') }}')
.css('background-color', '{{ type_event_color }}');
//It shows the CKEDITOR while Adding an Event
$('#cke_content').show();
//Reset the CKEditor content that persist in memory
CKEDITOR.instances['content'].setData('');
allFields.removeClass("ui-state-error");
$("#modalDialogForm").modal();
var btnSave = '<button id="btnSave" type="button" class="btn btn-primary">{{ "Add" | trans }}</button>';
$("#modalDialogForm #modalFooter").html(btnSave);
$("#btnSave").click( function() {
var bValid = true;
bValid = bValid && checkLength(title, "title", 1, 255);
//Update the CKEditor Instance to the remplaced textarea, ready to be serializable
for ( instance in CKEDITOR.instances ) {
CKEDITOR.instances[instance].updateElement();
}
var params = $("#add_event_form").serialize();
$.ajax({
url: url+'&'+params,
success:function(data) {
var user = $('#users_to_send').val();
if (user) {
if (user.length > 1) {
user = 0;
} else {
user = user[0];
}
var user_length = String(user).length;
if (String(user).substring(0,1) == 'G') {
var user_id = String(user).substring(6,user_length);
var user_id = "G:"+user_id;
} else {
var user_id = String(user).substring(5,user_length);
}
//var temp = "&user_id="+user_id;
//var position = String(window.location).indexOf("&user");
//var url = String(window.location).substring(0, position)+temp;
/*if (position > 0) {
window.location.replace(url);
} else {
url = String(window.location)+temp;
window.location.replace(url);
}*/
}
//var temp = "&user_id="+user_id;
//var position = String(window.location).indexOf("&user");
//var url = String(window.location).substring(0, position)+temp;
/*if (position > 0) {
window.location.replace(url);
} else {
url = String(window.location)+temp;
window.location.replace(url);
}*/
}
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('rerenderEvents');
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('rerenderEvents');
$('#modalDialogForm').modal('toggle');
}
$('#modalDialogForm').modal('toggle');
}
});
});
});
calendar.fullCalendar('unselect');
//Reload events
calendar.fullCalendar("refetchEvents");
calendar.fullCalendar("rerenderEvents");
}
},
eventClick: function(calEvent, jsEvent, view) {
var start = calEvent.start;
var end = calEvent.end;
var diffDays = moment(end).diff(start, 'days');
var endDateMinusOne = '';
if (end) {
var clone = end.clone();
endDateMinusOne = clone.subtract(1, 'days').format('{{ js_format_date }}');
}
var startDateToString = start.format("{{ js_format_date }}");
// Edit event.
if (calEvent.editable) {
$('#visible_to_input').hide();
$('#add_as_announcement_div').hide();
{% if type != 'admin' %}
$('#visible_to_read_only').show();
$("#visible_to_read_only_users").html(calEvent.sent_to);
$(".user-sender").show();
{% endif %}
loadColors(calEvent);
$('#simple_start_date').html(startDateToString);
if (diffDays > 1) {
$('#simple_end_date').html(' - ' + endDateMinusOne);
} else if (diffDays == 0) {
var start_date_value = start.format('ll');
var startTime = start.format('LT');
var endTime = end.format('LT');
$('#simple_start_date').html('');
$('#simple_end_date').html(start_date_value + " (" + startTime + " - " + endTime+") ");
} else {
$('#simple_end_date').html('');
calendar.fullCalendar('unselect');
//Reload events
calendar.fullCalendar("refetchEvents");
calendar.fullCalendar("rerenderEvents");
}
},
eventClick: function(calEvent, jsEvent, view) {
var start = calEvent.start;
var end = calEvent.end;
var diffDays = moment(end).diff(start, 'days');
var endDateMinusOne = '';
if (end) {
var clone = end.clone();
endDateMinusOne = clone.subtract(1, 'days').format('{{ js_format_date }}');
}
var startDateToString = start.format("{{ js_format_date }}");
// Edit event.
if (calEvent.editable) {
$('#visible_to_input').hide();
$('#add_as_announcement_div').hide();
{% if type != 'admin' %}
$('#visible_to_read_only').show();
$("#visible_to_read_only_users").html(calEvent.sent_to);
$(".user-sender").show();
{% endif %}
loadColors(calEvent);
$('#simple_start_date').html(startDateToString);
if (diffDays > 1) {
$('#simple_end_date').html(' - ' + endDateMinusOne);
} else if (diffDays == 0) {
var start_date_value = start.format('ll');
var startTime = start.format('LT');
var endTime = end.format('LT');
$('#simple_start_date').html('');
$('#simple_end_date').html(start_date_value + " (" + startTime + " - " + endTime+") ");
} else {
$('#simple_end_date').html('');
}
$("#simple_title").html(calEvent.title);
$("#simple_content").html(calEvent.description);
$("#simple_comment").html(calEvent.comment);
$("#simple_title").html(calEvent.title);
$("#simple_content").html(calEvent.description);
$("#simple_comment").html(calEvent.comment);
$("#simple_attachment").html(calEvent.attachment);
if (calEvent.course_name) {
$("#calendar_course_info_simple").html(calEvent.course_name);
$("#type_course").html("{{ 'Course' | get_lang }}");
} else {
$("#calendar_course_info_simple").html('');
}
if (calEvent.session_name) {
$("#calendar_course_info_simple").html(calEvent.session_name);
$('#type_course').html("{{ 'Session' | get_lang }}");
} else {
$("#calendar_course_info_simple").html('');
}
if (calEvent.course_name) {
$("#calendar_course_info_simple").html(calEvent.course_name);
$("#type_course").html("{{ 'Course' | trans }}");
}
allFields.removeClass( "ui-state-error" );
$('#calendarModal #modalTitle').html(calEvent.title);
$('#calendarModal').modal();
var url = '{{ web_agenda_ajax_url }}&a=edit_event&id='+calEvent.id+'&view='+view.name;
var delete_url = '{{ web_agenda_ajax_url }}&a=delete_event&id='+calEvent.id;
var urlOne = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
var urlTwo = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
var urlThree = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
var urlEdit = "{{ _p.web_main }}calendar/agenda.php?action=edit&type=fromjs&id="+calEvent.id+'&course_id='+calEvent.course_id+"";
var exportCalConfidential = '<a href="'+urlOne+'" class="btn btn-light">{{"ExportiCalConfidential"|get_lang}}</a>';
var exportCalPrivate = '<a href="'+urlTwo+'" class="btn btn-light">{{"ExportiCalPrivate"|get_lang}}</a>';
var exportCalPublic = '<a href="'+urlThree+'" class="btn btn-light">{{"ExportiCalPrivate"|get_lang}}</a>';
var btnEdit = '<a href="'+urlEdit+'" id="btnEdit" class="btn btn-primary">{{ "Edit" | get_lang }}</a>';
var btnDelete = '<button type="button" id="btnDelete" class="btn btn-danger">{{ "Delete" | get_lang }}</button>';
$('#calendarModal #modalFooter').html(exportCalConfidential+exportCalPrivate+exportCalPublic+btnEdit+btnDelete);
{% if type == 'not_available' %}
$('#btnEdit').click(function() {
var bValid = true;
bValid = bValid && checkLength( title, "title", 1, 255 );
var params = $("#add_event_form").serialize();
$.ajax({
url: url+'&'+params,
success:function() {
calEvent.title = $("#title").val();
calEvent.start = calEvent.start;
calEvent.end = calEvent.end;
calEvent.allDay = calEvent.allDay;
calEvent.description = $("#content").val();
calendar.fullCalendar('updateEvent',
calEvent,
true // make the event "stick"
);
//close modal
$('#calendarModal').modal('toggle');
}
});
});
{% endif %}
$('#btnDelete').click(function() {
if (calEvent.parent_event_id || calEvent.has_children != '') {
var newDiv = $('<div>');
newDiv.dialog({
modal: true,
title: "{{ 'DeleteThisItem' | get_lang }}",
buttons: []
if (calEvent.session_name) {
$("#calendar_course_info_simple").html(calEvent.session_name);
$('#type_course').html("{{ 'Session' | trans }}");
}
if (calEvent.comment != '') {
$("#comment_edit").html(calEvent.comment);
$("#comment_edit").show();
}
if (calEvent.attachment != '') {
$("#attachment_text").html(calEvent.attachment);
$("#attachment_block").show();
$("#attachment_text").show();
}
allFields.removeClass( "ui-state-error" );
$('#calendarModal #modalTitle').html(calEvent.title);
$('#calendarModal').modal();
var url = '{{ web_agenda_ajax_url }}&a=edit_event&id='+calEvent.id+'&view='+view.name;
var delete_url = '{{ web_agenda_ajax_url }}&a=delete_event&id='+calEvent.id;
var urlOne = "{{ url('web.main') }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
var urlTwo = "{{ url('web.main') }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
var urlThree = "{{ url('web.main') }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
var urlEdit = "{{ url('web.main') }}calendar/agenda.php?action=edit&type=fromjs&id="+calEvent.id+'&course_id='+calEvent.course_id+"";
var exportCalConfidential = '<a href="'+urlOne+'" class="btn btn-light">{{"Export in iCal format as confidential event"|trans}}</a>';
var exportCalPrivate = '<a href="'+urlTwo+'" class="btn btn-light">{{"Export in iCal format as private event"|trans}}</a>';
var exportCalPublic = '<a href="'+urlThree+'" class="btn btn-light">{{"Export in iCal format as public event"|trans}}</a>';
var btnEdit = '<a href="'+urlEdit+'" id="btnEdit" class="btn btn-primary">{{ "Edit" | trans }}</a>';
var btnDelete = '<button type="button" id="btnDelete" class="btn btn-danger">{{ "Delete" | trans }}</button>';
$('#calendarModal #modalFooter').html(exportCalConfidential+exportCalPrivate+exportCalPublic+btnEdit+btnDelete);
{% if type == 'not_available' %}
$('#btnEdit').click(function() {
var bValid = true;
bValid = bValid && checkLength( title, "title", 1, 255 );
var params = $("#add_event_form").serialize();
$.ajax({
url: url+'&'+params,
success:function() {
calEvent.title = $("#title").val();
calEvent.start = calEvent.start;
calEvent.end = calEvent.end;
calEvent.allDay = calEvent.allDay;
calEvent.description = $("#content").val();
calendar.fullCalendar('updateEvent',
calEvent,
true // make the event "stick"
);
//close modal
$('#calendarModal').modal('toggle');
}
});
});
{% endif %}
$('#btnDelete').click(function() {
if (calEvent.parent_event_id || calEvent.has_children != '') {
var newDiv = $('<div>');
newDiv.dialog({
modal: true,
title: "{{ 'Delete this item' | trans }}",
buttons: []
});
var buttons = newDiv.dialog("option", "buttons");
var buttons = newDiv.dialog("option", "buttons");
if (calEvent.has_children == '0') {
buttons.push({
text: '{{ "Delete this item" | trans }}',
click: function() {
$.ajax({
url: delete_url,
success:function() {
calendar.fullCalendar('removeEvents',
calEvent
);
calendar.fullCalendar("refetchEvents");
calendar.fullCalendar("rerenderEvents");
$("#dialog-form").dialog("close");
newDiv.dialog( "destroy" );
}
});
}
});
newDiv.dialog("option", "buttons", buttons);
}
if (calEvent.has_children == '0') {
var buttons = newDiv.dialog("option", "buttons");
buttons.push({
text: '{{ "DeleteThisItem" | get_lang }}',
text: '{{ "Delete all items" | trans }}',
click: function() {
$.ajax({
url: delete_url,
url: delete_url+'&delete_all_events=1',
success:function() {
calendar.fullCalendar('removeEvents',
calEvent
);
calendar.fullCalendar("refetchEvents");
calendar.fullCalendar("rerenderEvents");
$("#dialog-form").dialog("close");
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('rerenderEvents');
$("#dialog-form").dialog('close');
newDiv.dialog( "destroy" );
}
});
}
});
newDiv.dialog("option", "buttons", buttons);
return true;
}
var buttons = newDiv.dialog("option", "buttons");
buttons.push({
text: '{{ "DeleteAllItems" | get_lang }}',
click: function() {
$.ajax({
url: delete_url+'&delete_all_events=1',
success:function() {
calendar.fullCalendar('removeEvents',
calEvent
);
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('rerenderEvents');
$("#dialog-form").dialog('close');
newDiv.dialog( "destroy" );
}
});
$.ajax({
url: delete_url,
success:function() {
calendar.fullCalendar('removeEvents',
calEvent
);
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('rerenderEvents');
//close modal
$('#calendarModal').modal('toggle');
}
});
newDiv.dialog("option", "buttons", buttons);
return true;
}
$.ajax({
url: delete_url,
success:function() {
calendar.fullCalendar('removeEvents',
calEvent
);
calendar.fullCalendar('refetchEvents');
calendar.fullCalendar('rerenderEvents');
//close modal
$('#calendarModal').modal('toggle');
}
});
});
} else {
// Simple form
$('#simple_start_date').html(startDateToString);
if (diffDays > 1) {
$('#simple_end_date').html(' - ' + endDateMinusOne);
} else if (diffDays == 0) {
var start_date_value = start.format('ll');
var startTime = start.format('LT');
var endTime = end.format('LT');
$('#simple_start_date').html('');
$('#simple_end_date').html(start_date_value + " (" + startTime + " - " + endTime+") ");
} else {
$('#simple_end_date').html('');
}
loadColors(calEvent);
// Simple form
$('#simple_start_date').html(startDateToString);
if (diffDays > 1) {
$('#simple_end_date').html(' - ' + endDateMinusOne);
} else if (diffDays == 0) {
var start_date_value = start.format('ll');
var startTime = start.format('LT');
var endTime = end.format('LT');
$('#simple_start_date').html('');
$('#simple_end_date').html(start_date_value + " (" + startTime + " - " + endTime+") ");
} else {
$('#simple_end_date').html('');
}
if (calEvent.course_name) {
$("#calendar_course_info_simple").html(calEvent.course_name);
$("#type_course").html("{{ 'Course' | get_lang }}");
} else {
$("#calendar_course_info_simple").html('');
}
loadColors(calEvent);
if (calEvent.session_name) {
$("#type_course").append("{{ 'Session' | get_lang }}");
$("#calendar_session_info").html(calEvent.session_name);
} else {
$("#calendar_session_info").html('');
}
if (calEvent.course_name) {
$("#calendar_course_info_simple").html(calEvent.course_name);
$("#type_course").html("{{ 'Course' | trans }}");
} else {
$("#calendar_course_info_simple").html('');
}
$("#simple_title").html(calEvent.title);
$("#simple_content").html(calEvent.description);
$("#simple_comment").html(calEvent.comment);
$('#modalTitle').html(calEvent.title);
$('#calendarModal').modal();
if (calEvent.session_name) {
$("#type_course").append("{{ 'Session' | trans }}");
$("#calendar_session_info").html(calEvent.session_name);
} else {
$("#calendar_session_info").html('');
}
$("#simple_title").html(calEvent.title);
$("#simple_content").html(calEvent.description);
$("#simple_comment").html(calEvent.comment);
$('#modalTitle').html(calEvent.title);
$('#calendarModal').modal();
var urlOne = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
var exportCalConfidential = '<a href="'+urlOne+'" class="btn btn-light">{{"ExportiCalConfidential"|get_lang}}</a>';
var urlTwo = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
var exportCalPrivate = '<a href="'+urlTwo+'" class="btn btn-light">{{"ExportiCalPrivate"|get_lang}}</a>';
var urlThree = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
var exportCalPublic = '<a href="'+urlThree+'" class="btn btn-light">{{"ExportiCalPrivate"|get_lang}}</a>';
var urlOne = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
var exportCalConfidential = '<a href="'+urlOne+'" class="btn btn-light">{{"Export in iCal format as confidential event"|trans}}</a>';
var urlTwo = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
var exportCalPrivate = '<a href="'+urlTwo+'" class="btn btn-light">{{"Export in iCal format as private event"|trans}}</a>';
var urlThree = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
var exportCalPublic = '<a href="'+urlThree+'" class="btn btn-light">{{"Export in iCal format as public event"|trans}}</a>';
$('#calendarModal #modalFooter').html(exportCalConfidential+exportCalPrivate+exportCalPublic);
$('#calendarModal #modalFooter').html(exportCalConfidential+exportCalPrivate+exportCalPublic);
}
},
editable: true,
events: "{{web_agenda_ajax_url}}&a=get_events",
eventDrop: function(event, delta, revert_func) {
var allDay = 0;
if (event.allDay == true) {
allDay = 1;
}
$.ajax({
url: '{{ web_agenda_ajax_url }}',
data: {
a: 'move_event',
id: event.id,
all_day: allDay,
minute_delta: delta.asMinutes()
}
});
},
eventResize: function(event, delta, revert_func) {
$.ajax({
url: '{{ web_agenda_ajax_url }}',
data: {
a: 'resize_event',
id: event.id,
minute_delta: delta.asMinutes()
}
});
},
axisFormat: 'H(:mm)', // pm-am format -> h(:mm)a
timeFormat: 'H:mm', // pm-am format -> h:mm
loading: function(bool) {
if (bool) $('#loading').show();
else $('#loading').hide();
}
},
editable: true,
events: "{{web_agenda_ajax_url}}&a=get_events",
eventDrop: function(event, delta, revert_func) {
var allDay = 0;
if (event.allDay == true) {
allDay = 1;
}
$.ajax({
url: '{{ web_agenda_ajax_url }}',
data: {
a: 'move_event',
id: event.id,
all_day: allDay,
minute_delta: delta.asMinutes()
}
});
},
eventResize: function(event, delta, revert_func) {
$.ajax({
url: '{{ web_agenda_ajax_url }}',
data: {
a: 'resize_event',
id: event.id,
minute_delta: delta.asMinutes()
}
});
},
axisFormat: 'H(:mm)', // pm-am format -> h(:mm)a
timeFormat: 'H:mm', // pm-am format -> h:mm
loading: function(bool) {
if (bool) $('#loading').show();
else $('#loading').hide();
}
});
});
});
});
</script>
{{ actions_div }}
@ -473,7 +478,7 @@ $(function() {
<div id="loading" style="margin-left:150px;position:absolute;display:none">
{{ "Loading" | get_lang }}...
{{ "Loading" | trans }}...
</div>
<div id="calendar"></div>
@ -482,7 +487,7 @@ $(function() {
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ "Add event" | get_lang }}</h5>
<h5 class="modal-title">{{ "Add event" | trans }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
@ -516,7 +521,7 @@ $(function() {
</dd>
<!--- user sender -->
<dt class="user-sender col-sm-2" style="display: none;">
{{ "To" |get_lang }}
{{ "To" |trans }}
</dt>
<dd class="user-sender col-sm-10" style="display: none">
<span id="visible_to_read_only_users"></span>
@ -524,39 +529,43 @@ $(function() {
<!--- type agenda -->
<dt class="col-sm-2">
{{ "Agenda" |get_lang }}
{{ "Agenda" |trans }}
</dt>
<dd class="col-sm-10">
<div id="color_calendar"></div>
</dd>
<dt class="col-sm-2">{{ "Title" |get_lang }}</dt>
<dt class="col-sm-2">{{ "Title" |trans }}</dt>
<dd class="col-sm-10">
<div id="simple_title"></div>
</dd>
<dt class="col-sm-2">{{ "Date" |get_lang }}</dt>
<dt class="col-sm-2">{{ "Date" |trans }}</dt>
<dd class="col-sm-10">
<span id="simple_start_date"></span>
<span id="simple_end_date"></span>
</dd>
<dt class="col-sm-2">{{ "Description" |get_lang }}</dt>
<dt class="col-sm-2">{{ "Description" |trans }}</dt>
<dd class="col-sm-10">
<div id="simple_content"></div>
</dd>
<dt class="col-sm-2">{{ "Comment" |get_lang }}</dt>
<dt class="col-sm-2">{{ "Comment" |trans }}</dt>
<dd class="col-sm-10">
<div id="simple_comment"></div>
</dd>
<dt class="col-sm-2">{{ "Attachment" |trans }}</dt>
<dd class="col-sm-10">
<div id="simple_attachment"></div>
</dd>
</dl>
</div>
<div id="modalFooter" class="modal-footer">
</div>
</div>
</div>
</div>
{% endautoescape %}

@ -15,6 +15,7 @@ use Chamilo\CourseBundle\Repository\CAnnouncementAttachmentRepository;
use Chamilo\CourseBundle\Repository\CAnnouncementRepository;
use Chamilo\CourseBundle\Repository\CAttendanceRepository;
use Chamilo\CourseBundle\Repository\CCalendarEventRepository;
use Chamilo\CourseBundle\Repository\CCalendarEventAttachmentRepository;
use Chamilo\CourseBundle\Repository\CDocumentRepository;
use Chamilo\CourseBundle\Repository\CExerciseCategoryRepository;
use Chamilo\CourseBundle\Repository\CForumAttachmentRepository;
@ -348,6 +349,14 @@ class Container
return self::$container->get('Chamilo\CourseBundle\Repository\CCalendarEventRepository');
}
/**
* @return CCalendarEventAttachmentRepository
*/
public static function getCalendarEventAttachmentRepository()
{
return self::$container->get('Chamilo\CourseBundle\Repository\CCalendarEventAttachmentRepository');
}
/**
* @return CDocumentRepository
*/

@ -7,6 +7,7 @@ namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
use Chamilo\CoreBundle\Entity\Room;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
@ -117,6 +118,13 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
*/
protected $room;
/**
* @var ArrayCollection|CCalendarEventAttachment[]
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CCalendarEventAttachment", mappedBy="event", cascade={"persist", "remove"}, orphanRemoval=true)
*/
protected $attachments;
public function __construct()
{
}
@ -422,6 +430,33 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface
return $this;
}
/**
* @return CCalendarEventAttachment[]|ArrayCollection
*/
public function getAttachments()
{
return $this->attachments;
}
/**
* @param CCalendarEventAttachment[]|ArrayCollection $attachments
*
* @return CCalendarEvent
*/
public function setAttachments($attachments)
{
$this->attachments = $attachments;
return $this;
}
public function addAttachment(CCalendarEventAttachment $attachment)
{
$this->attachments->add($attachment);
return $this;
}
/**
* Resource identifier.
*/

@ -4,6 +4,9 @@
namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
use Chamilo\CoreBundle\Entity\Room;
use Doctrine\ORM\Mapping as ORM;
/**
@ -17,7 +20,7 @@ use Doctrine\ORM\Mapping as ORM;
* )
* @ORM\Entity
*/
class CCalendarEventAttachment
class CCalendarEventAttachment extends AbstractResource implements ResourceInterface
{
/**
* @var int
@ -64,18 +67,19 @@ class CCalendarEventAttachment
protected $size;
/**
* @var int
* @var string
*
* @ORM\Column(name="agenda_id", type="integer", nullable=false)
* @ORM\Column(name="filename", type="string", length=255, nullable=false)
*/
protected $agendaId;
protected $filename;
/**
* @var string
* @var CCalendarEvent
*
* @ORM\Column(name="filename", type="string", length=255, nullable=false)
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CCalendarEvent", cascade={"persist"}, inversedBy="attachments")
* @ORM\JoinColumn(name="agenda_id", referencedColumnName="iid", onDelete="CASCADE")
*/
protected $filename;
protected $event;
/**
* Set path.
@ -149,30 +153,6 @@ class CCalendarEventAttachment
return $this->size;
}
/**
* Set agendaId.
*
* @param int $agendaId
*
* @return CCalendarEventAttachment
*/
public function setAgendaId($agendaId)
{
$this->agendaId = $agendaId;
return $this;
}
/**
* Get agendaId.
*
* @return int
*/
public function getAgendaId()
{
return $this->agendaId;
}
/**
* Set filename.
*
@ -244,4 +224,50 @@ class CCalendarEventAttachment
{
return $this->cId;
}
/**
* @return int
*/
public function getIid()
{
return $this->iid;
}
/**
* @return CCalendarEvent
*/
public function getEvent(): CCalendarEvent
{
return $this->event;
}
/**
* @param CCalendarEvent $event
*
* @return CCalendarEventAttachment
*/
public function setEvent(CCalendarEvent $event): self
{
$this->event = $event;
return $this;
}
public function __toString(): string
{
return $this->getFilename();
}
/**
* Resource identifier.
*/
public function getResourceIdentifier(): int
{
return $this->getIid();
}
public function getResourceName(): string
{
return $this->getFilename();
}
}

@ -0,0 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CourseBundle\Repository;
use Chamilo\CoreBundle\Repository\ResourceRepository;
final class CCalendarEventAttachmentRepository extends ResourceRepository
{
}

@ -79,6 +79,10 @@ services:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CCalendarEvent'
Chamilo\CourseBundle\Repository\CCalendarEventAttachmentRepository:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CCalendarEventAttachment'
Chamilo\CourseBundle\Repository\CChatConversationRepository:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CChatConversation'

Loading…
Cancel
Save