Ajout de l'encours lors de la mise sous surveillance score, issue #0000183

This commit is contained in:
Michael RICOIS 2010-04-08 14:49:06 +00:00
parent ea21b0b675
commit 8300f43049
3 changed files with 73 additions and 57 deletions

View File

@ -12,7 +12,6 @@ function assocSourceDroit()
'dirigeants' => 'survdirigeants', 'dirigeants' => 'survdirigeants',
'privileges' => 'survpriv', 'privileges' => 'survpriv',
); );
} }
function assocSourceTxt() function assocSourceTxt()
@ -77,7 +76,7 @@ function formSurveillance($source, $siret, $notEmail, $inDialog = false)
$output.= '<input name="formSurv[source]" '. $output.= '<input name="formSurv[source]" '.
'type="hidden" value="'.$source.'"/>'."\n"; 'type="hidden" value="'.$source.'"/>'."\n";
} }
//Champ référence
$ref = ''; $ref = '';
if(isset($_REQUEST['ref'])){ if(isset($_REQUEST['ref'])){
$ref = $_REQUEST['ref']; $ref = $_REQUEST['ref'];
@ -90,6 +89,22 @@ function formSurveillance($source, $siret, $notEmail, $inDialog = false)
'value="'.$ref.'" size="10"/></div>'."\n"; 'value="'.$ref.'" size="10"/></div>'."\n";
$output.= '</div>'."\n"; $output.= '</div>'."\n";
//Champ spécial suivant source
$encours = '';
if(isset($_REQUEST['encours'])){
$encours = $_REQUEST['encours'];
}
if ($source=='score'){
$output.= '<div id="survForm">'."\n";
$output.= '<div class="fieldgrp">'."\n";
$output.= '<label class="StyleInfoLib">Votre encours</label>';
$output.= '<div class="field">';
$output.= '<input class="longfield" name="formSurv[encours]" '.
'type="text" value="'.$encours.'" size="10"/></div>'."\n";
$output.= '</div>'."\n";
}
//Champ email
$email = ''; $email = '';
if( !in_array($_SESSION['tabInfo']['login'],$notEmail) && if( !in_array($_SESSION['tabInfo']['login'],$notEmail) &&
!isset($_REQUEST['email'])){ !isset($_REQUEST['email'])){
@ -135,15 +150,14 @@ function getSurveillance($source, $siret){
$assocSourceDroit = assocSourceDroit(); $assocSourceDroit = assocSourceDroit();
$return = ''; $return = '';
$notEmail = array('testreunica', 'reunicacsf'); $notEmail = array('testreunica', 'reunicacsf');
if(!empty($source) && array_key_exists($source, $assocSourceDroit) && if (!empty($source) &&
preg_match('/\b'.$assocSourceDroit[$source].'\b/i', array_key_exists($source, $assocSourceDroit) &&
$_SESSION['tabInfo']['droits'])){ hasPerm($assocSourceDroit[$source]) ){
if( preg_match('/\bvoirsurv\b/i', $_SESSION['tabInfo']['pref']) && if( hasPref('voirsurv') && inSurveillance($source, $siret)){
inSurveillance($source, $siret)){ $return = '<br/>L\'entité est sous surveillance.'."\n";
$return = '<br/>L\'entité est sous surveillance.'."\n"; }else{
}else{ $return = formSurveillance($source, $siret, $notEmail);
$return = formSurveillance($source, $siret, $notEmail); }
}
}else{ }else{
$return = formSurveillance('', $siret, $notEmail); $return = formSurveillance('', $siret, $notEmail);
} }
@ -161,12 +175,9 @@ function getSurveillance($source, $siret){
* true or false * true or false
*/ */
function inSurveillance($source, $siret){ function inSurveillance($source, $siret){
global $client, $firephp; global $client;
$firephp->log($source, 'source');
$firephp->log($siret, 'siret');
try{ try{
$result = $client->getSurveillances($siret,$source); $result = $client->getSurveillances($siret,$source);
$firephp->log($result['results']['reponses'], 'response');
if(count($result['results']['reponses'])>0 ){ if(count($result['results']['reponses'])>0 ){
$find = FALSE; $find = FALSE;
if(strlen($siret)>9) $siret = substr($siret, 0, 9); if(strlen($siret)>9) $siret = substr($siret, 0, 9);
@ -190,32 +201,43 @@ function inSurveillance($source, $siret){
*/ */
function setSurveillance($tabForm) function setSurveillance($tabForm)
{ {
global $client, $firephp; global $client;
$siret = $tabForm['siret']; $siret = $tabForm['siret'];
$email = $tabForm['email']; $email = $tabForm['email'];
$ref = $tabForm['ref']; $ref = $tabForm['ref'];
$source = $tabForm['source']; $source = $tabForm['source'];
$firephp->log($tabForm,'tabForm'); isset($tabForm['encours']) && !empty($tabForm['encours']) ?
if(is_array($source)) $encours = $tabForm['encours'] : $encours = 0;
{
foreach($source as $s) //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{ try{
$result = $client->setSurveillance($siret, $email, $ref, $s); $result = $client->setSurveillance($siret, $email, $ref, $s,
$firephp->log($s, 'Surveillance'); false, $encours);
FB::log($s, 'Surveillance');
$result = '';
}catch(SoapFault $fault){ }catch(SoapFault $fault){
$firephp->log($fault,'fault'); FB::log($fault,'fault');
$result = false; $result = false;
} }
} }
}
else //Mise en surveillance pour une source
{ } else {
try{ try{
$result = $client->setSurveillance($siret, $email, $ref, $source); $result = $client->setSurveillance($siret, $email, $ref, $source,
$firephp->log($source, 'Surveillance seul'); false, $encours);
}catch(SoapFault $fault){ FB::log($source, 'Surveillance seul');
$firephp->log($fault,'fault'); $result = '';
}catch (SoapFault $fault){
FB::log($fault,'fault');
$result = false; $result = false;
} }
} }
@ -237,17 +259,11 @@ function setSurveillance($tabForm)
* Retourne la réponse du webservice ou false * Retourne la réponse du webservice ou false
*/ */
function deleteSurveillance($siret, $email, $ref, $source){ function deleteSurveillance($siret, $email, $ref, $source){
global $client, $firephp; global $client;
$firephp->log($siret, 'siret');
$firephp->log($email, 'email');
$firephp->log($ref, 'ref');
$firephp->log($source, 'source');
try{ try{
$result = $client->setSurveillance($siret, $email, $ref, $source, TRUE); $result = $client->setSurveillance($siret, $email, $ref, $source, TRUE);
$firephp->log('Suppression surveillance');
return TRUE; return TRUE;
}catch(SoapFault $fault){ }catch(SoapFault $fault){
$firephp->log($fault,'fault');
return FALSE; return FALSE;
} }
} }

View File

@ -41,14 +41,16 @@ $(document).ready(function(){
$(":button:contains('"+button+"')").attr('disabled','disabled'); $(":button:contains('"+button+"')").attr('disabled','disabled');
} }
var href = $(location).attr('href'); var href = $(location).attr('href');
var data = $("#frmSurv").serialize(); var serData = $("#frmSurv").serialize();
$("#frmSurv").replaceWith('<div id="frmSurv">Mise sous surveillance en cours...</div>'); $("#frmSurv").replaceWith('<div id="frmSurv">Mise sous surveillance en cours...</div>');
$.post('./pages/ajax_surveillance.php', data, $.post('./pages/ajax_surveillance.php', serData,
function(data, textStatus) { function(data) {
$('#frmSurv').html(data); if(data==''){
if(textStatus == 'success'){ $('#frmSurv').html("L'entité a été placé sous surveillance.\n");
$(location).attr('href', href); $(location).attr('href', href);
} }else{
$('#frmSurv').html(data);
}
}); });
}, },
Annuler: function() { $(this).dialog('close'); } Annuler: function() { $(this).dialog('close'); }

View File

@ -1,7 +1,7 @@
<?php <?php
require_once 'surveillance/surveillance.php'; require_once 'surveillance/surveillance.php';
$client = new SoapClient(null, array( $client = new SoapClient(null, array(
'trace' => 1, 'trace' => 1,
'soap_version' => SOAP_1_1, 'soap_version' => SOAP_1_1,
'location' => WEBSERVICE_URL, 'location' => WEBSERVICE_URL,
@ -12,13 +12,14 @@ $client = new SoapClient(null, array(
if($_REQUEST['q']=='setsurv') if($_REQUEST['q']=='setsurv')
{ {
$firephp->log($_REQUEST['formSurv'],'formSurv'); $set = setSurveillance($_REQUEST['formSurv']);
$set = setSurveillance($_REQUEST['formSurv']); FB::log($set, 'set');
$firephp->log($set, 'set'); if($set==''){
if($set!==false){ $return = '';
$return = '<br/>L\'entité a été placé sous surveillance.'."\n"; }elseif ($set===false){
$return = 'Erreur : Mise sous surveillance impossible.'."\n";
}else{ }else{
$return = '<br/>Une erreur a rendu impossible la mise sous surveillance.'."\n"; $return = 'Erreur : '.$set."\n";
} }
} }
elseif($_REQUEST['q']=='getsurv') elseif($_REQUEST['q']=='getsurv')
@ -27,12 +28,9 @@ elseif($_REQUEST['q']=='getsurv')
} }
elseif($_REQUEST['q']=='ajouter') elseif($_REQUEST['q']=='ajouter')
{ {
$firephp->log($_REQUEST, 'REQUEST');
$siret = $_REQUEST['siret']; $siret = $_REQUEST['siret'];
$source = ( isset($_REQUEST['source']) && !empty($_REQUEST['source']) ) ? $source = ( isset($_REQUEST['source']) && !empty($_REQUEST['source']) ) ?
$_REQUEST['source'] : '' ; $_REQUEST['source'] : '' ;
$return = formSurveillance($source, $siret, array(), true); $return = formSurveillance($source, $siret, array(), true);
} }
echo $return; echo $return;
exit;
?>