function read($tableName, $id) { $id = (int) $id; $result = listRecords($tableName, sprintf('`id`=\'%s\'', $id)); if ($result === false || count($result) !== 1) { return false; } return $result[0]; }
function generatePayload($ws_client_url, $service, $service_name, $parameters, $xsl) { global $debug, $defFile; //die($service_name." - ".$service); switch ($service_name) { case "Identify": $response = listRecords($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false); break; case "ListMetadataFormats": $response = getAbstractArticle($set = $parameters["pid"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false); break; case "ListIdentifiers": $response = listRecords($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false, $metadataprx = $parameters["metadataprefix"]); break; case "ListSets": $response = getTitles($lang = "en", $debug = false); break; case "ListRecords": $response = ListRecords($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false, $metadataprx = $parameters["metadataprefix"]); break; case "ListRecordsAgris": $response = ListRecordsAgris($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 100, $debug = false, $metadataprx = $parameters["metadataprefix"]); break; case "GetRecord": $response = getAbstractArticle($pid = $parameters["pid"], $lang = "en", $ws = $parameters["ws_oai"], $debug = false); break; case "GetRecordAgris": $response = getAbstractArticleAgris($pid = $parameters["pid"], $lang = "en", $ws = $parameters["ws_oai"], $debug = false); break; } #workaround for fatal error in DOMDocument::loadXML() when XML have & character $response = preg_replace('/ & /', ' & ', $response); if (!$debug) { $transform = new XSLTransformerOAI(); $transform->setXslBaseUri($defFile["PATH_OAI"]); $transform->setXslFile($defFile["PATH_OAI"] . $xsl); $transform->setXml($response); $transform->transform(); if ($transform->getError()) { echo "XSL Transformation error\n"; echo $transform->getError(); exit; } $result = $transform->getOutput(); } return $result; }
getRecord($identifier, $methodology, $fullpath); } break; case "Identify": print headXML($verb); print identify(); $error = false; break; case "ListIdentifiers": if ($error == false) { $dataModel = new $methodology(); listRecords($metadataPrefix, $methodology); } break; case "ListSets": listRecords($metadataPrefix, $methodology); break; case "ListMetadataFormats": print headXML($verb); print listMetadataFormats(); $error = false; break; default: $verb = ""; $errorMsg = "Illegal OAI verb"; $errorCode = "badVerb"; } } //If have errors, show message if ($errorMsg && $error == true) { print verbError($verb, $errorMsg, $errorCode);
echo $newmode; ?> " method="post"> Category Name: <input type="text" name="name" value="<?php echo $row['name']; ?> " size="50" maxlength="100" /><br /> <input name="butSubmit" type="submit" value="Enter Record" /> </form> <?php break; case 'DELETE': if (!isset($id)) { // no id present, display error echo 'No id present.'; } else { // process delete $query = "DELETE FROM categories WHERE id = '{$id}'"; if (!($result = mysql_query($query))) { // error during delete echo "Error processing query {$query}"; } else { // successful delete echo 'Record successfully deleted.'; listRecords(); } } break; } include 'footer.php';
function main() { //1 خواندن محصولات داخل سبد از پایگاه داده در حالت For Update //if(isset($_POST['submit'])){ if (!isset($_SESSION['cart']) || count($_SESSION['cart']) == 0) { // خالی بودن سبد خرید $url = BASE_URL; return array('redirect' => $url); } dbQuery('START TRANSACTION;'); $productIds = array_keys($_SESSION['cart']); $temp = implode(',', $productIds); $products = listRecords('products', sprintf('`id` IN (%s)', $temp), null, null, true); //2 چک کردن کفایت موجودی محصول if (count($products) !== count($_SESSION['cart'])) { // نمایش پیغام خطا برای برابر نبودن سبد خرید return; } $subtotal = 0; $orderDetailsData = array(); $productUpdateData = array(); $stockData = array(); $currentTimeStamp = date('Y-m-d H:i:s'); foreach ($products as $product) { $stock = (int) $product['product_stock']; $id = $product['id']; if ($product['product_is_saleable'] == '0' || $stock < $_SESSION['cart'][$id]) { //@ToDo نمایش پیغام خطا مقدار موجودی کمتر هست - ارسال به سبد خرید //@ToDo Advance : تمام آیتم ها بررسی شود بعد ارسال شود return; } $orderDetailsData[] = array('order_id' => '', 'product_id' => $id, 'product_count' => $_SESSION['cart'][$id], 'product_price' => $product['product_price']); $productUpdateData[$id] = array('product_stock' => array(CRUD_MODIFY => -$_SESSION['cart'][$id]), 'product_number_sold' => array(CRUD_MODIFY => $_SESSION['cart'][$id])); $newStockValue = $stock - $_SESSION['cart'][$id]; $stockData[] = array('product_id' => $id, 'stock_date' => $currentTimeStamp, 'stock_type' => 0, 'stock_detail' => sprintf('کاهش %d واحد از موجودی. تغییر موجودی از %d به %d. بابت سفارش شماره:', $_SESSION['cart'][$id], $stock, $newStockValue), 'stock_count' => $newStockValue); $subtotal += (int) $product['product_price'] * (int) $_SESSION['cart'][$id]; } //3 ایجاد رکورد جدید در جدول Order $userId = 1; //GetUserId() $discount = 0; // $address = 'Noaddress'; //read from Form $order = array('customer_id' => $userId, 'order_date' => $currentTimeStamp, 'order_subtotal' => $subtotal, 'order_discount' => $discount, 'order_address' => $address); $orderId = create('orders', $order); if ($orderId === false) { // نمایش پیغام خطا - سفارش ثبت نشد dbQuery('ROLLBACK'); return; // ارسال به صفحه کارت } //4 کاهش موجودی و ایجاد رکورد جدید در جدول stock foreach ($orderDetailsData as $key => $item) { $orderDetailsData[$key]['order_id'] = $orderId; } foreach ($stockData as $key => $item) { $stockData[$key]['stock_detail'] .= " {$orderId}"; } if (!massUpdate('products', array('product_stock', 'product_number_sold'), $productUpdateData)) { // نمایش پیغام خطا - سفارش ثبت نشد dbQuery('ROLLBACK'); return; // ارسال به صفحه کارت } if (!massCreate('stocks', array('product_id', 'stock_date', 'stock_type', 'stock_detail', 'stock_count'), $stockData)) { // نمایش پیغام خطا - سفارش ثبت نشد dbQuery('ROLLBACK'); return; // ارسال به صفحه کارت } //5 ایجاد رکورد های متناظر در جدول order_detail if (!massCreate('order_detail', array('order_id', 'product_id', 'product_count', 'product_price'), $orderDetailsData)) { // نمایش پیغام خطا - سفارش ثبت نشد dbQuery('ROLLBACK'); return; // ارسال به صفحه کارت } dbQuery('COMMIT'); // خالی کردن سبد تولید پیغام مناسب فرستادن مشتری به صفحه مناسب unset($_SESSION['cart']); addMessage(sprintf('سفارش شما با موفقیت ایجاد شد، شماره سفارش: %d', $orderId), SUCSESS); // currently we redirect the user to the homepage but later we will send him/her to payment or order history page return array('redirect' => BASE_URL); // } // isset submit }
function main() { $resp = array(); if (isset($_POST['submit'])) { $productData = array('product_name' => isset($_POST['product_name']) ? $_POST['product_name'] : null, 'category_id' => isset($_POST['product_category']) ? (int) $_POST['product_category'] : null, 'product_is_saleable' => isset($_POST['product_is_saleable']) ? (int) $_POST['product_is_saleable'] : null, 'product_price' => isset($_POST['product_price']) ? (int) $_POST['product_price'] : null, 'product_stock' => isset($_POST['product_stock']) ? (int) $_POST['product_stock'] : null, 'product_brand' => isset($_POST['product_brand']) ? (int) $_POST['product_brand'] : null, 'product_gender' => isset($_POST['product_gender']) ? (int) $_POST['product_gender'] : null, 'product_color' => isset($_POST['product_color']) ? $_POST['product_color'] : null, 'product_cloth_type' => isset($_POST['product_cloth_type']) ? $_POST['product_cloth_type'] : null, 'product_made_in' => isset($_POST['product_made_in']) ? (int) $_POST['product_made_in'] : null, 'product_description' => isset($_POST['product_description']) ? $_POST['product_description'] : null); //TODO implement dedicated validation checks for every piece of data rather than following simple test $dataIsCorrect = true; foreach ($productData as $pieceOfData) { if (is_null($pieceOfData)) { addMessage('اطلاعات محصول به درستی وارد نشده است', FAILURE); $dataIsCorrect = false; break; } } // Handling product picture $pictureHandlingResult = handleProductPictureUpload(); if (is_string($pictureHandlingResult)) { $productData['product_picture_name'] = $pictureHandlingResult; } if ($dataIsCorrect && $pictureHandlingResult !== false && create('products', $productData)) { addMessage(sprintf('"%s" با موفقیت ایجاد شد', htmlentities($productData['product_name'], ENT_QUOTES, 'UTF-8')), SUCSESS); return array('redirect' => BASE_URL . 'admin/product/list.php'); } elseif ($dataIsCorrect) { addMessage('خطا در ذخیره سازی محصول', FAILURE); } } $tempCategories = listRecords('categories'); $categories = array(); foreach ($tempCategories as $category) { $categories[$category['id']] = $category['category_name']; } //TODO consider a table or config file for country $tempCountries = listRecords('countries'); $countries = array(); foreach ($tempCountries as $country) { $countries[$country['id']] = $country['country_name']; } /* * Load Brands */ $tempBrands = listRecords('brands'); $brands = array(); foreach ($tempBrands as $brand) { $brands[$brand['id']] = $brand['brand_name']; } //TODO consider a table for OS // $oses=array( // 1=>'Windows', // 2=>'Android', // 3=>'IOS', // 4=>'Linux' // ); $resp['data'] = array('categories' => $categories, 'brands' => $brands, 'countries' => $countries, 'productData' => isset($productData) ? $productData : array()); return $resp; }
function generatePayload($ws_client_url, $service, $service_name, $parameters, $xsl) { global $debug, $defFile; //die($service_name." - ".$service); switch ($service_name) { case "Identify": $response = listRecords($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false); break; case "ListMetadataFormats": $response = getAbstractArticle($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false); break; case "ListIdentifiers": $response = listRecords($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false); break; case "ListSets": $response = getTitles($lang = "en", $debug = false); break; case "ListRecords": $response = ListRecords($set = $parameters["set"], $from = $parameters["from"], $until = $parameters["until"], $control = $parameters["control"], $lang = "en", $nrm = "iso", $count = 30, $debug = false); break; case "GetRecord": $response = getAbstractArticle($pid = $parameters["pid"], $lang = "en", $ws = $parameters["ws_oai"], $debug = false); break; } // $result = ""; if (!$debug) { $transform = new XSLTransformer(); if (getenv("ENV_SOCKET") != "true") { //socket $xsl = file_get_contents($defFile["PATH_OAI"] . $xsl); } else { $xsl = str_replace('.XSL', '', strtoupper($xsl)); } $transform->setXslBaseUri($defFile["PATH_OAI"]); $transform->setXsl($xsl); $transform->setXml($response); $transform->transform(); if ($transform->getError()) { // Transformation error echo "XSL Transformation error\n"; echo $transform->getError(); $transform->destroy(); exit; } $result = $transform->getOutput(); $transform->destroy(); } return $result; }