/** * 运行程序 * */ function run() { $cotrollerName = $_GET['model']; $file = 'controller/' . $cotrollerName . '.php'; $modelFile = 'model/' . $cotrollerName . '.php'; if (is_file($file)) { include $file; include $modelFile; $cotroller = new $cotrollerName(); $actionName = $_REQUEST['action']; if (method_exists($cotroller, $actionName)) { //数据验证 防止网络篡改 $data = postData(); if (!$this->ValidData($data)) { $cotroller->outError("数据验证失败,请重新尝试!"); exit; } //客户端如果保存SessionId 重新初始化Session $sessionId = getPostSessionId(); if (isset($sessionId) && !is_null($sessionId)) { session_id($sessionId); session_start(); } $cotroller->{$actionName}(); } else { if (method_exists($cotroller, '_noAction')) { $cotroller->_noAction(); } else { throw new Exception('no Action'); } } } else { throw new Exception('no cotroller'); } }
function cart_list() { $data = array(); if (!isset($_SESSION['cart'])) { $data['error'] = 'Giỏ trống trơn!'; } else { $data['cart'] = $_SESSION['cart']; $fromDB = model('book')->getCartList($data['cart']); $merge = array(); foreach ($data['cart'] as $cart) { foreach ($fromDB as $value) { if (intval($value['id']) == $cart['book_id']) { $merge[] = array_merge($cart, $value); } } } //var_dump($merge); $data['merge'] = $merge; } //Submit cart if (isPostRequest()) { $postData = postData(); for ($i = 1; $i <= count($_SESSION['cart']); $i++) { foreach ($_SESSION['cart'] as $key => $cart) { if ($postData['bookid' . $i] == $cart['book_id']) { $_SESSION['cart'][$key]['quantity'] = $postData['quantity' . $i]; } } } redirect('index.php?c=bill&m=view'); } $data['template_file'] = 'cart/list.php'; render('layout.php', $data); }
function bill_detail() { $data = array(); $user = adminLogged(); if (!adminLogged()) { redirect('/index.php?c=admin&m=login'); } else { $bill_detail = model('bill')->getBillDetails($_GET['id']); $data['total'] = 0; foreach ($bill_detail as $key => $b) { $book = model('book')->getSingle($b['book_id']); $bill_detail[$key]['name'] = $book['name']; $bill_detail[$key]['price'] = intval($book['price']); $bill_detail[$key]['total'] = $book['price'] * $b['quantity']; $bill_detail[$key]['image'] = $book['image']; $data['total'] += $book['price'] * $b['quantity']; } $data['bill_detail'] = $bill_detail; } $data['statuses'] = array('Chờ duyệt', 'Đang giao hàng', 'Đã giao hàng', 'Hủy'); $data['stt'] = model('bill')->getOneBy($_GET['id'], null)['status']; if (isPostRequest()) { $postData = postData(); db_update('bills', $postData, 'id=' . $_GET['id']); $data['stt'] = $postData['status']; $data['error'] = 'Tình trạng đơn hàng update thành công.'; } $data['user'] = model('user')->getOneBy(model('bill')->getOneBy($_GET['id'], null)['user_id'], null); $data['template_file'] = 'bill/detail.php'; render('layout.php', $data); }
function remove_roles() { $ids = array(); foreach (postData() as $v) { $ids[] = new MongoId($v); } $where = array("_id" => array('$in' => $ids)); $result = $this->role->remove('roles', $where); echo $this->json->encode($result); }
function edit_channel() { $data = postData(); if (isset($_GET['channel_logId']) && !isset($data['channel_name'])) { exit; } //两次请求会添加两条的bug $data['channel_logId'] = new MongoId($_GET['channel_logId']); $result = $this->logistic->save('logistics_channels', $data); echo $this->json->encode($result); }
function news_add() { $data = array(); if (isPostRequest()) { $postData = postData(); $currentUser = isLogged(); if (model('news')->addToUser($postData, $currentUser['id'])) { redirect('index.php?c=news&m=list.php'); } } $data['template_file'] = 'news/add.php'; render('layout.php', $data); }
function test_feedback() { $data = array(); if (isPostRequest()) { $postData = postData(); $currentUser = isLogged(); // echo "<pre>";;var_dump($postData);die(); if (model('question')->addToUser($postData, $currentUser['id'])) { redirect('index.php?c=test&m=list'); } } $data['template_file'] = 'test/feedback.php'; render('test.php', $data); }
function admin_login() { $data = array(); if (isPostRequest()) { $postData = postData(); if (model('admin')->adminLogin($postData)) { redirect('/admin/index.php?c=bill&m=list'); } else { $data['error'] = 'Login failed! Please try again!'; } } $data['template_file'] = 'admin/login.php'; render('layout.php', $data); }
function auth_register() { sleep(1); $data = array(); if (isPostRequest()) { $postData = postData(); if (model('user')->aut_register($postData)) { redirect('/blogtaolao_MVC_/index.php'); } else { $data['error'] = 'Email đã tồn tại '; } } $data['template_file'] = 'auth/register.php'; render('layout.php', $data); }
function auth_register() { $data = array(); $data['template_file'] = 'auth/register.php'; if (isPostRequest()) { $postData = postData(); if (model('user')->authRegister($postData)) { redirect('index.php?c=payment&m=list'); } else { $data['error'] = 'Register failed ! Email exists ! Please try again !'; $data['postData'] = $postData; } } render('layout.php', $data); }
function blog_detail() { $id = $_GET['id']; if (isPostRequest()) { $postData = postData(); $currentUser = isLogged(); if (model('blog')->addComment($postData, $id)) { redirect('/index.php?c=blog&m=detail&id=' . $id); } } $data['blog_content'] = model('blog')->getOneBlog($id); $data['blog_comment'] = model('blog')->getAllComment($id); //var_dump($data);die; $data['template_file'] = 'blog/viewBlog.php'; render('layout.php', $data); }
function blog_update() { $data = array(); if (isPostRequest()) { $postData = postData(); $currentUser = isLogged(); if ($currentUser && model('entry')->update($postData, $_GET['entry'])) { redirect('/index.php?c=blog&m=list'); } } else { $data['single'] = model('entry')->getSingle($_GET['entry']); } $data['title'] = 'Chỉnh sửa bài viết'; $data['template_file'] = 'entry/add.php'; render('layout.php', $data); }
function auth_change_info() { $logged = isLogged(); $email = $logged['email']; $role = $logged['role']; if (isPostRequest()) { $postData = postData(); //var_dump($postData);die; if (model('user')->authChangeInfo($postData, $email, $role)) { redirect('/index.php?c=blog&m=list'); } } $data['user_info'] = model('user')->authGetInfo($email); //var_dump($data);die; $data['template_file'] = 'auth/change_info.php'; render('layout.php', $data); }
function book_list() { $data = array(); if (isset($_GET['pagenum'])) { $pagenum = $_GET['pagenum']; } else { $pagenum = 0; } $data['books'] = model('book')->get12($pagenum); if (model('book')->getCount() % 12 === 0) { $data['pages'] = intval(model('book')->getCount()) / 12; } else { $data['pages'] = intval(model('book')->getCount() / 12) + 1; } $data['pagenum'] = $pagenum; //Thêm vào giỏ hàng: if (isPostRequest()) { $postData = postData(); $id = intval($postData['aidi']); $quantity = intval($postData['quantity']); if ($quantity <= 0) { $data['info'] = 'Số lượng không đúng!'; } else { if (!isset($_SESSION['cart'])) { $_SESSION['cart'][0] = array('book_id' => $id, 'quantity' => $quantity); } else { $flag = false; foreach ($_SESSION['cart'] as $cart) { if ($cart['book_id'] === $id) { //$cart['quantity'] += $quantity; $flag = true; $data['info'] = 'Sách này đã có trong giỏ hàng!'; break; } } if ($flag == false) { $_SESSION['cart'][] = array('book_id' => $id, 'quantity' => $quantity); $data['info'] = 'Thêm sách vào giỏ hàng thành công!'; } } } } //var_dump($_SESSION['cart']); $data['template_file'] = 'book/list.php'; render('layout.php', $data); }
function send_tpl_msg($touser, $tpl_id, $url, $data, $access_token) { //发送模板消息: $post = array(); $post['touser'] = $touser; //openid; $post['template_id'] = $tpl_id; $post['url'] = $url; $post['data'] = $data; //数据; // print_r($post);exit; $data = json_encode($post); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$access_token}"; $result = postData($url, $data); // print_r($result);exit; $rs = json_decode($result, true); return $rs; }
function book_update() { $data = array(); if (isPostRequest()) { $postData = postData(); $currentUser = adminLogged(); if ($currentUser && model('book')->update($postData, $_GET['bookid'], $_SERVER['DOCUMENT_ROOT'] . '/images/') === 'success') { redirect('/admin/index.php?c=book&m=list'); } else { $data['error'] = model('book')->update($postData, $_GET['bookid'], $_SERVER['DOCUMENT_ROOT'] . '/images/'); $data['single'] = model('book')->getSingle($_GET['bookid']); } } else { $data['single'] = model('book')->getSingle($_GET['bookid']); $_SESSION['oldImage'] = $data['single']['image']; } $data['title'] = 'Chỉnh sửa sách'; $data['template_file'] = 'book/add.php'; render('layout.php', $data); }
function bill_view() { $data = array(); if (!isset($_SESSION['cart'])) { redirect('index.php?c=cart&m=list'); } else { $data['cart'] = $_SESSION['cart']; $fromDB = model('book')->getCartList($data['cart']); $merge = array(); foreach ($data['cart'] as $cart) { foreach ($fromDB as $value) { if (intval($value['id']) == $cart['book_id']) { $merge[] = array_merge($cart, $value); } } } $total = 0; foreach ($merge as $m) { $total += $m['quantity'] * $m['price']; } $data['total'] = $total; } if (isLogged()) { $data['user'] = $_SESSION['logged']; } if (isset($_GET['update'])) { $data['update'] = 1; } if (isPostRequest()) { $postData = postData(); if (model('user')->update($postData, $postData['email'])) { $data['user'] = model('user')->getOneBy($postData['email'], 'email'); unset($data['user']['password']); $_SESSION['logged'] = $data['user']; unset($_GET['update']); redirect('index.php?c=bill&m=view'); } } $data['template_file'] = 'bill/view.php'; render('layout.php', $data); }
function product_update() { $id = $_POST['id']; if (isset($_POST['update'])) { $data['product_object'] = model('product')->getOne($id); //var_dump($data);die; $data['template_file'] = 'product/update.php'; render('layout.php', $data); } if (isset($_POST['saveUpdate'])) { unset($_POST['saveUpdate']); $postData = postData(); if ($_FILES["fileImage"]['name'] != "") { $postData['image'] = uploadImage(); deleteImage($_POST['image']); } if (model('product')->updateProduct($postData, $id)) { redirect('/index.php?c=product&m=list'); } } }
function auth_register() { $data = array(); $data['template_file'] = 'auth/register.php'; if (isPostRequest()) { $postData = postData(); if ($postData['status'] == 'on') { $postData['status'] = 1; } else { $postData['status'] = 0; exit; } if (model('user')->authRegister($postData)) { redirect('index.php?c=post&m=list'); } else { $data['error'] = 'Register failed ! Email exists ! Please try again !'; $data['postData'] = $postData; } } $data['category'] = model('category')->getAllBycategory(); render('layout.php', $data); }
function login() { $checkimg = $_SESSION["checkimg"]; $data = postData(); if (strtolower($data["checkimg"]) != strtolower($_SESSION["checkimg"])) { $this->outError("验证码错误."); exit; } $user = $this->user->find("users", array("name" => $data['name'], 'password' => $data['password'])); if (!$user["success"]) { $this->outData($user); exit; } if ($user["count"] == 0) { $this->outError("用户名或密码错误."); exit; } $user_id = $user['data'][0]['_id']->{'$id'}; $where = array('code' => array('$in' => $user['data'][0]['roles'])); $roles = $this->user->find('roles', $where); if (!$roles["success"]) { $this->outData($roles); exit; } if ($roles["count"] == 0) { $this->outError("用户权限异常"); exit; } $permissions = array(); foreach ($roles["data"] as $value) { $permissions = array_merge($value['permissions'], $permissions); } $permissions = array_unique($permissions); $this->user->redis_set(CFG_REDIS_PERMISSIONS_KEY . $user_id, json_encode($permissions)); $tempUser = $user['data'][0]; $tempUser["permissions"] = $permissions; $this->outSuccessData($tempUser); }
function _paymentStandard() { $module_display = 'gocoin'; $sts_default = MODULE_PAYMENT_GOCOIN_DEFAULT_ORDER_STATUS_ID; // Default $sts_processing = MODULE_PAYMENT_GOCOIN_ORDER_STATUS_ID; // Processing $access_token = MODULE_PAYMENT_GOCOIN_ACCESS_KEY; if (isset($access_token) && empty($access_token)) { $error_msg[] = 'API Key is Blank'; osLog('GoCoin Callback', 'API Key is Blank'); } $module_display = 'gocoin'; $data = postData(); if (isset($data->error)) { osLog('GoCoin Callback', $data->error); } else { $key = $access_token; $event_id = $data->id; $event = $data->event; $invoice = $data->payload; $payload_arr = get_object_vars($invoice); ksort($payload_arr); $signature = $invoice->user_defined_8; $sig_comp = sign($payload_arr, $key); $status = $invoice->status; $order_id = (int) $invoice->order_id; $order_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $order_id . "' and class = 'ot_total' limit 1"); if (isset($signature) && $signature != $sig_comp) { $msg = "Signature : " . $signature . "does not match for Order: " . $order_id . "{$sig_comp} | {$signature} "; $msg .= ' Event ID: ' . $event_id; osLog('GoCoin Callback', $msg); } elseif (empty($signature) || empty($sig_comp)) { $msg = "Signature is blank for Order: " . $order_id; $msg .= ' Event ID: ' . $event_id; osLog('GoCoin Callback', $msg); } elseif (tep_db_num_rows($order_query) > 0) { switch ($event) { case 'invoice_created': break; case 'invoice_payment_received': switch ($status) { case 'ready_to_ship': $msg = 'Order ' . $order_id . ' is paid and awaiting payment confirmation on blockchain.'; $msg .= " Price (Currency) : " . $invoice->price . "(" . $invoice->price_currency . ")"; $msg .= ' Event ID: ' . $event_id; updateOrderstatus($order_id, $sts_default, $msg); break; case 'paid': $msg = 'Order ' . $order_id . ' is paid and awaiting payment confirmation on blockchain.'; $msg .= " Price (Currency) : " . $invoice->price . "(" . $invoice->price_currency . ")"; $msg .= ' Event ID: ' . $event_id; updateOrderstatus($order_id, $sts_default, $msg); break; case 'underpaid': $msg = 'Order ' . $order_id . ' is underpaid.'; $msg .= " Price (Currency) : " . $invoice->price . "(" . $invoice->price_currency . ")"; $msg .= ' Event ID: ' . $event_id; updateOrderstatus($order_id, $sts_default, $msg); break; } break; case 'invoice_merchant_review': $msg = 'Order ' . $order_id . ' is under review. Action must be taken from the GoCoin Dashboard.'; $msg .= " Price (Currency) : " . $invoice->price . "(" . $invoice->price_currency . ")"; $msg .= ' Event ID: ' . $event_id; updateOrderstatus($order_id, $sts_default, $msg); break; case 'invoice_ready_to_ship': $msg = 'Order ' . $order_id . ' has been paid in full and confirmed on the blockchain.'; $msg .= " Price (Currency) : " . $invoice->price . "(" . $invoice->price_currency . ")"; $msg .= ' Event ID: ' . $event_id; updateOrderstatus($order_id, $sts_processing, $msg); break; case 'invoice_invalid': $msg = 'Order ' . $order_id . ' is invalid and will not be confirmed on the blockchain.'; $msg .= " Price (Currency) : " . $invoice->price . "(" . $invoice->price_currency . ")"; $msg .= ' Event ID: ' . $event_id; updateOrderstatus($order_id, $sts_default, $msg); break; default: $msg = "Unrecognized event type: " . $event; } } } }
/** * Get the ID of the project to use, creating it if appropriate. * Will call bounce if it experiences an error. * @return Project ID to use, or null if no project, or false if there was an * error. */ function getProjectId(&$tracks, &$action) { if (empty($action->project)) { return null; } $rawxml = getData($tracks, 'projects.xml'); if ($rawxml === false) { return false; } $xml = new SimpleXMLElement($rawxml); foreach ($xml->project as $project) { $name = $project->name; $name = "{$name}"; // Just to be sure. if (strcasecmp($name, $action->project) == 0) { return (int) $project->id; } } if ($action->createProject) { return postData($tracks, 'projects.xml', '<project><name>' . xmlentities($action->project) . '</name></project>'); } if ($tracks->finiky) { bounce($tracks, $action, 'Unknown project: ' . $action->project); return false; } return null; }
public function deletePost($id_post) { $query = "DELETE posts WHERE id_post = {$id_post}"; $rows = postData($query, "delete"); return $rows; }
function product_edit() { $data = array(); // kiểm tra login checkaut(); // bắt dữ id bài viết cần chỉnh sửa // $Currentproduct = empty($_GET['id']) ? null : strtolower($_GET['id']); if (!model('product')->check_true($Currentproduct, 'product_id')) { $msg = "sản phẩm không tồn tại!!"; abort($msg); } $data['products'] = model('product')->getOneBy($Currentproduct, 'product_id'); // lưu bài viết đã chỉnh sửa if (isPostRequest()) { $recheck = false; $postData = postData(); if (is_uploaded_file($_FILES['product_image']['tmp_name'])) { // lấy id cao nhất của product rồi+1 -> đặt tên cho image k bị trùng $id = $Currentproduct; // $FileName = $_FILES['product_image']['name']; $pos = strrpos($FileName, "."); $FileExtension = substr($FileName, $pos); $images = "../BlogTaolao_MVC_/images/product_{$id}" . $FileExtension; if (move_uploaded_file($_FILES['product_image']['tmp_name'], $images)) { // tạo data image cho file hình $postData['product_image'] = $images; $recheck = true; } else { $msg = "Không thể up hình!!"; abort($msg); } } if (model('product')->update($postData, $Currentproduct) >= 1) { redirect('/blogtaolao_MVC_/index.php?c=product&m=list'); } elseif ($recheck == true) { redirect('/blogtaolao_MVC_/index.php?c=product&m=list'); } } $data['template_file'] = 'product/edit.php'; render('layout.php', $data); }
function edit_logistics_category_channels() { $data = postData(); $result = $this->channel->save('logistics_category_channels', $data); echo $this->json->encode($result); }
public static function deleteProduct($product_id) { $query = "DELETE product WHERE product_id = {$product_id}"; $rows = postData($query, "delete"); return $rows; }
* User: kopa * Date: 16/1/29 * Time: 下午11:10 */ require_once '../include.php'; $access_token = $_SESSION['access_token']; //print_r($access_token); //获取用户opnid $open_Id = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$access_token}&openid=OPENID&lang=zh_CN"; $Get_openId = file_get_contents($open_Id); var_dump($Get_openId); //var_dump($post_url); //发送模板消息 $url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token={$access_token}"; $tpl_Id = trim('ONTzJifq38XoFfzrMBKrhm-MvGbDgRc4uo_0hHoEWOY'); $post_url = postData($url, $tpl_Id); function postData($url, $data) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); if (!empty($data)) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output;
function getSongUrl($strURL, $sid) { return postData($strURL, $sid); }
function news_addDb() { $data = array(); if (isLogged()) { if (isPostRequest()) { $postData = postData(); $currentUser = isLogged(); if (model('dichbenh')->addToUser($postData, $currentUser['id'])) { redirect('index.php?c=news&m=dichbenh'); } } } else { $data['error'] = 'Vui lòng đăng nhập !!!'; } $data['template_file'] = 'news/addDb.php'; render('layout.php', $data); }
function edit() { $data = postData(); $result = $this->merchant->save('merchants', $data); echo $this->json->encode($result); }