if (mysql_num_rows($result_coupon) > 0) {
     $message = "Coupon Name Already Exists !!";
 } else {
     $couponfiletype = $_FILES['txtCouponImage']['type'];
     $couponfilename = $_FILES['txtCouponImage']['name'];
     $coupontempname = $_FILES['txtCouponImage']['tmp_name'];
     //','txtCouponImage','txtCouponAmount','ddlArtist'
     $update_gift_coupon = "UPDATE " . $tableprefix . "products\n                                           SET product_name = " . GetSQLValueString($_POST['txtGiftCouponName'], "text") . ",\n                                               product_code = " . GetSQLValueString($_POST['txtGiftCouponCode'], "text") . ",\n                                               product_description = " . GetSQLValueString($_POST['txtCouponDescription'], "text") . ",\n                                               product_price = " . GetSQLValueString($_POST['txtCouponAmount'], "text");
     $update_gift_coupon .= " WHERE product_id = '" . $_GET['edit_product_id'] . "'";
     mysql_query($update_gift_coupon) or die(mysql_error());
     $update_product_options = "UPDATE " . $tableprefix . "product_options\n                                                SET product_stock = " . GetSQLValueString($_POST['txtCouponStock'], "text") . ",\n                                                    reorder_level = " . GetSQLValueString($_POST['txtStockReorder'], "text");
     $update_gift_coupon_master = "UPDATE " . $tableprefix . "giftcoupon_master\n\t\t\t\t\t\t\t\t\t  SET ngift_coupon_amount = " . GetSQLValueString($_POST['txtCouponAmount'], "text") . " WHERE ngift_product_id = " . $_GET['edit_product_id'];
     mysql_query($update_gift_coupon_master) or die(mysql_error());
     $message = "Gift Coupon Details Updated Successfully !!";
     if ($_FILES['txtCouponImage']['name'][0] != "") {
         if (!isValidWebImageType($couponfiletype, $couponfilename, $coupontempname)) {
             $message_image = " * Invalid Image !! Upload an image (jpg/gif/png)" . "<br>";
             $image_flag = 1;
         } else {
             $imagewidth_height_type_array = explode(":", ImageTypeBanner($_FILES['txtCouponImage']['tmp_name']));
             $imagetype = $imagewidth_height_type_array[0];
             $assignedname_small = "gift_coupon_small" . time() . "." . $imagetype;
             $assignedname_large = "gift_coupon_large" . time() . "." . $imagetype;
             if (move_uploaded_file($_FILES['txtCouponImage']['tmp_name'], "../products/" . $assignedname_large)) {
                 chmod("../products/{$assignedname_large}", 0777);
                 /*taken from the general site settings table*/
                 $gift_image_size = '400,400';
                 $gift_size = split(',', $gift_image_size);
                 resizeImg("../products/" . $assignedname_large, 283, 269, false, 100, 0, "_thumb");
                 @copy("../products/{$assignedname_large}", "../products/{$assignedname_small}");
                 resizeImg("../products/" . $assignedname_small, 191, 183, false, 100, 0, "_thumb");
}
if (!empty($productid)) {
    $select_bulk_images = "SELECT nproduct_image_id FROM " . $tableprefix . "product_view_images \n\t\t\t\t\t\t   WHERE nimage_productid = " . GetSQLValueString($_POST['product'], "text");
    $result_bulk_images = mysql_query($select_bulk_images) or die(mysql_error());
    $total_image_count = mysql_num_rows($result_bulk_images);
}
if (isset($_POST['add'])) {
    for ($i = 1; $i <= $settings_product_image_count[0]; $i++) {
        $product_image = "txtImage_" . $i;
        $productfiletype = $_FILES[$product_image]['type'];
        $productfilename = $_FILES[$product_image]['name'];
        $producttempname = $_FILES[$product_image]['tmp_name'];
        $product_description = "txtDescription_" . $i;
        $dir_dest = "../products/bulk_images/";
        if ($_FILES[$product_image]['name'][0] != "") {
            if (!isValidWebImageType($productfiletype, $productfilename, $producttempname)) {
                $message .= " * Image{$i} is no a valid image !! Upload an image (jpg/gif/png)" . "<br>";
                $invalid_image_flag = 1;
            } else {
                $imagewidth_height_type_array = explode(":", ImageTypeBanner($_FILES[$product_image]['tmp_name']));
                $imagetype = $imagewidth_height_type_array[0];
                list($org_name, $ext) = explode(".", $_FILES[$product_image]['name']);
                $name_replaced = "product_image_" . time() . $i . str_replace(' ', '', $org_name);
                $name_thumb = "thumb_product_image_" . time() . $i . str_replace(' ', '', $org_name);
                $assignedname = "product_image_" . time() . $i . str_replace(' ', '', $_FILES[$product_image]['name']);
                $thumbimage = "thumb_product_image_" . time() . $i . str_replace(' ', '', $_FILES[$product_image]['name']);
                $handle = new Upload($_FILES[$product_image]);
                if ($handle->uploaded) {
                    $handle->image_resize = true;
                    $handle->image_x = 192;
                    $handle->image_y = 183;
        $artistid = $_POST["artistid"];
    }
}
$banner_image_size = '940,260';
if (isset($_POST['add'])) {
    /*check whether banner with the same name exists in the database*/
    $bannerfiletype = $_FILES['txtBannerImage']['type'];
    $bannerfilename = $_FILES['txtBannerImage']['name'];
    $bannertempname = $_FILES['txtBannerImage']['tmp_name'];
    $portfoliodir = "../portfolios/banners/";
    if (!is_readable($portfoliodir) || !is_writable($portfoliodir) || !is_executable($portfoliodir)) {
        // $error = 1;
        $message .= " * Please request admin to change the permission of 'portfolios/banners' folder in the root to 777 <br>";
    }
    if ($_FILES['txtBannerImage']['name'][0] != "") {
        if (!isValidWebImageType($bannerfiletype, $bannerfilename, $bannertempname)) {
            $message .= " * Invalid Image !! Upload an image (jpg/gif/png)" . "<br>";
        } else {
            $imagewidth_height_type_array = explode(":", ImageTypeBanner($_FILES['txtBannerImage']['tmp_name']));
            $imagetype = $imagewidth_height_type_array[0];
            $assignedname = "banner" . time() . "." . $imagetype;
            if (move_uploaded_file($_FILES['txtBannerImage']['tmp_name'], "../portfolios/banners/" . $assignedname)) {
                chmod("../portfolios/banners/" . $assignedname, 0777);
                $banner_size = split(',', $banner_image_size);
                generateThumbNail("../portfolios/banners/" . $assignedname, "../portfolios/banners/" . $assignedname, $banner_size[0], $banner_size[1]);
                $insert_banner = "INSERT INTO " . $tableprefix . "seller_banner\n                                                                            (vBannerName, nSellerId)\n\t\t\t\t\t\t\t\t\t  VALUES('" . mysql_real_escape_string($assignedname) . "','" . mysql_real_escape_string($artistid) . "')";
                mysql_query($insert_banner) or die(mysql_error());
                header('Location:sellerbanners.php?artistid=' . $artistid . '&msg=Banner Added Successfully !!');
            }
        }
    } else {
} else {
    header("Location:login.php");
    exit;
}
if ($_POST["btnSaveChanges"] == "Save Changes") {
    $message = "";
    $logofile = $_FILES['userfile'][0];
    $logofilename = $_FILES['userfile']['name'][0];
    if (!empty($logofilename)) {
        $logofiletype = $_FILES['userfile']['type'][0];
        $logotempname = $_FILES['userfile']['tmp_name'][0];
        $logofilesize = $_FILES['userfile']['size'][0];
        $logoimagedest = "../banners/" . $logofilename;
        $logoimageTemp = "../banners/" . time() . $logofilename;
        if ($_FILES['userfile']['name'][0] != "") {
            if (!isValidWebImageType($logofiletype, $logofilename, $logotempname)) {
                $message .= " * Invalid Logo file ! Upload an image (jpg/gif/png)" . "<br>";
                $error = true;
            } else {
                if (file_exists($logoimagedest)) {
                    $message .= " * Logo file with the same name exists! Please rename the logo file and upload! " . "<br>";
                    $error = true;
                } elseif ($logofilesize > $maximagesizeinPHP) {
                    $message .= "*  Could Not Upload Logo Image File , File Size exceeds. Maximum allowed size is {$maximagesizestringinPHP}. <br>";
                }
            }
        }
        //Logo upload modified by Sreehari
        if (move_uploaded_file($_FILES['userfile']['tmp_name'][0], $logoimageTemp)) {
            $dir_dest = "../banners/";
            $handle = new Upload($logoimageTemp);
             $message .= "* Product Reorder Level should be a positive value for option " . ($i + 1) . "! <br>";
         } else {
             if ($reorder_level > $product_stock) {
                 $message .= "* Product Reorder Level should be less than the stock for option " . ($i + 1) . "! <br>";
             }
         }
     }
 }
 /*
  * More Images Validation
  */
 if (isset($_FILES['productMoreImage']['name']) && !empty($_FILES['productMoreImage']['name'])) {
     foreach ($_FILES['productMoreImage']['name'] as $key => $moreImage) {
         if ($moreImage != '') {
             $type = $_FILES['productMoreImage']['type'][$key];
             if (!isValidWebImageType($type)) {
                 $message .= " * Invalid more image " . ($key + 1) . "<br>";
             }
         }
     }
 }
 $moreFiles = array();
 foreach ($_FILES['productMoreImage'] as $k => $l) {
     foreach ($l as $j => $v) {
         if (!array_key_exists($j, $moreFiles)) {
             $moreFiles[$j] = array();
         }
         $moreFiles[$j][$k] = $v;
     }
 }
 /*if($txtfacebook != "" && !validateURL($txtfacebook)){
     $error = true;
     $message .= " * Change the permission of 'products' folder in the root to 777 <br>";
 }
 if ($picsmalltype != "") {
     if (!isValidWebImageType($picsmalltype, $picsmallfilename, $picsmalltempname)) {
         $message .= " * Invalid product picture (small)! Upload an image (jpg/gif/png)" . "<br>";
         $error = true;
     } else {
         if (file_exists($picsmalldest)) {
             $message .= " * Product picture (small) with the same name exists! Please rename the product picture (small) and upload! " . "<br>";
             $error = true;
         }
     }
 }
 if ($picbigtype != "") {
     if (!isValidWebImageType($picbigtype, $picbigfilename, $picbigtempname)) {
         $message .= " * Invalid product picture (big)! Upload an image (jpg/gif/png)" . "<br>";
         $error = true;
     } else {
         if (file_exists($picbigdest)) {
             $message .= " * Product picture (big) with the same name exists! Please rename the product picture (big) and upload! " . "<br>";
             $error = true;
         }
     }
 }
 /*----Digital Product Block Starts-------*/
 if (isNotNull($_FILES['txtProductZip']['name'])) {
     $uploadfile = ReplaceArrayImage($_FILES['txtProductZip']['name']);
     $types = array('zip', 'pdf', 'rar', 'psd', 'opf', 'azw', 'lit', 'pdb', 'pkg', 'mp3', 'mpeg', 'mp4', 'avi');
     preg_match('/\\.([a-zA-Z]+?)$/', $uploadfile, $matches);
     if (!in_array(strtolower($matches[1]), $types)) {
 }
 /*if (!isNotNull($txtArtistContactDetails)) {
       $message .= "* seller Contact Details is required! <br>";
   }*/
 $portfoliodir = "../portfolios/";
 if ($_FILES['artistphoto']['name'] != "" && $_FILES['artistphoto']['type'] != "") {
     $artistphoto = $_FILES['artistphoto'];
     $artistphotoname = time() . $_FILES['artistphoto']['name'];
     $artistphotoname_tmb = "tmb_" . $artistphotoname;
     $artistphototype = $_FILES['artistphoto']['type'];
     $artistfilename = $_FILES['artistphoto']['name'];
     $artisttempname = $_FILES['artistphoto']['tmp_name'];
     $artistphotodest = $portfoliodir . $artistphotoname;
     $artistphotodest_tmb = $portfoliodir . $artistphotoname_tmb;
     if ($artistphotoname != "") {
         if (!isValidWebImageType($artistphototype, $artistfilename, $artisttempname)) {
             $message .= " * Invalid  Photo! Upload an image (jpg/gif/png)" . "<br>";
             $error = 1;
         } else {
             if (file_exists($artistphotodest)) {
                 $message .= " * Photo with the same name exists! Please rename the Photo and upload! " . "<br>";
                 $error = 1;
             }
         }
         if (!is_readable($portfoliodir) || !is_writable($portfoliodir) || !is_executable($portfoliodir)) {
             // $error = 1;
             // $message .= " * Please request admin to change the permission of 'portfolios' folder in the root to 777 <br>";
         }
     }
 } else {
     if ($mybusinessid == "") {