event_type.php 13 KB

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