index.php 6.5 KB

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