Пример #1
0
/**
 * getCategories function
 * this funciton is to get the list of all those categories which accessable to the current logged in user,. exculded arvind IT users,
 * it will also give the list of categories under a particluar brand if brand if is provided in parameters.
 * @todo get the details of a particular id id category id is provided
 * @param id - category id, to get the details of a particular category
 * @param brand_id - get the list of categories under this brand_id
 * @return stdObject
 * @author Ankit Balyan - sf.ankit@gmail.com
 **/
function getCategories($id = NULL, $brand_id = NULL)
{
    global $wpdb;
    $user_id = isLogin();
    if ($id) {
        return array();
    } else {
        if (!isArvindUser()) {
            $sql = "SELECT \n\t\t\t\t\t    category.*\n\t\t\t\t\tFROM\n\t\t\t\t\t    rw_category AS category\n\t\t\t\t\t        LEFT OUTER JOIN\n\t\t\t\t\t    rw_brand_user_map AS user_brand ON user_brand.user_id = {$user_id}\n\t\t\t\t\t        LEFT OUTER JOIN\n\t\t\t\t\t    rw_brands AS brand ON brand.brand_id = user_brand.brand_id\n\t\t\t\t\t        OR brand.brand_parent_id = user_brand.brand_id\n\t\t\t\t\t        LEFT OUTER JOIN\n\t\t\t\t\t    rw_brand_category_map AS brand_category \n\t\t\t\t\t\t\tON brand_category.brand_id = brand.brand_id\n\t\t\t\t\tWHERE\n\t\t\t\t\t    category.category_id = brand_category.category_id";
            if (count($brand_id)) {
                if (is_array($brand_id)) {
                    $i = 0;
                    foreach ($brand_id as $key => $id) {
                        if ($i == 0) {
                            $sql .= " and ( brand_category.brand_id = {$id} ";
                        } else {
                            $sql .= " or brand_category.brand_id = {$id} ";
                        }
                        $i++;
                    }
                    $sql .= " ) ";
                } else {
                    $sql .= isset($brand_id) ? " and brand_category.brand_id = {$brand_id}" : "";
                }
            }
            $sql .= " group by category.category_id";
        } else {
            $sql = "SELECT * FROM rw_category";
        }
    }
    return $wpdb->get_results($sql);
}
Пример #2
0
    ?>
                    <div class="col-xs-12 col-sm-7 col-md-5">
                        <div class="shop-menu pull-right">
                            <ul class="nav navbar-nav navbar-fixed">
                                <li><a href=""><i class="fa fa-user"></i> <?php 
    echo "Hi! " . getRwUsers(isLogin())->user_fullname;
    ?>
</a></li>
                                <li><a href="<?php 
    echo site_url('my-orders');
    ?>
"><i class="fa fa-shopping-cart"></i> My Orders</a></li>
                                <!-- <li><a href="#"><i class="fa fa-star"></i> Wishlist</a></li>
                                <li><a href="checkout.html"><i class="fa fa-crosshairs"></i> Checkout</a></li> -->
                                <?php 
    if (!isArvindUser() && !isBrandUser()) {
        ?>
                                <li><a href="<?php 
        echo site_url('review');
        ?>
"><i class="fa fa-eye"></i> Review </a></li>
                                <?php 
    }
    ?>
                                <li><a href="javascript:void(0)" class="logout" onclick="logout();"><i class="fa fa-lock"></i> Logout</a></li>
                            </ul>
                        </div>
                    </div>
                <?php 
}
?>
Пример #3
0
/**
 * getOrderSum function
 * this funciton is to get total sum or the total quantities of all the orders and also by differenciating by user or confirmed orders.
 * 
 * @todo by providing order id, get the total sums.
 * @param int id, product id not implemented, always null
 * @param  sting qty, get the toal quantities of orders by providing qty = 'qty' string.
 * @param bool confirmed, TRUE or FALSE
 * @return int
 * @author Ankit Balyan - sf.ankit@gmail.com
 **/
