HOME


Mini Shell 1.0
DIR: /home/islapiiu/sites/madolduwaboatride/
Upload File :
Current File : /home/islapiiu/sites/madolduwaboatride/function.php
<?php

function filename() {

    $today = time();
    $startDate = date('YmdHi', strtotime('3012-03-14 09:06:00'));
    $range = $today - $startDate;
    $rand = rand(0, $range);
    $imgname = $rand . "_" . ($startDate + $rand) . '_' . $today . "_n";
    return $imgname;
}

function no1() {

    $codeRandom = rand(0, 99);

    return $codeRandom;
}

function no2() {
    $codeRandom = rand(0, 99);

    return $codeRandom;
}

function seoUrl($text) {
    //Lower case everything
    $string = strtolower($text);
    //Make alphanumeric (removes all other characters)
    $string2 = preg_replace("/[^a-z0-9_\s-]/", "", $string);
    //Clean up multiple dashes or whitespaces
    $string3 = preg_replace("/[\s-]+/", " ", $string2);
    //Convert whitespaces and underscore to dash
    $string4 = preg_replace("/[\s_]/", "-", $string3);
    return $string4;
}

// image slider //

function addNewSlide($post, $file) {

    $addImgName = filename();

    $dir_dest = '../images/slider/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {

        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 1920;
        $handle->image_y = 750;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $query = "INSERT INTO `slider` (title, image_name)
VALUES ('" . mysql_real_escape_string($_POST['title']) . "' , '" . mysql_real_escape_string($imgName) . "')";

    $result = $db->readQuery($query);

    return $result;
}

function getAllSlides() {

    $query = "SELECT * FROM `slider` ORDER BY sort ASC";

    $db = new DB();

    $result = $db->readQuery($query);

    $array_res = array();

    while ($row = mysql_fetch_array($result)) {
        array_push($array_res, $row);
    }

    return $array_res;
}

function getOneSlide($id) {

    $query = "SELECT * FROM `slider` WHERE `id` = '$id' LIMIT 1";

    $db = new DB();
    $result = $db->readQuery($query);

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateOneSlide($post, $file) {

    $id = $_POST['id'];
    $imageold = $_POST['oldImg'];

    $dir_dest = '../images/slider/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 1920;
        $handle->image_y = 750;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $sql = "UPDATE `slider` SET "
            . "`title` = '" . mysql_real_escape_string($_POST['title']) . "'"
            . "WHERE `id` = '$id' ";

    $result = $db->readQuery($sql);

    return $result;
}

//welcom text //

function getWelcomeNote() {

    $query = "SELECT * FROM `welcome-note` WHERE `id` = '1' LIMIT 1";

    $db = new DB();
    $result = $db->readQuery($query);

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateWelcomeNote($post) {

    $db = new DB();

    $sql = "UPDATE `welcome-note` SET "
            . "`title` = '" . mysql_real_escape_string($_POST['title']) . "',"
            . "`url` = '" . mysql_real_escape_string($_POST['url']) . "',"
            . "`description` = '" . mysql_real_escape_string($_POST['description']) . "'"
            . "WHERE `id` = 1 ";


    $result = $db->readQuery($sql);
    return $result;
}

//gallery //

function addNewImage($post, $file) {

    $addImgName = filename();

    $dir_dest = '../images/gallery/';
    $dir_dest_thumb = '../images/gallery/thumb/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 1280;
        $handle->image_y = 720;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }

        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 480;
        $handle->image_y = 270;

        $handle->Process($dir_dest_thumb);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
        }
    }

    $db = new DB();

    $query = "INSERT INTO `gallery` (caption, image_name)
VALUES ('" . mysql_real_escape_string($_POST['caption']) . "', '" . mysql_real_escape_string($imgName) . "')";

    $result = $db->readQuery($query);

    return $result;
}

