Source for file lib.php

Documentation is available at lib.php

  1. <?php
  2.  
  3.     /**
  4.     * Sloodle module core library functionality.
  5.     *
  6.     * This script is required by Moodle to contain certain key functionality for the module.
  7.     *
  8.     * @package sloodle
  9.     * @copyright Copyright (c) 2007 Sloodle (various contributors)
  10.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11.     *
  12.     * @contributor Peter R. Bloomfield
  13.     *
  14.     */
  15.  
  16. // Process the configuration options for the Sloodle module
  17. // $config is a reference to the submitted configuration settings
  18. // We can perform validation and other processing here as necessary
  19. function sloodle_process_options(&$config)
  20. {
  21.     global $CFG;
  22.  
  23.     // Determine the page which we should re-direct to if validation fails
  24.     $redirect $CFG->wwwroot '/admin/module.php?module=sloodle';
  25.  
  26.     // This string will contain error codes to supply to the configuration page if validation fails
  27.     $error_codes "";
  28.  
  29.     // Make sure the prim password is valid
  30.     $sloodle_pwd $config->prim_password;
  31.     // Is is an appropriate length?
  32.     $len strlen($sloodle_pwd);
  33.     if ($len 5{
  34.         $error_codes .= "&sloodlepwdshort=yes";
  35.     else if ($len 9{
  36.         $error_codes .= "&sloodlepwdlong=yes";
  37.     }
  38.     // Is it numeric only?
  39.     if (!ctype_digit($sloodle_pwd)) {
  40.         $error_codes .= "&sloodlepwdnonnum=yes";
  41.     }
  42.     // Does it have a leading zero?
  43.     if ($len >= && substr($sloodle_pwd01== "0"{
  44.         $error_codes .= "&sloodlepwdleadzero=yes";
  45.     }
  46.     
  47.     // Is the flag for allowing teachers to edit user data valid?
  48.     if (isset($config->allow_user_edit_by_teachers== FALSE || ($config->allow_user_edit_by_teachers != 'true' && $config->allow_user_edit_by_teachers != 'false')) {
  49.         // Force it to a default value
  50.         $config->allow_user_edit_by_teachers 'false';
  51.     }
  52.  
  53.     // Is the auth method recognised?
  54.     if (!($config->auth_method == "web" || $config->auth_method == "autoregister")) {
  55.         $error_codes .= "&sloodleauthinvalid=yes";
  56.     }
  57.  
  58.     // Were there any error messages?
  59.     if (!empty($error_codes)) {
  60.         // Append our parameters to the error codes string
  61.         $error_codes .= "&sloodlepwd={$config->prim_password}&sloodleauth={$config->auth_method}";
  62.     
  63.         // Redirect back to the configuration page
  64.         if (!headers_sent()) {
  65.         header("Location: " $redirect $error_codes "&header_redirect=true");
  66.             exit();
  67.         }
  68.         redirect($redirect $error_codes "&header_redirect=false""There was an error in the configuration. Please try again.");
  69.         exit();
  70.     }
  71. }
  72.  
  73.  
  74. // Placeholder functions
  75.  
  76. /**
  77.  * Given an object containing all the necessary data,
  78.  * (defined by the form in mod.html) this function
  79.  * will create a new instance and return the id number
  80.  * of the new instance.
  81.  * <b>Note:</b> this function is not yet used by Sloodle. Will hopefully be used in version 0.3!
  82.  *
  83.  * @param object $instance An object from the form in mod.html
  84.  * @return int The id of the newly inserted sloodle record
  85.  ***/
  86. function sloodle_add_instance($sloodle{
  87.     
  88.     return FALSE;
  89. }
  90.  
  91. /**
  92.  * Given an object containing all the necessary data,
  93.  * (defined by the form in mod.html) this function
  94.  * will update an existing instance with new data.
  95.  * <b>Note:</b> this function is not yet used by Sloodle. Will hopefully be used in version 0.3!
  96.  *
  97.  * @param object $instance An object from the form in mod.html
  98.  * @return boolean Success/Fail
  99.  ***/
  100. function sloodle_update_instance($sloodle{
  101.  
  102.     return FALSE;
  103. }
  104.  
  105. /**
  106.  * Given an ID of an instance of this module,
  107.  * this function will permanently delete the instance
  108.  * and any data that depends on it.
  109.  * <b>Note:</b> this function is not yet used by Sloodle. Will hopefully be used in version 0.3!
  110.  *
  111.  * @param int $id Id of the module instance
  112.  * @return boolean Success/Failure
  113.  ***/
  114. function sloodle_delete_instance($id{
  115.  
  116.     return FALSE;
  117. }
  118.  
  119. /**
  120.  * Return a small object with summary information about what a
  121.  * user has done with a given particular instance of this module
  122.  * Used for user activity reports.
  123.  * $return->time = the time they did it
  124.  * $return->info = a short text description
  125.  *
  126.  * @return null 
  127.  * @todo Finish documenting this function
  128.  ***/
  129. function sloodle_user_outline($course$user$mod$sloodle{
  130.     return NULL;
  131. }
  132.  
  133. /**
  134.  * Print a detailed representation of what a user has done with
  135.  * a given particular instance of this module, for user activity reports.
  136.  *
  137.  * @return boolean 
  138.  * @todo Finish documenting this function
  139.  ***/
  140. function sloodle_user_complete($course$user$mod$sloodle{
  141.     return true;
  142. }
  143.  
  144. /**
  145.  * Given a course and a time, this module should find recent activity
  146.  * that has occurred in sloodle activities and print it out.
  147.  * Return true if there was output, or false is there was none.
  148.  *
  149.  * @uses $CFG
  150.  * @return boolean 
  151.  * @todo Finish documenting this function
  152.  ***/
  153. function sloodle_print_recent_activity($course$isteacher$timestart{
  154.     global $CFG;
  155.  
  156.     return false;  //  True if anything was printed, otherwise false 
  157. }
  158.  
  159. /**
  160.  * Function to be run periodically according to the moodle cron
  161.  * This function searches for things that need to be done, such
  162.  * as sending out mail, toggling flags etc ...
  163.  *
  164.  * @uses $CFG
  165.  * @return boolean 
  166.  * @todo Finish documenting this function
  167.  ***/
  168. function sloodle_cron ({
  169.     global $CFG;
  170.  
  171.     return true;
  172. }
  173.  
  174. /**
  175.  * Must return an array of grades for a given instance of this module,
  176.  * indexed by user.  It also returns a maximum allowed grade.
  177.  * 
  178.  * Example:
  179.  *    $return->grades = array of grades;
  180.  *    $return->maxgrade = maximum allowed grade;
  181.  *
  182.  *    return $return;
  183.  *
  184.  * @param int $sloodleid ID of an instance of this module
  185.  * @return mixed Null or object with an array of grades and with the maximum grade
  186.  ***/
  187. function sloodle_grades($sloodleid{
  188.    return NULL;
  189. }
  190.  
  191. /**
  192.  * Must return an array of user records (all data) who are participants
  193.  * for a given instance of sloodle. Must include every user involved
  194.  * in the instance, independient of his role (student, teacher, admin...)
  195.  * See other modules as example.
  196.  *
  197.  * @param int $sloodleid ID of an instance of this module
  198.  * @return mixed boolean/array of students
  199.  ***/
  200. function sloodle_get_participants($sloodleid{
  201.     return false;
  202. }
  203.  
  204. /**
  205.  * This function returns if a scale is being used by one sloodle
  206.  * it it has support for grading and scales. Commented code should be
  207.  * modified if necessary. See forum, glossary or journal modules
  208.  * as reference.
  209.  *
  210.  * @param int $sloodleid ID of an instance of this module
  211.  * @return mixed 
  212.  * @todo Finish documenting this function
  213.  ***/
  214. function sloodle_scale_used ($sloodleid,$scaleid{
  215.     $return false;
  216.  
  217.     //$rec = get_record("sloodle","id","$sloodleid","scale","-$scaleid");
  218.     //
  219.     //if (!empty($rec)  && !empty($scaleid)) {
  220.     //    $return = true;
  221.     //}
  222.    
  223.     return $return;
  224. }
  225.  
  226.  
  227. ?>

Documentation generated on Tue, 04 Mar 2008 15:08:34 +0000 by phpDocumentor 1.4.0