function getOrderSum($id = NULL, $qty = NULL, $confirmed = FALSE, $user_id = NULL)
{
    $confirmed = $confirmed ? " and orders.order_confirm_ind = {$confirmed} " : ' ';
    global $wpdb;
    if (isBrandUser()) {
        $user_id = isLogin();
        if ($qty != 'qty') {
            $sql = "SELECT SUM(orders.total_price) as dist_total_price \n\t\t\t\tFROM \n\t\t\t\t\trw_orders AS orders \n\t\t\t\tLEFT OUTER JOIN \n\t\t\t\t\trw_products AS product on orders.product_id = product.product_id\n\t\t\t\tLEFT OUTER JOIN\n                \trw_brand_user_map AS user_brand ON user_brand.user_id = {$user_id}\n                LEFT OUTER JOIN\n                \trw_brands AS brand ON brand.brand_id = user_brand.brand_id\n                OR brand.brand_parent_id = user_brand.brand_id\n\t            where\n\t                product.brand_id = brand.brand_id\n\t            or\n\t                product.brand_id = brand.brand_parent_id\n\t\t\t\t\t\t{$confirmed}";
        } elseif ($qty == 'qty') {
            $sql = "SELECT SUM(orders.total_qty) as dist_total_qty \n\t\t\t\t\tFROM \n\t\t\t\t\t\trw_orders AS orders \n\t\t\t\t\tLEFT OUTER JOIN \n\t\t\t\t\t\trw_products AS product on orders.product_id = product.product_id\n\t\t\t\t    LEFT OUTER JOIN\n                \trw_brand_user_map AS user_brand ON user_brand.user_id = {$user_id}\n\t                LEFT OUTER JOIN\n\t                \trw_brands AS brand ON brand.brand_id = user_brand.brand_id\n\t                OR brand.brand_parent_id = user_brand.brand_id\n\t\t            where\n\t\t                product.brand_id = brand.brand_id\n\t\t            or\n\t\t                product.brand_id = brand.brand_parent_id {$confirmed}";
        }
        $wpdb->get_var($sql);
        $wpdb->last_query;
        return $wpdb->get_var($sql);
    } elseif (isArvindUser()) {
        if ($qty != 'qty') {
            $sql = "SELECT SUM(orders.total_price) as dist_total_price \n\t\t\t\tFROM \n\t\t\t\t\trw_orders AS orders \n\t\t\t    \twhere 1 {$confirmed}";
        } elseif ($qty == 'qty') {
            $sql = "SELECT SUM(orders.total_qty) as dist_total_qty \n\t\t\t\t\tFROM \n\t\t\t\t\t\trw_orders AS orders \n\t\t\t\t    \twhere 1 {$confirmed}";
        }
        if ($user_id) {
            $sql .= " and orders.created_by = " . $user_id;
        }
        $wpdb->get_var($sql);
        $wpdb->last_query;
        return $wpdb->get_var($sql);
    } elseif (count(isDistributor($user_id)) && $user_id && $qty != 'qty') {
        $sql = "SELECT SUM(orders.total_price) as dist_total_price \n\t\t\t\tFROM \n\t\t\t\t\trw_orders AS orders \n\t\t\t\t\tLEFT OUTER JOIN rw_users as users\n\t\t\t    \ton users.user_parent_id = {$user_id} \n\t\t\t    \tor users.user_id = {$user_id}\n\t\t\t    \twhere orders.created_by = users.user_id {$confirmed}";
    } elseif (count(isDistributor($user_id)) && $user_id && $qty == 'qty') {
        $sql = "SELECT SUM(orders.total_qty) as dist_total_qty \n\t\t\t\tFROM \n\t\t\t\t\trw_orders AS orders \n\t\t\t\t\tLEFT OUTER JOIN rw_users as users\n\t\t\t    \ton users.user_parent_id = {$user_id} \n\t\t\t    \tor users.user_id = {$user_id}\n\t\t\t    \twhere orders.created_by = users.user_id {$confirmed}";
    } elseif ($id && $qty != 'qty') {
        $sql = "SELECT \n\t\t\t\t   SUM(orders.total_price) AS user_total_price\n\t\t\t\tFROM\n\t\t\t\t    rw_orders AS orders\n\t\t\t\t    where orders.created_by = {$id} {$confirmed}";
    } elseif ($id && $qty == 'qty') {
        $sql = "SELECT \n\t\t\t\t   SUM(orders.total_qty) AS user_total_qty\n\t\t\t\tFROM\n\t\t\t\t    rw_orders AS orders\n\t\t\t\t    where orders.created_by = {$id} {$confirmed}";
    } elseif (!$id && $qty == 'qty') {
        $sql = "SELECT \n\t\t\t\t   SUM(orders.total_qty) AS user_total_qty\n\t\t\t\tFROM\n\t\t\t\t    rw_orders AS orders\n\t\t\t\t    where orders.created_by = " . isLogin() . " {$confirmed}";
    } else {
        $sql = "SELECT \n\t\t\t\t   SUM(orders.total_price) AS user_total_price\n\t\t\t\tFROM\n\t\t\t\t    rw_orders AS orders\n\t\t\t\t    where orders.created_by = " . isLogin() . " {$confirmed}";
    }
    $wpdb->get_var($sql);
    // /echo $wpdb->last_query;
    return $wpdb->get_var($sql);
}
Пример #4
0
/**
 * generates the array list of brands sub brands and caregories in parent child array format
 *
 * @return array
 * @author Ankit Balyan - sf.ankit@gmail.com
 **/