function getAllImages() {
    $db = new DB();
    $sql = "SELECT * FROM `gallery` ORDER BY sort ASC";
    $result = $db->readQuery($sql);

    $array_res = array();

    while ($row = mysql_fetch_array($result)) {

        $property = array(
            'id' => $row['id'],
            'caption' => $row['caption'],
            'image_name' => $row['image_name'],
            'sort' => $row['sort'],
        );

        array_push($array_res, $property);
    }
    return $array_res;
}

function getOneImage($id) {

    $query = "SELECT * FROM `gallery` WHERE `id` = '$id' LIMIT 1";

    $db = new DB();
    $result = $db->readQuery($query);

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateOneImage($post, $file) {

    $id = $_POST['id'];
    $imageold = $_POST['oldImg'];
    $dir_dest = '../images/gallery/';
    $dir_dest_thumb = '../images/gallery/thumb/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 1280;
        $handle->image_y = 720;


        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }


        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 480;
        $handle->image_y = 270;

        $handle->Process($dir_dest_thumb);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $sql = "UPDATE `gallery` SET "
            . "`caption` = '" . mysql_real_escape_string($_POST['caption']) . "'"
            . "WHERE `id` = '$id' ";



    $result = $db->readQuery($sql);

    return $result;
}

//about us //

function getAboutUspageContant() {

    $query = "SELECT * FROM `about_us` WHERE `id` = '1' LIMIT 1";

    $db = new DB();
    $result = $db->readQuery($query);

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateAboutUspageContant($post, $file) {

    $dir_dest = '../images/about/';

    $handle = new Upload($file['image']);

    $imgName = null;
    $db = new DB();
    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = 'aboutus.jpg';
        $handle->image_x = 500;
        $handle->image_y = 350;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }


    $sql = "UPDATE `about_us` SET "
            . "`title` = '" . mysql_real_escape_string($_POST['title']) . "',"
            . " `description` = '" . mysql_real_escape_string($_POST['description']) . "',"
            . "`vision` = '" . mysql_real_escape_string($_POST['vision']) . "',"
            . "`mission` = '" . mysql_real_escape_string($_POST['mission']) . "' "
            . "WHERE `id` = 1 ";


    $result = $db->readQuery($sql);
    return $result;
}

//rooms //

function addNewRoom($post, $file) {

    $addImgName = filename();

    $dir_dest = '../images/rooms/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 380;
        $handle->image_y = 230;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $query = "INSERT INTO `rooms` (title, price, sort_description, description, image_name)
VALUES ('" . mysql_real_escape_string($_POST['title']) . "','" . mysql_real_escape_string($_POST['price']) . "', '" . mysql_real_escape_string($_POST['sort_description']) . "', '" . mysql_real_escape_string($_POST['description']) . "', '" . mysql_real_escape_string($imgName) . "')";

    $result = $db->readQuery($query);

    return $result;
}

function getAllRooms() {

    $query = "SELECT * FROM `rooms` ORDER BY sort ASC";

    $db = new DB();

    $result = $db->readQuery($query);

    $array_res = array();

    while ($row = mysql_fetch_array($result)) {
        array_push($array_res, $row);
    }

    return $array_res;
}

function getOneRoom($id) {

    $query = "SELECT * FROM `rooms` WHERE `id` = '$id' LIMIT 1";

    $db = new DB();
    $result = $db->readQuery($query);

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateOneRoom($post, $file) {

    $imageold = $_POST['oldImg'];
    $id = $_POST['id'];

    $dir_dest = '../images/rooms/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 380;
        $handle->image_y = 230;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $sql = "UPDATE `rooms` SET "
            . "`title` = '" . mysql_real_escape_string($_POST['title']) . "',"
            . "`price` = '" . mysql_real_escape_string($_POST['price']) . "',"
            . "`sort_description` = '" . mysql_real_escape_string($_POST['sort_description']) . "',"
            . " `description` = '" . mysql_real_escape_string($_POST['description']) . "' "
            . "WHERE `id` = '$id' ";

    $result = $db->readQuery($sql);

    return $result;
}

function addNewRoomPhoto($post, $file) {

    $addImgName = filename();
    $id = $_POST['id'];

    $dir_dest = '../images/rooms/gallery/';
    $dir_dest_thumb = '../images/rooms/gallery/thumb/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 900;
        $handle->image_y = 500;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }

        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 300;
        $handle->image_y = 175;

        $handle->Process($dir_dest_thumb);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
        }
    }

    $db = new DB();

    $query = "INSERT INTO `rooms_photos` (room_id, caption, image_name)
