/**
  * Delete selected image
  */
 public static function deleteImageAction($mysqli)
 {
     include_once getcwd() . '/scripts/admin-helpers/admin-actions/elrh_image_manipulator.php';
     return ELRHImageManipulator::deleteImageAction($mysqli);
 }
 /**
  * Add new / Edit selected image
  */
 public static function editImageAction($mysqli)
 {
     // check for image name - MANDATORY atribute
     if (!empty($_POST["name"])) {
         // get posted image ID
         if (!empty($_POST["iid"])) {
             // edit existing image
             // check if exists
             include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
             $result = ELRHDataExtractor::retrieveRow($mysqli, "SELECT id FROM elrh_gallery_images WHERE id='" . mysqli_real_escape_string($mysqli, $_POST["iid"]) . "'");
             if (!empty($result) && $result[0] != "db_error") {
                 // perform edit action - name and description
                 include_once getcwd() . '/scripts/data-helpers/elrh_db_manipulator.php';
                 $query = ELRHDataManipulator::editRecord($mysqli, "UPDATE elrh_gallery_images SET name='" . mysqli_real_escape_string($mysqli, $_POST["name"]) . "', dscr='" . mysqli_real_escape_string($mysqli, $_POST["dscr"]) . "' WHERE id='" . mysqli_real_escape_string($mysqli, $_POST["iid"]) . "'");
                 if ($query) {
                     // image edited
                     return "admin_edit_image_success";
                 } else {
                     // edit query wasn't successful
                     return "admin_edit_image_fail";
                 }
             } else {
                 // wrong image id
                 return "admin_image_wrongid";
             }
         } else {
             // add new image
             // check for image file
             if (!empty($_FILES["img_file"]["name"])) {
                 // check for image file type
                 // only JPG, PNG and GIF allowed
                 $ext = ELRHImageManipulator::getImageExtension($_FILES["img_file"]);
                 if ($ext != "error") {
                     // process image file
                     $time = Time();
                     $dest = getcwd() . "/content/gallery/" . $time . $ext;
                     if (move_uploaded_file($_FILES["img_file"]["tmp_name"], $dest)) {
                         // create thumb
                         $thumb = getcwd() . "/content/gallery/thumbs/" . $time . $ext;
                         ELRHImageManipulator::createThumb($dest, $thumb);
                         // perform DB actions
                         include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
                         include_once getcwd() . '/scripts/data-helpers/elrh_db_manipulator.php';
                         // get ID of currently last image in gallery
                         $prev = ELRHDataExtractor::retrieveRow($mysqli, "SELECT id, ord FROM elrh_gallery_images WHERE gallery=" . mysqli_real_escape_string($mysqli, $_POST["gallery"]) . " AND next='0'");
                         // insert new image
                         $query = ELRHDataManipulator::addRecord($mysqli, "INSERT INTO elrh_gallery_images (author, created, gallery, ord, name, dscr, image, prev, next) VALUES ('" . mysqli_real_escape_string($mysqli, $_SESSION["user"]) . "', Now(), '" . mysqli_real_escape_string($mysqli, $_POST["gallery"]) . "', " . $prev["ord"] . "+1, '" . mysqli_real_escape_string($mysqli, $_POST["name"]) . "', '" . mysqli_real_escape_string($mysqli, $_POST["dscr"]) . "', '" . $time . $ext . "', '" . $prev["id"] . "', '0')");
                         if ($query) {
                             // get newly inserted ID
                             $_POST["iid"] = $mysqli->insert_id;
                             // update previously last image in gallery
                             $query = ELRHDataManipulator::editRecord($mysqli, "UPDATE elrh_gallery_images SET next='" . $_POST["iid"] . "' WHERE id='" . $prev["id"] . "'");
                         }
                         // return action result
                         if ($query) {
                             // image added
                             return "admin_add_image_success";
                         } else {
                             // edit query wasn't successful
                             return "admin_add_image_fail";
                         }
                     } else {
                         // failed to upload image
                         return "admin_add_image_uploadfail";
                     }
                 } else {
                     // wrong image type given
                     return "admin_add_image_wrongfile";
                 }
             } else {
                 // no image file given
                 return "admin_add_image_nofile";
             }
         }
     } else {
         // no name given
         return "admin_edit_image_noname";
     }
 }