function get_nested()
{
    global $wpdb;
    $user_id = isLogin();
    if (is_admin()) {
        $sql = "SELECT \n                brand.*, category.category_id\n            FROM\n                rw_brands AS brand\n                    LEFT OUTER JOIN\n                rw_brand_category_map AS catmap ON brand.brand_id = catmap.brand_id\n                    LEFT OUTER JOIN\n                rw_category AS category ON catmap.category_id = category.category_id\n                group by brand.brand_id";
    } elseif (!isArvindUser()) {
        $sql = "SELECT \n                brand.*, category.category_id\n            FROM\n                rw_brands AS brand\n                    LEFT OUTER JOIN\n                rw_brand_category_map AS catmap ON brand.brand_id = catmap.brand_id\n                    LEFT OUTER JOIN\n                rw_category AS category ON catmap.category_id = category.category_id\n                    LEFT OUTER JOIN\n                rw_brand_user_map AS user_brand ON user_brand.user_id = {$user_id}\n            where\n                brand.brand_id = user_brand.brand_id\n            or\n                brand.brand_parent_id = user_brand.brand_id\n            group by brand.brand_id";
    } else {
        $sql = "SELECT \n                brand.*, category.category_id\n            FROM\n                rw_brands AS brand\n                    LEFT OUTER JOIN\n                rw_brand_category_map AS catmap ON brand.brand_id = catmap.brand_id\n                    LEFT OUTER JOIN\n                rw_category AS category ON catmap.category_id = category.category_id\n                group by brand.brand_id";
    }
    $pages = $wpdb->get_results($sql);
    $array = array();
    foreach ($pages as $page) {
        $page = (array) $page;
        if (!$page['brand_parent_id'] && !$page['category_id']) {
            $array[$page['brand_id']] = $page;
        } elseif ($page['brand_parent_id'] && $page['category_id']) {
            $page['category'] = getBrandCats($page['brand_id']);
            $array[$page['brand_parent_id']]['children'][] = $page;
        } else {
            $array[$page['brand_parent_id']]['children'][] = $page;
        }
    }
    return $array;
}
Пример #5
0
        $allpieces = getOrderSum(null, 'qty', TRUE, isLogin());
        ?>
									<div class="finalTotal">All Total: <span class ="pull-right"> Rs <?php 
        echo $alltotal ? $alltotal : '0';
        ?>
