v20201206
authorKilian Saffran <ksaffran@dks.lu>
Mon, 7 Dec 2020 06:47:25 +0000 (07:47 +0100)
committerKilian Saffran <ksaffran@dks.lu>
Mon, 7 Dec 2020 06:47:25 +0000 (07:47 +0100)
13 files changed:
admin/.htaccess
admin/db.php
admin/js/filedata.js
admin/js/modules/galleries.js
admin/js/modules/gallery.js
admin/lib/config.php
admin/lib/helper.php [new file with mode: 0644]
admin/lib/modules/Gallery.php
admin/lib/phpini.php [new file with mode: 0644]
admin/tmpl/elements/dialogs/dlg_gallerymoveitem.html.mustache [new file with mode: 0644]
admin/tmpl/elements/dialogs/dlgaddgalleryitem.html.mustache
admin/tmpl/pages/galleries.html.mustache
admin/upload.php

index edc875e..cb2a886 100644 (file)
@@ -4,6 +4,8 @@ DirectoryIndex index.php index.html
 php_flag display_startup_errors off\r
 php_flag display_errors off\r
 php_flag html_errors off\r
+php_value post_max_size 32M\r
+php_value upload_max_filesize 32M\r
 RewriteCond %{REQUEST_FILENAME} !-f\r
 RewriteCond %{REQUEST_FILENAME} !-d\r
 RewriteRule "^(.*)$" "index.php"  [NC,L,QSA]
\ No newline at end of file
index 46cce8c..3a4a355 100644 (file)
@@ -74,6 +74,9 @@
     $html["sql"] = $updsql;
     $html["data"] = $db->exec($updsql);
 
