2011-05-23 06:48:16 +00:00
|
|
|
<?php
|
|
|
|
class TelechargementController extends Zend_Controller_Action
|
|
|
|
{
|
|
|
|
protected $filetime = 8;
|
|
|
|
protected $path = '';
|
|
|
|
|
|
|
|
protected function getFile($url)
|
|
|
|
{
|
|
|
|
if (!is_dir($this->path)) mkdir($this->path);
|
|
|
|
|
|
|
|
require_once 'common/curl.php';
|
|
|
|
|
|
|
|
// Recuperation du nom du fichier
|
|
|
|
$tableau = explode('/', $url);
|
|
|
|
$file = $tableau[sizeof($tableau) - 1];
|
|
|
|
|
|
|
|
// Suppression du fichier si le temps de cache est depasse
|
|
|
|
if (file_exists($this->path.'/'.$file)){
|
|
|
|
$dateFile = filemtime($this->path.'/'.$file);
|
|
|
|
$now = mktime(date('G'), date('i'), date('s'),
|
|
|
|
date('m') , date('d'), date('Y'));
|
|
|
|
$maxTime = mktime(date('G',$dateFile)+$this->filetime, date('i',$dateFile),
|
|
|
|
date('s',$dateFile), date('m',$dateFile),
|
|
|
|
date('d',$dateFile), date('Y',$dateFile));
|
|
|
|
if ($maxTime-$now<0) {
|
|
|
|
unlink($this->path.'/'.$file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recuperation du fichier sur le serveur
|
|
|
|
if (!file_exists($this->path.'/'.$file)) {
|
|
|
|
// On check si le fichier est present sur l'url
|
|
|
|
$url_tab = getUrl($url, '', '', '', false);
|
|
|
|
if ($url_tab['code'] == 408 ||
|
|
|
|
$url_tab['code'] == 400 ||
|
|
|
|
$url_tab['code'] == 404) {
|
|
|
|
// Fichier non disponible
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Ecriture du fichier sur le serveur en local
|
|
|
|
$body = $url_tab['body'];
|
|
|
|
$fp = fopen($this->path.'/'.$file, 'w');
|
|
|
|
fwrite($fp, $body);
|
|
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $file;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$this->_helper->viewRenderer->setNoRender(true);
|
|
|
|
|
|
|
|
require_once 'Scores/WsScores.php';
|
|
|
|
require_once 'Scores/Utilisateur.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function consommationAction()
|
|
|
|
{
|
|
|
|
$this->path = APPLICATION_PATH.'/../cache/consommation';
|
|
|
|
$this->filetime = 1;
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$start = $request->getParam('start', false);
|
|
|
|
|
|
|
|
//On souhaite récupérer l'url du fichier
|
|
|
|
if ($start==1) {
|
|
|
|
$mois = $request->getParam('mois');
|
|
|
|
$detail = $request->getParam('detail', 0);
|
|
|
|
$idClient = $request->getParam('idClient', 0);
|
|
|
|
$login = $request->getParam('login', '');
|
|
|
|
$all = $request->getParam('all', 0);
|
|
|
|
|
|
|
|
$date = substr($mois, 3, 4).substr($mois, 0, 2);
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($login)) {
|
|
|
|
$user = new Utilisateur();
|
|
|
|
$login = $user->getLogin();
|
|
|
|
}
|
|
|
|
|
|
|
|
$ws = new WsScores();
|
|
|
|
$reponse = $ws->getLogsClients($date, $detail, $idClient, $login, $all);
|
|
|
|
|
|
|
|
Zend_Registry::get('firebug')->info($reponse);
|
|
|
|
|
|
|
|
if (!empty($reponse->result->Url)) {
|
|
|
|
echo $reponse->result->Url;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
echo 'FALSE';
|
|
|
|
exit;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$url = $request->getParam('url', '');
|
|
|
|
|
|
|
|
$file = $this->getFile($url);
|
|
|
|
|
|
|
|
Zend_Registry::get('firebug')->info('File : '.$file);
|
|
|
|
|
|
|
|
// Le fichier existe sur l'extranet
|
|
|
|
if ($file && file_exists($this->path.'/'.$file)) {
|
|
|
|
if (filesize($this->path.'/'.$file) > 0) {
|
|
|
|
echo '<u><a title="Télécharger le fichier"'.
|
|
|
|
' target="_blank" href="/fichier/consommation/'.$file.
|
|
|
|
'">Cliquez-ici pour télécharger'.
|
|
|
|
' le fichier.</a></u>';
|
|
|
|
} else {
|
|
|
|
echo 'Aucune consommmation enregistrée.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function surveillanceAction()
|
|
|
|
{
|
|
|
|
$this->path = APPLICATION_PATH.'/../cache/surveillance';
|
2011-05-23 09:04:10 +00:00
|
|
|
$this->filetime = 8;
|
2011-05-23 06:48:16 +00:00
|
|
|
|
2011-05-23 09:04:10 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$start = $request->getParam('start', false);
|
|
|
|
|
|
|
|
if ($start==1) {
|
|
|
|
$source = $request->getParam('source', '');
|
|
|
|
|
|
|
|
$user = new Utilisateur();
|
|
|
|
$login = $user->getLogin();
|
|
|
|
$idClient = $user->getIdClient();
|
|
|
|
|
|
|
|
$ws = new WsScores();
|
|
|
|
$reponse = $ws->getListeSurveillancesCsv($source, $login, $idClient);
|
|
|
|
|
|
|
|
Zend_Registry::get('firebug')->info($reponse);
|
|
|
|
|
|
|
|
if (!empty($reponse->result->Url)) {
|
|
|
|
echo $reponse->result->Url;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
echo 'FALSE';
|
|
|
|
exit;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$url = $request->getParam('url', '');
|
|
|
|
|
|
|
|
$file = $this->getFile($url);
|
|
|
|
|
|
|
|
Zend_Registry::get('firebug')->info('File : '.$file);
|
|
|
|
|
|
|
|
// Le fichier existe sur l'extranet
|
|
|
|
if ($file && file_exists($this->path.'/'.$file)) {
|
|
|
|
if (filesize($this->path.'/'.$file) > 0) {
|
|
|
|
echo '<u><a title="Télécharger le fichier"'.
|
|
|
|
' target="_blank" href="/fichier/surveillance/'.$file.
|
|
|
|
'">Cliquez-ici pour télécharger'.
|
|
|
|
' le fichier.</a></u>';
|
|
|
|
} else {
|
|
|
|
echo 'Aucune surveillance enregistrée.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
2011-05-23 06:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function portefeuilleAction()
|
|
|
|
{
|
2011-05-23 09:04:10 +00:00
|
|
|
$this->path = APPLICATION_PATH.'/../cache/surveillance';
|
|
|
|
$this->filetime = 8;
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$start = $request->getParam('start', false);
|
|
|
|
|
|
|
|
if ($start==1) {
|
|
|
|
$user = new Utilisateur();
|
|
|
|
$login = $user->getLogin();
|
|
|
|
$idClient = $user->getIdClient();
|
|
|
|
|
|
|
|
$ws = new WsScores();
|
|
|
|
$reponse = $ws->getPortefeuilleCsv($login, $idClient);
|
|
|
|
|
|
|
|
Zend_Registry::get('firebug')->info($reponse);
|
|
|
|
|
|
|
|
if (!empty($reponse->result->Url)) {
|
|
|
|
echo $reponse->result->Url;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
echo 'FALSE';
|
|
|
|
exit;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$url = $request->getParam('url', '');
|
|
|
|
|
|
|
|
$file = $this->getFile($url);
|
2011-05-23 06:48:16 +00:00
|
|
|
|
2011-05-23 09:04:10 +00:00
|
|
|
Zend_Registry::get('firebug')->info('File : '.$file);
|
|
|
|
|
|
|
|
// Le fichier existe sur l'extranet
|
|
|
|
if ($file && file_exists($this->path.'/'.$file)) {
|
|
|
|
if (filesize($this->path.'/'.$file) > 0) {
|
|
|
|
echo '<u><a title="Télécharger le fichier"'.
|
|
|
|
' target="_blank" href="/fichier/portefeuille/'.$file.
|
|
|
|
'">Cliquez-ici pour télécharger'.
|
|
|
|
' le fichier.</a></u>';
|
|
|
|
} else {
|
|
|
|
echo 'Aucune surveillance enregistrée.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
2011-05-23 06:48:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|