event_type.php 13 KB

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