Example #1
0
 public function onlyDelete()
 {
     $this->allowForMethod = "DELETE";
     if (strtoupper(@$_SERVER['REQUEST_METHOD']) != 'DELETE') {
         resDie(array(), "Avaliable for only DELETE Method !");
     }
 }
Example #2
0
 public function logSave($userType = "", $user_id = "")
 {
     $userType = strtolower(trim($userType));
     if ($userType == "") {
         $userType = "guess";
     }
     if (!in_array($userType, array('guess', 'gaestaff', 'staff', 'owner', 'customer'))) {
         $errors = array("error" => "userType in correct!");
         resDie($errors, $this->methodPlace());
     }
     $is_https = 0;
     if (@$_SERVER["HTTPS"] == "on") {
         $is_https = 1;
     }
     $this->load->library('session');
     $logData["method_type"] = strtoupper(trim($this->input->server('REQUEST_METHOD')));
     $logData["url_call"] = base_url(uri_string());
     $logData["header_data"] = json_encode(getallheaders());
     $logData["request_data"] = json_encode($_REQUEST);
     $logData["get_data"] = json_encode($_GET);
     $logData["post_data"] = json_encode($_POST);
     $logData["file_data"] = json_encode($_FILES);
     $logData["shop_id"] = 1;
     $logData["is_https"] = $is_https;
     $logData["user_type"] = $userType;
     $logData["user_id"] = $user_id;
     $logData["controller_name"] = $this->router->fetch_class();
     $logData["function_name"] = $this->router->fetch_method();
     $logData["base_app_id"] = base_app_id();
     $logData["create_time"] = time();
     $logData["session_id"] = $this->session->userdata('session_id');
     $logData["ip_address"] = $this->input->ip_address();
     return $this->insert($logData);
 }
Example #3
0
 public function onlyOwner()
 {
     $ownerData = $this->getCurrentOwner();
     if (!$ownerData) {
         $error = array("user_type" => "owner", "error" => "require_login");
         resDie($error, "owner:require_login");
     }
     return $ownerData;
 }
Example #4
0
 function json_validate($string)
 {
     // decode the JSON data
     $result = json_decode($string);
     // switch and check possible JSON errors
     switch (json_last_error()) {
         case JSON_ERROR_NONE:
             $error = '';
             // JSON is valid // No error has occurred
             break;
         case JSON_ERROR_DEPTH:
             $error = 'The maximum stack depth has been exceeded.';
             break;
         case JSON_ERROR_STATE_MISMATCH:
             $error = 'Invalid or malformed JSON.';
             break;
         case JSON_ERROR_CTRL_CHAR:
             $error = 'Control character error, possibly incorrectly encoded.';
             break;
         case JSON_ERROR_SYNTAX:
             $error = 'Syntax error, malformed JSON.';
             break;
             // PHP >= 5.3.3
         // PHP >= 5.3.3
         case JSON_ERROR_UTF8:
             $error = 'Malformed UTF-8 characters, possibly incorrectly encoded.';
             break;
             // PHP >= 5.5.0
         // PHP >= 5.5.0
         case JSON_ERROR_RECURSION:
             $error = 'One or more recursive references in the value to be encoded.';
             break;
             // PHP >= 5.5.0
         // PHP >= 5.5.0
         case JSON_ERROR_INF_OR_NAN:
             $error = 'One or more NAN or INF values in the value to be encoded.';
             break;
         case JSON_ERROR_UNSUPPORTED_TYPE:
             $error = 'A value of a type that cannot be encoded was given.';
             break;
         default:
             $error = 'Unknown JSON error occured.';
             break;
     }
     if ($error !== '') {
         // throw the Exception or exit // or whatever :)
         resDie($error);
     }
     // everything is OK
     return array_map("unserialize", array_unique(array_map("serialize", json_decode(json_encode($result), true))));
 }
Example #5
0
 function editproductdetail()
 {
     $product_id = 233;
     $dbData['description'] = "30000";
     $this->load->model('product_model');
     try {
         $this->product_model->editDetail($dbData, $product_id);
     } catch (Exception $e) {
         resDie($e->getMessage());
     }
     // Response
     resOk();
     //end format insetr
 }
Example #6
0
 public function single_upload()
 {
     $this->load->library("form_validation");
     $this->form_validation->onlyPost();
     $this->form_validation->set_rules("txt_name", "required");
     $this->form_validation->requireFile("txt_file");
     $this->formCheck();
     $this->load->model("image_model");
     $result = $this->image_model->upload('txt_file');
     if ($result["rs"] == 1) {
         resOk($result["data"]);
     } else {
         resDie($result["data"]);
     }
 }
