enrichissement/application/controllers/IndexController.php

136 lines
4.0 KiB
PHP
Raw Normal View History

2012-01-13 13:35:11 +00:00
<?php
class IndexController extends Zend_Controller_Action
{
2012-05-15 15:02:37 +00:00
2012-01-13 13:35:11 +00:00
public function indexAction()
{
2012-12-04 16:36:12 +00:00
$request = $this->getRequest();
$idClient = $request->getParam('idClient', null);
2012-12-04 16:40:37 +00:00
$this->view->assign('idClient', $idClient);
2012-12-04 16:36:12 +00:00
//Liste des profils
2012-01-17 11:44:02 +00:00
$profilM = new Application_Model_Profil();
$sql = $profilM->select();
2012-01-19 15:25:47 +00:00
$this->view->assign('listProfil', $profilM->fetchAll($sql));
2012-05-15 15:02:37 +00:00
$commandesM = new Application_Model_Commandes($db);
//Liste des fichiers en attente de profil
2012-01-15 17:43:37 +00:00
$sql = $commandesM->select()->where('idProfil = ?', 0);
2012-05-15 15:02:37 +00:00
$this->view->assign('fileAttenteProfil', $commandesM->fetchAll($sql));
2012-01-15 17:43:37 +00:00
//Liste des enrichissements en cours
$sql = $commandesM->select()
->where('idProfil != ?', 0)
->where("dateStop = '0000-00-00 00:00:00'");
$this->view->assign('fileEnCours', $commandesM->fetchAll($sql));
2012-05-15 15:02:37 +00:00
2012-01-15 17:43:37 +00:00
//Liste des enrichissements terminé
$sql = $commandesM->select()
->where("dateStop != '0000-00-00 00:00:00'")
2012-12-04 16:36:12 +00:00
->where("error = ''")
->order('dateStart DESC');
if ( null != $idClient ) {
2012-12-05 13:59:34 +00:00
$sql->where('fichier LIKE "'.$idClient.'-%"');
2012-12-04 16:36:12 +00:00
} else {
$sql->limit(5);
}
2012-01-15 17:43:37 +00:00
$this->view->assign('fileFinish', $commandesM->fetchAll($sql));
2012-12-04 16:36:12 +00:00
//Récupérer les clients
$dbConfig = array(
'host' => MYSQL_HOST,
'port' => MYSQL_PORT,
'username' => MYSQL_USER,
'password' => MYSQL_PASS,
'dbname' => MYSQL_DEFAULT_DB,
'driver_options' => array(MYSQLI_INIT_COMMAND => 'SET NAMES UTF8;'),
//'driver_options' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8;')
);
$sqlmetier = Zend_Db::factory('Mysqli', $dbConfig);
$sql = $sqlmetier->select()
->from('sdv1.clients', array('id', 'nom'))
->where("actif = 'Oui'");
2012-12-04 16:36:12 +00:00
$clients = $sqlmetier->fetchAll($sql, null, Zend_Db::FETCH_OBJ);
2012-12-04 16:36:12 +00:00
$this->view->assign('clients', $clients);
2012-01-15 17:43:37 +00:00
}
2012-05-15 15:02:37 +00:00
public function getinfoAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
2012-05-15 15:02:37 +00:00
$request = $this->getRequest();
$id = $request->getParam('id');
if (!empty($id)){
2012-01-30 15:18:55 +00:00
$commandesM = new Application_Model_Commandes();
2012-05-15 15:02:37 +00:00
$result = $commandesM->find($id);
2012-01-30 15:19:38 +00:00
$info = $result->current();
2012-01-30 15:18:55 +00:00
$output = array(
2012-01-30 16:07:16 +00:00
'nbLigneT' => $info->nbLigneT,
2012-05-15 15:02:37 +00:00
);
2012-01-30 15:18:55 +00:00
echo json_encode($output);
2012-05-15 15:02:37 +00:00
}
}
2012-05-15 15:02:37 +00:00
2012-01-30 15:44:30 +00:00
public function getfileAction()
{
2012-01-30 15:42:37 +00:00
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
2012-01-30 15:44:30 +00:00
$file = $request->getParam('file', '');
2012-02-20 11:46:39 +00:00
$content_type = 'application/csv-tab-delimited-table';
$path = '/sites/dataenrichissement/export/';
//Envoi du fichier sur la sortie standard
if ( file_exists($path.$file) ) {
header('Content-Transfer-Encoding: none');
header('Content-type: ' . $content_type.'');
header('Content-Length: ' . filesize($path.$file));
header('Content-MD5: ' . base64_encode(md5_file($path.$file)));
header('Content-Disposition: filename="' . basename($path.$file) . '"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression', '0');
echo file_get_contents($path.$file);
} else {
echo 'Impossible de charger le fichier.';
}
2012-01-30 15:42:37 +00:00
}
2012-05-15 15:02:37 +00:00
public function restartAction()
{
$request = $this->getRequest();
$id = $request->getParam('id');
if (!empty($id)){
$commandesM = new Application_Model_Commandes();
$data = array(
'nbLigneT' => 0,
'error' => '',
'dateStart' => '0000-00-00 00:00:00',
2012-05-15 15:02:37 +00:00
'fichierOut' => '',
);
$commandesM->update($data, "id=$id");
}
}
2012-05-15 15:02:37 +00:00
public function repriseAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$id = $request->getParam('id');
if (!empty($id)){
$commandesM = new Application_Model_Commandes();
$data = array(
'error' => '',
);
$commandesM->update($data, "id=$id");
}
2012-05-15 15:02:37 +00:00
exec("php ".APPLICATION_PATH."/../batch/enrichissement.php --reprise --id ".$id." &");
}
2012-05-15 15:02:37 +00:00
2012-01-13 13:35:11 +00:00
}