extranet/includes/surveillance/surveillance.php

256 lines
6.8 KiB
PHP
Raw Normal View History

2009-05-20 15:49:08 +00:00
<?php
require_once 'user/user.php';
function assocSourceDroit()
{
return array(
'annonces' => 'survannonce',
'insee' => 'survinsee',
'bilans' => 'survbilan',
'score' => 'survscore',
'actes' => 'survactes',
'dirigeants' => 'survdirigeants',
'privileges' => 'survpriv',
);
2010-03-08 16:42:53 +00:00
}
function assocSourceTxt()
{
return array(
'annonces' => 'les annonces légales',
'insee' => 'les événements INSEE',
'bilans' => 'les bilans',
'score' => 'IndiScore',
'actes' => 'les actes &amp; status',
'dirigeants' => 'les dirigeants',
'privileges' => 'les privilèges',
);
}
2009-05-20 15:49:08 +00:00
/**
* Affiche le formulaire surveillance.
*
* @param string $page
* La page ou l'on affiche le formulaire, détermine le type de surveillance.
2009-05-20 15:49:08 +00:00
* @param string $siret
* L'établissement à surveiller.
2009-05-20 15:49:08 +00:00
* @param array $notEmail
2010-03-08 16:42:53 +00:00
* Un tableau de login pour exclure l'affichage de l'adresse email
2009-05-20 15:49:08 +00:00
* @return string
* Retourne sous forme de chaine de caractère le fomulaire en HTML
2009-05-20 15:49:08 +00:00
*/
function formSurveillance($source, $siret, $notEmail, $inDialog = false)
2010-03-08 16:42:53 +00:00
{
2009-12-17 09:40:18 +00:00
$assocSourceTxt = assocSourceTxt();
$assocSourceDroit = assocSourceDroit();
2010-03-08 16:42:53 +00:00
$style = file_get_contents(realpath(dirname(__FILE__)).'/style.css');
2010-03-08 16:42:53 +00:00
$output = '';
2010-03-08 16:42:53 +00:00
if($inDialog)
{
$output.= '<style type="text/css">'.$style.'</style>'."\n";
$output.= '<form id="frmSurv" name="frmSurv" '.
'action="./pages/ajax_surveillance.php" method="post">'."\n";
$output.= '<input name="q" type="hidden" value="setsurv"/>';
$output.= '<input name="formSurv[siret]" type="hidden" value="'.
2010-03-08 16:42:53 +00:00
$siret.'"/>'."\n";
if( empty($source) )
{
$output.= '<div class="fieldgrp">'."\n";
$output.= '<label>Types</label>'."\n";
$output.= '<div class="field">'."\n";
foreach($assocSourceTxt as $Source => $Txt)
{
if(hasPerm($assocSourceDroit[$Source]))
{
$output.='<input type="checkbox" '.
'name="formSurv[source][]" value="'.
$Source.'" checked/>&nbsp;'.$Txt."<br/>\n";
}
}
$output.= '</div>'."\n";
$output.= '</div>'."\n";
}else{
$output.= '<input name="formSurv[source]" '.
2010-03-08 16:42:53 +00:00
'type="hidden" value="'.$source.'"/>'."\n";
}
2010-03-08 16:42:53 +00:00
$ref = '';
if(isset($_REQUEST['ref'])){
$ref = $_REQUEST['ref'];
}
$output.= '<div id="survForm">'."\n";
$output.= '<div class="fieldgrp">'."\n";
$output.= '<label class="StyleInfoLib">Votre référence</label>';
$output.= '<div class="field">';
$output.= '<input class="longfield" name="formSurv[ref]" type="text" '.
'value="'.$ref.'" size="10"/></div>'."\n";
$output.= '</div>'."\n";
2010-03-08 16:42:53 +00:00
$email = '';
2010-03-08 16:42:53 +00:00
if( !in_array($_SESSION['tabInfo']['login'],$notEmail) &&
!isset($_REQUEST['email'])){
$email = $_SESSION['tabInfo']['email'];
}elseif(isset($_REQUEST['email'])){
$email = $_REQUEST['email'];
}
$output.= '<div class="fieldgrp">'."\n";
$output.= '<label class="StyleInfoLib">'.
'Adresse email du destinataire</label>';
$output.= '<div class="field">'.
'<input class="longfield" name="formSurv[email]" '.
'type="text" value="'.$email.'" size="20"/></div>'."\n";
$output.= '</div>'."\n";;
$output.= '</div>'."\n";
$output.= '</form>'."\n";
2010-03-08 16:42:53 +00:00
}else{
$output.= '<br/><a class="dialogsurv" '.
'href="./pages/ajax_surveillance.php?q=ajouter&siret='.
$siret.'&source='.$source.'" '.
'title="Ajouter la surveillance '.$source.'">'.
2010-03-26 14:27:57 +00:00
'Mettre sous surveillance ';
if( !empty($source) ) {
$output.= $assocSourceTxt[$source];
}
$output.= '</a><br/>'."\n";
2009-05-20 15:49:08 +00:00
}
return $output;
2009-05-20 15:49:08 +00:00
}
/**
2010-03-08 16:42:53 +00:00
* Gère la détection des droits et des préférences pour l'affichage
* de la surveillance.
2009-05-20 15:49:08 +00:00
* @param string $page
2010-03-08 16:42:53 +00:00
* La page ou l'on affiche le formulaire, détermine le type
* de surveillance.
2009-05-20 15:49:08 +00:00
* @param string $siret
* L'établissement à surveiller.
2009-05-20 15:49:08 +00:00
* @return void
*/
function getSurveillance($source, $siret){
$assocSourceDroit = assocSourceDroit();
$return = '';
2010-03-26 14:27:57 +00:00
$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 = '<br/>L\'entité est sous surveillance.'."\n";
}else{
$return = formSurveillance($source, $siret, $notEmail);
}
}else{
$return = formSurveillance('', $siret, $notEmail);
}
return $return;
2009-05-20 15:49:08 +00:00
}
/**
* Vérifie si l'établissement est en surveillance
2009-05-20 15:49:08 +00:00
*
* @param string $source
* Le type de surveillance.
* @param string $siret
* L'établissement surveillé.
2009-05-20 15:49:08 +00:00
* @return boolean
* true or false
*/
function inSurveillance($source, $siret){
global $client, $firephp;
2009-12-16 10:09:30 +00:00
$firephp->log($source, 'source');
$firephp->log($siret, 'siret');
2009-05-20 15:49:08 +00:00
try{
$result = $client->getSurveillances($siret,$source);
2009-12-16 10:09:30 +00:00
$firephp->log($result['results']['reponses'], 'response');
2010-03-08 16:42:53 +00:00
if(count($result['results']['reponses'])>0 ){
$find = FALSE;
if(strlen($siret)>9) $siret = substr($siret, 0, 9);
foreach($result['results']['reponses'] as $item){
if($item['siren'] == $siret){ $find = TRUE; }
}
2010-03-08 16:42:53 +00:00
return $find;
}else{ return false; }
2010-03-08 16:42:53 +00:00
}catch(SoapFault $fault){
return false;
2009-05-20 15:49:08 +00:00
}
}
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éponse du webservice ou false
2009-05-22 12:26:07 +00:00
*/
function setSurveillance($tabForm)
{
global $client, $firephp;
2009-05-20 15:49:08 +00:00
$siret = $tabForm['siret'];
$email = $tabForm['email'];
$ref = $tabForm['ref'];
$source = $tabForm['source'];
$firephp->log($tabForm,'tabForm');
2009-12-16 10:09:30 +00:00
if(is_array($source))
2010-03-08 16:42:53 +00:00
{
2009-12-16 10:09:30 +00:00
foreach($source as $s)
{
2009-12-16 10:09:30 +00:00
try{
$result = $client->setSurveillance($siret, $email, $ref, $s);
$firephp->log($s, 'Surveillance');
2010-03-08 16:42:53 +00:00
}catch(SoapFault $fault){
2009-12-16 10:09:30 +00:00
$firephp->log($fault,'fault');
$result = false;
2010-03-08 16:42:53 +00:00
}
}
2009-12-16 10:09:30 +00:00
}
else
{
try{
$result = $client->setSurveillance($siret, $email, $ref, $source);
$firephp->log($source, 'Surveillance seul');
2010-03-08 16:42:53 +00:00
}catch(SoapFault $fault){
2009-12-16 10:09:30 +00:00
$firephp->log($fault,'fault');
$result = false;
}
2009-05-20 15:49:08 +00:00
}
2009-12-16 10:09:30 +00:00
return $result;
2009-05-20 15:49:08 +00:00
}
2009-05-22 12:26:07 +00:00
/**
* Supprime la surveillance
*
* @param string $siret
* L'établissement surveillé.
2009-05-22 12:26:07 +00:00
* @param $email
* L'email enregistré pour la surveillance
2009-05-22 12:26:07 +00:00
* @param $ref
* La référence ajouté pour cette surveillance
2010-03-08 16:42:53 +00:00
* @param $source
2009-05-22 12:26:07 +00:00
* La source pour cette surveillance
* @return mixed
* Retourne la réponse du webservice ou false
2009-05-22 12:26:07 +00:00
*/
2009-05-20 15:49:08 +00:00
function deleteSurveillance($siret, $email, $ref, $source){
global $client, $firephp;
2009-05-25 15:25:44 +00:00
$firephp->log($siret, 'siret');
$firephp->log($email, 'email');
$firephp->log($ref, 'ref');
$firephp->log($source, 'source');
2009-05-20 15:49:08 +00:00
try{
$result = $client->setSurveillance($siret, $email, $ref, $source, TRUE);
$firephp->log('Suppression surveillance');
2009-05-25 13:19:02 +00:00
return TRUE;
2010-03-08 16:42:53 +00:00
}catch(SoapFault $fault){
2009-05-20 15:49:08 +00:00
$firephp->log($fault,'fault');
return FALSE;
}
}
?>