'; echo "Moodle Webservice Rest Test Client"; echo ''; echo ''; echo '

Moodle Webservice Rest Test Client

'; echo "

$title2

"; echo '
'; echo '
'; if ($title) echo '

'; } /** * end interface * * @param bool $ret=true: show return button */ function end_interface ($ret = true) { if ($ret) echo '

'; echo '
'; echo ''; echo ''; } /** * print XML div area * * @param string $xml * */ function show_xml ($xml) { echo '
'; echo 'Hide/Show XML'; echo "
"; echo '
';echo htmlentities($xml);echo '
'; echo "
"; echo "
"; } /** * format post data */ function format_postdata ($data) { $o=""; foreach ($data as $k=>$v) { $o.= "$k=".rawurlencode($v)."&"; } $post_data=substr($o,0,-1); return $post_data; } /** * shows an object in list format * * @param mixed $obj * @param integer $cols: number of colums * @ string string $check=false: if this attribute is not present, the $obj is ans error * */ function show_object ($obj,$cols=1,$check=false) { if (!is_array($obj)) $obj = array($obj); echo ''; } //---- XML simple parser ---- //this code was donated by Ferran Recio /** * convert a simple xml into php object * * @author ferran recio * * @param String $xml * * @return mixed */ function basicxml_xml_to_object ($xml) { $xml=utf8_encode($xml); //create the parser $parser = xml_parser_create (); xml_set_default_handler ($parser,'basicxml_xml_to_object_aux'); $values = array(); $index = array(); xml_parse_into_struct($parser,$xml,$values,$index); //print_object($values); //print_object($index); //just simplexml tag (disabled) //if (strtolower($values[0]['tag']) != 'basicxml') return false; //if (strtolower($values[count($values)-1]['tag']) != 'basicxml') return false; $res = basicxml_xml_to_object_aux ($values); //omit the first tag $parts = array_keys(get_object_vars($res)); $key = $parts[0]; return $res->$key; } /** * auxiliar function to basicxml_xml_to_object * * @author ferran recio * * @param mixed $values * * @return mixed */ function basicxml_xml_to_object_aux ($values) { if (!is_array($values)) return false; //print_object ($values); $currset = array(); $search = false; foreach ($values as $value) { $tag = strtolower($value['tag']); //if we are acomulating, just acomulate it if ($search) { //if it closes a tag, we just stop searching if ($tag == $search && $value['type']=='close') { //recursivity $obj2 = basicxml_xml_to_object_aux ($currset); //search cleaning $search = false; //add to result if (isset($res->{$tag})){ if (is_array($res->{$tag})){ $res->{$tag}[] = $obj2; } else { $res->{$tag} = array($res->{$tag},$obj2); } } else { $res->{$tag} = $obj2; } } else { //we are searching. If it's cdada, pass it throw if ($value['type']=='cdata') continue; //if isn't cdata, put it in the set and continue searching //(because isn't the close we're searching) $currset[] = $value; } } else { //walking the xml if ($value['type']=='open'){ //on open, let's search on it $currset = array(); $search = $tag; } else { //if it's complete just save it if ($value['type']=='complete') { if (!empty($value['value'] )) { $val = html_entity_decode($value['value']); if (isset($res->{$tag})){ if (is_array($res->{$tag})){ $res->{$tag}[] = $val; } else { $res->{$tag} = array($res->{$tag},$val); } } else { $res->{$tag} = $val; } } } } } } return $res; } ?>