VALUES ('" . mysql_real_escape_string($id) . "', '" . mysql_real_escape_string($_POST['caption']) . "', '" . mysql_real_escape_string($imgName) . "')";

    $result = $db->readQuery($query);

    return $result;
}

function getAllRoomsPhotos($id) {
    $db = new DB();
    $sql = "SELECT * FROM `rooms_photos` WHERE `room_id` = '$id' ORDER BY sort ASC";
    $result = $db->readQuery($sql);

    $array_res = array();

    while ($row = mysql_fetch_array($result)) {

        $property = array(
            'id' => $row['id'],
            'room_id' => $row['room_id'],
            'caption' => $row['caption'],
            'image_name' => $row['image_name'],
            'sort' => $row['sort'],
        );

        array_push($array_res, $property);
    }
    return $array_res;
}

function getOneRoomPhoto($id) {

    $sql = "SELECT * FROM `rooms_photos` WHERE `id` = '$id'";

    $db = new DB();
    $result = $db->readQuery($sql);

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateOneRoomPhoto($post, $file) {

    $imageold = $_POST['oldImg'];
    $id = $_POST['id'];

    $dir_dest = '../images/rooms/gallery/';
    $dir_dest_thumb = '../images/rooms/gallery/thumb/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 900;
        $handle->image_y = 500;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }

        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 300;
        $handle->image_y = 175;

        $handle->Process($dir_dest_thumb);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $sql = "UPDATE `rooms_photos` SET "
            . "`caption` = '" . mysql_real_escape_string($_POST['caption']) . "'"
            . "WHERE `id` = '$id' ";

    $result = $db->readQuery($sql);

    return $result;
}

//Activities //

function addNewActivitie($post, $file) {

    $addImgName = filename();

    $dir_dest = '../images/excursion/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 360;
        $handle->image_y = 230;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $query = "INSERT INTO `activities` (title, sort_description, description, image_name)
VALUES ('" . mysql_real_escape_string($_POST['title']) . "', '" . mysql_real_escape_string($_POST['sort_description']) . "', '" . mysql_real_escape_string($_POST['description']) . "', '" . mysql_real_escape_string($imgName) . "')";

    $result = $db->readQuery($query);

    return $result;
}

function getAllActivities() {

    $query = "SELECT * FROM `activities` ORDER BY sort ASC";

    $db = new DB();

    $result = $db->readQuery($query);

    $array_res = array();

    while ($row = mysql_fetch_array($result)) {
        array_push($array_res, $row);
    }

    return $array_res;
}

function getOneActivitie($id) {

    $query = "SELECT * FROM `activities` WHERE `id` = '$id' LIMIT 1";

    $db = new DB();
    $result = $db->readQuery($query);

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateOneActivitie($post, $file) {

    $imageold = $_POST['oldImg'];
    $id = $_POST['id'];
    $dir_dest = '../images/excursion/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 360;
        $handle->image_y = 230;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $sql = "UPDATE `activities` SET "
            . "`title` = '" . mysql_real_escape_string($_POST['title']) . "',"
            . "`sort_description` = '" . mysql_real_escape_string($_POST['sort_description']) . "',"
            . " `description` = '" . mysql_real_escape_string($_POST['description']) . "' "
            . "WHERE `id` = '$id' ";

    $result = $db->readQuery($sql);

    return $result;
}

function addNewActivitiePhoto($post, $file) {

    $addImgName = filename();

    $dir_dest = '../images/activities/gallery/';
    $dir_dest_thumb = '../images/activities/gallery/thumb/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 900;
        $handle->image_y = 500;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }

        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 300;
        $handle->image_y = 175;

        $handle->Process($dir_dest_thumb);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
        }
    }

    $db = new DB();

    $query = "INSERT INTO `activities_photos` (activities_id, caption, image_name)
