From 9d3f97870810e739041eccad234d47308747cb1f Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Thu, 6 Feb 2020 18:06:07 +0100 Subject: new feature : admin database manager fix #12 --- app/class/Controlleradmin.php | 45 ++++++++---- app/class/Modeladmin.php | 48 +++++++++++++ app/class/Modelmassedit.php | 0 app/class/Routes.php | 3 +- app/fn/fn.php | 57 +++++++++++++-- app/view/templates/admin.php | 145 +++++++++++++++++++++----------------- app/view/templates/backtopbar.php | 9 +-- assets/css/home.css | 6 ++ 8 files changed, 223 insertions(+), 90 deletions(-) create mode 100644 app/class/Modeladmin.php delete mode 100644 app/class/Modelmassedit.php diff --git a/app/class/Controlleradmin.php b/app/class/Controlleradmin.php index b7d0e31..835f158 100644 --- a/app/class/Controlleradmin.php +++ b/app/class/Controlleradmin.php @@ -7,6 +7,15 @@ class Controlleradmin extends Controller /** @var Modelmedia $mediamanager */ protected $mediamanager; + /** @var Modeladmin */ + protected $adminmanager; + + public function __construct($router) + { + parent::__construct($router); + + $this->adminmanager = new Modeladmin(); + } public function desktop() { @@ -30,6 +39,9 @@ class Controlleradmin extends Controller $datas['globalcss'] = ""; } + $datas['pagesdblist'] = $this->adminmanager->pagesdblist(); + $datas['pagesdbtree'] = $this->mediamanager->listdir(Model::PAGES_DIR); + $this->showtemplate('admin', $datas); } else { $this->routedirect('home'); @@ -38,8 +50,8 @@ class Controlleradmin extends Controller public function update() { - $this->globaldircheck(); - + MODEL::dircheck(MODEL::GLOBAL_DIR); + $globalcss = file_put_contents(Model::GLOBAL_DIR . 'global.css', $_POST['globalcss']); Config::hydrate($_POST); @@ -50,16 +62,25 @@ class Controlleradmin extends Controller } } - - public function globaldircheck() - { - if(!is_dir(Model::GLOBAL_DIR)) { - return mkdir(Model::GLOBAL_DIR); - } else { - return true; - } - } - + public function database() + { + if(!empty($_POST['action'])) { + switch ($_POST['action']) { + case 'duplicate': + if(!empty($_POST['dbsrc']) && !empty($_POST['dbtarget'])) { + $this->adminmanager->copydb($_POST['dbsrc'], $_POST['dbtarget']); + } + break; + case 'select': + if(!empty($_POST['pagetable'])) { + Config::hydrate($_POST); + Config::savejson(); + } + break; + } + } + $this->routedirect('admin'); + } } diff --git a/app/class/Modeladmin.php b/app/class/Modeladmin.php new file mode 100644 index 0000000..54c4f0c --- /dev/null +++ b/app/class/Modeladmin.php @@ -0,0 +1,48 @@ +copydb(Config::pagetable(), $name); + } + + /** + * Copy database folder to a new folder if it doeas not already exsit + * + * @param string $db name of source page database to copy + * @param string $name of the destination database + */ + public function copydb(string $db, string $name) + { + $dbdir = self::PAGES_DIR . $db; + $newdbdir = self::PAGES_DIR . idclean($name); + if(is_dir($dbdir) && !is_dir($newdbdir)) { + recurse_copy($dbdir, $newdbdir); + } + } +} + +?> \ No newline at end of file diff --git a/app/class/Modelmassedit.php b/app/class/Modelmassedit.php deleted file mode 100644 index e69de29..0000000 diff --git a/app/class/Routes.php b/app/class/Routes.php index c4571d9..277d478 100644 --- a/app/class/Routes.php +++ b/app/class/Routes.php @@ -36,8 +36,9 @@ class Routes ['GET', '/!font', 'Controllerfont#desktop', 'font'], ['GET', '/!font/render', 'Controllerfont#render', 'fontrender'], ['POST', '/!font/add', 'Controllerfont#add', 'fontadd'], - ['POST', '/!admin', 'Controlleradmin#update', 'adminupdate'], ['GET', '/!admin', 'Controlleradmin#desktop', 'admin'], + ['POST', '/!admin', 'Controlleradmin#update', 'adminupdate'], + ['POST', '/!admin/database', 'Controlleradmin#database', 'admindatabase'], ['GET', '/!user', 'Controlleruser#desktop', 'user'], ['POST', '/!user/add', 'Controlleruser#add', 'useradd'], ['POST', '/!user/update', 'Controlleruser#update', 'userupdate'], diff --git a/app/fn/fn.php b/app/fn/fn.php index 61c2312..6dfeb2c 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -210,9 +210,9 @@ function array_diff_assoc_recursive($array1, $array2) { /** - * Generate a folder tree based on reccurive array + * Generate a clickable folder tree based on reccurive array */ -function treecount(array $dir, string $dirname, int $deepness, string $path, string $currentdir, Medialist $mediaopt) +function treecount(array $dirlist, string $dirname, int $deepness, string $path, string $currentdir, Medialist $mediaopt) { if ($path . '/' === $currentdir) { $folder = '├─📂' . $dirname . ''; @@ -221,15 +221,48 @@ function treecount(array $dir, string $dirname, int $deepness, string $path, str } echo ''; echo '' . str_repeat('  ', $deepness) . $folder . ''; - echo '' . $dir['dirfilecount'] . ''; + echo '' . $dirlist['dirfilecount'] . ''; echo ''; - foreach ($dir as $key => $value) { + foreach ($dirlist as $key => $value) { if (is_array($value)) { treecount($value, $key, $deepness + 1, $path . DIRECTORY_SEPARATOR . $key, $currentdir, $mediaopt); } } } + +/** + * Generate a clickable folder tree based on reccurive array + */ +function basictree(array $dirlist, string $dirname, int $deepness, string $path, string $currentdir) +{ + + if ($path === $currentdir) { + $folder = '├─📂' . $dirname . ''; + $checked = 'checked'; + } else { + $folder = '├─📁' . $dirname; + $checked = ''; + } + + if($deepness === 1) { + $radio = ''; + } else { + $radio = ''; + } + + echo ''; + echo '' . $radio . ''; + echo ''; + echo '' . $dirlist['dirfilecount'] . ''; + echo ''; + foreach ($dirlist as $key => $value) { + if (is_array($value)) { + basictree($value, $key, $deepness + 1, $path . DIRECTORY_SEPARATOR . $key, $currentdir); + } + } +} + function checkboxes(string $name, array $optionlist = [], array $checkedlist = []) { $checkboxes = ''; @@ -245,6 +278,22 @@ function checkboxes(string $name, array $optionlist = [], array $checkedlist = [ } +function recurse_copy($src,$dst) { + $dir = opendir($src); + mkdir($dst); + while(false !== ( $file = readdir($dir)) ) { + if (( $file != '.' ) && ( $file != '..' )) { + if ( is_dir($src . '/' . $file) ) { + recurse_copy($src . '/' . $file,$dst . '/' . $file); + } + else { + copy($src . '/' . $file,$dst . '/' . $file); + } + } + } + closedir($dir); +} + diff --git a/app/view/templates/admin.php b/app/view/templates/admin.php index 57abfcc..0c9f5af 100644 --- a/app/view/templates/admin.php +++ b/app/view/templates/admin.php @@ -10,37 +10,37 @@
- +
- +

