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 '../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. $timeline = new Timeline();
  55. // Action handling: Add
  56. switch ($action) {
  57. case 'add':
  58. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  59. api_not_allowed();
  60. }
  61. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  62. $form = $timeline->return_form($url, 'add');
  63. // The validation or display
  64. if ($form->validate()) {
  65. if ($check) {
  66. $values = $form->exportValues();
  67. $res = $timeline->save($values);
  68. if ($res) {
  69. $message = Display::return_message(get_lang('ItemAdded'),'success');
  70. }
  71. }
  72. $content = $timeline->listing();
  73. } else {
  74. $actions .= '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  75. $form->addElement('hidden', 'sec_token');
  76. $form->setConstants(array('sec_token' => $token));
  77. $content = $form->return_form();
  78. }
  79. break;
  80. case 'edit':
  81. // Action handling: Editing
  82. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  83. $form = $timeline->return_form($url, 'edit');
  84. // The validation or display
  85. if ($form->validate()) {
  86. if ($check) {
  87. $values = $form->exportValues();
  88. //$timeline->update_all_promotion_status_by_career_id($values['id'],$values['status']);
  89. $res = $timeline->update($values);
  90. $message = Display::return_message(sprintf(get_lang('ItemUpdated'), $values['name']), 'confirmation');
  91. }
  92. $timeline->display();
  93. } else {
  94. $actions = '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  95. $form->addElement('hidden', 'sec_token');
  96. $form->setConstants(array('sec_token' => $token));
  97. $content = $form->return_form();
  98. }
  99. break;
  100. case 'add_item':
  101. // Action handling: Editing
  102. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&parent_id='.intval($_GET['parent_id']);
  103. $form = $timeline->return_item_form($url, 'edit');
  104. // The validation or display
  105. if ($form->validate()) {
  106. if ($check) {
  107. $values = $form->exportValues();
  108. $values['type'] = '';
  109. //$timeline->update_all_promotion_status_by_career_id($values['id'],$values['status']);
  110. $res = $timeline->save_item($values);
  111. $message = Display::return_message(sprintf(get_lang('ItemUpdated'), $values['name']), 'confirmation');
  112. }
  113. $timeline->display();
  114. } else {
  115. $actions = '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  116. $form->addElement('hidden', 'sec_token');
  117. $form->setConstants(array('sec_token' => $token));
  118. $content = $form->return_form();
  119. }
  120. break;
  121. case 'delete':
  122. // Action handling: delete
  123. if ($check) {
  124. $res = $timeline->delete($_GET['id']);
  125. if ($res) {
  126. $message = Display::return_message(get_lang('ItemDeleted'), 'success');
  127. }
  128. }
  129. $content = $timeline->listing();
  130. break;
  131. default:
  132. $content = $timeline->listing();
  133. break;
  134. }
  135. $tpl = new Template($tool_name);
  136. $tpl->assign('actions', $actions);
  137. $tpl->assign('message', $message);
  138. $tpl->assign('content', $content);
  139. $tpl->display_one_col_template();