123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Definition of new system event types.
- *
- * @deprecated to be removed in 2.x
- *
- * @package chamilo.admin.events
- */
- $cidReset = true;
- require_once __DIR__.'/../inc/global.inc.php';
- $this_section = SECTION_PLATFORM_ADMIN;
- api_protect_admin_script();
- if (api_get_setting('activate_email_template') != 'true') {
- api_not_allowed();
- }
- $action = isset($_POST['action']) ? $_POST['action'] : null;
- $eventName = isset($_POST['eventList']) ? $_POST['eventList'] : null;
- $eventUsers = isset($_POST['eventUsers']) ? $_POST['eventUsers'] : null;
- $eventMessage = isset($_POST['eventMessage']) ? $_POST['eventMessage'] : null;
- $eventSubject = isset($_POST['eventSubject']) ? $_POST['eventSubject'] : null;
- $eventMessageLanguage = isset($_POST['languages']) ? $_POST['languages'] : null;
- $activated = isset($_POST['activated']) ? $_POST['activated'] : 0;
- $event_name = isset($_REQUEST['event_type_name']) ? addslashes($_REQUEST['event_type_name']) : 0;
- if ($action == 'modEventType') {
- if ($eventUsers) {
- $users = explode(';', $eventUsers);
- } else {
- $users = [];
- }
- if (!empty($event_name)) {
- $eventName = $event_name;
- }
- Event::save_event_type_message(
- $eventName,
- $users,
- $eventMessage,
- $eventSubject,
- $eventMessageLanguage,
- $activated
- );
- header('location: event_controller.php');
- exit;
- }
- $ets = Event::get_all_event_types();
- $languages = api_get_languages();
- $ajaxPath = api_get_path(WEB_CODE_PATH).'inc/ajax/events.ajax.php';
- $action_array = [
- [
- 'url' => 'event_controller.php?action=listing',
- 'content' => Display::return_icon(
- 'view_text.png',
- get_lang('ListView'),
- [],
- ICON_SIZE_MEDIUM
- ),
- ],
- ];
- $key_lang = get_lang('YouHaveSomeUnsavedChanges');
- $users = UserManager::get_user_list([], ['firstname']);
- $new_user_list = [];
- foreach ($users as $user) {
- if ($user['status'] == ANONYMOUS) {
- continue;
- }
- $new_user_list[] = $user;
- }
- /**
- * Header definition.
- */
- $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
- $interbreadcrumb[] = ['url' => 'event_controller.php', 'name' => get_lang('Events')];
- $tool_name = get_lang('EventMessageManagement');
- Display::display_header($tool_name);
- echo Display::actions($action_array);
- /**
- * JavaScript code.
- *
- * @todo move into HTML header
- */
- ?>
- <script>
- var usersList = <?php echo json_encode($new_user_list); ?>;
- var eventTypes = <?php echo json_encode($ets); ?>;
- var eventsConfig = <?php echo json_encode($event_config); ?>;
- var currentLanguage = <?php echo json_encode(api_get_interface_language()); ?>;
- var flagContentHasChanged = false;
- var key_lang = "<?php echo $key_lang; ?>";
- var event_type_name = "<?php echo $event_name; ?>";
- $(document).ready(function() {
- confirmMessage("eventList");
- if (event_type_name != 0) {
- $("#event_list_group").hide();
- }
- });
- function ajax(params,func) {
- $.ajax({
- url: "<?php echo $ajaxPath; ?>",
- type: "POST",
- data: params,
- success: func
- });
- }
- function refreshUsersList() {
- removeAllOption($('#usersList'));
- $.each(usersList, function(ind,item) {
- addOption($('#usersList'), item.user_id, item.firstname + ' '+item.lastname);
- });
- }
- function getCurrentEventTypeName() {
- var name = false;
- if (event_type_name != 0) {
- return event_type_name;
- } else {
- return $('#eventList option:selected').first().attr('value');
- }
- }
- function self_sent_lock(self_sent) {
- if (self_sent == true) {
- $(".registration_case").show();
- $("#usersList").attr('disabled', 'true');
- $("#usersSubList").attr('disabled', 'true');
- removeAllOption($('#usersSubList'));
- } else {
- $(".registration_case").show();
- $("#usersList").removeAttr('disabled');
- $("#usersSubList").removeAttr('disabled');
- }
- }
- function showEventType() {
- cleanInput();
- currentEventName = getCurrentEventTypeName();
- $("span#activated_checkbox").css("display", "inline"); // make checkbox visible
- $('input[name=activated]').attr('checked', false);
- var self_sent = false;
- if (typeof(eventsConfig[currentEventName])!='undefined') {
- // if registration, only sent to self_user
- if (eventsConfig[currentEventName].self_sent == true) {
- self_sent = true;
- }
- }
- self_sent_lock(self_sent);
- // List of events configuration
- $('#eventName').attr('value', currentEventName);
- $('#eventNameTitle').text('');
- //$('#descLangVar').text(eventsConfig[currentEventName].desc_lang_var);
- // Set message and subject accoding to the current interface language
- $.each(eventTypes,function(key,value) {
- if (eventTypes[key]["event_type_name"] == currentEventName) {
- $('#eventNameTitle').text(eventTypes[key]["nameLangVar"]);
- }
- if (eventTypes[key]["event_type_name"] == currentEventName && eventTypes[key]["activated"] == 1) {
- $('input[name=activated]').attr('checked', true);
- }
- if (eventTypes[key]["event_type_name"] == currentEventName && eventTypes[key]["dokeos_folder"] == currentLanguage) {
- $('#eventMessage').val(eventTypes[key]["message"]);
- $('#eventSubject').val(eventTypes[key]["subject"]);
- }
- });
- // Displays the available keys for the mail template (related to an event name)
- $('#keys').find('li').remove();
- if(typeof(eventsConfig[currentEventName]["available_keyvars"])!='undefined') {
- $.each(eventsConfig[currentEventName]["available_keyvars"],function(key,value) {
- $('#keys').append('<li>'+key+'</li>');
- });
- }
- if (self_sent == false ) {
- $.ajax({
- url: '<?php echo $ajaxPath; ?>?action=get_event_users&eventName=' +currentEventName,
- dataType: 'json',
- success: function(data) {
- removeAllOption($('#usersSubList'));
- refreshUsersList();
- usersIds = new Array();
- var json = jQuery.parseJSON(data);
- $.each(json, function(ind,item) {
- addOption($('#usersSubList'),item.user_id, item.firstname + ' '+item.lastname);
- usersIds[ind] = item.value;
- removeOption($('#usersList'),item.user_id);
- });
- $('#eventUsers').attr('value',usersIds.join(';'));
- }
- });
- }
- }
- function submitForm() {
- if ($('#eventId')) {
- usersIds = new Array();
- $('#usersSubList option').each(function(ind,item) {
- usersIds[ind] = item.value;
- });
- $('#eventUsers').attr('value',usersIds.join(';'));
- return true;
- }
- return false;
- }
- function addOption(select,value,text) {
- select.append('<option value="'+value+'">'+text+'</option>');
- }
- function removeOption(select,value) {
- select.find('option[value='+value+']').remove();
- }
- function removeAllOption(select) {
- select.find('option').remove();
- }
- function moveUsers(src,dest) {
- src.find('option:selected').each(function(index,opt) {
- text = opt.text;
- val = opt.value;
- addOption(dest,val,text);
- removeOption(src,val);
- });
- }
- /**
- * Change the message of the mail according to the selected language
- */
- function changeLanguage()
- {
- cleanInput();
- currentEventName = getCurrentEventTypeName();
- $.each(eventTypes,function(key,value)
- {
- if(eventTypes[key]["event_type_name"] == currentEventName && eventTypes[key]["dokeos_folder"] == $('#languages option:selected').first().attr('value'))
- {
- $('#eventSubject').val(eventTypes[key]["subject"]);
- $('#eventMessage').val(eventTypes[key]["message"]);
- }
- });
- }
- /**
- * Set flag at true if message and/or content was changed
- */
- function contentChanged()
- {
- flagContentHasChanged = true;
- }
- /**
- * Asks if user want to abandon the changes he's done
- */
- function confirmMessage(sender) {
- if (flagContentHasChanged == true) {
- if (confirm(key_lang)) {
- flagContentHasChanged = false;
- if (sender == "eventList") {
- cleanInput();
- showEventType();
- } else if(sender == "languages") {
- cleanInput();
- changeLanguage();
- }
- }
- } else {
- if(sender == "eventList")
- showEventType();
- else if(sender == "languages")
- changeLanguage();
- }
- }
- /**
- * Empty the input and the textarea
- */
- function cleanInput() {
- $('#eventMessage').val("");
- $('#eventSubject').val("");
- }
- </script>
- <?php
- /**
- * HTML body.
- *
- * @todo move as template layout
- */
- ?>
- <div class="page-header">
- <h2><?php echo get_lang('EventMessageManagement'); ?></h2>
- </div>
- <form method="POST" onSubmit="return submitForm(); ">
- <div class="row">
- <div class="col-md-12" id="event_list_group">
- <h4><?php echo get_lang('Events'); ?></h4>
- <select class="col-md-6" multiple="1" id="eventList" onchange="confirmMessage(this.name); return false;" name="eventList">
- <?php
- foreach ($event_config as $key => $config) {
- echo '<option value="'.$key.'">'.$config['name_lang_var'].'</option>';
- }
- ?>
- </select>
- </div>
- <div class="col-md-4">
- <h4><?php echo get_lang('Users'); ?></h4>
- <select multiple="1" id="usersList" class="registration_case"></select>
- </div>
- <div class="col-md-4">
- <div class="registration_case">
- <button class="btn btn-default" onclick='moveUsers($("#usersList"),$("#usersSubList")); return false;'><em class="fa fa-arrow-left"></em></button>
- <br />
- <br />
- <button class="btn btn-default" onclick='moveUsers($("#usersSubList"),$("#usersList")); return false;'><em class="fa fa-arrow-right"></em></button>
- </div>
- </div>
- <div class="col-md-4">
- <h4><?php echo get_lang('ToBeWarnedUserList'); ?></h4>
- <select class="col-md-3" multiple="1" id="usersSubList" class="registration_case"></select>
- </div>
- </div>
- <br />
- <h2 id="eventNameTitle"></h2>
- <span id="activated_checkbox">
- <input type="checkbox" name="activated" value="1" />
- <label for="activated" style="display:inline;"><?php echo get_lang('ActivateEvent'); ?></label>
- </span>
- <br />
- <select id="languages" name="languages" style="margin-top:20px;" onclick='confirmMessage(this.name); return false;'>
- <?php foreach ($languages["name"] as $key => $value) {
- $english_name = $languages['folder'][$key]; ?>
- <option value="<?php echo $english_name; ?>" <?php echo ($english_name == api_get_interface_language()) ? "selected=selected" : ""; ?>>
- <?php echo $value; ?>
- </option>
- <?php
- } ?>
- </select>
- <input type="hidden" name="action" value="modEventType" />
- <input type="hidden" name="eventId" id="eventId" />
- <input type="hidden" name="eventUsers" id="eventUsers" />
- <input type="hidden" id="eventName" value="<?php echo $event_name; ?>"/>
- <br />
- <br />
- <label for="eventSubject">
- <h4><?php echo get_lang('Subject'); ?></h4>
- </label>
- <input class="col-md-6" type="text" id="eventSubject" name="eventSubject" onchange="contentChanged(); return false;" />
- <br /><br />
- <table>
- <tr>
- <td>
- <label for="eventMessage"><h4><?php echo get_lang('Message'); ?></h4></label>
- </td>
- <td class="available_keys" style="padding-left: 30px;">
- <h4><?php echo get_lang('AvailableEventKeys'); ?></h4>
- </td>
- </tr>
- <tr>
- <td>
- <textarea class="col-md-6" rows="10" name="eventMessage" id="eventMessage" onchange="contentChanged(); return false;">
- </textarea>
- </td>
- <td class="available_keys">
- <div id="keys" style="padding-left: 50px;"><ul></ul></div>
- </td>
- </tr>
- </table>
- <br /><br />
- <input class="btn btn-primary" type="submit" value="<?php echo get_lang('Save'); ?>" />
- </form>
- <?php
- Display :: display_footer();
|