private static function HowManyPages($countSql, $countSqlParams) { // Create a hash for the sql query $queryHashCode = md5($countSql . var_export($countSqlParams, true)); // Verify if we have the query results in cache if (isset($_SESSION['last_count_hash']) && isset($_SESSION['how_many_pages']) && $_SESSION['last_count_hash'] === $queryHashCode) { // Retrieve the cached value $how_many_pages = $_SESSION['how_many_pages']; } else { // Execute the query $items_count = DatabaseHandler::GetOne($countSql, $countSqlParams); //Calculate the number of pages $how_many_pages = ceil($items_count / PRODUCTS_PER_PAGE); // Save the query and its count result in the session $_SESSION['last_count_hash'] = $queryHashCode; $_SESSION['how_many_pages'] = $how_many_pages; } // Return the number of pages return $how_many_pages; }
public static function ExpensesByContext() { $statement = FinancialStatements::ExpensesStatement($_GET['sid'], $_GET['period'], $_GET['all']); if ($_GET['sid'] != 0) { $supplier = Supplier::GetSupplier($_GET['sid']); $name = $supplier->name; } else { $name = 'OFFICE'; } echo ' <div class="logo"> <h5 style="margin-bottom:-15px;margin-top:0px;font-size:14px;">Date: ' . date('d/m/Y') . '</h5> <h4 style="text-transform:uppercase">' . $name . ' EXPENSES REPORT</h4>'; if ($_GET['period'] != '' && $_GET['period']) { echo '<h5 style="margin-top:-10px">Period: ' . $_GET['period'] . '</h5>'; } echo '</div> <table class="table table-bordered table-striped" style="text-align:center;margin-left:0;margin-right:0;width:760px;font-size:12px;"> <thead class="title"> <tr> <td>DATE</td> <td>TX ID</td> <td>LEDGER</td> <td>AMOUNT</td> <td>DESCRIPTION</td> <td>TX BY</td> </tr> </thead> <tbody>'; $total = 0.0; foreach ($statement as $item) { echo '<tr> <td style="width: 100px">' . $item['when_charged'] . '</td> <td style="width: 70px">' . $item['transaction_id'] . '</td> <td style="width: 100px">' . $item['ledger_name'] . '</td> <td style="width: 100px"><script>document.writeln((' . $item['amount'] . ').formatMoney(2, \'.\', \',\'));</script></td> <td style="width: 200px">' . $item['description'] . '</td>'; $sql = 'SELECT user FROM transactions WHERE id = ' . $item['transaction_id'] . ' LIMIT 0,1'; $result = DatabaseHandler::GetOne($sql); echo '<td style="padding: 0 5px;">' . $result . '</td> </tr>'; $total += $item['amount']; } echo '</tbody> </table> <div class="logo"> <p style="margin: 5px 0 0 5px">Total Expenses: <b>Ksh. <script>document.writeln((' . $total . ').formatMoney(2, \'.\', \',\'));</script></b></p> </div>'; }
public static function GetTotalAmount() { // Составляем SQL - запрос $sql = 'CALL shopping_cart_get_total_amount(:cart_id)'; // Создаем массив параметров $params = array(':cart_id' => self::GetCartId()); // Выполняем запрос и возвращаем результат return DatabaseHandler::GetOne($sql, $params); }
public static function RemoveProductFromCategory($productId, $categoryId) { // Build SQL query $sql = 'CALL catalog_remove_product_from_category( :product_id, :category_id)'; // Build the parameters array $params = array(':product_id' => $productId, ':category_id' => $categoryId); // Execute the query and return the results return DatabaseHandler::GetOne($sql, $params); }
public static function GetUserIdOauth($id) { // Build SQL query //$sql = 'CALL blog_get_comments_list(:blog_id)'; $sql = 'SELECT user_id FROM users WHERE oauth_uid = "' . $id . '"'; //return $sql; //$params = array(':blog_id' => $blogId); // Execute the query and return the results return DatabaseHandler::GetOne($sql); //return DatabaseHandler::Execute($sql); }
<?php require_once "../core/core.php"; $id = $_SESSION["MM_USER_ID"]; $email = DatabaseHandler::GetOne("SELECT email FROM `users` WHERE id = '{$id}' ; "); $imagePath = "upload/"; $allowedExts = array("gif", "jpeg", "jpg", "png", "GIF", "JPEG", "JPG", "PNG"); $temp = explode(".", $_FILES["img"]["name"]); $extension = end($temp); //Check write Access to Directory if (!is_writable($imagePath)) { $response = array("status" => 'error', "message" => 'Can`t upload File; no write Access'); print json_encode($response); return; } if (in_array($extension, $allowedExts)) { if ($_FILES["img"]["error"] > 0) { $response = array("status" => 'error', "message" => 'ERROR Return Code: ' . $_FILES["img"]["error"]); } else { $filename = $_FILES["img"]["tmp_name"]; list($width, $height) = getimagesize($filename); move_uploaded_file($filename, $imagePath . $_FILES["img"]["name"]); $email_hash = sha1($email); $newName = $imagePath . $email_hash . rand() . "." . $extension; rename($imagePath . $_FILES["img"]["name"], $newName); $response = array("status" => 'success', "url" => $newName, "width" => $width, "height" => $height); } } else { $response = array("status" => 'error', "message" => 'something went wrong, most likely file is to large for upload. check upload_max_filesize, post_max_size and memory_limit in you php.ini'); } print json_encode($response);
public static function GetVoucher($txid) { try { $sql = 'SELECT voucher_id FROM vouchers WHERE transaction_id = ' . $txid; $res = DatabaseHandler::GetOne($sql); $res2; if (!empty($res)) { $sql2 = 'SELECT * FROM payments WHERE id = ' . $res; $res2 = DatabaseHandler::GetRow($sql2); } if ($res2) { return self::initialize($res2); } else { Logger::Log('PaymentVoucher', 'Missing', 'Missing payment voucher for transaction id:' . $txid); return false; } } catch (Exception $e) { Logger::Log('PaymentVoucher', 'Exception', $e->getMessage()); } }
public static function CreateAccount($item, $packsize, $featured, $availability, $openstock, $optstock, $lowstock, $pprice, $rprice, $wprice, $tax) { if (!self::$ledger_loaded) { self::LoadLedger(); } $datetime = new DateTime(); $timestamp = $datetime->format('YmdHis'); $acname = $item->name . ' Account'; $account; $sqlone = 'SELECT * FROM stock_accounts WHERE name = "' . $acname . '" AND resource_id = ' . intval($item->itemId); $res = DatabaseHandler::GetRow($sqlone); if (empty($res)) { $today = new DateTime(); $today = $today->format('Y-m-d'); //$sql = 'UPDATE stock_accounts SET pack_size = '.$packsize.', featured = '.$featured.', availability = '.$availability.', available_bal = '.$openstock.', actual_bal = '.$openstock.', optimum_bal = '.$optstock.', low_bal = '.$lowstock.', timestamp = '.$timestamp.' WHERE resource_id = '.$item->itemId; $sql = 'INSERT INTO stock_accounts (name, resource_id, unit_id, stock_bal, catalog_bal, low_bal, optimum_bal, cost_price, retail_price, wholesale_price, vat_code, ledger_id, pack_size, featured, availability, date_added, tstamp) VALUES ("' . $acname . '", ' . intval($item->itemId) . ', ' . intval($item->unit->unitId) . ', ' . $openstock . ', ' . $openstock . ', ' . $lowstock . ', ' . $optstock . ', ' . $pprice . ', ' . $rprice . ', ' . $wprice . ', ' . $tax . ', ' . intval(self::$ledgerId) . ', ' . $packsize . ', ' . $featured . ', ' . $availability . ', "' . $today . '", "' . $timestamp . '")'; DatabaseHandler::Execute($sql); //do something as an inventory objects $sql1 = 'SELECT account_id FROM stock_accounts ORDER BY tstamp DESC LIMIT 0,1'; //replace with more flexible for distributed env $account_id = DatabaseHandler::GetOne($sql1); $availstock = $openstock; $actualstock = $openstock; return new StockAccount($account_id, $item, $packsize, $featured, $availability, $availstock, $actualstock, $optstock, $lowstock, $pprice, $rprice, $wprice, $tax, $today, $timestamp); } else { return new StockAccount($res['account_id'], $item, $res['pack_size'], $res['featured'], $res['availability'], $res['catalog_bal'], $res['stock_bal'], $res['optimum_bal'], $res['low_bal'], $res['cost_price'], $res['retail_price'], $res['wholesale_price'], $res['vat_code'], $res['date_added'], $res['tstamp']); } }
private function processLatestEnquiries() { try { $sql = 'SELECT stamp FROM enquiries WHERE status = 0 ORDER BY stamp DESC LIMIT 0,5'; $res = DatabaseHandler::GetAll($sql); $sql2 = 'SELECT count(*) FROM enquiries WHERE status = 0'; $res2 = DatabaseHandler::GetOne($sql2); $enquiries = []; foreach ($res as $enquiry) { $enquiries[] = Enquiry::GetEnquiry($enquiry['stamp']); } $obj = new stdClass(); $obj->enquiries = $enquiries; $obj->total = $res2; $this->latestEnquiries = $obj; } catch (Exception $e) { } }
public static function Authorize($email, $password) { // Build SQL query //$sql = 'CALL blog_get_comments_list(:blog_id)'; $sql = 'SELECT id FROM customers WHERE email = "' . $email . '" AND password = sha1("' . $password . '")'; // Execute the query and return the results $id = DatabaseHandler::GetOne($sql); if ($id) { //initiate global $_SESSION variables return self::get($id); } else { return false; } }
public function initialize(Order $order) { $this->order = $order; if (!empty($this->buyer) && !empty($this->seller)) { parent::__construct($this->buyer, $this->seller, new ConnectedAccountabilityType('Sale Agreement')); $this->type->addConnectionRule($this->parent->type, $this->child->type); //save to db try { $sql = 'INSERT INTO accountabilities (name, parent_id, child_id, datetime, startstamp, status) VALUES ("' . $this->type->name . '",' . $this->parent->id . ', ' . $this->child->id . ', "' . $this->datetime . '", ' . $this->startstamp . ', "Opened")'; DatabaseHandler::Execute($sql); $sql = 'SELECT id FROM accountabilities WHERE startstamp = ' . $this->startstamp; $res = DatabaseHandler::GetOne($sql); $this->id = $res; $sql = 'INSERT INTO accountability_features (accountability_id, attribute, value) VALUES (' . $this->id . ', "orderId", "' . $this->order->id . '")'; DatabaseHandler::Execute($sql); } catch (Exception $e) { } } }
$title_en = $_POST['title_en']; $image = $_POST["image"]; $text = $_POST['text']; $source = $_POST['source']; $video = $_POST['video']; $description = $_POST['description']; $keywords = $_POST['keywords']; $read_time = $_POST['read_time']; $admin_id = $_SESSION['MM_admin_id']; $hit_count = 0; $add_time = time(); $modify_time = 0; $activate = 0; $insert_blog = BLOGS::blogs_Insert($title, $title_en, $image, $text, $source, $video, $description, $read_time, $hit_count, $admin_id, $add_time, $modify_time, $activate); if ($insert_blog) { $blog_id = DatabaseHandler::GetOne("SELECT `id` FROM blogs WHERE `add_time` = '{$add_time}' ; "); $keywords = explode(",", $keywords); foreach ($keywords as $keyword) { $keyword = trim($keyword); BLOG_KEYWORDS::blog_keywords_Insert($blog_id, $keyword); } if (isset($_POST['types'])) { $types = $_POST['types']; foreach ($types as $type) { $type = explode("-", $type); B_T::b_t_Insert($blog_id, $type['1']); } } if (isset($_POST['subjects'])) { $subjects = $_POST['subjects']; foreach ($subjects as $subject) {
public function GetCountAllLevel($post_id) { $params[] = intval($post_id); $sql = 'SELECT MAX(levl) FROM coments WHERE post_id = ?'; $arr = DatabaseHandler::GetOne($sql, $params); return $arr; }
public static function SupplierStatement($sid, $dates, $all) { if ($all == 'true') { $sql = 'SELECT * FROM general_ledger_entries WHERE account_no = ' . intval($sid) . ' AND ledger_name = "Creditors" ORDER BY id DESC'; } else { if ($dates != '') { $split = explode(' - ', $dates); $d1 = explode('/', $split[0]); $d2 = explode('/', $split[1]); $lower = $d1[2] . $d1[1] . $d1[0] . '000000' + 0; $upper = $d2[2] . $d2[1] . $d2[0] . '999999' + 0; $sql = 'SELECT * FROM general_ledger_entries WHERE account_no = ' . intval($sid) . ' AND ledger_name = "Creditors" AND stamp BETWEEN ' . $lower . ' AND ' . $upper . ' ORDER BY id DESC'; } } try { $result = DatabaseHandler::GetAll($sql); foreach ($result as &$tx) { $sql2 = 'SELECT type FROM transactions WHERE id = ' . intval($tx['transaction_id']); $res = DatabaseHandler::GetOne($sql2); $tx['type'] = $res; if ($tx['effect'] == 'dr') { $sql3 = 'SELECT voucher_id FROM vouchers WHERE transaction_id = ' . intval($tx['transaction_id']); $res3 = DatabaseHandler::GetOne($sql3); $sql4 = 'SELECT * FROM payments WHERE id = ' . $res3; $res4 = DatabaseHandler::GetRow($sql4); if (strpos($tx['description'], 'Reversal') !== false) { $tx['descr'] = $tx['description']; } else { $tx['descr'] = $res4['voucher_no']; } } else { $sql3 = 'SELECT voucher_id FROM vouchers WHERE transaction_id = ' . intval($tx['transaction_id']); $res3 = DatabaseHandler::GetOne($sql3); $sql4 = 'SELECT * FROM purchase_invoices WHERE id = ' . $res3; $res4 = DatabaseHandler::GetRow($sql4); if (strpos($tx['description'], 'Reversal') !== false) { $tx['descr'] = $tx['description']; } else { $tx['descr'] = 'Invoice no: ' . $res4['invno']; } } } return $result; } catch (Exception $e) { } }