odea/application/controllers/GestionController.php

417 lines
12 KiB
PHP
Raw Normal View History

2012-02-22 17:08:39 +00:00
<?php
class GestionController extends Zend_Controller_Action
{
public function preDispatch()
{
}
2012-05-02 19:06:36 +00:00
2012-02-24 09:54:21 +00:00
public function init()
{
2012-04-12 08:07:35 +00:00
$this->view->headLink()->appendStylesheet('/themes/default/styles/dashboard.css', 'all');
$this->view->headScript()->appendFile('/themes/default/scripts/dashboard.js', 'text/javascript');
2012-02-24 09:54:21 +00:00
}
2012-05-02 19:06:36 +00:00
2012-05-22 06:10:32 +00:00
/**
* Display all links
*/
2012-02-22 17:08:39 +00:00
public function indexAction()
{
2012-05-02 19:06:36 +00:00
2012-02-22 17:08:39 +00:00
}
2012-05-02 19:06:36 +00:00
2012-05-16 15:52:34 +00:00
/**
* Display profils to get data
* Filter with login and idClient
*
*/
2012-02-22 17:08:39 +00:00
public function profilsAction()
{
2012-05-16 15:52:34 +00:00
$request = $this->getRequest();
$login = $request->getParam('login', '');
$idClient = $request->getParam('idClient', null);
2012-05-02 19:06:36 +00:00
$profilsM = new Application_Model_EnrichissementProfils();
2012-05-16 15:52:34 +00:00
2012-02-24 09:54:21 +00:00
$sql = $profilsM->select()
->from($profilsM, array('id', 'idClient', 'login', 'reference', 'tarifLigne', 'dateAjout', 'dateSuppr', 'actif'));
2012-05-16 15:52:34 +00:00
if ( !empty($login) ) {
$sql->where('login = ?', $login.'%');
}
if ( $idClient!=null ) {
$sql->where('idClient = ?', $idClient);
}
2012-02-24 09:54:21 +00:00
$profils = $profilsM->fetchAll($sql);
2012-05-02 19:06:36 +00:00
2012-02-24 09:54:21 +00:00
$this->view->assign('profils', $profils);
2012-02-22 17:08:39 +00:00
}
2012-05-02 19:06:36 +00:00
2012-05-22 06:10:32 +00:00
/**
* Define fields for extraction to user
*/
2012-02-24 09:54:21 +00:00
public function profiladdAction()
{
$request = $this->getRequest();
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
2012-02-24 09:54:21 +00:00
//Sauvegarde du formulaire
if ( $request->isPost() )
{
2012-03-06 15:02:50 +00:00
$params = $request->getParams();
2012-05-02 19:06:36 +00:00
if ($params['reference']=='default') {
//Get default profil
$profilClientM = new Application_Model_CustomerParams();
$sql = $profilClientM->select()->where('idClient=?',$request->getParam('idClient'));
$profilClient = $profilClientM->fetchRow($sql);
if ( null !== $profilClient ) {
$params['criteres'] = json_decode($profilClient->criteres,true);
}
2012-03-06 15:02:50 +00:00
}
2012-05-02 19:06:36 +00:00
if (empty($params['criteres'])) {
$this->view->assign('message', "Erreur profil vide");
2012-03-06 15:02:50 +00:00
} else {
2012-05-02 19:06:36 +00:00
$data = array(
'idClient' => $params['idClient'],
'service' => $params['service'],
'login' => $params['login'],
'reference' => $params['reference'],
'criteres' => json_encode($params['criteres']),
'dataInsee' => 0,
'dateAjout' => date('Y-m-d H:i:s'),
'actif' => 1,
);
$profilM = new Application_Model_EnrichissementProfils();
if ( $profilM->insert($data) ) {
$this->view->assign('message', "Profil enregistré");
$this->view->assign('disableForm', true);
} else {
$this->view->assign('message', "Erreur lors de la sauvegarde");
}
}
2012-02-24 09:54:21 +00:00
}
2012-05-02 19:06:36 +00:00
2012-02-24 09:54:21 +00:00
//Affichage du formulaire
require_once 'Scores/Enrichissement.php';
$fieldsM = new Enrichissement();
2012-05-02 19:06:36 +00:00
$allFields = $fieldsM->getFields();
$this->view->assign('fields', $allFields);
2012-02-24 09:54:21 +00:00
}
2012-05-02 19:06:36 +00:00
2012-05-16 15:52:34 +00:00
/**
* Mark profil as deleted
*/
public function profildelAction()
{
}
2012-05-02 19:06:36 +00:00
2012-05-22 06:10:32 +00:00
/**
* List commands which must be done
*/
public function commandesAction()
{
$request = $this->getRequest();
$commandesM = new Application_Model_EnrichissementIdentifiants();
$sql = $commandesM->select()->setIntegrityCheck(false)
->from('enrichissement_identifiants AS e', array(
'e.id',
'e.reference AS commandeReference',
'e.nbLigneTotales',
'e.uniteInsee',
"DATE_FORMAT(e.dateAdded, '%Y/%m/%d %H:%i:%s') AS dateAdded"
))
2012-09-03 14:50:50 +00:00
->join('ciblage_criteres', 'idCriteres = ciblage_criteres.id', array(
'ciblage_criteres.reference AS critereReference',
'ciblage_criteres.login',
2012-05-22 06:10:32 +00:00
))
->where('e.dateStart = ?', "0000-00-00 00:00:00")
->where('fichier = ""')
->order('e.dateAdded DESC');
$this->view->commandes = $commandesM->fetchAll($sql)->toArray();
}
/**
* List commands with a file
*/
public function enrichissementsAction()
{
$commandesM = new Application_Model_EnrichissementIdentifiants();
$sql = $commandesM->select()->setIntegrityCheck(false)
->from('enrichissement_identifiants AS e', array(
'e.id',
'e.reference AS commandeReference',
'e.nbLigneTotales',
'e.uniteInsee',
2012-06-19 15:18:52 +00:00
"DATE_FORMAT(e.dateAdded, '%Y/%m/%d %H:%i:%s') AS dateAdded",
'e.fichier'
2012-05-22 06:10:32 +00:00
))
2012-09-03 14:50:50 +00:00
->join('ciblage_criteres', 'idCriteres = ciblage_criteres.id', array(
'ciblage_criteres.reference AS critereReference',
'ciblage_criteres.login',
2012-05-22 06:10:32 +00:00
))
->where('fichier != ""')
->order('e.dateAdded DESC');
$this->view->commandes = $commandesM->fetchAll($sql)->toArray();
}
/**
* Load enrichissement batch to complete data
*/
public function enrichitAction()
{
$request = $this->getRequest();
$id = $request->getParam('id');
exec('php '.APPLICATION_PATH.'/../batch/enrichissement.php --id '.$id.' &');
}
/**
2012-06-01 10:30:44 +00:00
* Extract only SIRETs from database
2012-05-22 06:10:32 +00:00
* @todo : To csv file
*/
2012-06-01 10:30:44 +00:00
public function extractAction()
2012-05-22 06:10:32 +00:00
{
$id = $this->getRequest()->getParam('id');
$table = new Application_Model_EnrichissementIdentifiants();
2012-06-01 10:30:44 +00:00
$sql = $table->select()->where('idComptage = ?', $id);
2012-05-22 06:10:32 +00:00
$result = $table->fetchRow($sql);
if(!empty($result)) {
$result = $result->toArray();
$sirets = json_decode($result['identifiants'], true);
2012-06-01 10:30:44 +00:00
$content = '';
2012-05-22 06:10:32 +00:00
foreach($sirets as $siret) {
2012-06-01 10:30:44 +00:00
$content.= $siret.",";
}
$this->view->assign('content', $content);
2012-05-22 06:10:32 +00:00
}else {
2012-06-01 10:30:44 +00:00
$this->view->assign('message', 'Aucune commande d\'enrichissement sur ce comptage');
}
2012-05-22 06:10:32 +00:00
}
/**
* List criteres and the last count
*/
public function ciblagesAction()
2012-04-12 08:07:35 +00:00
{
2012-05-16 15:52:34 +00:00
$comptagesM = new Application_Model_Comptages();
$sql = $comptagesM->select()->setIntegrityCheck(false)
2012-09-03 14:50:50 +00:00
->from('ciblage_comptages', array(
'ciblage_comptages.idDefinition',
'ciblage_comptages.resultat',
'ciblage_comptages.uniteInsee',
"DATE_FORMAT(ciblage_comptages.dateAjout, '%Y/%m/%d %H:%i:%s') as dateAjout"
2012-05-16 15:52:34 +00:00
))
2012-09-03 14:50:50 +00:00
->join('ciblage_criteres', 'ciblage_comptages.idDefinition = ciblage_criteres.id', array('ciblage_criteres.reference'))
->order('ciblage_comptages.dateAjout DESC')
->group('ciblage_criteres.id');
2012-05-16 15:52:34 +00:00
$comptages = $comptagesM->fetchAll($sql)->toArray();
Zend_Registry::get('firebug')->info($comptages);
$this->view->comptages = $comptages;
2012-04-12 08:07:35 +00:00
}
2012-05-02 19:06:36 +00:00
/**
* List customers
*/
public function customerparamsAction()
{
//@todo : what's in database
$customersM = new Application_Model_CustomerParams();
$sql = $customersM->select()
->from($customersM,array('idClient', 'service' , 'dateContrat', 'periodContrat'))
->order('dateAdded DESC')
->group('idClient');
$customers = $customersM->fetchAll($sql)->toArray();
//List login
$customerlist = array();
$profilsM = new Application_Model_EnrichissementProfils();
foreach($customers as $item) {
$sql = $profilsM->select()
->from($profilsM, array('login'))
->where('idClient=?',$item['idClient']);
$result = $profilsM->fetchAll($sql)->toArray();
$logins = array();
if (count($result)>0) {
foreach($result as $login) {
$logins[] = $login['login'];
}
}
$item['logins'] = $logins;
$customerlist[] = $item;
}
$this->view->assign('customerlist', $customerlist);
}
/**
* List customer's params
*/
public function customerparamAction()
{
2012-12-10 16:50:08 +00:00
//Fields
require_once 'Scores/Enrichissement.php';
$fieldsM = new Enrichissement();
$allFields = $fieldsM->getFields();
$this->view->assign('fields', $allFields);
2012-12-10 16:50:08 +00:00
$request = $this->getRequest();
$idClient= $request->getParam('id', null);
2012-12-10 16:50:08 +00:00
$this->view->assign('idClient', $idClient);
if ($idClient !== null) {
$paramsM = new Application_Model_CustomerParams();
2012-10-25 15:25:53 +00:00
$sql = $paramsM->select()->where('idClient = ?', $idClient);
$params = $paramsM->fetchRow($sql);
$infos = null;
2012-10-25 15:25:53 +00:00
if ($params!==null){
$infos = $params->toArray();
2012-12-10 16:50:08 +00:00
$infos['criteres'] = json_decode($infos['criteres'], true);
}
2012-10-25 15:25:53 +00:00
$this->view->assign('infos',$infos);
$loginsM = new Application_Model_EnrichissementProfils();
$sql = $loginsM->select()->where('idClient = ?', $idClient);
$logins = $loginsM->fetchAll($sql)->toArray();
$this->view->assign('logins', $logins);
}
}
public function customerparamaddAction()
{
//Fields
require_once 'Scores/Enrichissement.php';
$fieldsM = new Enrichissement();
$allFields = $fieldsM->getFields();
$this->view->assign('fields', $allFields);
$request = $this->getRequest();
//Sauvegarde du formulaire
2012-12-10 16:50:08 +00:00
if ( $request->isPost() && in_array($request->getParam('submit'), array('Enregistrer','Modifier')) ) {
$params = $request->getParams();
//Vérifier le formulaire
$errForm = 0;
foreach ( $params as $key => $value ) {
if ($value=='' && $key!='service') {
$errForm++;
}
}
2012-12-06 16:51:14 +00:00
if (!$errForm) {
$checkValues = array(
'filterRNCS' => 0,
'licenceINSEE' => 0,
'immediatExtract' => 0,
);
foreach ($checkValues as $key => $value) {
if (!array_key_exists($key, $params)) {
$params[$key] = $value;
}
}
$data = array(
'idClient' => $params['idClient'],
'service' => $params['service'],
'filterRNCS' => $params['filterRNCS'],
'licenceINSEE' => $params['licenceINSEE'],
'immediatExtract' => $params['immediatExtract'],
'dateContrat' => $params['dateContrat'],
'periodContrat' => $params['periodContrat'],
'periodPaiement' => $params['periodPaiement'],
'priceLine' => $params['priceLine'],
'forfait' => $params['forfait'],
'limitLines' => $params['limitLines'],
'limitFiles' => $params['limitFiles'],
'criteres' => json_encode($params['criteres']),
'dateAdded' => date('Y-m-d H:i:s'),
2012-12-10 16:50:08 +00:00
);
2012-12-10 16:50:08 +00:00
if ($request->getParam('submit')=='Modifier') {
//Overwrite default profil for each login
$profilM = new Application_Model_EnrichissementProfils();
$profilM->update(
array('criteres', json_encode($params['criteres'])),
"reference='default' AND idClient=".$params['idClient']);
2012-12-10 16:50:08 +00:00
//Set parameters
$customerParamsM = new Application_Model_CustomerParams();
if ( $customerParamsM->update($data, 'id='.$params['id']) ){
$this->view->assign('message', "Profil enregistré");
} else {
$this->view->assign('message', "Erreur lors de la sauvegarde");
}
2012-12-10 16:50:08 +00:00
} else {
//Set parameters
$customerParamsM = new Application_Model_CustomerParams();
if ( $customerParamsM->insert($data) ){
$this->view->assign('message', "Profil enregistré");
} else {
$this->view->assign('message', "Erreur lors de la sauvegarde");
}
}
} else {
$this->view->assign('message', "Erreur lors de la saisie");
}
2012-12-10 16:50:08 +00:00
} else {
$idClient = $request->getParam('id', null);
2012-12-10 16:50:08 +00:00
if ($idClient !== null) {
$paramsM = new Application_Model_CustomerParams();
$sql = $paramsM->select()->where('idClient = ?', $idClient);
$params = $paramsM->fetchRow($sql);
if ( $params!==null ) {
foreach ( $params as $key => $value ) {
switch ( $key ) {
case 'criteres':
$this->view->assign($key, json_decode($value,true));
break;
case 'dateContrat':
$this->view->assign($key, substr($value,0,10));
break;
default:
$this->view->assign($key, $value);
break;
}
}
}
2012-12-10 16:50:08 +00:00
} else {
$this->view->assign('filterRNCS', 1);
$this->view->assign('licenceINSEE', 0);
$this->view->assign('immediatExtract', 0);
$this->view->assign('limitLines', 50000);
$this->view->assign('limitFiles', 0);
}
}
}
2012-02-22 17:08:39 +00:00
}