. */ /** * @defgroup mcc Maarch Capture Connector */ /** * mcc_client = client for Maarch Capture Connector * * @file * @author Laurent Giovanonni / Yves Christian Kpakpo * @date $date$ * @version $Revision$ * @ingroup mcc * @brief mcc_client, client for Maarch Capture Connector */ if (!class_exists('gtk')) { die("Please load the php-gtk2 module in your php.ini\r\n"); } //Error mode and function error_reporting(E_ERROR); set_error_handler(errorHandler); //Global var of the program /** * keyword of the config file on mcc server */ $_ENV['configName'] = ""; /** * maarch capture connector path */ $_ENV['mccPath'] = ""; /** * scan import path */ $_ENV['scanImportPath'] = ""; /** * url of maarch */ $_ENV['maarchUrl'] = ""; /** * url of upload file */ $_ENV['uploadUrl'] = ""; /** * url to the ws url */ $_ENV['getDatasUrl'] = ""; /** * form mode flag */ $_ENV['formMode'] = "false"; /** * mass scan flag */ $_ENV['massScan'] = "false"; /** * image format */ $_ENV['imageFormat'] = ""; /** * is for MLB flag */ $_ENV['isForMlb'] = "false"; /** * location of the database server */ $_ENV['databaseserver'] = ""; /** * port of the database server */ $_ENV['databaseport'] = 0; /** * name of the database */ $_ENV['database'] = ""; /** * type of the database */ $_ENV['databasetype'] = ""; /** * user name of the database */ $_ENV['databaseuser'] = ""; /** * password of the database */ $_ENV['databasepwd'] = ""; /** * path to the log file */ $_ENV['log'] = ""; /** * path to the file to process in no form mode */ $_ENV['fileToProcess'] = ""; /** * ssl certificate */ $_ENV['sslCert'] = ""; /** * web port */ $_ENV['webPort'] = ""; /** * path of the browser */ $_ENV['browserPath'] = ""; /** * url proxy */ $_ENV['urlProxy'] = ""; /** * user proxy */ $_ENV['userProxy'] = ""; /** * proxy authentification type */ $_ENV['authTypeProxy'] = ""; /** * proxy type */ $_ENV['typeProxy'] = ""; /** * selected values array */ $_ENV['tabValues'] = array(); /** * mandatory field array */ $_ENV['tabMandatory'] = array(); /** * Class PhpGtkEntryCompletion : contains all the autocomplete functions for selection list * * @author Yves Christian Kpakpo * @license GPL * @package Maarch Entreprise 1.0 * @version 1.0 */ class PhpGtkEntryCompletion extends GtkEntry { protected $_list; protected $_model; public $_completion; function __construct($list = null){ parent::__construct(); $this->_list = $list; $this->create(); if($this->_list !== null) $this->completion_add_words($this->_list); } protected function create(){ // Create a model $this->_model = new GtkListStore(Gobject::TYPE_STRING); // create completion entry $this->_completion = new GtkentryCompletion(); # $this->_completion->set_match_func(array($this, 'completion_match')); $this->_completion->connect('match-selected', array($this, 'completion_match_select')); $this->_completion->set_model($this->_model); $this->_completion->set_text_column(0); $this->set_completion($this->_completion); } function completion_add_word($word){ $this->_model->append(array($word)); } function completion_add_words($words){ //foreach($words as $word) foreach($words as $key => $word) $this->_model->append(array($word)); } function completion_clear(){ $this->_model->clear(); } protected function completion_match($completion, $key, $iter){ $txt = $model->get_value($iter, 0); if(strpos($key, $txt, 0) === false) return false; return true; } public function completion_match_select($completion, $model, $iter){ $txt = $model->get_value($iter, 0); $this->set_text($txt); $this->set_position(-1); } } /** * Creation of the log file */ function loginCreation() { if(!is_dir($_ENV['mccPath'].DIRECTORY_SEPARATOR."logs".DIRECTORY_SEPARATOR)) { mkdir($_ENV['mccPath'].DIRECTORY_SEPARATOR."logs".DIRECTORY_SEPARATOR,0777); } $_ENV['log'] = $_ENV['mccPath'].DIRECTORY_SEPARATOR."logs".DIRECTORY_SEPARATOR."mcc_client.log"; writeLog("Application start with : ".$_SERVER['SCRIPT_FILENAME']); } /** * Write on the log file * @param $eventInfo string text which is written in the log file */ function writeLog($eventInfo) { $logFileOpened = fopen($_ENV['log'], "a"); fwrite($logFileOpened, "[".date("d")."/".date("m")."/".date("Y")." ".date("H").":".date("i").":".date("s")."] ".$eventInfo."\r\n"); fclose($logFileOpened); } /** * Write on the log file errors * @param $eventInfo string text which is written in the log file * @param $errorLevel integer text return code of an error */ function manageError($eventInfo, $errorLevel) { $logFileOpened = fopen($_ENV['log'], "a"); fwrite($logFileOpened, "[".date("d")."/".date("m")."/".date("Y")." ".date("H").":".date("i").":".date("s")."][ERRNO]".$errorLevel."[ERRNO][ERROR]".$eventInfo."[ERROR]\r\n"); fclose($logFileOpened); echo $errorLevel." ".$eventInfo; exit($errorLevel); } /** * Managing of errors * @param $errno integer number of the error * @param $errstr string text of the error * @param $errfile string file concerned with the error * @param $errline integer line of the error * @param $errcontext string context of the error */ function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) { $string = $errstr; $search1="'xml_file_loaded'"; $search2="'Undefined offset: 2'"; preg_match($search1,$string,$out); $count=count($out[0]); if($count == 1) { $find1 = true; } preg_match($search2,$string,$out); $count=count($out[0]); if($count == 1) { $find2 = true; } if(!$find1 && !$find2) { manageError("from line ".$errline." : ". $errstr, 1); $_ENV['errorLevel'] = 1; } } /** * Return the file's extention of a file * @param $sFullPath string path of the file */ function extractFileExt($sFullPath) { $sName = $sFullPath; if($sFullPath == "") { $extractFileExt = ""; } else { $extractFileExt = explode(".", $sName); } return $extractFileExt[count($extractFileExt) - 1]; } /** * Return only name of the file path * @param $sFullPath string path of the file */ function extractFileName($sFullPath) { if($_ENV['osName'] == "UNIX") { if(!ereg(DIRECTORY_SEPARATOR, $sFullPath)) { return $sFullPath; } else { return substr($sFullPath, strrpos($sFullPath, DIRECTORY_SEPARATOR) +1); } } else { if(!ereg("\\".DIRECTORY_SEPARATOR, $sFullPath)) { return $sFullPath; } else { return substr($sFullPath, strrpos($sFullPath, DIRECTORY_SEPARATOR) +1); } } } /** * Check if multidimensional array is empty * @param $mixed array */ function array_empty($mixed) { if (is_array($mixed)) { foreach ($mixed as $value) { if (!array_empty($value)) { return false; } } } elseif (!empty($mixed)) { return false; } return true; } /** * Check if some fields are mandatory */ function mandatoryField() { //print_r($_ENV['tabMandatory']); $mandatory = false; foreach ($_ENV['tabMandatory'] as $key => $value) { if (!isset($_ENV['tabValues'][$key]) || empty($_ENV['tabValues'][$key]) || strlen(trim($_ENV['tabValues'][$key])) == 0) { $mandatory .= $value." is mandatory !\r\n"; } } return $mandatory; } /** * Loading of the xml config file * @param $conf string path to the config file */ function loadConfig($conf) { //loading of the xml config file. $xmlConfig = simplexml_load_file($conf); $CONFIG =$xmlConfig -> CONFIG; $_ENV['configName'] = $CONFIG -> CONFIG_NAME; $_ENV['mccPath'] = $CONFIG -> MCC_PATH; loginCreation(); writeLog("Loading xml config file : ".$conf); writeLog("configName : ".$_ENV['configName']); writeLog("mccPath : ".$_ENV['mccPath']); $_ENV['scanImportPath'] = $CONFIG -> SCAN_IMPORT_PATH; writeLog("scanImportPath : ".$_ENV['scanImportPath']); $_ENV['maarchUrl'] = str_replace("&", "&", $CONFIG -> MAARCH_URL); writeLog("maarchUrl : ".$_ENV['maarchUrl']); $_ENV['uploadUrl'] = $CONFIG -> UPLOAD_URL; writeLog("uploadUrl : ".$_ENV['uploadUrl']); $_ENV['getDatasUrl'] = $CONFIG -> GET_DATAS_URL; writeLog("getDatasUrl : ".$_ENV['getDatasUrl']); $_ENV['sslCert'] = $CONFIG -> SSL_CERT; writeLog("sslCert : ".$_ENV['sslCert']); $_ENV['webPort'] = $CONFIG -> WEB_PORT; writeLog("webPort : ".$_ENV['webPort']); $_ENV['browserPath'] = $CONFIG -> BROWSER_PATH; writeLog("browserPath : ".$_ENV['browserPath']); $_ENV['urlProxy'] = $CONFIG -> URL_PROXY; writeLog("urlProxy : ".$_ENV['urlProxy']); $_ENV['userProxy'] = $CONFIG -> USER_PROXY; writeLog("userProxy : ".$_ENV['userProxy']); $_ENV['authTypeProxy'] = $CONFIG -> AUTH_TYPE_PROXY; writeLog("authTypeProxy : ".$_ENV['authTypeProxy']); $_ENV['typeProxy'] = $CONFIG -> TYPE_PROXY; writeLog("typeProxy : ".$_ENV['typeProxy']); $FORM =$xmlConfig -> FORM; $_ENV['formMode'] = $FORM -> FORM_MODE; writeLog("formMode : ".$_ENV['formMode']); $_ENV['massScan'] = $FORM -> MASS_SCAN; writeLog("massScan : ".$_ENV['massScan']); $_ENV['imageFormat'] = $FORM -> IMAGE_FORMAT; writeLog("imageFormat : ".$_ENV['imageFormat']); $_ENV['isForMlb'] = $FORM -> IS_FOR_MLB; writeLog("isForMlb : ".$_ENV['isForMlb']); } /** * Browse each file and folder in the import folder and return true if the process have to continue */ function verifInputFolder() { $folder = $_ENV['scanImportPath']; $foundDoc = false; $classScan= dir($folder); while(($fileScan=$classScan->read())!=false) { if($foundDoc) { return $foundDoc; } if($fileScan=='.'||$fileScan=='..' ||$fileScan=='backup' ||$fileScan=='failed' || $fileScan == '.svn') { continue; } elseif(is_dir($folder.DIRECTORY_SEPARATOR.$fileScan)) { //Looking in the sub directories $subClassScan = dir($folder.DIRECTORY_SEPARATOR.$fileScan); while(($subFileScan=$subClassScan->read())!=false) { if($subFileScan=='.' || $subFileScan=='..' || $subFileScan == '.svn') { continue; } else { if(strtoupper(extractFileExt($subFileScan)) == $_ENV['imageFormat'] || $_ENV['imageFormat'] == "ALL") { $foundDoc = true; } else { continue; } } } } else { if(strtoupper(extractFileExt($fileScan)) == $_ENV['imageFormat'] || $_ENV['imageFormat'] == "ALL") { $foundDoc = true; } else { continue; } } } return $foundDoc; } /** * Browse each file and folder in the import folder and process each document */ function processInputFolder() { $folder = $_ENV['scanImportPath']; $classScan= dir($folder); while(($fileScan=$classScan->read())!=false) { if($fileScan=='.'||$fileScan=='..' ||$fileScan=='backup' ||$fileScan=='failed' || $fileScan == '.svn') { continue; } elseif(is_dir($folder.DIRECTORY_SEPARATOR.$fileScan)) { //Looking in the sub directories $subClassScan = dir($folder.DIRECTORY_SEPARATOR.$fileScan); while(($subFileScan=$subClassScan->read())!=false) { if($subFileScan=='.' || $subFileScan=='..' || $subFileScan == '.svn') { continue; } else { if(strtoupper(extractFileExt($subFileScan)) == $_ENV['imageFormat'] || $_ENV['imageFormat'] == "ALL") { //Process doc $_ENV['fileToProcess'] = $_ENV['scanImportPath'].$fileScan.DIRECTORY_SEPARATOR.$subFileScan; sendDocument(); } else { continue; } } } } else { if(strtoupper(extractFileExt($fileScan)) == $_ENV['imageFormat'] || $_ENV['imageFormat'] == "ALL") { //Process doc $_ENV['fileToProcess'] = $_ENV['scanImportPath'].$fileScan; sendDocument(); } else { continue; } } } } /** * This function gets called as soon as the user clicks on the launch Maarch button. * @param GtkWindow $wnd The form window, needed to close it when all is ok */ function launchMaarchWithForm(GtkWindow $wnd, $fields, $entry, $buffer) { $errors = null; //If you want to catch the text field value if (count($fields) > 0) { foreach($fields->node as $input) { $type = (string) $input->type; $fieldId = (string) $input->id; $txt = ''; if($type == 'texBox') { $txt = $entry[$fieldId]->get_text(); } elseif($type == 'texArea') { $txt = $buffer[$fieldId]->get_text($buffer[$fieldId]->get_start_iter(), $buffer[$fieldId]->get_end_iter()); } //Store the text value if (strlen(trim($txt)) > 0) { $_ENV['tabValues'][$fieldId] = $txt; } } } //print_r( $_ENV['tabValues']); exit; if ( array_empty($_ENV['tabValues'])) { $errors = "\nYou must select at least one value!\r\n"; } else { $mandatory = mandatoryField(); if($mandatory !== false) { $errors .= $mandatory; } } if($errors !== null) { //There was at least one error. //We show a message box with the errors $dialog = new GtkMessageDialog($wnd, Gtk::DIALOG_MODAL, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, $errors); $dialog->set_markup( "The following errors occured:\r\n" . "" . $errors . "" ); $dialog->run(); $dialog->destroy(); } else { if($_ENV['massScan'] == "true") { if(verifInputFolder()) { processInputFolder(); } else { //There was at least one error. //We show a message box with the errors $dialog = new GtkMessageDialog($wnd, Gtk::DIALOG_MODAL, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, $errors); $dialog->set_markup( "The following errors occured:\r\n" . "\nNo file to process in ".$_ENV['scanImportPath']."" ); $dialog->run(); $dialog->destroy(); } } elseif($_ENV['massScan'] == "false") { openMaarchApplication(); } $wnd->destroy(); } } /** * Creation of a window with a form widget tree : wnd (GtkWindow) | Gtk::main_quit() vbox(GtkVBox) img (GtkImage) : "mcc_logo.gif" tbl (GtkTable) alignment (GtkAlignment) label (GtkLabel) entry (GtkEntry, GtkComboBox, PhpGtkEntryCompletion) bbox (GtkHButtonBox) btnLaunchMaarch (GtkButton) : "Valider" | on_button() btnCancel (GtkButton) : "Annuler" | on_button() */ function createWindowForm() { //Get the form from mcc server $xmlForm = retrieveForm(); //Create the window $wnd = new GtkWindow(); //Table for fields $tbl = new GtkTable(); //Title $wnd->set_title( utf8_decode((string) $xmlForm->title)); //Position, center or not if((string) $xmlForm->center =='true') { $wnd->set_position(Gtk::WIN_POS_CENTER); } //Size of the window if( (isset($xmlForm->width) && ! empty($xmlForm->width)) && (isset($xmlForm->height) && !empty($xmlForm->height))) { $wnd->set_size_request((integer) $xmlForm->width, (integer) $xmlForm->height); } //Fields $row = 0; $fields = $xmlForm->fields; $entry = array(); $buffer = array(); if(count($fields) > 0) { foreach($fields->node as $input) { $tabValues = array(); $saveTab = array(); $type = (string) $input->type; $mandatory = (string) $input->mandatory; $fieldId = (string) $input->id; $fieldLabel = utf8_decode((string) $input->label); $label = new GtkLabel($fieldLabel.' : '); $defaultValueId = ''; //Create the array for the selected, typed values $_ENV['tabValues'][$fieldId] = array(); //List values if (isset($input->values)) { $values = $input->values; $saveTab[$fieldId] = array(); foreach($values->node as $val) { //array_push($tabValues, (string) $val->label); //array_push($tabValues, (string) $val->id.' ['.(string) $val->label.']'); //array_push($tabValues, (string) $val->label.' ['.(string) $val->id.']'); //array_push($tabValues, array((string) $val->id, (string) $val->label)); $tabValues[(string) $val->id ] = (string) utf8_decode($val->label); //Sauvegarder le tableau dans un tableau global $saveTab[$fieldId][(string) $val->id] = (string) utf8_decode($val->label); } //print_r($tabValues); } //Default value if (isset($input->default_value)) { $defaultValueId = (string) $input->default_value; } /** * Type of composant */ if ($type =='texBox') //Text box { $entry[$fieldId] = new GtkEntry(); } elseif ($type =='radioButton') //radio Button { // $precKey = null; // $arrayButton = array(); // foreach($tabValues as $key => $strVal) // { // $arrayButton[$key] = &new GtkRadioButton($precKey, $strVal); // $precKey = $arrayButton[$key]; // } // $entry[$fieldId] = $arrayButton; } elseif ($type =='texArea') //text Area { $entry[$fieldId] = new GtkTextView(); $entry[$fieldId]->set_wrap_mode(Gtk::WRAP_WORD); $buffer[$fieldId] = new GtkTextBuffer(); $entry[$fieldId]->set_buffer($buffer[$fieldId]); } elseif ($type =='comboBox') //Combo Box { //Autocomplete $autocomplete = (string) $input->autocomplete; if ($autocomplete == 'true') { $entry[$fieldId] = new PhpGtkEntryCompletion($tabValues); $entry[$fieldId]->_completion->connect('match-selected', 'completionSelect', $fieldId, $saveTab[$fieldId]); //Rajouter l'argument false pour recuperer le libellé a la place de l'id } else { $showId = (string) $input->show_id ; if ($showId == 'true') //Show the id in list { $entry[$fieldId] = new GtkComboBox(); // Create a combobox //$listStore = new GtkListStore(Gobject::TYPE_STRING);// Create a model $listStore = new GtkListStore(GObject::TYPE_STRING, GObject::TYPE_STRING); // note 1 $entry[$fieldId]->set_model($listStore); $cellRendererId = new GtkCellRendererText();// Set up the combobox $entry[$fieldId]->pack_start($cellRendererId); $entry[$fieldId]->set_cell_data_func($cellRendererId, 'formatId', 0); $cellRendererLabel = new GtkCellRendererText(); $entry[$fieldId]->pack_start($cellRendererLabel); $entry[$fieldId]->set_attributes($cellRendererLabel, 'text', 1); foreach($tabValues as $key => $strVal) { $listStore->append(array($key, $strVal)); } } else //Hide the id { $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)); } } //Default value if (isset($defaultValueId) && !empty($defaultValueId)) { foreach($listStore as $key) { //echo $key[0]." / ".$defaultValueId."\r\n"; if(($key[0] == $defaultValueId)) { $entry[$fieldId]->set_active_iter($key->iter); $_ENV['tabValues'][$fieldId] = $key[0]; break; } elseif ($defaultValueId == array_search($key[0], $saveTab[$fieldId])) { $entry[$fieldId]->set_active_iter($key->iter); $_ENV['tabValues'][$fieldId] = array_search($key[0], $saveTab[$fieldId]); break; } } } $entry[$fieldId]->connect('changed', 'onChange', $type, $fieldId, $showId, $saveTab[$fieldId]); //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 progress bar to the vbox //$vbox->pack_start($progressBar); //A timeout to be called every 200 milliseconds that updates // the progress bar //Gtk::timeout_add(200, 'updateProgressBar', $progressBar); //Add the vbox to the window $wnd->add($vbox); //Show all widgets $wnd->show_all(); } /** * Creation of a splash window */ function createWinSplash() { //Create the window $wnd = new GtkWindow(); $wnd->set_title('Maarch Capture Connector'); //Title //$wnd->set_size_request(300, 200); //Size of the window $wnd->set_position(Gtk::WIN_POS_CENTER); //Position, center $img = GtkImage::new_from_file($_ENV['mccPath'].'mcc_logo.gif'); //Add an image $vbox = new GtkVBox(); //Add a vbox $vbox->pack_start($img); //Add image to the vbox $wnd->add($vbox); //Add the vbox to the window $wnd->show_all(); //Show all widgets } /** * Format the colmn in selection list * @param $column * @param $cell * @param $model * @param $iter * @param $col_num */ function formatId($column, $cell, $model, $iter, $col_num) { $col0 = $model->get_value($iter, 0); $cell->set_property('text', $col0.' '); // note 8 } /* * 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) { $id =''; if ($type ='comboBox') { if ($showId == 'true') { $model = $combobox->get_model(); $id = $model->get_value($combobox->get_active_iter(), 0); } else { $selection = $combobox->get_active_text(); // $id = array_search($selection, $tabValues); } } $_ENV['tabValues'][$fieldId] = $id; // echo "You have selected: $id !\n"; } /** * When value in autocompletion list is selected * @param $entryCompletion * @param $treeModelFilter * @param $treeIter * @param $fieldId string * @param $tabValues array * @patam $returnId boolean */ function completionSelect($entryCompletion, $treeModelFilter, $treeIter, $fieldId, $tabValues, $returnId = true) { $selection =''; $_ENV['tabValues'][$fieldId] = ''; $entry = $entryCompletion->get_entry(); $selection = $entry->get_text(); if ($returnId) { $id =''; $id = array_search($selection, $tabValues); $_ENV['tabValues'][$fieldId] = $id; // echo "You have selected: $id !\n"; } else { $_ENV['tabValues'][$fieldId] = $selection; // echo "You have selected: $selection !\n"; } } /** * Function to update the progress bar (to be updated with file size functions) */ function updateProgressBar(GtkProgressBar $progressBar) { //The normal mode needs a certain value to be set. // Here we add 10% to the current value, resetting // it to 0 when it reaches 110% (so that we get a nice // animation) $value = $progressBar->get_fraction(); echo $value.'/'; $progressBar->set_fraction( (($progressBar->get_fraction() * 10 + 1) % 11) / 10 ); //Setting the text to the current percentage $valueText = ($value * 100) . '%'; $progressBar->set_text($valueText); //Keep the timeout running. When not returning true, //it stops. if ($value != 1) { $progressBar->set_text($valueText); return true; } } // The callback function that is called when user clicks the submit button function on_button($button, $entry) { $txt = $entry->get_text(); echo "You have selected : $txt\n"; } /** * Retrieve form with curl api */ function retrieveForm() { require_once('class_http_request.php'); try { $http = new HTTPQuery($_ENV['getDatasUrl']); $http->addPostData('configName[0]', $_ENV['configName']); if($_ENV['webPort'] <> "") { $http->CURLOPT_PORT = "'".$_ENV['webPort']."'"; } if(file_exists($_ENV['sslCert'])) { //SSL verif with certificate on the server writeLog("Use certif : ".$_ENV['sslCert']); $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; $xmlForm = simplexml_load_string($response); //echo($xmlForm); exit; return $xmlForm; } catch (Exception $e) { die($e->getMessage()); } } /** * Sending document with curl api */ function sendDocument() { require_once('class_http_request.php'); try { echo "Process file: ".$_ENV['fileToProcess']."\n"; $http = new HTTPQuery($_ENV['uploadUrl']); $http->addPostData('configName', $_ENV['configName']); //Config Id $http->addPostFile('images', $_ENV['fileToProcess']); //File (retrieve on server with $_FILES['images']['name']) $http->addPostData('md5', md5_file($_ENV['fileToProcess'])); //Md5 //fields of the form foreach($_ENV['tabValues'] as $key => $val) { $http->addPostData($key, $val); } //Mass scan if($_ENV['massScan'] == "true") { $http->addPostData('massScan', "true"); } else { $http->addPostData('massScan', "false"); } //Mlb if($_ENV['isForMlb'] == "true") { $http->addPostData('mlb', "true"); } else { $http->addPostData('mlb', "false"); } //Web Serve Port if($_ENV['webPort'] <> "") { $http->CURLOPT_PORT = "'".$_ENV['webPort']."'"; } //SSl if(file_exists($_ENV['sslCert'])) { //SSL verif with certificate on the server $http->CURLOPT_CAINFO = $_ENV['sslCert']; $http->CURLOPT_SSL_VERIFYPEER = FALSE; } //Use proxy 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']."'"; } } $http->CURLOPT_VERBOSE = 1; $http->CURLOPT_HTTPHEADER = array('Expect:'); //var_dump($_ENV); //echo $_ENV['uploadUrl']; //var_dump($http); echo $http->doRequest(); //the request //unlink($_ENV['fileToProcess']); } catch (Exception $e) { manageError($e->getMessage(), 1); die($e->getMessage()); } } /** * Retrieve properties of the sending file and prepare the url */ function retrieveProperties() { $extension = extractFileExt($_ENV['fileToProcess']); $taille_fichier = filesize($_ENV['fileToProcess']); $md5 = md5_file($_ENV['fileToProcess']); $scan_user = "user"; $scan_wkstation = "pc"; $tmp_file = "tmp_file.".$extension; $index_type = "num"; if($_ENV['isForMlb'] == "true") { $Ftp_File = "tmp_file.".$extension; $params = "?extension=".$extension."&taille_fichier=".$taille_fichier."&Ftp_File=".$Ftp_File."&md5=".$md5."&scan_user=".$scan_user."&scan_wkstation=".$scan_wkstation."&tmp_file=".$tmp_file."&index_type=".$index_type; } else { $Ftp_File = "tmp_file_".md5_file($_ENV['fileToProcess']).".".$extension; $params = "&extension=".$extension."&taille_fichier=".$taille_fichier."&Ftp_File=".$Ftp_File."&md5=".$md5."&scan_user=".$scan_user."&scan_wkstation=".$scan_wkstation."&tmp_file=".$tmp_file."&index_type=".$index_type; } return $params; } /** * Open Maarch Application with the sended file */ function openMaarchApplication() { $urlParams = retrieveProperties($_ENV['fileToProcess']); sendDocument(); writeLog("\"".$_ENV['browserPath']."\" \"".$_ENV['maarchUrl'].$urlParams."\""); if ($_ENV['browserPath']) { $command = " \"".$_ENV['browserPath']."\" \"".$_ENV['maarchUrl'].$urlParams."\""; } else { $command = " start \"".$_ENV['browserPath']."\" \"".$_ENV['maarchUrl'].$urlParams."\""; } $batFile = $_ENV["mccPath"].DIRECTORY_SEPARATOR."os_scripts".DIRECTORY_SEPARATOR."tmp_script.bat"; $inF = fopen($batFile,"w"); fwrite($inF,$command); fclose($inF); $converter_result = exec($batFile, $return_var); //unlink($batFile); } /* * fonction qui permet de transformer un objet SimpleXML en tableau */ function xml2array($xmlObject) { $return = NULL; $var = NUll; if(is_array($xmlObject)) { foreach($xmlObject as $key => $value) $return[$key] = xml2array($value); } else { if(is_object($xmlObject)) $var = get_object_vars($xmlObject); if($var) { foreach($var as $key => $value) $return[$key] = xml2array($value); } else return strval($xmlObject); // strval and everything is fine } return $return; } //begin date_default_timezone_set('Europe/Paris'); if($argc < 2 ) { die("You must specify the configuration file\r\n"); } else { $conf = $argv[1]; if(!file_exists($conf)) { die ("The read of the configuration file has been stopped by Maarch Auto Import (Xml Error)"); } loadConfig($conf); if($_ENV['formMode'] == "true") { if($_ENV['massScan'] == "false") { if($argv[2] <> "") { $_ENV['fileToProcess'] = $argv[2]; writeLog("fileToProcess : ".$_ENV['fileToProcess']); //If the file exists if(file_exists($_ENV['fileToProcess']) && !(is_dir($_ENV['fileToProcess']))) { createWindowForm(); //Start the main loop Gtk::main(); } else { manageError("File not exists : ".$_ENV['fileToProcess'], 1); } } else { manageError("No file to process in argument", 1); } } elseif($_ENV['massScan'] == "true") { sleep(2); if(is_dir($_ENV['scanImportPath'])) { createWindowForm(); //Start the main loop Gtk::main(); } else { manageError("No folder to process", 1); } } } else { if($argv[2] <> "") { $_ENV['fileToProcess'] = $argv[2]; writeLog("fileToProcess : ".$_ENV['fileToProcess']); //If the file exists if(file_exists($_ENV['fileToProcess']) && !(is_dir($_ENV['fileToProcess']))) { createWinSplash(); //create splash window openMaarchApplication(); //Open Maarch application } else { manageError("File not exists : ".$_ENV['fileToProcess'], 1); } } else { manageError("No file to process in argument", 1); } } } exit(0); ?>