// RÉCUPÉRATION DES INSTANCES
$instances = $this->Instance->find('all');
- // RECUPERATION DE L'HISTORIQUE DE CHAQUE INSTANCE
+ // RECUPERATION DES INFOS DE CHAQUE INSTANCE
$historiques = array();
$totalAlertes = array();
+ $clients = array();
foreach($instances as $instance) {
+ // RECUPERATION DE L'HISTORIQUE
$historique = $historiquesController->Historique->findById($instance['Instance']['historique']);
if ($historique) {
// RÉCUPÉRATION DES ALERTES DE L'HISTORIQUE
// AJOUT DANS LA LISTE DES HISTORIQUES
$historiques[$instance['Instance']['id']] = $historique;
}
+ // RECUPERATION DU NOM DU CLIENT
+ $reference = str_replace("/", "\\/", $instance['Instance']['reference']);
+ $url = 'http://allo_serveur/?action=get_client&reference='.$reference;
+ $options = array("http" => array("method" => "GET"));
+ $context = stream_context_create($options);
+ $client = file_get_contents($url, false, $context);
+ if ($client) {
+ $clients[$instance['Instance']['id']] = $client;
+ }
}
// ENVOI DES DONNÉES À LA VUE
'historiques' => $historiques,
'_serialize' => array('historiques')
));
+ $this->set(array(
+ 'clients' => $clients,
+ '_serialize' => array('clients')
+ ));
$this->set(array(
'totalAlertes' => $totalAlertes,
'_serialize' => array('totalAlertes')
<tr>
<th>Référence</th>
<th>Produit</th>
+ <th>Client</th>
<th>Version</th>
<th>Alertes</th>
<th>Actions</th>
<tr>
<td><?php echo $instance['Instance']['reference']; ?></td>
<td><?php echo $instance['Instance']['nom']; ?></td>
+
+ <?php if(array_key_exists($instance['Instance']['id'], $clients)) {
+ $client = $clients[$instance['Instance']['id']]; ?>
+ <td><?php echo $client; ?></td>
+ <?php } else { ?>
+ <td>Client pour cette instance inexistant ou introuvable</td>
+ <?php } ?>
+
<td><?php echo $instance['Instance']['version']; ?></td>
<?php if(array_key_exists($instance['Instance']['id'], $historiques)) {
###### CONFIGURATION ALLO AGENT ######
# Référence de l'instance sur ALLO
-instance_reference="AS/CANIORT_1803151450"
+instance_reference="AS/VILLESEL_67462_3003150952"
# Type d'usager (exploitant|client)
usager_type="client"
# Type d'instance (qualif|prod)
-instance_type="prod"
+instance_type="qualif"
# Fqdn interne
instance_fqdn_interne="api_test"
# Fqdn externe
HTTP/1.1 200 OK\r
-Date: Mon, 23 Mar 2015 05:27:39 GMT\r
+Date: Mon, 30 Mar 2015 07:53:30 GMT\r
Server: Apache/2.2.22 (Ubuntu)\r
X-Powered-By: PHP/5.3.10-1ubuntu3.16\r
Access-Control-Allow-Origin: *\r
--- /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
\r
require_once('protected/required.php'); \r
header("Access-Control-Allow-Origin: *");\r
-/*\r
-//define('sugarEntry', TRUE);\r
-// specify the REST web service to interact with\r
-$url = 'http://sugar/service/v4_1/rest.php';\r
\r
-// Open a SugarHttpClient session for making the call\r
-require_once('classes/SugarHttpClient.php');\r
-$client = new SugarHttpClient();\r
-\r
-// Set the POST arguments to pass to the Sugar server\r
-$parameters = array(\r
- 'user_auth' => array(\r
- 'user_name' => 'admin',\r
- 'password' => md5('admin'),\r
- ),\r
-);\r
-\r
-$json = json_encode($parameters);\r
-\r
-$postArgs = array(\r
- 'method' => 'login',\r
- 'input_type' => 'JSON',\r
- 'response_type' => 'JSON',\r
- 'rest_data' => $json,\r
-);\r
-\r
-$postArgs = http_build_query($postArgs);\r
-\r
-// Make the REST call, returning the result\r
-$response = $client->callRest($url, $postArgs);\r
-\r
-if ( $response === false )\r
-{\r
- die("Request failed.\n");\r
-}\r
-\r
-// Convert the result from JSON format to a PHP array\r
-$result = json_decode($response);\r
-\r
-echo "<p>Devise de l'utilisateur admin : ".$result->name_value_list->user_currency_name->value."</p>";\r
-echo "<p>Format de date de l'utilisateur admin : ".$result->name_value_list->user_default_dateformat->value."</p>";\r
-\r
-if ( !is_object($result) )\r
-{\r
- die("Error handling result.\n");\r
-}\r
-\r
-if ( !isset($result->id) )\r
-{\r
- die("Error: {$result->name} - {$result->description}\n.");\r
-}\r
-\r
-// Get the session id\r
-$sessionId = $result->id;\r
-*/\r
switch ($_SERVER['REQUEST_METHOD']) {\r
case 'GET' :\r
require_once('protected/include/get.php');\r
break;\r
}\r
\r
-?>\r
echo ']';\r
}\r
break;\r
+\r
+ case 'test_sugar' :\r
+ $moduleName = 'Accounts';\r
+ $requestedInfos = array(\r
+ 'name',\r
+ 'billing_address_street',\r
+ 'phone_office',\r
+ 'officenumber_c'\r
+ );\r
+ $sugarConnector = new SugarConnector();\r
+ $sugarConnector -> login('admin', 'admin');\r
+ echo $sugarConnector -> getInfosModule($moduleName, $requestedInfos);\r
+ break;\r
+\r
+ case 'get_client' :\r
+ // LOGIN\r
+ $sugarConnector = new SugarConnector();\r
+ $sugarConnector -> login('admin', 'admin');\r
+\r
+ // RECUPÉRATION DE LA FICHE D'INSTALL DE L'INSTANCE VIA SA RÉFERENCE\r
+ $moduleName = 'Opportunities';\r
+ $requestedInfos = array('account_id');\r
+ $sqlWhereClause = "opportunities.name = '".$_GET['reference']."'";\r
+ $sqlOrderByClause = "opportunities.date_opened_c DESC";\r
+ $fiche_install_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause, $sqlOrderByClause));\r
+\r
+ // RÉCUPÉRATION DU COMPTE ASSOCIÉ VIA L'ID CLIENT DE LA FICHE D'INSTALL\r
+ $moduleName = 'Accounts';\r
+ $requestedInfos = array(\r
+ 'name',\r
+ 'billing_address_street',\r
+ 'phone_office',\r
+ 'officenumber_c'\r
+ );\r
+ $sqlWhereClause = "accounts.id = '".$fiche_install_infos->entry_list[0]->name_value_list->account_id->value."'";\r
+ $client_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));\r
+ echo $client_infos->entry_list[0]->name_value_list->name->value;\r
+ break;\r
}\r
} else { echo "Welcome sur ALLO Serveur !"; }\r
}\r
require_once('classes/manager/pdo/PdoProduitManager.php');\r
require_once('classes/manager/pdo/PdoVersionManager.php');\r
\r
+ require_once('classes/SugarHttpClient.php');\r
+ require_once('classes/SugarConnector.class.php');\r
?>
\ No newline at end of file