summaryrefslogtreecommitdiffstats
path: root/modules/imgmanagement
diff options
context:
space:
mode:
Diffstat (limited to 'modules/imgmanagement')
-rw-r--r--modules/imgmanagement/config.json5
-rw-r--r--modules/imgmanagement/module.inc.php76
-rw-r--r--modules/imgmanagement/templates/page-imgmanagement.html46
3 files changed, 127 insertions, 0 deletions
diff --git a/modules/imgmanagement/config.json b/modules/imgmanagement/config.json
new file mode 100644
index 00000000..49daa91a
--- /dev/null
+++ b/modules/imgmanagement/config.json
@@ -0,0 +1,5 @@
+{
+ "category":"hidden",
+ "enabled":"false",
+ "permission":"1"
+}
diff --git a/modules/imgmanagement/module.inc.php b/modules/imgmanagement/module.inc.php
new file mode 100644
index 00000000..27844e23
--- /dev/null
+++ b/modules/imgmanagement/module.inc.php
@@ -0,0 +1,76 @@
+<?php
+
+class Page_Imgmanagement extends Page
+{
+
+ private $page;
+ private $baselocation;
+ private $images;
+
+ protected function doPreprocess()
+ {
+
+ User::load();
+ if (!User::hasPermission('baseconfig_local')) {
+ Message::addError('no-permission');
+ Util::redirect('?do=Main');
+ }
+
+
+ //Depends on the server location;
+ $this->baselocation = '/var/images/';
+ $this->images = array();
+
+ error_reporting(E_ALL);
+ ini_set('display_errors','on');
+
+ Session::get('token');
+
+ }
+
+ protected function doRender()
+ {
+ /*get city of user !!!!NOT TESTED!!!!
+
+ $data=array( 'id'= User.getId());
+ $res = Database::exec("SELECT cityid FROM user WHERE userid=:id",$data);
+ $cityid = $res->fetch(PDO::FETCH_ASSOC);
+ $res = Database::exec("SELECT name FROM cities WHERE cityid=:cityid",$cityid);
+ $city = $res->fetch(PDO::FETCH_ASSOC);
+ $location = $baselocation . $city;
+
+
+ verify type of vars (string concatenation and more)
+ !!!!NOT TESTED!!!!
+ */
+
+ error_reporting(E_ALL);
+ ini_set('display_errors','on');
+ //Search images on location specified
+ $location = $this->baselocation . 'curitiba/*';
+ //Gets the configuration of each image
+ $config = substr($location,0,-1).'config.json';
+ $imgsactive = json_decode(file_get_contents($config),true);
+ $images = glob($location, GLOB_ONLYDIR);
+ $actives = array();
+ $deactives= array();
+ foreach($images as &$imgname){
+ $imgname= substr($imgname, strlen($location)-1);
+ //fill associative array (img->active[true/false])
+ $this->images[$imgname] = isset($imgsactive[$imgname])?$imgsactive[$imgname] : false;
+ if($this->images[$imgname]){
+ array_push($actives, array('name' => $imgname));
+ }else{
+ array_push($deactives, array('name'=>$imgname));
+ }
+ }
+
+ //Save eventually new images to config.json
+ $fp = fopen($config,'w');
+ fwrite($fp,json_encode($this->images));
+ fclose($fp);
+ Render::addTemplate('page-imgmanagement', array(
+ 'deactives' => $deactives,
+ 'actives' => $actives));
+ }
+}
diff --git a/modules/imgmanagement/templates/page-imgmanagement.html b/modules/imgmanagement/templates/page-imgmanagement.html
new file mode 100644
index 00000000..795ae39f
--- /dev/null
+++ b/modules/imgmanagement/templates/page-imgmanagement.html
@@ -0,0 +1,46 @@
+<div class="panel panel-default">
+ <div class="panel-heading">
+ Gerenciamento de Imagens
+ </div>
+
+ <div class="panel-body">
+ <div class="alert alert-info">
+ Imagens em azul indicam imagens criadas pelo usuário
+ </div>
+
+ <div class="panel-body col-xs-6">
+ <div class="left">
+ <ul class="source connected">
+ {{#deactives}}
+ <li>{{name}}</li>
+ {{/deactives}}
+ </ul>
+ </div>
+ </div>
+
+ <div class="panel-body col-xs-6">
+ <div class="right">
+ <ul class="target connected" id="ativa1">
+
+ {{#actives}}
+ <li>{{name}}</li>
+ {{/actives}}
+ </ul>
+ </div>
+ </div>
+
+ <a class="btn btn-default" href="#" role="button">Upload de Nova Imagem<a>
+ <a class="btn btn-info" href="#" role="button">Gerar IPXE<a>
+
+ </div>
+</div>
+
+<script src="script/jquery.sortable.min.js"></script>
+<script type="text/javascript">
+ $(document).ready(function() {
+ $(".source, .target").sortable({
+ connectWith: ".connected"
+ });
+
+ });
+</script>