1 | <?php |
||
44 | class Session |
||
45 | { |
||
46 | // HTTP Client instance |
||
47 | protected $httpClient; |
||
48 | |||
49 | // request timeout in seconds |
||
50 | protected $requestTimeout; |
||
51 | |||
52 | // Service URL to which client connects to |
||
53 | protected $vtigerUrl = null; |
||
54 | protected $wsBaseURL = null; |
||
55 | |||
56 | // Vtiger CRM and WebServices API version |
||
57 | private $vtigerApiVersion = '0.0'; |
||
58 | private $vtigerVersion = '0.0'; |
||
59 | |||
60 | // Webservice login validity |
||
61 | private $serviceExpireTime = null; |
||
62 | private $serviceToken = null; |
||
63 | |||
64 | // Webservice user credentials |
||
65 | private $userName = null; |
||
66 | private $accessKey = null; |
||
67 | |||
68 | // Webservice login credentials |
||
69 | private $userID = null; |
||
70 | private $sessionName = null; |
||
71 | |||
72 | /** |
||
73 | * Class constructor |
||
74 | * @param string $vtigerUrl The URL of the remote WebServices server |
||
75 | * @param string [$wsBaseURL = 'webservice.php'] WebServices base URL appended to vTiger root URL |
||
76 | * @param int $requestTimeout Number of seconds after which request times out |
||
77 | */ |
||
78 | public function __construct($vtigerUrl, $wsBaseURL = 'webservice.php', $requestTimeout = 0) |
||
89 | |||
90 | /** |
||
91 | * Login to the server using username and VTiger access key token |
||
92 | * @access public |
||
93 | * @param string $username VTiger user name |
||
94 | * @param string $accessKey VTiger access key token (visible on user profile/settings page) |
||
95 | * @return boolean Returns true if login operation has been successful |
||
96 | */ |
||
97 | public function login($username, $accessKey) |
||
129 | |||
130 | /** |
||
131 | * Allows you to login using username and password instead of access key (works on some VTige forks) |
||
132 | * @access public |
||
133 | * @param string $username VTiger user name |
||
134 | * @param string $password VTiger password (used to access CRM using the standard login page) |
||
135 | * @param string $accessKey This parameter will be filled with user's VTiger access key |
||
136 | * @return boolean Returns true if login operation has been successful |
||
137 | */ |
||
138 | public function loginPassword($username, $password, &$accessKey = null) |
||
162 | |||
163 | /** |
||
164 | * Gets a challenge token from the server and stores for future requests |
||
165 | * @access private |
||
166 | * @param string $username VTiger user name |
||
167 | * @return boolean Returns false in case of failure |
||
168 | */ |
||
169 | private function passChallenge($username) |
||
186 | |||
187 | /** |
||
188 | * Gets an array containing the basic information about current API user |
||
189 | * @access public |
||
190 | * @return array Basic information about current API user |
||
191 | */ |
||
192 | public function getUserInfo() |
||
200 | |||
201 | /** |
||
202 | * Gets vTiger version, retrieved on successful login |
||
203 | * @access public |
||
204 | * @return string vTiger version, retrieved on successful login |
||
205 | */ |
||
206 | public function getVtigerVersion() |
||
210 | |||
211 | /** |
||
212 | * Gets vTiger WebServices API version, retrieved on successful login |
||
213 | * @access public |
||
214 | * @return string vTiger WebServices API version, retrieved on successful login |
||
215 | */ |
||
216 | public function getVtigerApiVersion() |
||
220 | |||
221 | /** |
||
222 | * Sends HTTP request to VTiger web service API endpoint |
||
223 | * @access private |
||
224 | * @param array $requestData HTTP request data |
||
225 | * @param string $method HTTP request method (GET, POST etc) |
||
226 | * @return array Returns request result object (null in case of failure) |
||
227 | */ |
||
228 | public function sendHttpRequest(array $requestData, $method = 'POST') |
||
265 | |||
266 | /** |
||
267 | * Cleans and fixes vTiger URL |
||
268 | * @access private |
||
269 | * @static |
||
270 | * @param string Base URL of vTiger CRM |
||
271 | * @param string $baseUrl |
||
272 | * @return string Returns cleaned and fixed vTiger URL |
||
273 | */ |
||
274 | private static function fixVtigerBaseUrl($baseUrl) |
||
284 | |||
285 | /** |
||
286 | * Check if server response contains an error, therefore the requested operation has failed |
||
287 | * @access private |
||
288 | * @static |
||
289 | * @param array $jsonResult Server response object to check for errors |
||
290 | * @return boolean True if response object contains an error |
||
291 | */ |
||
292 | private static function checkForError(array $jsonResult) |
||
309 | } |
||
310 |