Example #7
0
 public function createAccessData($table_id, $item_id)
 {
     $dbData = array();
     $dbData["token"] = $this->generateAccessToken($table_id, $item_id);
     $dbData["holder_object_table_id"] = $table_id;
     $dbData["holder_object_id"] = $item_id;
     $dbData["status"] = 1;
     $dbData["create_time"] = time();
     $dbData["update_time"] = time();
     $dbData["session_id"] = $this->session->userdata('session_id');
     $dbData["ip_address"] = $this->input->ip_address();
     $access_id = $this->db->insert("access", $dbData);
     if (!$access_id) {
         resDie(array(), "Cannot Insert Access token");
     }
     $dbData["access_id"] = $access_id;
     $dbData["access_token"] = $dbData["token"];
     $this->setAccessTokenToCookie($dbData["access_token"]);
     return $dbData;
 }
Example #8
0
 private function updateStatus($deleteIdArray = array(), $status = 0)
 {
     if (!in_array($status, array(0, 1, 2))) {
         resDie("updateStatus is avaliable for 0,1,2");
     }
     $primary_field = "promotion_id";
     if (!(is_array($deleteIdArray) && sizeof($deleteIdArray) > 0)) {
         resDie(array(), "delete-is-not-array");
     }
     $idArray = $this->getUniqIdArrayForDelete($primary_field, $deleteIdArray);
     $deleteDataArray = array();
     $success_count = 0;
     if (sizeof($idArray) > 0) {
         foreach ($idArray as $index => $value) {
             $deleteRow = array();
             $deleteRow[$primary_field] = $value;
             if ($value == 0) {
                 $deleteRow["result"] = 0;
             } else {
                 if ($this->getDataById($value)) {
                     $result = $this->updateSimpleDataById(array("status" => $status), $value);
                     $deleteRow["result"] = 1;
                     $success_count++;
                 } else {
                     $deleteRow["result"] = 0;
                 }
             }
             array_push($deleteDataArray, $deleteRow);
         }
     }
     $deleteResult = array();
     $deleteResult["total"] = sizeof($idArray);
     $deleteResult["success"] = $success_count;
     $deleteResult["detail"] = $deleteDataArray;
     return $deleteResult;
 }
Example #9
0
 public function bulk_update_type()
 {
     // Form validation
     $this->form_validation->onlyPost();
     $this->form_validation->set_rules('ids', 'trim|required');
     $this->form_validation->set_rules('type', 'trim|required');
     $this->formCheck();
     // Receiving parameter
     $attribute_ids = t_Post('ids');
     $attribute_type = t_Post('type');
     // Business logic
     $attribute_ids = explode(',', $attribute_ids);
     if (!is_array($attribute_ids)) {
         resDie("Cannot delete referral data");
     }
     $this->mLoadModel('attribute_model');
     try {
         $this->attribute_model->batch_update_type($attribute_ids, $attribute_type);
     } catch (Exception $e) {
         resDie($e->getMessage());
     }
     // Response
     resOk();
 }
Example #10
0
 private function checkSinglePromotion($promotion_id)
 {
     $this->load->model("root_promotion_model");
     $ResDataPromotion = $this->root_promotion_model->getId($promotion_id);
     if ($ResDataPromotion) {
         $this->load->model("root_promotion_group_model");
         $promotion_group_id = $ResDataPromotion[0]['promotion_group_id'];
         $ResDataPromotionGroup = $this->root_promotion_group_model->getId($promotion_group_id);
         if ($ResDataPromotionGroup[0]['promotion_group_promotion_group_type_id'] == 1) {
             resDie(array(), 'promotion group is single');
         }
     }
 }
Example #11
0
 public function db_trans_complete($error_msg = "")
 {
     $this->db->trans_complete();
     if ($this->db->trans_status() === FALSE) {
         $this->db->trans_rollback();
         resDie(array(), $error_msg);
     } else {
         $this->db->trans_commit();
     }
 }
Example #12
0
 public function bulk_hide()
 {
     // Form validation
     $this->form_validation->onlyPost();
     $this->form_validation->set_rules('ids', 'trim|required');
     $this->formCheck();
     // Receiving parameter
     $referral_ids = t_Post('ids');
     // Business logic
     $referral_ids = explode(',', $referral_ids);
     if (!is_array($referral_ids)) {
         resDie("Cannot delete referral data");
     }
     $this->mLoadModel('referral_model');
     try {
         $this->referral_model->batch_update($referral_ids, self::STATUS_BLOCK);
     } catch (Exception $e) {
         resDie($e->getMessage());
     }
     // Response
     resOk();
 }
