/**
  * Delete selected gallery
  * Gallery must be empty, with no child galleries and no related articles
  */
 public static function deleteGalleryAction($mysqli)
 {
     // get posted gallery ID
     if (!empty($_POST["gallery"])) {
         // check for given gallery in DB
         include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
         $result = ELRHDataExtractor::retrieveRow($mysqli, "SELECT g.id, (SELECT count(*) FROM elrh_gallery_images i WHERE i.gallery = g.id) AS images, (SELECT count(*) FROM elrh_gallery_galleries c WHERE c.parent = g.id) AS children, (SELECT count(*) FROM elrh_articles a WHERE a.gallery = g.id) AS articles FROM elrh_gallery_galleries g WHERE g.id='" . mysqli_real_escape_string($mysqli, $_POST["gallery"]) . "'");
         if (!empty($result) && $result[0] != "db_error") {
             // gallery details loaded
             if ($result["images"] == 0 && $result["children"] == 0 && $result["articles"] == 0) {
                 // perform delete
                 include_once getcwd() . '/scripts/data-helpers/elrh_db_manipulator.php';
                 $query = ELRHDataManipulator::deleteRecord($mysqli, "DELETE FROM elrh_gallery_galleries WHERE id='" . mysqli_real_escape_string($mysqli, $_POST["gallery"]) . "'");
                 if ($query) {
                     // gallery edited
                     return "admin_delete_gallery_success";
                 } else {
                     // delete query wasn't successful
                     return "admin_delete_gallery_fail";
                 }
             } else {
                 // cannot delete
                 return "admin_delete_gallery_restricted";
             }
         } else {
             // wrong gallery id
             return "admin_gallery_wrongid";
         }
     } else {
         // input not set correctly
         return "admin_gallery_noid";
     }
 }
Ejemplo n.º 2
0
 /**
  * Validates login
  */
 public static function loginAction($mysqli)
 {
     // get login data
     if (!empty($_POST["name"]) && !empty($_POST["pass"])) {
         // check for given user's password in db
         include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
         $user = ELRHDataExtractor::retrieveRow($mysqli, "SELECT u_name, u_displayed_name, u_pass FROM elrh_users WHERE u_name='" . mysqli_real_escape_string($mysqli, $_POST["name"]) . "'");
         if (!empty($user) && $user[0] != "db_error") {
             // check password match
             $hashpass = hash('sha512', $_POST["pass"]);
             if ($hashpass == $user["u_pass"]) {
                 // set admin sessions
                 $_SESSION["user"] = $user["u_name"];
                 $_SESSION["user_name"] = $user["u_displayed_name"];
                 //
                 return "admin_login_success";
             } else {
                 // wrong pass
                 return "admin_login_wrong";
             }
         } else {
             // wrong user
             return "admin_login_wrong";
         }
     } else {
         // input not set correctly
         return "admin_login_invalid";
     }
 }
