[Hw4mdl-svn] SF.net SVN: hw4mdl: [54] trunk/moodle/mod/liveclassroom
Brought to you by:
jhlinder,
trollinger
From: <sh...@us...> - 2006-08-29 15:37:29
|
Revision: 54 Author: shazan Date: 2006-08-29 08:37:17 -0700 (Tue, 29 Aug 2006) ViewCVS: http://svn.sourceforge.net/hw4mdl/?rev=54&view=rev Log Message: ----------- Modified Paths: -------------- trunk/moodle/mod/liveclassroom/api.php trunk/moodle/mod/liveclassroom/index.php trunk/moodle/mod/liveclassroom/lib.php trunk/moodle/mod/liveclassroom/view.php Modified: trunk/moodle/mod/liveclassroom/api.php =================================================================== --- trunk/moodle/mod/liveclassroom/api.php 2006-08-28 10:02:53 UTC (rev 53) +++ trunk/moodle/mod/liveclassroom/api.php 2006-08-29 15:37:17 UTC (rev 54) @@ -42,8 +42,8 @@ */ require_once('System.php'); -require_once("LCHttpException.php"); + $LIVECLASSROOM_API_ADMIN = '/admin/api/api.pl?'; $LIVECLASSROOM_API_FUNCTION_NOOP = 'function=NOOP'; $LIVECLASSROOM_API_FUNCTION_CREATE_USER = 'function=createUser'; @@ -54,7 +54,10 @@ $LIVECLASSROOM_API_FUNCTION_CREATE_ROLE = 'function=createRole'; $LIVECLASSROOM_API_FUNCTION_DELETE_ROLE = 'function=deleteRole'; $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST = 'function=listClass'; +$LIVECLASSROOM_API_FUNCTION_CREATE_GROUP = 'function=createGroup'; +$LIVECLASSROOM_API_FUNCTION_MODIFY_GROUP = 'function=modifyGroup'; + $LIVECLASSROOM_API_RECORD_SEPERATOR = "=END RECORD"; /** @@ -136,48 +139,56 @@ global $LIVECLASSROOM_API_ADMIN; global $LIVECLASSROOM_API_FUNCTION_CREATE_USER; - if (!$ch = liveclassroom_api_authenticate()) { - return false; - } + + $data = liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_CREATE_USER, "&target=$userid&first_name=$rolename&last_name=$coursename"); + + preg_match("(\d*)", $data, $matches); + $respcode = $matches[0]; + /* + if ( $respcode == 301) { + error( "Creation user failed, already exist"); + return false; + }*/ + if ( $respcode != 100 && $respcode != 301) { + error( "Response: Account ($userId) Creation Failed: $resp_code"); + return false; + } + + + return true; - $url = $CFG->liveclassroom_servername. - $LIVECLASSROOM_API_ADMIN. - $LIVECLASSROOM_API_FUNCTION_CREATE_USER. - "&target=$userid". - "&first_name=$rolename". - "&last_name=$coursename"; - - //add_to_log("", "liveclassroom", "", "liveclassroom_api_create_user", "URL Sent: $url"); - - - curl_setopt($ch, CURLOPT_URL,$url); - $data = curl_exec($ch); - #print $data; - if (curl_errno($ch)) { - print curl_error($ch); - return false; - } - - preg_match("(\d*)", $data, $matches); - $respcode = $matches[0]; - - if ( $respcode != 100 && $respcode != 301) { - error( "Response: Account ($userId) Creation Failed: $resp_code"); - return false; - } - - return true; } - - -function liveclassroom_api_create_group() { +/* +* Create a group on the LC server +* @param $groupid : id of the group created +* +*/ +function liveclassroom_api_create_group($groupid) { + global $CFG; + global $LIVECLASSROOM_API_ADMIN; + global $LIVECLASSROOM_API_FUNCTION_CREATE_GROUP; + + $data = liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_CREATE_GROUP, "&target=$groupid"); + + if ( $respcode == 301) { + error( "Response: Authentication Failed: $resp_code"); + return false; + } + if ( $respcode != 100 && $respcode != 301) { + error( "Response: Cannot Create group with id:$groupid"); + return false; + } + + + return true; + + } - - + /** * Returns a session id (hzA) to be inserted in URLs to access the LC server * @uses CFG, USER @@ -248,45 +259,32 @@ return $authtoken; } - +/* +* Create a room on the LC server +* @param $roomid : id of the room created +* @param $roomname : name of the room created +*/ function liveclassroom_api_create_class ($roomid, $roomname) { global $CFG; global $LIVECLASSROOM_API_ADMIN, $LIVECLASSROOM_API_FUNCTION_CREATE_CLASS; - $data = liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_CREATE_CLASS,"&target=$roomid&longname=$roomname"); -/* - if (!$ch = liveclassroom_api_authenticate()) { - return false; - } + $data = liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_CREATE_CLASS,"&target=$roomid&longname=$roomname&preview=0"); + + preg_match("(\d*)", $data, $matches); + $respcode = $matches[0]; + + if ( $respcode == 301) { + error( "Class $roomname already exist"); + return false; + } + if ( $respcode != 100) { + error( "Response: Cannot Create Class with id:$roomid, and name: $roomname."); + return false; + } + + return true; - $url = $CFG->liveclassroom_servername. - $LIVECLASSROOM_API_ADMIN. - $LIVECLASSROOM_API_FUNCTION_CREATE_CLASS. - "&target=$roomid". - "&longname=$roomname"; - - //DEBUG - //add_to_log("", "liveclassroom", "", "liveclassroom_api_create_class", "URL Sent: $url"); - - curl_setopt($ch, CURLOPT_URL,$url); - $data = curl_exec($ch); - - //DEBUG - //add_to_log("", "liveclassroom", "", "liveclassroom_api_create_class", "DATA: <pre>$data</pre>"); - if (curl_errno($ch)) { - print curl_error($ch); - return false; - } -*/ - preg_match("(\d*)", $data, $matches); - $respcode = $matches[0]; - - if ( $respcode != 100) { - //error( "Response: Cannot Create Class with id:$roomid, and name: $roomname."); - return false; - } - return true; } function liveclassroom_api_add_user_role ($roomid, $userid, $role) { @@ -413,12 +411,10 @@ * Retrieve list of all rooms from the LC server available to the given user * ID. * - * @param userId User ID to filter by, null if none + * @param userid User ID to filter by, null if none * @param role Optional role to filter by, use ACCESS_PRIV_ constants from ListCommand. - * @param roomId - * @return List A List of LCRoom objects - * @throws - * If an error occurs in querying the server + * @param roomid + * @return */ function liveclassroom_api_get_room_list($userid, $role, $roomid) { @@ -507,8 +503,10 @@ /** - * $param $ch - * $param $const : function called + * Send a query to the server with the given function and the attributes given + * @param $ch + * @param $const : function called + * @param $attribute : different list of attribute for the function called * return $data : list of the result query */ function liveclassroom_api_send_query($ch,$const,$attribute) { @@ -518,7 +516,7 @@ if (!$ch = liveclassroom_api_authenticate()) { return false; } - try { + $url = $CFG->liveclassroom_servername. $LIVECLASSROOM_API_ADMIN. $const. @@ -532,13 +530,7 @@ return false; } - return $data; - - } - catch (LCHttpException $e) { - throw new LCHttpException("Bad URL"); - } - + return $data; } function liveclassroom_api_set_query_attribute($query,$attribute) { @@ -553,7 +545,6 @@ * Parses the HTTP response body * * @param response -* @throws */ function liveclassroom_parse_response($response) { return true; @@ -573,6 +564,7 @@ } /** +* Get the room id from a roomname * @params $roomname * return the room_id from the server */ @@ -597,30 +589,45 @@ $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]); // print $tok1[1]; $result = liveclassroom_parse_line($tok1[0],"class_id="); - // print $result; - return $result; + + // return $result; + + $response = substr($result,0,-1); + // print $response."<br>"; + + return $response; + + //$response = split(" ",$result); + //print $response; + /* $response = trim($result," "); + return $response;*/ } /** * deleteRoom on the server * - * @param roomId - * @throws + * @param roomid : id of the to delete */ - function liveclassroom_api_delete_room($roomId) { + function liveclassroom_api_delete_room($roomid) { global $CFG; global $LIVECLASSROOM_API_ADMIN, $LIVECLASSROOM_API_FUNCTION_DELETE_ROOM; liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_DELETE_ROOM,"&target=$roomid"); - + + if ( $respcode == 302) { + error( "Target not found"); + return false; + } + else if ( $respcode != 100) { + return false; + } return true; } /** - * Open Room on the server + * Open Room on the LC server * - * @param roomId - * @throws + * @param roomid : id of the room to open */ function liveclassroom_api_open_room($roomid) { global $CFG; @@ -631,6 +638,10 @@ preg_match("(\d*)", $data, $matches); $respcode = $matches[0]; + if ( $respcode == 302) { + error( "Target not found"); + return false; + } if ( $respcode != 100) { return false; } @@ -639,10 +650,9 @@ } /** - * Close Room on the server + * Close Room on the LC server * - * @param roomId - * @throws + * @param roomid : id of the room to close */ function liveclassroom_api_close_room($roomid) { global $CFG; @@ -653,12 +663,70 @@ preg_match("(\d*)", $data, $matches); $respcode = $matches[0]; + if ( $respcode == 302) { + error( "Target not found"); + return false; + } if ( $respcode != 100) { return false; } return true; } + + +/** + * Enroll the given user into the group. + * + * @param userid + * @param groupid + */ +function liveclassroom_api_add_user_in_group($userid, $groupid) { + + global $CFG; + global $LIVECLASSROOM_API_ADMIN; + global $LIVECLASSROOM_API_FUNCTION_MODIFY_GROUP; + + $data = liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_MODIFY_GROUP, "&target=$groupid&add_user=$user"); + + if ( $respcode != 100 && $respcode != 301) { + error( "Can't add user from group"); + return false; + } + + return true; +} + /** + * Remove the given user from the group. + * + * @param userif + * @param groupif + */ +function liveclassroom_api_remove_user_from_group($userid, $groupid) { + global $CFG; + global $LIVECLASSROOM_API_ADMIN; + global $LIVECLASSROOM_API_FUNCTION_MODIFY_GROUP; + + $data = liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_MODIFY_GROUP, "&target=$groupid&delete_user=$user"); + + if ( $respcode != 100 && $respcode != 301) { + error( "Can't remove user from group"); + return false; + } + + return true; + +} + +function liveclassroom_api_modify_room($roomid) { + global $CFG; + global $LIVECLASSROOM_API_ADMIN; + global $LIVECLASSROOM_API_FUNCTION_MODIFY_ROOM; + + $data = liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_MODIFY_ROOM, "&target=$groupid&delete_user=$user"); +} + + ?> Modified: trunk/moodle/mod/liveclassroom/index.php =================================================================== --- trunk/moodle/mod/liveclassroom/index.php 2006-08-28 10:02:53 UTC (rev 53) +++ trunk/moodle/mod/liveclassroom/index.php 2006-08-29 15:37:17 UTC (rev 54) @@ -126,7 +126,7 @@ if ($course->format == "weeks" or $course->format == "topics") { if (isteacher($course->id, $USER->id)) { - $table->data[] = array ($liveclassroom->section, $link, $liveclassroom->type, $image1, $image2, $image3, $image4); + $table->data[] = array ($liveclassroom->section, $link, liveclassroom_get_room_name($course,$liveclassroom->type), $image1, $image2, $image3, $image4); } else { $table->data[] = array ($liveclassroom->section, $link, $liveclassroom->type); Modified: trunk/moodle/mod/liveclassroom/lib.php =================================================================== --- trunk/moodle/mod/liveclassroom/lib.php 2006-08-28 10:02:53 UTC (rev 53) +++ trunk/moodle/mod/liveclassroom/lib.php 2006-08-29 15:37:17 UTC (rev 54) @@ -1,4 +1,4 @@ - <?PHP +<?PHP /****************************************************************************** * * * Copyright (c) 1999-2006 Horizon Wimba, All Rights Reserved. * @@ -32,8 +32,8 @@ require_once($CFG->libdir.'/datalib.php'); require_once("api.php"); -require_once("DbException.php"); + //Suffixes used when creting the profiles account on the LC server $LIVECLASSROOM_TEACHER_SUFFIX = "_T"; //Teachers will use the user $CFG->liveclassroom_settinguniqueid + $course->id + $LIVECLASSROOM_TEACHER_SUFFIX $LIVECLASSROOM_STUDENT_SUFFIX = "_S"; //Students will use the user $CFG->liveclassroom_settinguniqueid + $course->id + $LIVECLASSROOM_STUDENT_SUFFIX @@ -63,7 +63,10 @@ return; } - +/* +* Create a new instance of liveclassroom +* @param $liveclassroom : object liveclassroom +*/ function liveclassroom_add_instance($liveclassroom) { /// Given an object containing all the necessary data, /// (defined by the form in mod.html) this function @@ -220,6 +223,8 @@ /** * Create the different kind of room on this course + * call the function create_room for each type of room available for the course given + * @param $course : object course */ function liveclassroom_create_rooms ($course) { @@ -265,7 +270,12 @@ return liveclassroom_api_get_session ($userid, $nickname); } - +/* +* Create a room +* call the function create_class to create the room into the server +* @param $courseid : the id of the course where the room will be created +* @param $roomname : the name of the room +*/ function liveclassroom_create_room ($courseid, $roomname) { global $CFG; global $LIVECLASSROOM_TEACHER_SUFFIX, @@ -338,57 +348,56 @@ */ function liveclassroom_get_list_type_rooms() { - try { - if (!($list = get_records('liveclassroom_type_rooms','course',0) )) { - throw new DbException("Connection to db liveclassroom_type_rooms failed"); - } + if (!($list = get_records('liveclassroom_type_rooms','course',0) )) { + error( "Response get list type room : query to database failed"); + } - - for($i=0;$i<sizeof($list);$i++) { - $list_name[$i] = $list[$i+1]->name; - } - - return $list_name; - - }catch(DbException $e) { - echo $e->getError(); + for($i=0;$i<sizeof($list);$i++) { + $list_name[$i] = $list[$i+1]->name; } + + return $list_name; } + +/* +* Get the list of the rooms per course for a course given +* @param $course : object course +* return a list of the type of the room available for this course +*/ function liveclassroom_get_list_type_rooms_per_course($course) { - try { - if(!($list = get_records('liveclassroom_rooms','course',$course->id))) { - throw new DbException("Connection to db liveclassroom_rooms failed"); - } + if(!($list = get_records('liveclassroom_rooms','course',$course->id))) { + error( "Response get list type room per course : query to database failed"); + } - for($i=0;$i<sizeof($list);$i++) { - $list_name[$i] = $list[$i+1]->name; - } - - return $list_name; - - }catch(DbException $e) { - echo $e->getError(); + for($i=0;$i<sizeof($list);$i++) { + $list_name[$i] = $list[$i+1]->name; } + + return $list_name; } +/* +* Create a new instance of liveclassroom Room +* @param $liveclassroom_rooms : object liveclassroom_rooms +*/ function liveclassroom_rooms_add_instance($liveclassroom_rooms) { $liveclassroom_rooms->timemodified = time(); - - try { - - if(!(insert_record("liveclassroom_rooms", $liveclassroom_rooms))) { - throw new DbException("Insertion to liveclassroom_rooms failed"); - } - } - catch(DbException $e) { - $e->getError(); - } - + + if(!(insert_record("liveclassroom_rooms", $liveclassroom_rooms))) { + error( "Response: creation of new instance failed"); + return false; + } + return true; } + +/* +* Create a new type to liveclassroom Room +* @param $name : the name of the type +*/ function liveclassroom_rooms_add_new_type($name) { $liveclassroom_type_room->timemodified = time(); @@ -396,61 +405,49 @@ $liveclassroom_type_room->course = 0 ; $liveclassroom_type_room->lc_id = 0 ; $liveclassroom_type_room->name = $name ; - - try { - if(!(insert_record("liveclassroom_type_rooms", $liveclassroom_type_room))) { - throw new DbException("Insertion to liveclassroom_type_room failed"); - } - } - catch(DbException $e) { - $e->getError(); - } + + if(!(insert_record("liveclassroom_type_rooms", $liveclassroom_type_room))) { + error( "Response: creation of new type $name failed"); + } } /* * Get the type number of liveclassroom +* @param $liveclassroom : the object liveclassroom +* return the type number of the liveclassroom */ function liveclassroom_get_type($liveclassroom) { - - try { - - if(!($lc = get_record('liveclassroom','id',$liveclassroom->id))) { - throw new DbException("Connection to db liveclassroom failed"); - } - else { - return $lc->type; - } - - } - catch(DbException $e) { - echo $e->getError(); + + if(!($lc = get_record('liveclassroom','id',$liveclassroom->id))) { + error( "Response get type: query to database failed"); } - + else { + return $lc->type; + } } /** -* Give the name of the room for the course +* Give the name of the room for the course and the type given +* @param $course : course +* @param $type : type of the room +* return the name of the room for the course */ function liveclassroom_get_room_name($course,$type) { - - try { - if(!($lc = get_record('liveclassroom_type_rooms','id',$type+1))) { - throw new DbException("Connection to db liveclassroom_type_rooms failed"); - } - else { - $name = $course->shortname; - $typename = $lc->name; - - return $name.'_'.$typename; - } - }catch(DbException $e) { - echo $e->getError(); + + if(!($lc = get_record('liveclassroom_type_rooms','id',$type+1))) { + error( "Response get room name: query to database failed"); + } + else { + $name = $course->shortname; + $typename = $lc->name; + + return $name.'_'.$typename; } } /* * Check if the room exist in the moodle database liveclassroom_rooms -* +* return true if the room exist, false if not. */ function liveclassroom_rooms_exists($liveclassroom) { Modified: trunk/moodle/mod/liveclassroom/view.php =================================================================== --- trunk/moodle/mod/liveclassroom/view.php 2006-08-28 10:02:53 UTC (rev 53) +++ trunk/moodle/mod/liveclassroom/view.php 2006-08-29 15:37:17 UTC (rev 54) @@ -92,14 +92,18 @@ $liveclassroom_rooms->room_id = liveclassroom_api_get_roomid($name); if(!liveclassroom_rooms_add_instance($liveclassroom_rooms)) { return false; - } + } } + +//probleme !! // Create the session fir this user if (!$usersession = liveclassroom_create_session ($course, isteacher($course->id, $USER->id))) { error ("Cannot create session"); } + + /// Print the page header if ($course->category) { @@ -125,6 +129,16 @@ } </script> +<?php + $classid = liveclassroom_api_get_roomid(liveclassroom_get_room_name($course,liveclassroom_get_type($liveclassroom))); + if (isstudent($course->id)) { +?> + <body onload="javascript:startHorizon('<?php p($classid) ?>',null,null,null,null,'hzA=<?php p($usersession)?>' )"> + </body> + +<?php + } + ?> <table style="background-color: #ffffff !important; border-left : 1px solid #999; border-right : 1px solid #999; border-top : 1px solid #999;border-bottom : 1px solid #999;" width="100%" cellspacing="0" cellpadding="0" border="0" align="center" summary="layout"> <tr style="background-color:#EEEEEE; font-weight:normal; color:black;"> @@ -141,7 +155,8 @@ </td></tr> <tr> <td> - <a href="javascript:startHorizon(null,null,null,null,null,'hzA=<?php p($usersession)?>')"> + <a href="javascript:startHorizon('<?php p($classid) ?>',null,null,null,null,'hzA=<?php p($usersession)?>')"> + <?php p(get_string("accessrooms", 'liveclassroom')) ?> </a> </td> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |