Placeholder Image

ADN Informatique

Consultant Ingénierie Informatique

Saguenay (Jonquière), Québec, Canada. Tél: (581) 683-9887 Téléc: (581) 221-0874

Placeholder Picture

Retour

Serveur XML RPC (2) - PHP

2005-06-22 21:00:05 (ID: 67, Parent: 0, Type: post)
<?php // Title: Example de serveur XML-RPC en php // Version: 0.2 // Author: Jean-Luc Cyr  // Desc: Replacement for python xml-rpc server that handle //       imagem phone dictation system and audio-context calls.  // Exemple avec l'extension disponible // http://phpxmlrpc.sourceforge.net/  include "xmlrpc-1.0.99.2/xmlrpc.inc"; include "xmlrpc-1.0.99.2/xmlrpcs.inc";  // Declare global vars  //Setup parameters //Database user name $duser = "transcription"; //$duser = "DICTWEB"; //Database password //$dpass = "password"; $dpass = "imagemsoft"; //Database tnsname //$dhost = "interweb"; $dhost = "rcorcl"; //Document base path //$base_base = "/export/home/dictedoc/"; $base_path = "/export/home/jlcyr/tmp/";  $db = oci_pconnect($duser,$dpass,$dhost);       // Declare rpc_server possible methods $s=new xmlrpc_server( array("doc.putDoc" => array ("function" => "doc_putDoc"), 			    "doc.getDocInfo" => array ("function" => "doc_getDocInfo"), 			    "doc.createDoc" => array ("function" => "doc_createDoc"), 			    "doc.getUID" => array ("function" => "doc_getUID"), 			    "doc.updateDOC" => array ("function" => "doc_updateDoc"), 			    "doc.help" => array ("function" => "doc_help"), 			    "ris.getBirth" => array("function" => "risCMD_getBirth"), 			    "ris.getCMD" => array("function" => "risCMD_getCMD"), 			    "ris.help" => array("function" => "risCMD_help"), 			    "sql.execSql" => array("function" => "sql_execSql"), 			    "sql.getInst" => array ("function" => "sql_getInst"), 			    "sql.help" => array ("function" => "sql_help") 			    ));  oci_close($db);  // Don't know why, but seen we can't pass class method to xmlrpc_server array of function // so i've declared stand alone functions  ///////////////////////////////////////////////////////////////////////////////////////// // doc_putDoc invoqué via le web sous doc.putDoc // args: 1-Le contenu du document urlencoded //       2-Le path du media file set a concatener avec le root (global $base_path) //       3-Le nom du fichier à créer // retour: 0 function doc_putDoc($params)//($doc, $path, $filename) {   global $base_path;    $doc=$params->getParam(0)->scalarval();   $path=$params->getParam(1)->scalarval();   $filename=$params->getParam(2)->scalarval();    //Est-ce que le répertoir /export/home/dictedoc/$path existe?   if (!file_exists($base_path.$path))     {       //Si non le créer et le mettre chmod 777       mkdir($base_path."/".$path,0777,true);       chmod($base_path."/".$path,0777);     }    //Enregistrer le document $doc sous /export/home/dictedoc/$path/$filename   $f = fopen($base_path."/".$path."/".$filename,"w");   $data = urldecode($doc);   fwrite($f,$data);   fclose($f);   chmod($base_path."/".$path."/".$filename,0777);    return new xmlrpcresp(new xmlrpcval(0,"integer")); }  ///////////////////////////////////////////////////////////////////////////////////////// // doc_getDocInfo invoqué via le web sous doc.getDocInfo // args: le dd_id // retour: toutes les colonnes function doc_getDocInfo($params)//($info) {   global $db;   if ($db==false)       return new xmlrpcresp(new xmlrpcval("Error connection to db ","string"));    $info =$params->getParam(0)->scalarval();   $select = "select * from dictation_document where dd_id='$info'";   $arr = array();   //Execute select, return result values 1,2,3 in uid, id, fileset   $stmt = oci_parse($db,$select);   if (oci_execute($stmt,OCI_DEFAULT))     {       if (oci_fetch($stmt)) 	{ 	  $ncols = OCINumCols($stmt); 	  for ($i = 1; $i <= $ncols; $i++) { 	    $column_name  = OCIColumnName($stmt, $i); 	    $column_type  = OCIColumnType($stmt, $i); 	    $column_size  = OCIColumnSize($stmt, $i); 	    $column_data = OCIResult($stmt, $i);     	    $arr = $arr + array($column_name => new xmlrpcval($column_data,"string")); 	  } 	}       else 	{ 	  return new xmlrpcresp(new xmlrpcval("Error fetching result ","string")); 	}     }   else     {       return new xmlrpcresp(new xmlrpcval("Error executing select ".$select,"string"));     }    return new xmlrpcresp(new xmlrpcval($arr, "struct")); }  ///////////////////////////////////////////////////////////////////////////////////////// // args: le select à exécuter // retour: string "Doc Created" function doc_createDoc($params)//($select) {   $select = $params->getParam(0)->scalarval();    global $db;   if ($db==false)       return new xmlrpcresp(new xmlrpcval("Error connection to db ","string"));    //Execute select, return result values 1,2,3 in uid, id, fileset   $stmt = oci_parse($db,$select);   if (oci_execute($stmt,OCI_DEFAULT))     {       oci_commit($db);     }    //Executer le select dans $select    return new xmlrpcresp(new xmlrpcval("Doc Created","string")); }  ///////////////////////////////////////////////////////////////////////////////////////// // args: un service id // retour: struct: uid, id et fileset pour créer un nouveau document function doc_getUID($params)//($seruid) {   global $db;   if ($db==false)       return new xmlrpcresp(new xmlrpcval("Error connection to db ","string"));    $seruid = $params->getParam(0)->scalarval();    $select = "select '2.16.124.10.2.1.3.100.' ".     "||to_char(sysdate,'YYYYMMDD')||'.'".     "||to_char(to_number(to_char(to_date('010203','HH24MISS'),'HH24MISS')))||'.'".     "||(select CE_VALUE from config_env where CE_ITEM_CONF='INSTITUTION')||'.'".     "||SQ_DICTATION_UID.NEXTVAL,".     "to_char(SQ_DICTATION_UID.NEXTVAL), ".     "(select DS_NAME from DICTATION_SERVICE where DS_ID='$seruid')||'/'||to_char(sysdate,'YYYYIW') from dual";    //Execute select, return result values 1,2,3 in uid, id, fileset   $stmt = oci_parse($db,$select);   if (oci_execute($stmt,OCI_DEFAULT))     {       if (oci_fetch($stmt)) 	{ 	  $uid = oci_result($stmt,1); 	  $id = oci_result($stmt,2); 	  $fileset = oci_result($stmt,3); 	  //oci_commit($this->link); 	}       else 	{ 	  return new xmlrpcresp(new xmlrpcval("Error fetching result ","string")); 	}     }   else     {       return new xmlrpcresp(new xmlrpcval("Error executing select ".$select,"string"));     }    $arr = array( "uid" => new xmlrpcval($uid,"string"), 		"id" => new xmlrpcval($id,"string"), 		"fileset" => new xmlrpcval($fileset,"string") );    return new xmlrpcresp(new xmlrpcval($arr, "struct")); }  ///////////////////////////////////////////////////////////////////////////////////////// // Not done function doc_updateDoc() {   return new xmlrpcresp(new xmlrpcval("Doc Updated","string")); }  ///////////////////////////////////////////////////////////////////////////////////////// // doc_help invoqué via le web sous doc.help // args: aucun // retour: 1-liste des méthodes de l'objet web doc function doc_help() {   return new xmlrpcresp(new xmlrpcval("putDoc, getDocInfo, createDoc, getUID, updateDoc", "string")); }  ///////////////////////////////////////////////////////////////////////////////////////// // args: un patient id // retour: la date de naissance sous forme de string ou 0 si le patient n'existe pas function risCMD_getBirth($params)//($patid) {   $patid =$params->getParam(0)->scalarval();    $select = "select * from WEB.PATIENT where PAT_ID='$patid'";    global $db;   if ($db==false)       return new xmlrpcresp(new xmlrpcval("Error connection to db ","string"));    $stmt = oci_parse($db,$select);   if (oci_execute($stmt,OCI_DEFAULT))     {       if (oci_fetch($stmt)) 	{ 	  $birth = oci_result($stmt,"PAT_BIRTH"); 	}       else 	{ 	  return new xmlrpcresp(new xmlrpcval(0, "integer")); 	  //return new xmlrpcresp(new xmlrpcval("Error fetching result ","string")); 	}     }   else     {       return new xmlrpcresp(new xmlrpcval(0, "integer"));       //return new xmlrpcresp(new xmlrpcval("Error executing select ".$select,"string"));     }    return new xmlrpcresp(new xmlrpcval($birth, "string")); }  ///////////////////////////////////////////////////////////////////////////////////////// // args: le staff id et le délai maximum de validité du click dans le ris // retour: toutes les colonnes de la table RIS_DICTATION_INTERFACE function risCMD_getCMD($params)//($staffid, $gap) {   global $db;   if ($db==false)       return new xmlrpcresp(new xmlrpcval("Error connection to db ","string"));    $staffid = $params->getParam(0)->scalarval();   $gap = $params->getParam(1)->scalarval();    $select = "select * from RIS_DICTATION_INTERFACE where RDI_STAFF_ID='$staffid' and RDI_DT>(sysdate-$gap/(24*60)) order by RDI_DT desc";    //Execute select, Return all values in the array   $arr = array();   $stmt = oci_parse($db,$select);   if (oci_execute($stmt,OCI_DEFAULT))     {       if (oci_fetch($stmt)) 	{ 	  $ncols = OCINumCols($stmt); 	  for ($i = 1; $i <= $ncols; $i++) { 	    $column_name  = OCIColumnName($stmt, $i); 	    $column_type  = OCIColumnType($stmt, $i); 	    $column_size  = OCIColumnSize($stmt, $i); 	    $column_data = OCIResult($stmt, $i);     	    $arr = $arr + array($column_name => new xmlrpcval($column_data,"string")); 	  } 	}       else 	{ 	  return new xmlrpcresp(new xmlrpcval(0, "integer")); 	  //return new xmlrpcresp(new xmlrpcval("Error fetching result ","string")); 	}     }   else     {       return new xmlrpcresp(new xmlrpcval(0, "integer"));       //return new xmlrpcresp(new xmlrpcval("Error executing select ".$select,"string"));     }    return new xmlrpcresp(new xmlrpcval($arr, "struct")); }  ///////////////////////////////////////////////////////////////////////////////////////// function risCMD_help() {   return new xmlrpcresp(new xmlrpcval("getBirth, getCMD", "string")); }  ///////////////////////////////////////////////////////////////////////////////////////// // args: l'affirmation sql a exécuter // retour: la string "Sql Done" function sql_execSql($param)//($select) {   global $db;   if ($db==false)       return new xmlrpcresp(new xmlrpcval("Error connection to db ","string"));    $select = $params->getParam(0)->scalarval();    //Execute select, with commit   $stmt = oci_parse($db,$select);   if (oci_execute($stmt,OCI_DEFAULT))     {       oci_commit($db);     }    return new xmlrpcresp(new xmlrpcval("Sql Done", "string")); }  ///////////////////////////////////////////////////////////////////////////////////////// // args: N/A // retour: le numéro d'institution défini dans la table config_env sous institution //         ou 0 si non défini. function sql_getInst() {   global $db;   if ($db==false)       return new xmlrpcresp(new xmlrpcval("Error connection to db ","string"));    $select = "select CE_VALUE from config_env where CE_ITEM_CONF='INSTITUTION'";    //Execute select, return result value in $inst as a string   $stmt = oci_parse($db,$select);   if (oci_execute($stmt,OCI_DEFAULT))     {       if (oci_fetch($stmt)) 	{ 	  $inst = oci_result($stmt,"CE_VALUE"); 	}       else 	{ 	  return new xmlrpcresp(new xmlrpcval(0, "integer")); 	  //return new xmlrpcresp(new xmlrpcval("Error fetching result ","string")); 	}     }   else     {       return new xmlrpcresp(new xmlrpcval(0, "integer"));       //return new xmlrpcresp(new xmlrpcval("Error executing select ".$select,"string"));     }    return new xmlrpcresp(new xmlrpcval($inst, "string")); }  ///////////////////////////////////////////////////////////////////////////////////////// function sql_help() {   return new xmlrpcresp(new xmlrpcval("execSql, getInst", "string")); }  //Exemple de retour de message d'erreur //return new xmlrpcresp(0, $xmlrpcerruser+3, "Select return an error"); //return new xmlrpcresp($retVal);//OK 

 

Document Informatif

ADN Informatique

2015

Rev. 1

Jean-Luc Cyr