[Hw4mdl-svn] SF.net SVN: hw4mdl: [86] trunk/moodle/mod/liveclassroom/api.php
Brought to you by:
jhlinder,
trollinger
|
From: <sh...@us...> - 2006-10-13 13:48:14
|
Revision: 86
http://svn.sourceforge.net/hw4mdl/?rev=86&view=rev
Author: shazan
Date: 2006-10-13 06:48:08 -0700 (Fri, 13 Oct 2006)
Log Message:
-----------
authenticate system every 30 minutes
Modified Paths:
--------------
trunk/moodle/mod/liveclassroom/api.php
Modified: trunk/moodle/mod/liveclassroom/api.php
===================================================================
--- trunk/moodle/mod/liveclassroom/api.php 2006-10-13 12:41:52 UTC (rev 85)
+++ trunk/moodle/mod/liveclassroom/api.php 2006-10-13 13:48:08 UTC (rev 86)
@@ -64,6 +64,7 @@
$LIVECLASSROOM_API_RECORD_SEPERATOR = "=END RECORD";
+session_start();
/**
@@ -102,17 +103,18 @@
//add_to_log("", "liveclassroom", "", "liveclassroom_api_authenticate", "URL Sent: $url");
//add_to_log("", "liveclassroom", "", "", "Creating Auth Cookie in: ".dirname(__FILE__).'/cookie.txt');
+
+ $cookie_file_path = $CFG->dirroot.'/mod/liveclassroom/tmp/cookie.txt'; // Cookie File path
-
-
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
- curl_setopt($ch, CURLOPT_COOKIEJAR, System::mktemp("lc"));
+ curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
- #print_r $data;
+
if (curl_errno($ch)) {
print curl_error($ch);
return false;
@@ -126,9 +128,56 @@
}
return $ch;
+
}
+ /**
+ * Send a query to the server with the given function and the given attributes
+ * Check if the session cookie exist and get the cookie creation date.
+ * If it's less than 30 minutes, the cookie is got for the request, if not a new authenticate is done.
+ * @param $const : function called
+ * @param $attribute : different list of attributes for the function called
+ * return $data : result query
+ */
+ function liveclassroom_api_send_query($const,$attribute) {
+ global $CFG;
+ global $LIVECLASSROOM_API_ADMIN;
+ $cookie_file_path = $CFG->dirroot.'/mod/liveclassroom/tmp/cookie.txt'; //Cookie File path
+
+ $currentTime = time();
+
+ if( (!file_exists($cookie_file_path)) || ($currentTime > (time(filemtime($cookie_file_path))+1800)) ){
+ if (!$ch = liveclassroom_api_authenticate()) {
+ return false;
+ }
+ }
+
+ $url = $CFG->liveclassroom_servername.
+ $LIVECLASSROOM_API_ADMIN.
+ $const.
+ $attribute;
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL,$url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 4);
+ curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+
+ $data = curl_exec($ch);
+
+ if (curl_errno($ch)) {
+ print curl_error($ch);
+ return false;
+ }
+
+ return $data;
+ }
+
+
+
+
/**
* Create the Live Classroom User $user with the role $rolename. This function
* actually creates profiles that will further be used for teacher/student
@@ -192,8 +241,6 @@
}
-
-
/**
* Returns a session id (hzA) to be inserted in URLs to access the LC server
@@ -210,29 +257,8 @@
global $LIVECLASSROOM_API_ADMIN;
global $LIVECLASSROOM_API_FUNCTION_GET_TOKEN;
- if (!$ch = liveclassroom_api_authenticate()) {
- return false;
- }
+ $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_TOKEN, "&target=$userid&nickname=$nickname");
- $url = $CFG->liveclassroom_servername.
- $LIVECLASSROOM_API_ADMIN.
- $LIVECLASSROOM_API_FUNCTION_GET_TOKEN.
- "&target=$userid".
- "&nickname=$nickname";
-
- //DEBUG
- //add_to_log("", "liveclassroom", "", "liveclassroom_api_get_session", "URL Sent: $url");
-
- curl_setopt($ch, CURLOPT_URL,$url);
- $data = curl_exec($ch);
-
- //DEBUG
- //add_to_log("", "liveclassroom", "", "liveclassroom_api_get_session", "DATA: <pre>$data</pre>");
- if (curl_errno($ch)) {
- print curl_error($ch);
- return false;
- }
-
preg_match("(\d*)", $data, $matches);
$respcode = $matches[0];
@@ -306,32 +332,9 @@
$LIVECLASSROOM_API_FUNCTION_CREATE_ROLE;
- // liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_CREATE_ROLE,"&target=$roomid&user_id=$userid&role_id=$role");
-
- if (!$ch = liveclassroom_api_authenticate()) {
- return false;
- }
+ $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_CREATE_ROLE, "&target=$roomid&user_id=$userid&role_id=$role");
- $url = $CFG->liveclassroom_servername.
- $LIVECLASSROOM_API_ADMIN.
- $LIVECLASSROOM_API_FUNCTION_CREATE_ROLE.
- "&target=$roomid".
- "&user_id=$userid".
- "&role_id=$role";
-
- //DEBUG
- //add_to_log("", "liveclassroom", "", "liveclassroom_api_add_user_role", "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];
@@ -350,30 +353,9 @@
$LIVECLASSROOM_API_FUNCTION_DELETE_ROLE;
- if (!$ch = liveclassroom_api_authenticate()) {
- return false;
- }
+ $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_DELETE_ROLE, "&target=$roomid&user_id=$userid&role_id=$role");
- $url = $CFG->liveclassroom_servername.
- $LIVECLASSROOM_API_ADMIN.
- $LIVECLASSROOM_API_FUNCTION_DELETE_ROLE.
- "&target=$roomid".
- "&user_id=$userid".
- "&role_id=$role";
- //DEBUG
- //add_to_log("", "liveclassroom", "", "liveclassroom_api_remove_user_role", "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];
@@ -389,30 +371,9 @@
global $LIVECLASSROOM_API_ADMIN,
$LIVECLASSROOM_API_FUNCTION_DELETE_ROLE;
- if (!$ch = liveclassroom_api_authenticate()) {
- return false;
- }
+ $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_DELETE_ROLE, "&target=$roomid&user_id=$groupid&role_id=$role");
- $url = $CFG->liveclassroom_servername.
- $LIVECLASSROOM_API_ADMIN.
- $LIVECLASSROOM_API_FUNCTION_DELETE_ROLE.
- "&target=$roomid".
- "&group_id=$groupid".
- "&role_id=$role";
- //DEBUG
- // add_to_log("", "liveclassroom", "", "liveclassroom_api_remove_group_role", "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];
@@ -423,96 +384,7 @@
return true;
}
-/**
- * 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 role Optional role to filter by
- * @param roomid
- * @return
- */
- function liveclassroom_api_get_room_list($userid,$course) {
-
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN,
- $LIVECLASSROOM_API_RECORD_SEPERATOR,
- $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
-
- $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST,"&attribute=class_id&attribute=preview&attribute=longname&filter00=archive&filter00value=0&AccessUser=$userid");
-
- $studentuserid = liveclassroom_api_get_student_user_id($course->shortname);
-// $studentuserid = "_moodle_hgh_S";
- //add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_listp", "apres get student user id".time());
- preg_match("(\d*)", $data, $matches);
- $respcode = $matches[0];
-
- if ( $respcode != 100) {
- return false;
- }
- // print $data."<br>";
-
- $line = explode("\n",$data);
- $j=0;
- $k=0;
- // $line = strtok($data,"\n");
- // while (!empty($currentline) ) {
- // $currentline = strtok("\n");
- // }
-
- for($i=1;$i<sizeof($line)-3;$i=$i+4){
- //add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_list", "boucle".time());
- if(liveclassroom_api_role_user_room(liveclassroom_parse_line($line[$i+1],"class_id="), $studentuserid)=='Student') { //lecture room
- // add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_list", "boucle".time());
- $table_result[0][$j]= liveclassroom_parse_line($line[$i+1],"class_id=");
- //add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_list", "boucle2".$table_result[0][$j].time());
- $table_result[0][$j+1]= liveclassroom_parse_line($line[$i],"preview=");
- $table_result[0][$j+2]= liveclassroom_parse_line($line[$i+2],"longname=");
- $j = $j+3;
- }
- else {
- $table_result[1][$k]= liveclassroom_parse_line($line[$i+1],"class_id=");
- $table_result[1][$k+1]= liveclassroom_parse_line($line[$i],"preview=");
- $table_result[1][$k+2]= liveclassroom_parse_line($line[$i+2],"longname=");
- $k = $k+3;
- }
-
- }
- /*
- $i=0;
- $j=0;
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
- //add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_listp", "avant la boucle".time());
- foreach($tok1 as $tok1value) {
- //add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_listp", "1ere boucle".time());
- $line = explode("\n",$tok1value);
- foreach ($line as $line_value) {
- //add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_listp", "2eme boucle".time());
- $result = explode("=",$line_value);
- $room_table[$result[0]]=$result[1];
-
- if(liveclassroom_api_role_user_room($room_table['class_id'], $studentuserid)=='Student') { //lecture room
- $table_result[0][$i] = $room_table;
- add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_listp", $room_table['class_id']." ".time());
- $i++;
- }
- else { //breakout room
- $table_result[1][$j] = $room_table;
- add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_listp", $room_table['class_id']." ".time());
- $j++;
- }
- //$table_result[$i]=$result[1];
- // print $table_result[$i];
- // $i++;
- // add_to_log("", "liveclassroom", "", "liveclassroom_api_get_infos_room", $result[0]."=".$room_table[$result[0]] );
- }
- }
- */
- return $table_result;
-
- }
/**
@@ -550,55 +422,8 @@
}
- /**
- * 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($const,$attribute) {
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN;
-
- if (!$ch = liveclassroom_api_authenticate()) {
- return false;
- }
- $url = $CFG->liveclassroom_servername.
- $LIVECLASSROOM_API_ADMIN.
- $const.
- $attribute;
-
- curl_setopt($ch, CURLOPT_URL,$url);
- $data = curl_exec($ch);
-
- if (curl_errno($ch)) {
- print curl_error($ch);
- return false;
- }
-
- return $data;
- }
-
- function liveclassroom_api_set_query_attribute($query,$attribute) {
-
- }
-
- function liveclassroom_api_set_query_filter($query) {
-
- }
-
-/**
-* Parses the HTTP response body
-*
-* @param response
-*/
-function liveclassroom_parse_response($response) {
- return true;
-}
-
/**
*
* return a string delimited by the pattern and the end of line
@@ -794,24 +619,7 @@
}
}
- /*
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
- $j=0;
- foreach ($tok1 as $tok1_value) {
- //for($i=0;$i<sizeof($tok1);$i++) {
- // $test = strstr($tok1[$i],$roomid);
- $test = strstr($tok1_value,$roomid);
- if($test!=false){
- // print "yrr";
- // $result = liveclassroom_parse_line($tok1[$i],"class_id=");
- //Remove le " " at the end of the line
- $response = substr($test,0,-1);
- $list_return[$j]=$response;
- $j++;
- }
- }
- */
+
return $list_return;
}
@@ -960,15 +768,7 @@
return $result;
-/*
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
- $result = liveclassroom_parse_line($tok1[0],"user_id=");
- //Remove le " " at the end of the line
- $response = substr($result,0,-1);
-
- return $response;
-*/
+
}
@@ -1039,90 +839,11 @@
else return false;
}
-/*
-function liveclassroom_api_room_is_archive ($roomid){
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN;
- global $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
- global $LIVECLASSROOM_API_RECORD_SEPERATOR;
- $data = liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST, "&filter00=class_id&filter00value=$roomid&filter01=archive&filter01value=1");
-
- preg_match("(\d*)", $data, $matches);
- $respcode = $matches[0];
-
- if ( $respcode != 100) {
- return false;
- }
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
- if(sizeof($tok1)>1){
- return true;
- }
- else {
- return false;
- }
-}*/
/*
-* List all the orphaned archive on the server
-* NEED TO BE TESTED !!!!
-*/
-
-function liveclassroom_api_get_orphaned_archive_list() {
-
- $tab_archive = liveclassroom_api_get_archive_list() ;
-
-
- //liste des archive
- //si ya une class id on la prend pas
-
- $j=0;
-
- for($i=0;$i<sizeof($tab_archive);$i++) {
- if ($tok[$i]!=null) {
- //tester les room
- $list_return[$j]=$tok[$i];
- }
- }
- print $data;
- return $list_return;
-}
-
-/*
-* Give the description of he room given
-* @param $roomid : the id of the room
-* return a String :description of the room
-*/
-function liveclassroom_api_get_room_description($roomid){
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN;
- global $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
- global $LIVECLASSROOM_API_RECORD_SEPERATOR;
-
- $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST, "&attribute=description&filter00=class_id&filter00value=$roomid");
-
- preg_match("(\d*)", $data, $matches);
- $respcode = $matches[0];
-
- if ( $respcode != 100) {
- return false;
- }
- print $url;
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
-
- $tok2 = split("class_id=",$tok1[0]);
- $result = liveclassroom_parse_line($tok2[0],"description=");
- //Remove le " " at the end of the line
- $response = substr($result,0,-1);
-
- return $response;
-
-}
-/*
* Give the nam of the room given
* @param $roomid : the id of the room
* return a String :name of the room
@@ -1190,79 +911,8 @@
}
-/*
-*
-* @param $roomid : the id of the room
-* return a boolean :true if hms two way is enabled, false if not
-*/
-function liveclassroom_api_room_is_hmstwoway_enabled($roomid){
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN;
- global $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
- global $LIVECLASSROOM_API_RECORD_SEPERATOR;
-
- $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST, "&attribute=hms_two_way_enabled&filter00=class_id&filter00value=$roomid");
-
- preg_match("(\d*)", $data, $matches);
- $respcode = $matches[0];
-
- if ( $respcode != 100) {
- return false;
- }
- //print $url;
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
-
- $test = strstr($tok1[0],"hms_two_way_enabled=");
-
- //$tok2 = split("class_id=",$tok1[0]);
- $result = liveclassroom_parse_line($test,"hms_two_way_enabled=");
- //Remove le " " at the end of the line
- $response = substr($result,0,-1);
-
- if($response==1) {
- return true;
- }
- else return false;
-}
-/*
-*
-* @param $roomid : the id of the room
-* return a boolean :true if hms Simulcat is restricted, false if not
-*/
-function liveclassroom_api_room_is_hmsSimulcast_restricted($roomid){
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN;
- global $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
- global $LIVECLASSROOM_API_RECORD_SEPERATOR;
-
- $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST, "&attribute=hms_simulcast_restricted&filter00=class_id&filter00value=$roomid");
-
- preg_match("(\d*)", $data, $matches);
- $respcode = $matches[0];
-
- if ( $respcode != 100) {
- return false;
- }
- //print $url;
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
-
- $test = strstr($tok1[0],"hms_simulcast_restricted=");
-
- //$tok2 = split("class_id=",$tok1[0]);
- $result = liveclassroom_parse_line($test,"hms_simulcast_restricted=");
- //Remove le " " at the end of the line
- $response = substr($result,0,-1);
-
- if($response==1) {
- return true;
- }
- else return false;
-}
-
/*
* Get the number of user limit of the room given
* @param $roomid : the id of the room
@@ -1296,229 +946,11 @@
}
-/*
-* To know if a room enable private chat
-* @param $roomid : the id of the room
-* return a boolean : true is private chat is enabled, false if not
-*/
-function liveclassroom_api_is_private_chat_enabled($roomid){
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN;
- global $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
- global $LIVECLASSROOM_API_RECORD_SEPERATOR;
-
- $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST, "&attribute=privatechatenable&filter00=class_id&filter00value=$roomid");
-
- preg_match("(\d*)", $data, $matches);
- $respcode = $matches[0];
-
- if ( $respcode != 100) {
- return false;
- }
- //print $url;
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
-
- $test = strstr($tok1[0],"privatechatenable=");
-
- //$tok2 = split("class_id=",$tok1[0]);
- $result = liveclassroom_parse_line($test,"privatechatenable=");
- //Remove le " " at the end of the line
- $response = substr($result,0,-1);
-
- if($response==1) {
- return true;
- }
- else return false;
-}
-/*
-* To know if a room enable powerpoint import
-* @param $roomid : the id of the room
-* return a boolean : true is powerpoint import is enabled, false if not
-*/
-function liveclassroom_api_is_ppt_import_enabled($roomid){
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN;
- global $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
- global $LIVECLASSROOM_API_RECORD_SEPERATOR;
-
- $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST, "&attribute=can_ppt_import&filter00=class_id&filter00value=$roomid");
-
- preg_match("(\d*)", $data, $matches);
- $respcode = $matches[0];
-
- if ( $respcode != 100) {
- return false;
- }
- //print $url;
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
-
- $test = strstr($tok1[0],"can_ppt_import=");
-
- //$tok2 = split("class_id=",$tok1[0]);
- $result = liveclassroom_parse_line($test,"can_ppt_import=");
- //Remove le " " at the end of the line
- $response = substr($result,0,-1);
-
- if($response==1) {
- return true;
- }
- else return false;
-}
/*
-* To know if a room enable Application Sharing
-* @param $roomid : the id of the room
-* return a boolean : true is Application Sharing is enabled, false if not
-*/
-function liveclassroom_api_is_liveshare_enabled($roomid){
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN;
- global $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
- global $LIVECLASSROOM_API_RECORD_SEPERATOR;
-
- $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST, "&attribute=can_liveshare&filter00=class_id&filter00value=$roomid");
-
- preg_match("(\d*)", $data, $matches);
- $respcode = $matches[0];
-
- if ( $respcode != 100) {
- return false;
- }
- //print $url;
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
-
- $test = strstr($tok1[0],"can_liveshare=");
-
- //$tok2 = split("class_id=",$tok1[0]);
- $result = liveclassroom_parse_line($test,"can_liveshare=");
- //Remove le " " at the end of the line
- $response = substr($result,0,-1);
-
- if($response==1) {
- return true;
- }
- else return false;
-
-}
-
-/*
-* To know if a room enable archive
-* @param $roomid : the id of the room
-* return a boolean : true is archive is enabled, false if not
-*/
-function liveclassroom_api_is_archive_enabled($roomid){
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN;
- global $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
- global $LIVECLASSROOM_API_RECORD_SEPERATOR;
-
- $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST, "&attribute=can_archive&filter00=class_id&filter00value=$roomid");
-
- preg_match("(\d*)", $data, $matches);
- $respcode = $matches[0];
-
- if ( $respcode != 100) {
- return false;
- }
- //print $url;
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
-
- $test = strstr($tok1[0],"can_archive=");
-
- //$tok2 = split("class_id=",$tok1[0]);
- $result = liveclassroom_parse_line($test,"can_archive=");
- //Remove le " " at the end of the line
- $response = substr($result,0,-1);
-
- if($response==1) {
- return true;
- }
- else return false;
-
-}
-
-/*
-* To know if a room allow students to use the liveApp plugin tool on the whiteboard
-* @param $roomid : the id of the room
-* return a boolean : true is students can use theliveApp plugin tool, false if not
-*/
-function liveclassroom_api_is_student_liveApp_enabled($roomid){
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN;
- global $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
- global $LIVECLASSROOM_API_RECORD_SEPERATOR;
-
- $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST, "&attribute=student-wb-liveapp&filter00=class_id&filter00value=$roomid");
-
- preg_match("(\d*)", $data, $matches);
- $respcode = $matches[0];
-
- if ( $respcode != 100) {
- return false;
- }
- //print $url;
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
-
- $test = strstr($tok1[0],"student-wb-liveapp=");
-
- //$tok2 = split("class_id=",$tok1[0]);
- $result = liveclassroom_parse_line($test,"student-wb-liveapp=");
- //Remove le " " at the end of the line
- $response = substr($result,0,-1);
-
- if($response==1) {
- return true;
- }
- else return false;
-
-}
-
-/*
-* To know if a room enable all students to use the whiteboard tools
-* @param $roomid : the id of the room
-* return a boolean : true is students can use the whiteboard tools, false if not
-*/
-function liveclassroom_api_is_student_whiteBoard_enabled($roomid){
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN;
- global $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
- global $LIVECLASSROOM_API_RECORD_SEPERATOR;
-
- $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST, "&attribute=student-wb-enabled&filter00=class_id&filter00value=$roomid");
-
- preg_match("(\d*)", $data, $matches);
- $respcode = $matches[0];
-
- if ( $respcode != 100) {
- return false;
- }
- //print $url;
- $tok = split("100 OK",$data);
- $tok1 = split($LIVECLASSROOM_API_RECORD_SEPERATOR,$tok[1]);
-
- $test = strstr($tok1[0],"student-wb-enabled=");
-
- //$tok2 = split("class_id=",$tok1[0]);
- $result = liveclassroom_parse_line($test,"student-wb-enabled=");
- //Remove le " " at the end of the line
- $response = substr($result,0,-1);
-
- if($response==1) {
- return true;
- }
- else return false;
-
-}
-
-/*
* Give the information about a room given
* @param $roomid : the id of the room
* return a table with the key as the name of the attribute
@@ -1630,27 +1062,32 @@
return true;
}*/
-/*
-function ($roomname) {
- global $CFG;
- global $LIVECLASSROOM_API_ADMIN,
- $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
- $data = liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST,"&filter00=longname&filter00value=$roomname");
+function liveclassroom_api_get_room_list($userid,$course) {
+
+ global $CFG;
+ global $LIVECLASSROOM_API_ADMIN,
+ $LIVECLASSROOM_API_RECORD_SEPERATOR,
+ $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
+ $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST,"&attribute=class_id&attribute=longname&filter00=archive&filter00value=0&AccessUser=$userid");
+
preg_match("(\d*)", $data, $matches);
$respcode = $matches[0];
if ( $respcode != 100) {
return false;
}
- return $list;
+ $line = explode("\n",$data);
+ $rooms=array();
+ for($i=1;$i<sizeof($line)-2;$i=$i+3){
+ $room[0] = liveclassroom_parse_line($line[$i],"class_id="); //class_id
+ $room[1]= liveclassroom_parse_line($line[$i+1],"longname="); //longname
+ array_push($rooms,$room);
+ }
+ return $rooms;
}
-*/
-
-
-
/*
* List all the rooms and their archives associed + the orphaned archives list
*
@@ -1667,7 +1104,7 @@
global $CFG;
global $LIVECLASSROOM_API_ADMIN,
$LIVECLASSROOM_API_RECORD_SEPERATOR,
- $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
+ $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
$data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST,"&attribute=class_id&attribute=preview&attribute=longname&attribute=archive&AccessUser=$userid");
@@ -1738,20 +1175,29 @@
return $table_result;
}
-
-function liveclassroom_create_xml() {
-
- global $CFG;
+
+/*
+* List all the rooms and their archives associed + the orphaned archives list
+*
+* @param $userid : the user id of the current user
+* @param $course : the current course
+*
+* Return a table composed of 3 parts:
+* - an xml string who list all the lecture rooms and their archives associed
+* - an xml string who list all the breakout rooms and their archives associed
+**/
+function liveclassroom_create_xml($userid,$course) {
+
+ global $CFG;
global $LIVECLASSROOM_API_ADMIN,
$LIVECLASSROOM_API_RECORD_SEPERATOR,
- $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
+ $LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST;
+ // add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_list", "avant send data ".time());
+ $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST,"&attribute=class_id&attribute=preview&attribute=longname&filter01=archive&filter01value=0&AccessUser=$userid");
+ // add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_list", "apres send data ".time());
- // Cr\xE9ation d'un nouvel objet document
- $doc = new DOMDocument('1.0', 'ISO-8859-1');
-
- $data = liveclassroom_api_send_query($LIVECLASSROOM_API_FUNCTION_GET_ROOM_LIST,"&attribute=class_id&attribute=preview&attribute=longname&attribute=archive&AccessUser=$userid");
-
$studentuserid = liveclassroom_api_get_student_user_id($course->shortname);
+
preg_match("(\d*)", $data, $matches);
$respcode = $matches[0];
@@ -1759,82 +1205,88 @@
return false;
}
- $line = explode("\n",$data);
+
+ $lecturerooms = '<?xml version=1.0 ?>';
+ $breakoutrooms= '<?xml version=1.0 ?>';
+
+ $lecturerooms .= '<root><rooms>';
+ $breakoutrooms .= '<root><rooms>';
+ $line = explode("\n",$data);
+
$tabarchive = array();
- $orphanedarchives = array();
- $rooms=array(); //lecture rooms table
- $rooms1=array();//breakout rooms table
-
- for($i=1;$i<sizeof($line)-4;$i=$i+5){
- if((liveclassroom_parse_line($line[$i+3],"archive=")!=1)){ // it is a room
+ for($i=1;$i<sizeof($line)-3;$i=$i+4){
- $room[0] = liveclassroom_parse_line($line[$i+1],"class_id="); //class_id
- $room[1]= liveclassroom_parse_line($line[$i+2],"longname="); //longname
- $room[2]= liveclassroom_parse_line($line[$i],"preview="); //preview
- $room[3]= array();
-
- if(liveclassroom_api_role_user_room($room[0], $studentuserid)=='Student') { //lecture room
+ $room[0]= liveclassroom_parse_line($line[$i+1],"class_id="); //class_id
+ $room[1]= liveclassroom_parse_line($line[$i+2],"longname="); //longname
+ $room[2]= liveclassroom_parse_line($line[$i],"preview="); //preview
- $rooms[$room[0]]=$room;
-
- }
- else { //Breakout room
-
- $rooms1[$room[0]]=$room;
- }
-
- }
- else { // it is an archive
+ if(liveclassroom_api_role_user_room($room[0], $studentuserid)=='Student') { //lecture room
+
+ $lecturerooms .='<room>';
+ $lecturerooms .='<id>'.$room[0].'</id>';
+ $lecturerooms .='<longname>'.$room[1].'</longname>';
+ $lecturerooms .='<preview>'.$room[2].'</preview>';
- $archiveid=liveclassroom_parse_line($line[$i+1],"class_id=");// larchive id
- $roomid = substr($archiveid,0,strlen($archiveid)-18);//room id
+ $tabarchive = liveclassroom_api_get_archive_list_for_a_room($room[0],$userid);
+
+ if(sizeof($tabarchive)>0){ //archives
+ add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_list", "archive ".time());
+ $lecturerooms .='<archives>';
+ // for($j=0;$j<sizeof($tabarchive);$j++){
- $archive=array();
- $archive[0]=$archiveid;
- $archive[1]=liveclassroom_parse_line($line[$i+2],"longname="); //longname
- $archive[2]=liveclassroom_parse_line($line[$i],"preview=");
- $archive[3]=$roomid; //preview
- array_push($tabarchive,$archive);
+ foreach ($tabarchive as $archive) {
+ $lecturerooms .='<archive>';
+ $lecturerooms .='<id>'.$archive[1].'</id>';
+ $lecturerooms .='<longname>'.$archive[2].'</longname>';
+ $lecturerooms .='<preview>'.$archive[0].'</preview>';
+ $lecturerooms .='</archive>';
+ }
+ $lecturerooms .='</archives>';
+ }
+ $lecturerooms .='</room>';
}
- }
- foreach($tabarchive as $value) {
- if (array_key_exists($value[3],$rooms)) { //lecture room table
- array_push($rooms[$value[3]][3],$value);
- }
- else if (array_key_exists($value[3],$rooms1)) { //breakout room table
- array_push($rooms1[$value[3]][3],$value);
- }
- else { //orphaned archive
- array_push($orphanedarchives,$value);
- }
- }
+ else { //Breakout room
+
+ $breakoutrooms .='<room>';
+ $breakoutrooms .='<id>'.$room[0].'</id>';
+ $breakoutrooms .='<longname>'.$room[1].'</longname>';
+ $breakoutrooms .='<preview>'.$room[2].'</preview>';
+ // add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_list", "before archivze liste ".time());
+ $tabarchive = liveclassroom_api_get_archive_list_for_a_room($room[0],$userid);
+ // add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_list", "after archivze liste ".time());
+ if(sizeof($tabarchive)>0){ //archives
+ //add_to_log("", "liveclassroom", "", "liveclassroom_api_get_room_list", "archive ".time());
+ $breakoutrooms .='<archives>';
+ foreach ($tabarchive as $archive) {
+ $breakoutrooms .='<archive>';
+ $breakoutrooms .='<id>'.$archive[1].'</id>';
+ $breakoutrooms .='<longname>'.$archive[2].'</longname>';
+ $breakoutrooms .='<preview>'.$archive[0].'</preview>';
+ $breakoutrooms .='</archive>';
+ }
+ $breakoutrooms .='</archives>';
+ }
+
+ $breakoutrooms .='</room>';
+ }
- $table_result[0]=$rooms;
- $table_result[1]=$rooms1;
- $table_result[2]=$orphanedarchives;
-
-
-
-
+ }
+ $lecturerooms .= '</rooms></root>';
+ $breakoutrooms .= '</rooms></root>';
- $xml = '<racine><element>texte</element></racine>';
- $doc->loadXML($xml);
- // Cr\xE9ation de l'\xE9l\xE9ment racine
- $root = $dom->createElement($xmlObject->root->name);
- $dom->appendChild($root);
+ add_to_log($course->id, "liveclassroom", "view", "liveclassroom_create_xml", "after");
- // appel d'une fonction r\xE9cursive qui construit l'\xE9l\xE9ment XML
- // \xE0 partir de l'objet, en parcourant tout l'arbre de l'objet.
- setElement($dom, $xmlObject->root, $root);
+ $table_result[0]=$lecturerooms;
+ $table_result[1]=$breakoutrooms;
+
- // Mise \xE0 jour du fichier source original
- $dom->save($xmlObject->source);
- echo $xmlObject->source;
+ return $table_result;
+
}
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|