</span><span class ="pull-right"> <?php 
        echo $allpieces ? $allpieces . " pcs, " : '0' . " pcs, ";
        ?>
</span></div>
									<?php 
    }
    ?>
								</div>

								<?php 
} elseif ($user = isBrandUser() || isArvindUser()) {
    ?>
								<div id="review_order_tab3">
									<?php 
    $count = 0;
    ?>
										<?php 
    $ordered_ids = getOrederedIdByBrand(null, null, TRUE);
    ?>
										<?php 
    if (count($ordered_ids)) {
        ?>
										<?php 
        $count++;
        ?>
									<?php 
Пример #6
0
/**
 * genxls function
 * this funciton is to genterate the excel reports, save it or download at the browser
 * @param data - array of data that is need to be write on excel file
 * @param attachment - if true force to download the excel file at browser else save it in rwFiles direcory
 * @return sting - path of file stored
 * @author Ankit Balyan - sf.ankit@gmail.com
 **/
function genxls($data = array(), $attachment = false)
{
    /** Error reporting */
    error_reporting(E_ALL);
    /** Include path **/
    //	ini_set('include_path', ini_get('include_path').';../Classes/');
    /** PHPExcel */
    include ROADSHOW . 'PHPExcel/Classes/PHPExcel.php';
    /** PHPExcel_Writer_Excel2007 */
    include ROADSHOW . 'PHPExcel/Classes/PHPExcel/Writer/Excel2007.php';
    // Create new PHPExcel object
    //echo date('H:i:s') . " Create new PHPExcel object\n";
    $objPHPExcel = new PHPExcel();
    // Set properties
    //echo date('H:i:s') . " Set properties\n";
    $objPHPExcel->getProperties()->setCreator("Ankit Balyan");
    $objPHPExcel->getProperties()->setLastModifiedBy("Ankit Balyan");
    $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Report Title");
    $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Report Subject");
    $objPHPExcel->getProperties()->setDescription("This is a testing report document.");
    // Add some data
    //echo date('H:i:s') . " Add some data\n";
    $objPHPExcel->setActiveSheetIndex(0);
    //HEre your first sheet
    $objWorkSheet = $objPHPExcel->getActiveSheet();
    $brands = $data;
    //    print_r($data);
    $i = 0;
    foreach ($brands as $key => $data) {
        if (!isArvindUser()) {
            $objPHPExcel->getActiveSheet()->SetCellValue('A2', 'Order\'s Report');
            $objPHPExcel->getActiveSheet()->SetCellValue('A3', 'Customer Name:');
            $user = getRwUsers(isLogin());
            $objPHPExcel->getActiveSheet()->SetCellValue('B3', $user->user_fullname);
            $objPHPExcel->getActiveSheet()->SetCellValue('A4', 'Date:');
            $objPHPExcel->getActiveSheet()->SetCellValue('B4', date('d M Y'));
            $rowI = 5;
        } else {
            $rowI = 1;
        }
        if ($i != 0) {
            $objWorkSheet = $objPHPExcel->createSheet($key);
        }
        //Setting index when creating
        $count = count($data);
        if ($count) {
            $colI = 0;
            foreach ($data[0] as $k => $v) {
                $colChar = PHPExcel_Cell::stringFromColumnIndex($colI++);
                $cellId = $colChar . ($rowI + 1);
                $objWorkSheet->SetCellValue($cellId, $k);
            }
            $rowI++;
            foreach ($data as $key => $row) {
                $colI = 0;
                foreach ($row as $k => $v) {
                    $colChar = PHPExcel_Cell::stringFromColumnIndex($colI++);
                    $cellId = $colChar . ($rowI + 1);
                    $objWorkSheet->SetCellValue($cellId, $v);
                }
                $rowI++;
            }
            // Rename sheet
            //	echo date('H:i:s') . " Rename sheet\n";
            $objWorkSheet->setTitle('Brand');
            $i++;
        }
    }
    // Save Excel 2007 file
    //	echo date('H:i:s') . " Write to Excel2007 format\n";
    $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
    //$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
    $filename = "data_" . time() . ".xls";
    $DIR = $_SERVER["DOCUMENT_ROOT"] . '/rwFiles/';
    !is_dir($DIR) ? mkdir($DIR, 0777, true) : '';
    $path = $DIR . $filename;
    //$url = "http://".$_SERVER['HTTP_HOST'].'/oddpodimages/'.$filename;
    $fp = fopen($path, 'w');
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save($path);
    fclose($fp);
    $objPHPExcel->disconnectWorksheets();
    unset($objPHPExcel);
    if (file_exists($path) && $attachment) {
        header('Content-Description: File Transfer');
        header('Content-Transfer-Encoding: binary');
        header('Content-Disposition: attachment;filename=' . $filename);
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Length: ' . filesize($path));
        header('Pragma: no-cache');
        header('Expires: 0');
        ob_clean();
        flush();
        @readfile($path);
        exit;
    }
    return $path;
    die;
}
Пример #7
0
/**
 * getCatelog function
 * this funciton is get the all products with most of of the details alaong with them to render the catelog on home page, or get the details of a signle product if id is specified.
 * product catelog is based on the access level of current user, exluded from arvind Arvind IT Users
 * 
 * @param id, int - it is the product id of which images are required (optional)
 * @param offset - is to set the starting point of limits
 * @param limits - is to set the max total no. of results from the query 
 * @return stdObject
 * @author Ankit Balyan - sf.ankit@gmail.com
 **/
function getCatelog($id = NULL, $offSet = 0, $limits = 10)
{
    global $wpdb;
    global $products;
    $table = "rw_products";
    $user_id = isLogin();
    if ($id) {
        $sql = "SELECT \n\t\t\t\t    product.*, product.brand_id as brandId,product.category_id as categoryId, images.image_url, ratio.*\n\t\t\t\tFROM\n\t\t\t\t    rw_products AS product\n\t\t\t\t        LEFT OUTER JOIN\n\t\t\t\t    rw_images AS images ON product.product_id = images.product_id and images.thumnail_ind = 1\n\t\t\t\t\t\tLEFT OUTER JOIN\n\t\t\t\t\tuser_category_size_map AS ratio\n\t\t\t\t\t\tON product.brand_id = ratio.brand_id and product.category_id = ratio.category_id and ratio.user_id = " . isLogin() . " \n\t\t\t\t    where product.product_id = {$id}";
    } else {
        if (!isArvindUser()) {
            $sql = "SELECT \n\t\t\t\t    product.*, images.image_url\n\t\t\t\tFROM\n\t\t\t\t    rw_products AS product\n\t\t\t\t        LEFT OUTER JOIN\n\t\t\t\t    rw_images AS images ON product.product_id = images.product_id and images.thumnail_ind = 1\n\t\t\t\tLEFT OUTER JOIN\n                \trw_brand_user_map AS user_brand ON user_brand.user_id = {$user_id}\n                LEFT OUTER JOIN\n                \trw_brands AS brand ON brand.brand_id = user_brand.brand_id\n                OR brand.brand_parent_id = user_brand.brand_id\n\t            where\n\t                product.brand_id = brand.brand_id\n\t            or\n\t                product.brand_id = brand.brand_parent_id";
            //LIMIT $offSet, $limits";
        } else {
            $sql = "SELECT \n\t\t\t\t    product.*, images.image_url\n\t\t\t\tFROM\n\t\t\t\t    rw_products AS producty\n\t\t\t\t        LEFT OUTER JOIN\n\t\t\t\t    rw_images AS images ON product.product_id = images.product_id and images.thumnail_ind = 1";
            //LIMIT $offSet, $limits";
        }
    }
    $sql .= " GROUP BY product.product_id";
    $sql .= " LIMIT 0,100";
    $products = $wpdb->get_results($sql);
    return $wpdb->get_results($sql);
}