220 lines
5.3 KiB
PHP
220 lines
5.3 KiB
PHP
<?php
|
|
class ReportController extends Zend_Controller_Action
|
|
{
|
|
public function init()
|
|
{
|
|
//Override
|
|
$this->view->inlineScript()
|
|
->appendFile('/libs/jquery-2.0.3.min.js', 'text/javascript')
|
|
->appendFile('/libs/bootstrap-v3.0.0/js/bootstrap.min.js', 'text/javascript');
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function indexAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$request = $this->getRequest();
|
|
|
|
//Define title
|
|
|
|
//Control the prestation with the database - inject additionnaly parameters
|
|
|
|
//Get parameters
|
|
$siren = $request->getParam('siren');
|
|
$this->view->SirenExiste = false;
|
|
if (intval($siren)>100) {
|
|
//Vérifier que le SIREN existe en base
|
|
require_once 'Scores/WsScores.php';
|
|
$ws = new WsScores('mricois', 'ju2loh6o');
|
|
$response = $ws->getIdentiteLight($siren);
|
|
if ($response !== false) {
|
|
$this->view->Siren = $response->Siren;
|
|
$this->view->RaisonSociale = $response->Nom;
|
|
$this->view->SirenExiste = true;
|
|
$this->view->ButtonUrl = $this->view->url(array(
|
|
'controller'=>'report',
|
|
'action'=>'cmd',
|
|
'siren'=>$response->Siren
|
|
));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function cmdAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$siren = $request->getParam('siren');
|
|
|
|
//Affichage du formulaires
|
|
$form = new Application_Form_Command();
|
|
if ( $request->isPost() ) {
|
|
|
|
$values = $request->getPost();
|
|
$form->populate($values);
|
|
|
|
if ( $form->isValid($values) ) {
|
|
|
|
//Sauvegarde des informations
|
|
$commandM = new Application_Model_Command();
|
|
try {
|
|
$commandM->insert($form->getValues());
|
|
//Passage à la page suivante
|
|
$url = $this->view->url(array(
|
|
'controller'=>'report',
|
|
'action'=>'deliver',
|
|
'id' => $form->getValue('cmdId'),
|
|
));
|
|
$this->redirect($url);
|
|
} catch (Zend_Db_Adapter_Exception $e) {
|
|
$this->view->msg = "Impossible de passer la commande.";
|
|
}
|
|
}
|
|
} else {
|
|
|
|
if (intval($siren)>100) {
|
|
//Get report
|
|
$report = new Scores_Partner_Report('indiscore3', $siren, 'mricois', 'ju2loh6o');
|
|
$html = $report->getContent();
|
|
|
|
if ( $html !== false ) {
|
|
|
|
$c = Zend_Registry::get('config');
|
|
$pathCmd = $c->profil->path->data;
|
|
|
|
$id = uniqid();
|
|
//Write the file (name with commande id)
|
|
if ( file_put_contents($pathCmd . DIRECTORY_SEPARATOR . $id.'.html', $html) ) {
|
|
|
|
$this->view->CmdID = $id;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$this->view->form = $form;
|
|
$this->view->siren = $siren;
|
|
|
|
}
|
|
|
|
|
|
public function deliverAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$c = Zend_Registry::get('config');
|
|
$pathCmd = $c->profil->path->data;
|
|
|
|
//Commande ID
|
|
$cmdId = $request->getParam('id');
|
|
|
|
//Est ce que la commande existe
|
|
$commandM = new Application_Model_Command();
|
|
$where = $commandM->select()->where('cmdId=?', $cmdId);
|
|
$row = $commandM->fetchRow($where);
|
|
if ( $row!==null ) {
|
|
|
|
$infos = new stdClass();
|
|
$infos->NumCommande = $row->cmdId;
|
|
$date = new Zend_Date($row->dateInsert);
|
|
$infos->DateCommande = $date->toString('dd/MM/yyyy HH:mm:ss');
|
|
$infos->RaisonSociale = $row->rs;
|
|
$infos->NomPrenom = $row->nom . ' ' . $row->prenom;
|
|
$infos->Adresse = $row->adresse;
|
|
$infos->CpVille = $row->cp . ' ' . $row->ville;
|
|
$infos->Tel = $row->tel;
|
|
$infos->Mob = $row->mobile;
|
|
|
|
$this->view->Infos = $infos;
|
|
|
|
if ( file_exists($pathCmd . DIRECTORY_SEPARATOR . $row->cmdId . '.html') ) {
|
|
//Define links to get the HTML and/or PDF
|
|
$links = array(
|
|
0 => array(
|
|
'title' => 'Fichier PDF',
|
|
'desc' => 'Télécharger le bilan financier',
|
|
'url' => $this->view->url(array(
|
|
'controller'=>'report',
|
|
'action'=>'pdf',
|
|
'id' => $row->cmdId
|
|
))
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Display in blank page the html
|
|
*/
|
|
public function htmlAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
}
|
|
|
|
/**
|
|
* Distribute pdf file
|
|
*/
|
|
public function pdfAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$file = false;
|
|
|
|
//Commande ID
|
|
$cmdId = $request->getParam('id');
|
|
|
|
//Est ce que la commande existe
|
|
$commandM = new Application_Model_Command();
|
|
$where = $commandM->select()->where('cmdId=?', $cmdId);
|
|
$row = $commandM->fetchRow($where);
|
|
if ( $row !== null ) {
|
|
|
|
//Copy html from command directory to temporary storage
|
|
$c = Zend_Registry::get('config');
|
|
$source = $c->profil->path->data . DIRECTORY_SEPARATOR . $row->cmdId . '.html';
|
|
$dest = $c->profil->path->pages . DIRECTORY_SEPARATOR . $row->cmdId . '.html';
|
|
if ( copy($source, $dest) ) {
|
|
$wkthml = new Scores_Wkhtml_Pdf();
|
|
$file = $wkhtml->exec($dest);
|
|
}
|
|
|
|
}
|
|
|
|
//Distribute it to the output
|
|
if ( $file ) {
|
|
if( file_exists($file) && filesize($file)>0 ) {
|
|
header('Content-Transfer-Encoding: none');
|
|
header('Content-type: ' . $content_type.'');
|
|
header('Content-Length: ' . filesize($file));
|
|
header('Content-MD5: ' . base64_encode(md5_file($file)));
|
|
header('Content-Disposition: filename="' . basename($file) . '"');
|
|
header('Cache-Control: private, max-age=0, must-revalidate');
|
|
header('Pragma: public');
|
|
ini_set('zlib.output_compression', '0');
|
|
echo file_get_contents($file);
|
|
} else {
|
|
echo "Erreur lors de l'affichage du fichier.";
|
|
}
|
|
} else {
|
|
echo "Erreur lors de la génération du fichier.";
|
|
}
|
|
}
|
|
|
|
} |