list.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. api_protect_admin_script();
  5. //Adds the JS needed to use the jqgrid
  6. $htmlHeadXtra[] = api_get_jqgrid_js();
  7. $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : 'list';
  8. $check = Security::check_token('request');
  9. $token = Security::get_token();
  10. $id = !empty($_REQUEST['id']) ? $_REQUEST['id'] : 0;
  11. $mailTemplate = new MailTemplateManager();
  12. $content = '';
  13. switch ($action) {
  14. case 'add':
  15. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  16. $form = $mailTemplate->returnForm($url, 'add');
  17. // The validation or display
  18. if ($form->validate()) {
  19. if ($check) {
  20. $values = $form->exportValues();
  21. $values['template'] = $values['email_template'];
  22. $values['author_id'] = api_get_user_id();
  23. $values['url_id'] = api_get_current_access_url_id();
  24. $res = $mailTemplate->save($values);
  25. if ($res) {
  26. Display::addFlash(Display::return_message(get_lang('ItemAdded'), 'confirm'));
  27. }
  28. }
  29. header('Location: '.api_get_self());
  30. exit;
  31. } else {
  32. $content .= '<div class="actions">';
  33. $content .= Display::url(
  34. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM),
  35. api_get_self()
  36. );
  37. $content .= '</div>';
  38. $form->addElement('hidden', 'sec_token');
  39. $form->setConstants(['sec_token' => $token]);
  40. $content .= $form->returnForm();
  41. }
  42. break;
  43. case 'edit':
  44. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.$id;
  45. $form = $mailTemplate->returnForm($url, 'edit');
  46. $content .= '<div class="actions">';
  47. $content .= Display::url(
  48. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM),
  49. api_get_self()
  50. );
  51. $content .= '</div>';
  52. $content .= $form->returnForm();
  53. // The validation or display
  54. if ($form->validate()) {
  55. //if ($check) {
  56. $values = $form->exportValues();
  57. $values['template'] = $values['email_template'];
  58. $res = $mailTemplate->update($values);
  59. if ($res) {
  60. Display::addFlash(
  61. Display::return_message(get_lang('ItemUpdated').': '.$values['name'], 'confirm')
  62. );
  63. }
  64. //}
  65. header('Location: '.api_get_self());
  66. exit;
  67. }
  68. break;
  69. case 'delete':
  70. $mailTemplate->delete($id);
  71. Display::addFlash(
  72. Display::return_message(get_lang('Deleted'), 'confirm')
  73. );
  74. header('Location: '.api_get_self());
  75. exit;
  76. break;
  77. case 'set_default':
  78. $mailTemplate->setDefault($id);
  79. Display::addFlash(
  80. Display::return_message(get_lang('Updated'), 'confirm')
  81. );
  82. header('Location: '.api_get_self());
  83. break;
  84. case 'list':
  85. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_mail_template';
  86. $columns = [
  87. get_lang('Name'),
  88. get_lang('Type'),
  89. get_lang('Default'),
  90. get_lang('Actions'),
  91. ];
  92. $column_model = [
  93. [
  94. 'name' => 'name',
  95. 'index' => 'name',
  96. 'width' => '180',
  97. 'align' => 'left',
  98. ],
  99. [
  100. 'name' => 'type',
  101. 'index' => 'type',
  102. 'width' => '100',
  103. 'align' => 'left',
  104. ],
  105. [
  106. 'name' => 'default_template',
  107. 'index' => 'default_template',
  108. 'width' => '100',
  109. 'align' => 'left',
  110. 'hidden' => 'true',
  111. ],
  112. [
  113. 'name' => 'actions',
  114. 'index' => 'actions',
  115. 'width' => '100',
  116. 'align' => 'left',
  117. 'formatter' => 'action_formatter',
  118. 'sortable' => 'false',
  119. ],
  120. ];
  121. $extra_params['autowidth'] = 'true'; //use the width of the parent
  122. //$extra_params['editurl'] = $url; //use the width of the parent
  123. $extra_params['height'] = 'auto'; //use the width of the parent
  124. //With this function we can add actions to the jgrid
  125. $action_links = 'function action_formatter (cellvalue, options, rowObject) {
  126. var defaultIcon = "<i class=\"fa fa-circle fa-2x\"></i>";
  127. if (rowObject[2] == 1) {
  128. defaultIcon = "<i class=\"fa fa-check-circle fa-2x\"></i>";
  129. }
  130. return \'&nbsp;<a href="?action=edit&id=\'+options.rowId+\'"><i class=\"fa fa-pencil fa-2x\"></i></a>'.
  131. '&nbsp;<a href="?action=set_default&id=\'+options.rowId+\'" title=\"'.get_lang('Default').'\">\'+ defaultIcon + \'</a>'.
  132. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'"><i class=\"fa fa-trash fa-2x\"></i></a> \';
  133. }';
  134. $content = $mailTemplate->display();
  135. $content .= '
  136. <script>
  137. $(function() {
  138. '.Display::grid_js('mail_template', $url, $columns, $column_model, $extra_params, [], $action_links, true).'
  139. });
  140. </script>';
  141. break;
  142. }
  143. $template = new Template();
  144. $template->assign('content', $content);
  145. $template->display_one_col_template();