event_type.php 13 KB

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