Installer Class missing array variable check
[openemr.git] / phpmyadmin / libraries / sqlvalidator.class.php
blob19fc46a5f4449746d6ced7a0ba3079a50cfcc2c2
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * PHP interface to MimerSQL Validator
6 * Copyright 2002, 2003 Robin Johnson <robbat2@users.sourceforge.net>
7 * http://www.orbis-terrarum.net/?l=people.robbat2
9 * All data is transported over HTTP-SOAP
10 * And uses the PEAR SOAP Module
12 * Install instructions for PEAR SOAP
13 * Make sure you have a really recent PHP with PEAR support
14 * run this: "pear install Mail_Mime Net_DIME SOAP"
16 * If you got this file from somewhere other than phpMyAdmin
17 * please be aware that the latest copy will always be in the
18 * phpMyAdmin subversion tree as
19 * $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyAdmin/libraries/sqlvalidator.class.php $
21 * This code that also used to depend on the PHP overload module, but that has been
22 * removed now.
24 * @access public
26 * @author Robin Johnson <robbat2@users.sourceforge.net>
28 * @version $Id$
30 if (! defined('PHPMYADMIN')) {
31 exit;
34 @include_once 'SOAP/Client.php';
36 if (!function_exists('class_exists') || !class_exists('SOAP_Client')) {
37 $GLOBALS['sqlvalidator_error'] = TRUE;
38 } else {
39 // Ok, we have SOAP Support, so let's use it!
41 class PMA_SQLValidator {
43 var $url;
44 var $service_name;
45 var $wsdl;
46 var $output_type;
48 var $username;
49 var $password;
50 var $calling_program;
51 var $calling_program_version;
52 var $target_dbms;
53 var $target_dbms_version;
54 var $connectionTechnology;
55 var $connection_technology_version;
56 var $interactive;
58 var $service_link = null;
59 var $session_data = null;
62 /**
63 * Private functions - You don't need to mess with these
66 /**
67 * Service opening
69 * @param string URL of Mimer SQL Validator WSDL file
71 * @return object Object to use
73 * @access private
75 function _openService($url)
77 $obj = new SOAP_Client($url, TRUE);
78 return $obj;
79 } // end of the "openService()" function
82 /**
83 * Service initializer to connect to server
85 * @param object Service object
86 * @param string Username
87 * @param string Password
88 * @param string Name of calling program
89 * @param string Version of calling program
90 * @param string Target DBMS
91 * @param string Version of target DBMS
92 * @param string Connection Technology
93 * @param string version of Connection Technology
94 * @param integer boolean of 1/0 to specify if we are an interactive system
96 * @return object stdClass return object with data
98 * @access private
100 function _openSession($obj, $username, $password,
101 $calling_program, $calling_program_version,
102 $target_dbms, $target_dbms_version,
103 $connection_technology, $connection_technology_version,
104 $interactive)
106 $use_array = array("a_userName" => $username, "a_password" => $password, "a_callingProgram" => $calling_program, "a_callingProgramVersion" => $calling_program_version, "a_targetDbms" => $target_dbms, "a_targetDbmsVersion" => $target_dbms_version, "a_connectionTechnology" => $connection_technology, "a_connectionTechnologyVersion" => $connection_technology_version, "a_interactive" => $interactive);
107 $ret = $obj->call("openSession", $use_array);
109 // This is the old version that needed the overload extension
110 /* $ret = $obj->openSession($username, $password,
111 $calling_program, $calling_program_version,
112 $target_dbms, $target_dbms_version,
113 $connection_technology, $connection_technology_version,
114 $interactive); */
116 return $ret;
117 } // end of the "_openSession()" function
121 * Validator sytem call
123 * @param object Service object
124 * @param object Session object
125 * @param string SQL Query to validate
126 * @param string Data return type
128 * @return object stClass return with data
130 * @access private
132 function _validateSQL($obj, $session, $sql, $method)
134 $use_array = array("a_sessionId" => $session->sessionId, "a_sessionKey" => $session->sessionKey, "a_SQL" => $sql, "a_resultType" => $this->output_type);
135 $res = $obj->call("validateSQL", $use_array);
137 // This is the old version that needed the overload extension
138 // $res = $obj->validateSQL($session->sessionId, $session->sessionKey, $sql, $this->output_type);
139 return $res;
140 } // end of the "validateSQL()" function
144 * Validator sytem call
146 * @param string SQL Query to validate
148 * @return object stdClass return with data
150 * @access private
152 * @see validateSQL()
154 function _validate($sql)
156 $ret = $this->_validateSQL($this->service_link, $this->session_data,
157 $sql, $this->output_type);
158 return $ret;
159 } // end of the "validate()" function
163 * Public functions
167 * Constructor
169 * @access public
171 function PMA_SQLValidator()
173 $this->url = 'http://sqlvalidator.mimer.com/v1/services';
174 $this->service_name = 'SQL99Validator';
175 $this->wsdl = '?wsdl';
177 $this->output_type = 'html';
179 $this->username = 'anonymous';
180 $this->password = '';
181 $this->calling_program = 'PHP_SQLValidator';
182 $this->calling_program_version = '$Revision$';
183 $this->target_dbms = 'N/A';
184 $this->target_dbms_version = 'N/A';
185 $this->connection_technology = 'PHP';
186 $this->connection_technology_version = phpversion();
187 $this->interactive = 1;
189 $this->service_link = null;
190 $this->session_data = null;
191 } // end of the "PMA_SQLValidator()" function
195 * Sets credentials
197 * @param string the username
198 * @param string the password
200 * @access public
202 function setCredentials($username, $password)
204 $this->username = $username;
205 $this->password = $password;
206 } // end of the "setCredentials()" function
210 * Sets the calling program
212 * @param string the calling program name
213 * @param string the calling program revision
215 * @access public
217 function setCallingProgram($calling_program, $calling_program_version)
219 $this->calling_program = $calling_program;
220 $this->calling_program_version = $calling_program_version;
221 } // end of the "setCallingProgram()" function
225 * Appends the calling program
227 * @param string the calling program name
228 * @param string the calling program revision
230 * @access public
232 function appendCallingProgram($calling_program, $calling_program_version)
234 $this->calling_program .= ' - ' . $calling_program;
235 $this->calling_program_version .= ' - ' . $calling_program_version;
236 } // end of the "appendCallingProgram()" function
240 * Sets the target DBMS
242 * @param string the target DBMS name
243 * @param string the target DBMS revision
245 * @access public
247 function setTargetDbms($target_dbms, $target_dbms_version)
249 $this->target_dbms = $target_dbms;
250 $this->target_dbms_version = $target_dbms_version;
251 } // end of the "setTargetDbms()" function
255 * Appends the target DBMS
257 * @param string the target DBMS name
258 * @param string the target DBMS revision
260 * @access public
262 function appendTargetDbms($target_dbms, $target_dbms_version)
264 $this->target_dbms .= ' - ' . $target_dbms;
265 $this->target_dbms_version .= ' - ' . $target_dbms_version;
266 } // end of the "appendTargetDbms()" function
270 * Sets the connection technology used
272 * @param string the connection technology name
273 * @param string the connection technology revision
275 * @access public
277 function setConnectionTechnology($connection_technology, $connection_technology_version)
279 $this->connection_technology = $connection_technology;
280 $this->connection_technology_version = $connection_technology_version;
281 } // end of the "setConnectionTechnology()" function
285 * Appends the connection technology used
287 * @param string the connection technology name
288 * @param string the connection technology revision
290 * @access public
292 function appendConnectionTechnology($connection_technology, $connection_technology_version)
294 $this->connection_technology .= ' - ' . $connection_technology;
295 $this->connection_technology_version .= ' - ' . $connection_technology_version;
296 } // end of the "appendConnectionTechnology()" function
300 * Sets whether interactive mode should be used or not
302 * @param integer whether interactive mode should be used or not
304 * @access public
306 function setInteractive($interactive)
308 $this->interactive = $interactive;
309 } // end of the "setInteractive()" function
313 * Sets the output type to use
315 * @param string the output type to use
317 * @access public
319 function setOutputType($output_type)
321 $this->output_type = $output_type;
322 } // end of the "setOutputType()" function
326 * Starts service
328 * @access public
330 function startService()
333 $this->service_link = $this->_openService($this->url . '/' . $this->service_name . $this->wsdl);
335 } // end of the "startService()" function
339 * Starts session
341 * @access public
343 function startSession()
345 $this->session_data = $this->_openSession($this->service_link, $this->username, $this->password,
346 $this->calling_program, $this->calling_program_version,
347 $this->target_dbms, $this->target_dbms_version,
348 $this->connection_technology, $this->connection_technology_version,
349 $this->interactive);
351 if (isset($this->session_data) && ($this->session_data != null)
352 && ($this->session_data->target != $this->url)) {
353 // Reopens the service on the new URL that was provided
354 $url = $this->session_data->target;
355 $this->startService();
357 } // end of the "startSession()" function
361 * Do start service and session
363 * @access public
365 function start()
367 $this->startService();
368 $this->startSession();
369 } // end of the "start()" function
373 * Call to determine just if a query is valid or not.
375 * @param string SQL statement to validate
377 * @return string Validator string from Mimer
379 * @see _validate
381 function isValid($sql)
383 $res = $this->_validate($sql);
384 return $res->standard;
385 } // end of the "isValid()" function
389 * Call for complete validator response
391 * @param string SQL statement to validate
393 * @return string Validator string from Mimer
395 * @see _validate
397 function validationString($sql)
399 $res = $this->_validate($sql);
400 return $res->data;
402 } // end of the "validationString()" function
403 } // end class PMA_SQLValidator
405 //add an extra check to ensure that the class was defined without errors
406 if (!class_exists('PMA_SQLValidator')) {
407 $GLOBALS['sqlvalidator_error'] = TRUE;
410 } // end else