Skip to content

Commit 0b4a6bb

Browse files
authored
3.16.3
-fix in_array -fix link for empty views
1 parent 681cce2 commit 0b4a6bb

1 file changed

Lines changed: 34 additions & 22 deletions

File tree

lite.php

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
session_start();
77
$bg=2;
88
$step=20;
9-
$version="3.16.2";
9+
$version="3.16.3";
1010
$bbs=['False','True'];
1111
$deny=['sqlite_sequence'];
1212
$js=(file_exists('jquery.js')?"/jquery.js":"https://code.jquery.com/jquery-1.12.4.min.js");
@@ -166,7 +166,7 @@ public function check($level=[],$param=[]) {
166166
} else {
167167
$this->redir("50");
168168
}
169-
if(in_array(1,$level)) {//exist db
169+
if(in_array('1',$level)) {//exist db
170170
$op=$this->sg[0];
171171
$db=$this->sg[1];
172172
$dbx=$this->dir.$db.$this->ext;
@@ -176,13 +176,13 @@ public function check($level=[],$param=[]) {
176176
$this->con->exec("PRAGMA default_synchronous=OFF");
177177
}
178178
}
179-
if(in_array(2,$level)) {//check table
179+
if(in_array('2',$level)) {//check table
180180
$tb=$this->sg[2];
181181
$obj=(($op==20) ? "(type='table' OR type='view')":"type='table'");
182182
$ist=$this->con->query("SELECT 1 FROM sqlite_master WHERE name='$tb' AND ".$obj,true)->fetch();
183183
if(!$ist) $this->redir("5/$db",['err'=>"Table not exist"]);
184184
}
185-
if(in_array(3,$level)) {//check field
185+
if(in_array('3',$level)) {//check field
186186
$q_fld=$this->con->query("PRAGMA table_info($tb)")->fetch(2);
187187
$meta=[];
188188
foreach($q_fld as $row) $meta[]=$row['name'];
@@ -192,10 +192,10 @@ public function check($level=[],$param=[]) {
192192
if(!in_array($this->sg[5],$meta)) $this->redir($param['redir']."/$db/$tb",$err);
193193
}
194194
}
195-
if(in_array(4,$level)) {//check pagination
195+
if(in_array('4',$level)) {//check pagination
196196
if(!is_numeric($param['pg']) || $param['pg'] > $param['total'] || $param['pg'] <1) $this->redir($param['redir'],['err'=>"Invalid page number"]);
197197
}
198-
if(in_array(5,$level)) {//check view,trigger
198+
if(in_array('5',$level)) {//check view,trigger
199199
$sp=['view','trigger'];
200200
$sg3=$this->sg[3];
201201
if($op!=49 && ($op==40 && $sg3!=$sp[0]) || ($op==41 && $sg3!=$sp[1])) $this->redir("5/$db");
@@ -209,7 +209,12 @@ public function menu($db='',$tb='',$left='',$sp=[]) {
209209
if($db!='' && $db!=1) $str.="<li><a href='{$this->path}31/$db'>Export</a></li><li><a href='{$this->path}5/$db'>Tables</a></li>";
210210
$dv="<li class='divider'>---</li>";
211211
if($tb!="") $str.=$dv."<li><a href='{$this->path}10/$db/$tb'>Structure</a></li><li><a href='{$this->path}20/$db/$tb'>Browse</a></li><li><a href='{$this->path}21/$db/$tb'>Insert</a></li><li><a href='{$this->path}24/$db/$tb'>Search</a></li><li><a class='del' href='{$this->path}25/$db/$tb'>Empty</a></li><li><a class='del' href='{$this->path}26/$db/$tb'>Drop</a></li>";//table
212-
if(!empty($sp[1]) && $sp[0]=='view') $str.=$dv."<li><a href='{$this->path}40/$db/".$sp[1]."/view'>Structure</a></li><li><a href='{$this->path}20/$db/".$sp[1]."'>Browse</a></li><li><a class='del' href='{$this->path}49/$db/".$sp[1]."/view'>Drop</a></li>";//view
212+
if(!empty($sp[1]) && $sp[0]=='view'){
213+
$nr=@$this->con->query("SELECT COUNT(*) FROM ".$sp[1],true)->fetch();
214+
$str.=$dv."<li><a href='{$this->path}40/$db/".$sp[1]."/view'>Structure</a></li>".
215+
($nr!=false ? "<li><a href='{$this->path}20/$db/".$sp[1]."'>Browse</a></li>":"").
216+
"<li><a class='del' href='{$this->path}49/$db/".$sp[1]."/view'>Drop</a></li>";//view
217+
}
213218
if($db!='') $str.="</ul></div>";
214219

215220
if($db!="" && $db!=1) {
@@ -226,10 +231,18 @@ public function menu($db='',$tb='',$left='',$sp=[]) {
226231
if($qtype !='') $sl2.='</optgroup>';
227232
$sl2.='<optgroup label="'.$r_ts[1].'s">';
228233
}
229-
$in=($r_ts[1]=='view'?[20,40]:[10,20,21,24]);
234+
if($r_ts[1]=='view'){
235+
$in=[20,40];
236+
$nr=@$this->con->query("SELECT COUNT(*) FROM ".$r_ts[0],true)->fetch();
237+
}else{
238+
$in=[10,20,21,24];
239+
$nr=true;
240+
}
241+
if($nr!=false){
230242
$sl2.="<option value='".$this->path.($r_ts[1]=='trigger'?"41/$db/".$r_ts[0]."/".$r_ts[1]:(in_array($this->sg[0],$in)?$this->sg[0]:20)."/$db/".$r_ts[0])."'".($r_ts[0]==$tb || ($c_sp >1 && $r_ts[0]==$sp[1])?" selected":"").">".$r_ts[0]."</option>";
231243
$qtype=$r_ts[1];
232244
}
245+
}
233246
if($qtype !='') $sl2.='</optgroup>';
234247
$str.=$sl2."</select>".((!empty($_SESSION["_litesearch_{$db}_{$tb}"]) && $this->sg[0]==20) ? " [<a href='{$this->path}24/$db/$tb/reset'>reset search</a>]":"");
235248
}
@@ -419,7 +432,7 @@ public function getTables($db) {
419432
.ce{text-align:center}
420433
.link{float:right;padding:3px 0}
421434
.pg *{margin:0 2px;width:auto}
422-
caption{font-weight:bold;text-decoration:underline}
435+
caption{font-weight:bold;border:2px solid #9be}
423436
.l1 ul,.l2 ul{list-style:none}
424437
.left{float:left}
425438
.left button{margin:0 1px}
@@ -439,7 +452,7 @@ public function getTables($db) {
439452
.ok,.err{padding:8px;font-weight:bold;font-size:13px}
440453
.ok{background:#efe;color:#080;border-bottom:2px solid #080}
441454
.err{background:#fee;color:#f00;border-bottom:2px solid #f00}
442-
.l1,th,caption,button{background:#9be}
455+
.l1,th,button{background:#9be}
443456
.l2,.c1,.col1,h3{background:#cdf}
444457
.c2,.mn ul{background:#fff}
445458
.l3,tr:hover.r,button:hover{background:#fe3 !important}
@@ -460,14 +473,14 @@ public function getTables($db) {
460473
.msg,.a{cursor:pointer}
461474
</style>
462475
</head><body>'.(empty($_SESSION['ok'])?'':'<div class="msg ok">'.$_SESSION['ok'].'</div>').(empty($_SESSION['err'])?'':'<div class="msg err">'.$_SESSION['err'].'</div>').'<div class="l1"><b><a href="https://github.com/edmondsql/edliteadmin">EdLiteAdmin '.$version.'</a></b>'.(isset($ed->sg[0]) && $ed->sg[0]==50 ? "":'<ul class="mn m1"><li>More <small>&#9660;</small><ul><li><a href="'.$ed->path.'60">Info</a></li></ul></li><li><a href="'.$ed->path.'51">Logout</a></li></ul>').'</div>';
463-
$stru="<table><caption>TABLE STRUCTURE</caption><tr><th>FIELD</th><th>TYPE</th><th>VALUE</th><th>NULL</th><th>DEFAULT</th></tr>";
476+
$stru="<table><caption>Structure</caption><tr><th>Field</th><th>Type</th><th>Value</th><th>Null</th><th>Default</th></tr>";
464477

465478
if(!isset($ed->sg[0])) $ed->sg[0]=0;
466479
switch($ed->sg[0]) {
467480
default:
468481
case ""://show DBs
469482
$ed->check();
470-
echo $head.$ed->menu()."<div class='col1'>Create Database".$ed->form(2)."<input type='text' name='dbc' /><br/><button type='submit'>Create</button></form></div><div class='col2'><table><tr><th>DATABASE</th><th>Tables</th><th><a href='{$ed->path}31'>Exp</a> Actions</th></tr>";
483+
echo $head.$ed->menu()."<div class='col1'>Create Database".$ed->form(2)."<input type='text' name='dbc' /><br/><button type='submit'>Create</button></form></div><div class='col2'><table><tr><th>Database</th><th>Tables</th><th><a href='{$ed->path}31'>Exp</a>/ Actions</th></tr>";
471484
foreach($ed->listdb() as $db) {
472485
$bg=($bg==1)?2:1;
473486
$dbx=new DBT($ed->dir.$db.$ed->ext);
@@ -524,7 +537,7 @@ public function getTables($db) {
524537
}
525538
$offset=($pg - 1) * $step;
526539
echo $head.$ed->menu($db,'',1);
527-
echo "<table><tr><th>TABLE/VIEW</th><th>ROWS</th><th>ACTIONS</th></tr>";
540+
echo "<table><tr><th>Table/View</th><th>Rows</th><th>Actions</th></tr>";
528541
$q_tabs=$ed->con->query("SELECT name,type FROM sqlite_master WHERE type IN ('table','view') ORDER BY type,name LIMIT $offset,$step")->fetch(1);
529542
foreach($q_tabs as $r_tabs) {
530543
if(!in_array($r_tabs[0],$deny)) {
@@ -543,7 +556,7 @@ public function getTables($db) {
543556
echo "</table>";
544557
$q_tri=$ed->con->query("SELECT name,tbl_name FROM sqlite_master WHERE type='trigger' ORDER BY name")->fetch(1);
545558
$t=0;
546-
$trg_tab="<table><tr><th>TRIGGER</th><th>TABLE</th><th>ACTIONS</th></tr>";
559+
$trg_tab="<table><tr><th>Trigger</th><th>Table</th><th>Actions</th></tr>";
547560
foreach($q_tri as $r_tri) {
548561
$bg=($bg==1)?2:1;
549562
$trg_tab.="<tr class='r c$bg'><td>".$r_tri[0]."</td><td>".$r_tri[1]."</td><td><a href='{$ed->path}41/$db/".$r_tri[0]."/trigger'>Edit</a><a class='del' href='{$ed->path}49/$db/".$r_tri[0]."/trigger'>Drop</a></td></tr>";
@@ -686,19 +699,19 @@ public function getTables($db) {
686699
$ed->redir("10/$db/$tb",['err'=>"Wrong action"]);
687700
break;
688701

689-
case "10"://table structure
702+
case "10"://structure
690703
$ed->check([1,2]);
691704
$db=$ed->sg[1];
692705
$tb=$ed->sg[2];
693-
echo $head.$ed->menu($db,$tb,1).$ed->form("9/$db/$tb")."<table><caption>TABLE STRUCTURE</caption><thead><tr><th><input type='checkbox' onclick='toggle(this,\"idx[]\")' /></th><th>FIELD</th><th>TYPE</th><th>NULL</th><th>DEFAULT</th><th>PK</th><th>ACTIONS</th></tr></thead><tbody class='sort'>";
706+
echo $head.$ed->menu($db,$tb,1).$ed->form("9/$db/$tb")."<table><caption>Structure</caption><thead><tr><th><input type='checkbox' onclick='toggle(this,\"idx[]\")' /></th><th>Field</th><th>Type</th><th>Null</th><th>Default</th><th>PK</th><th>Actions</th></tr></thead><tbody class='sort'>";
694707
$q_rec=$ed->con->query("PRAGMA table_info($tb)")->fetch(1);
695708
foreach($q_rec as $rec) {
696709
$bg=($bg==1)?2:1;
697710
echo "<tr class='r c$bg' id='".$rec[1]."'><td><input type='checkbox' name='idx[]' value='".$rec[1]."' /></td><td>".$rec[1]."</td><td>".$rec[2]."</td><td>".($rec[3]==0 ? 'Yes':'No')."</td><td>".$rec[4]."</td><td>".($rec[5]>0 ? 'PK':'')."</td><td><a href='{$ed->path}12/$db/$tb/".$rec[1]."'>change</a><a class='del' href='{$ed->path}13/$db/$tb/".$rec[1]."'>drop</a><a href='{$ed->path}11/$db/$tb/'>add</a><span class='handle' title='move'>&#10070;</span></td></tr>";
698711
}
699712
echo "</tbody><tfoot><tr><td class='auto' colspan='7'><div class='left'><button type='submit' name='primary'>Primary</button><button type='submit' name='index'>Index</button><button type='submit' name='unique'>Unique</button></div><div class='link'><a href='{$ed->path}27/$db/$tb/analyze'>Analyze</a></div></td></tr></tfoot></table></form>";
700713
$q_idx=$ed->con->query("PRAGMA index_list($tb)")->fetch(1);
701-
echo "<table><caption>INDEX</caption><tr><th>NAME</th><th>FIELD</th><th>UNIQUE</th><th>ACTIONS</th></tr>";
714+
echo "<table><caption>Index</caption><tr><th>Name</th><th>Field</th><th>Unique</th><th>Actions</th></tr>";
702715
foreach($q_idx as $rc) {
703716
$bg=($bg==1)?2:1;
704717
echo "<tr class='r c$bg'><td>".$rc[1]."</td><td>";
@@ -707,7 +720,7 @@ public function getTables($db) {
707720
echo "</td><td>".($rc[2]==1 ? 'YES':'NO')."</td><td><a class='del' href='{$ed->path}9/$db/$tb/".base64_encode($rc[1])."'>drop</a></td></tr>";
708721
}
709722
$q_fkl=$ed->con->query("PRAGMA foreign_key_list($tb)")->fetch(2);
710-
echo "</table><table><caption>FOREIGN KEYS</caption><tr><th>FIELD</th><th>TARGET</th><th>ON DELETE</th><th>ON UPDATE</th><th>ACTIONS <a href='{$ed->path}14/$db/$tb'>add</a></th></tr>";
723+
echo "</table><table><caption>Foreign Keys</caption><tr><th>Field</th><th>Target</th><th>On delete</th><th>On update</th><th>Actions <a href='{$ed->path}14/$db/$tb'>add</a></th></tr>";
711724
foreach($q_fkl as $r_fkl) {
712725
$bg=($bg==1)?2:1;
713726
echo "<tr class='r c$bg'><td>".$r_fkl['from']."</td><td>".$r_fkl['table'].".".$r_fkl['to']."</td><td>".$r_fkl['on_delete']."</td><td>".$r_fkl['on_update']."</td><td><a href='{$ed->path}14/$db/$tb/{$r_fkl['id']}'>change</a><a class='del' href='{$ed->path}14/$db/$tb/{$r_fkl['id']}/fk'>drop</a></td></tr>";
@@ -827,7 +840,6 @@ public function getTables($db) {
827840
$q_r[]="COMMIT";
828841
foreach($q_r as $q) @$ed->con->exec($q);
829842
$ed->redir("5/$db",['ok'=>"Successfully deleted"]);
830-
831843
break;
832844

833845
case "14"://fk
@@ -914,7 +926,7 @@ public function getTables($db) {
914926
$r_col=$q_rex->fetch(2);
915927
$q_vws=$ed->con->query("SELECT type FROM sqlite_master WHERE name='$tb'",true)->fetch();
916928
echo $head.$ed->menu($db,($q_vws=='view'?'':$tb),1,($q_vws=='view'?['view',$tb]:''))."<table><tr>";
917-
if($q_vws !='view') echo "<th>ACTIONS</th>";
929+
if($q_vws !='view') echo "<th>Actions</th>";
918930
$q_ti=$ed->con->query("PRAGMA table_info($tb)")->fetch(1);
919931
$rinf=[];
920932
foreach($q_ti as $r_ti) {
@@ -1124,7 +1136,7 @@ public function getTables($db) {
11241136
$fields.="<option value='$fl'>$fl</option>";
11251137
echo "<tr><td>$fl</td><td><select name='cond__".$fl."'>$conds</select></td><td><input type='text' name='$fl'/></td></tr>";
11261138
}
1127-
echo "<tr class='c1'><td>ORDER</td><td><select name='order_field'>$fields</select></td><td><select name='order_ord'><option value='ASC'>ASC</option><option value='DESC'>DESC</option></select></td></tr><tr><td colspan='3'><button type='submit' name='search'>Search</button></td></tr></table></form>";
1139+
echo "<tr class='c1'><td>Order</td><td><select name='order_field'>$fields</select></td><td><select name='order_ord'><option value='ASC'>ASC</option><option value='DESC'>DESC</option></select></td></tr><tr><td colspan='3'><button type='submit' name='search'>Search</button></td></tr></table></form>";
11281140
break;
11291141

11301142
case "25"://table empty
@@ -1828,7 +1840,7 @@ public function getTables($db) {
18281840
unset($dbv);
18291841
$lty=DBT::$litetype[1];
18301842
}
1831-
$q_var=['Extension'=>$lty,'SQLite'=>$vv,'PHP'=>PHP_VERSION,'Software'=>$_SERVER['SERVER_SOFTWARE']];
1843+
$q_var=['Extension'=>$lty,'SQLite'=>$vv,'Php'=>PHP_VERSION,'Software'=>$_SERVER['SERVER_SOFTWARE']];
18321844
foreach($q_var as $r_k=>$r_var) {
18331845
$bg=($bg==1)?2:1;
18341846
echo "<tr class='r c$bg'><td>$r_k</td><td>$r_var</td></tr>";

0 commit comments

Comments
 (0)