diff --git a/includes/surveillance/surveillance.php b/includes/surveillance/surveillance.php index cc21e7d05..ecf888d39 100644 --- a/includes/surveillance/surveillance.php +++ b/includes/surveillance/surveillance.php @@ -12,7 +12,6 @@ function assocSourceDroit() 'dirigeants' => 'survdirigeants', 'privileges' => 'survpriv', ); - } function assocSourceTxt() @@ -77,7 +76,7 @@ function formSurveillance($source, $siret, $notEmail, $inDialog = false) $output.= ''."\n"; } - + //Champ référence $ref = ''; if(isset($_REQUEST['ref'])){ $ref = $_REQUEST['ref']; @@ -90,6 +89,22 @@ function formSurveillance($source, $siret, $notEmail, $inDialog = false) 'value="'.$ref.'" size="10"/>'."\n"; $output.= ''."\n"; + //Champ spécial suivant source + $encours = ''; + if(isset($_REQUEST['encours'])){ + $encours = $_REQUEST['encours']; + } + if ($source=='score'){ + $output.= '
'."\n"; + $output.= '
'."\n"; + $output.= ''; + $output.= '
'; + $output.= '
'."\n"; + $output.= '
'."\n"; + } + + //Champ email $email = ''; if( !in_array($_SESSION['tabInfo']['login'],$notEmail) && !isset($_REQUEST['email'])){ @@ -135,15 +150,14 @@ function getSurveillance($source, $siret){ $assocSourceDroit = assocSourceDroit(); $return = ''; $notEmail = array('testreunica', 'reunicacsf'); - if(!empty($source) && array_key_exists($source, $assocSourceDroit) && - preg_match('/\b'.$assocSourceDroit[$source].'\b/i', - $_SESSION['tabInfo']['droits'])){ - if( preg_match('/\bvoirsurv\b/i', $_SESSION['tabInfo']['pref']) && - inSurveillance($source, $siret)){ - $return = '
L\'entité est sous surveillance.'."\n"; - }else{ - $return = formSurveillance($source, $siret, $notEmail); - } + if (!empty($source) && + array_key_exists($source, $assocSourceDroit) && + hasPerm($assocSourceDroit[$source]) ){ + if( hasPref('voirsurv') && inSurveillance($source, $siret)){ + $return = '
L\'entité est sous surveillance.'."\n"; + }else{ + $return = formSurveillance($source, $siret, $notEmail); + } }else{ $return = formSurveillance('', $siret, $notEmail); } @@ -161,12 +175,9 @@ function getSurveillance($source, $siret){ * true or false */ function inSurveillance($source, $siret){ - global $client, $firephp; - $firephp->log($source, 'source'); - $firephp->log($siret, 'siret'); + global $client; try{ $result = $client->getSurveillances($siret,$source); - $firephp->log($result['results']['reponses'], 'response'); if(count($result['results']['reponses'])>0 ){ $find = FALSE; if(strlen($siret)>9) $siret = substr($siret, 0, 9); @@ -190,32 +201,43 @@ function inSurveillance($source, $siret){ */ function setSurveillance($tabForm) { - global $client, $firephp; + global $client; $siret = $tabForm['siret']; $email = $tabForm['email']; $ref = $tabForm['ref']; $source = $tabForm['source']; - $firephp->log($tabForm,'tabForm'); - if(is_array($source)) - { - foreach($source as $s) - { + isset($tabForm['encours']) && !empty($tabForm['encours']) ? + $encours = $tabForm['encours'] : $encours = 0; + + //Vérification de l'encours (chiffres) + if (!preg_match('/([0-9]+)/', $encours)){ + return 'Encours incorrect'; + exit; + } + + //Mise en surveillance pour une liste de sources + if (is_array($source)){ + foreach ($source as $s){ try{ - $result = $client->setSurveillance($siret, $email, $ref, $s); - $firephp->log($s, 'Surveillance'); + $result = $client->setSurveillance($siret, $email, $ref, $s, + false, $encours); + FB::log($s, 'Surveillance'); + $result = ''; }catch(SoapFault $fault){ - $firephp->log($fault,'fault'); + FB::log($fault,'fault'); $result = false; } } - } - else - { + + //Mise en surveillance pour une source + } else { try{ - $result = $client->setSurveillance($siret, $email, $ref, $source); - $firephp->log($source, 'Surveillance seul'); - }catch(SoapFault $fault){ - $firephp->log($fault,'fault'); + $result = $client->setSurveillance($siret, $email, $ref, $source, + false, $encours); + FB::log($source, 'Surveillance seul'); + $result = ''; + }catch (SoapFault $fault){ + FB::log($fault,'fault'); $result = false; } } @@ -237,17 +259,11 @@ function setSurveillance($tabForm) * Retourne la réponse du webservice ou false */ function deleteSurveillance($siret, $email, $ref, $source){ - global $client, $firephp; - $firephp->log($siret, 'siret'); - $firephp->log($email, 'email'); - $firephp->log($ref, 'ref'); - $firephp->log($source, 'source'); + global $client; try{ $result = $client->setSurveillance($siret, $email, $ref, $source, TRUE); - $firephp->log('Suppression surveillance'); return TRUE; }catch(SoapFault $fault){ - $firephp->log($fault,'fault'); return FALSE; } } diff --git a/www/js/scripts.js b/www/js/scripts.js index c8474608f..62f33a85d 100644 --- a/www/js/scripts.js +++ b/www/js/scripts.js @@ -41,14 +41,16 @@ $(document).ready(function(){ $(":button:contains('"+button+"')").attr('disabled','disabled'); } var href = $(location).attr('href'); - var data = $("#frmSurv").serialize(); + var serData = $("#frmSurv").serialize(); $("#frmSurv").replaceWith('
Mise sous surveillance en cours...
'); - $.post('./pages/ajax_surveillance.php', data, - function(data, textStatus) { - $('#frmSurv').html(data); - if(textStatus == 'success'){ - $(location).attr('href', href); - } + $.post('./pages/ajax_surveillance.php', serData, + function(data) { + if(data==''){ + $('#frmSurv').html("L'entité a été placé sous surveillance.\n"); + $(location).attr('href', href); + }else{ + $('#frmSurv').html(data); + } }); }, Annuler: function() { $(this).dialog('close'); } diff --git a/www/pages/ajax_surveillance.php b/www/pages/ajax_surveillance.php index 8f143b638..89467d512 100644 --- a/www/pages/ajax_surveillance.php +++ b/www/pages/ajax_surveillance.php @@ -1,7 +1,7 @@ 1, 'soap_version' => SOAP_1_1, 'location' => WEBSERVICE_URL, @@ -12,13 +12,14 @@ $client = new SoapClient(null, array( if($_REQUEST['q']=='setsurv') { - $firephp->log($_REQUEST['formSurv'],'formSurv'); - $set = setSurveillance($_REQUEST['formSurv']); - $firephp->log($set, 'set'); - if($set!==false){ - $return = '
L\'entité a été placé sous surveillance.'."\n"; + $set = setSurveillance($_REQUEST['formSurv']); + FB::log($set, 'set'); + if($set==''){ + $return = ''; + }elseif ($set===false){ + $return = 'Erreur : Mise sous surveillance impossible.'."\n"; }else{ - $return = '
Une erreur a rendu impossible la mise sous surveillance.'."\n"; + $return = 'Erreur : '.$set."\n"; } } elseif($_REQUEST['q']=='getsurv') @@ -27,12 +28,9 @@ elseif($_REQUEST['q']=='getsurv') } elseif($_REQUEST['q']=='ajouter') { - $firephp->log($_REQUEST, 'REQUEST'); $siret = $_REQUEST['siret']; - $source = ( isset($_REQUEST['source']) && !empty($_REQUEST['source']) ) ? + $source = ( isset($_REQUEST['source']) && !empty($_REQUEST['source']) ) ? $_REQUEST['source'] : '' ; $return = formSurveillance($source, $siret, array(), true); } -echo $return; -exit; -?> \ No newline at end of file +echo $return; \ No newline at end of file