[Hw4mdl-svn] SF.net SVN: hw4mdl: [11] trunk/moodle/mod/liveclassroom
Brought to you by:
jhlinder,
trollinger
From: <hu...@us...> - 2006-05-04 20:21:08
|
Revision: 11 Author: hugues Date: 2006-05-04 13:20:58 -0700 (Thu, 04 May 2006) ViewCVS: http://svn.sourceforge.net/hw4mdl/?rev=11&view=rev Log Message: ----------- - Fixed the cookie bug (I think) as it's creating it's own temporary file - Fixed a problem when clicking on exit in the admin tools - Implemented a validation of the parameters in the config page Modified Paths: -------------- trunk/moodle/mod/liveclassroom/api.php trunk/moodle/mod/liveclassroom/config.html 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-04-21 19:35:50 UTC (rev 10) +++ trunk/moodle/mod/liveclassroom/api.php 2006-05-04 20:20:58 UTC (rev 11) @@ -1,7 +1,18 @@ <?PHP -// This is the API to authenticate and perform transactions with the Live cLassroom server -// All functions here should start with liveclassroom_api_ +/** + * api.php - Sets up sessions, connects to LC server and so on + * + * This is the API to authenticate and perform transactions with the Live cLassroom server + * All functions here should start with liveclassroom_api_ + * + * Normally this is only called by liveclassroom *lib.php files + * @author Hugues Pisapia + * @version $Revision:$ + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package liveclassroom + */ +require_once('System.php'); $LIVECLASSROOM_API_ADMIN = '/admin/api/api.pl?'; $LIVECLASSROOM_API_FUNCTION_NOOP = 'function=NOOP'; @@ -12,34 +23,54 @@ $LIVECLASSROOM_API_FUNCTION_DELETE_ROLE = 'function=deleteRole'; -// Creates a CURL session with the liveclassroom server -// It returns the CURL handle incase of success, false otherwise. -function liveclassroom_api_authenticate () { + +/** + * Creates a CURL session with the Live Classroom server. Upon success, it + * returns a CURL Handle authenticated and ready for use. It returns false + * otherwise. + * + * If the $servername param is the empty string, the function will collect + * the data from $CFG->liveclassroom_* + * + * @param string $servername + * @param string $login + * @param string $password + * @return object - a CURL Handle authenticated and ready for use, false otherwise + * @uses CFG, LIVECLASSROOM_API_ADMIN, LIVECLASSROOM_API_FUNCTION_NOOP + */ +function liveclassroom_api_authenticate ($servername='', $login='', $passwd='') { global $CFG; global $LIVECLASSROOM_API_ADMIN; global $LIVECLASSROOM_API_FUNCTION_NOOP; + + if (empty($servername)) { // feed them with $CFG + $servername = $CFG->liveclassroom_servername; + $login = $CFG->liveclassroom_adminusername; + $passwd = $CFG->liveclassroom_adminpassword; + } - $url = $CFG->liveclassroom_servername. + $url = $servername. $LIVECLASSROOM_API_ADMIN. $LIVECLASSROOM_API_FUNCTION_NOOP. "&AuthType=AuthCookieHandler". "&AuthName=Horizon". - "&credential_0=". $CFG->liveclassroom_adminusername. - "&credential_1=". $CFG->liveclassroom_adminpassword; + "&credential_0=". $login. + "&credential_1=". $passwd; //add_to_log("", "liveclassroom", "", "liveclassroom_api_authenticate", "URL Sent: $url"); //add_to_log("", "liveclassroom", "", "", "Creating Auth Cookie in: ".dirname(__FILE__).'/cookie.txt'); + + $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, dirname(__FILE__).'/cookie.txt'); # XXX: cookiejar needs to be configurable? + curl_setopt($ch, CURLOPT_COOKIEJAR, System::mktemp("lc")); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); - #curl_setopt($ch, CURLOPT_HEADER, 1); $data = curl_exec($ch); - #print $data; + #print_r $data; if (curl_errno($ch)) { print curl_error($ch); return false; @@ -48,7 +79,7 @@ $resp_code = $matches[0]; if ( $resp_code != 100 && $resp_code != 301) { - error( "Response: Authentication Failed: $resp_code"); + //error( "Response: Authentication Failed: $resp_code"); return false; } @@ -56,10 +87,18 @@ } +/** + * Create the Live Classroom User $user with the role $rolename. This function + * actually creates profiles that will further be used for teacher/student + * roles. + * + * @uses CFG, LIVECLASSROOM_API_ADMIN, LIVECLASSROOM_API_FUNCTION_CREATE_USER + * @param $userid string - LC login for this profile + * @param $coursename string - LC first name for this profile. We use the couse name + * @param $rolename string - LC lastname of this profile. Usually 'Teacher' or 'Student' + * @return bool - true if the user is successfuly created, false otherwise + */ function liveclassroom_api_create_user ($userid, $coursename, $rolename) { -// Creating users as per design recommendations in -// http://wiki.horizonwimba.com/wiki/index.php/LC_Integration_Design_Guidelines#Click_on_Live_Classroom_tool_link -// global $CFG; global $LIVECLASSROOM_API_ADMIN; global $LIVECLASSROOM_API_FUNCTION_CREATE_USER; @@ -97,9 +136,16 @@ return true; } +/** + * Returns a session id (hzA) to be inserted in URLs to access the LC server + * @uses CFG, USER + * @uses LIVECLASSROOM_API_ADMIN, LIVECLASSROOM_API_FUNCTION_GET_TOKEN + * @param $userid string - the userid/login of the profile to be used + * @param $nickname string - the name of the user that will be displayed in the LC + * @return string - the session token (hzA) if the request was successful, + * false otherwise. + */ function liveclassroom_api_get_session ($userid, $nickname) { - // Returns a session id (token) for this userId - // global $CFG; global $USER; global $LIVECLASSROOM_API_ADMIN; Modified: trunk/moodle/mod/liveclassroom/config.html =================================================================== --- trunk/moodle/mod/liveclassroom/config.html 2006-04-21 19:35:50 UTC (rev 10) +++ trunk/moodle/mod/liveclassroom/config.html 2006-05-04 20:20:58 UTC (rev 11) @@ -1,5 +1,6 @@ <form method="post" action="module.php" name="form"> <input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>"> +<input type="hidden" name="module" value="liveclassroom"> <table cellpadding="9" cellspacing="0" > @@ -13,7 +14,7 @@ <tr valign="top"> <td align="right"><?php print_string('servername', 'liveclassroom')?>:</td> <td> - <input name="liveclassroom_servername" type="text" size="30" value="<?php p($CFG->liveclassroom_servername) ?>" /> + <input name="servername" type="text" size="30" value="<?php p($CFG->liveclassroom_servername) ?>" /> </td> <td> <?php print_string("configservername", "liveclassroom") ?> @@ -22,7 +23,7 @@ <tr valign="top"> <td align="right"><?php print_string('adminusername', 'liveclassroom')?>:</td> <td> - <input name="liveclassroom_adminusername" type="text" size="20" value="<?php p($CFG->liveclassroom_adminusername) ?>" /> + <input name="adminusername" type="text" size="20" value="<?php p($CFG->liveclassroom_adminusername) ?>" /> </td> <td> <?php print_string("configadminusername", "liveclassroom") ?> @@ -31,7 +32,7 @@ <tr valign="top"> <td align="right"><?php print_string('adminpassword', 'liveclassroom')?>:</td> <td> - <input name="liveclassroom_adminpassword" type="text" size="20" value="<?php p($CFG->liveclassroom_adminpassword) ?>" /> + <input name="adminpassword" type="text" size="20" value="<?php p($CFG->liveclassroom_adminpassword) ?>" /> </td> <td> <?php print_string("configadminpassword", "liveclassroom") ?> @@ -40,7 +41,7 @@ <tr valign="top"> <td align="right"><?php print_string('settinguniqueid', 'liveclassroom')?>:</td> <td> - <input name="liveclassroom_settinguniqueid" type="text" size="20" value="<?php p($CFG->liveclassroom_settinguniqueid) ?>" /> + <input name="settinguniqueid" type="text" size="20" value="<?php p($CFG->liveclassroom_settinguniqueid) ?>" /> </td> <td> <?php print_string("configsettinguniqueid", "liveclassroom") ?> Modified: trunk/moodle/mod/liveclassroom/lib.php =================================================================== --- trunk/moodle/mod/liveclassroom/lib.php 2006-04-21 19:35:50 UTC (rev 10) +++ trunk/moodle/mod/liveclassroom/lib.php 2006-05-04 20:20:58 UTC (rev 11) @@ -10,6 +10,28 @@ + +/** + * Validate the data in passed in the configuration page + * @param $config - the information from the form mod.html + * @return nothing, but returns an error if the configuration is wrong + */ +function liveclassroom_process_options ($config) { + global $CFG; + + if (!liveclassroom_api_authenticate($config->servername, + $config->adminusername, + $config->adminpassword)) { + error (get_string('wrongconfiguration', 'liveclassroom'), + "$CFG->wwwroot/admin/module.php?module=liveclassroom"); + } + + //TODO: check the user is really an admin + + return; +} + + function liveclassroom_add_instance($liveclassroom) { /// Given an object containing all the necessary data, /// (defined by the form in mod.html) this function Modified: trunk/moodle/mod/liveclassroom/view.php =================================================================== --- trunk/moodle/mod/liveclassroom/view.php 2006-04-21 19:35:50 UTC (rev 10) +++ trunk/moodle/mod/liveclassroom/view.php 2006-05-04 20:20:58 UTC (rev 11) @@ -63,6 +63,7 @@ /// Print the main part of the page ?> +<!--script type="text/javascript" src='<?PHP p($CFG->liveclassroom_servername)?>/js/launch-7892.js'></script--> <script type="text/javascript" src='<?PHP p($CFG->liveclassroom_servername)?>/js/launch.js'></script> <script type="text/javascript"> function doOpenAdmin(url) { @@ -97,7 +98,7 @@ ?> <tr> <td> - <a href="javascript:doOpenAdmin('<?php p($CFG->liveclassroom_servername)?>/admin/?hzA=<?php p($usersession)?>')"> + <a href="javascript:doOpenAdmin('<?php p($CFG->liveclassroom_servername)?>/admin/?hzA=<?php p($usersession)?>&closeOnExit=1')"> <?php p(get_string('managerooms', 'liveclassroom')) ?> </a> </td> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |