]> git.mjollnir.org Git - moodle.git/commitdiff
define PARAM_SAFEDIR (constant) and clean_param (function) if required for compatibil...
authorgbateson <gbateson>
Wed, 5 Apr 2006 01:28:12 +0000 (01:28 +0000)
committergbateson <gbateson>
Wed, 5 Apr 2006 01:28:12 +0000 (01:28 +0000)
mod/hotpot/lib.php

index c6e240112fc94128b7acf48bae0b5b4e70465128..7f60e6502a3a7ac3f5a1b71cca3e5aa12ee6d13f 100644 (file)
@@ -1,7 +1,7 @@
 <?PHP  // $Id$\r
 \r
 //////////////////////////////////\r
-/// CONFIGURATION settings \r
+/// CONFIGURATION settings\r
 \r
 if (!isset($CFG->hotpot_showtimes)) {\r
        set_config("hotpot_showtimes", 0);\r
@@ -166,9 +166,9 @@ define("HOTPOT_DISPLAYNEXT_INDEX",  "2");
 \r
 \r
 // possible return values:\r
-//    false: \r
+//    false:\r
 //        display moderr.html (if exists) OR "Could not update" and return to couse view\r
-//    string: \r
+//    string:\r
 //        display as error message and return to course view\r
 //  true (or non-zero number):\r
 //        continue to $hp->redirect (if set) OR hotpot/view.php (to displsay quiz)\r
@@ -237,7 +237,7 @@ function hotpot_set_form_values(&$hp) {
                $hp->timeopen = 0;\r
        } else {\r
                $hp->timeopen = make_timestamp(\r
-                       $hp->openyear, $hp->openmonth, $hp->openday, \r
+                       $hp->openyear, $hp->openmonth, $hp->openday,\r
                        $hp->openhour, $hp->openminute, 0\r
                );\r
        }\r
@@ -246,7 +246,7 @@ function hotpot_set_form_values(&$hp) {
                $hp->timeclose = 0;\r
        } else {\r
                $hp->timeclose = make_timestamp(\r
-                       $hp->closeyear, $hp->closemonth, $hp->closeday, \r
+                       $hp->closeyear, $hp->closemonth, $hp->closeday,\r
                        $hp->closehour, $hp->closeminute, 0\r
                );\r
        }\r
@@ -506,14 +506,14 @@ function hotpot_add_chain(&$hp) {
 \r
                        if (! set_field("course_modules", "section", $sectionid, "id", $hp->coursemodule)) {\r
                                error("Could not update the course module with the correct section");\r
-                       }   \r
+                       }\r
 \r
-                       add_to_log($hp->course, "course", "add mod", \r
-                               "../mod/$hp->modulename/view.php?id=$hp->coursemodule", \r
+                       add_to_log($hp->course, "course", "add mod",\r
+                               "../mod/$hp->modulename/view.php?id=$hp->coursemodule",\r
                                "$hp->modulename $hp->instance"\r
-                       ); \r
-                       add_to_log($hp->course, $hp->modulename, "add", \r
-                               "view.php?id=$hp->coursemodule", \r
+                       );\r
+                       add_to_log($hp->course, $hp->modulename, "add",\r
+                               "view.php?id=$hp->coursemodule",\r
                                "$hp->instance", $hp->coursemodule\r
                        );\r
 \r
@@ -630,11 +630,11 @@ function hotpot_get_titles_and_next_ex(&$hp, $filepath, $get_next=false) {
                                }\r
                        }\r
 \r
-               } else { \r
+               } else {\r
                        // xml file (...maybe)\r
                        $xml_tree = new hotpot_xml_tree($source);\r
                        $xml_tree->filetype = '';\r
-       \r
+\r
                        $keys = array_keys($xml_tree->xml);\r
                        foreach ($keys as $key) {\r
                                if (preg_match('/^(hotpot|textoys)-(\w+)-file$/i', $key, $matches)) {\r
@@ -648,7 +648,7 @@ function hotpot_get_titles_and_next_ex(&$hp, $filepath, $get_next=false) {
 \r
                                $title = strip_tags($xml_tree->xml_value('data,title'));\r
                                $subtitle = $xml_tree->xml_value('hotpot-config-file,'.$xml_tree->quiztype.',exercise-subtitle');\r
-       \r
+\r
                                if ($get_next) {\r
                                        $include = $xml_tree->xml_value('hotpot-config-file,global,include-next-ex');\r
                                        if (!empty($include)) {\r
@@ -679,8 +679,8 @@ function hotpot_get_all_instances_in_course($modulename, $course) {
        }\r
 \r
        $query = "\r
-               SELECT \r
-                       cm.id AS coursemodule, \r
+               SELECT\r
+                       cm.id AS coursemodule,\r
                        cm.course AS course,\r
                        cm.module AS module,\r
                        cm.instance AS instance,\r
@@ -692,12 +692,12 @@ function hotpot_get_all_instances_in_course($modulename, $course) {
                        cs.sequence AS sequence,\r
                        cs.visible AS sectionvisible,\r
                        thismodule.*\r
-               FROM \r
+               FROM\r
                        {$CFG->prefix}course_modules AS cm,\r
                        {$CFG->prefix}course_sections AS cs,\r
                        {$CFG->prefix}modules AS m,\r
                        {$CFG->prefix}$modulename AS thismodule\r
-               WHERE \r
+               WHERE\r
                        m.name = '$modulename' AND\r
                        m.id = cm.module AND\r
                        cm.course = '$course->id' AND\r
@@ -711,7 +711,7 @@ function hotpot_get_all_instances_in_course($modulename, $course) {
 \r
                $explodesection = array();\r
                $order = array();\r
-       \r
+\r
                foreach ($rawmods as $rawmod) {\r
 \r
                        if (empty($explodesection[$rawmod->section])) {\r
@@ -736,7 +736,7 @@ function hotpot_get_all_instances_in_course($modulename, $course) {
                        }\r
 \r
                } // end foreach $modinfo\r
-                       \r
+\r
                ksort($instances);\r
                $instances = array_values($instances);\r
        }\r
@@ -791,9 +791,9 @@ function hotpot_update_chain(&$hp) {
        return $ok;\r
 }\r
 function hotpot_delete_instance($id) {\r
-/// Given an ID of an instance of this module, \r
-/// this function will permanently delete the instance \r
-/// and any data that depends on it.  \r
+/// Given an ID of an instance of this module,\r
+/// this function will permanently delete the instance\r
+/// and any data that depends on it.\r
 \r
        $result = false;\r
        if (delete_records("hotpot", "id", "$id")) {\r
@@ -820,7 +820,7 @@ function hotpot_delete_and_notify($table, $select, $strtable) {
 }\r
 \r
 function hotpot_user_complete($course, $user, $mod, $hp) {\r
-/// Print a detailed representation of what a  user has done with \r
+/// Print a detailed representation of what a  user has done with\r
 /// a given particular instance of this module, for user activity reports.\r
 \r
        $report = hotpot_user_outline($course, $user, $mod, $hp);\r
@@ -834,7 +834,7 @@ function hotpot_user_complete($course, $user, $mod, $hp) {
 }\r
 \r
 function hotpot_user_outline($course, $user, $mod, $hp) {\r
-/// Return a small object with summary information about what a \r
+/// Return a small object with summary information about what a\r
 /// user has done with a given particular instance of this module\r
 /// Used for user activity reports.\r
 /// $report->time = the time they did it\r
@@ -880,8 +880,8 @@ function hotpot_format_status($record, $undefined='&nbsp;') {
 }\r
 \r
 function hotpot_print_recent_activity($course, $isteacher, $timestart) {\r
-/// Given a course and a time, this module should find recent activity \r
-/// that has occurred in hotpot activities and print it out. \r
+/// Given a course and a time, this module should find recent activity\r
+/// that has occurred in hotpot activities and print it out.\r
 /// Return true if there was output, or false is there was none.\r
 \r
        global $CFG;\r
@@ -891,18 +891,18 @@ function hotpot_print_recent_activity($course, $isteacher, $timestart) {
 \r
                $records = get_records_sql("\r
                        SELECT\r
-                               h.id AS id, \r
+                               h.id AS id,\r
                                h.name AS name,\r
                                COUNT(*) AS count_attempts\r
-                       FROM \r
-                               {$CFG->prefix}hotpot AS h, \r
+                       FROM\r
+                               {$CFG->prefix}hotpot AS h,\r
                                {$CFG->prefix}hotpot_attempts AS a\r
-                       WHERE \r
-                               h.course = $course->id \r
-                               AND h.id = a.hotpot \r
+                       WHERE\r
+                               h.course = $course->id\r
+                               AND h.id = a.hotpot\r
                                AND a.id = a.clickreportid\r
                                AND a.starttime > $timestart\r
-                       GROUP  BY \r
+                       GROUP  BY\r
                                h.id, h.name\r
                ");\r
                // note that PostGreSQL requires h.name in the GROUP BY clause\r
@@ -930,11 +930,11 @@ function hotpot_print_recent_activity($course, $isteacher, $timestart) {
                        $result = true;\r
                }\r
        }\r
-       return $result;  //  True if anything was printed, otherwise false \r
+       return $result;  //  True if anything was printed, otherwise false\r
 }\r
 \r
 function hotpot_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $cmid="", $userid="", $groupid="") {\r
-// Returns all quizzes since a given time. \r
+// Returns all quizzes since a given time.\r
 \r
        global $CFG;\r
 \r
@@ -944,16 +944,16 @@ function hotpot_get_recent_mod_activity(&$activities, &$index, $sincetime, $cour
 \r
        $records = get_records_sql("\r
                SELECT\r
-                       a.*, \r
-                       h.name, h.course, \r
+                       a.*,\r
+                       h.name, h.course,\r
                        cm.instance, cm.section,\r
                        u.firstname, u.lastname, u.picture\r
-               FROM \r
+               FROM\r
                        {$CFG->prefix}hotpot_attempts AS a,\r
                        {$CFG->prefix}hotpot AS h,\r
                        {$CFG->prefix}course_modules AS cm,\r
                        {$CFG->prefix}user AS u\r
-               WHERE \r
+               WHERE\r
                        a.timefinish > '$sincetime'\r
                        AND a.id = a.clickreportid\r
                        AND a.userid = u.id $user_select\r
@@ -961,7 +961,7 @@ function hotpot_get_recent_mod_activity(&$activities, &$index, $sincetime, $cour
                        AND cm.instance = h.id\r
                        AND cm.course = '$courseid'\r
                        AND h.course = cm.course\r
-               ORDER BY \r
+               ORDER BY\r
                        a.timefinish ASC\r
        ");\r
 \r
@@ -1044,8 +1044,8 @@ function hotpot_print_recent_mod_activity($activity, $course, $detail=false) {
 \r
 function hotpot_cron () {\r
 /// Function to be run periodically according to the moodle cron\r
-/// This function searches for things that need to be done, such \r
-/// as sending out mail, toggling flags etc ... \r
+/// This function searches for things that need to be done, such\r
+/// as sending out mail, toggling flags etc ...\r
 \r
        global $CFG;\r
 \r
@@ -1053,7 +1053,7 @@ function hotpot_cron () {
 }\r
 \r
 function hotpot_grades($hotpotid) {\r
-/// Must return an array of grades for a given instance of this module, \r
+/// Must return an array of grades for a given instance of this module,\r
 /// indexed by user.  It also returns a maximum allowed grade.\r
 \r
        $hotpot = get_record('hotpot', 'id', $hotpotid);\r
@@ -1128,14 +1128,14 @@ function hotpot_get_participants($hotpotid) {
        global $CFG;\r
 \r
        return get_records_sql("\r
-               SELECT DISTINCT \r
+               SELECT DISTINCT\r
                        u.id, u.id\r
-               FROM \r
+               FROM\r
                        {$CFG->prefix}user u,\r
                        {$CFG->prefix}hotpot_attempts a\r
-               WHERE \r
+               WHERE\r
                        u.id = a.userid\r
-                       AND a.hotpot = '$hotpotid' \r
+                       AND a.hotpot = '$hotpotid'\r
        ");\r
 }\r
 \r
@@ -1144,7 +1144,7 @@ function hotpot_scale_used ($hotpotid, $scaleid) {
 //it it has support for grading and scales. Commented code should be\r
 //modified if necessary. See forum, glossary or journal modules\r
 //as reference.\r
-   \r
+\r
        $report = false;\r
 \r
        //$rec = get_record("hotpot","id","$hotpotid","scale","-$scaleid");\r
@@ -1152,12 +1152,12 @@ function hotpot_scale_used ($hotpotid, $scaleid) {
        //if (!empty($rec)  && !empty($scaleid)) {\r
        //      $report = true;\r
        //}\r
-   \r
+\r
        return $report;\r
 }\r
 \r
 //////////////////////////////////////////////////////////\r
-/// Any other hotpot functions go here.  \r
+/// Any other hotpot functions go here.\r
 /// Each of them must have a name that starts with hotpot\r
 \r
 \r
@@ -1177,7 +1177,7 @@ function hotpot_add_attempt($hotpotid) {
 \r
        // set all previous "in progress" attempts at this quiz to "abandoned"\r
        $db->Execute("\r
-               UPDATE \r
+               UPDATE\r
                        {$CFG->prefix}hotpot_attempts as a\r
                SET\r
                        a.timefinish = $timefinish,\r
@@ -1275,7 +1275,7 @@ class hotpot_xml_tree {
                        // decode angle brackets\r
                        $value = strtr($value, array('&#x003C;'=>'<', '&#x003E;'=>'>', '&#x0026;'=>'&'));\r
 \r
-                       // remove white space between <table>, <ul|OL|DL> and <OBJECT|EMBED> parts \r
+                       // remove white space between <table>, <ul|OL|DL> and <OBJECT|EMBED> parts\r
                        // (so it doesn't get converted to <br />)\r
                        $htmltags = '('\r
                        .       'TABLE|/?CAPTION|/?COL|/?COLGROUP|/?TBODY|/?TFOOT|/?THEAD|/?TD|/?TH|/?TR'\r
@@ -1492,7 +1492,7 @@ class hotpot_xml_quiz extends hotpot_xml_tree {
                                        $this->draganddrop = '';\r
                                        if (\r
                                                empty($this->real_outputformat) ||\r
-                                               $this->real_outputformat==HOTPOT_OUTPUTFORMAT_BEST || \r
+                                               $this->real_outputformat==HOTPOT_OUTPUTFORMAT_BEST ||\r
                                                empty($HOTPOT_OUTPUTFORMAT_DIR[$this->real_outputformat])\r
                                        ) {\r
                                                if ($CFG->hotpotismobile && isset($HOTPOT_OUTPUTFORMAT_DIR[HOTPOT_OUTPUTFORMAT_MOBILE])) {\r
@@ -1868,7 +1868,7 @@ function hotpot_add_attempt_details(&$attempt) {
                                // adjust JCross question numbers\r
                                if (preg_match('/^(across|down)(.*)$/', $name, $matches)) {\r
                                        $num .= '_'.$matches[1]; // e.g. 01_across, 02_down\r
-                                       $name = $matches[2]; \r
+                                       $name = $matches[2];\r
                                        if (substr($name, 0, 1)=='_') {\r
                                                $name = substr($name, 1); // remove leading '_'\r
                                        }\r
@@ -1972,8 +1972,8 @@ function hotpot_add_response(&$attempt, &$question, &$response) {
                        $loopcount++;\r
                        $question->name = "$questionname ($loopcount)";\r
 \r
-                       // This method fails to correctly identify questions in \r
-                       // quizzes which allow questions to be shuffled or omitted. \r
+                       // This method fails to correctly identify questions in\r
+                       // quizzes which allow questions to be shuffled or omitted.\r
                        // As yet, there is no workaround for such cases.\r
 \r
                } else {\r
@@ -2163,13 +2163,14 @@ if (!function_exists('html_entity_decode')) {
 // required for Moodle 1.x\r
 if (!isset($CFG->pixpath)) {\r
        $CFG->pixpath = "$CFG->wwwroot/pix";\r
-}  \r
+}\r
 \r
 if (!defined('PARAM_RAW')) define('PARAM_RAW', 0x0000);\r
-if (!defined('PARAM_CLEAN')) define('PARAM_CLEAN', 0x0001);\r
 if (!defined('PARAM_INT'))  define('PARAM_INT', 0x0002);\r
+if (!defined('PARAM_CLEAN')) define('PARAM_CLEAN', 0x0001);\r
 if (!defined('PARAM_ALPHA')) define('PARAM_ALPHA', 0x0004);\r
 if (!defined('PARAM_ALPHANUM')) define('PARAM_ALPHANUM', 0x0400);\r
+if (!defined('PARAM_SAFEDIR')) define('PARAM_SAFEDIR', 0x4000);\r
 \r
 if (!function_exists('required_param')) {\r
        // add this function for Moodle version<1.4.2\r
@@ -2197,10 +2198,16 @@ if (!function_exists('optional_param')) {
                return $param;\r
        }\r
 }\r
-if (!function_exists('set_user_preference')) {\r
+if (!function_exists('clean_param')) {\r
+       // add this function for Moodle 1.3 and less\r
+       function clean_param($param, $type) {\r
+               return $param;\r
+       }\r
+}\r
+if (!function_exists('fullname')) {\r
        // add this function for Moodle 1.x\r
-       function set_user_preference($name, $value, $otheruser=NULL) {\r
-               return false;\r
+       function fullname($user) {\r
+               return "$user->firstname $user->lastname";\r
        }\r
 }\r
 if (!function_exists('get_user_preferences')) {\r
@@ -2209,38 +2216,37 @@ if (!function_exists('get_user_preferences')) {
                return $default;\r
        }\r
 }\r
-if (!function_exists('fullname')) {\r
+if (!function_exists('set_user_preference')) {\r
        // add this function for Moodle 1.x\r
-       function fullname($user) {\r
-               return "$user->firstname $user->lastname";\r
+       function set_user_preference($name, $value, $otheruser=NULL) {\r
+               return false;\r
        }\r
 }\r
-\r
 function hotpot_utf8_to_html_entity($char) {\r
        // http://www.zend.com/codex.php?id=835&single=1\r
 \r
-       // array used to figure what number to decrement from character order value \r
-       // according to number of characters used to map unicode to ascii by utf-8 \r
+       // array used to figure what number to decrement from character order value\r
+       // according to number of characters used to map unicode to ascii by utf-8\r
        static $HOTPOT_UTF8_DECREMENT = array(\r
                1=>0, 2=>192, 3=>224, 4=>240\r
        );\r
 \r
-       // the number of bits to shift each character by \r
+       // the number of bits to shift each character by\r
        static $HOTPOT_UTF8_SHIFT = array(\r
                1=>array(0=>0),\r
                2=>array(0=>6,  1=>0),\r
                3=>array(0=>12, 1=>6,  2=>0),\r
                4=>array(0=>18, 1=>12, 2=>6, 3=>0)\r
        );\r
-        \r
-       $dec = 0; \r
+\r
+       $dec = 0;\r
        $len = strlen($char);\r
        for ($pos=0; $pos<$len; $pos++) {\r
                $ord = ord ($char{$pos});\r
-               $ord -= ($pos ? 128 : $HOTPOT_UTF8_DECREMENT[$len]); \r
-               $dec += ($ord << $HOTPOT_UTF8_SHIFT[$len][$pos]); \r
-       } \r
-       return '&#x'.sprintf('%04X', $dec).';'; \r
+               $ord -= ($pos ? 128 : $HOTPOT_UTF8_DECREMENT[$len]);\r
+               $dec += ($ord << $HOTPOT_UTF8_SHIFT[$len][$pos]);\r
+       }\r
+       return '&#x'.sprintf('%04X', $dec).';';\r
 }\r
 \r
 function hotpot_print_show_links($course, $location, $reference, $actions='', $spacer=' &nbsp; ', $new_window=false) {\r