settings_nasatlx_line.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. /**
  3. * Settings NASA-TLX/LInE manager. Reaches this code from administrative Moodle area, in setting 'plugins' of iAssign.
  4. * 1. action==export: see a table with all data from NASA-TLX/LInE (all questionnaires, each one with all answers)
  5. * 2. action==?
  6. *
  7. * Release Notes:
  8. * - v 0.1 2019/03/04
  9. *
  10. * @package mod_nasatlx
  11. * @author Leônidas de Oliveira Brandão
  12. * @version v 0.1 2019/03/04
  13. * @category
  14. * @copyright 2014 LInE - http://line.ime.usp.br
  15. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  16. */
  17. global $CFG, $USER, $PAGE, $OUTPUT, $DB;
  18. require_once("../../config.php");
  19. require_once($CFG->dirroot . '/mod/nasatlx/locallib.php');
  20. //DDD require_once($CFG->dirroot . '/mod/nasatlx/settings_form.php');
  21. require_login();
  22. if (isguestuser()) {
  23. die();
  24. }
  25. //Parameters GET e POST (parâmetros GET e POST)
  26. $nasa_id = optional_param('nasa_id', 0, PARAM_INT);
  27. $action = optional_param('action', NULL, PARAM_TEXT);
  28. $url = new moodle_url('/admin/settings.php', array('section' => 'modsettingnasatlx'));
  29. //$from = optional_param('from', NULL, PARAM_TEXT);
  30. //$status = optional_param('status', 0, PARAM_INT);
  31. $contextuser = context_user::instance($USER->id);
  32. $PAGE->set_url($url);
  33. $PAGE->set_context($contextuser);
  34. $PAGE->blocks->show_only_fake_blocks(); //
  35. $PAGE->set_pagelayout('popup');
  36. //D echo "settings_nasatlx_line.php: 5 action=$action<br/>\n";
  37. if ($action == 'export') {
  38. // echo "Export not yet implemented<br/>\n";
  39. $title = get_string('export_all_nasatlx', 'nasatlx') . $OUTPUT->help_icon('export_all_nasatlx', 'nasatlx');
  40. $PAGE->set_title($title);
  41. // print($OUTPUT->notification(get_string('error_upload_ilm', 'nasatlx'), 'notifyproblem'));
  42. print($OUTPUT->header());
  43. print($OUTPUT->heading($title));
  44. print " <style>\n " .
  45. " th.c { border: 1px solid #aaa; padding: 5px 10px; background-color: #6a9ada; } " .
  46. " th { border: 1px solid #aaa; padding: 5px 10px; background-color: #5a8aca; } " .
  47. " .td1l { border: 1px solid #aaa; padding: 5px 10px; background-color: #eeeefe; text-align:left} " .
  48. " .td1r { border: 1px solid #aaa; padding: 5px 10px; background-color: #eeeefe; text-align:right} " .
  49. " .td2l { border: 1px solid #aaa; padding: 5px 10px; background-color: #eeefee; text-align:left} " .
  50. " .td2r { border: 1px solid #aaa; padding: 5px 10px; background-color: #eeefee; text-align:right}\n" .
  51. " </style>\n";
  52. // Tables: 'nasatlx' (id, course, name, intro, timecreated, timemodified), 'course' (id, fullname)
  53. // SELECT m_nasatlx_resps.id, m_nasatlx_resps.cmid, m_nasatlx_resps.course, m_nasatlx_resps.user FROM m_course_modules, m_nasatlx, m_nasatlx_resps
  54. // WHERE m_nasatlx_resps.cmid=m_course_modules.id AND m_course_modules.instance=m_nasatlx.id AND m_nasatlx.id = 1;
  55. $query1 = "SELECT n.*, c.id AS courseid, c.fullname FROM {nasatlx} n, {course} c WHERE c.id = n.course";
  56. //D echo "$query1<br/>";
  57. $nasatlx_quest = $DB->get_records_sql($query1); // *_nasatlx = id, course, name, intro, timecreated, timemodified
  58. // foreach ($nasatlx_quest as $nasa_item) echo " * " . $nasa_item->id . ", " . $nasa_item->course . ", " . $nasa_item->name . ", " . $nasa_item->intro . "<br/>";
  59. if (!$nasatlx_quest)
  60. print get_string('list_all_nasatlx_empty', 'nasatlx') . "<br/>\n";
  61. else { // There are NASA questionnaires
  62. // $nasatlx_quest = Array ( [1] => stdClass Object ( [id] => 1 [course] => 2 [name] => Title questionnaire NASA-TLX/LInE [intro] => Text... [introformat] => 1 [timecreated] => 1551989761 [timemodified] => 0 [courseid] => 2 [fullname] => Curso teste ) )
  63. //_ foreach ($nasatlx_quest as $item_nasa_quest) { // usually array[1]
  64. //_ print " <table class='nicetable'>\n";
  65. //_ print " <tr class='td1l'><th class='c' title='course id'>". $item_nasa_quest->courseid . "</th><th class='c' title='course fullname' colspan='24'>" . $item_nasa_quest->fullname . "</th></tr>\n";
  66. //_ print " <tr class='td2l'><th class='c' title='nasatlx id'>". $item_nasa_quest->id . "</th><th class='c' title='nasatlx name' colspan='24'>" . $item_nasa_quest->name . "</th></tr>\n";
  67. //_ }
  68. //_ print " </table >\n<br/>\n";
  69. print " <table class='nicetable'>\n";
  70. $count1 = 0;
  71. foreach ($nasatlx_quest as $item_nasa_quest) { // select all answer to the questionnaire $item_nasa_quest
  72. $nasa_id = $item_nasa_quest->id;
  73. print " <tr class='td1l'><th class='c' title='course id'>". $item_nasa_quest->courseid . "</th><th class='c' title='course fullname' colspan='24'>" . $item_nasa_quest->fullname . "</th></tr>\n";
  74. print " <tr class='td2l'><th class='c' title='nasatlx id'>". $item_nasa_quest->id . "</th><th class='c' title='nasatlx name' colspan='24'>" . $item_nasa_quest->name . "</th></tr>\n";
  75. // See tables: nasatlx_resps, nasatlx, course_modules, course
  76. // $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  77. $query2 = "SELECT r.* FROM {nasatlx_resps} r, {course_modules} cm, {nasatlx} tlx WHERE " .
  78. "r.cmid=cm.id AND cm.instance=tlx.id AND tlx.id = " . $nasa_id;
  79. $nasatlx_answers = $DB->get_records_sql($query2);
  80. if (!$nasatlx_quest)
  81. print get_string('list_all_nasatlx_ans_empty', 'nasatlx') . "<br/r>\n";
  82. else {
  83. // *_nasatlx : id scale1 scale2 scale3 scale4 scale5 calc1 calc2 calc3 calc4 calc5 peso1 peso2 peso3 peso4 peso5 cmid course user created
  84. // print " <tr><th>". $item_nasa_quest->id . "</th><th colspan='20'>" . $item_nasa_quest->name . "</th></tr>\n";
  85. print " <tr>\n";
  86. print " <th>id</th><th>scale1</th><th>scale2</th><th>scale3</th><th>scale4</th><th>scale5</th><th>scale6</th>\n" .
  87. " <th>calc1</th><th>calc2</th><th>calc3</th><th>calc4</th><th>calc5</th><th>calc6</th>\n";
  88. print " <th>peso1</th><th>peso2</th><th>peso3</th><th>peso4</th><th>peso5</th><th>peso6</th>\n" .
  89. " <th>pares</th><th>cmid</th><th>course</th><th>user</th><th>created</th></tr>\n";
  90. $count2 = 0;
  91. foreach ($nasatlx_answers as $answer) { // fields : id scale1 scale2 scale3 scale4 scale5 calc1 calc2 calc3 calc4 calc5 peso1 peso2 peso3 peso4 peso5 cmid course user created
  92. print " <tr>\n";
  93. //D if ($count1==0) { echo "answer: "; print_r($answer); echo "<br/>"; }
  94. foreach ($answer as $nvalue) { // turn the object in array (or use 'foreach ($answer as $nkey=>$nvalue)')
  95. $count2++;
  96. if ($count1 % 2 == 0) {
  97. if ($count2 < 12) print "<td class='td1r'>" . $nvalue . "</td>";
  98. else print "<td class='td1l'>" . $nvalue . "</td>";
  99. }
  100. else {
  101. if ($count2 < 12) print "<td class='td2r'>" . $nvalue . "</td>";
  102. else print "<td class='td2l'>" . $nvalue . "</td>";
  103. }
  104. $count1++;
  105. } // foreach ($answer as $nvalue)
  106. print " </tr>\n";
  107. } // foreach ($nasatlx_answers as $answer)
  108. // $nasatlx_answers = $DB->get_records_sql($query2);
  109. }
  110. } // foreach ($nasatlx_quest as $item_nasa_quest)
  111. print " </table>\n";
  112. } // else if (!$nasatlx_quest)
  113. print "<br/><b>Total respostas: $count1<b><br/>\n";
  114. print($OUTPUT->footer());
  115. die;
  116. } // if ($action == 'export')
  117. /*
  118. else
  119. if ($action == 'edit') { // Edit data of an NASA-TLX/LInE => processed in 'settings_form.php'
  120. print "Edit not yet implemented<br/>\n";
  121. //_ $title = get_string('edit_nasa_item', 'nasatlx') . $OUTPUT->help_icon('add_ilm_nasatlx', 'nasatlx');
  122. //_ $PAGE->set_title($title);
  123. //_ $param = ilm_settings::add_edit_copy_nasa_item($nasa_id, $action);
  124. //_ $description = $param->description_lang; // used to present the NASA-TLX/LInE description in 'settings_form.php' - {"en":"...","pt":"..."}
  125. //_ $mform = new mod_ilm_form($param); // in 'settings_form.php': class mod_ilm_form
  126. //_ $mform->set_data($param);
  127. //_ if ($mform->is_cancelled()) {
  128. //_ close_window();
  129. //_ die;
  130. //_ }
  131. //_ else if ($formdata = $mform->get_submitted_data()) {
  132. //_ ilm_settings::edit_nasa_item($formdata, $formdata->file);
  133. //_ close_window(0, true);
  134. //_ die;
  135. //_ }
  136. //_ print($OUTPUT->header());
  137. //_ print($OUTPUT->heading($title));
  138. //_ $mform->display();
  139. //_ print($OUTPUT->footer());
  140. //_ die;
  141. }
  142. else
  143. if ($action == 'copy') {
  144. print "Copy not yet implemented<br/>\n";
  145. //_ $title = get_string('copy_nasa_item', 'nasatlx') . $OUTPUT->help_icon('add_ilm_nasatlx', 'nasatlx');
  146. //_ $PAGE->set_title($title);
  147. //_ $param = ilm_settings::add_edit_copy_nasa_item($nasa_id, $action);
  148. //_ $mform = new mod_ilm_form();
  149. //_ $mform->set_data($param);
  150. //_ if ($mform->is_cancelled()) {
  151. //_ close_window();
  152. //_ die;
  153. //_ }
  154. //_ else if ($formdata = $mform->get_data()) {
  155. //_ ilm_settings::copy_new_version_ilm($formdata);
  156. //_ close_window(0, true);
  157. //_ die;
  158. //_ }
  159. //_ print($OUTPUT->header());
  160. //_ print($OUTPUT->heading($title));
  161. //_ $mform->display();
  162. //_ print($OUTPUT->footer());
  163. //_ die;
  164. }
  165. else
  166. if ($action == 'confirm_remove_nasa_item') {
  167. print "Remove not yet implemented<br/>\n";
  168. //_ $title = get_string('remove_nasa_item', 'nasatlx');
  169. //_ $PAGE->set_title($title);
  170. //_ $PAGE->set_pagelayout('base');
  171. //_ $remove_nasa_item = ilm_settings::confirm_remove_nasa_item($nasa_id, $ilm_parent);
  172. //_ print($OUTPUT->header());
  173. //_ print($OUTPUT->heading($title));
  174. //_ print($remove_nasa_item);
  175. //_ print($OUTPUT->footer());
  176. //_ die;
  177. //_ }
  178. else
  179. if ($action == 'remove') {
  180. print "Remove not yet implemented<br/>\n";
  181. //_ $title = get_string('remove_nasa_item', 'nasatlx');
  182. //_ $PAGE->set_title($title);
  183. //_ $PAGE->set_pagelayout('redirect');
  184. //_ $parent = ilm_settings::remove_nasa_item($nasa_id);
  185. //_ if ($parent == null) {
  186. //_ $title = get_string('remove_nasa_item', 'nasatlx');
  187. //_ $PAGE->set_title($title);
  188. //_ $PAGE->set_pagelayout('base');
  189. //_ $remove_nasa_item = ilm_settings::confirm_remove_nasa_item($nasa_id, $ilm_parent);
  190. //_ print($OUTPUT->header());
  191. //_ print($OUTPUT->heading($title));
  192. //_ print($OUTPUT->notification(get_string('error_folder_permission_denied', 'nasatlx'), 'notifyproblem'));
  193. //_ print($remove_nasa_item);
  194. //_ print($OUTPUT->footer());
  195. //_ die;
  196. //_ }
  197. //_ if ($parent == 0)
  198. //_ redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingnasatlx', 'action' => 'view')));
  199. //_ else
  200. //_ redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingnasatlx', 'action' => 'config', 'nasa_id' => $ilm_parent)));
  201. //_ }
  202. else
  203. if ($action == 'default') {
  204. //_ $title = get_string('default_ilm', 'nasatlx');
  205. //_ $PAGE->set_title($title);
  206. //_ $PAGE->set_pagelayout('redirect');
  207. //_ ilm_settings::default_ilm($nasa_id);
  208. //_ redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingnasatlx', 'action' => 'config', 'nasa_id' => $ilm_parent)));
  209. }
  210. else
  211. if ($action == 'list') {
  212. //_ $title = get_string('list_ilm', 'nasatlx');
  213. //_ $PAGE->set_title($title);
  214. //_ $list_ilm = ilm_settings::list_ilm();
  215. //_ print($OUTPUT->header());
  216. //_ print($OUTPUT->heading($title . $OUTPUT->help_icon('list_ilm', 'nasatlx')));
  217. //_ print($list_ilm);
  218. //_ print($OUTPUT->footer());
  219. //_ die;
  220. }
  221. else
  222. if ($action == 'upgrade') {
  223. //_ $title = get_string('upgrade_ilm_title', 'nasatlx');
  224. //_ $PAGE->set_title($title);
  225. //_ $PAGE->set_pagelayout('redirect');
  226. //_ $ilm = ilm_settings::upgrade_ilm($nasa_id);
  227. //_ if ($ilm == 0)
  228. //_ redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingnasatlx', 'action' => 'view')));
  229. //_ else
  230. //_ redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingnasatlx', 'action' => 'config', 'nasa_id' => $ilm)));
  231. }
  232. else
  233. if ($action == 'view') {
  234. $nasatlx_ilm = $DB->get_record('nasatlx_ilm', array('id' => $nasa_id));
  235. $title = get_string('view_ilm', 'nasatlx') . $OUTPUT->help_icon('add_ilm_nasatlx', 'nasatlx');
  236. $PAGE->set_title($title . ': ' . $nasatlx_ilm->name . ' ' . $nasatlx_ilm->version);
  237. $view_ilm = ilm_settings::view_ilm($nasa_id, $from);
  238. print($OUTPUT->header());
  239. print($OUTPUT->heading($title . ': ' . $nasatlx_ilm->name . ' ' . $nasatlx_ilm->version));
  240. print($view_ilm);
  241. print($OUTPUT->footer());
  242. die;
  243. }
  244. */