Definition architecture
This commit is contained in:
parent
bdce1b423e
commit
b35b5c7329
@ -1,4 +1,29 @@
|
||||
<?php
|
||||
return array(
|
||||
|
||||
array(
|
||||
'label'=> "Prestations",
|
||||
'title' => "",
|
||||
'controller' => 'index',
|
||||
'action' => 'index',
|
||||
'pages' => array(
|
||||
array(
|
||||
'label' => "Résumé",
|
||||
'title' => 'Listes de vos prestations',
|
||||
'controller' => 'presta',
|
||||
'action' => 'index',
|
||||
),
|
||||
array(
|
||||
'label' => "Fichiers",
|
||||
'title' => 'Listes de vos fichiers',
|
||||
'controller' => 'presta',
|
||||
'action' => 'files',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'label'=> "Contact",
|
||||
'title' => "Contact",
|
||||
'controller' => 'contact',
|
||||
'action' => 'index',
|
||||
),
|
||||
);
|
8
application/controllers/FileController.php
Normal file
8
application/controllers/FileController.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
class FileController extends Zend_Controller_Action
|
||||
{
|
||||
public function init(){}
|
||||
|
||||
public function indexAction(){}
|
||||
|
||||
}
|
@ -4,7 +4,7 @@ class IndexController extends Zend_Controller_Action
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
|
||||
// --- Liste des prestations
|
||||
|
||||
}
|
||||
|
||||
|
8
application/controllers/PrestaController.php
Normal file
8
application/controllers/PrestaController.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
class PrestaController extends Zend_Controller_Action
|
||||
{
|
||||
public function init(){}
|
||||
|
||||
public function indexAction(){}
|
||||
|
||||
}
|
@ -7,17 +7,15 @@
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="<?=$this->url(array('controller'=>'index', 'action'=>'index'), null, true)?>">Backoffice</a>
|
||||
<a class="navbar-brand" href="<?=$this->url(array('controller'=>'index', 'action'=>'index'), null, true)?>">WebFiler</a>
|
||||
</div>
|
||||
<div class="collapse navbar-collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<?php foreach ($this->navigation()->getContainer() as $page) {?>
|
||||
<li class="dropdown<?php if ( $page->isActive(true) ) { echo ' active'; } ?>">
|
||||
<?php if ( $page->hasPages() ) {?>
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><?=$page->label?> <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="<?=$page->getHref()?>">Accueil</a></li>
|
||||
<li class="divider"></li>
|
||||
<?php if ( $page->hasPages() ) {?>
|
||||
<?php foreach ( $page->getPages() as $child ) {?>
|
||||
<?php if ( $child->getHref() == '#') {?>
|
||||
<li class="divider"></li>
|
||||
@ -25,6 +23,8 @@
|
||||
<li <?php if ( $child->isActive(true) ) { echo "class='active'"; } ?>><a href="<?=$child->getHref()?>"><?=$child->label?></a></li>
|
||||
<?php }?>
|
||||
<?php }?>
|
||||
<?php } else {?>
|
||||
<a href="#"><?=$page->label?></a>
|
||||
<?php }?>
|
||||
</ul>
|
||||
</li>
|
||||
|
14
application/views/helpers/FileSize.php
Normal file
14
application/views/helpers/FileSize.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
class Zend_View_Helper_FileSize extends Zend_View_Helper_Abstract
|
||||
{
|
||||
public function fileSize($size)
|
||||
{
|
||||
$units = array('KB', 'MB', 'GB', 'TB', 'PB');
|
||||
$currUnit = '';
|
||||
while (count($units) > 0 && $size > 1024) {
|
||||
$currUnit = array_shift($units);
|
||||
$size /= 1024;
|
||||
}
|
||||
return ($size | 0) . ' ' . $currUnit;
|
||||
}
|
||||
}
|
17
application/views/helpers/ProfileLink.php
Normal file
17
application/views/helpers/ProfileLink.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_ProfileLink extends Zend_View_Helper_Abstract
|
||||
{
|
||||
public function profileLink()
|
||||
{
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if ($auth->hasIdentity()) {
|
||||
$username = $auth->getIdentity()->username;
|
||||
$logoutUrl = $this->view->url(array(
|
||||
'controller' => 'user',
|
||||
'action' => 'logout'
|
||||
), null, true);
|
||||
return '<a href="'.$logoutUrl.'" title="Se déconnecter" class="navbar-link">Déconnexion : ' . $username . '</a>';
|
||||
}
|
||||
}
|
||||
}
|
@ -1 +1,6 @@
|
||||
<?php
|
||||
<div class="container-fluid">
|
||||
|
||||
<h3>Liste des prestations</h3>
|
||||
|
||||
|
||||
</div>
|
@ -13,7 +13,7 @@
|
||||
<div class="container">
|
||||
|
||||
<form class="form-signin" method="<?=$this->form->getMethod()?>" action="<?=$this->form->getAction()?>">
|
||||
<h2 class="form-signin-heading">Backoffice</h2>
|
||||
<h2 class="form-signin-heading">WebFiler</h2>
|
||||
<input name="login" value="<?=$this->form->getValue('login')?>" type="text" class="form-control" placeholder="Identifiant" autofocus>
|
||||
<input name="pass" value="<?=$this->form->getValue('pass')?>" type="password" class="form-control" placeholder="Mot de passe">
|
||||
<button class="btn btn-lg btn-primary btn-block" type="submit">Connexion</button>
|
@ -9,7 +9,7 @@
|
||||
"classmap": [
|
||||
"application/",
|
||||
"library/Application/",
|
||||
"library/Scores/",
|
||||
"library/Scores/"
|
||||
]
|
||||
},
|
||||
"authors": [
|
||||
|
66
composer.lock
generated
Normal file
66
composer.lock
generated
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "21cd92d8299580fb00abd42b96cd39d8",
|
||||
"content-hash": "29c45f207db6f7e602df7361e5d3b32e",
|
||||
"packages": [
|
||||
{
|
||||
"name": "zendframework/zendframework1",
|
||||
"version": "1.12.16",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zendframework/zf1.git",
|
||||
"reference": "8a3c471ef0a337d303cd5ae578e64c2ba1d2c025"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/zendframework/zf1/zipball/8a3c471ef0a337d303cd5ae578e64c2ba1d2c025",
|
||||
"reference": "8a3c471ef0a337d303cd5ae578e64c2ba1d2c025",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.2.11"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/dbunit": "1.3.*",
|
||||
"phpunit/phpunit": "3.7.*"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.12.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Zend_": "library/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"include-path": [
|
||||
"library/"
|
||||
],
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"description": "Zend Framework 1",
|
||||
"homepage": "http://framework.zend.com/",
|
||||
"keywords": [
|
||||
"ZF1",
|
||||
"framework"
|
||||
],
|
||||
"time": "2015-09-15 15:49:51"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": []
|
||||
}
|
@ -18,63 +18,10 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
||||
$checkAuth = false;
|
||||
}
|
||||
|
||||
// --- Pas d'authentification sur ces services
|
||||
if ( in_array($controller, array('service', 'import'))
|
||||
|| ( $controller == 'fichier' && $action == 'logs' )
|
||||
|| ( $controller == 'fichier' && $action == 'kbis' )
|
||||
|| ( $controller == 'fichier' && $action == 'csv' )
|
||||
|| ( $controller == 'fichier' && $action == 'associations' )
|
||||
|| ( $controller == 'fichier' && $action == 'greffes' )
|
||||
|| ( $controller == 'fichier' && $action == 'crm' )) {
|
||||
$checkAuth = false;
|
||||
}
|
||||
|
||||
$checkWs = true;
|
||||
if ( $controller == 'fichier' ) {
|
||||
$checkWs = false;
|
||||
}
|
||||
|
||||
if ($checkAuth) {
|
||||
$login = $request->getParam('login');
|
||||
$pass = $request->getParam('pass', '');
|
||||
|
||||
$hach = $request->getParam('hach');
|
||||
if (!empty($hach)) {
|
||||
$pass = $hach;
|
||||
}
|
||||
|
||||
$auth = Zend_Auth::getInstance();
|
||||
|
||||
// --- On vérifie le tout lors d'une connexion par url
|
||||
if ( !empty($login) && !empty($pass) ) {
|
||||
|
||||
$authAdapter = new Scores_Auth_Adapter_Db($login, $pass, $checkWs);
|
||||
$result = $auth->authenticate($authAdapter);
|
||||
|
||||
if ($result->isValid()) {
|
||||
|
||||
$storage = new Zend_Auth_Storage_Session();
|
||||
$session = new Zend_Session_Namespace($storage->getNamespace());
|
||||
//$session->setExpirationSeconds(86400);
|
||||
$auth->setStorage($storage);
|
||||
|
||||
} else {
|
||||
|
||||
$layout = Zend_Layout::getMVCInstance();
|
||||
if ( !$layout->isEnabled() ){
|
||||
echo "Identification incorrect ou périmé.";
|
||||
} else {
|
||||
$request->setModuleName('default')
|
||||
->setControllerName('user')
|
||||
->setActionName('logout');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Sinon on reste sur le standard
|
||||
} else {
|
||||
|
||||
//Pas authentifié
|
||||
// --- Pas authentifié
|
||||
if ( !$auth->hasIdentity() || time() > $auth->getIdentity()->time ) {
|
||||
|
||||
$layout = Zend_Layout::getMVCInstance();
|
||||
@ -84,7 +31,7 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
||||
$this->_response->setRedirect('/user/login')->sendResponse();
|
||||
}
|
||||
|
||||
//Authentifié => on met à jour la session
|
||||
// --- Authentifié => on met à jour la session
|
||||
} else {
|
||||
|
||||
$identity = $auth->getIdentity();
|
||||
@ -92,7 +39,7 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
||||
$auth->getStorage()->write($identity);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
24
library/Application/Controller/Plugin/Menu.php
Normal file
24
library/Application/Controller/Plugin/Menu.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
class Application_Controller_Plugin_Menu extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
/**
|
||||
* Créer le menu en fonction des besoins et des paramètres en entrée
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
*/
|
||||
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$layout = Zend_Layout::getMVCInstance();
|
||||
|
||||
$controller = $request->getControllerName();
|
||||
$action = $request->getActionName();
|
||||
|
||||
if ( $layout->isEnabled() && $controller!='user' )
|
||||
{
|
||||
$view = $layout->getView();
|
||||
$config = include APPLICATION_PATH . '/configs/menu.config.php';
|
||||
$container = new Zend_Navigation($config);
|
||||
$view->navigation($container);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
6
library/Application/Model/Sdv1ClientsPresta.php
Normal file
6
library/Application/Model/Sdv1ClientsPresta.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
class Application_Model_Sdv1ClientsPresta extends Zend_Db_Table_Abstract
|
||||
{
|
||||
protected $_name = 'clients_presta';
|
||||
protected $_schema = 'sdv1';
|
||||
}
|
13
library/Application/Model/Sdv1Utilisateurs.php
Normal file
13
library/Application/Model/Sdv1Utilisateurs.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
class Application_Model_Sdv1Utilisateurs extends Zend_Db_Table_Abstract
|
||||
{
|
||||
protected $_name = 'utilisateurs';
|
||||
protected $_schema = 'sdv1';
|
||||
protected $_referenceMap = array(
|
||||
'Reporter' => array(
|
||||
'columns' => 'idClient',
|
||||
'refTableClass' => 'Sdv1Clients',
|
||||
'refColumns' => 'id'
|
||||
),
|
||||
);
|
||||
}
|
@ -1 +1,5 @@
|
||||
<?php
|
||||
class Application_Model_WebfilerPrestaDetail extends Zend_Db_Table_Abstract
|
||||
{
|
||||
|
||||
}
|
@ -1 +1,5 @@
|
||||
<?php
|
||||
class Application_Model_WebfilerPrestaFiles extends Zend_Db_Table_Abstract
|
||||
{
|
||||
|
||||
}
|
@ -1 +1,5 @@
|
||||
<?php
|
||||
class Application_Model_WebfilerPrestaLogin extends Zend_Db_Table_Abstract
|
||||
{
|
||||
|
||||
}
|
@ -1 +1,5 @@
|
||||
<?php
|
||||
class Application_Model_WebfilerPrestaManuel extends Zend_Db_Table_Abstract
|
||||
{
|
||||
|
||||
}
|
@ -1 +1,5 @@
|
||||
<?php
|
||||
class Application_Model_WebfilerUser extends Zend_Db_Table_Abstract
|
||||
{
|
||||
|
||||
}
|
72
library/Scores/Auth/Adapter/Webfiler.php
Normal file
72
library/Scores/Auth/Adapter/Webfiler.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
class Scores_Auth_Adapter_Webfiler implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
protected $_username;
|
||||
|
||||
protected $_password;
|
||||
|
||||
protected $_hash;
|
||||
|
||||
protected $_timeout = 3600;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
*/
|
||||
public function __construct($username, $password)
|
||||
{
|
||||
$this->_username = $username;
|
||||
$this->_password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the timeout
|
||||
* @param integer $seconds
|
||||
*/
|
||||
public function setTimeout($seconds = null)
|
||||
{
|
||||
if ($seconds===null)
|
||||
return;
|
||||
|
||||
$this->_timeout = $seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see Zend_Auth_Adapter_Interface::authenticate()
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
$userM = new Application_Model_Sdv1Utilisateurs();
|
||||
|
||||
$sql = $userM->select()
|
||||
->setIntegrityCheck(false)
|
||||
->from(array('u'=>'user'), array('u.clientId', 'u.id', 'u.login', 'u.password'), 'webfiler')
|
||||
->join(array('c'=>'clients'), 'u.clientId = c.id', array(), 'sdv1')
|
||||
->where('u.login=?', $this->_username)
|
||||
->where('u.deleted=?', 0)
|
||||
->where('c.actif=?','Oui');
|
||||
|
||||
$result = $userM->fetchRow($sql);
|
||||
|
||||
$identity = new stdClass();
|
||||
$identity->username = $this->_username;
|
||||
|
||||
if ( null === $result ) {
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, $identity);
|
||||
} else {
|
||||
if ( password_verify($this->_password, $result->password) ) {
|
||||
$identity->hash = $result->password;
|
||||
$identity->id = $result->id;
|
||||
$identity->clientId = $result->clientId;
|
||||
$timeout = (!empty($result->timeout)) ? $result->timeout : $this->_timeout;
|
||||
$identity->timeout = $timeout;
|
||||
$identity->time = time() + $timeout;
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
|
||||
} else {
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +1,15 @@
|
||||
<?php
|
||||
// Define path to application directory
|
||||
// --- Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
|
||||
|| define('APPLICATION_PATH', realpath(__DIR__ . '/../application'));
|
||||
|
||||
// Define application environment
|
||||
// --- Define application environment
|
||||
defined('APPLICATION_ENV')
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
// --- Composer autoload
|
||||
require_once realpath(__DIR__ . '/../vendor/autoload.php');
|
||||
|
||||
if (APPLICATION_ENV != 'production'){
|
||||
ini_set("soap.wsdl_cache_enabled", "0");
|
||||
}
|
||||
require_once '../config/config.php';
|
||||
|
||||
/** Zend_Application */
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
$application->bootstrap()
|
||||
->run();
|
||||
// --- Create application, bootstrap, and run
|
||||
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
|
||||
$application->bootstrap()->run();
|
56
public/themes/default/css/main.css
Normal file
56
public/themes/default/css/main.css
Normal file
@ -0,0 +1,56 @@
|
||||
/* Sticky footer styles
|
||||
-------------------------------------------------- */
|
||||
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
/* The html and body elements cannot have any padding or margin. */
|
||||
}
|
||||
|
||||
/* Wrapper for page content to push down footer */
|
||||
#wrap {
|
||||
min-height: 100%;
|
||||
height: auto !important;
|
||||
height: 100%;
|
||||
/* Negative indent footer by its height */
|
||||
margin: 0 auto -60px;
|
||||
/* Pad bottom by footer height */
|
||||
padding: 0 0 60px;
|
||||
}
|
||||
|
||||
/* Set the fixed height of the footer here */
|
||||
#footer {
|
||||
height: 60px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
|
||||
/* Custom page CSS
|
||||
-------------------------------------------------- */
|
||||
/* Not required for template or sticky footer method. */
|
||||
body { font-size:12px; }
|
||||
|
||||
.container .credit {
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
#footer > .container {
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
p.bg-classes {
|
||||
padding:15px;
|
||||
}
|
||||
|
||||
#wrap .h1, #wrap .h2, #wrap .h3, #wrap h1, #wrap h2, #wrap h3 {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
#wrap .breadcrumb {
|
||||
margin-bottom: 0px;
|
||||
}
|
73
public/themes/default/css/signin.css
Normal file
73
public/themes/default/css/signin.css
Normal file
@ -0,0 +1,73 @@
|
||||
body {
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
/* The html and body elements cannot have any padding or margin. */
|
||||
}
|
||||
|
||||
/* Wrapper for page content to push down footer */
|
||||
#wrap {
|
||||
min-height: 100%;
|
||||
height: auto !important;
|
||||
height: 100%;
|
||||
/* Negative indent footer by its height */
|
||||
margin: 0 auto -60px;
|
||||
/* Pad bottom by footer height */
|
||||
padding: 0 0 60px;
|
||||
}
|
||||
|
||||
#wrap > .container {
|
||||
padding: 60px 15px 0;
|
||||
}
|
||||
.container .credit {
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
/* Set the fixed height of the footer here */
|
||||
#footer {
|
||||
height: 60px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
#footer > .container {
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
}
|
||||
|
||||
.form-signin {
|
||||
max-width: 330px;
|
||||
padding: 15px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.form-signin .form-signin-heading,
|
||||
.form-signin .checkbox {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.form-signin .checkbox {
|
||||
font-weight: normal;
|
||||
}
|
||||
.form-signin .form-control {
|
||||
position: relative;
|
||||
font-size: 16px;
|
||||
height: auto;
|
||||
padding: 10px;
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.form-signin .form-control:focus {
|
||||
z-index: 2;
|
||||
}
|
||||
.form-signin input[type="text"] {
|
||||
margin-bottom: -1px;
|
||||
border-bottom-left-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
}
|
||||
.form-signin input[type="password"] {
|
||||
margin-bottom: 10px;
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
}
|
@ -1 +0,0 @@
|
||||
<?php
|
150
scripts/jobs/integrate.php
Normal file
150
scripts/jobs/integrate.php
Normal file
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
// --- Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(__DIR__ . '/../../application'));
|
||||
|
||||
// --- Define application environment
|
||||
defined('APPLICATION_ENV')
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|
||||
// --- Composer autoload
|
||||
require_once realpath(__DIR__ . '/../../vendor/autoload.php');
|
||||
|
||||
// --- Create application, bootstrap, and run
|
||||
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Affiche l'aide.",
|
||||
'cron' => "Use in crontab",
|
||||
'user=s' => "Regen for user et toutes ses prestations",
|
||||
'presta=s' => "Regen for a prestation",
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
echo $e->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
//Usage
|
||||
if(count($opts->getOptions())==0 || isset($opts->help))
|
||||
{
|
||||
echo "Integrate file in webfiler.";
|
||||
echo "\n\n";
|
||||
echo $opts->getUsageMessage();
|
||||
echo "\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$c = new Zend_Config($application->getOptions());
|
||||
$db = Zend_Db::factory($c->resources->db);
|
||||
|
||||
$prestaSql = $db->select()
|
||||
->from(array('p'=>'clients_presta'), array(), 'sdv1')
|
||||
->join(array('c'=>'clients'), 'c.id = p.clientId ', 'sdv1')
|
||||
->where('p.actif = ?', 1)
|
||||
->where('c.actif = ?', 'Oui');
|
||||
|
||||
$prestaList = $db->fetchAll($prestaSql, Zend_Db::FETCH_OBJ);
|
||||
|
||||
foreach ($prestaList as $p) {
|
||||
echo date('Y-m-d H:i:s')." - Recherche des paramètres pour la prestation ".$p->code."\n";
|
||||
|
||||
$params = array();
|
||||
$paramSql = $db->select()->from('prestadetail', array(), 'webfiler')->where('prestaCode = ?', $p->code);
|
||||
$paramResult = $db->fetchAll($paramSql, Zend_Db::FETCH_OBJ);
|
||||
if (count($paramsResult) > 0) {
|
||||
foreach ($params as $item) {
|
||||
$params[$item->name] = $item->value;
|
||||
}
|
||||
} else {
|
||||
echo date('Y-m-d H:i:s')." - Aucun paramètre.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
// --- Traitement
|
||||
if (count($params) > 0) {
|
||||
switch ($params['type']) {
|
||||
case 'db':
|
||||
// --- Lecture de la base de données pour obtenir la liste des fichiers
|
||||
$stmt = $db->query($sql);
|
||||
$rows = $stmt->fetchAll(Zend_Db::FETCH_OBJ);
|
||||
if (count($rows) > 0) {
|
||||
foreach ($rows as $f) {
|
||||
$directory = $f->directory;
|
||||
if (substr($f->directory, -1) == '/') {
|
||||
$directory = substr($f->directory, 0, strlen($f->directory)-1);
|
||||
}
|
||||
if (substr($directory, 0, 1) == '/') {
|
||||
$filename = $directory.'/'.$f->file;
|
||||
} else {
|
||||
$filename = $c->profil->path->secure.'/'.$directory.'/'.$f->file;
|
||||
}
|
||||
|
||||
if (file_exists($filename)) {
|
||||
|
||||
$fileDate = filectime($filename);
|
||||
$fileSize = filesize($filename);
|
||||
$fileMd5 = md5_file($filename);
|
||||
$fileSha1 = sha1_file($filename);
|
||||
|
||||
// --- Enregistrer dans la base
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'file':
|
||||
// --- Lecture du repertoire pour obtenir la liste des fichiers
|
||||
$directory = $params['directory'];
|
||||
if (substr($params['directory'], -1) == '/') {
|
||||
$directory = substr($params['directory'], 0, strlen($params['directory'])-1);
|
||||
}
|
||||
if (substr($directory, 0, 1) != '/') {
|
||||
$directory = $c->profil->path->secure.'/'.$directory;
|
||||
}
|
||||
if ($handle = opendir($directory)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file != "." && $file != "..") {
|
||||
|
||||
// --- Masque de fichier
|
||||
if (array_key_exists('filemask', $params)) {
|
||||
$pattern = '/'.$params['filemask'].'/';
|
||||
if (!preg_match($pattern, $file)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$filename = $directory.'/'.$file;
|
||||
$fileDate = filectime($filename);
|
||||
|
||||
// --- Calcul du nombre de jours
|
||||
$dateNow = new Zend_Date();
|
||||
$dateFile = new Zend_Date($fileDate, Zend_Date::TIMESTAMP);
|
||||
$difference = $dateNow->sub($dateFile);
|
||||
$measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::DAY);
|
||||
$measure->convertTo(Zend_Measure_Time::DAY);
|
||||
$nbJour = $measure->getValue(0);
|
||||
if ($nbJour > $params['maxkeepday']) {
|
||||
continue;
|
||||
}
|
||||
$fileSize = filesize($filename);
|
||||
$fileMd5 = md5_file($filename);
|
||||
$fileSha1 = sha1_file($filename);
|
||||
|
||||
// --- Enregistrer dans la base
|
||||
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
echo date('Y-m-d H:i:s')." - Type inconnu.\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user