]> git.mjollnir.org Git - moodle.git/commitdiff
webservice MDL-17135 add disable javascript to the valid until fields
authorjerome <jerome>
Tue, 20 Oct 2009 14:33:01 +0000 (14:33 +0000)
committerjerome <jerome>
Tue, 20 Oct 2009 14:33:01 +0000 (14:33 +0000)
admin/external_service_users.php
admin/webservice/script.js
webservice/wsdoc.php

index 595a206be8245ec6af1486288b92e61e73df7e65..88ec21252a2746ff21c33117a81b8c10cc378866 100644 (file)
@@ -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 .= "</div></div>";
         //valid until date selector
         $contents .= "<div class=\"fitem\"><div class=\"fitemtitle\"><label>".get_string('validuntil','webservice')." </label></div><div class=\"felement\">";
-        $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 .= "</div></div>";
         //TO IMPLEMENT : assign the required capability (if needed)
         $contents .=  "<div class=\"fitem\"><div class=\"fitemtitle\"><label>".get_string('addrequiredcapability','webservice')." </label></div><div class=\"felement fcheckbox\">";
index 9dce5fe0b1b43d9301aae82abcf630b54255170c..b604c24c1c9eb61ee464925af3243170fb36abe6 100644 (file)
@@ -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
index e74ebd9e922c458484d60938ba03124443bf89cf..9a00bf690afd1b81eda0b371557402924c1de295 100644 (file)
@@ -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 = "<H2>".get_string('functionlist','webservice')."</H2>";
-
-    //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 .= "<H3><u>".get_string('moodlepath','webservice').": ".$classpath."</u></H3><ul>";
-        if ($classname == "user_external") {
-            $description = $api->get_descriptions();
-            var_dump("<pre>");
-            convertDescriptionType($description);
-            var_dump("</pre>");
-            foreach ($description as $functionname => $functiondescription) {
-                $documentation .= <<<EOF
-        <li><b>{$functionname}(</b>
-EOF;
-                $arrayparams = array();
-                $comma="";
-                //TODO: this is not an array anymore!!! (all algo function)
-                foreach($functiondescription['params'] as $param => $type) {
-                    $documentation .= <<<EOF
-                <span style=color:green>{$comma} {$type} <b>{$param}</b>
-EOF;
-                    if (empty($comma)) {
-                        $comma = ',';
-                    }
-                }
-                $documentation .= <<<EOF
-                    <b></span>)</b> :
-EOF;
-                if (array_key_exists('return', $functiondescription)) {
-                    foreach($functiondescription['return'] as $return => $type) {
-                        $documentation .= <<<EOF
-                <span style=color:blue>
-                <i>
-                            {$type}</i>
-EOF;
-                        if (is_array($type)) {
-                            $arraytype = "<pre>".print_r($type, true)."</pre>";
-                            $documentation .= <<<EOF
-                 <b>{$return}</b><br/><br/><b>{$return}</b>  {$arraytype} </span>
-EOF;
-                        }
-                    }
-                }
-
-                $documentation .= <<<EOF
-                    <br/><br/><span style=color:green>
-EOF;
-                foreach($functiondescription['params'] as $param => $type) {
-
-                    if (is_array($type)) {
-                        $arraytype = "<pre>".print_r($type, true)."</pre>";
-                        $documentation .= <<<EOF
-         <b>{$param}</b> : {$arraytype} <br>
-EOF;
-                    }
-                    else {
-                        $documentation .= <<<EOF
-         <b>{$param}</b> : {$type} <br>
-EOF;
-                    }
-
-                }
-                $documentation .= <<<EOF
-                    </div><br/><br/>
-EOF;
-
-            }
-        }
-        $documentation .= <<<EOF
-            </ul>
-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;
     }
 }