Exemple #1
0
function updateCategory($categoryname = "", $category_url = "", $categoryid = '', $category_img = '', $categoryicon = '')
{
    if ($_FILES['imglink']['type'] == "image/jpeg" || $_FILES['imglink']['type'] == "image/jpg" || $_FILES['imglink']['type'] == "image/gif" || $_FILES['imglink']['type'] == "image/png" || $_FILES['imglink']['type'] == "image/pjpeg") {
        if (isset($_FILES['imglink'])) {
            try {
                $imgData = addslashes(file_get_contents($_FILES['imglink']['tmp_name']));
                $size = getimagesize($_FILES['imglink']['tmp_name']);
                $userid = $_SESSION["userid"];
                $imtype = $_FILES['imglink']['type'];
                switch ($imtype) {
                    case 'image/gif':
                        $im = imagecreatefromgif($_FILES['imglink']['tmp_name']);
                        break;
                    case "image/pjpeg":
                    case "image/jpg":
                    case 'image/jpeg':
                        $im = imagecreatefromjpeg($_FILES['imglink']['tmp_name']);
                        break;
                    case 'image/png':
                        $im = imagecreatefrompng($_FILES['imglink']['tmp_name']);
                        break;
                }
                $randomvalue = ranval();
                $width = imagesx($im);
                $height = imagesy($im);
                $thumb = imagecreatetruecolor($width, $height);
                ImageCopyResampled($thumb, $im, 0, 0, 0, 0, $width, $height, ImageSX($im), ImageSY($im));
                ImagejpeG($thumb, DOCUMENT_ROOT . "/uploads/category/" . $randomvalue . ".jpg");
                $imgurl = "uploads/category/" . $randomvalue . ".jpg";
            } catch (Exception $e) {
            }
        }
        $queryString = "update coupons_category set category_name = '{$categoryname}', category_url='{$category_url}', category_image='{$imgurl}' where category_id ='{$categoryid}'";
        $resultSet = mysql_query($queryString) or die(mysql_error());
    } else {
        $queryString = "update coupons_category set category_name = '{$categoryname}', category_url='{$category_url}' where category_id ='{$categoryid}'";
        $resultSet = mysql_query($queryString) or die(mysql_error());
    }
    //add categoryicon image
    if ($_FILES['categoryicon']['type'] == "image/jpeg" || $_FILES['categoryicon']['type'] == "image/jpg" || $_FILES['categoryicon']['type'] == "image/gif" || $_FILES['categoryicon']['type'] == "image/png" || $_FILES['categoryicon']['type'] == "image/pjpeg") {
        if (isset($_FILES['categoryicon'])) {
            try {
                $imgData = addslashes(file_get_contents($_FILES['categoryicon']['tmp_name']));
                $size = getimagesize($_FILES['categoryicon']['tmp_name']);
                $userid = $_SESSION["userid"];
                $imtype = $_FILES['categoryicon']['type'];
                switch ($imtype) {
                    case 'image/gif':
                        $im = imagecreatefromgif($_FILES['categoryicon']['tmp_name']);
                        break;
                    case "image/pjpeg":
                    case "image/jpg":
                    case 'image/jpeg':
                        $im = imagecreatefromjpeg($_FILES['categoryicon']['tmp_name']);
                        break;
                    case 'image/png':
                        $im = imagecreatefrompng($_FILES['categoryicon']['tmp_name']);
                        break;
                }
                $width = imagesx($im);
                $height = imagesy($im);
                $newwidth = 16;
                $newheight = 16;
                $thumb = imagecreatetruecolor($newwidth, $newheight);
                ImageCopyResampled($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, ImageSX($im), ImageSY($im));
                ImagejpeG($thumb, DOCUMENT_ROOT . "/uploads/categoryicon/" . $categoryid . ".jpg");
            } catch (Exception $e) {
            }
        }
    }
    return $resultSet;
}
Exemple #2
0
function couponUpload()
{
    include "docroot.php";
    include "config.php";
    $cname = htmlentities($_POST['couponname'], ENT_QUOTES);
    $deal_permalink = htmlentities($_POST['deal_permalink'], ENT_QUOTES);
    $cdesc = htmlentities($_POST['cdesc'], ENT_QUOTES);
    $cfineprints = htmlentities($_POST['cfineprints'], ENT_QUOTES);
    $chighlights = htmlentities($_POST['chighlights'], ENT_QUOTES);
    $cenddate = htmlentities($_POST['cenddate']);
    $cstartdate = htmlentities($_POST['cstartdate']);
    $cexpdate = htmlentities($_POST['cexpdate']);
    $climit = htmlentities($_POST['climit']);
    $cterms = htmlentities($_POST['cterms']);
    $cdiscountvalue = htmlentities($_POST['cdiscountvalue']);
    $cminuser = htmlentities($_POST['minlimit']);
    $cmaxuser = htmlentities($_POST['maxlimit']);
    $crealvalue = htmlentities($_POST['crealvalue']);
    //unneccessary input fields are removed
    $cperson = '';
    //htmlentities($_POST['cperson'], ENT_QUOTES);
    $phonenum = '';
    //htmlentities($_POST['phonenum']);
    $address = '';
    //htmlentities($_POST['address'], ENT_QUOTES);
    $meta_keywords = htmlentities($_POST['meta_keywords'], ENT_QUOTES);
    $meta_description = htmlentities($_POST['meta_description'], ENT_QUOTES);
    $termscondition = htmlentities($_POST['termscondition'], ENT_QUOTES);
    if ($_POST['max_dealpurchase'] > 0) {
        $max_dealpurchase = htmlentities($_POST['max_dealpurchase']);
    } else {
        $max_dealpurchase = 0;
    }
    if ($_POST['couponname'] == '' || $_POST['cdesc'] == '' || $_POST['crealvalue'] == '' || $_POST['crealvalue'] == 0) {
        $redirect_url = DOCROOT . "admin/couponsupload/";
        set_response_mes(1, 'All fields are mandatory.');
        url_redirect($redirect_url);
    }
    $uid = $_SESSION["userid"];
    $shopid = $_POST['shop'];
    $csubtype = $_POST['csubtype'];
    $ctype = $_POST['ctype'];
    $country = $_POST['country'];
    $city = $_POST['city'];
    if ($_POST['sidedeal']) {
        $sidedeal = 1;
    } else {
        $sidedeal = 0;
    }
    if ($_POST['maindeal']) {
        $maindeal = 1;
    } else {
        $maindeal = 0;
    }
    if ($_POST['instant_deal']) {
        $instant_deal = 1;
    } else {
        $instant_deal = 0;
    }
    $is_video = $_POST['is_video'];
    $embed_code = htmlentities($_REQUEST['embed_code'], ENT_QUOTES);
    $randomvalue = ranval();
    // get the image width and hight for the current theme
    $val = $ImageSize[DEFAULT_CURRENT_THEME];
    if ($val) {
        $width_val = $val['width'];
        $height_val = $val['hight'];
    } else {
        $width_val = 420;
        $height_val = 282;
    }
    $imageTypeFormats = array("image/jpeg", "image/jpg", "image/gif", "image/png", "image/pjpeg");
    if (in_array(strtolower($_FILES['cpicture']['type']), $imageTypeFormats)) {
        if (isset($_FILES['cpicture'])) {
            try {
                $imgData = addslashes(file_get_contents($_FILES['cpicture']['tmp_name']));
                $size = getimagesize($_FILES['cpicture']['tmp_name']);
                $userid = $_SESSION["userid"];
                $imtype = $_FILES['cpicture']['type'];
                switch ($imtype) {
                    case 'image/gif':
                        $im = imagecreatefromgif($_FILES['cpicture']['tmp_name']);
                        break;
                    case "image/pjpeg":
                    case "image/jpg":
                    case 'image/jpeg':
                        $im = imagecreatefromjpeg($_FILES['cpicture']['tmp_name']);
                        break;
                    case 'image/png':
                        $im = imagecreatefrompng($_FILES['cpicture']['tmp_name']);
                        break;
                }
                $width = imagesx($im);
                $height = imagesy($im);
                $newheight = $width_val;
                $newwidth = $height_val;
                $thumb = imagecreatetruecolor($newwidth, $newheight);
                ImageCopyResampled($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, ImageSX($im), ImageSY($im));
                ImagejpeG($thumb, DOCUMENT_ROOT . "/uploads/coupons/" . $randomvalue . ".jpg");
                $imgurl = "uploads/coupons/" . $randomvalue . ".jpg";
            } catch (Exception $e) {
            }
        }
    }
    $status = "A";
    if ($_SESSION['userrole'] == '3') {
        $status = "D";
    }
    $queryString = "insert into coupons_coupons\n\t    (coupon_name,deal_url,coupon_description,coupon_enddate,coupon_image,coupon_createdby,coupon_createddate,coupon_value,coupon_status,coupon_minuserlimit,coupon_maxuserlimit,coupon_realvalue,coupon_category,coupon_country,coupon_city,coupon_person,coupon_phoneno,coupon_address,  \tcoupon_shop,coupon_fineprints,coupon_highlights,side_deal,meta_keywords,meta_description,terms_and_condition,main_deal,coupon_expirydate,coupon_startdate,is_video, embed_code,max_deal_purchase,instant_deal) values ('{$cname}','{$deal_permalink}','{$cdesc}',STR_TO_DATE('{$cenddate}','%Y-%m-%d %H:%i:%s'),'{$imgurl}','{$uid}',now(),'{$cdiscountvalue}','{$status}','{$cminuser}','{$cmaxuser}','{$crealvalue}','{$ctype}','{$country}','{$city}', '{$cperson}', '{$phonenum}', '{$address}','{$shopid}','{$cfineprints}','{$chighlights}','{$sidedeal}','{$meta_keywords}','{$meta_description}','{$termscondition}','{$maindeal}','{$cexpdate}','{$cstartdate}','{$is_video}', '{$embed_code}','{$max_dealpurchase}','{$instant_deal}')";
    $resultset = mysql_query($queryString) or die(mysql_error());
    $last_insert_id = mysql_insert_id();
    if ($maindeal == 1) {
        $maindealQuery = "update coupons_coupons set main_deal=0 where coupon_city='{$city}' and coupon_id!='{$last_insert_id}'";
        $maindealResult = mysql_query($maindealQuery);
    }
    if (in_array(strtolower($_FILES['slide1']['type']), $imageTypeFormats)) {
        if (isset($_FILES['slide1'])) {
            try {
                $imgData = addslashes(file_get_contents($_FILES['slide1']['tmp_name']));
                $size = getimagesize($_FILES['slide1']['tmp_name']);
                $userid = $_SESSION["userid"];
                $imtype = $_FILES['slide1']['type'];
                switch ($imtype) {
                    case 'image/gif':
                        $im = imagecreatefromgif($_FILES['slide1']['tmp_name']);
                        break;
                    case "image/pjpeg":
                    case "image/jpg":
                    case 'image/jpeg':
                        $im = imagecreatefromjpeg($_FILES['slide1']['tmp_name']);
                        break;
                    case 'image/png':
                        $im = imagecreatefrompng($_FILES['slide1']['tmp_name']);
                        break;
                }
                $width = imagesx($im);
                $height = imagesy($im);
                $newwidthX = $width_val;
                $newheight = $width_val;
                $newwidth = $height_val;
                $thumb = imagecreatetruecolor($newwidth, $newheight);
                ImageCopyResampled($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, ImageSX($im), ImageSY($im));
                ImagejpeG($thumb, DOCUMENT_ROOT . "/uploads/slider_images/" . $last_insert_id . "_1.jpg");
                $imgurl = "uploads/slider_images/" . $last_insert_id . "_1.jpg";
                $slide1_image_name = $last_insert_id . "_1" . ".jpg";
                //slide show images
                $query = "insert into slider_images(coupon_id,imagename) values('{$last_insert_id}','{$slide1_image_name}')";
                $result = mysql_query($query) or die(mysql_error());
            } catch (Exception $e) {
            }
        }
    }
    if (in_array(strtolower($_FILES['slide2']['type']), $imageTypeFormats)) {
        if (isset($_FILES['slide2'])) {
            try {
                $imgData = addslashes(file_get_contents($_FILES['slide2']['tmp_name']));
                $size = getimagesize($_FILES['slide2']['tmp_name']);
                $userid = $_SESSION["userid"];
                $imtype = $_FILES['slide2']['type'];
                switch ($imtype) {
                    case 'image/gif':
                        $im = imagecreatefromgif($_FILES['slide2']['tmp_name']);
                        break;
                    case "image/pjpeg":
                    case "image/jpg":
                    case 'image/jpeg':
                        $im = imagecreatefromjpeg($_FILES['slide2']['tmp_name']);
                        break;
                    case 'image/png':
                        $im = imagecreatefrompng($_FILES['slide2']['tmp_name']);
                        break;
                }
                $width = imagesx($im);
                $height = imagesy($im);
                $newheight = $width_val;
                $newwidth = $height_val;
                $thumb = imagecreatetruecolor($newwidth, $newheight);
                ImageCopyResampled($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, ImageSX($im), ImageSY($im));
                ImagejpeG($thumb, DOCUMENT_ROOT . "/uploads/slider_images/" . $last_insert_id . "_2.jpg");
                $imgurl = "uploads/slider_images/" . $last_insert_id . "_2.jpg";
                $slide2_image_name = $last_insert_id . "_2" . ".jpg";
                $query = "insert into slider_images(coupon_id,imagename) values('{$last_insert_id}','{$slide2_image_name}')";
                $result = mysql_query($query) or die(mysql_error());
            } catch (Exception $e) {
            }
        }
    }
    if (in_array(strtolower($_FILES['slide3']['type']), $imageTypeFormats)) {
        if (isset($_FILES['slide3'])) {
            try {
                $imgData = addslashes(file_get_contents($_FILES['slide3']['tmp_name']));
                $size = getimagesize($_FILES['slide3']['tmp_name']);
                $userid = $_SESSION["userid"];
                $imtype = $_FILES['slide3']['type'];
                switch ($imtype) {
                    case 'image/gif':
                        $im = imagecreatefromgif($_FILES['slide3']['tmp_name']);
                        break;
                    case "image/pjpeg":
                    case "image/jpg":
                    case 'image/jpeg':
                        $im = imagecreatefromjpeg($_FILES['slide3']['tmp_name']);
                        break;
                    case 'image/png':
                        $im = imagecreatefrompng($_FILES['slide3']['tmp_name']);
                        break;
                }
                $width = imagesx($im);
                $height = imagesy($im);
                $newwidthX = $width_val;
                $newheight = $width_val;
                $newwidth = $height_val;
                $thumb = imagecreatetruecolor($newwidth, $newheight);
                ImageCopyResampled($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, ImageSX($im), ImageSY($im));
                ImagejpeG($thumb, DOCUMENT_ROOT . "/uploads/slider_images/" . $last_insert_id . "_3.jpg");
                $imgurl = "uploads/slider_images/" . $last_insert_id . "_3.jpg";
                $slide3_image_name = $last_insert_id . "_3" . ".jpg";
                $query = "insert into slider_images(coupon_id,imagename) values('{$last_insert_id}','{$slide3_image_name}')";
                $result = mysql_query($query) or die(mysql_error());
            } catch (Exception $e) {
            }
        }
    }
    // include admin language file
    $admin_lang = $_SESSION["site_admin_language"];
    if ($admin_lang) {
        include DOCUMENT_ROOT . "/system/language/admin_" . $admin_lang . ".php";
    } else {
        include DOCUMENT_ROOT . "/system/language/admin_en.php";
    }
    // get current date and time
    $cdate = date("Y-m-d H:i:s");
    //update the deal url into facebook and twitter
    if ($last_insert_id) {
        $url = 'deals/' . $deal_permalink . '_' . $last_insert_id . '.html';
        $share_link = DOCROOT . $url;
        $Status_Message = $share_link;
        if ($cstartdate <= $cdate) {
            //Twitter share
            include $_SERVER["DOCUMENT_ROOT"] . '/system/modules/twitter/update.php';
            include $_SERVER["DOCUMENT_ROOT"] . '/system/modules/facebook/function.php';
            facebook_status_update($Status_Message);
        }
    }
    $redirect_url = DOCROOT . "admin/couponsupload/";
    set_response_mes(1, $admin_language['couponcreated']);
    if ($_FILES["cpicture"]["size"] > $uploadimageSize['deal_pic'] || $_FILES["slide1"]["size"] > $uploadimageSize['deal_pic'] || $_FILES["slide2"]["size"] > $uploadimageSize['deal_pic'] || $_FILES["slide3"]["size"] > $uploadimageSize['deal_pic']) {
        $size = round($uploadimageSize['profile_pic'] / 1024000);
        $img_err2 = "Image file size should lesser than " . $size . 'MB';
        set_response_mes(1, $admin_language['couponcreated'] . $img_err2);
    }
    url_redirect($redirect_url);
}