summaryrefslogtreecommitdiff
path: root/public/app
diff options
context:
space:
mode:
Diffstat (limited to 'public/app')
-rw-r--r--public/app/config/app_constants.php3
-rw-r--r--public/app/controllers/admin/Course_admin.php136
-rw-r--r--public/app/routes/backend.php25
-rw-r--r--public/app/views/admin/categories.php10
-rw-r--r--public/app/views/admin/edit_lesson.php12
5 files changed, 170 insertions, 16 deletions
diff --git a/public/app/config/app_constants.php b/public/app/config/app_constants.php
index 0d04dc2..529d04a 100644
--- a/public/app/config/app_constants.php
+++ b/public/app/config/app_constants.php
@@ -4,7 +4,7 @@
// Default Values (user-privileges and user-roles)
-// read ini file id exist
+// read ini file if exist
// --- -- -- - - -
if (file_exists("../core/auth/.env")) {
$env = parse_ini_file("../core/auth/.env");
@@ -12,6 +12,7 @@ if (file_exists("../core/auth/.env")) {
+
// CENTRAL DEFAULTS ////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
diff --git a/public/app/controllers/admin/Course_admin.php b/public/app/controllers/admin/Course_admin.php
index 0e34e00..ef9ef0e 100644
--- a/public/app/controllers/admin/Course_admin.php
+++ b/public/app/controllers/admin/Course_admin.php
@@ -9,6 +9,13 @@ use app\models\cms\Course_model;
class Course_admin {
+ ## -------------------------------------------------------------------------
+ ##
+ ## COURSE (category) METHODS
+ ##
+ ## -------------------------------------------------------------------------
+
+
/** breadcrumbs
* ---
* responds to ajax GET: /admin/api/categories
@@ -90,4 +97,133 @@ class Course_admin {
];
}
+
+
+
+ ## -------------------------------------------------------------------------
+ ##
+ ## FILE METHODS
+ ##
+ ## -------------------------------------------------------------------------
+
+
+ /** upload_file
+ * upload the file to the file system
+ *
+ * the method reads the POST and FILES array
+ * to retrieve all needed parametres
+ *
+ * + $_FILES[file]
+ * + $_POST[folder] : lesson's ID
+ * + $_POST[reference] : reference type
+ */
+ public static function upload_file()
+ {
+ $post = Registry::get('REQUEST')->POST;
+ $files = Registry::get('REQUEST')->FILES;
+
+
+ // Checks before uploading the file
+ ////////////////////////////////////////////////////////////////////////
+
+ // ** 1: file is upladed to temporary folder ---------------------------
+ if (! is_uploaded_file($files['file']['tmp_name'])) {
+ return ['success' => false]; // bye!
+ }
+
+ // ** 2: File belongs to the allowed MIME types ------------------------
+ $allowed_file_types = array(
+ 'application/pdf',
+ 'image/png', 'image/jpeg',
+ 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+ 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
+ );
+ // Recomended MIME type checking via mime_content_type():
+ $mime_type = mime_content_type($files['file']['tmp_name']);
+ if (! in_array($mime_type, $allowed_file_types)) { // File type NOT allowed ...
+ return ['success' => false]; // bye!
+ }
+
+ $file_name = $files['file']['name'];
+ $file_type = $files['file']['type']; // do not take it for granted
+ $file_size = $files['file']['size'];
+ $file_tmp = $files['file']['tmp_name'];
+
+ $bare_name = pathinfo($file_name, PATHINFO_FILENAME);
+ $file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
+
+
+ // ** 3: filename or size checks may be added --------------------------
+ if ($file_name == "") {
+ return ['success' => false]; // bye!
+ }
+
+
+ // READY to finaly save/upload the file to CDN /////////////////////////
+
+ $folder = MEDIA_STORAGE_ROOT . $post['folder'];
+ if (!file_exists($folder)) { // create folder if not exists
+ mkdir($folder, 0757, true);
+ }
+
+ // print_r([
+ // 'dir' => $folder,
+ // 'file' => $bare_name,
+ // 'ext' => $file_ext,
+ // 'type' => $file_type
+ // ]); die();
+
+ $relative_filename = $post['folder']
+ .'/'
+ . strtolower(self::clear_file_name($bare_name) .'.'. $file_ext);
+ $store_filename = MEDIA_STORAGE_ROOT . $relative_filename;
+
+ if (move_uploaded_file($files["file"]["tmp_name"], $store_filename)) {
+ return [
+ 'success' => true,
+ 'path' => $store_filename,
+ 'type' => $mime_type
+ ];
+
+ } else { return ['success' => false]; }
+
+ }
+
+
+ /** clear_file_name
+ * replace greek characters and strip symbols
+ */
+ private static function clear_file_name($str)
+ {
+ $el = mb_split( "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάέήίόύώϊϋς ", "");
+ $en = str_split("ABGDEZHUIKLMNJOPRSTYFXCVabgdezhuiklmnjoprstyfxcvaehioyviys-");
+ $strip = str_split("!@#$%^&*()+~`[]{};'/<>?=\"");
+
+ return str_replace($strip, '', str_replace($el, $en, $str));
+ }
+
+
+ /** define_media
+ *
+ * create a record in media table
+ *
+ * @param $data
+ * @return id (int): id of created media record
+ */
+ public static function define_media($data)
+ {
+ $sql = "INSERT INTO wiki_media (`title`, `type`, `path`)
+ VALUES (:title, :mimetype, :filepath)";
+ $stmt = $this->pdo->prepare($sql);
+ $stmt->execute([
+ 'title' => $data['title'],
+ 'mimetype' => $data['type'],
+ 'filepath' => $data['path']
+ ]);
+ $inserted_id = $this->pdo->lastInsertId();
+
+ return $inserted_id;
+ }
+
+
} \ No newline at end of file
diff --git a/public/app/routes/backend.php b/public/app/routes/backend.php
index 88bf4b8..704d161 100644
--- a/public/app/routes/backend.php
+++ b/public/app/routes/backend.php
@@ -15,7 +15,7 @@ Route::add('/admin/lessons', function () {
});
-// admin cateogies
+// admin categories (=courses)
// -----------------------------------------------------------------------------
// manage categories page
@@ -23,7 +23,7 @@ Route::add('/admin/lessons', function () {
Route::add('/admin/categories', function () {
Auth::allowRoles([1, 2, 3]);
Render::view('admin/skeleton', [
- 'title' => 'Διαχείριση Κατηγοριών',
+ 'title' => 'Διαχείριση Κεφαλαίων',
'action' => 'categories',
]);
});
@@ -39,16 +39,14 @@ Route::add('/admin/api/categories', function () {
// ajax: add new category (course)
// ---
-Route::add('/admin/api/category/add', function () {
- Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
- Course_admin::add_course();
- },
- 'post'
-);
+Route::add('/admin/api/categories/add', function () {
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Course_admin::add_course();
+}, 'post');
// ajax: edit category (course)
// ---
-Route::add('/admin/api/category/update', function () {
+Route::add('/admin/api/categories/update', function () {
Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
Course_admin::update_course();
},
@@ -106,3 +104,12 @@ Route::add('/admin/edit_lesson/([0-9]*)', function ($id) {
'id' => intval($id)
]);
});
+
+
+
+// ajax: file-upload
+// ---
+Route::add('/admin/api/file_upload', function () {
+ Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles
+ Render::json(Course_admin::upload_file());
+}, 'post');
diff --git a/public/app/views/admin/categories.php b/public/app/views/admin/categories.php
index 91acec1..26fd5a2 100644
--- a/public/app/views/admin/categories.php
+++ b/public/app/views/admin/categories.php
@@ -5,7 +5,7 @@
<!-- Button trigger modal -->
<button type="button" class="btn pull-right"
data-bs-toggle="modal" data-bs-target="#manageCategory" data-id="0">
- <i class="fas fa-plus"></i> &nbsp; Νέα Κατηγορία
+ <i class="fas fa-plus"></i> &nbsp; Νέο Κεφάλαιο
</button>
</div>
</div>
@@ -18,7 +18,7 @@
<table id="dt-categories" class="table table-responsive dt-table" style="width:100%">
<thead>
- <th class="dt-breadcrumb">Κατηγορία</th>
+ <th class="dt-breadcrumb">Κατηγορία/Κεφάλαιο</th>
<th class="dt-actions"></th>
</thead>
</table>
@@ -72,12 +72,12 @@
</div><!-- /modal body -->
<div class="modal-footer">
- <div class="row">
+ <div class="row" style="width: 50%;">
<div class="form-actions">
- <div class="col-xs-4">
+ <div class="col-4">
<button type="button" class="btn btn-default js-modal-close col-sm-12" data-bs-dismiss="modal">Κλείσιμο</button>
</div>
- <div class="col-xs-8">
+ <div class="col-8">
<button class="btn btn-success col-sm-12" type="submit">Καταχώριση</button>
</div>
</div>
diff --git a/public/app/views/admin/edit_lesson.php b/public/app/views/admin/edit_lesson.php
index 4ea8104..7d74c38 100644
--- a/public/app/views/admin/edit_lesson.php
+++ b/public/app/views/admin/edit_lesson.php
@@ -96,7 +96,7 @@
<!-- Button trigger modal -->
<button type="button" class="btn btn-sm btn-success pull-right over-bar"
- data-toggle="modal" data-target="#editorModal" data-action="upload_file">
+ data-bs-toggle="modal" data-bs-target="#editorModal" data-action="upload_file">
<i class="fas fa-plus"></i> &nbsp; Προσθήκη
</button>
@@ -146,4 +146,14 @@
</div>
</div><!-- /manage -->
+
+
+<!-- MODAL for file uploads and preview -->
+<div class="modal fade" id="editorModal" aria-labelledby="myModalLabel" aria-hidden="true">
+ <div class="modal-dialog modal-lg" role="document">
+ <div class="modal-content">
+ <!-- content will be dynamic -->
+ </div>
+ </div>
+</div>