index.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. require_once '../inc/global.inc.php';
  11. require_once api_get_path(LIBRARY_PATH).'timeline.lib.php';
  12. $htmlHeadXtra[] = api_get_jqgrid_js();
  13. //$htmlHeadXtra[] = api_get_js('timeline/timeline-min.js');
  14. //$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/timeline/timeline.css');
  15. // setting breadcrumbs
  16. //$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  17. //$interbreadcrumb[]=array('url' => 'career_dashboard.php','name' => get_lang('CareersAndPromotions'));
  18. $action = isset($_GET['action']) ? $_GET['action'] : null;
  19. $check = Security::check_token('request');
  20. $token = Security::get_token();
  21. switch ($action) {
  22. case 'add':
  23. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('Timeline'));
  24. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Add'));
  25. break;
  26. case 'edit':
  27. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('Timeline'));
  28. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
  29. break;
  30. case 'add_item':
  31. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('Timeline'));
  32. $interbreadcrumb[]=array('url' => '#','name' => get_lang('TimelineItem'));
  33. break;
  34. default:
  35. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Timeline'));
  36. }
  37. //jqgrid will use this URL to do the selects
  38. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_timelines';
  39. //The order is important you need to check the the $column variable in the model.ajax.php file
  40. $columns = array(get_lang('Name'), get_lang('Actions'));
  41. //Column config
  42. $column_model = array(
  43. array('name'=>'name', 'index'=>'name', 'width'=>'120', 'align'=>'left'),
  44. array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left', 'sortable'=>'false')
  45. );
  46. //Autowidth
  47. $extra_params['autowidth'] = 'true';
  48. //height auto
  49. $extra_params['height'] = 'auto';
  50. //With this function we can add actions to the jgrid (edit, delete, etc)
  51. $htmlHeadXtra[] ='
  52. <script>
  53. $(function() {
  54. // grid definition see the $timeline->display() function
  55. '.Display::grid_js('timelines', $url,$columns,$column_model,$extra_params, array(), null,true).'
  56. });
  57. </script>';
  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('ItemAdded'),'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(array('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('ItemUpdated'), $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(array('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('ItemUpdated'), $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(array('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('ItemDeleted'), 'success');
  131. }
  132. }
  133. $content = $timeline->listing();
  134. break;
  135. default:
  136. $content = $timeline->listing();
  137. break;
  138. }
  139. $tpl = new Template($tool_name);
  140. $tpl->assign('actions', $actions);
  141. $tpl->assign('message', $message);
  142. $tpl->assign('content', $content);
  143. $tpl->display_one_col_template();