Example #1
0
 public function fullHtml()
 {
     /**
      * @var Config
      */
     $subgridConfig = $this->subgridConfig;
     $db = new Db($this->subgridConfig, $this->statusVariables);
     $where = $db->buildSqlWhere();
     $pageVariableName = $subgridConfig->pageVariableName();
     $currentPage = !empty($this->statusVariables[$pageVariableName]) ? (int) $this->statusVariables[$pageVariableName] : 1;
     if ($currentPage < 1) {
         $currentPage = 1;
     }
     $pageSize = $subgridConfig->pageSize($this->statusVariables);
     $from = ($currentPage - 1) * $pageSize;
     $totalPages = ceil($db->recordCount($where) / $pageSize);
     if ($currentPage > $totalPages) {
         $totalPages = $currentPage;
     }
     $pagination = new \Ip\Pagination\Pagination(array('currentPage' => $currentPage, 'totalPages' => $totalPages, 'pagerSize' => $subgridConfig->pagerSize()));
     $values = array(10, 20, 50, 100, 1000, 10000);
     if (!in_array($pageSize, $values)) {
         $values[] = $pageSize;
     }
     asort($values);
     $searchVariables = array();
     foreach ($this->statusVariables as $key => $value) {
         if (preg_match('/^s_/', $key)) {
             $searchVariables[substr($key, 2)] = $value;
         }
     }
     $variables = array('columns' => $this->getColumnData(), 'data' => $this->rowsData($db->fetch($from, $pageSize, $where)), 'actions' => $this->getActions(), 'pagination' => $pagination, 'deleteWarning' => $subgridConfig->deleteWarning(), 'createForm' => $this->createForm(), 'searchForm' => $this->searchForm($searchVariables), 'moveForm' => $this->moveForm(), 'title' => $subgridConfig->getTitle(), 'breadcrumb' => $this->getBreadcrumb(), 'pageSize' => $pageSize, 'pageSizes' => $values);
     $html = ipView($subgridConfig->layout(), $variables)->render();
     return $html;
 }
