media.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. use \ChamiloSession as Session;
  3. $language_file = array('exercice','tracking');
  4. // including the global library
  5. require_once '../inc/global.inc.php';
  6. // Access control
  7. api_protect_course_script(true);
  8. $course_id = api_get_course_int_id();
  9. //Add the JS needed to use the jqgrid
  10. $htmlHeadXtra[] = api_get_jqgrid_js();
  11. $interbreadcrumb[] = array("url" => "exercice.php", "name" => get_lang('Exercices'));
  12. Display::display_header(get_lang('Media'));
  13. $action = isset($_GET['action']) ? $_GET['action'] : null;
  14. $page_url = "media.php?".api_get_cidreq();
  15. $token = Security::get_token();
  16. switch ($action) {
  17. case 'add':
  18. $url = $page_url.'&action='.Security::remove_XSS($_GET['action']);
  19. $objQuestion = Question::getInstance(MEDIA_QUESTION);
  20. $form = new FormValidator('question_admin_form', 'post' , $url);
  21. // question form elements
  22. $objQuestion->createForm($form);
  23. $objQuestion->createAnswersForm($form);
  24. if ($form->validate()) {
  25. // question
  26. $objQuestion->processCreation($form, null);
  27. // answers
  28. $objQuestion->processAnswersCreation($form);
  29. } else {
  30. $form->display();
  31. }
  32. break;
  33. case 'edit':
  34. $url = $page_url.'&action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  35. $objQuestion = Question::read($_GET['id']);
  36. $form = new FormValidator('question_admin_form','post', $url);
  37. // question form elements
  38. $objQuestion->createForm($form);
  39. $objQuestion->createAnswersForm($form);
  40. $form->addElement('hidden', 'id', intval($_GET['id']));
  41. $defaults = array();
  42. $defaults['questionName'] = $objQuestion->question;
  43. $defaults['questionDescription'] = $objQuestion->description;
  44. $defaults['questionLevel'] = $objQuestion->level;
  45. $defaults['questionCategory'] = $objQuestion->category_list;
  46. $defaults['parent_id'] = $objQuestion->parent_id;
  47. $form->setDefaults($defaults);
  48. if ($form->validate()) {
  49. // question
  50. $objQuestion->processCreation($form, null);
  51. // answers
  52. $objQuestion->processAnswersCreation($form);
  53. } else {
  54. $form->display();
  55. }
  56. break;
  57. case 'delete':
  58. $objQuestion = Question::read($_GET['id']);
  59. $objQuestion->delete();
  60. break;
  61. }
  62. //jqgrid will use this URL to do the selects
  63. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_course_exercise_medias';
  64. //The order is important you need to check the the $column variable in the model.ajax.php file
  65. $columns = array(get_lang('Name'), get_lang('Actions'));
  66. //Column config
  67. $column_model = array(
  68. array('name'=>'name', 'index'=>'name', 'width'=>'200', 'align'=>'left'),
  69. array('name'=>'actions', 'index'=>'actions', 'width'=>'50', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
  70. );
  71. //Autowidth
  72. $extra_params['autowidth'] = 'true';
  73. //height auto
  74. $extra_params['height'] = 'auto';
  75. //With this function we can add actions to the jgrid (edit, delete, etc)
  76. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  77. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
  78. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(get_lang("ConfirmYourChoice"))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
  79. '\';
  80. }';
  81. ?>
  82. <script>
  83. $(function() {
  84. <?php
  85. // grid definition see the $career->display() function
  86. echo Display::grid_js('medias', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  87. ?>
  88. });
  89. </script>
  90. <?php
  91. $items = array(
  92. array('content' => Display::return_icon('add.png'), 'url' => $page_url.'&action=add')
  93. );
  94. echo Display::actions($items);
  95. echo Display::grid_html('medias');
  96. Display::display_footer();