VALUES ('" . mysql_real_escape_string($_POST['id']) . "', '" . mysql_real_escape_string($_POST['caption']) . "', '" . mysql_real_escape_string($imgName) . "')";

    $result = $db->readQuery($query);

    return $result;
}

function getAllActivitiePhotos($id) {

    $query = "SELECT * FROM `activities_photos` WHERE `activities_id` = '$id' ORDER BY sort ASC";

    $db = new DB();

    $result = $db->readQuery($query);

    $array_res = array();

    while ($row = mysql_fetch_array($result)) {
        array_push($array_res, $row);
    }

    return $array_res;
}

function getOneActivitiePhoto($id) {

    $sql = "SELECT * FROM `activities_photos` WHERE `id` = '$id'";

    $db = new DB();
    $result = $db->readQuery($sql);

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateOneActivitiePhoto($post, $file) {

    $imageold = $_POST['oldImg'];
    $id = $_POST['id'];

    $dir_dest = '../images/activities/gallery/';
    $dir_dest_thumb = '../images/activities/gallery/thumb/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 900;
        $handle->image_y = 500;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }

        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 300;
        $handle->image_y = 175;

        $handle->Process($dir_dest_thumb);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $sql = "UPDATE `activities_photos` SET "
            . "`caption` = '" . mysql_real_escape_string($_POST['caption']) . "'"
            . "WHERE `id` = '$id' ";

    $result = $db->readQuery($sql);

    return $result;
}

//album //

function addNewAlbum($post, $file) {

    $addImgName = filename();

    $dir_dest = '../images/album/';
    $dir_dest_thumb = '../images/album/thumb/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 720;
        $handle->image_y = 490;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }

        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 360;
        $handle->image_y = 245;

        $handle->Process($dir_dest_thumb);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
        }
    }

    $db = new DB();

    $query = "INSERT INTO `album` (title, shortDescription, image_name)
VALUES ('" . mysql_real_escape_string($_POST['title']) . "', '" . mysql_real_escape_string($_POST['shortDescription']) . "', '" . mysql_real_escape_string($imgName) . "')";

    $result = $db->readQuery($query);

    return $result;
}

function getAllAlbum() {

    $query = "SELECT * FROM `album` ORDER BY sort ASC";

    $db = new DB();

    $result = $db->readQuery($query);

    $array_res = array();

    while ($row = mysql_fetch_array($result)) {
        array_push($array_res, $row);
    }

    return $array_res;
}

function getOneAlbum($id) {

    $query = "SELECT * FROM `album` WHERE `id` = '$id'";

    $db = new DB();
    $result = $db->readQuery($query);

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateOneAlbum($post, $file) {

    $imageold = $_POST['oldImg'];
    $id = $_POST['id'];
    $dir_dest = '../images/album/';
    $dir_dest_thumb = '../images/album/thumb/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 720;
        $handle->image_y = 490;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }


        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 360;
        $handle->image_y = 245;

        $handle->Process($dir_dest_thumb);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $sql = "UPDATE `album` SET "
            . "`title` = '" . mysql_real_escape_string($_POST['title']) . "',"
            . " `shortDescription` = '" . mysql_real_escape_string($_POST['shortDescription']) . "'"
            . "WHERE `id` = '$id' ";



    $result = $db->readQuery($sql);

    return $result;
}

function addNewAlbumPhoto($post, $file) {

    $id = $_POST['id'];

    $addImgName = filename();

    $caption = $_POST['caption'];

    $dir_dest = '../images/album/gallery/';
    $dir_dest_thumb = '../images/album/gallery/thumb/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 1280;
        $handle->image_y = 720;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }

        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 480;
        $handle->image_y = 270;

        $handle->Process($dir_dest_thumb);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
        }
    }

    $db = new DB();

    $query = "INSERT INTO `album-photos` (album_id, caption, image_name)
