settings.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. <?php
  2. /**
  3. *
  4. * This PHP script is invoked by Moodle every time it enters at Admin section (./admin/search.php).
  5. * It provides a link to the iAssign general configurations area ('pluginname').
  6. *
  7. * Release Notes:
  8. * - v 2.0.1 2022/09/15
  9. * + Considering table 'iassign_ilm': messages to fields 'evaluate', 'reevaluate', 'editingbehavior'; fixes to allow the edition of 'reevaluate', 'editingbehavior'
  10. * - v 2.0.0 2022/02/22
  11. * + New option to see all activities of a given iLM (./mod/iassign/settings_activities.php?action=activities&ilm_id=38)
  12. * - v 1.9.3 2020/08/03
  13. * + Debug security added into "else if ($action == 'config')": if (!isset($ilm) || !$ilm) return;* - v 1.9.2 2020/02/15
  14. * + Fixed 2 problems inside 'if ($ilm_parent)': 1. Error: '+' -> '.'; 2. Changed 'if (is_object($ilm_parent)) if (is_object($ilm_parent->description))'
  15. * to '$current_language = current_language(); $description_obj = iassign_language::get_description_lang(...);... $str_description = $description_obj;'
  16. * - v 1.9.1 2017/12/02
  17. * + Indentation and comments improvements
  18. * - v 1.9 2013/12/12
  19. * + Allow use the language in iLM description.
  20. * - v 1.8 2013/10/31
  21. * + Insert support of export iLM in zip packages.
  22. * - v 1.7 2013/10/24
  23. * + Insert support of iLM upgrade.
  24. * - v 1.6 2013/09/11
  25. * + Insert support of iLM params.
  26. * - v 1.5 2013/08/01
  27. * + Fix bug for block change visibility in iLM wiht statement.
  28. * - v 1.4 2013/07/12
  29. * + Insert action config for accept versions of iLM.
  30. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR.
  31. * + Now view separate only iLMs for filter versions.
  32. *
  33. * @author Patricia Alves Rodrigues
  34. * @author Leo^nidas de Oliveira Branda~o
  35. * @version v 1.9.1 2017/12/02
  36. * @package mod_iassign_settings
  37. * @since 2010/09/27
  38. * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
  39. *
  40. * @calledby ./admin/search.php: every time enter 'search' Moodle class all plugin installed through its 'settings.php'
  41. * @calledby ./admin/search.php: when choose iAssign setting enter here again
  42. *
  43. * <b>License</b>
  44. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  45. */
  46. // Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
  47. defined('MOODLE_INTERNAL') || die();
  48. global $OUTPUT, $CFG, $DB;
  49. require_once($CFG->dirroot . '/mod/iassign/lib.php');
  50. require_once($CFG->dirroot . '/mod/iassign/locallib.php');
  51. if (!is_siteadmin()) { // ./lib/accesslib.php
  52. print "Access denied!<br/>";
  53. exit();
  54. }
  55. //$context = context_module::instance($USER->cm); // usado no: ilm_handlers/html5.php
  56. //USER.{context}.id=" . $context->id
  57. $action = optional_param('action', 'view', PARAM_TEXT);
  58. $ilm_id = optional_param('ilm_id', 0, PARAM_INT);
  59. $ilm_param_id = optional_param('ilm_param_id', 0, PARAM_INT);
  60. $ilm_id_parent = optional_param('ilm_id_parent', 0, PARAM_INT);
  61. $status = optional_param('status', 0, PARAM_INT);
  62. if (!$action && !$ilm_id) {
  63. return; // nothing to be done (it is the Admin entering at the initial administrative section)
  64. }
  65. if ($action == 'visible') {
  66. ilm_settings::visible_ilm($ilm_id, $status);
  67. $action = 'config';
  68. $ilm_id = $ilm_id_parent;
  69. }
  70. else
  71. if ($action == 'visible_param') {
  72. ilm_settings::visible_param($ilm_param_id, $status);
  73. $action = 'config';
  74. }
  75. else
  76. if ($action == 'export') {
  77. ilm_settings::export_ilm($ilm_id);
  78. $action = 'config';
  79. }
  80. $str = '';
  81. if (!file_exists($CFG->dirroot . '/filter/iassign_filter/version.php')) {
  82. $str .= $OUTPUT->box_start();
  83. $str .= '<center>' . $OUTPUT->error_text(get_string('error_check_iassign_filter', 'iassign')) . '</center>';
  84. $str .= $OUTPUT->box_end();
  85. }
  86. if (!file_exists($CFG->dirroot . '/blocks/iassign_block/version.php')) {
  87. $str .= $OUTPUT->box_start();
  88. $str .= '<center>' . $OUTPUT->error_text(get_string('error_check_iassign_block', 'iassign')) . '</center>';
  89. $str .= $OUTPUT->box_end();
  90. }
  91. if (!file_exists($CFG->dirroot . '/lib/editor/tinymce/plugins/iassign/version.php')) {
  92. $str .= $OUTPUT->box_start();
  93. $str .= '<center>' . $OUTPUT->error_text(get_string('error_check_iassign_tinymce', 'iassign')) . '</center>';
  94. $str .= $OUTPUT->box_end();
  95. }
  96. if ($action == 'view') { // in Admin interface after "click" over "Activities modules" of iAssign, reaches this point
  97. $url_add = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'add'));
  98. $action_add = new popup_action('click', $url_add, 'popup', array('width' => 900, 'height' => 650));
  99. $link_add = $OUTPUT->action_link($url_add, get_string('add_ilm_iassign', 'iassign'), $action_add) . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  100. //2022/02 'settings_see_activities' = "See all the iLM activies"
  101. //TODO $link_see_activities = "http://.../mod/iassign/settings_activities.php?action=activities" for now 'settings_activities.php' requires "&courseid=422&ilm_id=61"
  102. $url_activities = new moodle_url('/mod/iassign/settings_activities.php', array('action' => 'activities')); // examine the data base of all iLM activities
  103. $action_activities = new popup_action('click', $url_activities, 'popup', array('width' => 900, 'height' => 650));
  104. $link_see_activities = $OUTPUT->action_link($url_activities, get_string('settings_see_activities', 'iassign'), $action_activities) . $OUTPUT->help_icon('settings_see_activities', 'iassign');
  105. //$link_see_activities = "";
  106. //TODO To be used to see all the activities (for now is necessary to provide a given course to a specfic iLM, through it {modules}.id)
  107. $url_import = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'import'));
  108. $action_import = new popup_action('click', $url_import, 'popup', array('width' => 900, 'height' => 650));
  109. $link_import = $OUTPUT->action_link($url_import, get_string('import_ilm', 'iassign'), $action_import) . $OUTPUT->help_icon('import_ilm', 'iassign');
  110. // First list all iLM from type HTML, then the "applets"
  111. // $iassign_ilms = $DB->get_records('iassign_ilm', array('parent' => 0)); // id, version, parent, name
  112. // {iassign_ilm} : id name version type description url extension parent file_jar file_class width height enable timemodified author timecreated evaluate reevaluate editingbehavior submissionbehavior action_buttons
  113. // In upgrade could get erro if field 'reevaluate' does not exists
  114. // $iassign_ilms = $DB->get_records_sql("SELECT id,type,description,name,parent,url,version,extension,evaluate,reevaluate,editingbehavior,submissionbehavior FROM {iassign_ilm} WHERE parent=0 ORDER BY type");
  115. $iassign_ilms = $DB->get_records_sql("SELECT * FROM {iassign_ilm} WHERE parent=0 ORDER BY type");
  116. // Put at the first line of the iLM table: "Add iLM" "See all the activities" "Import iLM"
  117. $str .= '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . chr(13);
  118. $str .= '<tr><td colspan=2 align=left>' . $link_add . "</td>\n";
  119. $str .= "<td align=right></td>\n"; //2022/02
  120. //TODO $str .= "<td align=right>" . $link_see_activities . "</td>\n"; //TODO It will presents the option 'settings_see_activities' - must provide {course}.id and {modules}.id
  121. //TODO $link_see_activities = "http://.../mod/iassign/settings_activities.php?action=activities&courseid=422&ilm_id=61"
  122. $str .= '<td colspan=2 align=right>' . $link_import . "</td>\n";
  123. $str .= "</tr>\n";
  124. if ($iassign_ilms) {
  125. foreach ($iassign_ilms as $ilm) {
  126. //D echo " - iLM: id=" . $ilm->id . "; name=" . $ilm->name . "; extension=" . $ilm->extension . "<br/>\n";
  127. // ./mod/iassign/icon/icon_see_activities.gif
  128. $url_activities = new moodle_url('/mod/iassign/settings_activities.php', array('action' => 'activities', 'ilm_id' => $ilm->id)); // examine the data base of all iLM activities
  129. $link_activities = $OUTPUT->action_link($url_activities, iassign_icons::insertIT('icon_see_activities','see_ilm_activities','see_ilm_activities')); // locallib.php: class 'iassign_icons'
  130. $url_config = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm->id));
  131. $link_config = $OUTPUT->action_link($url_config, iassign_icons::insertIT('gear_bw_small','config_ilm','config_ilm')); // put the "gear" icon (at right): config_ilm = "Manager the configuration of iLM"
  132. $ilm_count = 1;
  133. $ilm_version = 0; //R $iassign_ilm_list = $DB->get_records('iassign_ilm', array('parent' => $ilm->id)); //_ other sintax to get iLM
  134. $iassign_ilm_list = $DB->get_records_sql("SELECT id, version FROM {iassign_ilm} WHERE parent = " . $ilm->id );
  135. if ($iassign_ilm_list) {
  136. foreach ($iassign_ilm_list as $ilm_parent) {
  137. $ilm_count++;
  138. if (floatval(preg_replace('/[^0-9]+/', '', $ilm_parent->version)) > $ilm_version) $ilm_version = floatval(preg_replace('/[^0-9]+/', '', $ilm_parent->version));
  139. }
  140. }
  141. $str_sql = "SELECT COUNT(id) FROM {iassign_statement} WHERE iassign_ilmid =" . $ilm->id;
  142. $iassign_count = $DB->count_records_sql($str_sql, null); // get the total of activities with this iLM
  143. // Count the number of iLM derived from '$ilm'
  144. //R $iassign_ilm_parent = $DB->get_records('iassign_ilm', array('parent' => $ilm->id)); //_ other sintax to get iLM
  145. $iassign_ilm_parent = $DB->get_records_sql("SELECT id FROM {iassign_ilm} WHERE parent = " . $ilm->id);
  146. foreach ($iassign_ilm_parent as $ilm_parent) {
  147. //R $iassign_statement = $DB->get_records('iassign_statement', array('iassign_ilmid' => $ilm_parent->id)); //_ other sintax to get iLM
  148. //R if ($iassign_statement) { $iassign_count += count($iassign_statement); }
  149. $str_sql_parents = "SELECT COUNT(id) FROM {iassign_statement} WHERE iassign_ilmid =" . $ilm_parent->id;
  150. $iassign_count += $DB->count_records_sql($str_sql_parents, null);
  151. }
  152. //D echo " &nbsp; &nbsp; #atividade derivadas do iLM id=" . $ilm->id . " : " . $iassign_count . "<br/>\n";
  153. $link_upgrade = "";
  154. $upgrade_file = $ilm->url . 'ilm-upgrade_' . strtolower($ilm->name) . '.xml';
  155. if ($upgrade_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA)) {
  156. $upgrade_version = floatval(preg_replace('/[^0-9]+/', '', $upgrade_xml->version));
  157. if ($ilm_version < $upgrade_version) {
  158. $url_upgrade = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'confirm_upgrade', 'ilm_id' => $ilm->id));
  159. $link_upgrade = $OUTPUT->action_link($url_upgrade, iassign_icons::insert('upgrade_ilm', $upgrade_xml->version));
  160. }
  161. }
  162. // Get field '*_iassign_ilm.description' that has the JSON text format: "{"pt_br":"...","en":"..." ...}"
  163. // locallib.php: class iassign_language : get text from JSON {"en":"...","pt":"..."}
  164. $current_language = current_language();
  165. $description_obj = iassign_language::get_description_lang($current_language, $ilm->description); // gets a pure text description
  166. //D echo "----------<br/>";print_r($description_obj); echo "<br/>";
  167. //D Warning: 'get_description_lang(...)' avoid the error "Debug info: Object of class stdClass could not be converted to string"
  168. if (is_object($description_obj)) // just in case (if some changes in Moodle/PHP 'json_decode(...)' function...
  169. $str_description = $description_obj->text;
  170. else
  171. $str_description = $description_obj;
  172. $str_info = 'type=' . $ilm->type . ', evaluate=' . $ilm->evaluate . ', reevaluate=' . $ilm->reevaluate . ', editingbehavior=' . $ilm->editingbehavior . ', submissionbehavior=' . $ilm->submissionbehavior;
  173. $str .= '<tr>';
  174. $str .= '<td class="header c1" width=70% title="fields: name, description"><strong title="' . $str_info . '">' . $ilm->name . ' (' . $ilm->version . ')<br/>' .
  175. $str_description . '</strong></td>' . chr(13);
  176. $str .= '<td class="header c1" width=10% ><strong>' . get_string('versions_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm_count . '</td>' . chr(13);
  177. $str .= '<td class="header c1" width=10% ><strong>' . get_string('activities', 'iassign') . ':</strong>&nbsp;' . $iassign_count . '</td>' . chr(13);
  178. //$str .= '<td class="header c1" width=5% ><strong>' . get_string('see_activities', 'iassign') . ':</strong>&nbsp;' . $link_see_activities . '</td>' . chr(13);
  179. $str .= '<td class="header c1" width=5% align="center">' . $link_activities . '</td>' . chr(13);
  180. //$str .= "<td></td>\n"; //$link_see_activities = ""; //2022/02
  181. $str .= '<td class="header c1" width=5% align="center">' . $link_upgrade . '&nbsp;&nbsp;' . $link_config . '</td>' . chr(13); // valign=bottom
  182. $str .= '</tr>' . chr(13);
  183. } // foreach ($iassign_ilms as $ilm)
  184. } // if ($iassign_ilms)
  185. $str .= '</table>' . chr(13);
  186. // Print the iLM table
  187. $settings->add(new admin_setting_heading('iassign', get_string('config_ilm', 'iassign') . $OUTPUT->help_icon('modulename', 'iassign'), $str));
  188. } // if ($action == 'view')
  189. else if ($action == 'confirm_upgrade') {
  190. $ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  191. $upgrade_file = $ilm->url . 'ilm-upgrade_' . strtolower($ilm->name) . '.xml';
  192. $upgrade_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  193. $lang = current_language();
  194. if (array_key_exists($lang, $upgrade_xml->description))
  195. $description = $upgrade_xml->description->$lang;
  196. else
  197. $description = $upgrade_xml->description->en;
  198. $str .= '<table id="outlinetable" class="generaltable boxaligncenter" width="100%">' . chr(13);
  199. $str .= '<tr><td>' . $description;
  200. $str .= '</td></tr></table>';
  201. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'view'));
  202. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'upgrade', 'ilm_id' => $ilm_id));
  203. $str .= "<center>" . $OUTPUT->heading(get_string('confirm_upgrade_ilm', 'iassign'), 3, 'helptitle', 'uniqueid');
  204. $url_yes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'upgrade', 'ilm_id' => $ilm_id));
  205. $link_yes = $OUTPUT->action_link($url_yes, "<font color='green'><b>" . get_string('yes', 'iassign') . "</b></font>");
  206. $url_no = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'view'));
  207. $link_no = $OUTPUT->action_link($url_no, "<b>" . get_string('no', 'iassign') . "</b>");
  208. $str .= $link_no . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $link_yes . "</center>";
  209. $settings->add(new admin_setting_heading('iassign', get_string('upgrade_ilm_title', 'iassign'), $str));
  210. } // else if ($action == 'confirm_upgrade')
  211. else if ($action == 'config') {
  212. // Administration > plugins > iAssign : after "click" over the "gear" icon (at right of the iLM line) reaches this point
  213. // Presents basic information about this iLM
  214. $url_return = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign'));
  215. $link_return = $OUTPUT->action_link($url_return, get_string('return', 'iassign'));
  216. $url_new_version = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'new_version', 'ilm_id' => $ilm_id));
  217. $action_new_version = new popup_action('click', $url_new_version, 'popup', array('width' => 900, 'height' => 650));
  218. $link_new_version = $OUTPUT->action_link($url_new_version, get_string('new_version_ilm', 'iassign'), $action_new_version);
  219. $str .= '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . chr(13);
  220. $str .= '<tr><td colspan=2 align=left>' . $link_return . '</td><td colspan=1 align=right>' . $link_new_version . '</td></tr>' . chr(13);
  221. $ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  222. if (!isset($ilm) || !$ilm) return; // debug security...
  223. // $sql_query = 'SELECT s.* FROM {iassign_ilm} s WHERE s.parent = :parent ORDER BY s.version DESC'; // must find ":parent" is $ilm->id
  224. $sql_query = 'SELECT s.* FROM {iassign_ilm} s WHERE s.parent = '. $ilm->id . ' ORDER BY s.version DESC'; // more efficient, one string replacement less
  225. $iassign_ilm_parent = $DB->get_records_sql($sql_query, array('parent' => $ilm->id));
  226. array_unshift($iassign_ilm_parent, $ilm);
  227. if ($iassign_ilm_parent) {
  228. //D echo "<br/><br/>iassign_ilm_parent: " . $sql_query . "<br/>"; $conta = 0; //hoje
  229. foreach ($iassign_ilm_parent as $ilm_parent) {
  230. //D echo $conta . ": ilm_parent="; print_r($ilm_parent); echo "<br/>\n"; $conta++; //hoje
  231. $url_default = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'confirm_default_ilm', 'ilm_id' => $ilm_parent->id, 'ilm_parent' => $ilm->id));
  232. if (count($iassign_ilm_parent) == 1)
  233. $link_default = "";
  234. else if ($ilm_parent->parent == 0) {
  235. $link_default = iassign_icons::insert('default_ilm');
  236. $ilm_parent->enable = -1;
  237. }
  238. else
  239. $link_default = $OUTPUT->action_link($url_default, iassign_icons::insert('default_ilm_disabled'));
  240. //if ($ilm_parent->file_jar != $ilm_parent->id) {
  241. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm_parent->id, 'from' => 'admin'));
  242. $action_view = new popup_action('click', $url_view, 'iplookup', array('title' => get_string('view_ilm', 'iassign'), 'width' => 1200, 'height' => 650));
  243. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm'), $action_view);
  244. // } else {
  245. //$link_view = '';
  246. // }
  247. $url_edit = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'edit', 'ilm_id' => $ilm_parent->id));
  248. $action_edit = new popup_action('click', $url_edit, 'iplookup', array('title' => get_string('edit_ilm', 'iassign'), 'width' => 900, 'height' => 650));
  249. $link_edit = $OUTPUT->action_link($url_edit, iassign_icons::insert('edit_ilm'), $action_edit);
  250. $url_visible = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'visible', 'ilm_id' => $ilm_parent->id, 'status' => $ilm_parent->enable, 'ilm_id_parent' => $ilm->id));
  251. $iassign_statement = $DB->get_records('iassign_statement', array('iassign_ilmid' => $ilm_parent->id));
  252. $total = 0;
  253. if ($iassign_statement)
  254. $total = count($iassign_statement);
  255. if ($ilm_parent->enable == 0 && $total == 0) {
  256. $link_visible = $OUTPUT->action_link($url_visible, iassign_icons::insert('show_ilm'));
  257. }
  258. elseif ($ilm_parent->enable == 1 && $total == 0) {
  259. $link_visible = $OUTPUT->action_link($url_visible, iassign_icons::insert('hide_ilm'));
  260. }
  261. else if ($ilm_parent->enable == 0) { // unlock = Unlock
  262. // $link_visible = '&nbsp;' . iassign_icons::insert('unlock'); - 'unlock' = 'Unlock'
  263. $link_visible = $OUTPUT->action_link($url_visible, iassign_icons::insert('show_ilm'));
  264. }
  265. else {
  266. $link_visible = $OUTPUT->action_link($url_visible, iassign_icons::insert('hide_ilm'));
  267. }
  268. $url_copy = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'copy', 'ilm_id' => $ilm_parent->id));
  269. $action_copy = new popup_action('click', $url_copy, 'iplookup', array('title' => get_string('copy_ilm', 'iassign'), 'width' => 900, 'height' => 650));
  270. $link_copy = $OUTPUT->action_link($url_copy, iassign_icons::insert('copy_ilm'), $action_copy);
  271. if ($total == 0 && ($ilm_parent->parent != 0 || count($iassign_ilm_parent) == 1) && !ilm_settings::applet_default($ilm_parent->file_jar)) {
  272. $url_delete = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'confirm_delete_ilm', 'ilm_id' => $ilm_parent->id, 'ilm_parent' => $ilm->id));
  273. $link_delete = $OUTPUT->action_link($url_delete, iassign_icons::insert('delete_ilm'));
  274. }
  275. else if (ilm_settings::applet_default($ilm_parent->file_jar)) {
  276. $url_delete = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'confirm_delete_ilm', 'ilm_id' => $ilm_parent->id, 'ilm_parent' => $ilm->id));
  277. $link_delete = $OUTPUT->action_link($url_delete, iassign_icons::insert('delete_ilm'));
  278. }
  279. else
  280. $link_delete = iassign_icons::insert('delete_ilm_disable');
  281. if (strtolower($ilm_parent->type) == 'html5') {
  282. $url_delete = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'confirm_delete_ilm', 'ilm_id' => $ilm_parent->id, 'ilm_parent' => $ilm->id));
  283. $link_delete = $OUTPUT->action_link($url_delete, iassign_icons::insert('delete_ilm'));
  284. }
  285. $url_export = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'export', 'ilm_id' => $ilm_parent->id, 'ilm_id_parent' => $ilm->id));
  286. $link_export = $OUTPUT->action_link($url_export, iassign_icons::insert('export_ilm'));
  287. $str .= '<tr><td colspan=3>';
  288. $str .= '<table width="100%">';
  289. if (!empty($ilm_parent->url))
  290. $url_ilm = display_url_ilm($ilm_parent->url);
  291. else
  292. $url_ilm = $ilm_parent->url;
  293. if ($ilm_parent->file_jar == $ilm_parent->id) {
  294. $ilm_parent->file_jar = "";
  295. }
  296. $str .= '<tr>' . chr(13);
  297. $str .= '<td width="50%"><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->version . '</td>' . chr(13);
  298. $str .= '<td width="50%" align="right" valign=bottom>';
  299. $str .= $link_default . '&nbsp;&nbsp;';
  300. $str .= $link_edit . '&nbsp;&nbsp;';
  301. $str .= $link_copy . '&nbsp;&nbsp;';
  302. $str .= $link_visible . '&nbsp;&nbsp;';
  303. $str .= $link_view . '&nbsp;&nbsp;';
  304. $str .= $link_export . '&nbsp;&nbsp;';
  305. $str .= $link_delete;
  306. $str .= '</td>' . chr(13) . '</tr>' . chr(13);
  307. // ./mod/iassign/locallib.php : function get_description_lang(...)
  308. //D print_r($ilm_parent->description); echo "<br/>"; exit(); // {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  309. //D ilm_parent->description = {"en":{"text":"iVProgH: interactive Visual ProgrammingA free educational tool of LInE - IME - USP.","format":"1"}, "pt_br":"Programa\u00e7\u00e3o visual interativa na Internet"}
  310. $str .= '<tr>' . chr(13);
  311. $current_language = current_language();
  312. // locallib.php: class iassign_language : get text from JSON {"en":"...","pt":"..."}
  313. $str_description = "";
  314. if ($ilm_parent) {
  315. $current_language = current_language();
  316. $description_obj = iassign_language::get_description_lang($current_language, $ilm_parent->description); // gets a pure text description
  317. if (is_object($description_obj)) // just in case (if some changes in Moodle/PHP 'json_decode(...)' function...
  318. $str_description = $description_obj->text;
  319. else
  320. $str_description = $description_obj;
  321. }
  322. $str .= '<td width="50%"><strong>' . get_string('description', 'iassign') . ':</strong>&nbsp;' .
  323. $str_description . '</td>' . chr(13); // iassign_language::get_description_lang($current_language, $ilm_parent->description)
  324. $str .= '<td width="50%"><strong>' . get_string('activities', 'iassign') . ':</strong>&nbsp;' . $total . '</td>' . chr(13);
  325. $str .= '</tr>' . chr(13);
  326. $langs_str = iassign_language::get_all_lang($ilm_parent->description);
  327. $str .= '<tr>';
  328. if ($langs_str != "")
  329. $str .= '<td><strong>' . get_string('language_label', 'iassign') . ':</strong>&nbsp;' . $langs_str . '</td>' . chr(13);
  330. $str .= '<td><strong>' . get_string('type_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->type . '</td>' . chr(13);
  331. $str .= '</tr>' . chr(13);
  332. if (strtolower($ilm_parent->type) == 'java') {
  333. $ilm_parent->file_jar = basename($ilm_parent->file_jar);
  334. }
  335. $str .= '<tr><td><strong>' . get_string('url_ilm', 'iassign') . ':</strong>&nbsp;<a href="' . $url_ilm . '" target="_blank">' . $url_ilm . '</a></td>';
  336. if ($ilm_parent->enable == 1 || $ilm_parent->enable == -1)
  337. $enable = get_string('yes', 'iassign');
  338. else
  339. $enable = get_string('no', 'iassign');
  340. $str .= '<td width="50%"><strong>' . get_string('enable', 'iassign') . ':</strong>&nbsp;' . $enable . '</td></tr>' . chr(13);
  341. // 'The iLM name of directory (HTML/JS) or iLM package (Java JAR)'
  342. // This field name is heritage from the first implementation of iAssign allowing only to integrate Java
  343. $str .= '<tr><td width="50%" title="field: file_jar"><strong>' . get_string('file_jar', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->file_jar . '</td>' . chr(13);
  344. // 'Initial file name ("*.html", if HTML; or "*.class", if Java)'
  345. // This field name is heritage from the first implementation of iAssign allowing only to integrate Java
  346. $str .= '<td width="50%" title="field: file_class"><strong>' . get_string('file_class', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->file_class . '</td></tr>' . chr(13);
  347. $str .= '<tr><td width="50%" title="field: extension"><strong>' . get_string('extension', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->extension . '</td>' . chr(13);
  348. $str .= '<td width="50%" title="field: width"><strong>' . get_string('width', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->width;
  349. $str .= '&nbsp;&nbsp;<strong>' . get_string('height', 'iassign') . ':</strong>&nbsp;' . $ilm_parent->height . '</td></tr>' . chr(13);
  350. // Field 'iassign_ilm.evaluate'
  351. if ($ilm_parent->evaluate == 1)
  352. $opt_evaluate = get_string('yes', 'iassign');
  353. else
  354. $opt_evaluate = get_string('no', 'iassign');
  355. $str .= '<tr><td width="50%" title="field: evaluate"><strong>' . get_string('evaluate', 'iassign') . ':</strong>&nbsp;' . $opt_evaluate . '</td>' . chr(13);
  356. if ($ilm_parent->reevaluate == 1)
  357. $opt_reevaluate = get_string('yes', 'iassign');
  358. else
  359. $opt_reevaluate = get_string('no', 'iassign');
  360. // Field 'iassign_ilm.reevaluate.'
  361. $str .= '<td width="50%"><strong>' . get_string('auto_evaluate_name_config', 'iassign') . ':</strong>&nbsp;' . $opt_reevaluate . '</td></tr>' . chr(13);
  362. // Field 'iassign_ilm.editingbehavior'
  363. $str .= '<tr><td><strong>' . get_string('editing_behavior_view', 'iassign') . ':</strong> ';
  364. if ($ilm_parent->editingbehavior == 0) { // 'iassign_ilm.editingbehavior' = 1 => the iLM allows the editing of a previous submission
  365. $str .= get_string('editing_behavior_0', 'iassign');
  366. } elseif ($ilm_parent->editingbehavior == 1) {
  367. $str .= get_string('editing_behavior_1', 'iassign');
  368. }
  369. $str .= ' </td><td><strong>' . get_string('submissionbehavior_view', 'iassign') . ':</strong> ';
  370. if ($ilm_parent->submissionbehavior == 0) {
  371. $str .= get_string('submission_behavior_0', 'iassign');
  372. } elseif ($ilm_parent->submissionbehavior == 1) {
  373. $str .= get_string('submission_behavior_1', 'iassign');
  374. }
  375. $str .= '</td></tr>' . chr(13);
  376. $str .= '<tr>' . chr(13);
  377. $str .= '<td width="50%"><strong>' . get_string('file_created', 'iassign') . ':</strong>&nbsp;' . userdate($ilm_parent->timecreated) . '</td>' . chr(13);
  378. $str .= '<td width="50%"><strong>' . get_string('file_modified', 'iassign') . ':</strong>&nbsp;' . userdate($ilm_parent->timemodified) . '</td>' . chr(13);
  379. $str .= '</tr>' . chr(13);
  380. $user_ilm = $DB->get_record('user', array('id' => $ilm_parent->author));
  381. if ($user_ilm) {
  382. $str .= '<tr>' . chr(13);
  383. $str .= '<td colspan=2><strong>' . get_string('author', 'iassign') . ':</strong>&nbsp;' . $user_ilm->firstname . '&nbsp;' . $user_ilm->lastname . '</td>' . chr(13);
  384. $str .= '</tr>' . chr(13);
  385. }
  386. $str .= '<tr>' . chr(13);
  387. $str .= '<td colspan=2><center>';
  388. $url_add_param = new moodle_url('/mod/iassign/settings_params.php', array('action' => 'add', 'ilm_id' => $ilm_id));
  389. $action_add_param = new popup_action('click', $url_add_param, 'popup', array('width' => 900, 'height' => 650));
  390. $link_add_param = $OUTPUT->action_link($url_add_param, iassign_icons::insert('add_param'), $action_add_param);
  391. $str .= '<table width="100%">' . chr(13);
  392. $str .= '<tr>' . chr(13);
  393. $str .= '<th colspan=3><center><strong>' . get_string('config_param', 'iassign') . $OUTPUT->help_icon('config_param', 'iassign') . '</strong></center></th>';
  394. $str .= '<th>' . $link_add_param . '</th>';
  395. $str .= '</tr>' . chr(13);
  396. $str .= '<tr>' . chr(13);
  397. $str .= '<td><strong>' . get_string('config_param_name', 'iassign') . '</strong></td>';
  398. $str .= '<td><strong>' . get_string('config_param_value', 'iassign') . '</strong></td>';
  399. $str .= '<td><strong>' . get_string('config_param_description', 'iassign') . '</strong></td>';
  400. $str .= '<td width="10%"><center><strong>' . get_string('config_param_actions', 'iassign') . '</strong></center></td>';
  401. $str .= '</tr>' . chr(13);
  402. $iassign_ilm_config = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $ilm_parent->id));
  403. foreach ($iassign_ilm_config as $ilm_config) {
  404. $url_edit_param = new moodle_url('/mod/iassign/settings_params.php', array('action' => 'edit', 'ilm_param_id' => $ilm_config->id));
  405. $action_edit_param = new popup_action('click', $url_edit_param, 'iplookup', array('title' => get_string('edit_param', 'iassign'), 'width' => 900, 'height' => 650));
  406. $link_edit_param = $OUTPUT->action_link($url_edit_param, iassign_icons::insert('edit_param'), $action_edit_param);
  407. $url_visible_param = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'visible_param', 'ilm_id' => $ilm_parent->id, 'status' => $ilm_config->visible, 'ilm_param_id' => $ilm_config->id));
  408. if ($ilm_config->visible == 0) {
  409. $link_visible_param = $OUTPUT->action_link($url_visible_param, iassign_icons::insert('show_param'));
  410. }
  411. elseif ($ilm_config->visible == 1) {
  412. $link_visible_param = $OUTPUT->action_link($url_visible_param, iassign_icons::insert('hide_param'));
  413. }
  414. $url_copy_param = new moodle_url('/mod/iassign/settings_params.php', array('action' => 'copy', 'ilm_param_id' => $ilm_config->id));
  415. $action_copy_param = new popup_action('click', $url_copy_param, 'iplookup', array('title' => get_string('copy_param', 'iassign'), 'width' => 900, 'height' => 650));
  416. $link_copy_param = $OUTPUT->action_link($url_copy_param, iassign_icons::insert('copy_param'), $action_copy_param);
  417. $url_delete_param = new moodle_url('/mod/iassign/settings_params.php', array('action' => 'delete', 'ilm_param_id' => $ilm_config->id, 'ilm_id' => $ilm_parent->id));
  418. $link_delete_param = $OUTPUT->action_link($url_delete_param, iassign_icons::insert('delete_param'));
  419. $str .= '<tr>' . chr(13);
  420. $str .= '<td>' . $ilm_config->param_name . '</td>' . chr(13);
  421. $str .= '<td>' . $ilm_config->param_value . '</td>' . chr(13);
  422. $str .= '<td width="50%">' . $ilm_config->description . '</td>' . chr(13);
  423. $str .= '<td width="10%"><center>';
  424. $str .= $link_edit_param . '&nbsp;&nbsp;';
  425. $str .= $link_copy_param . '&nbsp;&nbsp;';
  426. $str .= $link_visible_param . '&nbsp;&nbsp;';
  427. $str .= $link_delete_param;
  428. $str .= '</center></td>';
  429. $str .= '</tr>' . chr(13);
  430. }
  431. $str .= '</table>' . chr(13);
  432. $str .= '</center></td>';
  433. $str .= '</tr>' . chr(13);
  434. $str .= '</table>';
  435. $str .= '</td></tr>' . chr(13);
  436. $str .= '</tr><td colspan="3"></td></tr>' . chr(13);
  437. }
  438. } // if ($iassign_ilm_parent)
  439. $str .= '</table>';
  440. $settings->add(new admin_setting_heading('iassign', $ilm->name . '&nbsp;', $str));
  441. } // else if ($action == 'config')