Example #2
0
/**
*news
* @param $postObj
* @return string
itemArray = array(
* array(
* 'Title' => 'title',
* 'Description' => 'description',
* 'PicUrl' => 'www.sample.com/pic/user.png',
* 'Url' => 'www.sample.com/sample.html',
* )
* )
*/
function news($postObj)
{
    $fromUserName = $postObj->FromUserName;
    $toUserName = $postObj->ToUserName;
    $db = new Db();
    $log = new Logs();
    $itemArray = null;
    $query = array('select' => '*', 'table' => TB_NEWS, 'where' => array('state' => 1), 'order' => 'rank ASC');
    if (!($res = $db->fetch($query))) {
        $log->write_log($db->error);
    }
    foreach ($res as $item) {
        $itemArray[] = array('Title' => $item['title'], 'Description' => $item['description'], 'PicUrl' => $item['picurl'], 'Url' => $item['url']);
    }
    $news = array('fromUserName' => $fromUserName, 'toUserName' => $toUserName, 'itemArray' => $itemArray);
    return responseMultiNews($news);
}
     $result["return"] = false;
     $result["message"] = "Invalid user.";
     echo json_encode($result);
     exit;
 }
 //count category
 $salesmanCount = Db::rowCount("salesman", array("user_id" => $userId, "active" => "y"), array("=", "="));
 if ($salesmanCount <= 0) {
     $result["return"] = true;
     $result["count"] = $salesmanCount;
     $result["message"] = "No salesman added. ";
     echo json_encode($result);
     exit;
 }
 //fetch category list
 $list = Db::fetch("salesman", array("user_id" => $userId, "active" => "y"), array("=", "="));
 //create a new list
 $newList = array();
 foreach ($list as $key => $value) {
     $newList[$key]["id"] = $value["id"];
     $newList[$key]["name"] = $value["name"];
     $newList[$key]["user_id"] = $value["user_id"];
     $newList[$key]["time"] = $value["time"];
 }
 if (Db::getError()) {
     $result["return"] = false;
     $result["message"] = "Failed to load salesmanCount";
 } else {
     $result["return"] = true;
     $result["message"] = "Success";
     $result["data"] = $newList;
     $result["return"] = false;
     $result["message"] = "Invalid user.";
     echo json_encode($result);
     exit;
 }
 //count category
 $categoryCount = Db::rowCount("category", array("user_id" => $userId, "active" => "y"), array("=", "="));
 if ($categoryCount <= 0) {
     $result["return"] = true;
     $result["count"] = $categoryCount;
     $result["message"] = "No category found";
     echo json_encode($result);
     exit;
 }
 //fetch category list
 $list = Db::fetch("category", array("user_id" => $userId, "active" => "y"), array("=", "="));
 //create a new list
 $newList = array();
 foreach ($list as $key => $value) {
     $newList[$key]["id"] = $value["id"];
     $newList[$key]["name"] = $value["name"];
     $newList[$key]["user_id"] = $value["user_id"];
     $newList[$key]["time"] = $value["time"];
 }
 if (Db::getError()) {
     $result["return"] = false;
     $result["message"] = "Failed to load category";
 } else {
     $result["return"] = true;
     $result["message"] = "Success";
     $result["data"] = $newList;
     $result["return"] = false;
     $result["message"] = "Invalid category Id";
     echo json_encode($result);
     exit;
 }
 //count product
 $count = Db::rowCount("product", array("user_id" => $userId, "category_id" => $categoryId, "active" => "y"), array("=", "=", "="));
 if ($count <= 0) {
     $result["return"] = true;
     $result["message"] = "No product Added yet!";
     $result["count"] = 0;
     echo json_encode($result);
     exit;
 }
 //fetch all the product
 $product = Db::fetch("product", array("user_id" => $userId, "category_id" => $categoryId, "active" => "y"), array("=", "=", "="));
 if (!Db::getError()) {
     //create a new product array with only that fields which are required
     $newProductArray = array();
     foreach ($product as $key => $value) {
         $newProductArray[$key]["productId"] = $value["id"];
         $newProductArray[$key]["userId"] = $value["user_id"];
         $newProductArray[$key]["categoryId"] = $value["category_id"];
         $newProductArray[$key]["name"] = $value["name"];
         $newProductArray[$key]["image"] = $value["image_thumb"];
         $newProductArray[$key]["code"] = $value["code"];
         $newProductArray[$key]["time"] = date('d/m/y', $value["time"]);
     }
     //output the result json
     $result["return"] = true;
     $result["message"] = "Success";
 //check user is active or not
 if (!check_user_active($userId)) {
     $result["return"] = false;
     $result["message"] = "Dear user! Please pay your bills to reactivate your account.";
     echo json_encode($result);
     exit;
 }
 //check Product is valid and belong to the user
 if (!check_productId_is_valid($productId, $userId)) {
     $result["return"] = false;
     $result["message"] = "Invalid Product Id";
     echo json_encode($result);
     exit;
 }
 //fetch all the product
 $product = Db::fetch("product", array("user_id" => $userId, "id" => $productId), array("=", "="));
 if (!Db::getError()) {
     //create dateTime from time stamp
     $dateTime = date("d/m/y", $product[0]["time"]);
     //fetch Size & quantity
     $q = Db::query("SELECT size,quantity FROM `sq` WHERE user_id=? AND product_id=?", array($userId, $productId));
     $sqResult = $q->fetchAll(PDO::FETCH_ASSOC);
     $sizeArray = array();
     $quantityArray = array();
     //create size and quantity array
     foreach ($sqResult as $key => $r) {
         $sizeArray[$key] = $r["size"];
         $quantityArray[$key] = $r["quantity"];
     }
     //output the result json
     $result["return"] = true;
Example #7
0
<?php

/**
 * Created by PhpStorm.
 * User: Arsan Irianto
 * Date: 18/11/2015
 * Time: 15:41
 */
include '../../library/Db.php';
/*
$query = "select * from REKAP_FGTM";
$result = $conn->prepare($query);
$result->execute();
*/
$i = 0;
while ($row = Db::fetch("REKAP_FGTM", "", "")) {
    $rows['data'][$i] = array($row[0], $row[1]);
    $i++;
}
print json_encode($rows, JSON_NUMERIC_CHECK);
//Db::getConnection();
//$r = Db::fetch("REKAP_FGTM","","");
//echo $r[2];
//display result
/*
echo "<pre>";
print_r($r[2]);
echo "</pre>";
*/
if (isset($_POST['email']) && isset($_POST['password'])) {
    //escape value
    $email = e($_POST["email"]);
    $password = e($_POST['password']);
    if (empty($email) || empty($password)) {
        $result["message"] = "Fill in all the fields";
        $result["return"] = false;
        echo json_encode($result);
        exit;
    }
    //check email is valid
    $count = Db::rowCount("user", array("email" => $email), array("="));
    //if one user exits
    if ($count == 1) {
        //fetch results and display
        $detail = Db::fetch("user", array("email" => $email), array("="));
        //store the hash password
        $hash = $detail[0]["password"];
        //check the hash match the password
        if (password_verify($password, $hash)) {
            if (db::getError() == true) {
                $result["message"] = "Query failed";
                $result["return"] = false;
            } else {
                $result["message"] = "success";
                $result["return"] = true;
                $result["user"] = $detail;
            }
            json($result);
        } else {
            $result["message"] = "Invalid password";
     json($result);
 }
 //check that this salesman id belongs to the particular user
 if (!check_salesman_id_is_valid($salesman_id, $user_id)) {
     $result["message"] = "Invalid salesman. Salesman does belongs to your account";
     $result["return"] = false;
     json($result);
 }
 //check salesman has sold something or not
 if (!check_salesman_has_done_any_sales($salesman_id)) {
     $result["message"] = "No sales done by this salesman yet";
     $result["return"] = false;
     json($result);
 }
 //fetch all the sales
 $all_sales_fetch = Db::fetch("sales", array("user_id" => $user_id, "salesman_id" => $salesman_id), array("=", "="), "DESC");
 //array to store all the sales id which are between FROM & To date
 $sales_id_array = array();
 $total_item_sold_to_customers = 0;
 //Fetch thought all the sales and get the sales which is between from and to date
 //and store its sales id in $sales_id_array
 foreach ($all_sales_fetch as $sales_fetch) {
     //GET THE CURRENT SALES DATE
     //Replace "/" with "-" on current date
     $current_date = str_replace("/", "-", $sales_fetch["date"]);
     $current_sales_id = $sales_fetch["id"];
     /*
         CHECK CURRENT Date is IN BETWEEN FROM AND TO DATE
         if yes store its sales_id in $sales_id_array
     */
     if (check_in_range($from_date, $to_date, $current_date)) {