From 472f56d926feb9d47f7c244bcf1eed50b61e4378 Mon Sep 17 00:00:00 2001 From: jerome Date: Tue, 20 Oct 2009 14:33:01 +0000 Subject: [PATCH] webservice MDL-17135 add disable javascript to the valid until fields --- admin/external_service_users.php | 30 ++++-- admin/webservice/script.js | 15 +++ webservice/wsdoc.php | 175 +++++-------------------------- 3 files changed, 67 insertions(+), 153 deletions(-) diff --git a/admin/external_service_users.php b/admin/external_service_users.php index 595a206be8..88ec21252a 100644 --- a/admin/external_service_users.php +++ b/admin/external_service_users.php @@ -30,6 +30,7 @@ require_once($CFG->dirroot.'/admin/webservice/lib.php'); $id = required_param('id', PARAM_INT); $PAGE->set_url('admin/external_service_users.php', array('id'=>$id)); +$PAGE->requires->js('admin/webservice/script.js'); admin_externalpage_setup('externalserviceusers'); admin_externalpage_print_header(); @@ -106,15 +107,20 @@ $alloweduserselector = new service_user_selector('removeselect', array('servicei /// save user settings (administrator clicked on update button) if (optional_param('updateuser', false, PARAM_BOOL) && confirm_sesskey()) { - $useridtoupdate = optional_param('userid', false, PARAM_BOOL); + $useridtoupdate = optional_param('userid', false, PARAM_INT); $iprestriction = optional_param('iprestriction', '', PARAM_TEXT); $serviceuserid = optional_param('serviceuserid', '', PARAM_INT); - $fromday = optional_param('fromday', '', PARAM_INT); - $frommonth = optional_param('frommonth', '', PARAM_INT); - $fromyear = optional_param('fromyear', '', PARAM_INT); + $fromday = optional_param('fromday'.$useridtoupdate, '', PARAM_INT); + $frommonth = optional_param('frommonth'.$useridtoupdate, '', PARAM_INT); + $fromyear = optional_param('fromyear'.$useridtoupdate, '', PARAM_INT); $addcap = optional_param('addcap', false, PARAM_INT); $enablevaliduntil = optional_param('enablevaliduntil', false, PARAM_INT); - $validuntil = mktime(23, 59, 59, $frommonth, $fromday, $fromyear); + if (!empty($fromday) && !empty($frommonth) && !empty($fromyear)) { + $validuntil = mktime(23, 59, 59, $frommonth, $fromday, $fromyear); + } + else { + $validuntil = ""; + } $serviceuser = new object(); $serviceuser->id = $serviceuserid; @@ -170,16 +176,26 @@ if (!empty($allowedusers)) { $contents .= ""; //valid until date selector $contents .= "
"; - $selectors = html_select::make_time_selectors(array('days' => 'fromday','months' => 'frommonth', 'years' => 'fromyear'),$user->validuntil); + // the following date selector needs to have specific day/month/year field ids because we use javascript (enable/disable). + $selectors = html_select::make_time_selectors(array('days' => 'fromday'.$user->id,'months' => 'frommonth'.$user->id, 'years' => 'fromyear'.$user->id),$user->validuntil); foreach ($selectors as $select) { + if (empty($user->validuntil)) { + $select->disabled = true; + } $contents .= $OUTPUT->select($select); - } $checkbox = new html_select_option(); + } + $checkbox = new html_select_option(); $checkbox->value = 1; + $checkbox->id = 'enablevaliduntil'.$user->id; + $checkbox->name = 'enablevaliduntil'; $checkbox->selected = empty($user->validuntil)?false:true; $checkbox->text = get_string('enabled', 'webservice'); $checkbox->label->text = get_string('enabled', 'webservice'); $checkbox->alt = get_string('enabled', 'webservice'); + $checkbox->add_action('change', 'disablevaliduntil', array($user->id)); //into admin/webservice/script.js $contents .= $OUTPUT->checkbox($checkbox, 'enablevaliduntil'); + $contents .= ""; //init date selector disable status + $contents .= "
"; //TO IMPLEMENT : assign the required capability (if needed) $contents .= "
"; diff --git a/admin/webservice/script.js b/admin/webservice/script.js index 9dce5fe0b1..b604c24c1c 100644 --- a/admin/webservice/script.js +++ b/admin/webservice/script.js @@ -70,4 +70,19 @@ capability_service = { } +} + +/* This function disable the valid until field of a user into external_service_users.php*/ +function disablevaliduntil(event, userid) { + var disabled; + if (document.getElementById('enablevaliduntil'+userid).checked) + { + disabled = false; + } + else { + disabled = true; + } + document.getElementById('menufromday'+userid).disabled = disabled; + document.getElementById('menufromyear'+userid).disabled = disabled; + document.getElementById('menufrommonth'+userid).disabled = disabled; } \ No newline at end of file diff --git a/webservice/wsdoc.php b/webservice/wsdoc.php index e74ebd9e92..9a00bf690a 100644 --- a/webservice/wsdoc.php +++ b/webservice/wsdoc.php @@ -31,6 +31,11 @@ die('TODO'); require_once('../config.php'); require_once('lib.php'); $protocol = optional_param('protocol',"soap",PARAM_ALPHA); +$username = optional_param('username',"",PARAM_ALPHA); +$password = optional_param('password',"",PARAM_ALPHA); + +/// TODO Retrieve user (authentication) +$user = ""; /// PAGE settings $PAGE->set_course($COURSE); @@ -38,13 +43,34 @@ $PAGE->set_url('webservice/wsdoc.php'); $PAGE->set_title(get_string('wspagetitle', 'webservice')); $PAGE->set_heading(get_string('wspagetitle', 'webservice')); $PAGE->set_generaltype("form"); + +// Display the documentation echo $OUTPUT->header(); -webservice_lib::display_webservices_availability($protocol); -generate_documentation($protocol); -generate_functionlist(); +generate_documentation($protocol); //documentation relatif to the protocol +generate_functionlist($protocol, $user); //documentation relatif to the available function echo $OUTPUT->footer(); +function generate_functionlist($protocol, $user) { + + /// retrieve all function that the user can access + /// => + /// retrieve all function that are available into enable services that + /// have (no restriction user or the user is into the restricted user list) + /// and (no required capability or the user has the required capability) + + // do SQL request here + + /// load once all externallib.php of the retrieved functions + + /// foreach retrieved functions display the description + + // in order to display the description we need to use an algo similar to the validation + // every time we get a scalar value, we need to convert it into a human readable value as + // PARAM_INT => 'integer' or PARAM_TEXT => 'string' or PARAM_BOOL => 'boolean' ... + +} + /** * Generate documentation specific to a protocol @@ -68,132 +94,6 @@ function generate_documentation($protocol) { } -/** - * Generate web service function list - * @global object $CFG - */ -function generate_functionlist () { - global $CFG; - $documentation = "

".get_string('functionlist','webservice')."

"; - - //retrieve all external file - $externalfiles = array(); - $externalfunctions = array(); - webservice_lib::setListApiFiles($externalfiles, $CFG->dirroot); - - foreach ($externalfiles as $file) { - require($file); - - $classpath = substr($file,strlen($CFG->dirroot)+1); //remove the dir root + / from the file path - $classpath = substr($classpath,0,strlen($classpath) - 13); //remove /external.php from the classpath - $classpath = str_replace('/','_',$classpath); //convert all / into _ - $classname = $classpath."_external"; - $api = new $classname(); - $documentation .= "

".get_string('moodlepath','webservice').": ".$classpath."

    "; - if ($classname == "user_external") { - $description = $api->get_descriptions(); - var_dump("
    ");
    -            convertDescriptionType($description);
    -            var_dump("
    "); - foreach ($description as $functionname => $functiondescription) { - $documentation .= <<{$functionname}( -EOF; - $arrayparams = array(); - $comma=""; - //TODO: this is not an array anymore!!! (all algo function) - foreach($functiondescription['params'] as $param => $type) { - $documentation .= <<{$comma} {$type} {$param} -EOF; - if (empty($comma)) { - $comma = ','; - } - } - $documentation .= <<) : -EOF; - if (array_key_exists('return', $functiondescription)) { - foreach($functiondescription['return'] as $return => $type) { - $documentation .= << - - {$type} -EOF; - if (is_array($type)) { - $arraytype = "
    ".print_r($type, true)."
    "; - $documentation .= <<{$return}

    {$return} {$arraytype} -EOF; - } - } - } - - $documentation .= <<
    -EOF; - foreach($functiondescription['params'] as $param => $type) { - - if (is_array($type)) { - $arraytype = "
    ".print_r($type, true)."
    "; - $documentation .= <<{$param} : {$arraytype}
    -EOF; - } - else { - $documentation .= <<{$param} : {$type}
    -EOF; - } - - } - $documentation .= <<

    -EOF; - - } - } - $documentation .= << -EOF; - - } - - echo $documentation; - -} - -function convertDescriptionType(&$description) { - foreach ($description as &$type) { - if (is_array($type)) { //is it a List ? - convertDescriptionType($type); - } - else { - if (is_object($type)) { //is it a object - convertObjectTypes($type); - } - else { //it's a primary type - $type = converterMoodleParamIntoWsParam($type); - } - } - } -} - -function convertObjectTypes(&$type) { - foreach (get_object_vars($type) as $propertyname => $propertytype) { //browse all properties of the object - if (is_array($propertytype)) { //the property is an array - convertDescriptionType($propertytype); - $type->$propertyname = $propertytype; - } else if (is_object($propertytype)) { //the property is an object - convertObjectTypes($propertytype); - $type->$propertyname = $propertytype; - } - else { //the property is a primary type - $type->$propertyname = converterMoodleParamIntoWsParam($propertytype); - } - } -} - /** * Convert a Moodle type (PARAM_ALPHA, PARAM_NUMBER,...) as a SOAP type (string, interger,...) * @param integer $moodleparam @@ -228,22 +128,5 @@ function converterMoodleParamIntoWsParam($moodleparam) { case PARAM_TEXT: return "string"; break; - //here we check that the value has not already been changed - //the algo could want to do it in the case two functions of the web description use the - //same object ($params or $return could be the same for two functions, so the guy - //writing the web description use the same object) - //as the convertDescriptionType function passes parameter in reference - case "integer": - return "integer"; - break; - case "boolean": - return "boolean"; - break; - case "string": - return "string"; - break; - default: - return "object"; - break; } } -- 2.39.5