Ejemplo n.º 3
0
 public static function prepareData($item, $mysqli)
 {
     include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
     // determine data according the item request
     if (empty($item)) {
         // if no item selected = show list of all articles
         $data["entries"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT a.id AS aid, a.cat, a.posted, a.name AS article_name, a.dscr, g.id AS gid, g.name AS gallery_name, u.u_displayed_name AS author_name FROM elrh_articles a LEFT JOIN elrh_gallery_galleries g ON a.gallery=g.id JOIN elrh_users u ON a.author=u.u_name ORDER BY a.posted DESC");
         // notify content renderer, there will be only list of articles
         $data["single"] = false;
     } else {
         // still have to determine between article-id and admin operations
         if (is_numeric($item)) {
             // notify content renderer, there will be only one article
             $data["single"] = true;
             // try to find particular article
             $data["entry"] = ELRHDataExtractor::retrieveRow($mysqli, "SELECT a.id AS aid, a.author, a.cat, a.posted, a.name AS article_name, a.dscr, a.content, g.id AS gid, g.name AS gallery_name, (SELECT count(*) FROM elrh_gallery_images i WHERE i.gallery=g.id) AS images, u.u_displayed_name AS author_name FROM elrh_articles a LEFT JOIN elrh_gallery_galleries g ON a.gallery=g.id JOIN elrh_users u ON a.author=u.u_name WHERE a.id='" . mysqli_real_escape_string($mysqli, $item) . "'");
             if (!empty($data["entry"])) {
                 // page title adjustment
                 $data["item_title"] = ": " . $data["entry"]["article_name"];
                 // notify content renderer, that article exists
                 $data["exists"] = true;
             } else {
                 // notify content renderer, that article not found
                 $data["exists"] = false;
             }
         } else {
             // TODO admin operations
         }
     }
     // save prepared data for renderer
     return $data;
 }
Ejemplo n.º 4
0
 public static function prepareData($item, $mysqli)
 {
     // get all news
     include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
     $data["news"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT n.date, n.content, u.u_displayed_name AS author FROM elrh_news n JOIN elrh_users u ON n.author=u.u_name ORDER BY date DESC");
     // save prepared data for renderer
     return $data;
 }
Ejemplo n.º 5
0
 public static function prepareData($item, $mysqli)
 {
     // get stored contacts
     include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
     $data["contacts"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT contact, name, link FROM elrh_contacts");
     // save prepared data for renderer
     return $data;
 }
Ejemplo n.º 6
0
 public static function prepareData($item, $mysqli)
 {
     // get relevant interactive map entries
     include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
     $data["interactives"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT name, gallery, coord_x, coord_y, size FROM elrh_map");
     // save prepared data for renderer
     return $data;
 }
Ejemplo n.º 7
0
 public static function prepareData($item, $mysqli)
 {
     // get relevant books
     include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
     // find all categories
     $data["books_cats"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT id, name FROM elrh_books_cat ORDER BY ord");
     // find books for each category
     if (!empty($data["books_cats"])) {
         foreach ($data["books_cats"] as $cat) {
             $data["books"][$cat["name"]] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT name, writer, year, dscr, url, thumb, review, review_ext FROM elrh_books WHERE cat='" . $cat["id"] . "' ORDER BY ord");
         }
     }
     // save prepared data for renderer
     return $data;
 }
Ejemplo n.º 8
0
 /**
  * Get details for selected image
  */
 public static function selectImageAction($mysqli, $iid)
 {
     // get selected gallery
     if (!empty($iid)) {
         // check for given image ID in gallery
         include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
         $result = ELRHDataExtractor::retrieveRow($mysqli, "SELECT id, gallery, ord, name, dscr, image, prev, next FROM elrh_gallery_images WHERE id='" . mysqli_real_escape_string($mysqli, $iid) . "'");
         if (!empty($result) && $result[0] != "db_error") {
             // gallery details loaded
             $result["exists"] = true;
             $result["result"] = "admin_select_image_success";
         } else {
             // wrong gallery id
             $result["exists"] = false;
             $result["result"] = "admin_image_wrongid";
         }
     } else {
         // input not set correctly
         $result["exists"] = false;
         $result["result"] = "admin_image_noid";
     }
     //
     return $result;
 }
Ejemplo n.º 9
0
 /**
  * Move selected image forwards in gallery (ord++)
  */
 public static function moveImageForwardsAction($mysqli, $iid)
 {
     // check given id
     if (!empty($iid)) {
         // check for given image in DB
         include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
         $result = ELRHDataExtractor::retrieveRow($mysqli, "SELECT id, prev, next FROM elrh_gallery_images WHERE id='" . mysqli_real_escape_string($mysqli, $iid) . "'");
         if (!empty($result) && $result[0] != "db_error") {
             // image details loaded
             // check if image isn't last in gallery
             if ($result["next"] > 0) {
                 // 1st - get info for next image
                 $next = ELRHDataExtractor::retrieveRow($mysqli, "SELECT id, next FROM elrh_gallery_images WHERE id='" . $result["next"] . "'");
                 // 2nd - place original image one position "forward"
                 include_once getcwd() . '/scripts/data-helpers/elrh_db_manipulator.php';
                 $query = ELRHDataManipulator::editRecord($mysqli, "UPDATE elrh_gallery_images SET ord=ord+1, prev='" . $result["next"] . "', next='" . $next["next"] . "' WHERE id='" . $result["id"] . "'");
                 // 3rd - place prev image one position "backward"
                 if ($query) {
                     $query = ELRHDataManipulator::editRecord($mysqli, "UPDATE elrh_gallery_images SET ord=ord-1, prev='" . $result["prev"] . "', next='" . $result["id"] . "' WHERE id='" . $result["next"] . "'");
                 }
                 // 3rd - re-link next of next image
                 if ($query) {
                     $query = ELRHDataManipulator::editRecord($mysqli, "UPDATE elrh_gallery_images SET prev='" . $result["id"] . "' WHERE id='" . $next["next"] . "'");
                 }
                 // 4th re-link prev of original image
                 if ($query) {
                     if ($result["prev"] > 0) {
                         $query = ELRHDataManipulator::editRecord($mysqli, "UPDATE elrh_gallery_images SET next='" . $result["next"] . "' WHERE id='" . $result["prev"] . "'");
                     }
                 }
                 // inform about result
                 if ($query) {
                     // gallery edited
                     return "admin_move_forwards_success";
                 } else {
                     // delete query wasn't successful
                     return "admin_move_forwards_fail";
                 }
             } else {
                 // image is last
                 return "admin_image_last";
             }
         } else {
             // wrong image id
             return "admin_image_wrongid";
         }
     } else {
         // input not set correctly
         return "admin_image_noid";
     }
 }
Ejemplo n.º 10
0
 public static function prepareData($item, $mysqli)
 {
     include_once getcwd() . '/scripts/admin-helpers/elrh_admin_resolver.php';
     // login-action
     // must be before "logged-in only" section
     if ($item == "login") {
         // tries to log user in (may success or fail)
         $data["admin_output"] = ELRHAdminResolver::loginAction($mysqli);
     }
     // other options only available for logged-in user
     if (isset($_SESSION["user"])) {
         // split request by "/" (there might be some extra data regarding image IDs
         $request = preg_split('~/~', $item);
         // determine action by request
         // excluding "login" action, that already resolved, and "select", that will be resolved later
         switch ($request[0]) {
             case "login":
             case "select_gallery":
             case "select_image":
                 // just to avoid falling into "invalid_request" branch
                 break;
             case "logout":
                 // pefrom logout for current user
                 $data["admin_output"] = ELRHAdminResolver::logoutAction();
                 break;
             case "edit_gallery":
                 // try to perform DB action (add/edit gallery)
                 $data["admin_output"] = ELRHAdminResolver::editGalleryAction($mysqli);
                 // predend "select gallery" action for loading gallery details later in "SELECT actions" block
                 if (!empty($_POST["gid"])) {
                     $request[0] = "load_gallery";
                     $_POST["item"] = $_POST["gid"];
                 }
                 break;
             case "delete_gallery":
                 // try to perform DB action (delete gallery)
                 $data["admin_output"] = ELRHAdminResolver::deleteGalleryAction($mysqli);
                 break;
             case "edit_image":
                 // try to perform DB action (add/edit image)
                 $data["admin_output"] = ELRHAdminResolver::editImageAction($mysqli);
                 // predend "select image" action for loading image details later in "SELECT actions" block
                 if (!empty($_POST["iid"])) {
                     $request[0] = "load_image";
                     $_POST["item"] = $_POST["iid"];
                 }
                 break;
             case "delete_image":
                 // try to perform DB action (delete image)
                 $data["admin_output"] = ELRHAdminResolver::deleteImageAction($mysqli);
                 // predend "select gallery" action for loading gallery details later in "SELECT actions" block
                 // (ID is set inside deleteImageAction method)
                 $request[0] = "load_gallery";
                 break;
             case "move_image":
                 // try to perform DB action (move image to other gallery)
                 $data["admin_output"] = ELRHAdminResolver::moveImageToGalleryAction($mysqli);
                 // predend "select image" action for loading image details later in "SELECT actions" block
                 if (!empty($_POST["iid"])) {
                     $request[0] = "load_image";
                     $_POST["item"] = $_POST["iid"];
                 }
                 break;
             case "move_forwards":
                 $data["admin_output"] = ELRHAdminResolver::moveImageForwardsAction($mysqli, $request[1]);
                 // predend "select image" action for loading image details later in "SELECT actions" block
                 if (!empty($request[1])) {
                     $request[0] = "load_image";
                     $_POST["item"] = $request[1];
                 }
                 break;
             case "move_backwards":
                 $data["admin_output"] = ELRHAdminResolver::moveImageBackwardsAction($mysqli, $request[1]);
                 // predend "select image" action for loading image details later in "SELECT actions" block
                 if (!empty($request[1])) {
                     $request[0] = "load_image";
                     $_POST["item"] = $request[1];
                 }
                 break;
             default:
                 if (!empty($item)) {
                     // requested action doesn't exist
                     $data["admin_output"] = "admin_invalid_request";
                 } else {
                     // no action requested
                     // (just some mock data to avoid errors later)
                     $data["null"] = "null";
                 }
         }
         // SELECT actions
         // default - no item selected
         $id = 0;
         // option 1 - ID given in $_GET request
         // option 2 - ID given in $_POST request
         if (!empty($request[1]) && is_numeric($request[1])) {
             $id = $request[1];
         } elseif (!empty($_POST["item"])) {
             $id = $_POST["item"];
         }
         // if there is request - eleaborate it
         if ($id > 0) {
             switch ($request[0]) {
                 case "select_gallery":
                 case "load_gallery":
                     $data["current_gallery"] = ELRHAdminResolver::selectGalleryAction($mysqli, $id);
                     // for initial select, action result shall be displayed
                     if ($request[0] == "select_gallery") {
                         $data["admin_output"] = $data["current_gallery"]["result"];
                     }
                     break;
                 case "select_image":
                 case "load_image":
                     $data["current_image"] = ELRHAdminResolver::selectImageAction($mysqli, $id);
                     // for initial select, action result shall be displayed
                     if ($request[0] == "select_image") {
                         $data["admin_output"] = $data["current_image"]["result"];
                     }
                     // after loading image, try load details for its gallery
                     if ($data["current_image"]["exists"]) {
                         $data["current_gallery"] = ELRHAdminResolver::selectGalleryAction($mysqli, $data["current_image"]["gallery"]);
                     }
                     break;
                     // select_article and select_link not yet implemented
             }
         }
         // SELECT actions
         // get necessary data to be displayed throughout administration
         include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
         // get all existing galleries
         $data["galleries"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT g.id, g.name, (SELECT name FROM elrh_gallery_galleries WHERE id=g.parent) AS parent FROM elrh_gallery_galleries g ORDER BY g.name");
         // if there is selected gallery, pick all images from it
         if (!empty($data["current_gallery"]) && $data["current_gallery"]["exists"]) {
             $data["images"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT id, name FROM elrh_gallery_images WHERE gallery='" . $data["current_gallery"]["id"] . "' ORDER BY ord");
         } else {
             // notify renderer that gallery selection is empty
             $data["current_gallery"]["exists"] = false;
             // some mock data to avoid errors later
             $data["images"] = "null";
         }
         // notify renderer that image selection is empty, if needed
         if (empty($data["current_image"])) {
             $data["current_image"]["exists"] = false;
         }
     } else {
         // not logged in
         // (just some mock data to avoid errors later)
         $data["null"] = "null";
     }
     // save prepared data for renderer
     return $data;
 }
Ejemplo n.º 11
0
 public static function prepareData($item, $mysqli)
 {
     include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
     // determine data according the item request
     if (empty($item)) {
         // notify content renderer, there will be index of galleries
         $data["display"] = "index";
         // try to load galleries
         $data["galleries"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT id, name, dscr, (SELECT count(*) FROM elrh_gallery_images i WHERE i.gallery=g.id) AS images FROM elrh_gallery_galleries g WHERE parent='0' ORDER BY name");
         // for each gallery load further info
         if (!empty($data["galleries"])) {
             foreach ($data["galleries"] as $gallery) {
                 // first 7 images to feature
                 $data[$gallery["name"]]["images"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT id, name, image FROM elrh_gallery_images WHERE gallery='" . $gallery["id"] . "' ORDER BY ord LIMIT 7");
                 // related galleries
                 $data[$gallery["name"]]["galleries"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT id, name, (SELECT count(*) FROM elrh_gallery_images i WHERE i.gallery=g.id) AS images FROM elrh_gallery_galleries g WHERE parent='" . $gallery["id"] . "' ORDER BY name");
                 // related articles
                 $data[$gallery["name"]]["articles"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT a.id, a.name, u.u_displayed_name AS author_name FROM elrh_articles a JOIN elrh_users u ON a.author=u.u_name WHERE gallery='" . $gallery["id"] . "' ORDER BY name");
             }
         }
     } else {
         // TODO admin operations
         // still have to determine whether displaying particular gallery or particular image
         // split request by "/"
         $request = preg_split('~/~', $item);
         if ($request[0] == "g") {
             // notify content renderer, there will be detail of particular gallery
             $data["display"] = "gallery";
             // try to load gallery details
             $data["entry"] = ELRHDataExtractor::retrieveRow($mysqli, "SELECT g.id AS gid, g.parent AS pid, g.created, g.name, g.dscr, (SELECT count(*) FROM elrh_gallery_images i WHERE i.gallery=g.id) AS images, u.u_displayed_name AS author_name FROM elrh_gallery_galleries g JOIN elrh_users u ON g.author=u.u_name WHERE g.id='" . mysqli_real_escape_string($mysqli, $request[1]) . "'");
             if (!empty($data["entry"])) {
                 // images to display
                 $data["images"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT id, name, image FROM elrh_gallery_images WHERE gallery='" . $data["entry"]["gid"] . "' ORDER BY ord");
                 // possible parent gallery
                 $data["parent"] = ELRHDataExtractor::retrieveRow($mysqli, "SELECT id, name FROM elrh_gallery_galleries WHERE id='" . $data["entry"]["pid"] . "'");
                 // related galleries
                 $data["galleries"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT id, name, (SELECT count(*) FROM elrh_gallery_images i WHERE i.gallery=g.id) AS images FROM elrh_gallery_galleries g WHERE parent='" . $data["entry"]["gid"] . "' ORDER BY name");
                 // related articles
                 $data["articles"] = ELRHDataExtractor::retrieveArray($mysqli, "SELECT a.id, a.name, u.u_displayed_name AS author_name FROM elrh_articles a JOIN elrh_users u ON a.author=u.u_name WHERE gallery='" . $data["entry"]["gid"] . "' ORDER BY name");
                 // page title adjustment
                 $data["item_title"] = ": " . $data["entry"]["name"];
                 // notify content renderer, that gallery exists
                 $data["exists"] = true;
             } else {
                 // notify content renderer, that gallery not found
                 $data["exists"] = false;
             }
         } else {
             if ($request[0] == "i") {
                 // notify content renderer, there will be detail of particular gallery
                 $data["display"] = "image";
                 // try to load image details
                 $data["entry"] = ELRHDataExtractor::retrieveRow($mysqli, "SELECT i.id AS iid, i.gallery AS gid, i.created, i.name, i.dscr, i.image, i.prev, i.next, u.u_displayed_name AS author_name FROM elrh_gallery_images i JOIN elrh_users u ON i.author=u.u_name WHERE i.id='" . mysqli_real_escape_string($mysqli, $request[1]) . "'");
                 if (!empty($data["entry"])) {
                     // parent gallery info
                     $data["parent"] = ELRHDataExtractor::retrieveRow($mysqli, "SELECT id, name FROM elrh_gallery_galleries WHERE id='" . $data["entry"]["gid"] . "'");
                     // page title adjustment
                     $data["item_title"] = ": " . $data["entry"]["name"];
                     // notify content renderer, that gallery exists
                     $data["exists"] = true;
                 } else {
                     // notify content renderer, that gallery not found
                     $data["exists"] = false;
                 }
             } else {
                 // notify content renderer, there is an error
                 $data["display"] = "error";
             }
         }
     }
     // save prepared data for renderer
     return $data;
 }
Ejemplo n.º 12
0
 public function prepareData()
 {
     // variable initial set (to avoid possible warnings later)
     $this->page_data["texts"]["null"] = "";
     $this->page_data["item_title"] = "";
     // TODO allow other languages
     $this->page_data["lang"] = "cz";
     // set mySQL
     $this->getMySQLConnection();
     // variable info that depends on displayed page
     // mysql must work and page must exist
     if ($this->page_data["mysql"] == true) {
         if ($this->page_request != "error") {
             // get additional data to be displayed
             include_once getcwd() . '/pages/page-data/elrh_' . $this->page_request . '_data.php';
             $this->page_data = array_merge($this->page_data, ELRHPageData::prepareData($this->item_request, $this->mysqli));
             // get language variables for given page
             include_once getcwd() . '/scripts/data-helpers/elrh_text_retriever.php';
             $this->page_data["texts"] = ELRHTextRetriever::getTextsForPage($this->mysqli, $this->page_data["lang"], $this->page_request);
             // for admin requests we need special "output" text variable
             if (!empty($this->page_data["admin_output"])) {
                 $this->page_data["texts"]["admin_output"] = ELRHTextRetriever::getText($this->mysqli, $this->page_data["lang"], $this->page_data["admin_output"]);
             }
         } else {
             // get global site title
             include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
             $this->page_data["title"] = ELRHDataExtractor::retrieveItem($this->mysqli, "SELECT value FROM elrh_settings WHERE var='global_title'", "value");
         }
     }
     // always presented info
     // mysql must work
     if ($this->page_data["mysql"] == true) {
         // global site text values
         include_once getcwd() . '/scripts/data-helpers/elrh_sitedata_retriever.php';
         $this->page_data["texts"] = array_merge($this->page_data["texts"], ELRHSitedataCreator::createSiteTexts($this->mysqli, $this->page_data["lang"]));
         $this->page_data["settings"] = ELRHSitedataCreator::createSiteSettings($this->mysqli);
         // page title
         // concluding from global title and possibly from particular page subtitle or article/gallery/image title
         // global_site_title contains always presented global title - set up along with global texts
         // $this->page_request."_headline" stands for page headline (and therefore subtitle) - set up along with particular page texts
         // item_title may contain item-specific title - set up along with page data
         // for "index" and "error" use simplified title
         if ($this->page_request == "index" || $this->page_request == "error") {
             $this->page_data["title"] = $this->page_data["settings"]["global_title"];
         } else {
             include_once getcwd() . '/scripts/content-helpers/elrh_title_creator.php';
             $this->page_data["title"] = ELRHTitleCreator::createSiteTitle($this->page_data["settings"]["global_title"], $this->page_data["texts"][$this->page_request . "_headline"], $this->page_data["item_title"]);
         }
         // menu
         include_once getcwd() . '/scripts/content-helpers/elrh_menu_creator.php';
         $this->page_data["menu"] = ELRHMenuCreator::createMenuContent($this->page_data["texts"]);
         // bottom navigation
         include_once getcwd() . '/scripts/content-helpers/elrh_navigation_creator.php';
         $this->page_data["nav"] = ELRHNavigationCreator::createNavigationContent($this->page_data["lang"], $this->mysqli);
     } else {
         // set hard-core default values
         $this->page_data["title"] = 'ELRHistory Web - NoDB';
         $this->page_data["menu"]["top"] = '<div id="menu">&nbsp;Not connected</div>';
         $this->page_data["nav"] = '&raquo;&nbsp;<a href="/" title="Index">INDEX</a>';
     }
 }
Ejemplo n.º 13
0
 /**
  * Delete selected image
  */
 public static function deleteImageAction($mysqli)
 {
     // get posted image ID
     if (!empty($_POST["item"])) {
         // check for given image in DB
         include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
         $result = ELRHDataExtractor::retrieveRow($mysqli, "SELECT id, gallery, ord, image, prev, next FROM elrh_gallery_images WHERE id='" . mysqli_real_escape_string($mysqli, $_POST["item"]) . "'");
         if (!empty($result) && $result[0] != "db_error") {
             // image details loaded
             include_once getcwd() . '/scripts/data-helpers/elrh_db_manipulator.php';
             // 1st - perform delete itself
             $query = ELRHDataManipulator::deleteRecord($mysqli, "DELETE FROM elrh_gallery_images WHERE id='" . $result["id"] . "'");
             // 2nd - delete related image files
             if ($query) {
                 unlink(getcwd() . "/content/gallery/" . $result["image"]);
                 unlink(getcwd() . "/content/gallery/thumbs/" . $result["image"]);
             }
             // 3rd - re-link prev and next images in gallery
             if ($query) {
                 if ($result["prev"] > 0) {
                     $query = ELRHDataManipulator::editRecord($mysqli, "UPDATE elrh_gallery_images SET next='" . $result["next"] . "' WHERE id='" . $result["prev"] . "'");
                 }
             }
             if ($query) {
                 if ($result["next"] > 0) {
                     $query = ELRHDataManipulator::editRecord($mysqli, "UPDATE elrh_gallery_images SET prev='" . $result["prev"] . "' WHERE id='" . $result["next"] . "'");
                 }
             }
             // 4th - adjust ord (ord--) for next and all other images
             if ($query) {
                 if ($result["next"] > 0) {
                     $query = ELRHDataManipulator::editRecord($mysqli, "UPDATE elrh_gallery_images SET ord=ord-1 WHERE ord>'" . $result["ord"] . "' AND gallery='" . $result["gallery"] . "'");
                 }
             }
             // h4x for keeping "current_gallery" info
             $_POST["item"] = $result["gallery"];
             // inform about result
             if ($query) {
                 // gallery edited
                 return "admin_delete_image_success";
             } else {
                 // delete query wasn't successful
                 return "admin_delete_image_fail";
             }
         } else {
             // wrong image id
             return "admin_image_wrongid";
         }
     } else {
         // input not set correctly
         return "admin_image_noid";
     }
 }