view->headLink()->appendStylesheet('/themes/default/styles/dashboard.css', 'all'); $this->view->headScript()->appendFile('/themes/default/scripts/dashboard.js', 'text/javascript'); } /** * Display all links */ public function indexAction() { } /** * Display profils to get data * Filter with login and idClient * */ public function profilsAction() { $request = $this->getRequest(); $login = $request->getParam('login', ''); $idClient = $request->getParam('idClient', null); $profilsM = new Application_Model_EnrichissementProfils(); $sql = $profilsM->select() ->from($profilsM, array('id', 'idClient', 'login', 'reference', 'tarifLigne', 'dateAjout', 'dateSuppr', 'actif')); if ( !empty($login) ) { $sql->where('login = ?', $login.'%'); } if ( $idClient!=null ) { $sql->where('idClient = ?', $idClient); } $profils = $profilsM->fetchAll($sql); $this->view->assign('profils', $profils); } /** * Define fields for extraction to user */ public function profiladdAction() { $request = $this->getRequest(); $auth = Zend_Auth::getInstance(); $user = $auth->getIdentity(); //Sauvegarde du formulaire if ( $request->isPost() ) { $params = $request->getParams(); 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); } } if (empty($params['criteres'])) { $this->view->assign('message', "Erreur profil vide"); } else { $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"); } } } //Affichage du formulaire require_once 'Scores/Enrichissement.php'; $fieldsM = new Enrichissement(); $allFields = $fieldsM->getFields(); $this->view->assign('fields', $allFields); } /** * Mark profil as deleted */ public function profildelAction() { } /** * List commands which must be done */ public function commandesAction() { $request = $this->getRequest(); $month = $request->getParam('month', date('m')); $year = $request->getParam('year', date('Y')); $this->view->assign('month', $month); $this->view->assign('year', $year); $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" )) ->join('ciblage_criteres', 'idCriteres = ciblage_criteres.id', array( 'ciblage_criteres.reference AS critereReference', 'ciblage_criteres.login', )) ->where('e.dateStart = ?', "0000-00-00 00:00:00") ->where('fichier = ""') ->where("e.dateAdded LIKE '".$year."-".$month."%'") ->order('e.dateAdded DESC'); $this->view->commandes = $commandesM->fetchAll($sql)->toArray(); } /** * List commands with a file */ public function enrichissementsAction() { $request = $this->getRequest(); $month = $request->getParam('month', date('m')); $year = $request->getParam('year', date('Y')); $this->view->assign('month', $month); $this->view->assign('year', $year); $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", 'e.fichier' )) ->join('ciblage_criteres', 'idCriteres = ciblage_criteres.id', array( 'ciblage_criteres.reference AS critereReference', 'ciblage_criteres.login', )) ->where('fichier != ""') ->where("e.dateAdded LIKE '".$year."-".$month."%'") ->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.' &'); } /** * Extract only SIRETs from database * @todo : To csv file */ public function extractAction() { $id = $this->getRequest()->getParam('id'); $table = new Application_Model_EnrichissementIdentifiants(); $sql = $table->select()->where('idComptage = ?', $id); $result = $table->fetchRow($sql); if(!empty($result)) { $result = $result->toArray(); $sirets = json_decode($result['identifiants'], true); $content = ''; foreach($sirets as $siret) { $content.= $siret.","; } $this->view->assign('content', $content); }else { $this->view->assign('message', 'Aucune commande d\'enrichissement sur ce comptage'); } } /** * List criteres and the last count */ public function ciblagesAction() { $comptagesM = new Application_Model_Comptages(); $sql = $comptagesM->select()->setIntegrityCheck(false) ->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" )) ->join('ciblage_criteres', 'ciblage_comptages.idDefinition = ciblage_criteres.id', array('ciblage_criteres.reference')) ->order('ciblage_comptages.dateAjout DESC') ->group('ciblage_criteres.id'); $comptages = $comptagesM->fetchAll($sql)->toArray(); Zend_Registry::get('firebug')->info($comptages); $this->view->comptages = $comptages; } /** * 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() { //Fields require_once 'Scores/Enrichissement.php'; $fieldsM = new Enrichissement(); $allFields = $fieldsM->getFields(); $this->view->assign('fields', $allFields); $request = $this->getRequest(); $idClient= $request->getParam('id', null); $this->view->assign('idClient', $idClient); if ($idClient !== null) { $paramsM = new Application_Model_CustomerParams(); $sql = $paramsM->select()->where('idClient = ?', $idClient); $params = $paramsM->fetchRow($sql); $infos = null; if ($params!==null){ $infos = $params->toArray(); $infos['criteres'] = json_decode($infos['criteres'], true); } $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 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++; } } 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'), ); 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']); //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"); } } 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"); } } else { $idClient = $request->getParam('id', null); 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; } } } } 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); } } } }