Skip to content

Commit d946290

Browse files
committed
2 parents 2c1eaa0 + 259803d commit d946290

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

mongodbadmin.php

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Render a document preview for the black code box with referenced
4343
* linked to the collection and id for that database reference.
4444
*
45-
* @param string $document
45+
* @param string $document
4646
* @return string $preview
4747
*/
4848
function renderDocumentPreview($mongo, $document)
@@ -92,7 +92,7 @@ function linkDocumentReferences($mongo, $document)
9292

9393
/**
9494
* Prepare user submitted array of PHP code as a MongoDB
95-
* document that can be saved.
95+
* document that can be saved.
9696
*
9797
* @param mixed $value
9898
* @return array $document
@@ -212,7 +212,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
212212
$mongo
213213
->selectDB($_REQUEST['delete_db'])
214214
->drop();
215-
215+
216216
header('location: ' . $_SERVER['PHP_SELF']);
217217
exit;
218218
}
@@ -221,18 +221,18 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
221221
if (isset($_REQUEST['create_db'])) {
222222
$mongo->selectDB($_REQUEST['create_db'])->createCollection('__tmp_collection_');
223223
$mongo->selectDB($_REQUEST['create_db'])->dropCollection('__tmp_collection_');
224-
224+
225225
header('location: ' . $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['create_db']);
226226
exit;
227-
227+
228228
}
229229

230230
// CREATE DB COLLECTION
231231
if (isset($_REQUEST['create_collection'])) {
232232
$mongo
233233
->selectDB($_REQUEST['db'])
234234
->createCollection($_REQUEST['create_collection']);
235-
235+
236236
header('location: ' . $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['create_collection']);
237237
exit;
238238
}
@@ -243,7 +243,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
243243
->selectDB($_REQUEST['db'])
244244
->selectCollection($_REQUEST['delete_collection'])
245245
->drop();
246-
246+
247247
header('location: ' . $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db']);
248248
exit;
249249
}
@@ -351,16 +351,15 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
351351
}
352352

353353
#create_form {
354-
position: absolute;
355-
top: 20px;
356-
right: 20px;
357354
-moz-border-radius: 10px;
358355
-webkit-border-radius: 10px;
359356
border-radius: 10px;
360357
padding: 15px;
361358
background: #f5f5f5;
362359
border: 1px solid #ccc;
363360
width: 400px;
361+
float: right;
362+
margin-bottom: 10px;
364363
}
365364
#create_form label {
366365
float: left;
@@ -447,11 +446,11 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
447446
}
448447
</style>
449448
</head>
450-
449+
451450
<body>
452451

453452
<div id="content">
454-
<h1>PHP MongoDB Admin</h1>
453+
<h1>PHP MongoDB Admin - <?php echo $server ?></h1>
455454
<?php if (isset($_REQUEST['error'])): ?>
456455
<div class="error">
457456
<?php echo $_REQUEST['error'] ?>
@@ -477,6 +476,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
477476
<thead>
478477
<tr>
479478
<th>Name</th>
479+
<th>Collections</th>
480480
<th></th>
481481
</tr>
482482
</thead>
@@ -485,6 +485,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
485485
<?php foreach ($dbs['databases'] as $db): if ($db['name'] === 'local' || $db['name'] === 'admin') continue; ?>
486486
<tr>
487487
<td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $db['name'] ?>"><?php echo $db['name'] ?></a></td>
488+
<td><?php echo count($mongo->selectDb($db['name'])->listCollections()) ?></td>
488489
<td><a href="<?php echo $_SERVER['PHP_SELF'] ?>?delete_db=<?php echo $db['name'] ?>" onClick="return confirm('Are you sure you want to delete this database?');">Delete</a></td>
489490
</tr>
490491
<?php endforeach; ?>
@@ -510,6 +511,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
510511
<thead>
511512
<tr>
512513
<th>Name</th>
514+
<th>Documents</th>
513515
<th></th>
514516
</tr>
515517
</thead>
@@ -518,6 +520,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
518520
<?php foreach ($collections as $collection): ?>
519521
<tr>
520522
<td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $collection->getName() ?>"><?php echo $collection->getName() ?></a></td>
523+
<td><?php echo $collection->count(); ?></td>
521524
<td><a href="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo $_REQUEST['db'] ?>&delete_collection=<?php echo $collection->getName() ?>" onClick="return confirm('Are you sure you want to delete this collection?');">Delete</a></td>
522525
</tr>
523526
<?php endforeach; ?>
@@ -527,12 +530,6 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
527530
<?php // CREATE AND LIST DB COLLECTION DOCUMENTS ?>
528531
<?php elseif ( ! isset($_REQUEST['id']) || isset($_REQUEST['search'])): ?>
529532

530-
<h2>
531-
<a href="<?php echo $_SERVER['PHP_SELF'] ?>">Databases</a> >>
532-
<a href="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo $_REQUEST['db'] ?>"><?php echo $_REQUEST['db'] ?></a> >>
533-
<?php echo $_REQUEST['collection'] ?>
534-
</h2>
535-
536533
<?php
537534
$max = 20;
538535
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
@@ -555,24 +552,35 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
555552
->find()
556553
->limit($limit)
557554
->skip($skip);
558-
}
555+
}
559556

560557
$total = $cursor->count();
561558
$pages = ceil($total / $max);
559+
562560
if ($pages && $page > $pages) {
563561
header('location: ' . $_SERVER['HTTP_REFERER']);
564562
exit;
565563
}
566-
if ($pages > 1): ?>
564+
?>
565+
566+
<h2>
567+
<a href="<?php echo $_SERVER['PHP_SELF'] ?>">Databases</a> >>
568+
<a href="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo $_REQUEST['db'] ?>"><?php echo $_REQUEST['db'] ?></a> >>
569+
<?php echo $_REQUEST['collection'] ?> (<?php echo $cursor->count() ?> Documents)
570+
</h2>
571+
572+
<?php if ($pages > 1): ?>
567573
<div id="pager">
568-
<?php echo $pages ?> pages. Go to page
569-
<input type="text" name="page" size="4" value="<?php echo $page ?>" onChange="javascript: location.href = '<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>&page=' + this.value;" />
574+
<?php echo $pages ?> pages. Go to page
575+
<input type="text" name="page" size="4" value="<?php echo $page ?>" onChange="javascript: location.href = '<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>&search=<?php echo urlencode($_REQUEST['search']) ?>&page=' + this.value;" />
570576
<input type="button" name="go" value="Go" />
571577
</div>
572578
<?php endif; ?>
573579

574580
<div id="search">
575-
<form action="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo $_REQUEST['db'] ?>&collection=<?php echo $_REQUEST['collection'] ?>" method="POST">
581+
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET">
582+
<input type="hidden" name="db" value="<?php echo $_REQUEST['db'] ?>" />
583+
<input type="hidden" name="collection" value="<?php echo $_REQUEST['collection'] ?>" />
576584
<label for="search_input">Search</label>
577585
<input type="text" id="search_input" name="search" size="36"<?php echo isset($_REQUEST['search']) ? ' value="' . htmlspecialchars($_REQUEST['search']) . '"': '' ?> />
578586
<input type="submit" name="submit_search" value="Search" />
@@ -630,7 +638,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
630638
<?php endforeach; ?>
631639
</tbody>
632640
</table>
633-
641+
634642
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
635643
<input type="hidden" name="values[_id]" value="<?php echo $document['_id'] ?>" />
636644

@@ -652,8 +660,8 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
652660

653661
<h2>
654662
<a href="<?php echo $_SERVER['PHP_SELF'] ?>">Databases</a> >>
655-
<a href="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo $_REQUEST['db'] ?>"><?php echo $_REQUEST['db'] ?></a> >>
656-
<a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>"><?php echo $_REQUEST['collection'] ?></a> >>
663+
<a href="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo $_REQUEST['db'] ?>"><?php echo $_REQUEST['db'] ?></a> >>
664+
<a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>"><?php echo $_REQUEST['collection'] ?></a> >>
657665
<?php echo $_REQUEST['id'] ?>
658666
</h2>
659667
<?php $document = findMongoDbDocument($_REQUEST['id'], $_REQUEST['db'], $_REQUEST['collection']); ?>
@@ -681,4 +689,3 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
681689
</div>
682690
</body>
683691
</html>
684-

0 commit comments

Comments
 (0)