index.php 6.0 KB

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