diff --git a/main/calendar/agenda.lib.php b/main/calendar/agenda.lib.php index f2b2b4dc72..59579625e4 100755 --- a/main/calendar/agenda.lib.php +++ b/main/calendar/agenda.lib.php @@ -16,6 +16,7 @@ class Agenda public $senderId; /** @var array */ public $course; + public $comment; /** * Constructor @@ -114,6 +115,7 @@ class Agenda * @param int $parentEventId * @param array $attachmentArray $_FILES[''] * @param string $attachmentComment + * @param string $eventComment * * @return int */ @@ -127,7 +129,8 @@ class Agenda $addAsAnnouncement = false, $parentEventId = null, $attachmentArray = array(), - $attachmentComment = null + $attachmentComment = null, + $eventComment = null ) { $start = api_get_utc_datetime($start); $end = api_get_utc_datetime($end); @@ -160,6 +163,12 @@ class Agenda 'c_id' => $this->course['real_id'] ); + $allow = api_get_configuration_value('allow_agenda_event_comment'); + + if ($allow) { + $attributes['comment'] = $eventComment; + } + if (!empty($parentEventId)) { $attributes['parent_event_id'] = $parentEventId; } @@ -533,6 +542,7 @@ class Agenda * @param int $editRepeatType * @param array $attachmentArray * @param string $attachmentComment + * @param string $comment * * @return bool */ @@ -545,7 +555,8 @@ class Agenda $content, $usersToSend = array(), $attachmentArray = array(), - $attachmentComment = null + $attachmentComment = null, + $comment = null ) { $start = api_get_utc_datetime($start); $end = api_get_utc_datetime($end); @@ -594,6 +605,12 @@ class Agenda 'all_day' => $allDay ); + $allow = api_get_configuration_value('allow_agenda_event_comment'); + + if ($allow) { + $attributes['comment'] = $comment; + } + Database::update( $this->tbl_course_agenda, $attributes, @@ -1322,6 +1339,7 @@ class Agenda } $sql .= $dateCondition; + $allowComments = api_get_configuration_value('allow_agenda_event_comment'); $result = Database::query($sql); if (Database::num_rows($result)) { @@ -1428,9 +1446,16 @@ class Agenda $event['parent_event_id'] = $row['parent_event_id']; $event['has_children'] = $this->hasChildren($row['id'], $course_id) ? 1 : 0; + if ($allowComments) { + $event['comment'] = $row['comment']; + } else { + $event['comment'] = null; + } + $this->events[] = $event; } } + return $this->events; } @@ -1822,6 +1847,11 @@ class Agenda ); if ($this->type == 'course') { + $allow = api_get_configuration_value('allow_agenda_event_comment'); + + if ($allow) { + $form->addElement('textarea', 'comment', get_lang('Comment')); + } $form->addElement('file', 'user_upload', get_lang('AddAnAttachment')); if ($showAttachmentForm) { @@ -1839,7 +1869,7 @@ class Agenda } } - $form->addElement('textarea', 'file_comment', get_lang('Comment')); + $form->addElement('textarea', 'file_comment', get_lang('FileComment')); } if (empty($id)) { diff --git a/main/calendar/agenda.php b/main/calendar/agenda.php index d1b3095f03..3463da9364 100755 --- a/main/calendar/agenda.php +++ b/main/calendar/agenda.php @@ -114,6 +114,8 @@ if (api_is_allowed_to_edit(false, true) OR $attachment = $sendAttachment ? $_FILES['user_upload'] : null; $attachmentComment = isset($values['file_comment']) ? $values['file_comment'] : null; + $comment = isset($values['comment']) ? $values['comment'] : null; + $startDate = $values['date_range_start']; $endDate = $values['date_range_end']; @@ -127,7 +129,8 @@ if (api_is_allowed_to_edit(false, true) OR $sendEmail, null, $attachment, - $attachmentComment + $attachmentComment, + $comment ); if (!empty($values['repeat']) && !empty($eventId)) { @@ -174,6 +177,7 @@ if (api_is_allowed_to_edit(false, true) OR $sendAttachment = isset($_FILES['user_upload']) ? true : false; $attachment = $sendAttachment ? $_FILES['user_upload'] : null; $attachmentComment = isset($values['file_comment']) ? $values['file_comment'] : null; + $comment = isset($values['comment']) ? $values['comment'] : null; // This is a sub event. Delete the current and create another BT#7803 @@ -190,7 +194,8 @@ if (api_is_allowed_to_edit(false, true) OR false, null, $attachment, - $attachmentComment + $attachmentComment, + $comment ); $message = Display::return_message(get_lang('Updated'), 'confirmation'); @@ -209,7 +214,8 @@ if (api_is_allowed_to_edit(false, true) OR $values['content'], $values['users_to_send'], $attachment, - $attachmentComment + $attachmentComment, + $comment ); if (!empty($values['repeat']) && !empty($eventId)) { diff --git a/main/calendar/agenda_js.php b/main/calendar/agenda_js.php index f7be93357f..687ea2b22d 100755 --- a/main/calendar/agenda_js.php +++ b/main/calendar/agenda_js.php @@ -1,5 +1,6 @@ addElement('label', get_lang('Date'), 'addElement('text', 'title', get_lang('Title'), array('id' => 'title')); $form->addElement('textarea', 'content', get_lang('Description'), array('id' => 'content')); +$allowEventComment = api_get_configuration_value('allow_agenda_event_comment'); + if ($agenda->type == 'course') { $form->addElement('html', ' '); + if ($allowEventComment) { + $form->addElement('textarea', 'comment', get_lang('Comment'), array('id' => 'comment')); + } } $tpl->assign('form_add', $form->return_form()); @@ -234,6 +240,8 @@ $content = $tpl->fetch('default/agenda/month.tpl'); $message = Session::read('message'); $tpl->assign('message', $message); +$tpl->assign('allow_agenda_event_comment', $allowEventComment); + Session::erase('message'); $tpl->assign('content', $content); diff --git a/main/calendar/agenda_list.php b/main/calendar/agenda_list.php index 0b3344bd62..a59e543356 100755 --- a/main/calendar/agenda_list.php +++ b/main/calendar/agenda_list.php @@ -3,9 +3,7 @@ /** * @package chamilo.calendar */ -/** - * INIT SECTION - */ + // name of the language file that needs to be included $language_file = array('agenda', 'group', 'announcements'); diff --git a/main/cron/import_csv.php b/main/cron/import_csv.php index fecbbf4e04..ca5d065833 100755 --- a/main/cron/import_csv.php +++ b/main/cron/import_csv.php @@ -644,17 +644,47 @@ class ImportCsv { $data = Import::csv_to_array($file); + if ($this->getDumpValues()) { + // Remove all calendar items + $truncateTables = array( + Database::get_course_table(TABLE_AGENDA), + Database::get_course_table(TABLE_AGENDA_ATTACHMENT), + Database::get_course_table(TABLE_AGENDA_REPEAT), + Database::get_course_table(TABLE_AGENDA_REPEAT_NOT), + Database::get_main_table(TABLE_PERSONAL_AGENDA), + Database::get_main_table(TABLE_PERSONAL_AGENDA_REPEAT_NOT), + Database::get_main_table(TABLE_PERSONAL_AGENDA_REPEAT) + ); + + foreach ($truncateTables as $table) { + $sql = "TRUNCATE $table"; + Database::query($sql); + } + + $table = Database::get_course_table(TABLE_ITEM_PROPERTY); + $sql = "DELETE FROM $table WHERE tool = 'calendar_event'"; + Database::query($sql); + } + if (!empty($data)) { $this->logger->addInfo(count($data) . " records found."); $eventsToCreate = array(); $errorFound = false; foreach ($data as $row) { - $sessionId = SessionManager::get_session_id_from_original_id( - $row['external_sessionID'], - $this->extraFieldIdNameList['session'] - ); + $sessionId = null; + $externalSessionId = null; + if (isset($row['external_sessionID'])) { + $externalSessionId = $row['external_sessionID']; + $sessionId = SessionManager::get_session_id_from_original_id( + $externalSessionId, + $this->extraFieldIdNameList['session'] + ); + } - $courseCode = $row['coursecode']; + $courseCode = null; + if (isset($row['coursecode'])) { + $courseCode = $row['coursecode']; + } $courseInfo = api_get_course_info($courseCode); if (empty($courseInfo)) { @@ -662,7 +692,7 @@ class ImportCsv } if (empty($sessionId)) { - $this->logger->addInfo("external_sessionID: ".$row['external_sessionID']." does not exists."); + $this->logger->addInfo("external_sessionID: ".$externalSessionId." does not exists."); } $teacherId = null; @@ -793,6 +823,12 @@ class ImportCsv $agenda->setSessionId($event['session_id']); $agenda->setSenderId($event['sender_id']); + $eventComment = $event['comment']; + + // To use the event comment you need + // ALTER TABLE c_calendar_event ADD COLUMN comment TEXT; + // add in configuration.php allow_agenda_event_comment = true + if (empty($courseInfo)) { $this->logger->addInfo( "No course found for added: #".$event['course_id']." Skipping ..." @@ -814,7 +850,11 @@ class ImportCsv $event['title'], $content, array('everyone'), // send to - false //$addAsAnnouncement = false + false, //$addAsAnnouncement = false + null, // $parentEventId + array(), //$attachmentArray = array(), + null, //$attachmentComment = null, + $eventComment ); if (!empty($eventId)) { diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 8936040688..2bb8bcdd62 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -284,3 +284,5 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE; //); // Shows a warning message explaining that the site uses cookies //$_configuration['cookie_warning'] = false; +// Allows a comment field in the course calendar events. Requires DB change +//$_configuration['allow_agenda_event_comment'] = false; diff --git a/main/template/default/agenda/event_list.tpl b/main/template/default/agenda/event_list.tpl index db518c2e84..4af213398e 100755 --- a/main/template/default/agenda/event_list.tpl +++ b/main/template/default/agenda/event_list.tpl @@ -29,7 +29,15 @@
{{ event.description}}
+ + {% if event.description %} +{{ event.description}}
+ {% endif %} + + {% if event.comment %} +{{ event.comment}}
+ {% endif %} + {{ event.attachment }}