configuration

+
- +

Home page

@@ -51,11 +51,6 @@
-
- form="admin"> - -
-
form="admin"> @@ -66,7 +61,7 @@ + ?> >--use default BODY element-- + ?> @@ -104,7 +99,7 @@ + ?> Alert pages +

Set the style and text to show when a page does not exist, or when a visitor don't have access to it.

+

Common options

@@ -125,7 +122,7 @@ + ?> @@ -183,7 +180,7 @@ You can use body.alert class to specify style.

- +

Render

@@ -222,7 +219,7 @@ + ?> --no thumbnail-- - - + + - - -

Databases

- -

Manage databases

- -

- - - -

- -

-

- - - -
-

- - -

Interface

Set interface Style

@@ -273,7 +244,7 @@ + ?> - +
+
+
+

Databases

+
+ +
+ + + + + + +
usingdatabasespages
+ + + + +
+ +

Duplicate Database

+ +
+ + + + + + + +
+ + +
+
+
+
diff --git a/app/view/templates/backtopbar.php b/app/view/templates/backtopbar.php index c632d66..c1dd361 100644 --- a/app/view/templates/backtopbar.php +++ b/app/view/templates/backtopbar.php @@ -30,10 +30,6 @@ media -> - - font - isadmin()) { ?> @@ -74,10 +70,7 @@ if($user->isadmin()) { -> - - timeline - + > id() ?> diff --git a/assets/css/home.css b/assets/css/home.css index fdf6e5b..1c2edfb 100644 --- a/assets/css/home.css +++ b/assets/css/home.css @@ -242,6 +242,12 @@ main.admin input, main.admin select, main.admin textarea { +main section.admin { + max-width: 400px; +} + + + div.checkbox [type="checkbox"] { display: inline-block; width: auto; -- cgit v1.2.3