extranet/application/controllers/DashboardController.php
2013-07-02 09:45:41 +00:00

1101 lines
33 KiB
PHP

<?php
class DashboardController extends Zend_Controller_Action
{
protected $typeActes= array(
'a00' => 'MODIFICATION',
'a01' => 'MODIFICATION',
'a02' => 'DISSOLUTION',
'a03' => 'CONSTITUTION',
'a04' => 'STATUTS CONSTITUTIFS',
'a06' => 'STATUTS A JOUR',
'a07' => 'STATUTS A JOUR',
'a08' => 'STATUTS A JOUR ET DECLARATION DE CONFORMITE',
'a09' => 'STATUTS APRES TRANSFERT DE SIEGE',
'a1D' => 'AUGMENTATION ET REDUCTION CAPITAL',
'a25' => 'AUGMENTATION DE CAPITAL',
'a26' => 'REDUCTION DE CAPITAL',
'a31' => 'TRANSFERT SIEGE SOCIAL HORS RESSORT',
'a33' => 'CHANGEMENT DE GERANT',
'a39' => 'CHANGEMENT DE COMMISSAIRE AUX COMPTES',
'a77' => 'CONTINUATION MALGRE LA PERTE DE LA MOITIE DU CAPITAL',
'aA1' => 'STATUTS',
'aAA' => 'ACTE',
'aAB' => 'ACTE MODIFICATIF',
'aAC' => 'ACTE RECTIFICATIF',
'aAD' => 'ACTE SOUS SEING PRIVE',
'aAE' => 'AMPLIATION',
'aAG' => 'AVENANT',
'aAH' => 'AVENANT AUX STATUTS',
'aAI' => 'ATTESTATION',
'aAJ' => 'ANNEXES',
'aAK' => 'ATTESTATION BANCAIRE',
'aAP' => 'PROJET APPORT PARTIEL D&quot,ACTIF',
'aAT' => 'DELIVRANCE DE L&quot,INFORMATION FAITE AU CONJOINT SUR LES CONSEQUENCES DES DETTES',
'aCA' => 'CERTIFICAT',
'aCB' => 'COMPTES DE CLOTURE DE LIQUIDATION',
'aCD' => 'CONTRAT',
'aCE' => 'CONVENTION',
'aCF' => 'CERTIFICAT DE SOUSCRIPTION D&quot,ACTIONS',
'aDA' => 'DECISION DE GERANCE',
'aDB' => 'DECISION DE L&quot,ASSOCIE UNIQUE',
'aDC' => 'DECISION DES ASSOCIES',
'aDE' => 'DECLARATION DE CONFORMITE',
'aDF' => 'DECLARATION DE SOUSCRIPTION ET DE VERSEMENT',
'aDH' => 'DECLARATION DE CONFORMITE (ART.374 L24/07/1966)',
'aDI' => 'DECISION DE L&quot,ACTIONNAIRE UNIQUE',
'aDP' => 'DECISION DU PRESIDENT',
'aEA' => 'EXPEDITION',
'aEB' => 'EXPEDITION NOTARIEE',
'aEC' => 'EXTRAIT DU PROCES-VERBAL',
'aFU' => 'PROJET DE FUSION',
'aIF' => 'PROJET APPORT PARTIEL D&quot,ACTIF',
'aJA' => 'JUGEMENT',
'aLA' => 'LETTRE',
'aLB' => 'LISTE DES SIEGES SOCIAUX ANTERIEURS',
'aLC' => 'LETTRE DE DEMISSION',
'aLD' => 'LETTRE DE NOMINATION',
'aLF' => 'LISTE DES SOUSCRIPTEURS',
'aLS' => 'CERTIFICAT DE DEPOT DES FONDS AVEC LISTE DES SOUSCRIPTEURS',
'aNA' => 'NOMINATION DE REPRESENTANT',
'aO9' => 'NOMINATION DE GERANT(S)',
'aOA' => 'ORDONNANCE',
'aOB' => 'ORDONNANCE DE REFERE',
'aOC' => 'ORDONNANCE DU PRESIDENT',
'aOD' => 'ORDONNANCE SUR REQUETE',
'aOE' => 'ORDONNANCE',
'aPA' => 'PROCES VERBAL',
'aPC' => 'PROCES VERBAL D&quot,ASSEMBLEE CONSTITUTIVE',
'aPD' => 'PROCES VERBAL D&quot,ASSEMBLEE DU DIRECTOIRE',
'aPE' => 'PROCES VERBAL D&quot,ASSEMBLEE GENERALE',
'aPF' => 'PROCES VERBAL D&quot,ASSEMBLEE GENERALE EXTRAORDINAIRE',
'aPG' => 'PROCES VERBAL D&quot,ASSEMBLEE GENERALE ORDINAIRE',
'aPH' => 'PROCES VERBAL D&quot,ASSEMBLEE MIXTE',
'aPI' => 'PROCES VERBAL D&quot,ASSEMBLEES ORDINAIRE ET EXTRAORDINAIRE',
'aPL' => 'PROCES VERBAL DIRIGEANT SOCIAL',
'aPM' => 'PROCES VERBAL DU CONSEIL D&quot,ADMINISTRATION',
'aPN' => 'PROCES VERBAL DU CONSEIL DE SURVEILLANCE',
'aPO' => 'PROCES VERBAL DE LA GERANCE',
'aPT' => 'PROJET DE TRAITE D&quot,APPORT',
'aPU' => 'PROJET DE FUSION',
'aPV' => 'PV D&quot,ASSEMBLEE',
'aQ2' => 'CONSTITUTION DE LA SOCIETE',
'aR1' => 'CESSION DE PARTS (OU DONATION)',
'aR4' => 'TRAITE DE FUSION',
'aRA' => 'RAPPORT',
'aRB' => 'RAPPORT COMMISSAIRE AUX COMPTES',
'aRC' => 'RAPPORT COMMISSAIRE FUSION',
'aRE' => 'RAPPORT CR/CPTES TRANSFORM. STE',
'aRG' => 'RAPPORT DU COMMISSAIRE A LA FUSION',
'aRH' => 'RAPPORT DU COMMISSAIRE A LA SCISSION',
'aRI' => 'RAPPORT DU COMMISSAIRE A LA TRANSFORMATION',
'aRK' => 'RAPPORT DU COMMISSAIRE AUX APPORTS',
'aRL' => 'RAPPORT DU COMMISSAIRE AUX APPORTS ET A LA FUSION',
'aRQ' => 'RAPPORT GERANCE',
'aRS' => 'RAPPORT SPECIAL DU CONSEIL D&quot,ADMINISTRATION',
'aRU' => 'PROJET',
'aTA' => 'TRAITE',
'aTB' => 'TRAITE D&quot,APPORT-FUSION',
'aTC' => 'TRAITE DE FUSION',
'aUA' => 'ATTESTATION DU CONJOINT COMMUN EN BIENS',
);
/**
* Return a ramdom password
* @param int $length
* Length of the string
* @param int $strength
* $strength = 1:- 0-9
* $strength = 2:- A-Z0-9
* $strength = 3:- A-Za-z0-9
* $strength = 4:- A-Za-z0-9 and # $ % &
* $strength = 5:- A-Za-z0-9 and # $ % & = > ? @
* @return string
*/
protected function randomPassword($length,$strength)
{
$char_sets=array('48-57','65-90','97-122','35-38','61-64');
$new_password='';
srand(microtime()*10000000);
for($i=0;$i<$length;$i++){
$random=rand(0,$strength-1);
list($start,$end)=explode('-',$char_sets[$random]);
$new_password.=chr(rand($start,$end));
}
return $new_password;
}
public function init()
{
require_once 'Scores/WsScores.php';
require_once 'common/dates.php';
}
public function preDispatch()
{
$user = new Scores_Utilisateur();
if (!$user->checkModeEdition() && $user->getIdClient()!=1 ){
$this->_forward('perms', 'error');
}
}
/**
* Affichage des différents liens d'administration
*/
public function indexAction()
{
$liens = array(
0 => array(
'libelle' => 'Gestion des clients',
'url' => $this->view->url(array('action'=>'clients')),
),
1 => array(
'libelle' => 'Gestion des commandes',
'url' => $this->view->url(array('action'=>'commandes')),
),
2 => array(
'libelle' => 'Gestion des fichiers nouveautés',
'url' => $this->view->url(array('action'=>'newform')),
),
3 => array(
'libelle' => 'Statistiques',
'url' => $this->view->url(array('action'=>'stat')),
),
);
$this->view->assign('Liens', $liens);
}
/**
* Créer des graphiques pour les statistiques
* @param array $data
* @param array $labels
* @param string $name
*/
protected function statChart($data, $labels, $name)
{
require_once("Vendors/ChartDirector/phpchartdir.php");
$hChart = 210;
$c = new PieChart($hChart*3, $hChart);
$c->setPieSize($hChart/2, $hChart/2, $hChart/3);
$c->set3D(10);
$c->setData($data, $labels);
$c->setSectorStyle(LocalGradientShading);
$c->setLabelLayout(SideLayout, 16);
$c->setLabelFormat("{={sector}+1}");
$textBoxObj = $c->setLabelStyle("arial.ttf", 10);
$textBoxObj->setBackground(Transparent);
$b = $c->addLegend($hChart*1.5, $hChart/2, true, "arial.ttf", 10);
$b->setAlignment(Left);
$b->setBackground(Transparent, 0xaaaaaa);
$b->setRoundedCorners();
$b->setMargin(16);
$b->setKeySpacing(0, 4);
$b->setKeyBorder(SameAsMainColor);
$b->setText(
"<*block,valign=top*>{={sector}+1}.<*advanceTo=22*><*block,width=120*>{label}".
"<*/*><*block,width=40,halign=right*>{percent}<*/*>%");
$fChart = fopen('themes/default/images/charts/chart-'.$name.'.png', "w");
fwrite($fChart, $c->makeChart2('png'));
fclose($fChart);
}
/**
* Affichage des statistiques des clients
*/
public function statAction()
{
$client_stat = new Application_Model_ClientStat();
$statTypes = array('Navigateur'=>'browserName', 'Résolution d\'écran'=>'screenSize', 'Type d\'appareil'=>'isMobile');
while($statType = current($statTypes)) {
$sql = $client_stat->select($statType)
->group($statType);
$rows = $client_stat->fetchAll($sql);
$i=0;
$values = array();
$keys = array();
foreach ($rows as $item) {
$isMobile = ($statType=='isMobile')?(($item->$statType==0)?'Ordinateur':'Mobile'):$item->$statType;
$values[$i] = $isMobile;
$keys[$i] = $client_stat->statCnt($statType, $item->$statType);
$i++;
}
$this->statChart($keys, $values, $statType);
next($statTypes);
}
$this->view->assign('statTypes', $statTypes);
}
/**
* Gestion des commandes de l'extranet
* Type : greffes | kbis | graydon | giant
*/
public function commandesAction()
{
$this->view->headScript()->appendFile('/themes/default/scripts/dashboard.js', 'text/javascript');
$request = $this->getRequest();
$type = $request->getParam('type', '');
$date = $request->getParam('date', mktime(0, 0, 0, date('n'), 1, date('Y')));
$user = new Scores_Utilisateur();
$typesCommande = array('kbis', 'greffes');
if (in_array($type, $typesCommande))
{
require_once 'Scores/GestionCommandes.php';
//Valeur pour la sélection des dates
$dateSelect = array();
$dateToday = date('m');
$dateIntervalle = 12;
if ($user->checkModeEdition()){
$dateIntervalle = 24;
}
for($i=$dateToday-$dateIntervalle; $i<=$dateToday; $i++)
{
$dateTime = mktime(0, 0, 0, $i, 1, date('Y'));
$selected = '';
if ($dateTime==$date){
$selected = 'selected';
}
$dateSelect[] = array(
'value' => $dateTime,
'select' => $selected,
'affichage' => date('m/Y', $dateTime)
);
}
$this->view->assign('dateSelect', $dateSelect);
switch($type)
{
case 'kbis':
$num = $request->getParam('num');
$num = str_replace(' ', '', strtoupper($num));
$etat = $request->getParam('etat');
$mode = $request->getParam('mode', 'M');
$modeSelect = array(
'C' => array('value' => 'C', 'select' => '', 'affichage' => 'courrier S&amp;D'),
'M' => array('value' => 'M', 'select' => '', 'affichage' => 'e-mail'),
);
$modeSelect[$mode]['select'] = ' selected';
$gestionCommande = new GestionCommande();
$status = $gestionCommande->listStatus($mode);
$etatSelect = array();
$etatSelect[] = array('value'=>0, 'select'=>'', 'affichage'=>'');
foreach($status as $item){
$select = '';
if ($item['id']==$etat){
$select = ' selected';
}
$etatSelect[] = array('value'=>$item['id'], 'select'=>$select, 'affichage'=>$item['libStatut']);
}
${'status'.$mode} = $gestionCommande->listStatus($mode);
$this->view->assign('etatSelect', $etatSelect);
$this->view->assign('modeSelect', $modeSelect);
$this->view->assign('num', $num);
if (!empty($num)){
if (preg_match('/[0-9]{9}/', $num)){
$listCommandes = $gestionCommande->listCommandesKbisBySiren($num);
} elseif(substr($num,0,1)=='K'){
$listCommandes = $gestionCommande->listCommandesKbisByNum($num);
}
} elseif (!empty($date)) {
$listCommandes = $gestionCommande->listCommandesKbis($date, $etat, $mode);
}
//Parcours de la liste des commandes et vérification document existe
if (count($listCommandes)>0) {
for($i=0;$i<count($listCommandes);$i++)
{
//Etat de la commande
$cmdEtatSelect = array();
$cmdEtatSelect[] = array('value'=>0, 'select'=>'', 'affichage'=>'');
$typeCommande = $listCommandes[$i]->type;
if (isset(${'status'.$typeCommande})){
foreach(${'status'.$typeCommande} as $item){
$select = '';
if ($item['id']==$listCommandes[$i]->statutCommande){
$select = ' selected';
}
$cmdEtatSelect[] = array(
'value' => $item['id'],
'affichage' => $item['libStatut'],
'select' => $select,
);
}
}
$listCommandes[$i]->cmdEtatSelect = $cmdEtatSelect;
}
}
break; //Fin Gestion Kbis
case 'greffes':
$num = $request->getParam('num');
$num = str_replace(' ', '', strtoupper($num));
$etat = $request->getParam('etat');
$mode = $request->getParam('mode', 'G');
$login = $request->getParam('login');
if (empty($mode) && !empty($num)) $mode = substr($num,0,1);
$modeSelect = array(
'G' => array('value' => 'G', 'select' => '', 'affichage' => 'courrier infogreffe'),
'C' => array('value' => 'C', 'select' => '', 'affichage' => 'courrier S&amp;D'),
'M' => array('value' => 'M', 'select' => '', 'affichage' => 'e-mail'),
);
$modeSelect[$mode]['select'] = ' selected';
$gestionCommande = new GestionCommande();
//Liste des états possible pour les commandes
$status = $gestionCommande->listStatus($mode);
$etatSelect = array();
$etatSelect[] = array('value'=>0, 'select'=>'', 'affichage'=>'');
foreach($status as $item){
$select = '';
if ($item['id']==$etat){
$select = ' selected';
}
$etatSelect[] = array(
'value' => $item['id'],
'select' => $select,
'affichage' => $item['libStatut']
);
}
$this->view->assign('etatSelect', $etatSelect);
$this->view->assign('modeSelect', $modeSelect);
$this->view->assign('num', $num);
$this->view->assign('login', $login);
if (!empty($num)){
if (preg_match('/[0-9]{9}/', $num)){
$listCommandes = $gestionCommande->listCommandesGreffeBySiren($num);
} elseif(substr($num,0,1)=='G' || substr($num,0,1)=='C'){
$listCommandes = $gestionCommande->listCommandesGreffeByNum($num);
}
} elseif (!empty($login)) {
$listCommandes = $gestionCommande->listCommandesGreffeByLogin($login, $date);
} elseif (!empty($date)) {
$listCommandes = $gestionCommande->listCommandesGreffe($date, $etat, $mode);
}
//Liste des différents états pour les commandes
${'status'.$mode} = $gestionCommande->listStatus($mode);
//Parcours de la liste des commandes et vérification document existe
if (count($listCommandes)>0)
{
for($i=0;$i<count($listCommandes);$i++)
{
//Etat de la commande
$cmdEtatSelect = array();
$cmdEtatSelect[] = array('value'=>0, 'select'=>'', 'affichage'=>'');
$typeCommande = $listCommandes[$i]->typeCommande;
if (isset(${'status'.$typeCommande})){
foreach(${'status'.$typeCommande} as $item){
$select = '';
if ($item['id']==$listCommandes[$i]->statutCommande){
$select = ' selected';
}
$cmdEtatSelect[] = array(
'value' => $item['id'],
'affichage' => $item['libStatut'],
'select' => $select,
);
}
}
$listCommandes[$i]->cmdEtatSelect = $cmdEtatSelect;
//Lien vers le fichier
$documentLien = '';
$document = '';
$sirenLien = '';
switch($type)
{
case 'greffes':
if (preg_match('/^([0-9a-zA-Z]{2,}-).*?$/', $listCommandes[$i]->refDocument, $matches)){
if (substr($listCommandes[$i]->refDocument,0,3)=='ST-'){
$document = 'DERNIER STATUS &Agrave; JOUR';
} else {
$explodedRef = explode('-', $listCommandes[$i]->refDocument);
$dateref = WDate::dateT('Ymd','d/m/Y',$explodedRef[1]);
$depot = ', Dépôt n°'.$explodedRef[6].' au '.$dateref;
$document = $this->typeActes['a'.substr($listCommandes[$i]->refDocument,0,2)].$depot;
}
$c = Zend_Registry::get('config');
$refFile = realpath($c->profil->path->data).'/pdf/acte-'.
$listCommandes[$i]->siren.'-'.
trim($listCommandes[$i]->refDocument).'.pdf';
if (file_exists($refFile)) {
$document = '<a href="/fichier/pdf/acte-'.
$listCommandes[$i]->siren.'-'.
trim($listCommandes[$i]->refDocument).'.pdf'.
'" target="_blank">'.$document.'</a>';
}
$sirenLien = $this->view->url(array(
'controller' => 'pieces',
'action' => 'actes',
'siret' => $listCommandes[$i]->siren,
), null, true);
} elseif (preg_match('/^([0-9]{4}).*?$/', $listCommandes[$i]->refDocument, $matches)){
$document = 'Bilan de '.$matches[1];
require_once 'Infogreffe/Infogreffe.php';
$infogreffe = new Infogreffe();
$path = $infogreffe->bilanPath($listCommandes[$i]->refDocument);
$fichier = $infogreffe->bilanFilename($listCommandes[$i]->siren, $listCommandes[$i]->refDocument);
if(file_exists($refFile)){
$document = '<a href="/fichier/pdf/'.$fichier.'" target="_blank">'.$document.'</a>';
}
$sirenLien = $this->view->url(array(
'controller' => 'pieces',
'action' => 'bilans',
'siret' => $listCommandes[$i]->siren,
), null, true);
}
break;
}
$listCommandes[$i]->document = $document;
$listCommandes[$i]->documentLien = $documentLien;
$listCommandes[$i]->sirenLien = $sirenLien;
}
}
break; //Fin Gestion Greffes
}
$this->view->assign('commandes', $listCommandes);
$this->renderScript('dashboard/commandes-'.$type.'.phtml');
}
//Affichage des liens vers les différents types de commande
$this->view->assign('typesCommande', $typesCommande);
}
/**
* Modification de l'état d'une commande infogreffe
*/
public function commandesetatchangeAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$etat = $request->getParam('etat');
$idCommande = $request->getParam('idCommande');
$mode = $request->getParam('mode', 'C');
$type = $request->getParam('type');
require_once 'Scores/GestionCommandes.php';
$commande = new GestionCommande();
if ($type == 'kbis'){
echo $commande->changeEtatKbis($idCommande, $etat, $mode);
} elseif ($type == 'greffe') {
echo $commande->changeEtatGreffe($idCommande, $etat, $mode);
}
}
/**
* Affichage de la raison sociale à partir du siren
*/
public function rsAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$siren = $request->getParam('siren');
$ws = new WsScores();
$infos = $ws->getIdentite($siren);
if ($infos==false) {
echo 'Erreur';
} else {
echo $infos->Nom;
}
}
/**
* Génération automatique du courrier PDF / ODT
*/
public function courrierAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$numCommande = $request->getParam('commande');
require_once 'GenCourrier/GenCourrier.php';
$courrier = new GenCourrier($numCommande);
$courrier->computeOdt();
}
/**
* Liste les clients
*/
public function clientsAction()
{
$user = new Scores_Utilisateur();
if ( !$user->isSuperAdmin() ){
$this->_forward('perms', 'error');
}
$this->view->headScript()
->appendFile('/themes/default/scripts/dashboard.js', 'text/javascript');
$ws = new WsScores();
$reponse = $ws->getListeClients();
$listeClients = $reponse->result->item;
$reponse = $ws->getListeDroits();
$wsdroits = $reponse->item;
$this->view->assign('ListeClients', $listeClients);
$this->view->assign('wsdroits', $wsdroits);
}
/**
* Edition ou création d'un nouveau client
*/
public function clientAction()
{
$user = new Scores_Utilisateur();
if ( !$user->isSuperAdmin() ) {
$this->_forward('perms', 'error');
}
$this->view->headScript()->appendFile('/libs/checkbox/jquery.checkbox.js', 'text/javascript');
$this->view->headLink()->appendStylesheet('/libs/checkbox/jquery.checkbox.css', 'all');
$request = $this->getRequest();
$idClient = $request->getParam('idClient', false);
$titre = 'CREATION NOUVEAU CLIENT';
$submitValue = 'Créer le client';
$ws = new WsScores();
if ($idClient!==false){
$reponse = $ws->getListeClients($idClient);
$InfosClient = $reponse->result->item[0];
$titre = 'EDITION CLIENT';
$submitValue = 'Modifier le client';
}
$reponse = $ws->getListeDroits();
$wsdroits = array();
foreach ($reponse->item as $tmp) {
$wsdroits[$tmp->code] = $tmp->desc;
}
$this->view->assign('wsdroits', $wsdroits);
$reponse = $ws->getCategory();
$wscategory = $reponse->item;
$this->view->assign('wscategory', $wscategory);
$this->view->assign('idClient', $idClient);
$this->view->assign('InfosClient', $InfosClient);
$this->view->assign('titre', $titre);
$this->view->assign('submitValue', $submitValue);
}
/**
* Enregistre les informations sur le client
*/
public function clientsaveAction()
{
$request = $this->getRequest();
$infos = $request->getParams();
$ws = new WsScores();
$reponse = $ws->setClient($infos);
if ($reponse->error->errnum==1) {
$this->_forward('client', 'dashboard', null, array('idClient' => $infos['idClient']));
}
$this->view->assign('infos', $request->getParams());
}
public function usersAction()
{
$this->view->headLink()->appendStylesheet('/themes/default/styles/user.css', 'all');
$user = new Scores_Utilisateur();
$request = $this->getRequest();
$idClient = $request->getParam('idClient', $user->getIdClient());
$service = $request->getParam('service', null);
if (!$user->isSuperAdmin() && !$user->isAdmin()) {
$this->renderScript('error/perms.phtml');
}
if ($user->isAdmin()){
$idClient = $user->getIdClient();
}
$ws = new WsScores();
$services = $ws->getServices($idClient);
if (is_array($services)) {
$this->view->assign('services', $services->item);
} else {
$this->view->assign('services', array());
}
if ( null === $service ) {
$infos = $ws->getListeUtilisateurs($user->getLogin(), $idClient);
$utilisateurs = $infos->result->item;
} else {
$infos = $ws->getServiceUsers($idClient, $service);
$utilisateurs = $infos->item;
$this->view->assign('service', $service);
}
$this->view->assign('utilisateurs', $utilisateurs);
$this->view->assign('idClient', $idClient);
}
public function userAction()
{
$this->view->headLink()
->appendStylesheet('/themes/default/styles/user.css', 'all')
->appendStylesheet('/themes/default/styles/form.css', 'all');
$this->view->headScript()->appendFile('/themes/default/scripts/user.js', 'text/javascript');
$request = $this->getRequest();
$op = $request->getParam('op');
$idClient = $request->getParam('idClient');
$login = $request->getParam('login');
if ($op=='save') {
$options = $request->getParam('frmOptions', '');
$action = $options['action'];
$idClient = $options['idClient'];
$login = $options['login'];
require_once 'Scores/WsScores.php';
$ws = new WsScores();
$result = $ws->setInfosLogin($login, $action, $options);
if (is_string($result)) {
$this->view->assign('message',$result);
switch($action) {
case 'new': $op = 'new'; break;
case 'update': $op = 'edit'; break;
}
} else {
$this->_redirect('/dashboard/users/idClient/'.$idClient);
}
}
switch($op) {
case 'new':
require_once 'Scores/WsScores.php';
$ws = new WsScores();
//Liste des catégories d'accès
$reponse = $ws->getCategory();
$wscategory = $reponse->item;
$this->view->assign('wscategory', $wscategory);
//Liste de tous les droits
$listeDroits = $ws->getListeDroits();
$droitsLib = array();
foreach($listeDroits->item as $droit) {
$droitsLib[strtoupper($droit->code)] = $droit->desc;
}
$this->view->assign('droitsLib', $droitsLib);
//Liste de toutes les préférences
$listePrefs = $ws->getListePrefs();
$prefsLib = array();
foreach($listePrefs->item as $pref) {
$prefsLib[strtoupper($pref->code)] = $pref->desc;
}
$this->view->assign('prefsLib', $prefsLib);
$options['idClient'] = $idClient;
$this->view->assign('options', $options);
//Customer informations
$reponse = $ws->getNextLogin($idClient);
$this->view->assign('loginNew', $reponse->result->racine);
$this->view->assign('droitsClients', explode(' ', strtolower($reponse->result->droitsClients)));
$this->view->assign('password', $this->randomPassword(10, 3));
$this->view->assign('action', 'new');
break;
case 'edit':
require_once 'Scores/WsScores.php';
$ws = new WsScores();
//Liste des catégories d'accès
$reponse = $ws->getCategory();
$wscategory = $reponse->item;
$this->view->assign('wscategory', $wscategory);
//Liste de tous les droits
$listeDroits = $ws->getListeDroits();
$droitsLib = array();
foreach($listeDroits->item as $droit) {
$droitsLib[strtoupper($droit->code)] = $droit->desc;
}
$this->view->assign('droitsLib', $droitsLib);
//Liste de toutes les préférences
$listePrefs = $ws->getListePrefs();
$prefsLib = array();
foreach($listePrefs->item as $pref) {
$prefsLib[strtoupper($pref->code)] = $pref->desc;
}
$this->view->assign('prefsLib', $prefsLib);
$options->idClient = $idClient;
$this->view->assign('options', $options);
//Customer informations
$reponse = $ws->getListeClients($idClient);
$InfosClient = $reponse->result->item[0];
$this->view->assign('loginNew', $InfosClient->racineLogin);
$this->view->assign('droitsClients', explode(' ', strtolower($InfosClient->droits)));
//User informations
$user = $ws->getUser($login);
$options = json_decode($user, true);
Zend_Registry::get('firebug')->info($user);
$this->view->assign('droits', explode(' ',$options['droits']));
$this->view->assign('prefs', explode(' ',$options['pref']));
$this->view->assign('options', $options);
$this->view->assign('action', 'update');
break;
case 'delete':
$action = 'delete';
require_once 'Scores/WsScores.php';
$ws = new WsScores();
$ws->setInfosLogin($login, $action);
//Redirect
$this->_redirect('/dashboard/users/idClient/'.$idClient);
break;
case 'enable':
$action = 'enable';
require_once 'Scores/WsScores.php';
$ws = new WsScores();
$ws->setInfosLogin($login, $action);
//Redirect
$this->_redirect('/dashboard/users/idClient/'.$idClient);
break;
case 'disable':
$action = 'disable';
require_once 'Scores/WsScores.php';
$ws = new WsScores();
$ws->setInfosLogin($login, $action);
//Redirect
$this->_redirect('/dashboard/users/idClient/'.$idClient);
break;
}
}
public function userserviceAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$submit = $request->getParam('submit', null);
$idClient = $request->getParam('idClient');
$service = $request->getParam('service');
$this->view->assign('service', $service);
$login = $request->getParam('login');
$this->view->assign('login', $login);
$ws = new WsScores();
if ( $request->isPost() && null!==$submit ) {
$ws->setUserService($login, $service);
} else {
$services = $ws->getServices($idClient);
$this->view->assign('services', $services->item);
}
}
public function usersearchAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$idClient = $request->getParam('idClient');
$query = $request->getParam('q');
$ws = new WsScores();
$result = $ws->searchLogin($idClient, $query);
$items = json_decode($result);
$output = array();
if (count($items)>0){
$separator = ", ";
foreach ($items as $item) {
$output[] = array(
'label' => $item->login,
'value' => $item->login,
);
}
}
Zend_Registry::get('firebug')->info($output);
$this->view->assign('output', $output);
}
/**
* Affichage du formulaire pour l'envoi des fichiers concernant les nouveautées
*/
public function newformAction()
{
//Only the view
}
/**
* Réception du fichier des nouveautés et enregistrement des informations
*/
public function newuploadAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
if ( isset($_FILES) && count($_FILES)==1 ) {
$c = Zend_Registry::get('config');
$path = realpath($c->profil->path->data).'/nouveautes';
if(!file_exists($path)) mkdir($path);
$tmp_name = $_FILES['fichier']['tmp_name'];
$n = $_FILES['fichier']['name'];
$name = uniqid('new');
$extValide = array('pdf');
$extension = strrchr($n,'.');
$extension = strtolower(substr($extension,1));
//Vérifier l'extension du fichier
if(!in_array($extension, $extValide)){
echo "Extension de fichier incorrect !";
} elseif (move_uploaded_file($tmp_name, $path.'/'.$name.'.'.$extension)){
$request = $this->getRequest();
//Enregistrement des informations
$data = array(
'categorie' => $request->getParam('categorie'),
'intitule' => $request->getParam('intitule'),
'date' => $request->getParam('date'),
'fichier' => $name.'.'.$extension,
);
$new = new Application_Model_Nouveautes();
try {
$new->insert($data);
echo "Fichier enregistré";
} catch(Exception $e) {
echo "Erreur lors de l'enregistrement";
if ( file_exists($path.'/'.$name.'.'.$extension) ) unlink($path.'/'.$name.'.'.$extension);
}
} else {
echo "Erreur";
}
}
}
public function newprogressAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$key = $request->getParam('key', '');
if (!empty($key)) {
//$rep sera égal à false si la clef n'existe pas dans le cache apc
$rep = apc_fetch('upload_'.$key);
echo json_encode($rep);
}
}
public function prestationsAction()
{
$request = $this->getRequest();
$idClient = $request->getParam('idClient');
$this->view->assign('idClient', $idClient);
}
public function prestationAction()
{
$request = $this->getRequest();
$idClient = $request->getParam('idClient');
$this->view->assign('idClient', $idClient);
$submitValue = "Créer";
$id = $request->getParam('id');
if ($id!=null) {
//Recup param prestation
$submitValue = "Modifier";
}
$this->view->assign('submitValue', $submitValue);
}
public function prestationsaveAction(){}
public function tarifsAction()
{
$request = $this->getRequest();
$idClient = $request->getParam('idClient');
$this->view->assign('idClient', $idClient);
$ws = new WsScores();
//Liste des periodes de facturation
$contrats = $ws->getClientTarifs($idClient);
Zend_Registry::get('firebug')->info($contrats);
$this->view->assign('contrats', $contrats->item);
//Liste des services
$services = $ws->getServices($idClient);
$this->view->assign('services', $services->item);
//Liste des logs
$logs = $ws->getLogs();
$this->view->assign('logs', $logs->item);
}
public function tarifAction()
{
$request = $this->getRequest();
$idClient = $request->getParam('idClient');
$ws = new WsScores();
if ( $request->isXmlHttpRequest() ) {
$this->_helper->layout()->disableLayout();
if ( $request->isPost() ) {
$log = $request->getParam('log');
$service = $request->getParam('service');
$type = $request->getParam('type');
$priceUnit = $request->getParam('priceUnit');
$limit = $request->getParam('limit');
$date = $request->getParam('date');
$duree = $request->getParam('duree');
$doublon = $request->getParam('doublon');
$result = $ws->setClientTarif($idClient, $log, $service, $type, $priceUnit, $limit, $date, $duree, $doublon);
if(is_int($result)) {
//OK
} else {
$this->view->assign('log', $log);
$this->view->assign('service', $service);
$this->view->assign('type', $type);
$this->view->assign('priceUnit', $priceUnit);
$this->view->assign('date', $date);
$this->view->assign('duree', $duree);
$this->view->assign('doublon', $doublon);
$this->view->assign('error', $result);
}
}
}
$services = $ws->getServices($idClient);
$this->view->assign('services', $services->item);
$logs = $ws->getLogs();
$this->view->assign('logs', $logs->item);
$this->view->assign('idClient', $idClient);
}
public function serviceAction()
{
$request = $this->getRequest();
$idClient = $request->getParam('idClient');
$ws = new WsScores();
if ( $request->isPost() ) {
$code = $request->getParam('code');
$label = $request->getParam('label');
$droitsP = $request->getParam('droits');
$droits = join(' ', $droitsP);
$infos = array(
'code' => $code,
'label' => $label,
'droits' => $droits,
);
$result = $ws->setService($idClient, json_encode($infos));
if(is_int($result)) {
$this->view->assign('message', 'Service crée.');
} else {
$this->view->assign('message', $result);
}
} else {
//Droits du client
//Liste des catégories d'accès
$reponse = $ws->getCategory();
$wscategory = $reponse->item;
$this->view->assign('wscategory', $wscategory);
//Liste de tous les droits
$listeDroits = $ws->getListeDroits();
$droitsLib = array();
foreach($listeDroits->item as $droit) {
$droitsLib[strtoupper($droit->code)] = $droit->desc;
}
$this->view->assign('droitsLib', $droitsLib);
//Customer informations
$reponse = $ws->getNextLogin($idClient);
$this->view->assign('droitsClients', explode(' ', strtolower($reponse->result->droitsClients)));
}
$this->view->assign('idClient', $idClient);
}
}