diff --git a/ci_scms/.gitignore b/ci_scms/.gitignore
new file mode 100644
index 0000000..3ebe0b2
--- /dev/null
+++ b/ci_scms/.gitignore
@@ -0,0 +1,4 @@
+img/upload/**
+img/gallery/mid/**
+img/gallery/orig/**
+img/gallery/thumb/**
\ No newline at end of file
diff --git a/ci_scms/application/.htaccess b/ci_scms/application/.htaccess
new file mode 100644
index 0000000..6c63ed4
--- /dev/null
+++ b/ci_scms/application/.htaccess
@@ -0,0 +1,6 @@
+
Directory access is forbidden.
+ + + diff --git a/ci_scms/application/controllers/main.php b/ci_scms/application/controllers/main.php new file mode 100644 index 0000000..f3d043f --- /dev/null +++ b/ci_scms/application/controllers/main.php @@ -0,0 +1,90 @@ +load->model('menu_model'); + $this->load->model("content_model"); + $data["is_admin"] = $this->is_admin; + + if ($page != "") { + if (!$this->menu_model->is_page_valid($page)) { + show_404(); + } + } + + if ($page == "") { + $data = $this->menu_model->getFirstMenuItem(); + $page = $data["link"]; + } + + $pageid = $this->menu_model->getPageId($page); + $data["pageid"] = $pageid; + $content_data; + $contents; + $i = 0; + + if ($pageid != -1) { + $contentlinks = $this->content_model->get_page_contents($pageid); + + if (sizeof($contentlinks) > 0) + { + //first let's prep a class like array + foreach($contentlinks as $c) { + $contents[$i]["link"] = $c; + + $d = null; + if ($c["content_type"] == "1") { + $d = $this->content_model->get_content_text($c["content_id"]); + } elseif ($c["content_type"] == "3") { + $d["main"] = $this->content_model->get_content_gallery($c["content_id"]); + $d["data"] = $this->content_model->get_gallery_data($d["main"]["id"]); + } elseif ($c["content_type"] == "4") { + $d["main"] = $this->content_model->get_content_multi_gallery($c["content_id"]); + $d["folders"] = $this->content_model->get_content_multi_gallery_folders($d["main"]["id"]); + } + + $contents[$i]["data"] = $d; + + $i++; + } + } + } + + + $this->_send_headers($page); + + $htmld; + $j = 0; + + if (isset($contents)) { + if (sizeof($contents) > 0) { + $i = 0; + $data["contsize"] = sizeof($contents); + foreach ($contents as $c) { + $data["data"] = $c["data"]; + $data["link"] = $c["link"]; + $data["i"] = $i; + //var_dump($c["data"]); + //var_dump($c["data"]); + if ($c["link"]["content_type"] == 1) { + $data["htmld"][$j] = $this->load->view("textcontent", $data, true); + } else if ($c["link"]["content_type"] == 3) { + $data["htmld"][$j] = $this->load->view("gallerycontent", $data, true); + } else if ($c["link"]["content_type"] == 4) { + $data["htmld"][$j] = $this->load->view("multigallerycontent", $data, true); + } + + $i++; + $j++; + } + } + } + + $this->load->view("content", $data); + $this->_send_footer(); + } +} \ No newline at end of file diff --git a/ci_scms/application/core/V_Controller.php b/ci_scms/application/core/V_Controller.php new file mode 100644 index 0000000..583f325 --- /dev/null +++ b/ci_scms/application/core/V_Controller.php @@ -0,0 +1,159 @@ +isadmin = false; + $this->_manage_session(); + } + + function _manage_session() { + if (isset($_SESSION['sid'])) { + $this->load->model("admin_model"); + $this->is_admin = $this->admin_model->is_admin($_SESSION['sid']); + } + } + + function _manage_admin_session() { + } + + function _send_admin_headers() { + } + + function _send_headers($page, $type = "") { + $this->load->helper('url'); + + $data["title"] = "title"; + $data["pageid"] = $page; + $data["is_admin"] = $this->is_admin; + $data["type"] = $type; + + $this->load->helper("url"); + + $this->_send_header($data); + $this->_send_menu($data); + } + + function _send_header($data) { + $this->load->view("header", $data); + } + + function _send_menu($data) { + $this->load->model('menu_model'); + + $data["menu"] = $this->menu_model->getBaseMenuData(); + + $this->load->view("menu", $data); + } + + function _send_footer() { + $data["is_admin"] = $this->is_admin; + $this->load->view("footer", $data); + } + + function salt_md5($text) { + return hash("sha512", "dla=/aasdf42)%/sf14" . $text . "$)/fasdfh297452sdikfahzsbgdfa|"); + } + + function redirect_to_pageid($id) { + $this->load->helper('url'); + + if (!is_numeric($id)) + redirect("main/index"); + + if ($id < 0) + redirect("main/index"); + + $this->load->model("common_model"); + $pname = $this->common_model->get_page_name_from_id($id); + + if ($pname) + redirect("main/index/" . $pname); + else + redirect("main/index"); + } + + protected function _url_sanitize_name($name) { + //allowed a-z, A-Z, 0-9, _ + + $name = str_replace(" ","_", $name); + + //var_dump($name); + + $regex = '/[^A-Za-z0-9_]/'; + + $name = preg_replace($regex, "", $name); + + //var_dump($name); + + return $name; + } + + protected function _get_unique_file_name($path, $hint) { + $filename = ""; + + $this->load->helper('file'); + $dir = get_filenames($path); + + if ($hint) { + //$hint = str_replace(" ","_", $hint); + $hint = $this->_url_sanitize_name($hint); + $h = $hint . ".jpg"; + $mid = ""; + + if ($dir) { + $i = 0; + while (true) { + $ffound = false; + foreach ($dir as $d) { + if ($d == $h) { + $ffound = true; + break; + } + } + + if ($ffound) { + $mid = "_" . $i; + $h = $hint . $mid . ".jpg"; + } else { + return $hint . $mid; + } + + $i++; + } + } else { + return $hint; + } + } else { + if ($dir) { + $max = 0; + foreach ($dir as $d) { + $n = explode(".", $d); + if ($n[0]) { + $name = $n[0]; + + if (is_numeric($name)) { + $num = intval($name); + + if ($num > $max) { + $max = $num; + } + } + } + } + + $max++; + return $max; + } else { + return "1"; + } + } + + return $filename; + } +} diff --git a/ci_scms/application/core/V_Model.php b/ci_scms/application/core/V_Model.php new file mode 100644 index 0000000..20ada0f --- /dev/null +++ b/ci_scms/application/core/V_Model.php @@ -0,0 +1,51 @@ +escape($text); + $text = $this->convert_le_to_br($text); + $text = $this->convert_bb_to_html($text); + + return $text; + } + + public function escape($text) { + $text = strip_tags($text); + $text = htmlentities($text, ENT_COMPAT | ENT_HTML5, "UTF-8", true); + $test = htmlspecialchars($text, ENT_COMPAT | ENT_HTML5, "UTF-8", true); + + return $text; + } + + public function convert_le_to_br($text) { + $text = nl2br($text, false); + return $text; + } + + public function convert_bb_to_html($text) { + return $text; + } + + protected function _url_sanitize_name($name) { + //allowed a-z, A-Z, 0-9, _ + + $name = str_replace(" ","_", $name); + + //var_dump($name); + + $regex = '/[^A-Za-z0-9_]/'; + + $name = preg_replace($regex, "", $name); + + //var_dump($name); + + return $name; + } +} \ No newline at end of file diff --git a/ci_scms/application/core/index.html b/ci_scms/application/core/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/ci_scms/application/core/index.html @@ -0,0 +1,11 @@ + + + +Directory access is forbidden.
+ + + diff --git a/ci_scms/application/index.html b/ci_scms/application/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/ci_scms/application/index.html @@ -0,0 +1,11 @@ + + + +Directory access is forbidden.
+ + + diff --git a/ci_scms/application/models/Common_model.php b/ci_scms/application/models/Common_model.php new file mode 100644 index 0000000..759d9da --- /dev/null +++ b/ci_scms/application/models/Common_model.php @@ -0,0 +1,22 @@ +db->query($sql, array($id)); + + if (!$res->num_rows()) + return false; + + $res = $res->row_array(); + + return $res["link"]; + } +} \ No newline at end of file diff --git a/ci_scms/application/models/admin_model.php b/ci_scms/application/models/admin_model.php new file mode 100644 index 0000000..bdeadb4 --- /dev/null +++ b/ci_scms/application/models/admin_model.php @@ -0,0 +1,221 @@ +db->query($sql); + + $res = $res->result_array(); + + foreach ($res as $r) { + if ($r["name"] == "reg_enabled") { + if ($r["value"] == "true") { + return true; + } else { + return false; + } + } + } + + return false; + } + + function check_user($username, $password) { + $sql = "SELECT password FROM avxg_users WHERE name = ?"; + $res = $this->db->query($sql, array($username)); + + if ($res->num_rows() <= 0) { + return false; + } + + $res = $res->row_array(); + + + if ($res['password'] == $password) + return true; + + return false; + } + + function create_cookie_session_id() { + $sql = "SELECT * FROM session_links"; + $res = $this->db->query($sql); + + if ($res->num_rows() <= 0) + return $this->getcsid(); + + $res->result_array(); + + $sess_id = ""; + $found = false; + while(!found) { + $sess_id = $this->getcsid(); + + $f = false; + foreach ($res as $r) { + if ($r["cookie_session_id"] == $sess_id) { + $f = true; + break; + } + } + + if (!$f) { + $found = true; + } + } + + return $sess_id; + } + + function getcsid() { + return md5("+41)d" . rand() . "ikZtzdDJU"); + } + + function get_or_create_session_id($username) { + $sql = "SELECT * FROM avxg_users WHERE name = ?"; + $res = $this->db->query($sql, array($username)); + + if ($res->num_rows() <= 0) + return -1; + + $res = $res->row_array(); + + $sess_id = ""; + if ($res['session_id'] == "") { + $sql = "SELECT * FROM avxg_users"; + $res2 = $this->db->query($sql); + + $res2 = $res2->result_array(); + + $found = false; + while (!$found) { + $sess_id = md5("77=89$@" + rand() + "99)(!4%)"); + + $f = false; + foreach ($res2 as $u) { + if ($u["session_id"] == $sess_id) { + $f = true; + break; + } + } + + if (!$f) { + $found = true; + } + + $sql = "UPDATE avxg_users SET session_id = ? WHERE name = ?"; + $this->db->query($sql, array($sess_id, $username)); + } + } else { + $sess_id = $res['session_id']; + } + + return $sess_id; + } + + function register_session($sessionid, $cookie_session_id) { + $sql = "INSERT INTO session_links VALUES(default, ?, ?)"; + $this->db->query($sql, array($sessionid, $cookie_session_id)); + + return true; + } + + function login_user($username, $sessionid) { + + } + + function register_user($username, $password, $email) { + $sql = "SELECT * FROM avxg_users"; + $res = $this->db->query($sql); + $res = $res->result_array(); + + $nametaken = false; + $emailtaken = false; + foreach ($res as $r) { + if ($r["name"] == $username) { + $nametaken = true; + } + + if ($r["email"] == $email) { + $emailtaken = true; + } + } + + //TODO tell error? + + if ($emailtaken || $nametaken) + return; + + $sql = "INSERT INTO avxg_users VALUES(default, ?, ?, ?, NULL, NULL, NULL)"; + + $this->db->query($sql, array($username, $password, $email)); + + //turn off registration + $sql = "UPDATE settings SET value = 'false' WHERE name LIKE 'reg_enabled'"; + $this->db->query($sql); + } + + function is_admin($sid) { + $sql = "SELECT * FROM session_links WHERE cookie_session_id = ?"; + $res = $this->db->query($sql, array($sid)); + + if (!$res->num_rows()) + return false; + + $res = $res->row_array(); + + $sql = "SELECT * FROM avxg_users WHERE session_id = ?"; + $res2 = $this->db->query($sql, array($res["session_id"])); + + if (!$res2->num_rows()) + return false; + + return true; + } + + function get_username_sid($sid) { + $sql = "SELECT * FROM session_links WHERE cookie_session_id = ?"; + $res = $this->db->query($sql, array($sid)); + + if (!$res->num_rows()) + return "E"; + + $res = $res->row_array(); + + $sql = "SELECT * FROM avxg_users WHERE session_id = ?"; + $res2 = $this->db->query($sql, array($res["session_id"])); + + if (!$res2->num_rows()) + return "E2"; + + $res2 = $res2->row_array(); + + return $res2["name"]; + } + + function logout($sid) { + $sql = "DELETE FROM session_links WHERE cookie_session_id = ?"; + $this->db->query($sql, array($sid)); + } + + function logout_all($sid) { + $sql = "SELECT * FROM session_links WHERE cookie_session_id = ?"; + $res = $this->db->query($sql, array($sid)); + + if (!$res->num_rows()) + return; + + $res = $res->row_array(); + + $sql = "DELETE FROM session_links WHERE session_id = ?"; + $this->db->query($sql, array($res["session_id"])); + } +} \ No newline at end of file diff --git a/ci_scms/application/models/content_model.php b/ci_scms/application/models/content_model.php new file mode 100644 index 0000000..2ef8a34 --- /dev/null +++ b/ci_scms/application/models/content_model.php @@ -0,0 +1,355 @@ + "TEXT" + ); + + function __construct() + { + parent::__construct(); + } + + function get_page_contents($pageid) { + $sql = "SELECT * FROM page_contents WHERE pageid = ? ORDER BY `order` ASC"; + $res = $this->db->query($sql, array($pageid)); + return $res->result_array(); + } + + function get_content_text($id) { + $sql = "SELECT * FROM content_text WHERE id = ?"; + $res = $this->db->query($sql, array($id)); + + + if (!$res->num_rows()) + return false; + + return $res->row_array(); + } + + function get_content_gallery($id) { + $sql = "SELECT * FROM content_gallery WHERE id = ?"; + $res = $this->db->query($sql, array($id)); + + + if (!$res->num_rows()) + return false; + + return $res->row_array(); + } + + function get_gallery_data($id) { + $sql = "SELECT * FROM gallery_data WHERE gallery_id = ?"; + $res = $this->db->query($sql, array($id)); + + + if (!$res->num_rows()) + return false; + + return $res->result_array(); + } + + function get_content_multi_gallery($id) { + $sql = "SELECT * FROM content_multi_gallery WHERE id = ?"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return false; + + return $res->row_array(); + } + + function get_content_multi_gallery_folders($id) { + $sql = "SELECT * FROM multi_gallery_folders WHERE galleryid = ?"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return false; + + return $res->result_array(); + } + + function get_content_text_noformat($id) { + $sql = "SELECT * FROM content_text WHERE id = ?"; + $res = $this->db->query($sql, array($id)); + + + //if ($res->num_rows() > 0) + //$res = $res->row_array(); + + return $res->row_array(); + } + + function add_page_text($pageid, $message) { + $sql = "SELECT * FROM page_contents WHERE pageid = ? ORDER BY `order` ASC"; + $res = $this->db->query($sql, array($pageid)); + + $nextid = 1; + + if ($res->num_rows()) { + $res = $res->result_array(); + + foreach($res as $e) { + if ($e["order"] > $nextid) { + $nextid = $e["order"]; + } + } + + $nextid++; + } + + $m = $message; + $messagehtmld = $this->convert_string_all($m); + + $sql = "INSERT INTO content_text VALUES(DEFAULT, ?, ?)"; + $this->db->query($sql, array($messagehtmld, $message)); + + $sql = "SELECT MAX(id) AS id FROM content_text"; + $res = $this->db->query($sql); + + if ($res->num_rows()) { + $res = $res->row_array(); + + $sql = "INSERT INTO page_contents VALUES(DEFAULT, ?, ?, 1, ?)"; + $this->db->query($sql, array($pageid, $nextid, $res["id"])); + } + } + + function edit_page_text($textid, $message) { + $m = $message; + $messagehtmld = $this->convert_string_all($m); + + $sql = "UPDATE content_text SET `text` = ?,`text_noformat` = ? WHERE id = ?"; + $this->db->query($sql, array($messagehtmld, $message, $textid)); + } + + function get_content_types() { + return $content_types; + } + + function content_down($pageid, $id) { + $sql = "SELECT * from page_contents WHERE pageid = ?"; + $res = $this->db->query($sql, array($pageid)); + + if (!$res->num_rows()) + return; + + $res = $res->result_array(); + + $selected; + foreach ($res as $r) { + if ($r["id"] == $id) { + $selected = $r; + break; + } + } + + if (!$selected) + return; + + $lower; + foreach ($res as $r) { + if ($r["order"] == $selected["order"] + 1) { + $lower = $r; + break; + } + } + + if (!$lower) + return; + + $sql = "UPDATE page_contents SET `order` = ? WHERE id = ?"; + $this->db->query($sql, array($lower["order"], $selected["id"])); + $this->db->query($sql, array($selected["order"], $lower["id"])); + } + + function content_up($pageid, $id) { + $sql = "SELECT * from page_contents WHERE pageid = ?"; + $res = $this->db->query($sql, array($pageid)); + + if (!$res->num_rows()) + return; + + $res = $res->result_array(); + + $selected; + foreach ($res as $r) { + if ($r["id"] == $id) { + $selected = $r; + break; + } + } + + if (!$selected) + return; + + $higher; + foreach ($res as $r) { + if ($r["order"] == $selected["order"] - 1) { + $higher = $r; + break; + } + } + + if (!$higher) + return; + + $sql = "UPDATE page_contents SET `order` = ? WHERE id = ?"; + $this->db->query($sql, array($higher["order"], $selected["id"])); + $this->db->query($sql, array($selected["order"], $higher["id"])); + } + + function content_delete($pageid, $id) { + $sql = "SELECT * FROM page_contents WHERE id = ?"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return; + + $res = $res->row_array(); + + $sql = "DELETE FROM page_contents WHERE id = ?"; + $this->db->query($sql, array($id)); + + $sql = "SELECT * FROM page_contents WHERE pageid = ?"; + $ares = $this->db->query($sql, array($id)); + + if (!$ares->num_rows()) + return; + + $ares = $ares->result_array(); + + //TODO make a concatenated query + foreach ($ares as $r) { + if ($r["order"] > $res["order"]) { + $sql = "UPDATE page_contents SET `order` = ? WHERE id = ?"; + $this->db->query($sql, array($r["order"] - 1, $r["id"])); + } + } + + switch ($res["content_type"]) { + case 1: //text + $sql = "DELETE FROM content_text WHERE id = ?"; + $this->db->query($sql, array($res["content_id"])); + break; + } + } + + function add_gallery($pageid, $name, $description) { + $link = ""; + + if ($name) { + $link = _url_sanitize_name($name); + + $sql = "SELECT * FROM content_gallery WHERE link LIKE ?"; + $res = $this->db->query($sql, array($link)); + + if ($res->num_rows()) + $link = ""; + } + + $sql = "INSERT INTO content_gallery VALUES(default, ?, ?, ?, default)"; + $this->db->query($sql, array($name, $link, $description)); + + $sql = "SELECT MAX(id) AS id FROM content_gallery"; + $res = $this->db->query($sql); + $res = $res->row_array(); + + $id = $res["id"]; + + if (!$name) { + $sql = "UPDATE content_gallery SET name = ? WHERE id = ?"; + $this->db->query($sql, array($id, $id)); + } + + if (!$link) { + $sql = "UPDATE content_gallery SET link = ? WHERE id = ?"; + $this->db->query($sql, array($id, $id)); + } + + $order = 1; + + $sql = "SELECT MAX(`order`) AS `order` FROM page_contents WHERE pageid = ?"; + $res = $this->db->query($sql, array($pageid)); + + if ($res->num_rows()) { + $res = $res->row_array(); + $order = $res["order"]; + $order++; + } + + $sql = "INSERT INTO page_contents VALUES(default, ?, ?, 3, ?)"; + $this->db->query($sql, array($pageid, $order, $id)); + } + + function add_gallery_image($galleryid, $name, $description, $img, $thumb, $orig_img) { + $link = ""; + + if ($name) { + $link = $this->_url_sanitize_name($name); + + $sql = "SELECT * FROM gallery_data WHERE gallery_id = ? AND link LIKE ?"; + $res = $this->db->query($sql, array($galleryid, $link)); + + if ($res->num_rows()) + $link = ""; + } + + $sql = "INSERT INTO gallery_data VALUES(default, ?, ?, ?, ?, ?, ?, ?)"; + $this->db->query($sql, array($galleryid, $name, $link, $description, $img, $thumb, $orig_img)); + + if (!$link) { + $sql = "UPDATE gallery_data SET link = id ORDER BY id DESC LIMIT 1"; + $this->db->query($sql); + } + } + + function add_multi_gallery($pageid, $name, $description) { + $link = ""; + + if ($name) { + $link = $this->_url_sanitize_name($name); + + $sql = "SELECT * FROM content_multi_gallery WHERE id = ? AND link LIKE ?"; + $res = $this->db->query($sql, array($pageid, $link)); + + if ($res->num_rows()) + $link = ""; + } + + $sql = "INSERT INTO content_multi_gallery VALUES(default, ?, ?, ?, default)"; + $this->db->query($sql, array($name, $link, $description)); + + $sql = "SELECT MAX(id) AS id FROM content_multi_gallery"; + $res = $this->db->query($sql); + $res = $res->row_array(); + + $id = $res["id"]; + + if (!$name) { + $sql = "UPDATE content_multi_gallery SET name = ? WHERE id = ?"; + $this->db->query($sql, array($id, $id)); + } + + if (!$link) { + $sql = "UPDATE content_multi_gallery SET link = ? WHERE id = ?"; + $this->db->query($sql, array($id, $id)); + } + + $order = 1; + + $sql = "SELECT MAX(`order`) AS `order` FROM page_contents WHERE pageid = ?"; + $res = $this->db->query($sql, array($pageid)); + + if ($res->num_rows()) { + $res = $res->row_array(); + $order = $res["order"]; + $order++; + } + + $sql = "INSERT INTO page_contents VALUES(default, ?, ?, 4, ?)"; + $this->db->query($sql, array($pageid, $order, $id)); + } +} \ No newline at end of file diff --git a/ci_scms/application/models/gallery_model.php b/ci_scms/application/models/gallery_model.php new file mode 100644 index 0000000..d6c682b --- /dev/null +++ b/ci_scms/application/models/gallery_model.php @@ -0,0 +1,149 @@ +db->query($sql, array($galleryname)); + + if ($res->num_rows()) + return $res->row_array(); + + $sql = "SELECT * FROM content_gallery LIMIT 1"; + $res = $this->db->query($sql); + + if ($res->num_rows()) + return $res->row_array(); + } + + function get_gallery_data($galleryid) { + $sql = "SELECT * FROM gallery_data WHERE gallery_id = ?"; + $res = $this->db->query($sql, array($galleryid)); + + if ($res->num_rows()) + return $res->result_array(); + + return null; + } + + function get_gallery_image_data($galleryid, $imagename) { + + } + + function get_first_gallery_name() { + + } + + function get_fake_page_and_id_from_gallery_name() { + //let's just return false for now + return false; + + /* + $sql = "SELECT * FROM content_gallery LIMIT 1"; + $res = $this->db->query($sql); + + $res = $res->row_array(); + + $id = $res["id"]; + + $sql = "SELECT * FROM page_contents WHERE content_id = ? AND content_type = 3"; + $res = $this->db->query($sql, array($id)); + + $res = $res->row_array(); + $pageid = $res["pageid"]; + + $sql = "SELECT * FROM menu WHERE id = ?"; + $res = $this->db->query($sql, array($pageid)); + + $res = $res->row_array(); + $link = $res["link"]; + + $d["page"] = $link; + $d["pageid"] = $pageid; + + return $d;*/ + } + + function get_page_and_id_from_gallery_link($galleryname) { + $sql = "SELECT * FROM content_gallery WHERE link = ?"; + $res = $this->db->query($sql, array($galleryname)); + + if (!$res->num_rows()) + return $this->get_fake_page_and_id_from_gallery_name(); + + $res = $res->row_array(); + + $id = $res["id"]; + + $sql = "SELECT * FROM page_contents WHERE content_id = ? AND content_type = 3"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return $this->get_fake_page_and_id_from_gallery_name(); + + $res = $res->row_array(); + + $pageid = $res["pageid"]; + + $sql = "SELECT * FROM menu WHERE id = ?"; + $res = $this->db->query($sql, array($pageid)); + + if (!$res->num_rows()) + return $this->get_fake_page_and_id_from_gallery_name(); + + $res = $res->row_array(); + $link = $res["link"]; + + + $d["page"] = $link; + $d["pageid"] = $pageid; + + return $d; + } + + function get_gallery_name($id) { + $sql = "SELECT * FROM content_gallery WHERE id = ?"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return $this->get_first_gallery_name(); + + $res = $res->row_array(); + + return $res["name"]; + } + + function get_gallery_link($id) { + $sql = "SELECT * FROM content_gallery WHERE id = ?"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return $this->get_first_gallery_name(); + + $res = $res->row_array(); + + return $res["link"]; + } + + function del_gallery_image_from_db($id) { + $id = intval($id); + $sql = "SELECT * FROM gallery_data WHERE id = ?"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return false; + + $res = $res->row_array(); + + $sql = "DELETE FROM gallery_data WHERE id = ?"; + $this->db->query($sql, array($id)); + + return $res; + } +} \ No newline at end of file diff --git a/ci_scms/application/models/index.html b/ci_scms/application/models/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/ci_scms/application/models/index.html @@ -0,0 +1,11 @@ + + + +Directory access is forbidden.
+ + + diff --git a/ci_scms/application/models/menu_model.php b/ci_scms/application/models/menu_model.php new file mode 100644 index 0000000..7b9e4cb --- /dev/null +++ b/ci_scms/application/models/menu_model.php @@ -0,0 +1,57 @@ +db->query($sql); + + if (!$res->num_rows()) + return false; + + $res = $res->result_array(); + + foreach ($res as $m) { + if ($m["link"] == $page) { + return true; + } + } + + return false; + } + + function getFirstMenuItem() { + $sql = "SELECT * FROM menu WHERE id = 1"; + + $q = $this->db->query($sql); + + return $q->row_array(); + } + + function getBaseMenuData() { + $sql = "SELECT * FROM menu ORDER BY menu.order ASC"; + + $q = $this->db->query($sql); + + return $q->result_array(); + } + + function getPageId($page) { + $sql = "SELECT * FROM menu WHERE name = ?"; + + $q = $this->db->query($sql, array($page)); + + if ($q->num_rows()) + $q = $q->row_array(); + else + return -1; + + return $q["id"]; + } +} \ No newline at end of file diff --git a/ci_scms/application/models/multi_gallery_model.php b/ci_scms/application/models/multi_gallery_model.php new file mode 100644 index 0000000..eeac6ed --- /dev/null +++ b/ci_scms/application/models/multi_gallery_model.php @@ -0,0 +1,260 @@ +_url_sanitize_name($name); + + $sql = "SELECT * FROM multi_gallery_folders WHERE galleryid = ? AND link LIKE ?"; + $res = $this->db->query($sql, array($galleryid, $link)); + + if ($res->num_rows()) + $link = ""; + } + + $sql = "INSERT INTO multi_gallery_folders VALUES(default, ?, ?, ?, ?, ?, ?, default)"; + $this->db->query($sql, array($galleryid, $name, $link, $description, $filename, 0)); + + if (!$link) { + $sql = "UPDATE multi_gallery_folders SET link = id ORDER BY id DESC LIMIT 1"; + $this->db->query($sql); + } + } + + function get_content_multi_gallery($id) { + $sql = "SELECT * FROM content_multi_gallery WHERE id = ?"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return false; + + return $res->row_array(); + } + + function get_content_multi_gallery_folders($id) { + $sql = "SELECT * FROM multi_gallery_folders WHERE galleryid = ?"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return false; + + return $res->result_array(); + } + + function get_multi_gallery_folder($gallery, $folder) { + //is folder is a number, it's the id, no need for $gallery + if (is_numeric($folder)) { + $sql = "SELECT * FROM multi_gallery_folders WHERE id = ?"; + $res = $this->db->query($sql, array($folder)); + + if (!$res->num_rows()) + return false; + + return $res->row_array(); + } else { + $sql = ""; + $res = null; + + if (is_numeric($gallery)) { + $sql = "SELECT * FROM multi_gallery_folders WHERE link LIKE ? AND galleryid = ?"; + $res = $this->db->query($sql, array($folder, $gallery)); + } else { + $sql = "SELECT * FROM content_multi_gallery WHERE link LIKE ?"; + $res = $this->db->query($sql, array($gallery)); + + if (!$res->num_rows()) + return false; + + $res = $res->row_array(); + + $sql = "SELECT * FROM multi_gallery_folders WHERE link LIKE ? AND galleryid = ?"; + $res = $this->db->query($sql, array($folder, $res["id"])); + } + + if (!$res->num_rows()) + return false; + + return $res->row_array(); + } + } + + function get_multi_gallery_folder_images($folderid) { + $sql = "SELECT * FROM multi_gallery_data WHERE folderid = ?"; + $res = $this->db->query($sql, array($folderid)); + + if (!$res->num_rows()) + return false; + + return $res->result_array(); + } + + function add_gallery_image($folderid, $name, $description, $thumb, $mid, $big, $orig) { + $link = ""; + + if ($name) { + $link = $this->_url_sanitize_name($name); + + $sql = "SELECT * FROM multi_gallery_data WHERE folderid = ? AND link LIKE ?"; + $res = $this->db->query($sql, array($folderid, $name)); + + if ($res->num_rows()) + $link = ""; + } + + $sql = "INSERT INTO multi_gallery_data VALUES(default, ?, ?, ?, ?, ?, ?, ?, ?)"; + $this->db->query($sql, array($folderid, $name, $link, $description, $thumb, $mid, $big, $orig)); + + if (!$name) { + $sql = "UPDATE multi_gallery_data SET name = id ORDER BY id DESC LIMIT 1"; + $this->db->query($sql); + } + + if (!$link) { + $sql = "UPDATE multi_gallery_data SET link = id ORDER BY id DESC LIMIT 1"; + $this->db->query($sql); + } + } + + function get_gallery_name($id) { + $sql = "SELECT * FROM content_multi_gallery WHERE id = ?"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return ""; + + $res = $res->row_array(); + + return $res["link"]; + } + + function get_folder_name($id) { + $sql = "SELECT * FROM multi_gallery_folders WHERE id = ?"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return ""; + + $res = $res->row_array(); + + return $res["link"]; + } + + function del_image_from_db($imageid) { + $imageid = intval($imageid); + $sql = "SELECT * FROM multi_gallery_data WHERE id = ?"; + $res = $this->db->query($sql, array($imageid)); + + if (!$res->num_rows()) + return false; + + $res = $res->row_array(); + + $sql = "DELETE FROM multi_gallery_data WHERE id = ?"; + $this->db->query($sql, array($imageid)); + + return $res; + } + + //TODO are any of this needed?: + function get_fake_page_and_id_from_gallery_name() { + //let's just return false for now + return false; + + /* + $sql = "SELECT * FROM content_gallery LIMIT 1"; + $res = $this->db->query($sql); + + $res = $res->row_array(); + + $id = $res["id"]; + + $sql = "SELECT * FROM page_contents WHERE content_id = ? AND content_type = 3"; + $res = $this->db->query($sql, array($id)); + + $res = $res->row_array(); + $pageid = $res["pageid"]; + + $sql = "SELECT * FROM menu WHERE id = ?"; + $res = $this->db->query($sql, array($pageid)); + + $res = $res->row_array(); + $link = $res["link"]; + + $d["page"] = $link; + $d["pageid"] = $pageid; + + return $d;*/ + } + + function get_page_and_id_from_gallery_name($galleryname) { + $id = 0; + if (!is_numeric($galleryname)) { + $sql = "SELECT * FROM content_multi_gallery WHERE link = ?"; + $res = $this->db->query($sql, array($galleryname)); + + if (!$res->num_rows()) + return $this->get_fake_page_and_id_from_gallery_name(); + + $res = $res->row_array(); + + $id = $res["id"]; + } else { + $id = $galleryname; + } + + $sql = "SELECT * FROM page_contents WHERE content_id = ? AND content_type = 4"; + $res = $this->db->query($sql, array($id)); + + if (!$res->num_rows()) + return $this->get_fake_page_and_id_from_gallery_name(); + + $res = $res->row_array(); + + $pageid = $res["pageid"]; + + $sql = "SELECT * FROM menu WHERE id = ?"; + $res = $this->db->query($sql, array($pageid)); + + if (!$res->num_rows()) + return $this->get_fake_page_and_id_from_gallery_name(); + + $res = $res->row_array(); + $link = $res["link"]; + + $d["page"] = $link; + $d["pageid"] = $pageid; + + return $d; + } + + function get_page_name_from_gallery_id($galleryid) { + $sql = "SELECT * FROM page_contents WHERE content_id = ? AND content_type = 4"; + $res = $this->db->query($sql, array($galleryid)); + + if (!$res->num_rows()) + return ""; + + $res = $res->row_array(); + + $pageid = $res["pageid"]; + + $sql = "SELECT * FROM menu WHERE id = ?"; + $res = $this->db->query($sql, array($pageid)); + + if (!$res->num_rows()) + return ""; + + $res = $res->row_array(); + + return $res["link"]; + } +} \ No newline at end of file diff --git a/ci_scms/application/views/admin/add_gallery.php b/ci_scms/application/views/admin/add_gallery.php new file mode 100644 index 0000000..1f80a53 --- /dev/null +++ b/ci_scms/application/views/admin/add_gallery.php @@ -0,0 +1,52 @@ + + + + + + "> + +