start.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /* For license terms, see /license.txt */
  3. require_once __DIR__.'/../../main/inc/global.inc.php';
  4. $allow = api_is_platform_admin() || api_is_teacher();
  5. if (!$allow) {
  6. api_not_allowed(true);
  7. }
  8. $plugin = LearningCalendarPlugin::create();
  9. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
  10. $calendarId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
  11. $formToString = '';
  12. switch ($action) {
  13. case 'add':
  14. $form = new FormValidator('calendar', 'post', api_get_self().'?action=add');
  15. $plugin->getForm($form);
  16. $form->addButtonSave(get_lang('Save'));
  17. $formToString = $form->returnForm();
  18. if ($form->validate()) {
  19. $values = $form->getSubmitValues();
  20. $params = [
  21. 'title' => $values['title'],
  22. 'total_hours' => $values['total_hours'],
  23. 'minutes_per_day' => $values['minutes_per_day'],
  24. 'description' => $values['description'],
  25. 'author_id' => api_get_user_id(),
  26. ];
  27. Database::insert('learning_calendar', $params);
  28. Display::addFlash(Display::return_message(get_lang('Saved')));
  29. header('Location: start.php');
  30. exit;
  31. }
  32. break;
  33. case 'edit':
  34. $form = new FormValidator('calendar', 'post', api_get_self().'?action=edit&id='.$calendarId);
  35. $plugin->getForm($form);
  36. $form->addButtonSave(get_lang('Update'));
  37. $item = $plugin->getCalendar($calendarId);
  38. $plugin->protectCalendar($item);
  39. if (empty($item)) {
  40. api_not_allowed(true);
  41. }
  42. $form->setDefaults($item);
  43. $formToString = $form->returnForm();
  44. if ($form->validate()) {
  45. $values = $form->getSubmitValues();
  46. $params = [
  47. 'title' => $values['title'],
  48. 'total_hours' => $values['total_hours'],
  49. 'minutes_per_day' => $values['minutes_per_day'],
  50. 'description' => $values['description'],
  51. ];
  52. Database::update('learning_calendar', $params, ['id = ?' => $calendarId]);
  53. Display::addFlash(Display::return_message(get_lang('Updated')));
  54. header('Location: start.php');
  55. exit;
  56. }
  57. break;
  58. case 'copy':
  59. $result = $plugin->copyCalendar($calendarId);
  60. if ($result) {
  61. Display::addFlash(Display::return_message(get_lang('Saved')));
  62. }
  63. header('Location: start.php');
  64. exit;
  65. break;
  66. case 'delete':
  67. $result = $plugin->deleteCalendar($calendarId);
  68. if ($result) {
  69. Display::addFlash(Display::return_message(get_lang('Deleted')));
  70. }
  71. header('Location: start.php');
  72. exit;
  73. break;
  74. case 'toggle_visibility':
  75. $itemId = isset($_REQUEST['lp_item_id']) ? $_REQUEST['lp_item_id'] : 0;
  76. $lpId = isset($_REQUEST['lp_id']) ? $_REQUEST['lp_id'] : 0;
  77. $plugin->toggleVisibility($itemId);
  78. Display::addFlash(Display::return_message(get_lang('Updated')));
  79. $url = api_get_path(WEB_CODE_PATH).
  80. 'lp/lp_controller.php?action=add_item&type=step&lp_id='.$lpId.'&'.api_get_cidreq();
  81. header("Location: $url");
  82. exit;
  83. break;
  84. }
  85. $htmlHeadXtra[] = api_get_jqgrid_js();
  86. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_learning_path_calendars';
  87. $columns = [
  88. get_lang('Title'),
  89. get_lang('TotalHours'),
  90. get_lang('MinutesPerDay'),
  91. get_lang('Actions'),
  92. ];
  93. $columnModel = [
  94. [
  95. 'name' => 'title',
  96. 'index' => 'title',
  97. 'width' => '300',
  98. 'align' => 'left',
  99. 'sortable' => 'false',
  100. ],
  101. [
  102. 'name' => 'total_hours',
  103. 'index' => 'total_hours',
  104. 'width' => '100',
  105. 'align' => 'left',
  106. 'sortable' => 'false',
  107. ],
  108. [
  109. 'name' => 'minutes_per_day',
  110. 'index' => 'minutes_per_day',
  111. 'width' => '100',
  112. 'align' => 'left',
  113. 'sortable' => 'false',
  114. ],
  115. [
  116. 'name' => 'actions',
  117. 'index' => 'actions',
  118. 'width' => '150',
  119. 'align' => 'left',
  120. //'formatter' => 'action_formatter',
  121. 'sortable' => 'false',
  122. ],
  123. ];
  124. $extraParams = [];
  125. $extraParams['autowidth'] = 'true';
  126. // height auto
  127. $extraParams['height'] = 'auto';
  128. $template = new Template();
  129. if (in_array($action, ['add', 'edit'])) {
  130. $actionLeft = Display::url(
  131. Display::return_icon(
  132. 'back.png',
  133. get_lang('Back'),
  134. null,
  135. ICON_SIZE_MEDIUM
  136. ),
  137. api_get_self().'?'.api_get_cidreq()
  138. );
  139. } else {
  140. $actionLeft = Display::url(
  141. Display::return_icon(
  142. 'add.png',
  143. get_lang('Add'),
  144. null,
  145. ICON_SIZE_MEDIUM
  146. ),
  147. api_get_self().'?'.api_get_cidreq().'&action=add'
  148. );
  149. $content = '<script>
  150. $(function() {'.
  151. Display::grid_js(
  152. 'calendars',
  153. $url,
  154. $columns,
  155. $columnModel,
  156. $extraParams,
  157. [],
  158. '',
  159. true
  160. ).'
  161. });
  162. </script>';
  163. $content .= Display::grid_html('calendars');
  164. $template->assign('grid', $content);
  165. }
  166. $template->assign('form', $formToString);
  167. $actions = Display::toolbarAction('toolbar-calendar', [$actionLeft]);
  168. $content = $template->fetch('learning_calendar/view/start.tpl');
  169. $template->assign('content', $content);
  170. $template->assign('actions', $actions);
  171. $template->display_one_col_template();