Example #13
0
 public function delete($deleteIdArray = array())
 {
     if (!(is_array($deleteIdArray) && sizeof($deleteIdArray) > 0)) {
         resDie(array(), "delete-is-not-array");
     }
     $idArray = array();
     foreach ($deleteIdArray as $index => $row) {
         if (is_numeric(@$row["imagegallery_id"])) {
             if (!in_array(@$row["imagegallery_id"], $idArray)) {
                 array_push($idArray, @$row["imagegallery_id"]);
             }
         }
     }
     $deleteDataArray = array();
     $success_count = 0;
     if (sizeof($idArray) > 0) {
         foreach ($idArray as $index => $value) {
             $deleteRow = array();
             $deleteRow["imagegallery_id"] = $value;
             if ($value == 0) {
                 $deleteRow["result"] = 0;
             } else {
                 if ($this->getDataById($value)) {
                     $result = $this->updateDataById(array("status" => 0), $value);
                     $this->makeImageInGalleryIdDelete($value);
                     $deleteRow["result"] = 1;
                     $success_count++;
                 } else {
                     $deleteRow["result"] = 0;
                 }
             }
             array_push($deleteDataArray, $deleteRow);
         }
     }
     $deleteResult = array();
     $deleteResult["total"] = sizeof($idArray);
     $deleteResult["success"] = $success_count;
     $deleteResult["detail"] = $deleteDataArray;
     return $deleteResult;
 }
Example #14
0
 public function addProductForPackage($Dbdata)
 {
     $Dbdata['shop_id'] = $this->currentShopId();
     $Dbdata['status'] = 1;
     $Dbdata['create_time'] = time();
     $Dbdata['update_time'] = time();
     $FieldData = 'package_id,product_id';
     // $PackageData = $this->CheckProductInPackage($Dbdata,$Tbname='package',$FieldData) ;
     $PackageData = $this->GetPackageData($Dbdata, $Tbname = 'package', $FieldData);
     $PackageMatchData = $this->GetPackageData($Dbdata, $Tbname = 'product_matchto_package', $FieldData);
     if (!$PackageData and !$PackageMatchData) {
         return $this->insertToTable("product_matchto_package", $Dbdata);
     } else {
         return resDie('Your Database Have same package_id ' . $Dbdata['package_id'] . ' and product_id' . $Dbdata['product_id']);
     }
 }
Example #15
0
 public function update_status()
 {
     // Form validation
     $this->form_validation->onlyPost();
     $this->form_validation->set_rules('id', 'trim|required');
     $this->form_validation->set_rules('status', 'trim|required');
     $this->formCheck();
     // Receiving parameter
     $customer_id = t_Post('id');
     $customer_status = t_Post('status');
     // Business logic
     $status_active = 1;
     $status_blocked = 2;
     $dbData = array();
     $dbData['status'] = $customer_status == $status_active ? $status_blocked : $status_active;
     $dbData['update_time'] = time();
     $this->mLoadModel('customer_model');
     try {
         $this->customer_model->update($dbData, $customer_id);
     } catch (Exception $e) {
         resDie($e->getMessage());
     }
     // Response
     resOk();
 }
Example #16
0
 public function update_sort()
 {
     // Form validation
     $this->form_validation->onlyPost();
     $this->form_validation->set_rules('sort', 'trim|required');
     $this->form_validation->set_rules('sorted', 'trim|required');
     $this->formCheck();
     // Receiving parameter
     $referral_sort = t_Post('sort');
     $referral_sorted = t_Post('sorted');
     // Business logic
     $this->mLoadModel('referral_model');
     try {
         $order = explode('&', $referral_sort);
         $order = explode('||', $order[0]);
         $order = $order[1]--;
         $sorted = explode('&', $referral_sorted);
         foreach ($sorted as $sort) {
             $sort = explode('||', $sort);
             $referral_id = str_replace('id=', '', $sort[0]);
             $dbData = array();
             $dbData['update_time'] = time();
             $dbData['sort_index'] = $order++;
             $this->referral_model->update($dbData, $referral_id);
         }
     } catch (Exception $e) {
         resDie($e->getMessage());
     }
     // Response
     resOk();
 }
Example #17
0
 public function getId($item_id)
 {
     $result = $this->getDataById($item_id);
     if (!$result) {
         resDie(array(), "module_model : data-not-foud");
     }
     return $result;
 }
Example #18
0
 private function checknumGroupAndType($num)
 {
     if (!in_array($num['badge_group_type_id'], array(1, 2))) {
         resDie("badge_group is avaliable for 1,2");
     } else {
         if (!in_array($num['badge_check_type_id'], array(1, 2))) {
             resDie("badge_check is avaliable for 1,2");
         }
     }
 }
Example #19
0
 public function bulk_delete()
 {
     // Form validation
     $this->form_validation->onlyPost();
     $this->form_validation->set_rules('ids', 'trim|required');
     $this->formCheck();
     // Receiving parameter
     $staff_group_ids = t_Post('ids');
     // Business logic
     $staff_group_ids = explode(',', $staff_group_ids);
     if (!is_array($staff_group_ids)) {
         resDie("Cannot delete staff data");
     }
     $this->mLoadModel('staff_group_model');
     try {
         $this->staff_group_model->batch_delete($staff_group_ids);
     } catch (Exception $e) {
         resDie($e->getMessage());
     }
     // Response
     resOk();
 }
