enrichissement/application/controllers/EnvoiController.php

140 lines
3.7 KiB
PHP
Raw Normal View History

2012-01-13 13:35:11 +00:00
<?php
2012-05-09 21:34:16 +00:00
class EnvoiController extends Zend_Controller_Action
2012-01-13 13:35:11 +00:00
{
public function init()
{
2013-10-29 10:25:57 +00:00
$this->view->headLink()->appendStylesheet('/themes/default/css/enrichissement.css');
2012-01-13 13:35:11 +00:00
}
2012-05-09 21:34:16 +00:00
2012-01-13 13:35:11 +00:00
/**
* Enter description here ...
*/
public function indexAction(){}
2012-05-09 21:34:16 +00:00
2012-01-13 13:35:11 +00:00
public function fileformAction()
{
2016-08-30 11:56:05 +02:00
$this->view->inlineScript()->appendFile('/libs/jquery.form.min.js', 'text/javascript');
2013-10-29 10:25:57 +00:00
$this->view->inlineScript()->appendFile('/themes/default/js/jqueryprogressbar.js', 'text/javascript');
2012-01-15 17:43:37 +00:00
$this->view->assign('filesize', ini_get('upload_max_filesize'));
//Récupérer les clients
2013-10-29 10:25:57 +00:00
$c = Zend_Registry::get('config');
2016-11-25 19:25:18 +01:00
$sqlmetier = Zend_Db::factory($c->profil->db->metier);
2012-01-15 17:43:37 +00:00
$sql = $sqlmetier->select()
->from('sdv1.clients', array('id', 'nom'))
->where("actif = 'Oui'");
$clients = $sqlmetier->fetchAll($sql, null, Zend_Db::FETCH_OBJ);
2012-05-09 21:34:16 +00:00
$this->view->assign('clients', $clients);
2012-01-13 13:35:11 +00:00
}
2012-05-09 21:34:16 +00:00
2012-01-13 13:35:11 +00:00
public function fileuploadAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
2012-05-09 21:34:16 +00:00
2012-01-19 15:25:47 +00:00
$request = $this->getRequest();
2012-05-09 21:34:16 +00:00
2012-01-19 15:25:47 +00:00
$name = $request->getParam('ref', '');
2012-02-01 16:58:38 +00:00
$idClient = $request->getParam('client');
if (empty($name)) {
2012-05-09 21:34:16 +00:00
echo "Référence non définie.";
}
else
{
2013-01-28 17:31:29 +00:00
$c = Zend_Registry::get('config');
$path = realpath($c->profil->path->data).'/validation';
if(!file_exists($path)) mkdir($path);
2012-05-09 21:34:16 +00:00
if ( isset($_FILES) && count($_FILES)==1 ){
$n = $_FILES['fichier']['name'];
$s = $_FILES['fichier']['size'];
$tmp_name = $_FILES['fichier']['tmp_name'];
2012-05-09 21:34:16 +00:00
$extValide = array('csv');
$extension = strrchr($n,'.');
$extension = substr($extension,1);
//Vérifier l'extension du fichier
2012-05-09 21:34:16 +00:00
if(!in_array($extension, $extValide)){
echo "Extension de fichier incorrect !";
2012-01-15 17:43:37 +00:00
} elseif (move_uploaded_file($tmp_name, $path.'/'.$idClient.'-'.$name.'.'.$extension)){
echo "Fichier envoyé, <a href=\"".
$this->view->url(array(
'controller' => 'envoi',
'action' => 'checkfile',
'file' => $idClient.'-'.$name.'.'.$extension,
))
."\">Vérifier le format</a>";
} else {
echo "Erreur : ".$_FILES['fichier']['error'];
}
2012-01-13 13:35:11 +00:00
}
}
2012-01-13 13:35:11 +00:00
}
2012-05-09 21:34:16 +00:00
2012-01-13 13:35:11 +00:00
/**
* Etat de progression de l'upload du fichier
*/
public function fileprogressAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
2012-05-09 21:34:16 +00:00
$request = $this->getRequest();
2012-01-13 13:35:11 +00:00
$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);
}
}
2012-05-09 21:34:16 +00:00
2012-01-15 17:43:37 +00:00
public function checkfileAction()
{
$request = $this->getRequest();
$file = $request->getParam('file');
2012-05-09 21:34:16 +00:00
2013-01-28 17:31:29 +00:00
$c = Zend_Registry::get('config');
2012-05-09 21:34:16 +00:00
2013-01-28 17:31:29 +00:00
$pathIn =$c->profil->path->data.'/validation';
$pathOut = $c->profil->path->data.'/clients';
2012-01-19 15:25:47 +00:00
if(!file_exists($pathOut)) mkdir($pathOut);
2012-05-09 21:34:16 +00:00
2012-01-15 17:43:37 +00:00
//Vérifier le format du fichier
2016-07-18 11:30:00 +02:00
$data = new Scores_Extract_Dict();
2012-05-09 21:34:16 +00:00
2012-01-15 17:43:37 +00:00
$result = $data->checkFileEntete($pathIn.'/'.$file);
2012-05-09 21:34:16 +00:00
if ($result===FALSE)
2012-01-15 17:43:37 +00:00
{
$this->view->assign('errors',array("Impossible de lire le fichier !"));
//Supprimer le fichier
unlink($pathIn.'/'.$file);
2012-05-09 21:34:16 +00:00
}
2012-01-15 17:43:37 +00:00
elseif (is_array($result))
{
2012-05-09 21:34:16 +00:00
$this->view->assign('errors',$result);
2012-01-15 17:43:37 +00:00
//Supprimer le fichier
unlink($pathIn.'/'.$file);
2012-05-09 21:34:16 +00:00
}
2012-01-15 17:43:37 +00:00
elseif (is_int($result))
{
//Enregistrer dans la bdd
$commandesM = new Application_Model_Commandes();
$data = array(
'fichier' => $file,
'idProfil' => 0,
'nbLigne' => $result,
'nbLigneT' => 0,
2012-01-19 15:25:47 +00:00
'error' => '',
2012-01-15 17:43:37 +00:00
'dateAdded' => date('Y-m-d H:i:s'),
);
if ($commandesM->insert($data)){
//Déplacer le fichier
2012-01-19 15:25:47 +00:00
rename($pathIn.'/'.$file, $pathOut.'/'.$file);
2012-01-15 17:43:37 +00:00
}
2012-01-19 15:25:47 +00:00
$this->view->assign('nb', $result);
2012-01-15 17:43:37 +00:00
}
}
2012-05-09 21:34:16 +00:00
2012-01-13 13:35:11 +00:00
}