Example #1
0
 function logout($session_id)
 {
     if (!$session_id) {
         return;
     }
     $es_cache = new external_services_cache('es_cache_blob', 1200);
     $session_info = $es_cache->decache_single_object($session_id, CACHE_TYPE_OPACEMPRSESSION);
     if ($session_info !== false) {
         $es_cache->delete_single_object($session_id, CACHE_TYPE_OPACEMPRSESSION);
     }
 }
Example #2
0
 function getAdvancedSearchField($field_id, $search_realm, $vlang, $fetch_values, $search_object = NULL, $nocache = false)
 {
     global $dbh, $msg, $lang, $include_path, $class_path;
     if (!$nocache) {
         //Allons chercher les infos dans le cache si elles existent
         $cache_ref = "getAdvancedSearchField_result_" . $field_id . "_" . $lang . "_" . $search_realm;
         $es_cache = new external_services_cache('es_cache_blob', 86400);
         $cached_result = $es_cache->decache_single_object($cache_ref, CACHE_TYPE_MISC);
         if ($cached_result !== false) {
             $cached_result = unserialize(base64_decode($cached_result));
             return $cached_result;
         }
     }
     //Si on nous passe le $search_object, c'est que tout l'environnement est prêt
     if (!$search_object) {
         $opac_realm = false;
         $full_path = '';
         if (substr($search_realm, 0, 5) == 'opac|') {
             $search_realm = substr($search_realm, 5);
             global $base_path;
             $full_path = $base_path . "/includes/search_queries/";
             $opac_realm = true;
         }
         //Ajoutant la langue demandée à l'environnement
         if ($opac_realm) {
             if (file_exists("{$base_path}/includes/messages/{$vlang}.xml")) {
                 //Allons chercher les messages
                 include_once "{$class_path}/XMLlist.class.php";
                 $messages = new XMLlist("{$base_path}/includes/messages/{$vlang}.xml", 0);
                 $messages->analyser();
                 global $msg;
                 $msg = $messages->table;
             }
         } else {
             if ($vlang != $lang && file_exists("{$include_path}/messages/{$vlang}.xml")) {
                 //Allons chercher les messages
                 include_once "{$class_path}/XMLlist.class.php";
                 $messages = new XMLlist("{$include_path}/messages/{$vlang}.xml", 0);
                 $messages->analyser();
                 global $msg;
                 $msg = $messages->table;
             }
         }
         $search_object = new search(false, $search_realm, $full_path);
     }
     if (isset($search_object->fixedfields[$field_id])) {
         $content = $search_object->fixedfields[$field_id];
         $aresult = array("operators" => array());
         $aresult["id"] = $field_id;
         $aresult["label"] = utf8_normalize($content["TITLE"]);
         $aresult["type"] = $content["INPUT_TYPE"];
         foreach ($content["QUERIES"] as $aquery) {
             $aresult["operators"][] = array("id" => $aquery["OPERATOR"], "label" => utf8_normalize($search_object->operators[$aquery["OPERATOR"]]));
         }
         $aresult["values"] = array();
         $aresult["fieldvar"] = array();
         if ($fetch_values) {
             switch ($content["INPUT_TYPE"]) {
                 case "query_list":
                     $aresult["values"] = array();
                     $requete = $content["INPUT_OPTIONS"]["QUERY"][0]["value"];
                     $resultat = mysql_query($requete, $dbh);
                     while ($opt = mysql_fetch_row($resultat)) {
                         $aresult["values"][] = array("value_id" => $opt[0], "value_caption" => utf8_normalize($opt[1]));
                     }
                     break;
                 case "list":
                     if (!isset($content["INPUT_OPTIONS"]["OPTIONS"][0]["OPTION"])) {
                         break;
                     }
                     foreach ($content["INPUT_OPTIONS"]["OPTIONS"][0]["OPTION"] as $aoption) {
                         if (substr($aoption["value"], 0, 4) == "msg:") {
                             $aoption["value"] = $msg[substr($aoption["value"], 4)];
                         }
                         $aresult["values"][] = array("value_id" => $aoption["VALUE"], "value_caption" => utf8_normalize($aoption["value"]));
                     }
                     break;
                 case "marc_list":
                     $options = new marc_list($content["INPUT_OPTIONS"]["NAME"][0]["value"]);
                     asort($options->table);
                     reset($options->table);
                     // gestion restriction par code utilise.
                     if ($content["INPUT_OPTIONS"]["RESTRICTQUERY"][0]["value"]) {
                         $restrictquery = mysql_query($content["INPUT_OPTIONS"]["RESTRICTQUERY"][0]["value"], $dbh);
                         if ($restrictqueryrow = @mysql_fetch_row($restrictquery)) {
                             if ($restrictqueryrow[0]) {
                                 $restrictqueryarray = explode(",", $restrictqueryrow[0]);
                                 $existrestrict = true;
                             } else {
                                 $existrestrict = false;
                             }
                         } else {
                             $existrestrict = false;
                         }
                     } else {
                         $existrestrict = false;
                     }
                     while (list($key, $val) = each($options->table)) {
                         if ($existrestrict && array_search($key, $restrictqueryarray) !== false) {
                             $aresult["values"][] = array("value_id" => $key, "value_caption" => utf8_normalize($val));
                         } elseif (!$existrestrict) {
                             $aresult["values"][] = array("value_id" => $key, "value_caption" => utf8_normalize($val));
                         }
                     }
                     $r .= "</select>";
                     break;
                 case "text":
                 case "authoritie":
                 default:
                     $aresult["values"] = array();
                     break;
             }
         }
         if ($content['VAR']) {
             $params = array();
             foreach ($content['VAR'] as $variable) {
                 if ($variable['TYPE'] == "input") {
                     $input = $variable['OPTIONS']['INPUT'][0];
                     $values = array();
                     switch ($input['TYPE']) {
                         case "query_list":
                             $concat = "";
                             $query_list_result = @mysql_query($input['QUERY'][0]['value']);
                             while ($value = mysql_fetch_array($query_list_result)) {
                                 if ($concat) {
                                     $concat .= ",";
                                 }
                                 $concat .= $value[0];
                                 $values[] = array('value_id' => $value[0], 'value_caption' => utf8_normalize($value[1]));
                             }
                             if ($input['QUERY'][0]['ALLCHOICE'] == "yes") {
                                 $values[] = array('value_id' => $concat, 'value_caption' => utf8_normalize($msg[substr($input['QUERY'][0]['TITLEALLCHOICE'], 4, strlen($input['QUERY'][0]['TITLEALLCHOICE']) - 4)]));
                             }
                             break;
                         case "checkbox":
                         case "hidden":
                             $values = array($input["VALUE"][0]["value"]);
                             break;
                     }
                     $params[] = array('label' => utf8_normalize($variable['COMMENT']), 'name' => $variable['NAME'], 'type' => $input['TYPE'], 'values' => $values);
                 }
                 $aresult['fieldvar'] = $params;
             }
         }
     } else {
         $aresult = array();
         foreach ($search_object->dynamicfields as $prefix => $content) {
             $pp = new parametres_perso($content['TYPE']);
             foreach ($pp->t_fields as $id => $field) {
                 if ($field_id == $prefix . $id) {
                     if ($field['OPAC_SHOW'] && $field['SEARCH']) {
                         $field['ident'] = $field_id;
                         $field['ID'] = $id;
                         $field['PREFIX'] = "notices";
                         $aresult = aff_empr_search($field);
                         $aresult['label'] = utf8_normalize($aresult['label']);
                         $aresult['id'] = $prefix . "_" . $id;
                         foreach ($content['FIELD'] as $field_spec) {
                             if ($field_spec['DATATYPE'] == $field['DATATYPE']) {
                                 $queries = $field_spec['QUERIES'];
                             }
                         }
                         foreach ($queries as $aquery) {
                             $aresult['operators'][] = array("id" => $aquery["OPERATOR"], "label" => utf8_normalize($search_object->operators[$aquery["OPERATOR"]]));
                         }
                     }
                 }
             }
         }
         $aresult['values'] = array();
         $aresult['fieldvar'] = array();
     }
     //		if(sizeof($aresult)==0){
     //			throw new Exception("id not found");
     //		}
     //
     if (!$nocache) {
         //Mettons le resultat dans le cache
         $es_cache = new external_services_cache('es_cache_blob', 86400);
         $es_cache->encache_single_object($cache_ref, CACHE_TYPE_MISC, base64_encode(serialize($aresult)));
     }
     return $aresult;
 }
 function external_services($allow_caching = false)
 {
     if ($allow_caching) {
         $es_cache = new external_services_cache('es_cache_blob', 86400);
         //Vérifions que le catalogue xml n'a pas changé avant de chercher dans le cache
         $situation = $this->compute_situation_catalog_identity();
         $old_situation = $es_cache->decache_single_object('external_service_catalog_situation', CACHE_TYPE_MISC);
         if ($old_situation == $situation) {
             $cached_result = $es_cache->decache_single_object('external_service_catalog', CACHE_TYPE_MISC);
             if ($cached_result !== false) {
                 $cached_result = unserialize(base64_decode($cached_result));
                 $this->catalog = $cached_result;
             }
         }
     }
     if (!$this->catalog) {
         //Parse des bibliothèques disponibles
         $this->catalog = new es_catalog();
         if ($this->catalog->error) {
             $this->copy_error($this->catalog);
             return;
         }
         if ($allow_caching) {
             //Mettons le catalogue dans le cache
             $es_cache = new external_services_cache('es_cache_blob', 86400);
             $es_cache->encache_single_object('external_service_catalog', CACHE_TYPE_MISC, base64_encode(serialize($this->catalog)));
             $es_cache->encache_single_object('external_service_catalog_situation', CACHE_TYPE_MISC, $situation);
         }
     }
 }
    function return_wsdl($source_object, $user_id = 0)
    {
        global $charset;
        global $declared_types;
        global $type_aliases;
        $cache_ref = "api_soap_wsdl_" . $source_object->id;
        if ($source_object->connector->config["cache_wsdl"]) {
            //Voyons si on peut trouver quelque chose de pas trop vieux dans le cache
            $es_cache = new external_services_cache('es_cache_blob', 3600);
            $cached_result = $es_cache->decache_single_object($cache_ref, CACHE_TYPE_MISC);
            if ($cached_result !== false) {
                //Il est bon? On l'envoi
                if (!isset($_GET["nx"])) {
                    header('Content-Type: text/xml');
                }
                print $cached_result;
                exit;
            }
        }
        //Récupérons la liste des fonctions que l'on doit exporter
        $api_catalog = new es_catalog();
        $api_es = new external_services();
        //$api_rights = new external_services_rights($api_es);
        $final_method_list = array();
        foreach ($source_object->config["exported_functions"] as $amethod) {
            //		if ($api_rights->has_rights($user_id, $amethod["group"], $amethod["name"])) {
            $final_method_list[] = $amethod;
            //		}
        }
        //Les entêtes du fichier
        $wsdl_headers = '<?xml version="1.0" encoding="UTF-8"?>
		<?xml-stylesheet type="text/xsl" href="connecteurs/out/apisoap/wsdl-viewer.xsl"?>
		<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://sigb.net/pmb/es/apisoap" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PMBSOAPAPI" targetNamespace="http://sigb.net/pmb/es/apisoap">';
        //Les entêtes des déclaration de type
        $wsdl_types = '<wsdl:types>
		    <xsd:schema targetNamespace="http://sigb.net/pmb/es/apisoap" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
		    	<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>';
        //On va construire la liste des types à déclarer en fonction de ce que l'on va rencontrer, puis on y reviendra
        $additional_definitions = array();
        $declared_types = array();
        $type_aliases = array();
        //Ajoutons les types du manifest s'il y en a
        $handled_groups = array();
        foreach ($final_method_list as $amethod) {
            //Vérifions si on a pas déjà traité les types de ce groupe
            if (isset($handled_groups[$amethod["group"]])) {
                continue;
            }
            //Ajoutons les types du groupe de la methode courante
            foreach ($api_catalog->groups[$amethod["group"]]->types as &$atype) {
                if ($atype->imported) {
                    $base_name = $api_catalog->groups[$atype->imported_from]->name . '_' . $atype->name;
                    $local_base_name = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->group . '_' . $atype->name;
                    if (isset($declared_types[$base_name])) {
                        if (!isset($type_aliases[$local_base_name])) {
                            $type_aliases[$local_base_name] = $base_name;
                        }
                        continue;
                    }
                    $this->type_to_wsdl($api_catalog->groups[$atype->imported_from]->types[$atype->name], $base_name, $atype->imported_from, $additional_definitions, "element");
                    $type_aliases[$local_base_name] = $base_name;
                } else {
                    $base_name = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->group . '_' . $atype->name;
                    if (isset($declared_types[$base_name])) {
                        continue;
                    }
                    $this->type_to_wsdl($atype, $base_name, $amethod["group"], $additional_definitions, "element");
                }
                $declared_types[$base_name] = true;
            }
            $handled_groups[$amethod["group"]] = true;
        }
        //Construction des messages
        $wsdl_messages = "";
        foreach ($final_method_list as $amethod) {
            $method_name = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->group . '_' . $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->name;
            $wsdl_messages .= '<wsdl:message name="' . XMLEntities($method_name) . 'Request">';
            foreach ($api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->inputs as $ainput) {
                $wsdl_messages .= $this->input_to_wsdl($ainput, $method_name, $amethod["group"], $additional_definitions, "part");
            }
            $wsdl_messages .= '</wsdl:message>';
            $wsdl_messages .= '<wsdl:message name="' . XMLEntities($method_name) . 'Response">';
            $output_count = count($api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->outputs);
            if ($output_count > 1) {
                $additional_definition = "";
                $additional_definition .= '<xsd:complexType name="' . XMLEntities($method_name) . 'ResponseStruct">';
                $additional_definition .= '<xsd:sequence>';
                foreach ($api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->outputs as $ainput) {
                    $additional_definition .= $this->output_to_wsdl($ainput, $method_name, $amethod["group"], $additional_definitions, "element");
                }
                $additional_definition .= '</xsd:sequence>';
                $additional_definition .= '</xsd:complexType>';
                $additional_definitions[XMLEntities($method_name) . 'ResponseStruct'] = $additional_definition;
                $wsdl_messages .= '<wsdl:part name="result" type="tns:' . XMLEntities($method_name) . 'ResponseStruct"/>';
            } else {
                if ($output_count) {
                    $wsdl_messages .= $this->output_to_wsdl($api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->outputs[0], $method_name, $amethod["group"], $additional_definitions, "part");
                }
            }
            $wsdl_messages .= '</wsdl:message>';
        }
        //On a maintenant les types, on fini de construire le bloc associé
        $wsdl_types .= implode("", $additional_definitions);
        $wsdl_types .= '</xsd:schema>
		     	</wsdl:types>';
        //PortType
        $wsdl_porttype = "";
        $wsdl_porttype .= '<wsdl:portType name="PMBSOAPAPI">';
        foreach ($final_method_list as $amethod) {
            $method_name = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->group . '_' . $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->name;
            $method_group = $amethod["group"];
            $method_description = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->description;
            $input_description = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->input_description;
            $output_description = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->output_description;
            $wsdl_porttype .= '
			       <wsdl:operation name="' . XMLEntities($method_name) . '">
	                 <wsdl:documentation>' . XMLEntities($api_es->get_text($method_description, $method_group)) . '</wsdl:documentation>
			         <wsdl:input message="tns:' . XMLEntities($method_name) . 'Request">
			           <wsdl:documentation>' . XMLEntities($api_es->get_text($input_description, $method_group)) . '</wsdl:documentation>
			         </wsdl:input>
			         <wsdl:output message="tns:' . XMLEntities($method_name) . 'Response">
			           <wsdl:documentation>' . XMLEntities($api_es->get_text($output_description, $method_group)) . '</wsdl:documentation>
			         </wsdl:output>
			       </wsdl:operation>';
        }
        $wsdl_porttype .= '</wsdl:portType>';
        //Binding
        $wsdl_binding = "";
        $wsdl_binding .= '<wsdl:binding name="PMBSOAPAPI_Binding" type="tns:PMBSOAPAPI">
			    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>';
        foreach ($final_method_list as $amethod) {
            $method_name = $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->group . '_' . $api_catalog->groups[$amethod["group"]]->methods[$amethod["name"]]->name;
            $wsdl_binding .= '
				   <wsdl:operation name="' . XMLEntities($method_name) . '">
				      <soap:operation soapAction="http://sigb.net/pmb/es/apisoap/' . XMLEntities($method_name) . '" style="rpc"/>
				      <wsdl:input>
 			            <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" />
  				      </wsdl:input>
				      <wsdl:output>
				        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" />
				      </wsdl:output>
				   </wsdl:operation>';
        }
        $wsdl_binding .= '</wsdl:binding>';
        //Service
        $server_location = serverURL();
        $wsdl_service = "";
        $wsdl_service .= '
	  <wsdl:service name="PMBSOAPAPI">
	    <wsdl:port binding="tns:PMBSOAPAPI_Binding" name="PMBSOAPAPI">
	      <soap:address location="' . XMLEntities($server_location) . '"/>
	    </wsdl:port>
	  </wsdl:service>';
        $wsdl_footer = '</wsdl:definitions>';
        //On conbine le tout pour donner le wsdl final
        $wsdl = $wsdl_headers . $wsdl_types . $wsdl_messages . $wsdl_porttype . $wsdl_binding . $wsdl_service . $wsdl_footer;
        if ($charset != 'utf-8') {
            $wsdl = utf8_encode($wsdl);
        }
        //On le met en cache si on le souhaite
        if ($source_object->connector->config["cache_wsdl"]) {
            $es_cache = new external_services_cache('es_cache_blob', 600);
            $es_cache->encache_single_object($cache_ref, CACHE_TYPE_MISC, $wsdl);
        }
        //Et on l'envoi
        if (!isset($_GET["nx"])) {
            header('Content-Type: text/xml');
        }
        print $wsdl;
        exit;
    }