Source for file sl_classroomlib.php

Documentation is available at sl_classroomlib.php

  1. <?php
  2.     
  3.     /**
  4.     * Sloodle classroom setup profile library.
  5.     *
  6.     * Provides back-end functionality for handling and managing Sloodle classroom setup profiles.
  7.     *
  8.     * @package sloodle
  9.     * @copyright Copyright (c) 2006-8 Sloodle (various contributors)
  10.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11.     *
  12.     * @contributor Edmund Edgar
  13.     * @contributor Peter R. Bloomfield
  14.     *
  15.     */
  16.     
  17.     
  18.     require_once(SLOODLE_DIRROOT.'/lib/sl_generallib.php');
  19.  
  20.     function sloodle_get_classroom_profiles($courseid null{
  21.         return get_records('sloodle_classroom_setup_profile','courseid',$courseid);
  22.     }
  23.  
  24.     function sloodle_get_classroom_profile_entries($profileid{
  25.         return get_records('sloodle_classroom_setup_profile_entry','sloodle_classroom_setup_profile_id ',$profileid);
  26.     }
  27.  
  28.     function sloodle_get_classroom_profile($profileid{
  29.         return get_record('sloodle_classroom_setup_profile','id',$profileid);
  30.     }
  31.  
  32.     function sloodle_get_classroom_profile_by_name($name$courseid{
  33.         return get_record('sloodle_classroom_setup_profile','name',$name,'courseid',$courseid);
  34.     }
  35.  
  36.     function sloodle_classroom_profile_exists_by_name($name$courseid{
  37.         return record_exists('sloodle_classroom_setup_profile','name',$name,'courseid',$courseid);
  38.     }
  39.  
  40.     function sloodle_add_classroom_profile($profile{
  41.         return insert_record('sloodle_classroom_setup_profile'$profile);
  42.     }
  43.  
  44.     function sloodle_add_classroom_profile_entry($profileentry{
  45.         return insert_record('sloodle_classroom_setup_profile_entry'$profileentry);
  46.     }
  47.  
  48.     /*function sloodle_update_classroom_profile_entry($profileentry) {
  49.         return update_record('sloodle_classroom_setup_profile_entry', $profileentry);
  50.     }
  51.  
  52.     function sloodle_save_classroom_profile_entry($profileentry) {
  53.         if ( isset($profileentry->id) && ($profileentry->id != '') && ($profileentry->id > 0) ) {
  54.             return update_record('sloodle_classroom_setup_profile_entry', $profileentry);
  55.         } else {
  56.             return insert_record('sloodle_classroom_setup_profile_entry', $profileentry);
  57.         }
  58.     }*/
  59.  
  60.     function sloodle_save_classroom_profile_entries($profileid,$entries{
  61.         $deleted delete_records('sloodle_classroom_setup_profile_entry''sloodle_classroom_setup_profile_id'$profileid)// Just in case
  62.         $success TRUE;
  63.         foreach($entries as $e{
  64.             if (!sloodle_add_classroom_profile_entry($e)) {
  65.                 $success FALSE;
  66.                 break;
  67.             }
  68.         }
  69.         return $success;
  70.     }
  71.  
  72.     function sloodle_save_classroom_profile($profile{
  73.         return update_record('sloodle_classroom_setup_profile'$profile);
  74.     }
  75.     
  76.     function sloodle_validate_object_for_pwd($uuid,$pwd{
  77.         $entry get_record('sloodle_active_object','uuid',$uuid);
  78.         return ($entry->pwd == $pwd);
  79.     }
  80.  
  81.     function sloodle_register_object($uuid,$name,$userid,$masteruuid{
  82.     
  83.         $o null;
  84.         $isnew true;
  85.         $o get_record('sloodle_active_object''uuid',$uuid);
  86.         if (is_object($o)) {
  87.             $isnew false;
  88.         else {
  89.             $o new stdClass();
  90.         }
  91.  
  92.         $o->uuid $uuid;
  93.         $o->sloodle_classroom_setup_profile_id 0;
  94.         $o->name $name;
  95.         $o->master_uuid $uuid;
  96.         // if an object is aready registered, leave the password 
  97.         $o->authenticated_by_userid $userid;
  98.         if ($isnew{
  99.             $o->pwd sloodle_random_object_pwd();
  100.         }
  101.         
  102.  
  103.         $ok false;
  104.         if ($isnew{    
  105.             $ok insert_record('sloodle_active_object',$o);
  106.         else {
  107.             $ok update_record('sloodle_active_object',$o)
  108.         }
  109.  
  110.         if ($ok{
  111.             return $o;
  112.         else {
  113.             return false;
  114.         }
  115.  
  116.     }
  117.  
  118.     function sloodle_random_object_pwd({
  119.         $sc '';
  120.         $str="0123456789";
  121.         for($length 0$length 9$length++{
  122.             $str str_shuffle($str);
  123.             $charnum mt_rand(0strlen($str)-1);
  124.             $char $str[$charnum];
  125.             // Don't allow 0 as the first character! -PRB
  126.             if ($length == && $char == '0'$char '1';
  127.             $sc .= $char;
  128.         }
  129.         return $sc;
  130.     }
  131.     
  132.     function sloodle_authorize_object($uuid,$name,$userid,$channel{
  133.         $entry sloodle_register_object($uuid,$name,$userid,$uuid);
  134.         if ($entry == null{
  135.             return FALSE;
  136.         }
  137.         return sloodle_send_xmlrpc_message($channel,0,$entry->pwd);
  138.     }
  139.  
  140. ?>

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