Example #20
0
 function bulk_delete_customer()
 {
     // Form validation
     $this->form_validation->onlyPost();
     $this->form_validation->set_rules('id', 'trim|required');
     $this->form_validation->set_rules('customerIds', 'trim|required');
     $this->formCheck();
     // Receiving parameter
     $customer_group_id = t_Post('id');
     $customer_customer_ids = t_Post('customerIds');
     // Business logic
     $customer_customer_ids = explode(',', $customer_customer_ids);
     if (!is_array($customer_customer_ids)) {
         resDie("Cannot delete customer data");
     }
     $this->mLoadModel('customer_mathto_customer_group_model');
     try {
         $this->customer_mathto_customer_group_model->delete_customer($customer_group_id, $customer_customer_ids);
     } catch (Exception $e) {
         resDie($e->getMessage());
     }
     // Response
     resOk();
 }
Example #21
0
function getValueForId($value = "")
{
    if ($value == "") {
        resDie(array(), "No id");
    }
    if (!is_numeric($value)) {
        resDie(array(), "Id is not currect");
    }
    return intval($value);
}
Example #22
0
 public function startCropImageById($imageId, $cropData, $isRect = false)
 {
     $cropData = $this->checkCropDataFormat($cropData);
     $cx = $cropData["cx"];
     $cy = $cropData["cy"];
     $cw = $cropData["cw"];
     $ch = $cropData["ch"];
     $imageData = $this->getId($imageId);
     $db_image_size_using = $imageData["image_size_using"];
     $full_dirImage = $this->getRootImagesPath($imageData["image_server_id"]) . $imageData["image_file_dir"];
     $source_imagePath = $full_dirImage . $imageData["image_file_name"];
     if (!file_exists($source_imagePath)) {
         resDie(array(), "image-soure-file-not-found");
     }
     if ($isRect == true) {
         $imageSize = getimagesize($source_imagePath);
         $imageW = $imageSize[0];
         $imageH = $imageSize[1];
         $max_rec_size = $imageH;
         if ($imageW < $imageH) {
             $max_rec_size = $imageW;
         }
         $diff_cx_cw = $cw - $cx;
         if ($diff_cx_cw > $max_rec_size) {
             $cw = $cw - ($diff_cx_cw - $max_rec_size);
         }
         $diff_cy_ch = $ch - $cy;
         if ($diff_cy_ch > $max_rec_size) {
             $ch = $ch - ($diff_cy_ch - $max_rec_size);
         }
     }
     $imagePathArray = array();
     $imageSizeUsingArray = $this->getSizeUsingArray();
     $imageSizeUsingArray_crop = array();
     foreach ($imageSizeUsingArray as $key => $value) {
         if ($value["type"] == "rect") {
             array_push($imageSizeUsingArray_crop, $value);
         }
     }
     if (sizeof($db_image_size_using) > 0) {
         foreach ($db_image_size_using as $key => $value) {
             if ($value["type"] == "rect") {
                 $is_foundExistName = false;
                 foreach ($imageSizeUsingArray_crop as $usingCropIndex => $usingCropRow) {
                     if ($value["name"] == $usingCropRow["name"]) {
                         $is_foundExistName = true;
                     }
                 }
                 if (!$is_foundExistName) {
                     array_push($imageSizeUsingArray_crop, $value);
                 }
             }
         }
     }
     $cropData = array();
     foreach ($imageSizeUsingArray_crop as $key => $value) {
         $crop_imagePath = $full_dirImage . $value["name"] . $imageData["image_file_name"];
         $resize_to = intval($value["width"]);
         $cropData = $this->cropAndResize($source_imagePath, $crop_imagePath, $cx, $cy, $cw, $ch, $resize_to);
     }
     $resultData = array();
     $resultData["cropData"] = $cropData;
     $resultData["imageData"] = $imageData;
     return $resultData;
 }
Example #23
0
 private function getNewFileId($fileData)
 {
     $insertData = array("file_id" => "", "server_id" => $this->current_server_id, "title" => $fileData["name"], "file_size" => $fileData["size"], "status" => 0, "create_time" => time(), "update_time" => time(), "ip_address" => $this->input->ip_address());
     $newFileId = $this->insert($insertData);
     if (!$newFileId) {
         $error = array("error" => "Cannot insert new file to database!");
         resDie($error, $this->methodPlace());
         exit;
     }
     return $newFileId;
 }
Example #24
0
 protected function resDie($dataArray = array())
 {
     resDie($dataArray, $this->methodName());
 }