index.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Julio Montoya <gugli100@gmail.com> BeezNest 2011
  5. *
  6. * @package chamilo.timeline
  7. */
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. $htmlHeadXtra[] = api_get_jqgrid_js();
  10. //$htmlHeadXtra[] = api_get_js('timeline/timeline-min.js');
  11. //$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/timeline/timeline.css');
  12. // setting breadcrumbs
  13. //$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('Administration'));
  14. //$interbreadcrumb[]=array('url' => 'career_dashboard.php','name' => get_lang('Careers and promotions'));
  15. $action = isset($_GET['action']) ? $_GET['action'] : null;
  16. $check = Security::check_token('request');
  17. $token = Security::get_token();
  18. $actions = '';
  19. $message = '';
  20. switch ($action) {
  21. case 'add':
  22. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Timeline')];
  23. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add')];
  24. break;
  25. case 'edit':
  26. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Timeline')];
  27. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
  28. break;
  29. case 'add_item':
  30. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Timeline')];
  31. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Item')];
  32. break;
  33. default:
  34. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Timeline')];
  35. }
  36. //jqgrid will use this URL to do the selects
  37. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_timelines';
  38. //The order is important you need to check the the $column variable in the model.ajax.php file
  39. $columns = [get_lang('Name'), get_lang('Detail')];
  40. //Column config
  41. $column_model = [
  42. ['name' => 'name', 'index' => 'name', 'width' => '120', 'align' => 'left'],
  43. ['name' => 'actions', 'index' => 'actions', 'width' => '100', 'align' => 'left', 'sortable' => 'false'],
  44. ];
  45. //Autowidth
  46. $extra_params['autowidth'] = 'true';
  47. //height auto
  48. $extra_params['height'] = 'auto';
  49. //With this function we can add actions to the jgrid (edit, delete, etc)
  50. $htmlHeadXtra[] = '
  51. <script>
  52. $(function() {
  53. // grid definition see the $timeline->display() function
  54. '.Display::grid_js('timelines', $url, $columns, $column_model, $extra_params, [], null, true).'
  55. });
  56. </script>';
  57. $toolbarAction = '';
  58. $timeline = new Timeline();
  59. // Action handling: Add
  60. switch ($action) {
  61. case 'add':
  62. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  63. api_not_allowed();
  64. }
  65. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  66. $form = $timeline->return_form($url, 'add');
  67. // The validation or display
  68. if ($form->validate()) {
  69. if ($check) {
  70. $values = $form->exportValues();
  71. $res = $timeline->save($values);
  72. if ($res) {
  73. $message = Display::return_message(get_lang('Item added'), 'success');
  74. }
  75. }
  76. $content = $timeline->listing();
  77. } else {
  78. $actions .= '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  79. $form->addElement('hidden', 'sec_token');
  80. $form->setConstants(['sec_token' => $token]);
  81. $content = $form->return_form();
  82. }
  83. break;
  84. case 'edit':
  85. // Action handling: Editing
  86. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  87. $form = $timeline->return_form($url, 'edit');
  88. // The validation or display
  89. if ($form->validate()) {
  90. if ($check) {
  91. $values = $form->exportValues();
  92. //$timeline->update_all_promotion_status_by_career_id($values['id'],$values['status']);
  93. $res = $timeline->update($values);
  94. $message = Display::return_message(sprintf(get_lang('Item updated'), $values['name']), 'confirmation');
  95. }
  96. $timeline->display();
  97. } else {
  98. $actions = '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  99. $form->addElement('hidden', 'sec_token');
  100. $form->setConstants(['sec_token' => $token]);
  101. $content = $form->return_form();
  102. }
  103. break;
  104. case 'add_item':
  105. // Action handling: Editing
  106. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&parent_id='.intval($_GET['parent_id']);
  107. $form = $timeline->return_item_form($url, 'edit');
  108. // The validation or display
  109. if ($form->validate()) {
  110. if ($check) {
  111. $values = $form->exportValues();
  112. $values['type'] = '';
  113. //$timeline->update_all_promotion_status_by_career_id($values['id'],$values['status']);
  114. $res = $timeline->save_item($values);
  115. $message = Display::return_message(sprintf(get_lang('Item updated'), $values['name']), 'confirmation');
  116. }
  117. $timeline->display();
  118. } else {
  119. $actions = '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  120. $form->addElement('hidden', 'sec_token');
  121. $form->setConstants(['sec_token' => $token]);
  122. $content = $form->return_form();
  123. }
  124. break;
  125. case 'delete':
  126. // Action handling: delete
  127. if ($check) {
  128. $res = $timeline->delete($_GET['id']);
  129. if ($res) {
  130. $message = Display::return_message(get_lang('Item deleted'), 'success');
  131. }
  132. }
  133. $content = $timeline->listing();
  134. break;
  135. default:
  136. $content = $timeline->listing();
  137. break;
  138. }
  139. $tpl = new Template();
  140. $tpl->assign('actions', $actions);
  141. $tpl->assign('message', $message);
  142. $tpl->assign('content', $content);
  143. $tpl->display_one_col_template();