function getPeriods($yr, $mo, $account, $dimension, $dimension2, $balance = false) { //$begin = date2sql(begin_fiscalyear()); $date13 = date('Y-m-d', mktime(0, 0, 0, $mo + 12, 1, $yr)); $date12 = date('Y-m-d', mktime(0, 0, 0, $mo + 11, 1, $yr)); $date11 = date('Y-m-d', mktime(0, 0, 0, $mo + 10, 1, $yr)); $date10 = date('Y-m-d', mktime(0, 0, 0, $mo + 9, 1, $yr)); $date09 = date('Y-m-d', mktime(0, 0, 0, $mo + 8, 1, $yr)); $date08 = date('Y-m-d', mktime(0, 0, 0, $mo + 7, 1, $yr)); $date07 = date('Y-m-d', mktime(0, 0, 0, $mo + 6, 1, $yr)); $date06 = date('Y-m-d', mktime(0, 0, 0, $mo + 5, 1, $yr)); $date05 = date('Y-m-d', mktime(0, 0, 0, $mo + 4, 1, $yr)); $date04 = date('Y-m-d', mktime(0, 0, 0, $mo + 3, 1, $yr)); $date03 = date('Y-m-d', mktime(0, 0, 0, $mo + 2, 1, $yr)); $date02 = date('Y-m-d', mktime(0, 0, 0, $mo + 1, 1, $yr)); $date01 = date('Y-m-d', mktime(0, 0, 0, $mo, 1, $yr)); if (!$balance) { $sql = "SELECT SUM(CASE WHEN tran_date >= '{$date01}' AND tran_date < '{$date02}' THEN amount ELSE 0 END) AS per01,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date02}' AND tran_date < '{$date03}' THEN amount ELSE 0 END) AS per02,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date03}' AND tran_date < '{$date04}' THEN amount ELSE 0 END) AS per03,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date04}' AND tran_date < '{$date05}' THEN amount ELSE 0 END) AS per04,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date05}' AND tran_date < '{$date06}' THEN amount ELSE 0 END) AS per05,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date06}' AND tran_date < '{$date07}' THEN amount ELSE 0 END) AS per06,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date07}' AND tran_date < '{$date08}' THEN amount ELSE 0 END) AS per07,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date08}' AND tran_date < '{$date09}' THEN amount ELSE 0 END) AS per08,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date09}' AND tran_date < '{$date10}' THEN amount ELSE 0 END) AS per09,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date10}' AND tran_date < '{$date11}' THEN amount ELSE 0 END) AS per10,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date11}' AND tran_date < '{$date12}' THEN amount ELSE 0 END) AS per11,\n\t\t \t\tSUM(CASE WHEN tran_date >= '{$date12}' AND tran_date < '{$date13}' THEN amount ELSE 0 END) AS per12\n \t\t\tFROM " . TB_PREF . "gl_trans\n\t\t\t\tWHERE account='{$account}'"; } else { $sql = "SELECT SUM(CASE WHEN tran_date < '{$date02}' THEN amount ELSE 0 END) AS per01,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date03}' THEN amount ELSE 0 END) AS per02,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date04}' THEN amount ELSE 0 END) AS per03,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date05}' THEN amount ELSE 0 END) AS per04,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date06}' THEN amount ELSE 0 END) AS per05,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date07}' THEN amount ELSE 0 END) AS per06,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date08}' THEN amount ELSE 0 END) AS per07,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date09}' THEN amount ELSE 0 END) AS per08,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date10}' THEN amount ELSE 0 END) AS per09,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date11}' THEN amount ELSE 0 END) AS per10,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date12}' THEN amount ELSE 0 END) AS per11,\n\t\t \t\tSUM(CASE WHEN tran_date < '{$date13}' THEN amount ELSE 0 END) AS per12\n \t\t\tFROM " . TB_PREF . "gl_trans\n\t\t\t\tWHERE account='{$account}'"; } if ($dimension != 0) { $sql .= " AND dimension_id = " . ($dimension < 0 ? 0 : db_escape($dimension)); } if ($dimension2 != 0) { $sql .= " AND dimension2_id = " . ($dimension2 < 0 ? 0 : db_escape($dimension2)); } $result = db_query($sql, "Transactions for account {$account} could not be calculated"); return db_fetch($result); }
function sConfig($key, $value) { $key = db_escape($key); $value = db_escape($value); $sql = "REPLACE INTO " . PREF . "config\n\t\tVALUE ('{$key}', '{$value}')"; query($sql); }
function getContactPerson($imc, $debtor_no, $branch_code) { $sql = "Select CONCAT (d.name, d.name2) AS contactName FROM " . TB_PREF . "cust_branch b INNER JOIN\n" . TB_PREF . "crm_contacts c on b.debtor_no=c.entity_id INNER JOIN " . TB_PREF . "crm_persons d on c.person_id=d.id where b.salesman = " . db_escape($imc) . "\n\tAND b.debtor_no = " . db_escape($debtor_no) . " AND b.branch_code = " . db_escape($branch_code) . ""; $result = db_query($sql, "could not get IMC"); $row = db_fetch_row($result); return $row[0]; }
/** * Database server contents (list of tables) * * @path: /ctl/$db_name * @accept: get * @view: db.database * **/ function database() { /* {{{ */ $this->tpl->add('tables', db_fetch_array('SHOW TABLES FROM `' . db_escape($this->db_name) . '`;')); $this->tpl->view('db.database'); /* }}} */ }
/** * Firstly, try to find controller class described in file * if not found, try initialize crud controller from database automatically * * @param string $controller - name on controller, interpreted in function * as part of filename or part of tablename * @return object controller **/ function get_controller_by_name($controller) { $ctrl_file = '../app/controller/' . $controller . '.php'; if (file_exists($ctrl_file)) { exec("echo 'Controller [{$GLOBALS['controller']}] loaded.' >> /tmp/weblog"); require_once $ctrl_file; #TODO: find way to make class name independ of file name $ctl_class_name = $controller . '_ctl'; if (!class_exists($ctl_class_name)) { exit; } $ctl = new $ctl_class_name(); } else { #TODO: add security restrictions (black/white lists) for crud cotroller #TODO: improve search algorythm (strict compare instead of "like '%name'") $table = db_fetch_value('show tables like "%' . db_escape($controller) . '"'); if ($table) { $ctl = new crud_ctl(); $ctl->table = $table; } else { exec("echo 'ERROR: Controller [{$controller}] not found (requested {$_SERVER['PATH_INFO']}).' >> /tmp/weblog"); die("<pre>Controller <strong>[{$controller}]</strong> not found.\n\n"); } } return $ctl; }
function get_sundry($customized) { $sql = "SELECT DISTINCT a.*, v.type from " . TB_PREF . "gl_trans a inner join " . TB_PREF . "customized b on a.type=b.type AND a.type_no=b.type_no\n LEFT JOIN " . TB_PREF . "voided v ON v.type = a.type and v.id=a.type_no\n where a.type=" . ST_DISBURSEMENT . " AND b.customized_no = " . db_escape($customized) . ""; //if ($imc != 0) // $sql .= " and ".TB_PREF."salesman.salesman_code =".db_escape($imc); //display_notification($sql); return db_query($sql, "No transactions were returned"); }
function getTransactions($supplier_id, $date) { $date = date2sql($date); $sql = "SELECT SUM((ov_amount+ov_discount)*rate) AS Turnover\n\t\tFROM " . TB_PREF . "supp_trans\n\t\tWHERE supplier_id=" . db_escape($supplier_id) . "\n\t\tAND (type=" . ST_SUPPINVOICE . " OR type=" . ST_SUPPCREDIT . ")\n\t\tAND tran_date >='{$date}'"; $result = db_query($sql, "No transactions were returned"); $row = db_fetch_row($result); return $row[0]; }
function getTransactions($debtorno, $branchcode, $date) { $date = date2sql($date); $sql = "SELECT SUM((ov_amount+ov_freight+ov_discount)*rate) AS Turnover\n\t\tFROM " . TB_PREF . "debtor_trans\n\t\tWHERE debtor_no=" . db_escape($debtorno) . "\n\t\tAND branch_code=" . db_escape($branchcode) . "\n\t\tAND (type=" . ST_SALESINVOICE . " OR type=" . ST_CUSTCREDIT . ")\n\t\tAND tran_date >='{$date}'"; $result = db_query($sql, "No transactions were returned"); $row = db_fetch_row($result); return $row[0]; }
function check_login(){ $user=db_easy("SELECT `name`, `password_hash` FROM `users` WHERE `name`='".db_escape(@$_POST['user'])."'"); if(generate_hash($user['name'], @$_POST['password'])==$user['password_hash']){ return true; }else{ return false; } }
function done() { $this->tpl->add('index', db_fetch_all(' SELECT * FROM ' . db_escape($this->table) . ' WHERE is_closed = 1 ORDER BY date_closed ')); }
/** * Handle on_user_cleanup event * * @param array $cleanup * @return null */ function discussions_handle_on_user_cleanup(&$cleanup) { if (!isset($cleanup['project_objects'])) { $cleanup['project_objects'] = array(); } // if $cleanup['project_objects'][] = array('id' => 'integer_field_1', 'name' => 'varchar_field_1', 'email' => 'varchar_field_2', 'condition' => 'type = ' . db_escape('Discussion')); }
function msg_send_simple_message($owners, $sender, $timestamp, $message_type, $from, $subject, $text, $escaped = false, $force = false) { global $config, $user, $sn_message_class_list; if (!$owners) { return; } $timestamp = $timestamp ? $timestamp : SN_TIME_NOW; $sender = intval($sender); if (!is_array($owners)) { $owners = array($owners); } if (!$escaped) { $from = db_escape($from); $subject = db_escape($subject); $text = db_escape($text); } $text_unescaped = stripslashes(str_replace(array('\\r\\n', "\r\n"), "<br />", $text)); $message_class = $sn_message_class_list[$message_type]; $message_class_email = $message_class['email']; $message_class_switchable = $message_class['switchable']; $message_class_name = $message_class['name']; $message_class_name_total = $sn_message_class_list[MSG_TYPE_NEW]['name']; if ($owners[0] == '*') { if ($user['authlevel'] < 3) { return false; } // TODO Добавить $timestamp - рассылка может быть и отсроченной // TODO Добавить $sender - рассылка может быть и от кого-то db_message_insert_all($message_type, $from, $subject, $text); $owners = array(); } else { $insert_values = array(); $insert_template = "('%u'," . str_replace('%', '%%', " '{$sender}', '{$timestamp}', '{$message_type}', '{$from}', '{$subject}', '{$text}')"); foreach ($owners as $owner) { if ($user['id'] != $owner) { $owner_row = db_user_by_id($owner); } else { $owner_row = $user; } sys_user_options_unpack($owner_row); if ($force || !$message_class_switchable || $owner_row["opt_{$message_class_name}"]) { $insert_values[] = sprintf($insert_template, $owner); } if ($message_class_email && $config->game_email_pm && $owner_row["opt_email_{$message_class_name}"]) { @($result = mymail($owner_row['email'], $subject, $text_unescaped, '', true)); } } if (empty($insert_values)) { return; } doquery($QryInsertMessage = 'INSERT INTO {{messages}} (`message_owner`, `message_sender`, `message_time`, `message_type`, `message_from`, `message_subject`, `message_text`) ' . 'VALUES ' . implode(',', $insert_values)); } db_user_list_set_mass_mail($owners, "`{$message_class_name}` = `{$message_class_name}` + 1, `{$message_class_name_total}` = `{$message_class_name_total}` + 1"); if (in_array($user['id'], $owners) || $owners[0] == '*') { $user[$message_class_name]++; $user[$message_class_name_total]++; } }
function get_sql_for_commission_voucher($imc, $invoice_no) { $sql = "SELECT a.imc, a.invoice_no, a.client, DATE_FORMAT(a.date, '%m-%d-%Y') as tranDate from " . TB_PREF . "comm_voucher a where a.imc= " . db_escape($imc) . ""; if ($invoice_no != 0) { $sql .= " and a.invoice_no =" . db_escape($invoice_no); } $sql .= " ORDER BY a.invoice_no"; return $sql; }
function getList($imc) { $sql = "SELECT a.* from " . TB_PREF . "cust_branch a"; if ($imc != 0) { $sql .= " where salesman =" . db_escape($imc); } $sql .= " ORDER BY a.salesman"; return db_query($sql, "Error getting order details"); }
function getTransactions($fromsupp) { $sql = "SELECT " . TB_PREF . "grn_batch.id,\n\t\t\torder_no,\n\t\t\t" . TB_PREF . "grn_batch.supplier_id,\n\t\t\t" . TB_PREF . "suppliers.supp_name,\n\t\t\t" . TB_PREF . "grn_items.item_code,\n\t\t\t" . TB_PREF . "grn_items.description,\n\t\t\tqty_recd,\n\t\t\tquantity_inv,\n\t\t\tstd_cost_unit,\n\t\t\tact_price,\n\t\t\tunit_price\n\t\tFROM " . TB_PREF . "grn_items,\n\t\t\t" . TB_PREF . "grn_batch,\n\t\t\t" . TB_PREF . "purch_order_details,\n\t\t\t" . TB_PREF . "suppliers\n\t\tWHERE " . TB_PREF . "grn_batch.supplier_id=" . TB_PREF . "suppliers.supplier_id\n\t\tAND " . TB_PREF . "grn_batch.id = " . TB_PREF . "grn_items.grn_batch_id\n\t\tAND " . TB_PREF . "grn_items.po_detail_item = " . TB_PREF . "purch_order_details.po_detail_item\n\t\tAND qty_recd-quantity_inv <>0 "; if ($fromsupp != ALL_TEXT) { $sql .= "AND " . TB_PREF . "grn_batch.supplier_id =" . db_escape($fromsupp) . " "; } $sql .= "ORDER BY " . TB_PREF . "grn_batch.supplier_id,\n\t\t\t" . TB_PREF . "grn_batch.id"; return db_query($sql, "No transactions were returned"); }
function getList($imc) { $sql = "Select b.*, c.*, d.* FROM " . TB_PREF . "cust_branch b INNER JOIN\n" . TB_PREF . "crm_contacts c on b.debtor_no=c.entity_id INNER JOIN " . TB_PREF . "crm_persons d on c.person_id=d.id where c.type='customer'"; if ($imc != 0) { $sql .= " AND b.salesman =" . db_escape($imc); } $sql .= " ORDER BY b.salesman"; return db_query($sql, "Error getting order details"); }
public static function Add($text, $type) { global $currentUser; $user_id = $currentUser->isLogged() ? $currentUser['id'] : null; $ip = get_ip(); $timestamp = time(); $text = db_escape($text); exequery("INSERT INTO logs (ip, `timestamp`, user_id, `text`, type) VALUES ('{$ip}', '{$timestamp}', {$user_id}, '{$text}', {$type})"); }
function getTransactions($from) { $fromdate = date2sql($from); $sql = "SELECT a.*, DATE_FORMAT(a.tran_date, '%m-%d-%Y') as tranDate, c.*, d.*, v.type as IsVoid from " . TB_PREF . "debtor_trans a \n\t\t\tLEFT JOIN " . TB_PREF . "voided v ON v.type = a.type and v.id=a.trans_no\n\t\t\tINNER JOIN " . TB_PREF . "cust_branch c on a.branch_code=c.branch_code AND a.debtor_no=c.debtor_no \n\t\t\tINNER JOIN " . TB_PREF . "customized d on a.type=d.type AND a.trans_no=d.type_no\n\t\t\twhere a.tran_date >= '{$fromdate}' AND a.payment_terms = 4 AND a.type=" . ST_SALESINVOICE . ""; if ($imc != 0) { $sql .= " and " . TB_PREF . "salesman.salesman_code =" . db_escape($imc); } //display_notification($sql); return db_query($sql, "No transactions were returned"); }
function get_dimension_id_from_reference($ref) { if ($ref == null || trim($ref) == '') { return 0; } $sql = "SELECT id FROM " . TB_PREF . "dimensions WHERE reference LIKE " . db_escape($ref); $result = db_query($sql, "could not get dimension from reference"); $row = db_fetch_row($result); return $row[0]; }
function getTransactions($imc) { $sql = "SELECT " . TB_PREF . "debtor_trans.*, DATE_FORMAT(" . TB_PREF . "debtor_trans.tran_date, '%m-%d-%Y') as tranDate, \n\t\tov_amount+ov_discount AS InvoiceTotal, alloc.*,\n\t\t" . TB_PREF . "debtors_master.name AS DebtorName, " . TB_PREF . "debtors_master.curr_code, " . TB_PREF . "cust_branch.br_name,\n\t\t" . TB_PREF . "cust_branch.contact_name, " . TB_PREF . "salesman.*, " . TB_PREF . "customized.customized_no, " . TB_PREF . "comm_voucher.*, v.type as IsVoided\n\t\tFROM " . TB_PREF . "debtor_trans \n\t\tLEFT JOIN " . TB_PREF . "voided v ON v.type = " . TB_PREF . "debtor_trans.type and v.id=" . TB_PREF . "debtor_trans.trans_no\n\t\t\tINNER JOIN " . TB_PREF . "customized on " . TB_PREF . "debtor_trans.type=" . TB_PREF . "customized.type \n\t\t\tINNER JOIN " . TB_PREF . "comm_voucher on " . TB_PREF . "customized.customized_no = " . TB_PREF . "comm_voucher.invoice_no\n\t\t\tINNER JOIN " . TB_PREF . "cust_allocations alloc on alloc.trans_no_to=" . TB_PREF . "debtor_trans.trans_no AND alloc.trans_type_to=" . TB_PREF . "debtor_trans.type,\n\t\t" . TB_PREF . "debtors_master, " . TB_PREF . "sales_orders, " . TB_PREF . "cust_branch, \n\t\t\t" . TB_PREF . "salesman\n\t\tWHERE " . TB_PREF . "sales_orders.order_no=" . TB_PREF . "debtor_trans.order_\n\t\t AND " . TB_PREF . "sales_orders.branch_code=" . TB_PREF . "cust_branch.branch_code\n\t\t AND " . TB_PREF . "cust_branch.salesman=" . TB_PREF . "salesman.salesman_code\n\t\t AND " . TB_PREF . "debtor_trans.debtor_no=" . TB_PREF . "debtors_master.debtor_no\n\t\t AND " . TB_PREF . "debtor_trans.trans_no=" . TB_PREF . "customized.type_no\n\t\t AND (" . TB_PREF . "debtor_trans.type=" . ST_SALESINVOICE . ") and " . TB_PREF . "debtor_trans.payment_terms!=4"; if ($imc != 0) { $sql .= " and " . TB_PREF . "salesman.salesman_code =" . db_escape($imc); } $sql .= " ORDER BY alloc.date_alloc"; //display_notification($sql); return db_query($sql, "No transactions were returned"); }
function get_kits($category = 0) { $sql = "SELECT i.item_code AS kit_code, i.description AS kit_name, c.category_id AS cat_id, c.description AS cat_name, count(*)>1 AS kit\n\t\t\tFROM\n\t\t\t" . TB_PREF . "item_codes i\n\t\t\tLEFT JOIN\n\t\t\t" . TB_PREF . "stock_category c\n\t\t\tON i.category_id=c.category_id"; $sql .= " WHERE !i.is_foreign AND i.item_code!=i.stock_id"; if ($category != 0) { $sql .= " AND c.category_id = " . db_escape($category); } $sql .= " GROUP BY i.item_code"; return db_query($sql, "No kits were returned"); }
function fetchTitle($id) { $catcher = ""; $sql = "SELECT description from " . TB_PREF . "item_codes WHERE stock_id = " . db_escape($id) . " "; $result = db_query($sql, 'Error'); while ($myrow = db_fetch($result)) { $catcher = $myrow[0]; } return $catcher; }
function sn_ube_report_load($report_cypher) { $report_cypher = db_escape($report_cypher); $report_row = doquery("SELECT * FROM {{ube_report}} WHERE ube_report_cypher = '{$report_cypher}' LIMIT 1", true); if (!$report_row) { return UBE_REPORT_NOT_FOUND; } $combat_data = array(UBE_OPTIONS => array(UBE_LOADED => true, UBE_COMBAT_ADMIN => $report_row['ube_report_combat_admin'], UBE_MISSION_TYPE => $report_row['ube_report_mission_type']), UBE_TIME => strtotime($report_row['ube_report_time_combat']), UBE_TIME_SPENT => $report_row['ube_report_time_spent'], UBE_REPORT_CYPHER => $report_cypher, UBE_REPORT_ID => $report_row['ube_report_id'], UBE_OUTCOME => array(UBE_COMBAT_RESULT => $report_row['ube_report_combat_result'], UBE_SFR => $report_row['ube_report_combat_sfr'], UBE_PLANET => array(PLANET_ID => $report_row['ube_report_planet_id'], PLANET_NAME => $report_row['ube_report_planet_name'], PLANET_SIZE => $report_row['ube_report_planet_size'], PLANET_GALAXY => $report_row['ube_report_planet_galaxy'], PLANET_SYSTEM => $report_row['ube_report_planet_system'], PLANET_PLANET => $report_row['ube_report_planet_planet'], PLANET_TYPE => $report_row['ube_report_planet_planet_type']), UBE_DEBRIS => array(RES_METAL => $report_row['ube_report_debris_metal'], RES_CRYSTAL => $report_row['ube_report_debris_crystal']), UBE_MOON => $report_row['ube_report_moon'], UBE_MOON_CHANCE => $report_row['ube_report_moon_chance'], UBE_MOON_SIZE => $report_row['ube_report_moon_size'], UBE_MOON_REAPERS => $report_row['ube_report_moon_reapers'], UBE_MOON_DESTROY_CHANCE => $report_row['ube_report_moon_destroy_chance'], UBE_MOON_REAPERS_DIE_CHANCE => $report_row['ube_report_moon_reapers_die_chance'], UBE_CAPTURE_RESULT => $report_row['ube_report_capture_result'], UBE_ATTACKERS => array(), UBE_DEFENDERS => array())); $outcome =& $combat_data[UBE_OUTCOME]; $query = doquery("SELECT * FROM {{ube_report_player}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); while ($player_row = db_fetch($query)) { $combat_data[UBE_PLAYERS][$player_row['ube_report_player_player_id']] = array(UBE_NAME => $player_row['ube_report_player_name'], UBE_ATTACKER => $player_row['ube_report_player_attacker'], UBE_BONUSES => array(UBE_ATTACK => $player_row['ube_report_player_bonus_attack'], UBE_SHIELD => $player_row['ube_report_player_bonus_shield'], UBE_ARMOR => $player_row['ube_report_player_bonus_armor'])); } $query = doquery("SELECT * FROM {{ube_report_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); while ($fleet_row = db_fetch($query)) { $combat_data[UBE_FLEETS][$fleet_row['ube_report_fleet_fleet_id']] = array(UBE_OWNER => $fleet_row['ube_report_fleet_player_id'], UBE_FLEET_TYPE => $combat_data[UBE_PLAYERS][$fleet_row['ube_report_fleet_player_id']][UBE_ATTACKER] ? UBE_ATTACKERS : UBE_DEFENDERS, UBE_PLANET => array(PLANET_ID => $fleet_row['ube_report_fleet_planet_id'], PLANET_NAME => $fleet_row['ube_report_fleet_planet_name'], PLANET_GALAXY => $fleet_row['ube_report_fleet_planet_galaxy'], PLANET_SYSTEM => $fleet_row['ube_report_fleet_planet_system'], PLANET_PLANET => $fleet_row['ube_report_fleet_planet_planet'], PLANET_TYPE => $fleet_row['ube_report_fleet_planet_planet_type']), UBE_BONUSES => array(UBE_ATTACK => $player_row['ube_report_fleet_bonus_attack'], UBE_SHIELD => $player_row['ube_report_fleet_bonus_shield'], UBE_ARMOR => $player_row['ube_report_fleet_bonus_armor']), UBE_RESOURCES => array(RES_METAL => $player_row['ube_report_fleet_resource_metal'], RES_CRYSTAL => $player_row['ube_report_fleet_resource_crystal'], RES_DEUTERIUM => $player_row['ube_report_fleet_resource_deuterium'])); } $combat_data[UBE_ROUNDS] = array(); $rounds_data =& $combat_data[UBE_ROUNDS]; $query = doquery("SELECT * FROM {{ube_report_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_unit_sort_order`"); while ($round_row = db_fetch($query)) { $round = $round_row['ube_report_unit_round']; $fleet_id = $round_row['ube_report_unit_fleet_id']; $side = $combat_data[UBE_FLEETS][$fleet_id][UBE_FLEET_TYPE]; $rounds_data[$round][$side][UBE_ATTACK][$fleet_id] = 0; if (!isset($rounds_data[$round][UBE_FLEETS][$fleet_id])) { $rounds_data[$round][UBE_FLEETS][$fleet_id] = array(); } $round_fleet_data =& $rounds_data[$round][UBE_FLEETS][$fleet_id]; $unit_id = $round_row['ube_report_unit_unit_id']; $round_fleet_data[UBE_COUNT][$unit_id] = $round_row['ube_report_unit_count']; $round_fleet_data[UBE_UNITS_BOOM][$unit_id] = $round_row['ube_report_unit_boom']; $round_fleet_data[UBE_ATTACK][$unit_id] = $round_row['ube_report_unit_attack']; $round_fleet_data[UBE_SHIELD][$unit_id] = $round_row['ube_report_unit_shield']; $round_fleet_data[UBE_ARMOR][$unit_id] = $round_row['ube_report_unit_armor']; $round_fleet_data[UBE_ATTACK_BASE][$unit_id] = $round_row['ube_report_unit_attack_base']; $round_fleet_data[UBE_SHIELD_BASE][$unit_id] = $round_row['ube_report_unit_shield_base']; $round_fleet_data[UBE_ARMOR_BASE][$unit_id] = $round_row['ube_report_unit_armor_base']; } $query = doquery("SELECT * FROM {{ube_report_outcome_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); while ($row = db_fetch($query)) { $fleet_id = $row['ube_report_outcome_fleet_fleet_id']; $outcome[UBE_FLEETS][$fleet_id] = array(UBE_RESOURCES_LOST => array(RES_METAL => $row['ube_report_outcome_fleet_resource_lost_metal'], RES_CRYSTAL => $row['ube_report_outcome_fleet_resource_lost_crystal'], RES_DEUTERIUM => $row['ube_report_outcome_fleet_resource_lost_deuterium']), UBE_CARGO_DROPPED => array(RES_METAL => $row['ube_report_outcome_fleet_resource_dropped_metal'], RES_CRYSTAL => $row['ube_report_outcome_fleet_resource_dropped_crystal'], RES_DEUTERIUM => $row['ube_report_outcome_fleet_resource_dropped_deuterium']), UBE_RESOURCES_LOOTED => array(RES_METAL => $row['ube_report_outcome_fleet_resource_loot_metal'], RES_CRYSTAL => $row['ube_report_outcome_fleet_resource_loot_crystal'], RES_DEUTERIUM => $row['ube_report_outcome_fleet_resource_loot_deuterium']), UBE_RESOURCES_LOST_IN_METAL => array(RES_METAL => $row['ube_report_outcome_fleet_resource_lost_in_metal'])); $side = $combat_data[UBE_FLEETS][$fleet_id][UBE_FLEET_TYPE]; $outcome[$side][UBE_FLEETS][$fleet_id] =& $outcome[UBE_FLEETS][$fleet_id]; } $query = doquery("SELECT * FROM {{ube_report_outcome_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_outcome_unit_sort_order`"); while ($row = db_fetch($query)) { $fleet_id = $row['ube_report_outcome_unit_fleet_id']; $side = $combat_data[UBE_FLEETS][$fleet_id][UBE_FLEET_TYPE]; $outcome[$side][UBE_FLEETS][$fleet_id][UBE_UNITS_LOST][$row['ube_report_outcome_unit_unit_id']] = $row['ube_report_outcome_unit_lost']; $outcome[$side][UBE_FLEETS][$fleet_id][UBE_DEFENCE_RESTORE][$row['ube_report_outcome_unit_unit_id']] = $row['ube_report_outcome_unit_restored']; } return $combat_data; }
function get_supp_inv_reference($supplier_id, $stock_id, $date) { $sql = "SELECT " . TB_PREF . "supp_trans.supp_reference\n\t\tFROM " . TB_PREF . "supp_trans,\n\t\t\t" . TB_PREF . "supp_invoice_items,\n\t\t\t" . TB_PREF . "grn_batch,\n\t\t\t" . TB_PREF . "grn_items\n\t\tWHERE " . TB_PREF . "supp_trans.type=" . TB_PREF . "supp_invoice_items.supp_trans_type\n\t\tAND " . TB_PREF . "supp_trans.trans_no=" . TB_PREF . "supp_invoice_items.supp_trans_no\n\t\tAND " . TB_PREF . "grn_items.grn_batch_id=" . TB_PREF . "grn_batch.id\n\t\tAND " . TB_PREF . "grn_items.item_code=" . TB_PREF . "supp_invoice_items.stock_id\n\t\tAND " . TB_PREF . "supp_trans.supplier_id=" . db_escape($supplier_id) . "\n\t\tAND " . TB_PREF . "supp_invoice_items.stock_id=" . db_escape($stock_id) . "\n\t\tAND " . TB_PREF . "supp_trans.tran_date=" . db_escape($date); $result = db_query($sql, "No transactions were returned"); $row = db_fetch_row($result); if (isset($row[0])) { return $row[0]; } else { return ''; } }
function getTaxTransactions($from, $to, $tax_id) { $fromdate = date2sql($from); $todate = date2sql($to); $sql = "SELECT d.debtor_no, d.name AS cust_name, d.tax_id, dt.type, dt.trans_no, \n\t\t\tCASE WHEN dt.type=" . ST_CUSTCREDIT . " THEN (ov_amount+ov_freight+ov_discount)*-1 \n\t\t\tELSE (ov_amount+ov_freight+ov_discount) END *dt.rate AS total\n\t\tFROM " . TB_PREF . "debtor_trans dt\n\t\t\tLEFT JOIN " . TB_PREF . "debtors_master d ON d.debtor_no=dt.debtor_no\n\t\tWHERE (dt.type=" . ST_SALESINVOICE . " OR dt.type=" . ST_CUSTCREDIT . ") "; if ($tax_id) { $sql .= "AND tax_id<>'' "; } $sql .= "AND dt.tran_date >=" . db_escape($fromdate) . " AND dt.tran_date<=" . db_escape($todate) . "\n\t\tORDER BY d.debtor_no"; return db_query($sql, "No transactions were returned"); }
function getTransactions($category, $from, $to) { $from = date2sql($from); $to = date2sql($to); $sql = "SELECT item.category_id,\n\t\t\tcategory.description AS cat_description,\n\t\t\titem.stock_id,\n\t\t\titem.description,\n\t\t\tline.unit_price,\n\t\t\tSUM(line.quantity) as quantity\n\t\tFROM " . TB_PREF . "stock_master item,\n\t\t\t" . TB_PREF . "stock_category category,\n\t\t\t" . TB_PREF . "debtor_trans trans,\n\t\t\t" . TB_PREF . "debtor_trans_details line\n\t\tWHERE line.stock_id = item.stock_id\n\t\tAND item.category_id=category.category_id\n\t\tAND line.debtor_trans_type=trans.type\n\t\tAND line.debtor_trans_no=trans.trans_no\n\t\tAND trans.tran_date>='{$from}'\n\t\tAND trans.tran_date<='{$to}'\n\t\tAND line.quantity<>0\n\t\tAND line.debtor_trans_type = " . ST_SALESINVOICE; if ($category != 0) { $sql .= " AND item.category_id = " . db_escape($category); } $sql .= " GROUP BY item.category_id,\n\t\t\tcategory.description,\n\t\t\titem.stock_id,\n\t\t\titem.description,\n\t\t\tline.unit_price\n\t\tORDER BY item.category_id, item.stock_id, line.unit_price"; //display_notification($sql); return db_query($sql, "No transactions were returned"); }
function getTransactions($category, $location) { $sql = "SELECT " . TB_PREF . "stock_master.category_id,\n\t\t\t" . TB_PREF . "stock_category.description AS cat_description,\n\t\t\t" . TB_PREF . "stock_master.stock_id,\n\t\t\t" . TB_PREF . "stock_master.description, " . TB_PREF . "stock_master.inactive,\n\t\t\tIF(" . TB_PREF . "stock_moves.stock_id IS NULL, '', " . TB_PREF . "stock_moves.loc_code) AS loc_code,\n\t\t\tSUM(IF(" . TB_PREF . "stock_moves.stock_id IS NULL,0," . TB_PREF . "stock_moves.qty)) AS qty_on_hand\n\t\tFROM (" . TB_PREF . "stock_master,\n\t\t\t" . TB_PREF . "stock_category)\n\t\tLEFT JOIN " . TB_PREF . "stock_moves ON\n\t\t\t(" . TB_PREF . "stock_master.stock_id=" . TB_PREF . "stock_moves.stock_id)\n\t\tWHERE " . TB_PREF . "stock_master.category_id=" . TB_PREF . "stock_category.category_id\n\t\tAND (" . TB_PREF . "stock_master.mb_flag='B' OR " . TB_PREF . "stock_master.mb_flag='M')"; if ($category != 0) { $sql .= " AND " . TB_PREF . "stock_master.category_id = " . db_escape($category); } if ($location != 'all') { $sql .= " AND IF(" . TB_PREF . "stock_moves.stock_id IS NULL, '1=1'," . TB_PREF . "stock_moves.loc_code = " . db_escape($location) . ")"; } $sql .= " GROUP BY " . TB_PREF . "stock_master.category_id,\n\t\t" . TB_PREF . "stock_category.description,\n\t\t" . TB_PREF . "stock_master.stock_id,\n\t\t" . TB_PREF . "stock_master.description\n\t\tORDER BY " . TB_PREF . "stock_master.category_id,\n\t\t" . TB_PREF . "stock_master.stock_id"; return db_query($sql, "No transactions were returned"); }
public function getLastExchangeRate($rest, $currencyCode) { $date = date2sql(Today()); $sql = "SELECT rate_buy, max(date_) as date_ FROM " . TB_PREF . "exchange_rates WHERE curr_code = " . db_escape($id) . " AND date_ <= '{$date}' GROUP BY rate_buy ORDER BY date_ Desc LIMIT 1"; $result = db_query($sql, "could not query exchange rates"); if (db_num_rows($result) == 0) { // no stored exchange rate, just return 0 api_success_response(json_encode(array('curr_abrev' => $id, 'rate' => 0, 'date' => $date))); } $myrow = db_fetch_row($result); api_success_response(json_encode(array('curr_abrev' => $id, 'rate' => $myrow[0], 'date' => $myrow[1]))); }
function player_save_option_array(&$user, $options_array) { if (isset($user['id']) && is_numeric($user['id']) && !empty($options_array)) { foreach ($options_array as $option_id => &$option_value) { $user[$option_id] = $option_value; $option_id = db_escape($option_id); $option_value = db_escape($option_value); $option_value = "({$user['id']},'{$option_id}','{$option_value}')"; } doquery("REPLACE INTO {{player_options}} (`player_id`, `option_id`, `value`) VALUES " . implode(',', $options_array)); } }
function check() { if ($this->user_id === NULL) { return 'user id is NULL'; } if ($this->user_password !== NULL) { $this->user_password = db_escape(trim($this->user_password)); } // TODO MORE return NULL; // object is ok }