event_type.php 13 KB

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