index.php 6.1 KB

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