HOME


Mini Shell 1.0
DIR: /home/islapiiu/sites/villaeffort/
Upload File :
Current File : /home/islapiiu/sites/villaeffort/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 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 = 1500;
        $handle->image_y = 864;

        $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, description, image_name)
VALUES ('" . mysql_real_escape_string($_POST['title']) . "', '" . mysql_real_escape_string($_POST['description']) . "', '" . 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 = 1500;
        $handle->image_y = 864;

        $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']) . "',"
            . "`description` = '" . mysql_real_escape_string($_POST['description']) . "' "
            . "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;

        $image_dst_x = $handle->image_dst_x;
        $image_dst_y = $handle->image_dst_y;
        $newSize = calculateResize(700, $image_dst_x, $image_dst_y);
        $handle->image_x = $newSize[0];
        $handle->image_y = $newSize[1];


        $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 = 270;
        $handle->image_y = 320;

        $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;

        $image_dst_x = $handle->image_dst_x;
        $image_dst_y = $handle->image_dst_y;
        $newSize = calculateResize(700, $image_dst_x, $image_dst_y);
        $handle->image_x = $newSize[0];
        $handle->image_y = $newSize[1];



        $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 = 270;
        $handle->image_y = 320;

        $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 = 'L';
        $handle->file_new_name_body = 'aboutus.jpg';
        $handle->image_x = 500;
        $handle->image_y = 300;

        $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 = 360;
        $handle->image_y = 240;

        $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, priceRO, extraBeds, extraBedPrice, numOfRoom, sort_description, description, image_name)
VALUES ('" . mysql_real_escape_string($_POST['title']) . "', '" .
            mysql_real_escape_string($_POST['price']) . "', '" .
            mysql_real_escape_string($_POST['priceRO']) . "', '" .
            mysql_real_escape_string($_POST['extraBeds']) . "', '" .
            mysql_real_escape_string($_POST['extraBedPrice']) . "', '" .
            mysql_real_escape_string($_POST['numOfRoom']) . "', '" .
            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 = 360;
        $handle->image_y = 240;

        $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']) . "',"
            . "`priceRO` = '" . mysql_real_escape_string($_POST['priceRO']) . "',"
            . "`extraBeds` = '" . mysql_real_escape_string($_POST['extraBeds']) . "',"
            . "`extraBedPrice` = '" . mysql_real_escape_string($_POST['extraBedPrice']) . "',"
            . "`numOfRoom` = '" . mysql_real_escape_string($_POST['numOfRoom']) . "',"
            . "`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;

        $image_dst_x = $handle->image_dst_x;
        $image_dst_y = $handle->image_dst_y;
        $newSize = calculateResize(700, $image_dst_x, $image_dst_y);
        $handle->image_x = $newSize[0];
        $handle->image_y = $newSize[1];

        $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;

        $image_dst_x = $handle->image_dst_x;
        $image_dst_y = $handle->image_dst_y;
        $newSize = calculateResize(700, $image_dst_x, $image_dst_y);
        $handle->image_x = $newSize[0];
        $handle->image_y = $newSize[1];

        $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/activities/';

    $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 = 263;
        $handle->image_y = 308;

        $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/activities/';

    $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 = 263;
        $handle->image_y = 308;

        $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 = 360;
        $handle->image_y = 234;

        $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 = 360;
        $handle->image_y = 234;

        $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;
}

//service //

function addNewService($post, $file) {

    $addImgName = filename();

    $dir_dest = '../images/services/';
    $dir_dest_thumb = '../images/services/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 = 540;
        $handle->image_y = 400;

        $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 = 263;
        $handle->image_y = 308;

        $handle->Process($dir_dest_thumb);

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

    $db = new DB();

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

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

    return $result;
}

function getAllServices() {

    $query = "SELECT * FROM `services` 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 getOneService($id) {

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

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

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateOneService($post, $file) {

    $imageold = $_POST['oldImg'];
    $id = $_POST['id'];
    $dir_dest = '../images/services/';
    $dir_dest_thumb = '../images/services/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 = 540;
        $handle->image_y = 400;

        $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 = 263;
        $handle->image_y = 308;

        $handle->Process($dir_dest_thumb);

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

    $db = new DB();

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



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

    return $result;
}

function addNewServicePhoto($post, $file) {

    $id = $_POST['id'];

    $addImgName = filename();

    $caption = $_POST['caption'];

    $dir_dest = '../images/services/gallery/';
    $dir_dest_thumb = '../images/services/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 = 600;

        $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 = 200;

        $handle->Process($dir_dest_thumb);

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

    $db = new DB();

    $query = "INSERT INTO `services-photos` (service_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 getAllServicePhotos($id) {

    $query = "SELECT * FROM `services-photos` WHERE `service_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 getOneServicePhoto($id) {

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

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

    $row = mysql_fetch_assoc($result);

    return $row;
}

function updateOneServicePhoto($post, $file) {

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

    $dir_dest = '../images/services/gallery/';
    $dir_dest_thumb = '../images/services/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 = 600;



        $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 = 200;

        $handle->Process($dir_dest_thumb);

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

    $db = new DB();

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

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

    return $result;
}

// 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 = 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();

    $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 calculateResize($newHeight, $width, $height) {

    $percent = $newHeight / $height;
    $result1 = $percent * 100;

    $result2 = $width * $result1 / 100;

    return array($result2, $newHeight);
}


function CheckUser($id, $username, $enPw) {

    $sql = "SELECT * FROM `user` WHERE `id` = '$id' AND `user_name`= '$username' AND `password`= '$enPw'";

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

    return mysql_fetch_array($result);
//    if ($result) {
//            return TRUE;
//        } else {
//            return FALSE;
//        }
}

function getAllUserDetails($id) {

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

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

    return mysql_fetch_array($result);
//    if ($result) {
//            return TRUE;
//        } else {
//            return FALSE;
//        }
}

function checkEmail($email) {

    $query = "SELECT `email`,`user_name` FROM `user` WHERE `email`= '" . $email . "'";

    $db = new DB();

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

    if (!$result) {
        return FALSE;
    } else {
        return $result;
    }
}

function GenarateCode($email) {

    $rand = rand(10000, 99999);

    $query = "UPDATE  `user` SET "
            . "`resetcode` ='" . $rand . "' "
            . "WHERE `email` = '" . $email . "'";

    $db = new DB();

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

    if ($result) {
        return TRUE;
    } else {
        return FALSE;
    }
}

function SelectForgetUser($email) {

    if ($email) {

        $query = "SELECT `email`,`user_name`,`resetcode` FROM `user` WHERE `email`= '" . $email . "'";

        $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 SelectResetCode($code) {

    $query = "SELECT `id` FROM `user` WHERE `resetcode`= '" . $code . "'";

    $db = new DB();

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

    if (!$result) {
        return FALSE;
    } else {
        return TRUE;
    }
}

function updatePassword($password, $code) {

   
    $enPass = md5($password);

    $query = "UPDATE  `user` SET "
            . "`password` ='" . $enPass . "' "
            . "WHERE `resetcode` = '" . $code . "'";

    $db = new DB();

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

    if ($result) {
        return TRUE;
    } else {
        return FALSE;
    }
}