Example #1
0
<?php

/********************************************************************************************************************

#Coder       : Manoj Pandit

#Description : This Code is used to display list of all product and remove any on them 


*********************************************************************************************************************/
extract($_GET);
extract($_POST);
$obj_block = new common();
$currentTimestamp = getCurrentTimestamp();
if ($model_id != '' && $action == 'delete') {
    $logoname = $obj_block->getNameById(TBL__HTMLTEMPLATE, 'id=' . $model_id);
    /*if($logoname->image!='') {
    		@chmod(LIST_ROOT_ADMIN."/images/new_model/",0777);
    		unlink(LIST_ROOT_ADMIN."/images/new_model/".$logoname->image);
    				
    	}*/
    $deleteProduct = $obj_block->delete(TBL__HTMLTEMPLATE, 'id =' . $model_id);
    $_SESSION['msg'] = 'Car Template Successfully Deleted';
    unset($obj_block);
    echo '<script>location.href="' . DEFAULT_ADMIN_URL . '/htmltemplate/index.php";</script>';
    exit;
}
$getBlock = $obj_block->read(TBL__HTMLTEMPLATE, '', ' creation_date DESC');
unset($obj_block);
    //--------------------------------------------//
    if ($error) {
        $errorMsg = "<font color='#FF0000' family='verdana' size=2>" . $error . "</font>";
    } else {
        $image = '';
        if ($_FILES["image"]["name"]) {
            $type = explode(".", $_FILES["image"]["name"]);
            if (end($type) == "png" || end($type) == "jpeg" || end($type) == "jpg" || end($type) == "gif") {
                $image = getCurrentTimestamp() . '-' . $_FILES["image"]["name"];
                //chmod(DEFAULT_ADMIN_URL."/images/used_car/image",0777);
                move_uploaded_file($_FILES["image"]["tmp_name"], LIST_ROOT_ADMIN . "/images/used_car/image/" . $image);
            }
        }
        $dispo = '';
        if ($_FILES["dispo"]["name"]) {
            $type = explode(".", $_FILES["dispo"]["name"]);
            if (end($type) == "png" || end($type) == "jpeg" || end($type) == "jpg" || end($type) == "gif") {
                $dispo = getCurrentTimestamp() . '-' . $_FILES["dispo"]["name"];
                //chmod(DEFAULT_ADMIN_URL."/images/used_car/dispo",0777);
                move_uploaded_file($_FILES["dispo"]["tmp_name"], LIST_ROOT_ADMIN . "/images/used_car/dispo/" . $dispo);
            }
        }
        $dataArr = array('model_name' => $model_name, 'brand_id' => $brand_id, 'year' => $year, 'image' => $image, 'dispo' => $dispo, 'prix' => $prix, 'publish' => $publish, 'creation_date' => $currentTimestamp);
        $add_product = $obj_block->save(TBL_USED_CAR, $dataArr);
        $_SESSION['msg'] = 'Car Successfully Added';
        redirectUrl(DEFAULT_ADMIN_URL . '/used_car/index.php');
        unset($obj_block);
        unset($obj);
        exit;
    }
}
    }
    $filterarray[] = array('name' => 'ListingType', 'value' => $val, 'paramName' => '', 'paramValue' => '');
} else {
    $filterarray[] = array('name' => 'ListingType', 'value' => array('FixedPrice', 'StoreInventory', 'AuctionWithBIN', 'Auction'), 'paramName' => '', 'paramValue' => '');
}
$userTblName = 'temp_' . $_SESSION['unique_id'][0];
if (!isset($_SESSION['announces'])) {
    $common->customQuery('DROP TABLE IF EXISTS `' . $userTblName . '`');
    $common->customQuery('CREATE TABLE `' . $userTblName . '` (
							  `type` int(10) NOT NULL,
							  `itemId` bigint(20) NOT NULL,
							  `title` varchar(255) NOT NULL,
							  `Price` float NOT NULL,
							  `content` longtext
							) ENGINE=MyISAM DEFAULT CHARSET=latin1');
    $common->customQuery('INSERT INTO master_temp (user_id, tbl_name, lastAct) VALUES ("' . $_SESSION['unique_id'][0] . '","' . $userTblName . '",' . getCurrentTimestamp() . ')');
    $common->customQuery("DELETE FROM " . $userTblName);
}
if (!isset($_GET['page'])) {
    $_SESSION['announces'] = array();
    $_SESSION['announces']['fill'] = true;
    $page = 1;
    $_SESSION['announces']['page'] = 8;
    $_SESSION['announces']['fillfor'] = 1;
    $common->customQuery("DELETE FROM " . $userTblName);
} else {
    $DbPage = ceil($page / $_SESSION['announces']['page']);
    if ($_SESSION['announces']['fillfor'] != $DbPage) {
        $_SESSION['announces']['fill'] = true;
        $_SESSION['announces']['fillfor'] = $DbPage;
    }
$obj_handle = new Handle();
/* Get Current Date Time Stamp */
$currentTimestamp = getCurrentTimestamp();
if (isset($submit) && $submit != "" && $_SERVER['REQUEST_METHOD'] == 'POST') {
    $error = '';
    $obj->add_fields($title, 'req', 'Please Enter Title');
    $error = $obj->validate();
    $image = '';
    //--------------------------------------------//
    if ($error) {
        $errorMsg = "<font color='#FF0000' family='verdana' size=2>" . $error . "</font>";
    } else {
        if ($_FILES["logo"]["name"]) {
            $type = explode(".", $_FILES["logo"]["name"]);
            if (end($type) == "png" || end($type) == "jpeg" || end($type) == "jpg" || end($type) == "gif") {
                $image = getCurrentTimestamp() . '-' . $_FILES["logo"]["name"];
                //chmod(DEFAULT_ADMIN_URL."/images/brands",0777);
                move_uploaded_file($_FILES["logo"]["tmp_name"], LIST_ROOT_ADMIN . "/images/brands/" . $image);
            }
        }
        $dataArr = array('title' => $title, 'logo' => $image, 'publish' => $publish, 'creation_date' => $currentTimestamp);
        $add_product = $obj_block->save(TBL_BRANDS, $dataArr);
        $_SESSION['msg'] = 'Brand Successfully Added';
        redirectUrl(DEFAULT_ADMIN_URL . '/brands/index.php');
        unset($obj_block);
        unset($obj);
        exit;
    }
}
?>
 public function AddCar($arrPost, $arrFiles, $edit = false, $car_id = '')
 {
     global $db;
     if ($edit) {
         $result = $this->customQuery("SELECT car_id FROM car WHERE stock_id= '" . $arrPost['stock_id'] . "' and vin = '" . $arrPost['vin'] . "'");
         if (mysql_num_rows($result) == 0) {
             $arr = array("stock_id" => $arrPost[stock_id], "vin" => $arrPost[vin], "updated_at" => getCurrentTimestamp());
             $this->update("car", $arr, "car_id = " . $car_id);
             unset($arrPost['stock_id']);
             unset($arrPost['vin']);
         } else {
             $result_id = $db->fetchNextObject($result);
             if ($car_id != $result_id->car_id) {
                 $this->error .= 'Stock Id and VIN Duplicate.' . '<br>';
                 return false;
             } else {
                 $arr = array("stock_id" => $arrPost[stock_id], "vin" => $arrPost[vin], "updated_at" => getCurrentTimestamp());
                 if (!empty($arrPost['brand_id'])) {
                     $arr['brand_id'] = $arrPost['brand_id'];
                 }
                 $this->update("car", $arr, "car_id = " . $car_id);
                 unset($arrPost['stock_id']);
                 if (!empty($arrPost['brand_id'])) {
                     unset($arrPost['brand_id']);
                 }
                 unset($arrPost['vin']);
             }
         }
         // deleted images
         if (!empty($arrPost['deleted_img'])) {
             foreach ($arrPost['deleted_img'] as $image) {
                 $resultImage = $this->customQuery("DELETE FROM `car_media_gallery` WHERE `car_media_gallery`.`value` = '" . $image . "' LIMIT 1");
                 unlink(UPLOAD_CAR_IMAGES . '/' . $image);
             }
         }
     } else {
         $result = $this->customQuery("SELECT car_id FROM car WHERE stock_id= '" . $arrPost['stock_id'] . "' and vin = '" . $arrPost['vin'] . "'");
         if (mysql_num_rows($result) == 0) {
             $arr = array("stock_id" => $arrPost[stock_id], "vin" => $arrPost[vin], "created_at" => getCurrentTimestamp());
             if (!empty($arrPost['brand_id'])) {
                 $arr['brand_id'] = $arrPost['brand_id'];
             }
             if (!empty($_REQUEST['type']) && $_REQUEST['type'] == 'nostock') {
                 $arr['site_name'] = 2;
             }
             $car_id = $this->save("car", $arr);
             unset($arrPost['stock_id']);
             unset($arrPost['vin']);
             unset($arrPost['brand_id']);
             unset($arrPost['site_name']);
         } else {
             $this->error .= 'Stock Id and VIN Duplicate.' . '<br>';
             return false;
         }
     }
     $attributes = $this->getAttributes();
     foreach ($arrPost as $key => $value) {
         if ($key == "submit") {
             break;
         }
         if ($value == '') {
             continue;
         }
         if ($attributes[$key]["front"] == "select") {
             if ($value == 'other') {
                 $arr = array("attribute_id" => $attributes[$key]["id"], "value" => $arrPost[$key . "_other"]);
                 $value = $this->save("attribute_option_value", $arr);
                 unset($arrPost[$key . "_other"]);
             }
         }
         $arr = array("attribute_id" => $attributes[$key]["id"], "car_id" => $car_id, "value" => $value);
         if (!empty($attributes[$key]["id"])) {
             $result = $this->customQuery("SELECT value_id FROM car_" . $attributes[$key]["back"] . " WHERE\n\t\t\t\t\t\t\t     attribute_id= '" . $attributes[$key]["id"] . "' and\n\t\t\t\t\t\t\t     car_id = '" . $car_id . "'");
             $exists = mysql_fetch_array($result);
             if (!empty($exists['value_id'])) {
                 $value = $this->update("car_" . $attributes[$key]["back"], $arr, "value_id = " . $exists['value_id']);
             } else {
                 $value = $this->save("car_" . $attributes[$key]["back"], $arr);
             }
         }
     }
     $j = 1;
     $counter = 0;
     foreach ($arrFiles['images']['name'] as $file) {
         $path = $this->getUploadDirPath($file);
         if (move_uploaded_file($arrFiles['images']["tmp_name"][$counter], UPLOAD_CAR_IMAGES . '/' . $path)) {
             $arr = array("attribute_id" => $attributes['images']["id"], "car_id" => $car_id, "value" => $path, "fetched" => 1);
             $value = $this->save("car_" . $attributes['images']["back"], $arr);
             $arr = array("value_id" => $value, "position" => $j++);
             $value = $this->save("car_" . $attributes['images']["back"] . "_value", $arr);
         } else {
             $this->error .= 'Cannot Upload File.<br>';
         }
         $counter++;
     }
     return true;
 }
    //$obj->add_fields($model, 'req', 'Please select a Model');
    $obj->add_fields($year, 'req', 'Please Enter year');
    $obj->add_fields($expert, 'req', 'Please Enter Excerpt');
    $obj->add_fields($ensemble, 'req', 'Please Enter Ensemble');
    $obj->add_fields($characteristique, 'req', 'Please Enter Characteristique');
    $obj->add_fields($_FILES['image']['name'], 'req', 'Please Upload Image');
    $obj->add_fields($_FILES['image'], 'ftype=jpg,gif,png', 'Please Upload Valid Image');
    $error = $obj->validate();
    //echo "<pre>";
    //print_r($error); die;
    if ($error) {
        $errorMsg = "<font color='#FF0000' family='verdana' size=2>Please fill all required fields.</font>";
    } else {
        $make_name = $makes[$make];
        $models_new = $getEntityObj->getEntityOutput($make, 4);
        $model_name = $models_new[$model];
        $image_name = time() . '-' . $_FILES['image']['name'];
        //$path = LIST_ROOT.'/images/reviews/media/';
        $path = LIST_ROOT_ADMIN_REVIEW_IMAGEPATH . '/';
        move_uploaded_file($_FILES["image"]["tmp_name"], $path . $image_name);
        $_SESSION['success_msg'] = 'New review has been saved successfully.';
        $dataArr = array('short_description' => $short_description, 'old_new' => $old_new, 'editorial' => $editorial, 'pdsf' => $pdsf, 'mpg' => $mpg, 'image' => $image_name, 'make' => $make, 'model' => $model, 'year' => $year, 'expert' => $expert, 'ensemble' => $ensemble, 'characteristique' => $characteristique, 'updated' => getCurrentTimestamp(), 'make_name' => $make_name, 'model_name' => $model_name);
        $review_id = $obj_setting->save('reviews', $dataArr);
        foreach ($medias as $media) {
            $dataArrMedia = array('review_id' => $review_id, 'media_type' => $media['mediatype'], 'order_id' => $media['order'], 'media_name' => $media['value'], 'updated' => getCurrentTimestamp());
            $review_media_id = $obj_setting->save('reviews_media', $dataArrMedia);
        }
        echo '<script>location.href="' . DEFAULT_ADMIN_URL . '/reviews";</script>';
        exit;
    }
}