event_type.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Definition of new system event types.
  5. *
  6. * @deprecated to be removed in 2.x
  7. *
  8. * @package chamilo.admin.events
  9. */
  10. $cidReset = true;
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script();
  14. if (api_get_setting('activate_email_template') != 'true') {
  15. api_not_allowed();
  16. }
  17. $action = isset($_POST['action']) ? $_POST['action'] : null;
  18. $eventName = isset($_POST['eventList']) ? $_POST['eventList'] : null;
  19. $eventUsers = isset($_POST['eventUsers']) ? $_POST['eventUsers'] : null;
  20. $eventMessage = isset($_POST['eventMessage']) ? $_POST['eventMessage'] : null;
  21. $eventSubject = isset($_POST['eventSubject']) ? $_POST['eventSubject'] : null;
  22. $eventMessageLanguage = isset($_POST['languages']) ? $_POST['languages'] : null;
  23. $activated = isset($_POST['activated']) ? $_POST['activated'] : 0;
  24. $event_name = isset($_REQUEST['event_type_name']) ? addslashes($_REQUEST['event_type_name']) : 0;
  25. if ($action == 'modEventType') {
  26. if ($eventUsers) {
  27. $users = explode(';', $eventUsers);
  28. } else {
  29. $users = [];
  30. }
  31. if (!empty($event_name)) {
  32. $eventName = $event_name;
  33. }
  34. Event::save_event_type_message(
  35. $eventName,
  36. $users,
  37. $eventMessage,
  38. $eventSubject,
  39. $eventMessageLanguage,
  40. $activated
  41. );
  42. header('location: event_controller.php');
  43. exit;
  44. }
  45. $ets = Event::get_all_event_types();
  46. $languages = api_get_languages();
  47. $ajaxPath = api_get_path(WEB_CODE_PATH).'inc/ajax/events.ajax.php';
  48. $action_array = [
  49. [
  50. 'url' => 'event_controller.php?action=listing',
  51. 'content' => Display::return_icon(
  52. 'view_text.png',
  53. get_lang('ListView'),
  54. [],
  55. ICON_SIZE_MEDIUM
  56. ),
  57. ],
  58. ];
  59. $key_lang = get_lang('YouHaveSomeUnsavedChanges');
  60. $users = UserManager::get_user_list([], ['firstname']);
  61. $new_user_list = [];
  62. foreach ($users as $user) {
  63. if ($user['status'] == ANONYMOUS) {
  64. continue;
  65. }
  66. $new_user_list[] = $user;
  67. }
  68. /**
  69. * Header definition.
  70. */
  71. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  72. $interbreadcrumb[] = ['url' => 'event_controller.php', 'name' => get_lang('Events')];
  73. $tool_name = get_lang('EventMessageManagement');
  74. Display::display_header($tool_name);
  75. echo Display::actions($action_array);
  76. /**
  77. * JavaScript code.
  78. *
  79. * @todo move into HTML header
  80. */
  81. ?>
  82. <script>
  83. var usersList = <?php echo json_encode($new_user_list); ?>;
  84. var eventTypes = <?php echo json_encode($ets); ?>;
  85. var eventsConfig = <?php echo json_encode($event_config); ?>;
  86. var currentLanguage = <?php echo json_encode(api_get_interface_language()); ?>;
  87. var flagContentHasChanged = false;
  88. var key_lang = "<?php echo $key_lang; ?>";
  89. var event_type_name = "<?php echo $event_name; ?>";
  90. $(document).ready(function() {
  91. confirmMessage("eventList");
  92. if (event_type_name != 0) {
  93. $("#event_list_group").hide();
  94. }
  95. });
  96. function ajax(params,func) {
  97. $.ajax({
  98. url: "<?php echo $ajaxPath; ?>",
  99. type: "POST",
  100. data: params,
  101. success: func
  102. });
  103. }
  104. function refreshUsersList() {
  105. removeAllOption($('#usersList'));
  106. $.each(usersList, function(ind,item) {
  107. addOption($('#usersList'), item.user_id, item.firstname + ' '+item.lastname);
  108. });
  109. }
  110. function getCurrentEventTypeName() {
  111. var name = false;
  112. if (event_type_name != 0) {
  113. return event_type_name;
  114. } else {
  115. return $('#eventList option:selected').first().attr('value');
  116. }
  117. }
  118. function self_sent_lock(self_sent) {
  119. if (self_sent == true) {
  120. $(".registration_case").show();
  121. $("#usersList").attr('disabled', 'true');
  122. $("#usersSubList").attr('disabled', 'true');
  123. removeAllOption($('#usersSubList'));
  124. } else {
  125. $(".registration_case").show();
  126. $("#usersList").removeAttr('disabled');
  127. $("#usersSubList").removeAttr('disabled');
  128. }
  129. }
  130. function showEventType() {
  131. cleanInput();
  132. currentEventName = getCurrentEventTypeName();
  133. $("span#activated_checkbox").css("display", "inline"); // make checkbox visible
  134. $('input[name=activated]').attr('checked', false);
  135. var self_sent = false;
  136. if (typeof(eventsConfig[currentEventName])!='undefined') {
  137. // if registration, only sent to self_user
  138. if (eventsConfig[currentEventName].self_sent == true) {
  139. self_sent = true;
  140. }
  141. }
  142. self_sent_lock(self_sent);
  143. // List of events configuration
  144. $('#eventName').attr('value', currentEventName);
  145. $('#eventNameTitle').text('');
  146. //$('#descLangVar').text(eventsConfig[currentEventName].desc_lang_var);
  147. // Set message and subject accoding to the current interface language
  148. $.each(eventTypes,function(key,value) {
  149. if (eventTypes[key]["event_type_name"] == currentEventName) {
  150. $('#eventNameTitle').text(eventTypes[key]["nameLangVar"]);
  151. }
  152. if (eventTypes[key]["event_type_name"] == currentEventName && eventTypes[key]["activated"] == 1) {
  153. $('input[name=activated]').attr('checked', true);
  154. }
  155. if (eventTypes[key]["event_type_name"] == currentEventName && eventTypes[key]["dokeos_folder"] == currentLanguage) {
  156. $('#eventMessage').val(eventTypes[key]["message"]);
  157. $('#eventSubject').val(eventTypes[key]["subject"]);
  158. }
  159. });
  160. // Displays the available keys for the mail template (related to an event name)
  161. $('#keys').find('li').remove();
  162. if(typeof(eventsConfig[currentEventName]["available_keyvars"])!='undefined') {
  163. $.each(eventsConfig[currentEventName]["available_keyvars"],function(key,value) {
  164. $('#keys').append('<li>'+key+'</li>');
  165. });
  166. }
  167. if (self_sent == false ) {
  168. $.ajax({
  169. url: '<?php echo $ajaxPath; ?>?action=get_event_users&eventName=' +currentEventName,
  170. dataType: 'json',
  171. success: function(data) {
  172. removeAllOption($('#usersSubList'));
  173. refreshUsersList();
  174. usersIds = new Array();
  175. var json = jQuery.parseJSON(data);
  176. $.each(json, function(ind,item) {
  177. addOption($('#usersSubList'),item.user_id, item.firstname + ' '+item.lastname);
  178. usersIds[ind] = item.value;
  179. removeOption($('#usersList'),item.user_id);
  180. });
  181. $('#eventUsers').attr('value',usersIds.join(';'));
  182. }
  183. });
  184. }
  185. }
  186. function submitForm() {
  187. if ($('#eventId')) {
  188. usersIds = new Array();
  189. $('#usersSubList option').each(function(ind,item) {
  190. usersIds[ind] = item.value;
  191. });
  192. $('#eventUsers').attr('value',usersIds.join(';'));
  193. return true;
  194. }
  195. return false;
  196. }
  197. function addOption(select,value,text) {
  198. select.append('<option value="'+value+'">'+text+'</option>');
  199. }
  200. function removeOption(select,value) {
  201. select.find('option[value='+value+']').remove();
  202. }
  203. function removeAllOption(select) {
  204. select.find('option').remove();
  205. }
  206. function moveUsers(src,dest) {
  207. src.find('option:selected').each(function(index,opt) {
  208. text = opt.text;
  209. val = opt.value;
  210. addOption(dest,val,text);
  211. removeOption(src,val);
  212. });
  213. }
  214. /**
  215. * Change the message of the mail according to the selected language
  216. */
  217. function changeLanguage()
  218. {
  219. cleanInput();
  220. currentEventName = getCurrentEventTypeName();
  221. $.each(eventTypes,function(key,value)
  222. {
  223. if(eventTypes[key]["event_type_name"] == currentEventName && eventTypes[key]["dokeos_folder"] == $('#languages option:selected').first().attr('value'))
  224. {
  225. $('#eventSubject').val(eventTypes[key]["subject"]);
  226. $('#eventMessage').val(eventTypes[key]["message"]);
  227. }
  228. });
  229. }
  230. /**
  231. * Set flag at true if message and/or content was changed
  232. */
  233. function contentChanged()
  234. {
  235. flagContentHasChanged = true;
  236. }
  237. /**
  238. * Asks if user want to abandon the changes he's done
  239. */
  240. function confirmMessage(sender) {
  241. if (flagContentHasChanged == true) {
  242. if (confirm(key_lang)) {
  243. flagContentHasChanged = false;
  244. if (sender == "eventList") {
  245. cleanInput();
  246. showEventType();
  247. } else if(sender == "languages") {
  248. cleanInput();
  249. changeLanguage();
  250. }
  251. }
  252. } else {
  253. if(sender == "eventList")
  254. showEventType();
  255. else if(sender == "languages")
  256. changeLanguage();
  257. }
  258. }
  259. /**
  260. * Empty the input and the textarea
  261. */
  262. function cleanInput() {
  263. $('#eventMessage').val("");
  264. $('#eventSubject').val("");
  265. }
  266. </script>
  267. <?php
  268. /**
  269. * HTML body.
  270. *
  271. * @todo move as template layout
  272. */
  273. ?>
  274. <div class="page-header">
  275. <h2><?php echo get_lang('EventMessageManagement'); ?></h2>
  276. </div>
  277. <form method="POST" onSubmit="return submitForm(); ">
  278. <div class="row">
  279. <div class="col-md-12" id="event_list_group">
  280. <h4><?php echo get_lang('Events'); ?></h4>
  281. <select class="col-md-6" multiple="1" id="eventList" onchange="confirmMessage(this.name); return false;" name="eventList">
  282. <?php
  283. foreach ($event_config as $key => $config) {
  284. echo '<option value="'.$key.'">'.$config['name_lang_var'].'</option>';
  285. }
  286. ?>
  287. </select>
  288. </div>
  289. <div class="col-md-4">
  290. <h4><?php echo get_lang('Users'); ?></h4>
  291. <select multiple="1" id="usersList" class="registration_case"></select>
  292. </div>
  293. <div class="col-md-4">
  294. <div class="registration_case">
  295. <button class="btn btn-default" onclick='moveUsers($("#usersList"),$("#usersSubList")); return false;'><em class="fa fa-arrow-left"></em></button>
  296. <br />
  297. <br />
  298. <button class="btn btn-default" onclick='moveUsers($("#usersSubList"),$("#usersList")); return false;'><em class="fa fa-arrow-right"></em></button>
  299. </div>
  300. </div>
  301. <div class="col-md-4">
  302. <h4><?php echo get_lang('ToBeWarnedUserList'); ?></h4>
  303. <select class="col-md-3" multiple="1" id="usersSubList" class="registration_case"></select>
  304. </div>
  305. </div>
  306. <br />
  307. <h2 id="eventNameTitle"></h2>
  308. <span id="activated_checkbox">
  309. <input type="checkbox" name="activated" value="1" />
  310. <label for="activated" style="display:inline;"><?php echo get_lang('ActivateEvent'); ?></label>
  311. </span>
  312. <br />
  313. <select id="languages" name="languages" style="margin-top:20px;" onclick='confirmMessage(this.name); return false;'>
  314. <?php foreach ($languages["name"] as $key => $value) {
  315. $english_name = $languages['folder'][$key]; ?>
  316. <option value="<?php echo $english_name; ?>" <?php echo ($english_name == api_get_interface_language()) ? "selected=selected" : ""; ?>>
  317. <?php echo $value; ?>
  318. </option>
  319. <?php
  320. } ?>
  321. </select>
  322. <input type="hidden" name="action" value="modEventType" />
  323. <input type="hidden" name="eventId" id="eventId" />
  324. <input type="hidden" name="eventUsers" id="eventUsers" />
  325. <input type="hidden" id="eventName" value="<?php echo $event_name; ?>"/>
  326. <br />
  327. <br />
  328. <label for="eventSubject">
  329. <h4><?php echo get_lang('Subject'); ?></h4>
  330. </label>
  331. <input class="col-md-6" type="text" id="eventSubject" name="eventSubject" onchange="contentChanged(); return false;" />
  332. <br /><br />
  333. <table>
  334. <tr>
  335. <td>
  336. <label for="eventMessage"><h4><?php echo get_lang('Message'); ?></h4></label>
  337. </td>
  338. <td class="available_keys" style="padding-left: 30px;">
  339. <h4><?php echo get_lang('AvailableEventKeys'); ?></h4>
  340. </td>
  341. </tr>
  342. <tr>
  343. <td>
  344. <textarea class="col-md-6" rows="10" name="eventMessage" id="eventMessage" onchange="contentChanged(); return false;">
  345. </textarea>
  346. </td>
  347. <td class="available_keys">
  348. <div id="keys" style="padding-left: 50px;"><ul></ul></div>
  349. </td>
  350. </tr>
  351. </table>
  352. <br /><br />
  353. <input class="btn btn-primary" type="submit" value="<?php echo get_lang('Save'); ?>" />
  354. </form>
  355. <?php
  356. Display :: display_footer();