Skip to content

Commit ca2c153

Browse files
authored
1.1
-remove php version check -increase general font size -add drop db, empty collection, drop collection error messages
1 parent 9a2a1aa commit ca2c153

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

mongo.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?php
22
error_reporting(E_ALL);
3-
if(version_compare(PHP_VERSION,'7.0.0','<')) die('Require PHP 7.0 or higher');
43
if(!extension_loaded('mongodb')) die('Install Mongodb extension!');
54
session_name('Mongo');
65
session_start();
76
$bg=2;
87
$step=20;
9-
$version="1.0";
8+
$version="1.1";
109
class DBT {
1110
private static $instance=NULL;
1211
protected $_cnx,$db,$bw,$wc;
@@ -261,7 +260,7 @@ public function menu($db='',$tb='',$left='') {
261260
if(!in_array($db,$this->deny)) {
262261
$tbl='';
263262
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 (&lt;".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'>";
265264
} else {
266265
$str.="<div class='col3'>";
267266
}
@@ -348,7 +347,7 @@ public function imp_xml($body) {
348347
$head='<!DOCTYPE html><html lang="en"><head>
349348
<title>EdMongoAdmin</title><meta charset="utf-8">
350349
<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}
352351
html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;background:#fff}
353352
html,textarea{overflow:auto}
354353
.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) {
645644
$tb=$ed->sg[2];
646645
$id=$ed->sg[3];
647646
$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+
}
651653
break;
652654

653655
case "24"://search
@@ -676,8 +678,12 @@ public function imp_xml($body) {
676678
$ed->check([1,2]);
677679
$db=$ed->sg[1];
678680
$tb=$ed->sg[2];
681+
try {
679682
$ed->con->delete($db.'.'.$tb);
680683
$ed->redir("20/$db/$tb",['ok'=>"Table is empty"]);
684+
} catch(Exception $e) {
685+
$ed->redir("20/$db/$tb",['err'=>"Empty failed"]);
686+
}
681687
break;
682688

683689
case "26"://drop collection
@@ -791,7 +797,7 @@ public function imp_xml($body) {
791797
}
792798
echo "</select><h3>File format</h3>";
793799
$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>";
795801
echo "<h3>File compression</h3><p><select name='ftype'>";
796802
$fty=['plain'=>'None','zip'=>'Zip','gz'=>'GZ'];
797803
foreach($fty as $k=> $ft) echo "<option value='$k'>$ft</option>";
@@ -952,7 +958,7 @@ public function imp_xml($body) {
952958
session_unset();
953959
session_destroy();
954960
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>
956962
<div>Username<br/><input type='text' name='username' value=''/></div>
957963
<div>Password<br/><input type='password' name='password'/></div>
958964
<div>Database<br/><input type='text' name='db'/></div>

0 commit comments

Comments
 (0)