SAASADMIN; if ( $SAASADMIN -> LOGIN <> '' && $SAASADMIN -> URL <> '' ) { $_ENV['masterConfigName'] = $SAASADMIN -> MASTER_NAME_CONFIG; $_ENV['login'] = $SAASADMIN -> LOGIN; $_ENV['url'] = $SAASADMIN -> URL; $_ENV['sslCert'] = $SAASADMIN -> SSL_CERT; $_ENV['webPort'] = $SAASADMIN -> WEB_PORT; $_ENV['urlProxy'] = $SAASADMIN -> URL_PROXY; $_ENV['userProxy'] = $SAASADMIN -> USER_PROXY; $_ENV['authTypeProxy'] = $SAASADMIN -> AUTH_TYPE_PROXY; $_ENV['typeProxy'] = $SAASADMIN -> TYPE_PROXY; $_ENV['forceHttp10'] = ((string) $SAASADMIN->FORCE_HTTP_10) === "true" ? true : false; $_ENV['mccPath'] = $SAASADMIN -> MCC_PATH; } else { die("saasadmin.xml not well formed ! \r\n"); } } //var_dump($_ENV['saasadmin']);exit; } /** * Retrieve form with curl api */ function retrieveCustoms() { require_once('class_http_request.php'); try { $http = new HTTPQuery($_ENV['url']); setHttpVersion($http); $http->addPostData('login', $_ENV['login']); if ($_ENV['webPort'] <> "") { $http->CURLOPT_PORT = "'" . $_ENV['webPort'] . "'"; } if (file_exists($_ENV['sslCert'])) { //SSL verif with certificate on the server $http->CURLOPT_CAINFO = $_ENV['sslCert']; $http->CURLOPT_SSL_VERIFYPEER = FALSE; } if ($_ENV['urlProxy'] <> "" ) { $http->CURLOPT_RETURNTRANSFER = 1; $http->CURLOPT_HTTPPROXYTUNNEL = 1; $http->CURLOPT_PROXY = "'" . $_ENV['urlProxy'] . "'"; if ($_ENV['userProxy'] <> "") { $http->CURLOPT_PROXYUSERPWD = "'" . $_ENV['userProxy'] . "'"; } if ($_ENV['authTypeProxy'] <> "") { $http->CURLOPT_PROXYAUTH = "'" . $_ENV['authTypeProxy'] . "'"; } if ($_ENV['typeProxy'] <> "") { $http->CURLOPT_PROXYTYPE = "'" . $_ENV['typeProxy'] . "'"; } } //the request $response = $http->doRequest(); //echo $response; $customs = explode(';', $response); //var_dump($customs); return $customs; } catch (Exception $e) { die($e->getMessage()); } } /** * Configure cURL to use HTTP 1.0 version. * HTTP 1.0 is forced if and only if the variable $_ENV['forceHttp10'] * is equal to the boolean "true". any other value lets cURL deccide * which version to use. * * @param &$http a reference to the request object to modify * if neccessary */ function setHttpVersion(&$http) { if ($_ENV['forceHttp10'] === true) { $http->CURLOPT_HTTP_VERSION = CURL_HTTP_VERSION_1_0; } } /* * The on change action on combo return value selected * @param $combobox * @param $type string * @param $fieldId string * @param $showId string * @param $tabValues array * @param $returnId bolean */ function onChange($combobox, $type, $fieldId, $showId, $tabValues, $returnId = true, $wnd) { $id =''; $selection = $combobox->get_active_text(); $id = array_search($selection, $tabValues); $wnd->deiconify(); $_ENV['tabValues'][$fieldId] = $id; createServerXml($selection); createClientXml($selection); $command = $_ENV['mccPath'] . 'tools' . DIRECTORY_SEPARATOR . 'php-gtk2'. DIRECTORY_SEPARATOR . 'php.exe ' . $_ENV['mccPath'] . DIRECTORY_SEPARATOR . 'mcc_client.php ' . $_ENV['mccPath'] . 'tmp' . DIRECTORY_SEPARATOR . 'config_' . $selection . '.xml ' . $_ENV['pathToImg'] . ' > result.txt'; $execError = ''; exec($command, $tmpCmd, $execError); if ($execError > 0) { $response = 'KO'; } exit; } /** * Create xml config file for the server */ function createServerXml($customId) { require_once('class_http_request.php'); try { $http = new HTTPQuery($_ENV['url']); setHttpVersion($http); $http->addPostData('customId', $customId); if ($_ENV['webPort'] <> "") { $http->CURLOPT_PORT = "'" . $_ENV['webPort'] . "'"; } if (file_exists($_ENV['sslCert'])) { //SSL verif with certificate on the server $http->CURLOPT_CAINFO = $_ENV['sslCert']; $http->CURLOPT_SSL_VERIFYPEER = FALSE; } if ($_ENV['urlProxy'] <> "" ) { $http->CURLOPT_RETURNTRANSFER = 1; $http->CURLOPT_HTTPPROXYTUNNEL = 1; $http->CURLOPT_PROXY = "'" . $_ENV['urlProxy'] . "'"; if ($_ENV['userProxy'] <> "") { $http->CURLOPT_PROXYUSERPWD = "'" . $_ENV['userProxy'] . "'"; } if ($_ENV['authTypeProxy'] <> "") { $http->CURLOPT_PROXYAUTH = "'" . $_ENV['authTypeProxy'] . "'"; } if ($_ENV['typeProxy'] <> "") { $http->CURLOPT_PROXYTYPE = "'" . $_ENV['typeProxy'] . "'"; } } //the request $response = $http->doRequest(); } catch (Exception $e) { die($e->getMessage()); } } function createClientXml($customId) { $master = $_ENV['mccPath'] . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $_ENV['masterConfigName']; $newXml = $_ENV['mccPath'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'config_' . $customId . '.xml'; copy($master, $newXml); $content = file_get_contents($newXml); $content = str_replace('{{custom_id}}', $customId, $content); file_put_contents($newXml, $content); } /** * Creation of a window with a form */ function createWindowForm() { //Create the window $wnd = new GtkWindow(); //Table for fields $tbl = new GtkTable(); //Title $wnd->set_title('selection du client'); //Position, center or not $wnd->set_position(Gtk::WIN_POS_CENTER); //Size of the window $wnd->set_size_request(900, 450); //Fields $row = 0; $entry = array(); $buffer = array(); $tabValues = array(); $saveTab = array(); $type = (string) $input->type; $mandatory = (string) $input->mandatory; $fieldId = (string) $input->id; $fieldLabel = 'custom'; $label = new GtkLabel($fieldLabel . ' : '); $defaultValueId = ''; //Create the array for the selected, typed values $_ENV['tabValues'][$fieldId] = array(); $values = array(); $i = 0; $customs = array(); $customs = retrieveCustoms(); $saveTab[$fieldId] = array(); //construct customs array for ($i=0;$i '') { $values[$i]['id'] = $customs[$i]; $values[$i]['label'] = $customs[$i]; } } $i = 0; for ($i=0;$i '') { $tabValues[$values[$i]['id']] = $customs[$i]; //Sauvegarder le tableau dans un tableau global $saveTab[$values[$i]['id']] = $customs[$i]; } } $entry[$fieldId] = new GtkComboBox(); $listStore = new GtkListStore(Gobject::TYPE_STRING);// Create a model $entry[$fieldId]->set_model($listStore); $cellRenderer = new GtkCellRendererText(); $entry[$fieldId]->pack_start($cellRenderer); $entry[$fieldId]->set_attributes($cellRenderer, 'text', 0); foreach ($tabValues as $key => $strVal) { $listStore->append(array($strVal)); } $entry[$fieldId]->connect('changed', 'onChange', $type, $fieldId, $showId, $saveTab[$fieldId], true, $wnd); //Rajouter l'argument false pour recuperer le libellé a la place de l'id $alignment = new GtkAlignment(1, .5, 0, 0); // Alignment $alignment->add($label); $tbl->attach($alignment, 0, 1, $row, $row+1); $tbl->attach($entry[$fieldId], 1, 2, $row, $row+1); //Mandatory red asterix $mandatoryLabel = new GtkLabel(); if ($mandatory == "true") { $mandatoryLabel->set_markup('*'); $_ENV['tabMandatory'][$fieldId] = $fieldLabel; } $mandatoryAlignment = new GtkAlignment(0, .5, 0, 0); // $mandatoryAlignment->add($mandatoryLabel); $tbl->attach($mandatoryAlignment, 2, 3, $row, $row+1); ++$row; //Close the main loop when the window is destroyed $wnd->connect_simple('destroy', array('gtk', 'main_quit')); //Send data button //$btnLaunchMaarch = new GtkButton('_Valider'); //Cancel button $btnCancel = new GtkButton('_Annuler'); //Add an image $img = GtkImage::new_from_file($_ENV['mccPath'] . 'mcc_logo.gif'); //Create a new continuous progress bar $progressBar = new GtkProgressBar(); //Destroy the window when the user clicks Cancel $btnCancel->connect_simple('clicked', array($wnd, 'destroy')); //Call the launchMaarchWithForm function when the user clicks on click //$btnLaunchMaarch->connect_simple('clicked', 'launchMaarchWithForm', $wnd, $fields, $entry, $buffer); //Add the buttons to a button box $bbox = new GtkHButtonBox(); $bbox->set_layout(Gtk::BUTTONBOX_EDGE); //$bbox->add($btnLaunchMaarch); $bbox->add($btnCancel); //Add the table and the button box to a vbox $vbox = new GtkVBox(); $vbox->pack_start($img); $vbox->pack_start($tbl); $vbox->pack_start($bbox); //Add the vbox to the window $wnd->add($vbox); //Show all widgets $wnd->show_all(); } $conf = $argv[1]; if (!file_exists($conf)) { die ('The read of the configuration file has been stopped by saasadmin_client (Xml Error)'); } loadConfig($conf); if(file_exists($argv[2]) && !(is_dir($argv[2]))) { $_ENV['pathToImg'] = $argv[2]; } createWindowForm(); //Start the main loop Gtk::main();