extranet/includes/surveillance/surveillance.php

193 lines
5.9 KiB
PHP
Raw Normal View History

2009-05-20 15:49:08 +00:00
<?php
/**
* Affiche le formulaire surveillance.
*
* @param string $page
* La page ou l'on affiche le formulaire, d<EFBFBD>termine le type de surveillance.
* @param string $siret
* L'<EFBFBD>tablissement <EFBFBD> surveiller.
* @param array $notEmail
* Un tableau de login pour exclure l'affichage de l'adresse email
* @return string
* Retourne sous forme de chaine de caract<EFBFBD>re le fomulaire en HTML
*/
function formSurveillance($source, $siret, $notEmail, $displayAjax = TRUE){
$assocSourceTxt = array(
'annonces' => 'les annonces l<>gales',
2009-05-22 12:26:07 +00:00
'insee' => 'les <20>v<EFBFBD>nements INSEE',
2009-05-20 15:49:08 +00:00
'bilans' => 'les bilans',
2009-05-22 12:26:07 +00:00
'score' => 'IndiScore',
2009-05-20 15:49:08 +00:00
);
$fileStyle = 'style.css';
$fileJs = 'script.js';
if($displayAjax){
$fileStyle = 'style-ajax.css';
2009-05-22 09:53:48 +00:00
$fileJs = 'script-ajax.js';
2009-05-20 15:49:08 +00:00
}
$style = file_get_contents(realpath(dirname(__FILE__)).'/'.$fileStyle);
$js = file_get_contents(realpath(dirname(__FILE__)).'/'.$fileJs);
$formHTML = '';
$formHTML.= '<script type="text/javascript" src="./js/jquery.form.js"></script>'."\n";
$formHTML.= '<script type="text/javascript">'.$js.'</script>'."\n";
$formHTML.= '<style type="text/css">'.$style.'</style>'."\n";
$formHTML.= '<form id="frmSurv" name="frmSurv" action="./pages/ajax_surveillance.php" method="POST">';
2009-05-22 12:26:07 +00:00
if($displayAjax){
$formHTML.= '<input name="surveillance" type="checkbox"/> Mettre sous surveillance '.$assocSourceTxt[$source].'<br/>';
}
2009-05-20 15:49:08 +00:00
$formHTML.= '<input name="q" type="hidden" value="setsurv"/>';
$formHTML.= '<input name="formSurv[siret]" type="hidden" value="'.$siret.'"/>';
$formHTML.= '<input name="formSurv[source]" type="hidden" value="'.$source.'"/>';
$ref='';
if(isset($_REQUEST['ref'])){
$ref = $_REQUEST['ref'];
}
2009-05-20 15:49:08 +00:00
$formHTML.= '<div id="survForm">';
$formHTML.= '<div class="fieldgrp">';
$formHTML.= '<label class="StyleInfoLib">Votre r<>f<EFBFBD>rence</label><div class="field"><input name="formSurv[ref]" type="text" value="'.$ref.'" size="10"/></div>';
2009-05-20 15:49:08 +00:00
$formHTML.= '</div>';
2009-05-20 15:49:08 +00:00
$email = '';
if(!in_array($_SESSION['tabInfo']['login'],$notEmail) && !isset($_REQUEST['email'])){
2009-05-20 15:49:08 +00:00
$email = $_SESSION['tabInfo']['email'];
}elseif(isset($_REQUEST['email'])){
$email = $_REQUEST['email'];
2009-05-20 15:49:08 +00:00
}
$formHTML.= '<div class="fieldgrp">';
$formHTML.= '<label class="StyleInfoLib">Adresse email du destinataire</label><div class="field"><input name="formSurv[email]" type="text" value="'.$email.'" size="20"/></div>';
$formHTML.= '</div>';
$formHTML.= '<div class="submit"><p class="submit-button">';
$formHTML.= '<input class="submit" type="image" src="./img/boutton_valider_off.gif" name="submit" onmouseover="this.src=\'./img/boutton_valider_on.gif\'" onmouseout="this.src=\'./img/boutton_valider_off.gif\'" title="Mettre sous surveillance...">';
$formHTML.= '</p></div>';
$formHTML.= '</div>';
$formHTML.= '</form>';
return $formHTML;
}
/**
* G<EFBFBD>re la d<EFBFBD>tection des droits et des pr<EFBFBD>f<EFBFBD>rences pour l'affichage de la surveillance.
*
* @param string $page
* La page ou l'on affiche le formulaire, d<EFBFBD>termine le type de surveillance.
* @param string $siret
* L'<EFBFBD>tablissement <EFBFBD> surveiller.
* @return void
*/
function getSurveillance($page, $siret){
global $client;
global $firephp;
$assocPageDroit = array(
'annonces' => 'survannonce',
'evenements' => 'survinsee',
'liasse' => 'survbilan',
'indiscore' => 'survscore',
);
$assocPageSource = array(
'annonces' => 'annonces',
'evenements' => 'insee',
'liasse' => 'bilans',
'indiscore' => 'score',
);
$firephp->log($_SESSION,'SESSION');
if(preg_match('/'.$assocPageDroit[$page].'/i', $_SESSION['tabInfo']['droits'])){
if(preg_match('/voirsurv/i', $_SESSION['tabInfo']['pref']) && inSurveillance($assocPageSource[$page], $siret)){
$return = '<br/>L\'entit<69> est sous surveillance.'."\n";
2009-05-20 15:49:08 +00:00
}else{
$notEmail = array('testreunica', 'reunicacsf');
2009-05-22 12:26:07 +00:00
$return = formSurveillance($assocPageSource[$page], $siret, $notEmail);
2009-05-20 15:49:08 +00:00
}
}
return $return;
}
/**
* V<EFBFBD>rifie si l'<EFBFBD>tablissement est en surveillance
*
* @param string $source
* Le type de surveillance.
* @param string $siret
* L'<EFBFBD>tablissement surveill<EFBFBD>.
* @return boolean
* true or false
*/
function inSurveillance($source, $siret){
global $client;
global $firephp;
$firephp->log('inSurveillance');
try{
$result = $client->getSurveillances($siret,$source);
$firephp->log($result,'result');
if(count($result['results'])>0 ){
$find = FALSE;
if(strlen($siret)>9) $siret = substr($siret, 0, 9);
foreach($result['results'] as $item){
if($item['siren'] == $siret){ $find = TRUE; }
}
return $find;
}else{ return false; }
2009-05-20 15:49:08 +00:00
}catch(SoapFault $fault){
return false;
}
}
2009-05-22 12:26:07 +00:00
/**
* Envoi la surveillance au webservice
*
* @param array $tabForm
* Le type de surveillance.
* @return mixed
* Retourne la r<EFBFBD>ponse du webservice ou false
*/
2009-05-20 15:49:08 +00:00
function setSurveillance($tabForm){
global $client;
global $firephp;
2009-05-22 12:26:07 +00:00
$firephp->log($tabForm,'tabForm');
2009-05-20 15:49:08 +00:00
$siret = $tabForm['siret'];
$email = $tabForm['email'];
$ref = $tabForm['ref'];
$source = $tabForm['source'];
$message = '';
try{
$result = $client->setSurveillance($siret, $email, $ref, $source);
$firephp->log('Mise sous surveillance OK');
return $result;
}catch(SoapFault $fault){
$firephp->log($fault,'fault');
return false;
2009-05-20 15:49:08 +00:00
}
}
2009-05-22 12:26:07 +00:00
/**
* Supprime la surveillance
*
* @param string $siret
* L'<EFBFBD>tablissement surveill<EFBFBD>.
* @param $email
* L'email enregistr<EFBFBD> pour la surveillance
* @param $ref
* La r<EFBFBD>f<EFBFBD>rence ajout<EFBFBD> pour cette surveillance
* @param $source
* La source pour cette surveillance
* @return mixed
* Retourne la r<EFBFBD>ponse du webservice ou false
*/
2009-05-20 15:49:08 +00:00
function deleteSurveillance($siret, $email, $ref, $source){
global $client;
global $firephp;
try{
$result = $client->setSurveillance($siret, $email, $ref, $source, TRUE);
$firephp->log('Suppression surveillance');
2009-05-25 13:19:02 +00:00
return TRUE;
2009-05-20 15:49:08 +00:00
}catch(SoapFault $fault){
$firephp->log($fault,'fault');
return FALSE;
}
}
?>