Skip to content

Commit

Permalink
supression du module d'upload
Browse files Browse the repository at this point in the history
  • Loading branch information
willkoua committed Jun 15, 2016
1 parent 0c2f8cd commit 19f7a8c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 143 deletions.
2 changes: 1 addition & 1 deletion config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
$routes->connect('/tv/*', ['controller' => 'Pages', 'action' => 'tv']);
$routes->connect('/pages/tv/*', ['controller' => 'Pages', 'action' => 'tv']);
$routes->connect('/pages/statistics', ['controller' => 'Pages', 'action' => 'statistics']);
$routes->connect('/pages/administration/*', ['controller' => 'Pages', 'action' => 'administration']);
$routes->connect('/pages/administration', ['controller' => 'Pages', 'action' => 'administration']);

/**
* ...and connect the rest of 'Pages' controller's URLs.
Expand Down
93 changes: 3 additions & 90 deletions src/Controller/PagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public function isAuthorized($user)
{
$user = $this->Users->findById($user['id'])->first();

if ($user && ($this->request->action == "administration" || $this->request->action == "deleteImg")
&& $user->hasRoleName(['Administrator'])
if ($user && ($this->request->action == "administration") && $user->hasRoleName(['Administrator'])
) {
return true;
}
Expand Down Expand Up @@ -103,7 +102,6 @@ public function display()
public function home()
{
//$this->viewBuilder()->layout(false);
set_time_limit(1000);
$this->loadModel("Users");
$numberUsers = $this->Users->find('all')->count();
$numberStudents = $this->Users->find('all')->where(['isStudent' => true])->count();
Expand Down Expand Up @@ -148,10 +146,7 @@ public function home()
);
$numberMissions = count($missions->toArray());

$path = WWW_ROOT . "img/carousel/";
$fichiers = $this->_getImgagesDir($path);

$this->set(compact('numberUsers', 'numberProjects', 'numberMissions', 'numberStudents', 'fichiers'));
$this->set(compact('numberUsers', 'numberProjects', 'numberMissions', 'numberStudents'));
}

/**
Expand Down Expand Up @@ -579,88 +574,6 @@ public function administration($img = null)
)
->fetchAll('assoc');

//gestion des images du carousel
$pathCar = WWW_ROOT . "img/carousel/";
$pathTV = WWW_ROOT . "img/tv/";
chmod($pathCar, 777);
chmod($pathTV, 777);
$request = $this->request;

if (is_file($pathCar . $img)) {
if (unlink($pathCar . $img)) {
$this->Flash->success(__('file deleted'), 'er_gene');
} else {
$this->Flash->error(__('no file deleted'), 'er_gene');
}
}
if ($request->is('post') && !empty($request->data)) {
$image = $request->data['avatar_file'];
$hidden = $request->data('hidden');
$fileName = $image['name'];
$dim = null;
$path = null;
$flag = false;

if (!empty($image['tmp_name'])) {
if ($image['type'] == 'image/png') {
$dim = getimagesize($image['tmp_name']);

if ($dim[0] >= 1920 && $dim[1] >= 1080) {
if ($hidden == 'car') {
$flag = true;
$path = $pathCar;
}
if ($hidden == 'tv') {
if (preg_match("#^tv[1-5]$#", $fileName)) {
$flag = true;
$path = $pathTV;
} else {
$this->Flash->error(__('rename image file (tv[1,2,3,4 or 5])'), ['key' => 'er_tv']);
}
}
if ($flag && !empty($path)) {
if (move_uploaded_file($image['tmp_name'], $path . $fileName)) {
$this->Flash->success(__('file transfer'), 'er_gene');
} else {
$this->Flash->error(__('no file transfer'), 'er_gene');
}
} else {
$this->Flash->error(__('path specified not valid'), 'er_gene');
}
} else {
$this->Flash->error(__('image file size incorrect'), 'er_gene');
}
} else {
$this->Flash->error(__('the format is not good'), 'er_gene');
}
} else {
$this->Flash->error(__('no file transfer'), 'er_gene');
}
}
//fin gestion du carousel
$filesCar = $this->_getImgagesDir($pathCar);
$filesTV = $this->_getImgagesDir($pathTV);
$this->set(compact('projects', 'organizations', 'filesCar', 'filesTV'));
}

/**
* _getImgagesDir method
*
* @param string $path _getImgagesDir page
*
* @return array
*/
private function _getImgagesDir($path)
{
$fichiers = [];

if (false !== ($dossier = opendir($path))) {
while (false !== ($fichier = readdir($dossier))) {
if ($fichier != '.' && $fichier != '..' && $fichier != 'index.php') {
array_push($fichiers, $fichier);
}
}
}
return $fichiers;
$this->set(compact('projects', 'organizations'));
}
}
52 changes: 0 additions & 52 deletions src/Template/Pages/administration.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -115,56 +115,4 @@
</div>
</div>
</div>
<div class="col-lg-6 col-xs-12 hidden-xs hide">
<div class="panel panel-default">
<div class="panel-body">
<h3 class="header-title">TV</h3>

<div class="row">
<div class="col-lg-12 col-md-12">

<?php
$i = 0;
foreach ($filesTV as $fichier):
$i++;
?>
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<img src="<?= $this->request->webroot . "img/tv/". $fichier ?>" />
<div class="caption">
<p><?= "tv".$i ?></p>
</div>
</div>
</div>
<?php endforeach; ?>

</div>

<div class="col-lg-12 col-md-12">
<div class='col-lg-5 col-lg-offset-2'>
<h4>Enregistrer une image</h4>

<?= $this->Flash->render('er_tv'); ?>
<?= $this->Flash->render('er_gene'); ?>
<?= $this->Form->create('image', array('type'=>'file')); ?>
<ul>
<li>Format png</li>
<li>Exemple de nom de fichier: tv1.png</li>
<li>Taille minimale (1920 x 1080)</li>
</ul>

<?= $this->Form->hidden('hidden', ['value' => 'tv']); ?>
<?= $this->Form->input('avatar_file', array('label' => 'Envoyer votre image',
'type' => 'file')); ?>

<?= $this->Form->button('Envoyé'); ?>
<?= $this->Form->end(); ?>
</div>

</div>
</div>

</div>
</div>
</div>
</div>

0 comments on commit 19f7a8c

Please sign in to comment.