question_list_pagination_admin.inc.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Code library for HotPotatoes integration.
  5. * @package chamilo.exercise
  6. */
  7. /**
  8. * QUESTION LIST ADMINISTRATION
  9. *
  10. * This script allows to manage the question list
  11. * It is included from the script admin.php
  12. *
  13. */
  14. // deletes a question from the exercise (not from the data base)
  15. if ($deleteQuestion) {
  16. // If the question exists
  17. if ($objQuestionTmp = Question::read($deleteQuestion)) {
  18. $objQuestionTmp->delete($exerciseId);
  19. // if the question has been removed from the exercise
  20. if ($objExercise->removeFromList($deleteQuestion)) {
  21. $nbrQuestions--;
  22. }
  23. }
  24. // destruction of the Question object
  25. unset($objQuestionTmp);
  26. }
  27. $token = Security::get_token();
  28. //jqgrid will use this URL to do the selects
  29. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_question_list&exerciseId='.$exerciseId;
  30. //The order is important you need to check the the $column variable in the model.ajax.php file
  31. $columns = array(get_lang('Questions'), get_lang('Type'), get_lang('Category'), get_lang('Difficulty'), get_lang('Score'), get_lang('Actions'));
  32. //$columns = array(get_lang('Questions'), get_lang('Type'), get_lang('Category'), get_lang('Score'));
  33. // Adding filtered question extra fields
  34. $extraField = new ExtraField('question');
  35. $extraFields = $extraField->get_all(array('field_filter = ?' => 1));
  36. if (!empty($extraFields)) {
  37. foreach ($extraFields as $field) {
  38. $columns[] = $field['field_display_text'];
  39. }
  40. }
  41. $columns[] = get_lang('Actions');
  42. //Column config
  43. $column_model = array(
  44. array('name' => 'question', 'index' => 'question', 'width' => '300', 'align' => 'left'),
  45. array(
  46. 'name' => 'type',
  47. 'index' => 'type',
  48. 'width' => '100',
  49. 'align' => 'left',
  50. 'sortable' => 'false'
  51. ),
  52. array(
  53. 'name' => 'category',
  54. 'index' => 'category',
  55. 'width' => '100',
  56. 'align' => 'left',
  57. 'sortable' => 'false'
  58. ),
  59. array(
  60. 'name' => 'level',
  61. 'index' => 'level',
  62. 'width' => '50',
  63. 'align' => 'left',
  64. 'sortable' => 'false'
  65. ),
  66. array(
  67. 'name' => 'score',
  68. 'index' => 'score',
  69. 'width' => '50',
  70. 'align' => 'left',
  71. 'sortable' => 'false'
  72. )
  73. );
  74. if (!empty($extraFields)) {
  75. foreach ($extraFields as $field) {
  76. $column_model[] =
  77. array(
  78. 'name' => $field['field_variable'],
  79. 'index' => $field['field_variable'],
  80. 'width' => '100',
  81. 'align' => 'left',
  82. 'sortable' => 'false'
  83. );
  84. }
  85. }
  86. $column_model[] = array(
  87. 'name' => 'actions',
  88. 'index' => 'actions',
  89. 'width' => '50',
  90. 'align' => 'left',
  91. 'formatter' => 'action_formatter',
  92. 'sortable' => 'false'
  93. );
  94. //Autowidth
  95. $extra_params['autowidth'] = 'true';
  96. //height auto
  97. $extra_params['height'] = 'auto';
  98. $courseCode = api_get_course_id();
  99. $delete_link = null;
  100. if ($objExercise->edit_exercise_in_lp == true) {
  101. $delete_link = '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(get_lang("ConfirmYourChoice"))."\'".')) return false;" href="?exerciseId='.$exerciseId.'&cidReq='.$courseCode.'&sec_token='.$token.'&deleteQuestion=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
  102. }
  103. //With this function we can add actions to the jgrid (edit, delete, etc)
  104. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  105. return \'<a href="?exerciseId='.$exerciseId.'&myid=1&cidReq='.$courseCode.'&editQuestion=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
  106. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(get_lang("ConfirmYourChoice"))."\'".')) return false;" href="?cidReq='.$courseCode.'&sec_token='.$token.'&clone_question=\'+options.rowId+\'">'.Display::return_icon('cd.gif', get_lang('Copy'), '',ICON_SIZE_SMALL).'</a>'.
  107. $delete_link.'\';
  108. }';
  109. ?>
  110. <script>
  111. $(function () {
  112. <?php
  113. // grid definition see the $career->display() function
  114. echo Display::grid_js('question_list', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  115. ?>
  116. $("#question_list").jqGrid('navGrid','#question_list_pager',
  117. {search:false, edit:false, add:false, del:false, refresh:true}
  118. );
  119. });
  120. </script>
  121. <div id="dialog-confirm" title="<?php echo get_lang("ConfirmYourChoice"); ?>" style="display:none;">
  122. <p>
  123. <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0; display:none;">
  124. </span>
  125. <?php echo get_lang("AreYouSureToDelete"); ?>
  126. </p>
  127. </div>
  128. <?php
  129. Question::display_type_menu($objExercise);
  130. echo Question::getMediaLabels();
  131. echo '<br/><div style="clear:both;"></div>';
  132. echo Display::grid_html('question_list');