VALUES ('" . mysql_real_escape_string($id) . "', '" . mysql_real_escape_string($caption) . "', '" . mysql_real_escape_string($imgName) . "')";

    $result = $db->readQuery($query);

    return $result;
}

function getAllAlbumPhotos($id) {

    $query = "SELECT * FROM `album-photos` WHERE `album_id` = '$id' ORDER BY sort ASC";

    $db = new DB();

    $result = $db->readQuery($query);

    $array_res = array();

    while ($row = mysql_fetch_array($result)) {
        array_push($array_res, $row);
    }

    return $array_res;
}

function getOneAlbumPhoto($id) {

    $sql = "SELECT * FROM `album-photos` WHERE `id` = '$id'";

    $db = new DB();
    $result = $db->readQuery($sql);

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateOneAlbumPhoto($post, $file) {

    $imageold = $_POST['oldImg'];
    $id = $_POST['id'];

    $dir_dest = '../images/album/gallery/';
    $dir_dest_thumb = '../images/album/gallery/thumb/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 1280;
        $handle->image_y = 720;



        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }


        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 480;
        $handle->image_y = 270;

        $handle->Process($dir_dest_thumb);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $sql = "UPDATE `album-photos` SET "
            . "`caption` = '" . mysql_real_escape_string($_POST['caption']) . "'"
            . "WHERE `id` = '$id' ";

    $result = $db->readQuery($sql);

    return $result;
}

function countPhotos($id) {

    $query = "SELECT * FROM `album-photos` WHERE `album_id` = '$id'";
    $db = new DB();
    $result = $db->readQuery($query);
    $num_rows = mysql_num_rows($result);
    return $num_rows;
}

// comments //

function addNewComment($post, $file) {

    $addImgName = filename();

    $dir_dest = '../images/comments/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 100;
        $handle->image_y = 100;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $query = "INSERT INTO `comments` (name, comment, image_name)
VALUES ('" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['comment']) . "', '" . mysql_real_escape_string($imgName) . "')";

    $result = $db->readQuery($query);

    return $result;
}

function getAllComments() {

    $query = "SELECT * FROM `comments` ORDER BY sort ASC";

    $db = new DB();

    $result = $db->readQuery($query);

    $array_res = array();

    while ($row = mysql_fetch_array($result)) {
        array_push($array_res, $row);
    }

    return $array_res;
}

function getOneComment($id) {

    $query = "SELECT * FROM `comments` WHERE `id` = '$id' LIMIT 1";

    $db = new DB();
    $result = $db->readQuery($query);

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateOneComment($post, $file) {

    $id = $_POST['id'];
    $imageold = $_POST['oldImg'];
    $dir_dest = '../images/comments/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_body = TRUE;
        $handle->file_overwrite = TRUE;
        $handle->file_new_name_ext = FALSE;
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $imageold;
        $handle->image_x = 90;
        $handle->image_y = 90;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $sql = "UPDATE `comments` SET "
            . "`name` = '" . mysql_real_escape_string($_POST['name']) . "',"
            . " `comment` = '" . mysql_real_escape_string($_POST['comment']) . "'"
            . "WHERE `id` = '$id' ";



    $result = $db->readQuery($sql);

    return $result;
}

function addNewGuestComment($post, $file) {

    $addImgName = filename();

    $dir_dest = 'images/comments/';

    $handle = new Upload($file['image']);

    $imgName = null;

    if ($handle->uploaded) {
        $handle->image_resize = true;
        $handle->file_new_name_ext = 'jpg';
        $handle->image_ratio_crop = 'C';
        $handle->file_new_name_body = $addImgName;
        $handle->image_x = 100;
        $handle->image_y = 100;

        $handle->Process($dir_dest);

        if ($handle->processed) {
            $info = getimagesize($handle->file_dst_pathname);
            $imgName = $handle->file_dst_name;
        }
    }

    $db = new DB();

    $query = "INSERT INTO `comments` (name, comment, image_name)
VALUES ('" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['comment']) . "', '" . mysql_real_escape_string($imgName) . "')";

    $result = $db->readQuery($query);

    return $result;
}