|
1 | 1 | <?php |
2 | 2 | error_reporting(E_ALL); |
3 | | -if(version_compare(PHP_VERSION,'7.0.0','<')) die('Require PHP 7.0 or higher'); |
4 | 3 | if(!extension_loaded('mongodb')) die('Install Mongodb extension!'); |
5 | 4 | session_name('Mongo'); |
6 | 5 | session_start(); |
7 | 6 | $bg=2; |
8 | 7 | $step=20; |
9 | | -$version="1.0"; |
| 8 | +$version="1.1"; |
10 | 9 | class DBT { |
11 | 10 | private static $instance=NULL; |
12 | 11 | protected $_cnx,$db,$bw,$wc; |
@@ -261,7 +260,7 @@ public function menu($db='',$tb='',$left='') { |
261 | 260 | if(!in_array($db,$this->deny)) { |
262 | 261 | $tbl=''; |
263 | 262 | foreach($q_ts as $k=>$r_tb) if($r_tb!='view' && substr($k,0,7)!='system.') $tbl.="<option value='$k'>$k</option>"; |
264 | | - $str.="<div class='col1'>".$this->form("2")."<input type='hidden' name='dbn' value='$db'/><input type='text' name='colln' placeholder='Collection'/><br/><button type='submit'>Create</button></form>".$this->form("30/$db",1)."<h3>Import</h3><small>json, xml, gz, zip</small><br/><input type='file' name='importfile' /><br/><button type='submit'>Import</button></form>".$this->form("9/$db")."<h3>Rename Collection</h3><select name='oldtb'>$tbl</select><br/><input type='text' name='newtb' placeholder='New Name' /><br/><button type='submit'>Rename</button></form>".$this->form("9/$db")."<h3>Create View</h3><select name='tbl'>$tbl</select><br/><input type='text' name='vn' placeholder='View Name' /><br/><input type='text' name='fld' placeholder='Romove fields (comma separated)' /><br/><button type='submit'>Create</button></form></div><div class='col2'>"; |
| 263 | + $str.="<div class='col1'>".$this->form("2")."<input type='hidden' name='dbn' value='$db'/><input type='text' name='colln' placeholder='Collection'/><br/><button type='submit'>Create</button></form>".$this->form("30/$db",1)."<h3>Import</h3><small>json, xml, gz, zip</small><br/><input type='file' name='importfile' /><br/><button type='submit'>Upload (<".ini_get("upload_max_filesize")."B)</button></form>".$this->form("9/$db")."<h3>Rename Collection</h3><select name='oldtb'>$tbl</select><br/><input type='text' name='newtb' placeholder='New Name' /><br/><button type='submit'>Rename</button></form>".$this->form("9/$db")."<h3>Create View</h3><select name='tbl'>$tbl</select><br/><input type='text' name='vn' placeholder='View Name' /><br/><input type='text' name='fld' placeholder='Romove fields (comma separated)' /><br/><button type='submit'>Create</button></form></div><div class='col2'>"; |
265 | 264 | } else { |
266 | 265 | $str.="<div class='col3'>"; |
267 | 266 | } |
@@ -348,7 +347,7 @@ public function imp_xml($body) { |
348 | 347 | $head='<!DOCTYPE html><html lang="en"><head> |
349 | 348 | <title>EdMongoAdmin</title><meta charset="utf-8"> |
350 | 349 | <style> |
351 | | -*{margin:0;padding:0;font-size:12px;color:#333;font-family:Arial} |
| 350 | +*{margin:0;padding:0;font-size:14px;color:#333;font-family:Arial} |
352 | 351 | html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;background:#fff} |
353 | 352 | html,textarea{overflow:auto} |
354 | 353 | .container{overflow:auto;overflow-y:hidden;-ms-overflow-y:hidden;white-space:nowrap;scrollbar-width:thin} |
@@ -645,9 +644,12 @@ public function imp_xml($body) { |
645 | 644 | $tb=$ed->sg[2]; |
646 | 645 | $id=$ed->sg[3]; |
647 | 646 | $oid=$ed->sg[4]??''; |
648 | | - $del=$ed->con->delete($db.'.'.$tb,['_id'=>$ed->con->convert_id($id,$oid)]); |
649 | | - if($del) $ed->redir("20/$db/$tb",['ok'=>"Successfully deleted"]); |
650 | | - else $ed->redir("20/$db/$tb",['err'=>"Delete failed"]); |
| 647 | + try { |
| 648 | + $ed->con->delete($db.'.'.$tb,['_id'=>$ed->con->convert_id($id,$oid)]); |
| 649 | + $ed->redir("20/$db/$tb",['ok'=>"Successfully deleted"]); |
| 650 | + } catch(Exception $e) { |
| 651 | + $ed->redir("20/$db/$tb",['err'=>"Delete failed"]); |
| 652 | + } |
651 | 653 | break; |
652 | 654 |
|
653 | 655 | case "24"://search |
@@ -676,8 +678,12 @@ public function imp_xml($body) { |
676 | 678 | $ed->check([1,2]); |
677 | 679 | $db=$ed->sg[1]; |
678 | 680 | $tb=$ed->sg[2]; |
| 681 | + try { |
679 | 682 | $ed->con->delete($db.'.'.$tb); |
680 | 683 | $ed->redir("20/$db/$tb",['ok'=>"Table is empty"]); |
| 684 | + } catch(Exception $e) { |
| 685 | + $ed->redir("20/$db/$tb",['err'=>"Empty failed"]); |
| 686 | + } |
681 | 687 | break; |
682 | 688 |
|
683 | 689 | case "26"://drop collection |
@@ -791,7 +797,7 @@ public function imp_xml($body) { |
791 | 797 | } |
792 | 798 | echo "</select><h3>File format</h3>"; |
793 | 799 | $ffo=['json'=>'JSON','xml'=>'XML']; |
794 | | - foreach($ffo as $k=> $ff) echo "<p><input type='radio' name='ffmt[]' onclick='opt()' value='$k'".($k=='json' ? ' checked':'')." /> $ff</p>"; |
| 800 | + foreach($ffo as $k=> $ff) echo "<p><input type='radio' name='ffmt[]' value='$k'".($k=='json' ? ' checked':'')." /> $ff</p>"; |
795 | 801 | echo "<h3>File compression</h3><p><select name='ftype'>"; |
796 | 802 | $fty=['plain'=>'None','zip'=>'Zip','gz'=>'GZ']; |
797 | 803 | foreach($fty as $k=> $ft) echo "<option value='$k'>$ft</option>"; |
@@ -952,7 +958,7 @@ public function imp_xml($body) { |
952 | 958 | session_unset(); |
953 | 959 | session_destroy(); |
954 | 960 | echo $head.$ed->menu('','',2).$ed->form("50")."<div class='dw'><h3>LOGIN</h3> |
955 | | - <div>Host<br/><input type='text' id='host' name='lhost' value='localhost:27017'/></div> |
| 961 | + <div>Host<br/><input type='text' id='host' name='lhost' value='localhost'/></div> |
956 | 962 | <div>Username<br/><input type='text' name='username' value=''/></div> |
957 | 963 | <div>Password<br/><input type='password' name='password'/></div> |
958 | 964 | <div>Database<br/><input type='text' name='db'/></div> |
|
0 commit comments