+  } elseif(isset($params["getconfig"])){
+    $helper = new helper();
+    $html["data"] = $helper->getiniconfig($params["getconfig"]);
   }
    elseif(isset($params["logout"])){
     $html["data"] = $sess->deleteSession($vars["sid"]);
index 3c60908..090f980 100644 (file)
@@ -2,12 +2,14 @@ let filedata = {
   getfileinfo: function (fileobjid){
     var files = {"count":0,"size":0,"sizehr":"0 bytes","fileinfo":[]};
     var nBytes = 0;
-    var oFiles = document.getElementById(fileobjid).files;
-    files.count = oFiles.length;
-    for (var nFileId = 0; nFileId < files.count; nFileId++) {
-      var nfo = {"name":name,"type":type,"size":oFiles[nFileId].size,"sizehr":filedata.sizeHumanReadble(oFiles[nFileId].size)} 
-      files.fileinfo.push(nfo);
-      nBytes += oFiles[nFileId].size;
+    if (document.getElementById(fileobjid).files.length != 0){
+      var oFiles = document.getElementById(fileobjid).files;
+      files.count = oFiles.length;
+      for (var nFileId = 0; nFileId < files.count; nFileId++) {
+        var nfo = {"name":oFiles[nFileId].name,"type":oFiles[nFileId].type,"size":oFiles[nFileId].size,"sizehr":filedata.sizeHumanReadble(oFiles[nFileId].size)} 
+        files.fileinfo.push(nfo);
+        nBytes += oFiles[nFileId].size;
+      }
     }
     files.size = nBytes;
     files.sizehr = filedata.sizeHumanReadble(nBytes);
@@ -16,9 +18,9 @@ let filedata = {
   sizeHumanReadble: function(nBytes){
     var sOutput = nBytes + " bytes" 
     for (var aMultiples = ["KB", "MB", "GB"], nMultiple = 0, nApprox = nBytes / 1024; nApprox > 1; nApprox /= 1024, nMultiple++) {
-      sOutput = nApprox.toFixed(3) + " " + aMultiples[nMultiple] + " (" + nBytes + " bytes)";
+      sOutput = nApprox.toFixed(2) + " " + aMultiples[nMultiple] + " (" + nBytes + " bytes)";
     }
-    return sOutput;
+    return sOutput.replace(/\./,',');
   }
   
 }
\ No newline at end of file
index 064c5a2..09c1ee6 100644 (file)
@@ -13,10 +13,13 @@ let galleries = {
       //   //e.preventDefault();
       //   galleries.edit();
       // },
+      rowFormatter:function(row, data){},
       rowContext:function(e, row){ e.preventDefault(); },
         columns: [
-          {title: "Gallerie", field: "gallery"},
-          {title: "description",field: "description"}
+          {title: "Image", field: "picture",formatter:previewFormatter,width:200},
+          {title: "Gallerie", field: "gallery",width: 150},
+          {title: "description",field: "description"},
+          {title: "Élements",field: "items",formatter:"number", width: 50}
       ]
     });
     
@@ -45,4 +48,9 @@ let galleries = {
   remove: function(){
 
   }
-} 
\ No newline at end of file
+} 
+
+let previewFormatter = function(cell, formatterParams){
+  
+  return '<div><img style="height: 75px;" src="media/galleries/' + cell.getValue()+'" /></div>';
+};
\ No newline at end of file
index 7a699e5..f1bc06a 100644 (file)
@@ -1,8 +1,9 @@
 let gallery = {
   id_gallery: null,
   gallery_folder: null,
+  maxuploadsize: null,
   tbl: null,
-  selects: {},
+  selects: {"movegalleryitem_id_gallery":null},
   viewpanel: function(id){
     gallery.id_gallery=id;
     let sel = galleries.tbl.getSelectedData();
@@ -27,6 +28,10 @@ let gallery = {
       altFormat: "d.m.Y",dateFormat: "Y-m-d","locale": "fr",
       // onClose: function(selectedDates, dateStr, instance) {}
     });
+    gallery.selects["movegalleryitem_id_gallery"] = new SlimSelect({
+      select: "#movegalleryitem_id_gallery",
+      showSearch: false
+    });
     tinymce.init({
       selector: '#galleryitem_description,#galleries_description',
       plugins: 'paste importcss searchreplace autolink directionality visualblocks visualchars template charmap nonbreaking advlist lists  textpattern noneditable charmap autoresize ',
@@ -64,12 +69,7 @@ let gallery = {
       
       selectable: true,
       selectableRangeMode:"click",
-      //autoResize:false,
-      rowFormatter:function(row, data){
-        //console.log(row);
-
-        
-      },
+      rowFormatter:function(row, data){},
       rowContext:function(e, row){ e.preventDefault(); },
         columns: [
           {title: "Image", field: "filename",formatter:pictureFormatter,width:200},
@@ -79,6 +79,7 @@ let gallery = {
           {title: "fin publication",field: "unpublishdate",width: 100,formatter:"datetime",headerSort:true,formatterParams:{inputFormat:"YYYY-MM-DD",outputFormat:"DD.MM.YYYY",invalidPlaceholder:""}},
       ]
     });
+    gallery.getGalleries();
   },
   gettabledata: function(){
     postData({"cl":"gallery","fn":"getItems","id":gallery.id_gallery}).then(data => {
@@ -87,7 +88,21 @@ let gallery = {
     })
   },
   add: function(){
-    myapp.viewdialog("addgalleryitem");
+    postData({"getconfig":"post_max_size"}).then(data => {
+      console.log(data.data)
+      gallery.maxuploadsize = data.data.post_max_size;
+      gallery.showUploadSize();
+      myapp.viewdialog("addgalleryitem");
+    });
+    
+  },
+  showUploadSize: function(){
+    let uplfiles = document.getElementById("addgalleryitem_file");
+    let uplsize= filedata.getfileinfo("addgalleryitem_file");
+    let maxsize = filedata.sizeHumanReadble(gallery.maxuploadsize);
+    
+    document.getElementById("addgalleryitem_maxfilesize").value=maxsize;
+    document.getElementById("addgalleryitem_filesize").value=uplsize.sizehr;
   },
   uploadItem: async function(){
     let data = {};
@@ -98,9 +113,6 @@ let gallery = {
     }
     myapp.closedlg("addgalleryitem");
     var uplfiles = document.getElementById("addgalleryitem_file");
-    //console.log("files:",uplfiles.files);
-    //let progresssteps = uplfiles.files.length;
-    //let cstep = 1;
     myapp.openDataLoad("Téléchargement en cours","Attendez s.v.p.!",null);
     postFile(uplfiles,data).then(filesdata => {
       console.log(filesdata);
@@ -110,37 +122,6 @@ let gallery = {
       });
     });
   },
-  // uploadRequest: async function(uplfile,upldata){
-  //   await postFile(uplfile,upldata).then(filedata => {
-  //     console.log("file uploaded ", filedata.file);
-  //     postData({"cl":"gallery","fn":"addItem","idgallery":gallery.id_gallery,"filename":filedata.file}).then( data => {
-  //       console.log("finally data", data);
-  //       //     if (last == true){
-  //       //       gallery.gettabledata();
-  //       //       myapp.closeDataLoad();
-  //       //     }
-  //       //     return data.data;
-  //       //   })
-  //     });
-  //   });
-  // },
-  // addItem: function(filename,last){
-  //   console.log("Add Item " + filename);
-  //   postData({"cl":"gallery","fn":"addItem","idgallery":gallery.id_gallery,"filename":filename}).then( data => {
-  //     if (last == true){
-  //       gallery.gettabledata();
-  //       myapp.closeDataLoad();
-  //     }
-  //     return data.data;
-  //   }).catch(err => {
-  //     if (last == true){
-  //       gallery.gettabledata();
-  //       myapp.closeDataLoad();
-  //     }
-  //     console.log("postData RETURN ERROR",err);
-  //   });
-    
-  // },
   confirmRemove: function(){
     var sel = gallery.tbl.getSelectedData();
     
@@ -164,6 +145,27 @@ let gallery = {
     }
     
   },
+  move: function(){
+    let sel = gallery.tbl.getSelectedData();
+    if(sel[0]){
+
+    }
+  },
+  moveItem: function(){
+    let sel = gallery.tbl.getSelectedData();
+    let newgallery = gallery.selects["movegalleryitem_id_gallery"].selected();
+    for (s in sel){
+      ids.push(sel[s].id);
+    }
+    console.log("IDs to move",ids);
+    if (ids.length > 0){
+      postData({"cl":"gallery","fn":"moveItems","idgallery":newgallery,"ids":ids}).then(data => {
+        console.log(data.data + " files moved!");
+        gallery.tbl.deselectRow(ids);
+        gallery.gettabledata();
+      });
+    }
+  },
   edit: function(){
     let sel =  this.tbl.getSelectedData();
     //console.log(sel);
@@ -202,6 +204,11 @@ let gallery = {
   },
   changeDefaultImage: function(file){
     document.getElementById("gpreview").src = 'media/galleries/' + file+ "?" + moment().format('YYYYMMDDhhmmss') ;
+  },
+  getGalleries: function(){
+    postData({"cl":"gallery","fn":"getAll"}).then(data => {
+      dataform.fillselectlist(gallery.selects["movegalleryitem_id_gallery"],data.data,'id','gallery');
+    });
   }
 
 }
index f45be8c..ce76134 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+
+
   $cfg = array(
     "basepath" => "/oldbelladmin/",
     "cookie" => "oldbell_lu",
     "sitename" => "oldbell.lu",
     "sitetemplatepath" => $_SERVER["DOCUMENT_ROOT"].'/oldbell_lu'
   );
-
-  // function getparams(){
-  //   $get_arr = array();
-  //   if ($_SERVER['QUERY_STRING'] != ""){
-  //   $xar = explode("&", $_SERVER['QUERY_STRING']);
-  //   #print_r($xar);
-  //   if (count($xar) > 0){
-  //     foreach ($xar as $tmp_arr_param) {
-  //       $split_param = explode("=", $tmp_arr_param);
-  //       if ($split_param[1]){
-  //         $get_arr[$split_param[0]] = urldecode($split_param[1]);
-  //       }
-  //     }
-  //   }
-  //   }
-  //   return $get_arr; 
-  // }
 ?>
\ No newline at end of file
diff --git a/admin/lib/helper.php b/admin/lib/helper.php
new file mode 100644 (file)
index 0000000..69b2b0c
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+class helper {
+  private  $picdef= array();
+  public function __construct(){
+    
+  }
+  public function __destruct(){
+    
+  }
+  function getbytes ($size_str){
+    switch (substr ($size_str, -1))
+    {
+        case 'M': case 'm': return (int)$size_str * 1048576;
+        case 'K': case 'k': return (int)$size_str * 1024;
+        case 'G': case 'g': return (int)$size_str * 1073741824;
+        default: return $size_str;
+    }
+  }
+  function getiniconfig($name){
+    if ($name == "post_max_size" || $name == "upload_max_filesize"){
+       return array($name => $this->getbytes(ini_get($name)),"hr".$name => ini_get($name));  
+    }
+    return array($name => ini_get($name));
+  }
+}
+
+
+?>
\ No newline at end of file
index 58cf9d2..9761bd0 100644 (file)
@@ -8,7 +8,7 @@ class gallery {
   }
 
   public function getAll(){
-    $sql = "select * from galleries order by gallery;";
+    $sql = "select g.*,count(gi.id) as items from galleries g left join galleryitems gi on (g.id=gi.id_gallery) group by g.id order by g.gallery;";
     return $this->dbh->queryarray($sql);
   }
 
@@ -91,6 +91,25 @@ class gallery {
     return count($fdata);
   }
 
+  public function moveItems($idgallery,$ids){
+    foreach ($ids as $key => $value){
+      $ids[$key] = $this->dbh->value($value); 
+    }
+    $sqlgal = "SELECT link from galleries where id=".$this->dbh->value($idgallery).";";
+    $gal = $this->dbh->query($sqlgal);
+    $sqlfile = "SELECT gi.id,gi.filename,g.link,gi.filetype,gi.thumbname from public.galleries g join public.galleryitems gi on (g.id=gi.id_gallery) where gi.id in (".implode(',',$ids).");";
+    $fdata = $this->dbh->queryarray($sqlfile);
+    foreach ($fdata as $key => $fd){
+      $sqlupd ="UPDATE galleryitems set id_gallery=".$this->dbh->value($idgallery).",filename=replace(".$this->dbh->value($fd["link"]).",".$this->dbh->value($gal["link"])."),thumbname=replace(".$this->dbh->value($fd["link"]).",".$this->dbh->value($gal["link"]).") WHERE id=".$this->dbh->value($fd["id"]).";";
+      $this->dbh->exec($sqlupd);
+      rename($this->cfg["adminmediapath"]."galleries/".$fd["link"]."/".$fd["filename"],$this->cfg["adminmediapath"]."galleries/".$gal["link"]."/".str_replace($fd["link"],$gal["link"],$fd["filename"]));
+      rename($this->cfg["adminmediapath"]."galleries/".$fd["link"]."/thumb/".$fd["thumbname"],$this->cfg["adminmediapath"]."galleries/".$gal["link"]."/thumb/".str_replace($fd["link"],$gal["link"],$fd["thumbname"]));
+      rename($this->cfg["webmediapath"]."galleries/".$fd["link"]."/".$fd["filename"],$this->cfg["webmediapath"]."galleries/".$gal["link"]."/".str_replace($fd["link"],$gal["link"],$fd["filename"]));
+      rename($this->cfg["webmediapath"]."galleries/".$fd["link"]."/thumb/".$fd["thumbname"],$this->cfg["webmediapath"]."galleries/".$gal["link"]."/thumb/".str_replace($fd["link"],$gal["link"],$fd["thumbname"]));
+    }
+    return count($fdata);
+  }
+
   public function updateItemData($id,$data){
     $updsql = $this->dbh->createUpdateDDL("public","galleryitems",array("id" => $this->dbh->value($id)),$data);
     $this->dbh->exec($updsql);
diff --git a/admin/lib/phpini.php b/admin/lib/phpini.php
new file mode 100644 (file)
index 0000000..f600a36
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+  // ini_set('post_max_size', '32000');
+  // ini_set('upload_max_filesize', '32000');
+?>
\ No newline at end of file
diff --git a/admin/tmpl/elements/dialogs/dlg_gallerymoveitem.html.mustache b/admin/tmpl/elements/dialogs/dlg_gallerymoveitem.html.mustache
new file mode 100644 (file)
index 0000000..a9d8d16
--- /dev/null
@@ -0,0 +1,25 @@
+<div id="dlg_movegalleryitem" class="modal">
+  <div class="modal-content animate-top card-4">
+    <header> 
+      <span onclick="document.getElementById('dlg_movegalleryitem').style.display='none'; return false;" 
+       class="button toolbarbtn display-topright" ><span class="icon icon-remove" style="font-size: 18px;"></span></span>
+      <h3 id="dlgmovegalleryitem_title">Déplacer Image/Video</h3>
+    </header>
+    <div class="container">
+      <div id="dlg_movegalleryitem_infomsg"></div>
+        <form id="frm_movegalleryitem">
+        <div class="row">
+                <div class="cell" style="width: 400px;">
+                  <label class="label" for="movegalleryitem_id_gallery">Déplacer vers</label>
+                  <select class="select border data_movegalleryitem" data-column="id_gallery" data-id="" data-selected="" data-table="galleryitems" id="movegalleryitem_id_gallery"></select>
+                </div>
+        </div>
+        
+       </form>  
+    </div>
+    <footer>
+    <button class="button theme-light margin-right border" onclick="document.getElementById('dlg_movegalleryitem').style.display='none'; return false;"><span class="icon icon-remove"></span>&nbsp;Annuler</button>
+    <button class="button actionbtn margin-right border" onclick="gallery.moveItem();"><span class="icon icon-save"></span>&nbsp;Déplacer</button>  
+    </footer>
+  </div>
+</div>
index 422c299..a658c9a 100644 (file)
         <div class="row">
                 <div class="cell container" style="width: 400px;">
                 <label for="addgalleryitem_file" class="label">Fichier</label>
-                  <input type="file" class="input  data_addgalleryitem " id="addgalleryitem_file" data-column="filename"  data-table="galleryitems" multiple data-id="" value="" />
+                  <input type="file" class="input  data_addgalleryitem " id="addgalleryitem_file" data-column="filename"  data-table="galleryitems" multiple data-id="" value="" onchange="gallery.showUploadSize();"/>
                 </div>
         </div>
+        <div class="row">
+          
+            <div class="cell container" style="width: 300px;">
+              <label class="label" for="addgalleryitem_filesize">taille</label>
+              <input class="input border text data_formname readonly" data-column="column" data-id="" data-table="table" id="addgalleryitem_filesize"   readonly>
+            </div>
+            <div class="cell container" style="width: 300px;">
+              <label class="label" for="addgalleryitem_maxfilesize">max taille</label>
+              <input class="input border text data_formname readonly" data-column="column" data-id="" data-table="table" id="addgalleryitem_maxfilesize"   readonly>
+            </div>
+          
+        </div>
         <div class="row">
           <div class="cell" style="width: 100%">
             <div class="container">
index 7284dd7..bd3030d 100644 (file)
@@ -2,6 +2,7 @@
 {{> panels/pnl_gallery.html.mustache }}
 {{> dialogs/dlgaddgalleryitem.html.mustache }}
 {{> dialogs/dlg_galleryitem.html.mustache }}
+{{> dialogs/dlg_gallerymoveitem.html.mustache }}
 {{> dialogs/confirm.html.mustache }}
 {{> dialogs/dataload.html.mustache }}
 <script type="text/javascript" src="js/modules/galleries.js?v={{config.appversion}}"></script>
index 45c693d..c329630 100644 (file)
@@ -1,8 +1,8 @@
 <?php
+   require("lib/phpini.php");
    require("lib/config.php");
    require("lib/database.php");
    require("lib/session.php");
-   ini_set('upload_max_filesize', your_value_here);
    $db = new database($cfg["db"]);
    $sess = new session($db);
    $vars = array();