]> git.nbdom.net Git - nb.git/commitdiff
www/dbq/dbq.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 3 Jan 2018 00:34:03 +0000 (00:34 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 3 Jan 2018 00:34:03 +0000 (00:34 +0000)
www/dbq/dbq.php
www/dbq/etc/nginx.conf
www/dbq/html/default.min.css
www/dbq/html/default.min.js

index 423a52f9047b018bc4801384b5f175b5f72c38bb..0d34a159d0c136e2eece18343a83f972ad731100 100644 (file)
@@ -189,9 +189,17 @@ class DbQ extends nb {
                $this->page($rows);
        }
 
-       public function page_table_ls($args) {
+       public function page_table_ls($args=null) {
                $this->deniedUnless($this->perm >= self::READ);
-               if (!empty($args) and !strpos($args,'=')) $this->table->fields_only = explode(',',$args);
+
+               $fields_only = (string)$args === '' ? [] : explode(',',$args);
+               if (!empty($fields_only)) {
+                       foreach ($fields_only as $f) {
+                               if (!$this->table->field($f)) $this->error("Unknown field ".$f);
+                       }
+                       $this->table->fields_only = $fields_only;
+               }
+
                $this->page($this,'table_rows');
        }
 
@@ -332,19 +340,27 @@ class DbQ extends nb {
 
                // New
                global $DB_CONFS;
+               if(empty($DB_CONFS)) $DB_CONFS = [];
+
+               if (!empty($_SERVER['DBQ_CONF_FILE'])) {
+                       $DB_CONFS = array_merge($DB_CONFS,explode(' ',$_SERVER['DBQ_CONF_FILE']));
+               }
+
                if (!empty($_SERVER['DBQ_CONF_DIR'])) {
-                       $DB_CONFS = Db::conf_load(array_merge(
+                       $DB_CONFS = array_merge($DB_CONFS,
                                (array)glob($_SERVER['DBQ_CONF_DIR'].'/*.yml'),
                                (array)glob($_SERVER['DBQ_CONF_DIR'].'/*.yaml'),
                                (array)glob($_SERVER['DBQ_CONF_DIR'].'/*.php'),
-                       []));
-
-               } elseif (!empty($_SERVER['DBQ_CONF_FILE'])) {
-                       $DB_CONFS = Db::conf_load(explode(' ',$_SERVER['DBQ_CONF_FILE']));
+                       []);
+               }
 
-               } else {
+               if (empty($DB_CONFS)) {
                        require_once(NB_ROOT.'/lib/php/db/config.php');
+               } else {
+                       #debug($DB_CONFS);
+                       $DB_CONFS = Db::conf_load($DB_CONFS);
                }
+
                $this->db = new Db(['conf'=>$DB_CONFS]);
                $this->db->base = '';
 
@@ -1152,6 +1168,9 @@ EOF;
                } elseif ($action == 'ls') {
                        $this->page_table_ls($this->params['args']);
 
+               } elseif ($action == 'sql') {
+                       $this->page(['sql'=>$this->table->sql()]);
+
                } elseif ($action == 'fields') {
                        $this->page($this->table,'fields_rows');
 
@@ -1191,8 +1210,10 @@ EOF;
                        $this->page($info);
 
 
+               } elseif (preg_match('/^fields=(.*)\s*$/',$action,$m)) {
+                       $this->page_table_ls($m[1]);
+
                } else {
-                       if (!strpos($action,'=')) $this->page_table_ls($action);
                        $this->notImplemented('Unknown table action'." `$action`");
 
                }
index 4cf2402ecec9fffd003ae3183fa8cfa34f97040b..768253af7666791e002f52a0d6f1e758a9a8b961 100644 (file)
@@ -40,8 +40,13 @@ location ~ /index\.php$ {
        fastcgi_buffers 4 16k;
 
        fastcgi_param DBQ_TITLE $DBQ_TITLE;
-       if ($DBQ_CONF_FILE = "") { set $DBQ_CONF_FILE $document_root/../../../etc/dbq/000-local.php; }
+
+       if ($DBQ_CONF_FILE = "") { set $DBQ_CONF_FILE ""; }
        fastcgi_param DBQ_CONF_FILE $DBQ_CONF_FILE;
+
+       if ($DBQ_CONF_DIR = "") { set $DBQ_CONF_DIR ""; }
+       fastcgi_param DBQ_CONF_DIR $DBQ_CONF_DIR;
+
        fastcgi_param DBQ_PERM $DBQ_PERM;
 
        if ($DBQ_PROD = "") { set $DBQ_PROD ""; }
index 9521d0215636bf11519185090634c58c64ada3ea..05e11cf8dde89a61f0d972b3c56e25c0c02e8140 100644 (file)
@@ -1 +1 @@
-html{font:90% 'Trebuchet MS',sans-serif;background-color:#eee}body{display:table;margin-left:auto;margin-right:auto;padding-left:1em;padding-right:1em;color:#444}h1{margin:0 0 .2em 0;font-size:180%;padding-bottom:.3em;margin-bottom:.5em;border-bottom:dashed 1px #444}a{color:inherit}div>a,li a,p a,td a{color:#3572b0}a,a:visited{text-decoration:none}.button:hover,a:hover{opacity:.8}ul{padding:0;margin:0}li{list-style:none;padding:0 0 0 .3em}table{border-collapse:collapse}td,th{padding:.2em .7em}th a.sort{padding:0 .3em}input:not([type]),input[type=''],input[type=date],input[type=email],input[type=password],input[type=text],input[type=url],select,textarea{border-radius:3px;border:solid 1px #ddd;padding:.3em .4em;box-shadow:0 1px 1px #eee}input[size]{max-width:70%}div.row div label:after,form label:after{content:':'}form input,form label,form select{vertical-align:middle;margin:.2em .4em .2em 0}.block,.menu,div.row,form.edit,iframe,pre,table.rows,ul.row{border-radius:4px;border-spacing:0;padding:.5em .2em;margin-bottom:.5em;border:solid 1px #ddd;background-color:#fafafa;box-shadow:0 1px 2px #eee}.rows{padding:0}table.rows{border-style:hidden;border-collapse:collapse;box-shadow:0 0 0 1px #ddd;table-layout:fixed}table.rows.fixed{width:100%}table.rows tr:nth-child(even) td{background-color:#fefefe}div.row div,table.rows td,table.rows th,ul.row li{border-bottom:solid 1px #ddd}div.row div,table.rows tr:last-child td,ul.row li{border-bottom:none}table.rows td,table.rows th{border-right:dashed 1px #ddd}table.rows th{text-align:left}table.rows td{padding:.3em .3em}table.rows.fixed td{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}table.rows td.delete,table.rows td.view{width:1%;white-space:nowrap}table.rows.fixed th.view{width:2em}table.rows.fixed th.delete{width:2.7em}div.row div{margin:0}div.row div label,ul.row li label{padding:.1em .5em .1em 0;min-width:20%;display:inline-block}.button{font:inherit;display:inline-block;text-decoration:none;line-height:1.6em;cursor:pointer;white-space:nowrap;box-sizing:border-box;margin:0 .1em 0 0;padding:0 .3em;border-radius:4px;border:none;color:#3572b0;background-color:#eee;background:linear-gradient(to bottom right,#eee,#ddd);box-shadow:0 1px 1px #bbb}.center,.menu,.nav,.rows,td.button{display:table}.buttons,.center,.menu,.nav,.rows,td.button{margin-left:auto;margin-right:auto}div.buttons{text-align:center;margin-top:.5em}form.menu{padding:.5em;background-color:#fafafa}form.menu .button.add{float:right;margin-top:.2em}form.menu .criterias{border-top:dashed 1px #ddd;margin-top:.3em;padding-top:.3em}form.menu .criterias span.label{border-right:solid 1px #fff;padding:.2em .1em;margin:.2em .2em 0 0;border-radius:3px}form.menu .criterias span.label:last-child{border-right:none}form.menu select:focus{max-width:auto}form.menu select{max-width:20%}form.menu .criterias input[type=text]:focus{width:auto}form.menu .criterias input[type=text]{width:4em}form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}form.edit .fields .label span{width:54%;display:inline-block;text-align:left;vertical-align:middle;margin-top:.2em}form.Wedit .fields .label span input{vertical-align:bottom!important}form.edit .fields input[size],form.edit .fields select,form.edit .fields textarea{width:65%}
+html{font:90% 'Trebuchet MS',sans-serif;background-color:#eee}body{display:table;margin-left:auto;margin-right:auto;padding-left:1em;padding-right:1em;color:#444}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}.loader{border:16px solid #fff;border-radius:50%;border-top:16px solid #000;padding:0;margin:0 auto 0 auto;width:8em;height:8em;animation:spin 2s linear infinite;display:block}body.loader{margin-top:8em}.loader *{display:none!important}h1{margin:0 0 .2em 0;font-size:180%;padding-bottom:.3em;margin-bottom:.5em;border-bottom:dashed 1px #444}a{color:inherit}div>a,li a,p a,td a{color:#3572b0}a,a:visited{text-decoration:none}.button:hover,a:hover{opacity:.8}ul{padding:0;margin:0}li{list-style:none;padding:0 0 0 .3em}table{border-collapse:collapse}td,th{padding:.2em .7em}th a.sort{padding:0 .3em}input:not([type]),input[type=''],input[type=date],input[type=email],input[type=password],input[type=text],input[type=url],select,textarea{border-radius:3px;border:solid 1px #ddd;padding:.3em .4em;box-shadow:0 1px 1px #eee}input[size]{max-width:70%}div.row div label:after,form label:after{content:':'}form input,form label,form select{vertical-align:middle;margin:.2em .4em .2em 0}.block,.menu,div.row,form.edit,iframe,pre,table.rows,ul.row{border-radius:4px;border-spacing:0;padding:.5em .2em;margin-bottom:.5em;border:solid 1px #ddd;background-color:#fafafa;box-shadow:0 1px 2px #eee}.rows{padding:0}table.rows{border-style:hidden;border-collapse:collapse;box-shadow:0 0 0 1px #ddd;table-layout:fixed}table.rows.fixed{width:100%}table.rows tr:nth-child(even) td{background-color:#fefefe}div.row div,table.rows td,table.rows th,ul.row li{border-bottom:solid 1px #ddd}div.row div,table.rows tr:last-child td,ul.row li{border-bottom:none}table.rows td,table.rows th{border-right:dashed 1px #ddd}table.rows th{text-align:left}table.rows td{padding:.3em .3em}table.rows.fixed td{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}table.rows td.delete,table.rows td.view{width:1%;white-space:nowrap}table.rows.fixed th.view{width:2em}table.rows.fixed th.delete{width:2.7em}div.row div{margin:0}div.row div label,ul.row li label{padding:.1em .5em .1em 0;min-width:20%;display:inline-block}.button{font:inherit;display:inline-block;text-decoration:none;line-height:1.6em;cursor:pointer;white-space:nowrap;box-sizing:border-box;margin:0 .1em 0 0;padding:0 .3em;border-radius:4px;border:none;color:#3572b0;background-color:#eee;background:linear-gradient(to bottom right,#eee,#ddd);box-shadow:0 1px 1px #bbb}.center,.menu,.nav,.rows,td.button{display:table}.buttons,.center,.menu,.nav,.rows,td.button{margin-left:auto;margin-right:auto}div.buttons{text-align:center;margin-top:.5em}form.menu{padding:.5em;background-color:#fafafa}form.menu .button.add{float:right;margin-top:.2em}form.menu .criterias{border-top:dashed 1px #ddd;margin-top:.3em;padding-top:.3em}form.menu .criterias span.label{border-right:solid 1px #fff;padding:.2em .1em;margin:.2em .2em 0 0;border-radius:3px}form.menu .criterias span.label:last-child{border-right:none}form.menu select:focus{max-width:auto}form.menu select{max-width:20%}form.menu .criterias input[type=text]:focus{width:auto}form.menu .criterias input[type=text]{width:4em}form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}form.edit .fields .label span{width:54%;display:inline-block;text-align:left;vertical-align:middle;margin-top:.2em}form.Wedit .fields .label span input{vertical-align:bottom!important}form.edit .fields input[size],form.edit .fields select,form.edit .fields textarea{width:65%}
index e6afad117e2437fbaabff37244a90c28e1e2ea79..7e4029a30279294912c470d8f751ea861f558e5e 100644 (file)
@@ -1 +1 @@
-function form_clean(e){var t;for(i=0;i<e.length;i++)"none"!=(t=e.elements[i]).style.display&&("text"==t.type?t.value="":!t.type.match(/^select/)||"limit"!=t.name&&"format"!=t.name||(t.selectedIndex=0))}function form_submit_clean(e){var t=0,n="",o=e.getAttribute("action");if("get"!=e.getAttribute("method"))return!0;for(t=0;t<e.length;t++){var r=e[t];r.name&&(""!=r.value&&"undefined"!=r.value&&(n+=(n?"&":"?")+encodeURI(r.name)+"="+encodeURI(r.value)))}return n=("?"==o?"":o)+n,e.reset(),window.location=n,!1}document.addEventListener("DOMContentLoaded",function(){if(NodeList.prototype.forEach=Array.prototype.forEach,document.querySelectorAll("form").forEach(function(e){e.onsubmit=function(){if(this.elements.limit){var e=this.elements.limit;"undefined"!=window._dbq.default_limit&&e.value==window._dbq.default_limit&&e.removeAttribute("value")}return form_submit_clean(this)}}),document.querySelectorAll("form.menu").forEach(function(e){e.setAttribute("action",window.location.toString().replace(/\?.*$/,"")),e.querySelectorAll("form.menu select.format").forEach(function(e){e.removeAttribute("name"),e.onchange=function(){return this.form.setAttribute("action",window._dbq["table.base"]+"."+this.value),this.form.onsubmit()}}),e.querySelectorAll("form.menu select.tables").forEach(function(e){e.removeAttribute("name"),e.onchange=function(){return this.form.setAttribute("action",window._dbq["db.base"]+"/"+this.value+".html"),this.form.onsubmit()}}),e.querySelectorAll("form.menu select.limit").forEach(function(e){e.onchange=function(){return this.form.onsubmit()}})}),document.querySelector(".nav.bottom")&&document.querySelector("table.rows")&&document.querySelector("table.rows").insertAdjacentHTML("beforebegin",'<div class="nav top">'+document.querySelector(".nav.bottom").innerHTML+"</div>"),document.querySelectorAll("table").forEach(function(e){parseInt(e.offsetWidth)>parseInt(window.innerWidth)&&(e.className=e.className.replace(/(^| +)fixed($| )/,"")+" fixed",e.className=e.className.trim())}),window._dbq.perm<window._dbq.perms.write&&(document.querySelectorAll("form.edit").forEach(function(e){e.setAttribute("onsubmit","return false")}),document.querySelectorAll("form.edit input[type=submit],form.edit input[type=reset]").forEach(function(e){e.setAttribute("style","display:none")})),document.querySelectorAll("form.menu input[type=submit]").forEach(function(e){e.insertAdjacentHTML("afterend",'&nbsp;<input type="button" class="clear '+e.className+'" onclick="form_clean(this.form)" value="'+window._dbq["text.clear"]+'" />'+(window._dbq.perm>=window._dbq.perms.write?'&nbsp;<input type="button" class="add '+e.className+'" onclick="window.location=\''+window._dbq["table.base"]+'/add/\'" value="'+window._dbq["text.add"]+'"/>':""))}),document.querySelector("th.delete")){var e=document.createElement("a");e.setAttribute("href","#"),e.innerHTML=document.querySelector("th.delete").innerHTML+"&nbsp;All",document.querySelector("th.delete").innerHTML="",e.onclick=function(){var e=document.querySelectorAll("form.rm");for(j=0;j<e.length;++j){var t=e[j],n=t.getAttribute("action"),o=[],r=t.getElementsByTagName("input");for(i=0;i<r.length;++i){var l=r[i];o.push(l.name+"="+encodeURI(l.value))}var a=new XMLHttpRequest;a.open("POST",n,!1),a.setRequestHeader("Content-type","application/x-www-form-urlencoded"),a.onload=function(e){a.readyState},a.send(o.join("&"))}return location.reload(),!1},document.querySelector("th.delete").appendChild(e)}});
+function form_clean(e){var t;for(i=0;i<e.length;i++)"none"!=(t=e.elements[i]).style.display&&("text"==t.type?t.value="":!t.type.match(/^select/)||"limit"!=t.name&&"format"!=t.name||(t.selectedIndex=0))}function form_submit_clean(e){var t=0,n="",o=e.getAttribute("action");if("get"!=e.getAttribute("method"))return!0;for(t=0;t<e.length;t++){var r=e[t];r.name&&(""!=r.value&&"undefined"!=r.value&&(n+=(n?"&":"?")+encodeURI(r.name)+"="+encodeURI(r.value)))}return n=("?"==o?"":o)+n,e.reset(),window.location=n,!1}document.addEventListener("DOMContentLoaded",function(){if(NodeList.prototype.forEach=Array.prototype.forEach,document.querySelectorAll("form").forEach(function(e){e.onsubmit=function(){if(this.elements.limit){var e=this.elements.limit;"undefined"!=window._dbq.default_limit&&e.value==window._dbq.default_limit&&e.removeAttribute("value")}return form_submit_clean(this)}}),document.querySelectorAll("form.menu").forEach(function(e){e.setAttribute("action",window.location.toString().replace(/\?.*$/,"")),e.querySelectorAll("form.menu select.format").forEach(function(e){e.removeAttribute("name"),e.onchange=function(){return this.form.setAttribute("action",window._dbq["table.base"]+"."+this.value),this.form.onsubmit()}}),e.querySelectorAll("form.menu select.tables").forEach(function(e){e.removeAttribute("name"),e.onchange=function(){return this.form.setAttribute("action",window._dbq["db.base"]+"/"+this.value+".html"),this.form.onsubmit()}}),e.querySelectorAll("form.menu select.limit").forEach(function(e){e.onchange=function(){return this.form.onsubmit()}})}),document.querySelector(".nav.bottom")&&document.querySelector("table.rows")&&document.querySelector("table.rows").insertAdjacentHTML("beforebegin",'<div class="nav top">'+document.querySelector(".nav.bottom").innerHTML+"</div>"),document.querySelectorAll("table").forEach(function(e){parseInt(e.offsetWidth)>parseInt(window.innerWidth)&&(e.className=e.className.replace(/(^| +)fixed($| )/,"")+" fixed",e.className=e.className.trim())}),window._dbq.perm<window._dbq.perms.write&&(document.querySelectorAll("form.edit").forEach(function(e){e.setAttribute("onsubmit","return false")}),document.querySelectorAll("form.edit input[type=submit],form.edit input[type=reset]").forEach(function(e){e.setAttribute("style","display:none")})),document.querySelectorAll("form.menu input[type=submit]").forEach(function(e){e.insertAdjacentHTML("afterend",'&nbsp;<input type="button" class="clear '+e.className+'" onclick="form_clean(this.form)" value="'+window._dbq["text.clear"]+'" />'+(window._dbq.perm>=window._dbq.perms.write?'&nbsp;<input type="button" class="add '+e.className+'" onclick="window.location=\''+window._dbq["table.base"]+'/add/\'" value="'+window._dbq["text.add"]+'"/>':""))}),document.querySelector("th.delete")){var e=document.createElement("a");e.setAttribute("href","#"),e.innerHTML=document.querySelector("th.delete").innerHTML,document.querySelector("th.delete").innerHTML="",e.onclick=function(){var e=document.querySelectorAll("form.rm");for(document.querySelector(".rows").className="loader",j=0;j<e.length;++j){var t=e[j],n=t.getAttribute("action"),o=[],r=t.getElementsByTagName("input");for(i=0;i<r.length;++i){var l=r[i];o.push(l.name+"="+encodeURI(l.value))}var a=new XMLHttpRequest;a.open("POST",n,!0),a.setRequestHeader("Content-type","application/x-www-form-urlencoded"),a.onload=function(t){if(4===a.readyState){if(j!=e.length)return;location.reload()}},a.send(o.join("&"))}return!1},document.querySelector("th.delete").appendChild(e)}});