iassign_form.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <?php
  2. /**
  3. * Form to add and edit interactive activities
  4. *
  5. *
  6. * Release Notes:
  7. * - v 1.5 2013/09/19
  8. * + Insert function for validation form (mod_iassign_form::validation).
  9. * + Fix bugs in download exercise file.
  10. * - v 1.4 2013/08/21
  11. * + Change title link with message for get file for donwload file.
  12. * - v 1.3 2013/08/15
  13. * + Change view file for allow download file.
  14. * - v 1.2 2013/08/01
  15. * + Fix error in sql query for var $igeom.
  16. * - v 1.1 2013/07/12
  17. * + Fix error messages of 'setType' in debug mode for hidden fields.
  18. *
  19. * @author Patricia Alves Rodrigues
  20. * @author Leônidas O. Brandão
  21. * @version v 1.5 2013/09/19
  22. * @package mod_iassign
  23. * @since 2010/09/27
  24. * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
  25. *
  26. * <b>License</b>
  27. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28. */
  29. // Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
  30. if (!defined('MOODLE_INTERNAL')) {
  31. die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
  32. }
  33. require_once($CFG->libdir . '/formslib.php');
  34. require_once($CFG->dirroot . '/course/moodleform_mod.php');
  35. require_once($CFG->dirroot . '/mod/iassign/lib.php');
  36. /// This class create form based moodleform.
  37. // @see moodleform
  38. class mod_iassign_form extends moodleform {
  39. /// Add elements to form
  40. function definition () {
  41. global $CFG, $COURSE, $USER, $DB, $OUTPUT; // $OUTPUT only used to get '$OUTPUT->help_icon(...)'
  42. $mform = & $this->_form;
  43. $instance = $this->_customdata;
  44. // iGeom has special parameter 'script'
  45. $params = array('name' => '%iGeom%', 'parent' => 0);
  46. $igeom = $DB->get_records_sql(
  47. "SELECT s.id, s.name, s.parent FROM {iassign_ilm} s
  48. WHERE s.name LIKE :name AND s.parent = :parent", $params);
  49. $id = $COURSE->cm;
  50. foreach ($igeom as $item)
  51. $idigeom = $item->id; // get the last id of iGeom
  52. $all_ilm = $DB->get_records('iassign_ilm', array('enable' => 1)); // or use ./lib.php function: $all_ilm = search_iLM(1);
  53. $iassigns = $DB->get_records('iassign_statement', array('iassignid' => $COURSE->iassignid));
  54. if ($all_ilm) {
  55. $ids = "";
  56. $names = "";
  57. $evaluates = "";
  58. foreach ($all_ilm as $one_ilm) {
  59. $ids .= "'" . $one_ilm->id . "',";
  60. $names .= "'" . $one_ilm->name . "',";
  61. $evaluates .= "'" . $one_ilm->evaluate . "',";
  62. }
  63. $ids .= "'0'";
  64. $evaluates .= "'0'";
  65. }
  66. $name_iassigns = "";
  67. if ($iassigns) {
  68. foreach ($iassigns as $iassign) {
  69. $name_iassigns .= "'" . $iassign->name . "',";
  70. }
  71. }
  72. $name_iassigns .= "''";
  73. $error_name = get_string('error_iassign_name', 'iassign');
  74. // @todo Código Javascript, verificar alternativa.
  75. $code_javascript = "
  76. <script type='text/javascript'>
  77. //<![CDATA[
  78. var i;
  79. var ids = new Array($ids);
  80. var evaluates = new Array($evaluates);
  81. document.forms['mform1'].filename.disabled=1;
  82. if (document.forms['mform1'].type_iassign.value==1) {
  83. document.forms['mform1'].grade.style.display='none';
  84. document.forms['mform1'].max_experiment.style.display='none';
  85. } else {
  86. document.forms['mform1'].grade.style.display='block';
  87. document.forms['mform1'].max_experiment.style.display='block';
  88. }
  89. for (i=0;i<ids.length;i++) {
  90. if (ids[i]==document.forms['mform1'].iassign_ilmid.value && evaluates[i]==0) {
  91. document.forms['mform1'].automatic_evaluate.style.display='none';
  92. document.forms['mform1'].show_answer.style.display='none';
  93. //document.forms['mform1'].automatic_evaluate.disabled=1;
  94. // document.forms['mform1'].show_answer.disabled=1;
  95. }
  96. }
  97. if (document.forms['mform1'].iassign_ilmid.value==" . $idigeom .") { // iGeom has special parameter 'script'
  98. document.forms['mform1'].special_param1.style.display='block';
  99. document.forms['mform1'].special_param1.disabled=0;
  100. }
  101. else {
  102. document.forms['mform1'].special_param1.style.display='none';
  103. document.forms['mform1'].special_param1.value=0;
  104. document.forms['mform1'].special_param1.disabled=1;
  105. }
  106. function confirm_name (name) {
  107. var i;
  108. var names = new Array($name_iassigns);
  109. for (i=0;i<names.length;i++) {
  110. if (names[i]==name)
  111. alert('" . $error_name . "');
  112. }
  113. }
  114. function config_ilm (id) {
  115. //alert('config_ilm('+id+'): idigeom=$idigeom, ilmid='+document.forms['mform1'].iassign_ilmid.value);
  116. if (id==$idigeom) {
  117. document.forms['mform1'].special_param1.style.display='block';
  118. document.forms['mform1'].special_param1.disabled=0;
  119. }
  120. else {
  121. document.forms['mform1'].special_param1.style.display='none';
  122. document.forms['mform1'].special_param1.value=0;
  123. document.forms['mform1'].special_param1.disabled=1;
  124. }
  125. var i;
  126. var ids = new Array($ids);
  127. var evaluates = new Array($evaluates);
  128. if (document.forms['mform1'].type_iassign.value==1) {
  129. document.forms['mform1'].automatic_evaluate.disabled=1;
  130. document.forms['mform1'].show_answer.disabled=1;
  131. document.forms['mform1'].automatic_evaluate.value=0;
  132. document.forms['mform1'].show_answer.value=0;
  133. }
  134. else { // if (document.forms['mform1'].type_iassign.value==1)
  135. for (i=0;i<ids.length;i++) {
  136. if (ids[i]==id) {
  137. if (document.forms['mform1'].action.value=='edit') {
  138. if (evaluates[i]==0){
  139. document.forms['mform1'].automatic_evaluate.style.display='none';
  140. document.forms['mform1'].show_answer.style.display='none';
  141. document.forms['mform1'].automatic_evaluate.disabled=1;
  142. document.forms['mform1'].show_answer.disabled=1;
  143. document.forms['mform1'].automatic_evaluate.value=0;
  144. document.forms['mform1'].show_answer.value=0;
  145. }
  146. else {
  147. document.forms['mform1'].automatic_evaluate.style.display='block';
  148. document.forms['mform1'].show_answer.style.display='block';
  149. document.forms['mform1'].automatic_evaluate.disabled=0;
  150. document.forms['mform1'].show_answer.disabled=0;
  151. document.forms['mform1'].automatic_evaluate.value=1;
  152. document.forms['mform1'].show_answer.value=1;
  153. }
  154. }
  155. if (document.forms['mform1'].action.value=='add') {
  156. if (evaluates[i]==0) {
  157. document.forms['mform1'].automatic_evaluate.style.display='none';
  158. document.forms['mform1'].show_answer.style.display='none';
  159. document.forms['mform1'].automatic_evaluate.disabled=1;
  160. document.forms['mform1'].show_answer.disabled=1;
  161. document.forms['mform1'].automatic_evaluate.value=0;
  162. document.forms['mform1'].show_answer.value=0;
  163. }
  164. else {
  165. document.forms['mform1'].automatic_evaluate.style.display='block';
  166. document.forms['mform1'].show_answer.style.display='block';
  167. document.forms['mform1'].automatic_evaluate.disabled=0;
  168. document.forms['mform1'].show_answer.disabled=0;
  169. document.forms['mform1'].automatic_evaluate.value=1;
  170. document.forms['mform1'].show_answer.value=1;
  171. }
  172. }
  173. } // if (ids[i]==id)
  174. } // for (i=0;i<ids.length;i++)
  175. } // else if (document.forms['mform1'].type_iassign.value==1)
  176. } // function config_ilm(id)
  177. function disable_answer (resp) {
  178. if (resp==0) {
  179. document.forms['mform1'].show_answer.value=0;
  180. document.forms['mform1'].show_answer.disabled=1;
  181. }
  182. else {
  183. document.forms['mform1'].show_answer.disabled=0;
  184. }
  185. }
  186. function view_ilm_manager () {
  187. document.forms['mform1'].filename.disabled=1;
  188. open_ilm_manager=window.open('$CFG->wwwroot/mod/iassign/ilm_manager.php?id=$COURSE->id&from=iassign&ilmid='+document.forms['mform1'].iassign_ilmid.value,'','width=1000,height=880,menubar=0,location=0,scrollbars,status,fullscreen,resizable');
  189. }
  190. //]]>
  191. </script>";
  192. //-------------------------------------------------------------------------------
  193. // Adding the "title_type_iassign" fieldset, where all the common settings are showed
  194. // Data is insert through 'locallib.php ! action() -> new_iassign($param) : 3433/6441'
  195. $mform->addElement('header', 'title_type_iassign', get_string('type_iassign', 'iassign'));
  196. $type_iassign = array();
  197. $type_iassign[1] = get_string('example', 'iassign');
  198. $type_iassign[2] = get_string('test', 'iassign');
  199. $type_iassign[3] = get_string('exercise', 'iassign');
  200. $mform->addElement('select', 'type_iassign', get_string('choose_type_activity', 'iassign'), $type_iassign, array('onChange' => 'config_type(this.value);'));
  201. $mform->setDefault('type_iassign', 3); // default type_iassign = 3
  202. $mform->addHelpButton('type_iassign', 'helptypeiassign', 'iassign');
  203. //-------------------------------------------------------------------------------
  204. // Adding the "data_activity" fieldset, where all the common settings are showed
  205. $mform->addElement('header', 'data_activity', get_string('data_activity', 'iassign'));
  206. $mform->addElement('static', 'author', get_string('author_id', 'iassign'));
  207. $mform->addElement('static', 'author_modified', get_string('author_id_modified', 'iassign'));
  208. // Adding the standard "name" field
  209. $mform->addElement('text', 'name', get_string('iassigntitle', 'iassign'), array('size' => '55', 'onChange' => 'confirm_name(this.value);'));
  210. $mform->setType('name', PARAM_TEXT);
  211. $mform->addRule('name', get_string('required', 'iassign'), 'required');
  212. // Adding the standard "proposition" field
  213. //moodle2: $mform->addElement('htmleditor', 'proposition', get_string('proposition', 'iassign'));
  214. $mform->addElement('editor', 'proposition', get_string('proposition', 'iassign')); //moodle 3
  215. $mform->setType('proposition', PARAM_RAW);
  216. $mform->addRule('proposition', get_string('required', 'iassign'), 'required');
  217. //-----------------------------------------------------------------------------
  218. // Adding the "interactivy_learning_module" fieldset, where all the common settings are showed
  219. $mform->addElement('header', 'interactivy_learning_module', get_string('interactivy_learning_module', 'iassign'));
  220. //$mform->setExpanded('interactivy_learning_module');
  221. // Search iLM registered in the database
  222. // Field : 'iassign_ilmid'
  223. // $ilms = search_iLM(1);
  224. $ilms = $all_ilm;
  225. //TODO Trick: was difficult to use 'mform->addGroup(...)', then I made by hand <select name='iassign_ilmid'...>' with 'optgroup' by hand!
  226. //TODO But MoodleForm clear/do not register the 'iassign_ilmid' in 'locallib.php!new_iassign($param)'
  227. //TODO Then (in 'new_iassign(...)') get $_POST['iassign_ilmid'] directly!!
  228. //TODO See: 'locallib.php!add_edit_iassign()', 'locallib.php!function add_edit_iassign()' and 'locallib.php!function new_iassign($param)'
  229. //2019 $applets = array();
  230. //2019 foreach ($ilms as $ilm)
  231. //2019 $applets[$ilm->id] = $ilm->name . ' ' . $ilm->version;
  232. //2019 $mform->addElement('select', 'iassign_ilmid', get_string('choose_iLM', 'iassign'), $applets, array('onChange' => 'config_ilm(this.value);'));
  233. //2019 $mform->addHelpButton('iassign_ilmid', 'helpchoose_ilm', 'iassign');
  234. //D echo "<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>iassign_form.php:<br/>";
  235. // Split all iLM in those HTML from Java
  236. $list_html = array(); $list_html_id = array();
  237. $list_applets = array(); $list_applets_id = array();
  238. $num_iLM_html = $num_iLM_java = 0;
  239. foreach ($ilms as $ilm) {
  240. $type4 = substr($ilm->type, 0,4); // ensure the use of the only first 4 character (avoid difference if type is defined as 'HTML5')
  241. if (strcasecmp($type4, "HTML") == 0) { // Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.
  242. $list_html[$num_iLM_html] = $ilm->name . ' (' . $ilm->version . ')';
  243. $list_html_id[$num_iLM_html] = $ilm->id;
  244. $num_iLM_html++;
  245. } else {
  246. $list_applets[$num_iLM_java] = $ilm->name . ' (' . $ilm->version . ')';
  247. $list_applets_id[$num_iLM_java] = $ilm->id;
  248. $num_iLM_java++;
  249. } //D echo $ilm->id . " : " . $ilm->type . " <br/>";
  250. }
  251. //D echo "" . get_string('interactivy_learning_module', 'iassign') . ": num_iLM_html=$num_iLM_html, num_iLM_java=$num_iLM_java<br/>";
  252. //D Interactive Learning Modules: num_iLM_html=0, num_iLM_java=9
  253. //TODO Assim o '/lib/formslib.php : get_data()' destroi o campo 'iassign_ilmid'...
  254. $html_group = get_string("group", "iassign") . " HTML";
  255. $java_group = get_string("group", "iassign") . " Java";
  256. $groups_ilm_select = array($html_group => array(), $java_group => array());
  257. for ($ii=0; $ii<$num_iLM_html; $ii++) {
  258. $groups_ilm_select[$html_group][$list_html_id[$ii]] = $list_html[$ii];
  259. }
  260. for ($ii=0; $ii<$num_iLM_java; $ii++) {
  261. $groups_ilm_select[$java_group][$list_applets_id[$ii]] = $list_applets[$ii];
  262. }
  263. $mform->addElement('selectgroups', 'iassign_ilmid', get_string('choose_iLM', 'iassign'), $groups_ilm_select);
  264. $mform->addHelpButton('iassign_ilmid', 'choose_iLM', 'iassign');
  265. //TODO Adaptives to use API of MoodleForm
  266. // addOption($optgroup, $text, $value, $attributes=null)
  267. // $allOptions = array(); $ilmHtml = array(); $ilmJava = array();
  268. // $ilmHtml[] = $mform->createElement('optgroup', 'groupHtml', 'Group HTML');
  269. // for ($ii=0; $ii<$num_iLM_html; $ii++) $ilmHtml[] = $mform->createElement('optgroup', 'groupHtml', 'Group HTML'); //$allOptions[] = $mform->addOption('Group HTML', $list_html[$ii], $list_html_id[$ii]);
  270. // $mform->addGroup($ilmHtml, 'groupHtml', '', array(' '), false);
  271. // $list_html $list_html_id $num_iLM_html
  272. // $list_applets $list_applets_id $num_iLM_java
  273. // echo "<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>iassign_form.php: num_iLM_html=$num_iLM_html, num_iLM_java=$num_iLM_java<br/>";exit;
  274. // $allOptions[] = array('-1' => 'Group HTML'); for ($ii=0; $ii<$num_iLM_html; $ii++) $allOptions[] = array(''.$list_html_id[$ii] => $list_html[$ii]);
  275. // $allOptions[] = array('-2' => 'Group Java'); for ($ii=0; $ii<$num_iLM_java; $ii++) $allOptions[] = array(''.$list_applets_id[$ii] => $list_applets[$ii]);
  276. // $allOptions[$ilm->id] = $ilm->name . ' ' . $ilm->version;
  277. // $mform->addElement('select', 'iassign_ilmid', get_string('choose_iLM', 'iassign'), $allOptions, array('onChange' => 'config_ilm(this.value);'));
  278. // for ($ii=0; $ii<$num_iLM_html; $ii++) $allOptions[] = $list_html[$ii];
  279. // for ($jj=0; $jj<$num_iLM_java; $jj++) $allOptions[] = $list_applets[$jj];
  280. // $mform->addElement('select', 'iassign_ilmid', get_string('choose_iLM', 'iassign'), $allOptions, array('onChange' => 'config_ilm(this.value);'));
  281. // $mform->addHelpButton('iassign_ilmid', 'helpchoose_ilm', 'iassign');
  282. // Field 'action'
  283. $fileurl = "";
  284. $filename = "";
  285. if (!is_null($COURSE->iassign_file_id)) {
  286. $mform->addElement('hidden', 'action', 'viewpluginpage');
  287. $fs = get_file_storage();
  288. $file = $fs->get_file_by_id($COURSE->iassign_file_id);
  289. $fileurl = $CFG->wwwroot . "/pluginfile.php/" . $file->get_contextid() . "/mod_iassign/exercise" . '/' . $file->get_itemid() . $file->get_filepath() . $file->get_filename();
  290. $filename = $file->get_filename();
  291. }
  292. //D echo "123";
  293. $html_div = '<br/>&nbsp;<br/><div id="fitem_id_iassign_file_id" class="fitem required fitem_fgroup">';
  294. $html_div .= '<div class="fitemtitle"><label for="id_iassign_file_id">' . get_string('choose_file', 'iassign'); // 'Choose the file with the iLM activity'
  295. $html_div .= '<img class="req" title="' . get_string('requiredelement', 'form') . '" alt="' . get_string('requiredelement', 'form') . '" src="' . $CFG->wwwroot . '/theme/image.php/standard/core/1379534589/req"></label></div>';
  296. $html_div .= '<div class="felement fselect">';
  297. $html_div .= '<span id="iassign_file_link" style="color:#000000;"><a href="' . $fileurl . '" target="_blank" title="' . get_string('download_file', 'iassign') . $filename . '">' . $filename . '</a></span>';
  298. if ($fileurl != "")
  299. $html_div .= '&nbsp;&nbsp;&nbsp;';
  300. $html_div .= '<input onclick="view_ilm_manager()" name="add_ilm" value="' . get_string('add_ilm', 'iassign') . '" type="button" id="id_add_ilm"/>';
  301. $html_div .= '</div>';
  302. $html_div .= '</div>';
  303. $mform->addElement('html', $html_div);
  304. //Applies only iLM iGeom
  305. $mform->addElement('selectyesno', 'special_param1', get_string('special_param', 'iassign')); //$ynoptions
  306. $mform->setDefault('special_param1', 0);
  307. $mform->addHelpButton('special_param1', 'helpspecial_param', 'iassign');
  308. //-----------------------------------------------------------------------------
  309. //Applies only when the iLM is automatic evaluate.
  310. $mform->addElement('header', 'id_automatic_evaluate', get_string('only_automatic_evaluate', 'iassign'));
  311. // Using automatic evaluation activity? 0 - no / 1 – yes
  312. $mform->addElement('selectyesno', 'automatic_evaluate', get_string('automatic_evaluate', 'iassign'), array('onChange' => 'disable_answer(this.value);'));
  313. $mform->disabledIf('automatic_evaluate', 'type_iassign', 'eq', 1); //activity does not display if the type example
  314. $mform->setDefault('automatic_evaluate', 0);
  315. // @todo Ver código comentado
  316. //$mform->addHelpButton('automatic_evaluate', 'helpautomatic_evaluate', 'iassign');
  317. //Show automatic evaluation results to students? 0 - no / 1 - yes
  318. $mform->addElement('selectyesno', 'show_answer', get_string('show_answer', 'iassign'));
  319. $mform->disabledIf('show_answer', 'type_iassign', 'eq', 1); //activity does not display if the type example
  320. // $mform->disabledIf('show_answer', 'automatic_evaluate', 'neq', 0);
  321. $mform->setDefault('show_answer', 0);
  322. //$mform->addHelpButton('show_answer', 'helpshow_answer', 'iassign');
  323. //-----------------------------------------------------------------------------
  324. // Adding the "duration_activity" fieldset, where all the common settings are showed
  325. $mform->addElement('header', 'duration_activity', get_string('duration_activity', 'iassign'));
  326. $mform->addElement('date_time_selector', 'timeavailable', get_string('availabledate', 'iassign'));
  327. $mform->setDefault('timeavailable', time());
  328. $mform->disabledIf('timeavailable', 'type_iassign', 'eq', 1); // activity does not display if the type example
  329. $mform->addElement('date_time_selector', 'timedue', get_string('duedate', 'iassign'));
  330. $mform->setDefault('timedue', time() + 7 * 24 * 3600);
  331. $mform->disabledIf('timedue', 'type_iassign', 'eq', 1); //activity does not display if the type example
  332. //Allow sending late? 0 - no or unlocked / 1 - yes or locked
  333. $mform->addElement('selectyesno', 'preventlate', get_string('preventlate', 'iassign'));
  334. $mform->setDefault('preventlate', 0);
  335. $mform->addHelpButton('preventlate', 'helppreventlate', 'iassign');
  336. $mform->disabledIf('preventlate', 'type_iassign', 'eq', 1); //activity does not display if the type example
  337. $mform->disabledIf('preventlate', 'type_iassign', 'eq', 2); //activity does not display if the type test
  338. //Allow test after delivery? 0 - no or unlocked / 1 - yes or locked
  339. $mform->addElement('selectyesno', 'test', get_string('permission_test', 'iassign'));
  340. $mform->setDefault('test', 0);
  341. $mform->addHelpButton('test', 'helptest', 'iassign');
  342. $mform->disabledIf('test', 'type_iassign', 'eq', 1); //activity does not display if the type example
  343. $mform->disabledIf('test', 'type_iassign', 'eq', 2); //activity does not display if the type test
  344. //--------------
  345. $mform->addElement('header', 'op_val', get_string('op_val', 'iassign'));
  346. $mform->addElement('modgrade', 'grade', get_string('grade', 'iassign'));
  347. $mform->setDefault('grade', 100);
  348. $mform->disabledIf('grade', 'type_iassign', 'eq', 1); //activity does not display if the type example
  349. $mform->disabledIf('grade', 'type_iassign', 'eq', 2); //activity does not display if the type test
  350. $max_experiment_options = array(0 => get_string('ilimit', 'iassign'));
  351. for ($i = 1; $i <= 20; $i++)
  352. $max_experiment_options[$i] = $i;
  353. $mform->addElement('select', 'max_experiment', get_string('experiment', 'iassign'), $max_experiment_options);
  354. $mform->setDefault('max_experiment', 0);
  355. $mform->addHelpButton('max_experiment', 'helpexperiment', 'iassign');
  356. $mform->disabledIf('max_experiment', 'type_iassign', 'eq', 1); //activity does not display if the type example
  357. $mform->disabledIf('max_experiment', 'type_iassign', 'eq', 2); //activity does not display if the type test
  358. if ($COURSE->iassign_list) {
  359. //-------------- dependency
  360. $mform->addElement('header', 'headerdependency', get_string('dependency', 'iassign'));
  361. $mform->addHelpButton('headerdependency', 'helpdependency', 'iassign');
  362. foreach ($COURSE->iassign_list as $iassign) {
  363. $tmp = 'iassign_list[' . $iassign->id . ']';
  364. if ($iassign->enable == 1)
  365. $mform->addElement('checkbox', $tmp, $iassign->name);
  366. } //foreach ($COURSE->iassign_list as $iassign)
  367. } //if ($COURSE->iassign_list)
  368. $mform->addElement('hidden', 'dependency');
  369. $mform->setType('dependency', PARAM_RAW);
  370. //-------------- config
  371. $mform->addElement('header', 'config', get_string('general', 'iassign'));
  372. $visibleoptions = array(1 => get_string('show'), 0 => get_string('hide'));
  373. $mform->addElement('select', 'visible', get_string('visible', 'iassign'), $visibleoptions);
  374. $mform->setDefault('visible', 0);
  375. //-------------------------------------------------------------------------------
  376. // Hidden fields
  377. $mform->addElement('hidden', 'action');
  378. $mform->setType('action', PARAM_TEXT);
  379. $mform->addElement('hidden', 'oldname');
  380. $mform->setType('oldname', PARAM_TEXT);
  381. $mform->addElement('hidden', 'id');
  382. $mform->setType('id', PARAM_TEXT);
  383. $mform->addElement('hidden', 'iassign_id');
  384. $mform->setType('iassign_id', PARAM_TEXT);
  385. $mform->addElement('hidden', 'file', '0');
  386. $mform->setType('file', PARAM_INT);
  387. $mform->addElement('hidden', 'filename');
  388. $mform->setType('filename', PARAM_TEXT);
  389. $mform->addElement('hidden', 'fileold');
  390. $mform->setType('fileold', PARAM_TEXT);
  391. $mform->addElement('hidden', 'iassignid');
  392. $mform->setType('iassignid', PARAM_TEXT);
  393. $mform->addElement('hidden', 'author_name');
  394. $mform->setType('author_name', PARAM_TEXT);
  395. $mform->addElement('hidden', 'author_modified_name');
  396. $mform->setType('author_modified_name', PARAM_TEXT);
  397. $mform->addElement('hidden', 'timecreated');
  398. $mform->setType('timecreated', PARAM_TEXT);
  399. $mform->addElement('hidden', 'position');
  400. $mform->setType('position', PARAM_TEXT);
  401. $mform->addElement('html', $code_javascript);
  402. // add standard elements, common to all modules
  403. $this->add_action_buttons();
  404. } // function definition()
  405. function validation ($data, $files) {
  406. global $COURSE, $DB;
  407. $errors = parent::validation($data, $files);
  408. $mform = & $this->_form;
  409. $errors = array();
  410. if ($mform->elementExists('name')) {
  411. $value = trim($data['name']);
  412. if ($value == '') {
  413. $errors['name'] = get_string('required', 'iassign');
  414. }
  415. }
  416. if ($mform->elementExists('proposition')) {
  417. // echo "iassign_form.php : data['proposition'] :<br/>"; print_r($data['proposition']);
  418. // $data['proposition'] = Array ([text] => ... [format] => ) - segundo esta' vazio!
  419. if (is_array($data['proposition'])) {
  420. // foreach ($data['proposition'] as $key => $value) echo "key=" . $key . " - value=" . $value . "<br/>";
  421. // $data['proposition'] = [format] => ) key=text - value=
  422. $aux = $data['proposition']; // Format JSON: {"em":"...","pt":"..."}
  423. if (isset($aux['text']))
  424. $value = trim($aux['text']);
  425. else
  426. $value = trim($aux[0]);
  427. }
  428. else
  429. $value = trim($data['proposition']);
  430. if ($value == '') {
  431. $errors['proposition'] = get_string('required', 'iassign');
  432. }
  433. }
  434. // echo "iassign_form.php : mform :<br/>"; // print_r($mform); exit();
  435. if ($mform->elementExists('file')) {
  436. $value = trim($data['file']);
  437. if ($value == 0) {
  438. $errors['iassign_ilmid'] = get_string('required_iassign_file', 'iassign');
  439. }
  440. }
  441. return $errors;
  442. } // function validation($data, $files)
  443. } // class mod_iassign_form extends moodleform