--- /dev/null
+<?php
+
+require_once('protected/required.php');
+
+class SugarConnector extends SugarHttpClient {
+
+ protected $url, $sessionId;
+
+ /// CONSTRUCTEUR
+ function __construct($url = 'http://sugar/service/v4_1/rest.php', $sessionId = null) {
+ //define('sugarEntry', TRUE);
+ $this -> url = $url;
+ $this -> sessionId = $sessionId;
+ }
+
+ /// GETTERS
+ public function getUrl() { return $this -> url; }
+ public function getSessionId() { return $this -> sessionId; }
+
+ /// SETTERS
+ public function setUrl($url) { $this -> url = $url; }
+ public function setSessionId($sessionId) { $this -> sessionId = $sessionId; }
+
+
+ public function login ($login, $pass) {
+ // Set the POST arguments to pass to the Sugar server
+ $parameters = array(
+ 'user_auth' => array(
+ 'user_name' => $login,
+ 'password' => md5($pass),
+ ),
+ );
+
+ $json = json_encode($parameters);
+
+ $postArgs = array(
+ 'method' => 'login',
+ 'input_type' => 'JSON',
+ 'response_type' => 'JSON',
+ 'rest_data' => $json,
+ );
+
+ $postArgs = http_build_query($postArgs);
+
+ // Make the REST call, returning the result
+ $response = $this->callRest($this -> url, $postArgs);
+
+ if ( $response === false )
+ {
+ die("Request failed.\n");
+ }
+
+ // Convert the result from JSON format to a PHP array
+ $result = json_decode($response);
+
+ if ( !is_object($result) )
+ {
+ die("Error handling result.\n");
+ }
+
+ if ( !isset($result->id) )
+ {
+ die("Error: {$result->name} - {$result->description}\n.");
+ }
+
+ // Get the session id
+ $this -> sessionId = $result->id;
+ }
+
+ public function getInfosModule ($moduleName, $requestedInfos, $sqlWhereClause = "", $sqlOrderByClause = "") {
+ $get_entry_list_parameters = array(
+ //session id
+ 'session' => $this -> sessionId,
+ //The name of the module from which to retrieve records
+ 'module_name' => $moduleName,
+ //The SQL WHERE clause without the word "where".
+ 'query' => $sqlWhereClause,//"accounts.name = 'SDIS 40'",
+ //The SQL ORDER BY clause without the phrase "order by".
+ 'order_by' => $sqlOrderByClause,
+ //The record offset from which to start.
+ 'offset' => 0,
+ //A list of fields to include in the results.
+ 'select_fields' => $requestedInfos,
+ //The maximum number of results to return.
+ 'max_results' => 1,
+ 'wl_list_max_entries_per_page' => 2,
+ //If deleted records should be included in results.
+ 'deleted' => 0,
+ //If only records marked as favorites should be returned.
+ 'favorites' => false,
+ );
+
+ $json = json_encode($get_entry_list_parameters);
+
+ $postArgs = array(
+ 'method' => 'get_entry_list',
+ 'input_type' => 'JSON',
+ 'response_type' => 'JSON',
+ 'rest_data' => $json,
+ );
+
+ $postArgs = http_build_query($postArgs);
+
+ // Make the REST call, returning the result
+ $response = $this -> callRest($this -> url, $postArgs);
+
+ // Convert the result from JSON format to a PHP array
+ //$result = json_decode($response);
+
+ return $response;
+ }
+
+}
+
+
+/*
+
+
+echo "Liste des clients :";
+
+?>
+<table>
+ <tr>
+ <th>Nom</th>
+ <th>Adresse</th>
+ <th>Tel</th>
+ </tr>
+ <?php foreach($result->entry_list as $account) { ?>
+ <tr>
+ <?php echo "<td>".$account->name_value_list->name->value."</td>"; ?>
+ <?php echo "<td>".$account->name_value_list->billing_address_street->value."</td>"; ?>
+ <?php echo "<td>".$account->name_value_list->phone_office->value."</td>"; ?>
+ </tr>
+ <?php } ?>
+</table>
+<?php
+*/
+
+/*
+$get_entry_list_parameters = array(
+ //session id
+ 'session' => $sessionId,
+ //The name of the module from which to retrieve records
+ 'module_name' => 'Opportunities',
+ //The SQL WHERE clause without the word "where".
+ 'query' => "",//"accounts.name = 'SDIS 40'",
+ //The SQL ORDER BY clause without the phrase "order by".
+ 'order_by' => "",
+ //The record offset from which to start.
+ 'offset' => 0,
+ //A list of fields to include in the results.
+ 'select_fields' => array(
+ //'id',
+ 'name',
+ 'date_closed',
+ 'account_name'
+ ),*/
+ //A list of link names and the fields to be returned for each link name.
+ /*'link_name_to_fields_array' => array(
+ array(
+ 'name' => 'email_addresses',
+ 'value' => array(
+ 'email_address',
+ 'opt_out',
+ 'primary_address'
+ ),
+ ),
+ ),*/
+ //The maximum number of results to return.
+ /*'max_results' => 1,
+ 'wl_list_max_entries_per_page' => 1,
+ //If deleted records should be included in results.
+ 'deleted' => 0,
+ //If only records marked as favorites should be returned.
+ 'favorites' => false,
+);
+
+$json = json_encode($get_entry_list_parameters);
+
+$postArgs = array(
+ 'method' => 'get_entry_list',
+ 'input_type' => 'JSON',
+ 'response_type' => 'JSON',
+ 'rest_data' => $json,
+);
+
+$postArgs = http_build_query($postArgs);
+
+// Make the REST call, returning the result
+$response = $client->callRest($url, $postArgs);
+
+// Convert the result from JSON format to a PHP array
+$result = json_decode($response);
+
+echo "Liste des fiches d'installation :";
+
+?>
+<table>
+ <tr>
+ <th>Nom</th>
+ <th>Date de fin</th>
+ <th>Nom du compte</th>
+ </tr>
+ <?php foreach($result->entry_list as $opportunity) { ?>
+ <tr>
+ <?php echo "<td>".$opportunity->name_value_list->name->value."</td>"; ?>
+ <?php echo "<td>".$opportunity->name_value_list->date_closed->value."</td>"; ?>
+ <?php echo "<td>".$opportunity->name_value_list->account_name->value."</td>"; ?>
+ </tr>
+ <?php } ?>
+</table>
+}*/
\ No newline at end of file