document.getElementById('log_msg').innerHTML='$demo_text'}, 1000*$login_delay);</script>";
$demo_text = $blocked_msg;
}
+ flush_dir(user_js_cache());
if (!isset($def_coy))
$def_coy = 0;
$def_theme = "default";
}
}
-function key_in_crm_contacts($id) // extra function for testing foreign concatenated key. Joe 02.09.2013.
-{
- $row = get_crm_category($id);
- $sql = "SELECT COUNT(*) FROM ".TB_PREF."crm_contacts WHERE type='".$row['type']."' AND action='".$row['action']."'";
- $result = db_query($sql, "check relations for crm_contacts failed");
- $contacts = db_fetch($result);
- return $contacts[0];
-}
-
if ($Mode == 'Delete')
{
$cancel_delete = 0;
- if (key_in_crm_contacts($selected_id))
+ if (is_crm_category_used($selected_id))
{
$cancel_delete = 1;
display_error(_("Cannot delete this category because there are contacts related to it."));
function refresh_sys_prefs()
{
- flush_dir(company_path().'/js_cache'); // clear cache
+ flush_dir(user_js_cache()); // clear cache
unset($_SESSION['SysPrefs']);
get_company_prefs();
}
return $count[0];
}
+//---------------------------------------------------------------------------------------------
+//
+// Resets $theme references in users records to 'default'.
+//
+function clean_user_themes($theme)
+{
+ global $db_connections, $db, $installed_extensions;
+
+ $comp = user_company();
+
+ foreach ($db_connections as $n => $conn) {
+ $db = $_SESSION["wa_current_user"]->set_db_connection($n);
+ $sql = "UPDATE {$conn['tbpref']}users SET theme='default' WHERE theme='$theme'";
+ if (!db_query($sql, 'Cannot update user theme settings'))
+ return false;
+ }
+ $db = $_SESSION["wa_current_user"]->set_db_connection($comp);
+
+ $_SESSION['wa_current_user']->prefs->theme = 'default';
+ return true;
+}
+
+
?>
\ No newline at end of file
{
return db_num_rows(db_query(get_sql_for_view_transactions($trans_type, $trans_no, $trans_no, $dummy)));
}
+
+//
+// Returns counterparty (supplier/customer) name for selected transaction.
+//
+function get_counterparty_name($trans_type, $trans_no, $full=true)
+{
+ switch($trans_type)
+ {
+ case ST_SALESORDER:
+ case ST_SALESQUOTE:
+ $sql = "SELECT order.customer_id as person_id, debtor.name as name
+ FROM ".TB_PREF."sales_orders order, ".TB_PREF."debtors_master debtor
+ WHERE order_no=".db_escape($trans_no)." AND trans_type=".db_escape($trans_type)
+ ." AND order.debtor_no=debtor.debtor_no";
+ break;
+
+ case ST_RECEIPTINVOICE :
+ case ST_SALESINVOICE :
+ case ST_CUSTCREDIT :
+ case ST_CUSTPAYMENT :
+ case ST_CUSTDELIVERY :
+ $sql = "SELECT trans.debtor_no as person_id, debtor.name as name
+ FROM ".TB_PREF."debtor_trans trans, ".TB_PREF."debtors_master debtor
+ WHERE trans_no=".db_escape($trans_no)." AND type=".db_escape($trans_type)
+ ." AND trans.debtor_no=debtor.debtor_no";
+ break;
+
+ case ST_PURCHORDER :
+ $sql = "SELECT order.supplier_id as person_id, supp.supp_name as name
+ FROM ".TB_PREF."purch_orders order, ".TB_PREF."suppliers supp
+ WHERE order_no=".db_escape($trans_no)
+ ." AND order.supplier_id=supp.supplier_id";
+ break;
+
+ case ST_SUPPINVOICE :
+ case ST_SUPPCREDIT :
+ case ST_SUPPAYMENT :
+ $sql = "SELECT trans.supplier_id as person_id, supp.supp_name as name
+ FROM ".TB_PREF."supp_trans trans, ".TB_PREF."suppliers supp
+ WHERE trans_no=".db_escape($trans_no)." AND type=".db_escape($trans_type)
+ ." AND trans.supplier_id=supp.supplier_id";
+ break;
+
+ case ST_SUPPRECEIVE :
+ $sql = "SELECT trans.supplier_id as person_id, supp.supp_name as name
+ FROM ".TB_PREF."grn_batch trans, ".TB_PREF."suppliers supp
+ WHERE id=".db_escape($trans_no)
+ ." AND trans.supplier_id=supp.supplier_id";
+ break;
+
+ case ST_BANKPAYMENT :
+ case ST_BANKDEPOSIT :
+ $sql = "SELECT trans.debtor_no as person_id, debtor.name as name
+ FROM ".TB_PREF."debtor_trans trans, ".TB_PREF."debtors_master debtor
+ WHERE trans_no=".db_escape($trans_no)." AND type=".db_escape($trans_type)
+ ." AND trans.debtor_no=debtor.debtor_no
+ UNION
+ SELECT trans.supplier_id as person_id, supp.supp_name as name
+ FROM ".TB_PREF."supp_trans trans, ".TB_PREF."suppliers supp
+ WHERE trans_no=".db_escape($trans_no)." AND type=".db_escape($trans_type)
+ ." AND trans.supplier_id=supp.supplier_id";
+ break;
+
+ case ST_JOURNAL: // FIXME - this one can have multiply counterparties of various types depending on person_type_id
+
+ default:
+ /* // internal operations
+ case ST_WORKORDER :
+ case ST_INVADJUST : // GRN/DN returns ?
+ case ST_BANKTRANSFER :
+ case ST_LOCTRANSFER :
+ case ST_MANUISSUE :
+ case ST_MANURECEIVE :
+ case ST_COSTUPDATE :
+ */
+ return null;
+ }
+
+ $result = db_query($sql, 'cannot retrieve counterparty name');
+ if (db_num_rows($result))
+ {
+ $row = db_fetch($result);
+ return sprintf("[%05s] %s", $row['person_id'], $row['name']);
+ }
+
+ return '';
+}
+
+
+//-----------------------------------------------------------------------------------------
+// Returns next transaction number.
+// Used only for transactions stored in tables without autoincremented key.
+//
+
+function get_next_trans_no ($trans_type){
+
+ $st = get_systype_db_info($trans_type);
+
+ if (!($st && $st[0] && $st[2])) {
+ // this is in fact internal error condition.
+ display_error('Internal error: invalid type passed to get_next_trans_no()');
+ return 0;
+ }
+ $sql1 = "SELECT MAX(`$st[2]`) as last_no FROM $st[0]";
+ if ($st[1] != null)
+ $sql1 .= " WHERE `$st[1]`=".db_escape($trans_type);
+
+ // check also in voided transactions (some transactions like location transfer are removed completely)
+ $sql2 = "SELECT MAX(`id`) as last_no FROM ".TB_PREF."voided WHERE `type`=".db_escape($trans_type);
+
+ $sql = "SELECT max(last_no) last_no FROM ($sql1 UNION $sql2) a";
+ $result = db_query($sql,"The next transaction number for $trans_type could not be retrieved");
+ $myrow = db_fetch_row($result);
+
+ return $myrow[0] + 1;
+}
+
+//-----------------------------------------------------------------------------
+
+function get_systype_db_info($type)
+{
+ switch ($type)
+ {
+ case ST_JOURNAL : return array("".TB_PREF."gl_trans", "type", "type_no", null, "tran_date");
+ case ST_BANKPAYMENT : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
+ case ST_BANKDEPOSIT : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
+ case 3 : return null;
+ case ST_BANKTRANSFER : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
+ case ST_SALESINVOICE : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
+ case ST_CUSTCREDIT : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
+ case ST_CUSTPAYMENT : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
+ case ST_CUSTDELIVERY : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
+ case ST_LOCTRANSFER : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date");
+ case ST_INVADJUST : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date");
+ case ST_PURCHORDER : return array("".TB_PREF."purch_orders", null, "order_no", "reference", "ord_date");
+ case ST_SUPPINVOICE : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
+ case ST_SUPPCREDIT : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
+ case ST_SUPPAYMENT : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
+ case ST_SUPPRECEIVE : return array("".TB_PREF."grn_batch", null, "id", "reference", "delivery_date");
+ case ST_WORKORDER : return array("".TB_PREF."workorders", null, "id", "wo_ref", "released_date");
+ case ST_MANUISSUE : return array("".TB_PREF."wo_issues", null, "issue_no", "reference", "issue_date");
+ case ST_MANURECEIVE : return array("".TB_PREF."wo_manufacture", null, "id", "reference", "date_");
+ case ST_SALESORDER : return array("".TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date");
+ case 31 : return array("".TB_PREF."service_orders", null, "order_no", "cust_ref", "date");
+ case ST_SALESQUOTE : return array("".TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date");
+ case ST_DIMENSION : return array("".TB_PREF."dimensions", null, "id", "reference", "date_");
+ case ST_COSTUPDATE : return array("".TB_PREF."gl_trans", "type", "type_no", null, "tran_date");
+ }
+
+ display_db_error("invalid type ($type) sent to get_systype_db_info", "", true);
+}
+
+function get_systypes()
+{
+ $sql = "SELECT * FROM ".TB_PREF."sys_types";
+ $result = db_query($sql, "could not query systypes table");
+ return $result;
+}
+
?>
number_list_row(_("Exchange Rates:"), 'rates_dec', user_exrate_dec(), 0, 10);
number_list_row(_("Percentages:"), 'percent_dec', user_percent_dec(), 0, 10);
-table_section_title(_("Dateformat and Separators"));
+table_section_title(_("Date Format and Separators"));
-dateformats_list_row(_("Dateformat:"), "date_format", user_date_format());
+dateformats_list_row(_("Date Format:"), "date_format", user_date_format());
dateseps_list_row(_("Date Separator:"), "date_sep", user_date_sep());
include_once($path_to_root . "/includes/ui.inc");
//---------------------------------------------------------------------------------------------
-// If theme is used in customer record set to default
-//
-function clean_user_themes($id)
-{
- global $db_connections, $db, $installed_extensions;
-
- $theme = $installed_extensions[$id]['package'];
- $comp = user_company();
-
- foreach ($db_connections as $n => $conn) {
- $db = $_SESSION["wa_current_user"]->set_db_connection($n);
- $sql = "UPDATE {$conn['tbpref']}users SET theme='default' WHERE theme='$theme'";
- if (!db_query($sql, 'Cannot update user theme settings'))
- return false;
- }
- $db = $_SESSION["wa_current_user"]->set_db_connection($comp);
-
- $_SESSION['wa_current_user']->prefs->theme = 'default';
- return true;
-}
-if (($id = find_submit('Delete', false)) && clean_user_themes($id))
+if (($id = find_submit('Delete', false))
+ && clean_user_themes($installed_extensions[$id]['package']))
{
$extensions = get_company_extensions();
$theme = $extensions[$id]['package'];
//--------------------------------------------------------------------------------------
-function get_sql_for_search_dimensions($dim)
-{
+function get_sql_for_search_dimensions($dim, $from, $to, $order='', $type = -1, $open=false, $overdue = false)
+{
$sql = "SELECT dim.id,
dim.reference,
dim.name,
dim.closed
FROM ".TB_PREF."dimensions as dim WHERE id > 0";
- if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
+ if ($order)
{
- $sql .= " AND reference LIKE ".db_escape("%". $_POST['OrderNumber'] . "%");
+ $sql .= " AND reference LIKE ".db_escape("%". $order . "%");
} else {
if ($dim == 1)
$sql .= " AND type_=1";
- if (isset($_POST['OpenOnly']))
- {
+ if ($open)
$sql .= " AND closed=0";
- }
- if (isset($_POST['type_']) && ($_POST['type_'] > 0))
- {
- $sql .= " AND type_=".db_escape($_POST['type_']);
- }
+ if ($type > 0)
+ $sql .= " AND type_=".db_escape($type);
- if (isset($_POST['OverdueOnly']))
+ if ($overdue)
{
$today = date2sql(Today());
$sql .= " AND due_date < '$today'";
}
- $sql .= " AND date_ >= '" . date2sql($_POST['FromDate']) . "'
- AND date_ <= '" . date2sql($_POST['ToDate']) . "'";
+ $sql .= " AND date_ >= '" . date2sql($from) . "'
+ AND date_ <= '" . date2sql($to) . "'";
}
return $sql;
-}
+}
?>
\ No newline at end of file
"/dimensions/dimension_entry.php?trans_no=" . $row["id"], ICON_EDIT);
}
-$sql = get_sql_for_search_dimensions($dim);
+$sql = get_sql_for_search_dimensions($dim, $_POST['FromDate'], $_POST['ToDate'],
+ $_POST['OrderNumber'], $_POST['type_'], $_POST['OpenOnly'], $_POST['OverdueOnly']);
$cols = array(
_("#") => array('fun'=>'view_link'),
$myrow = db_fetch_row($result);
return ($myrow[0] > 0);
}
-?>
\ No newline at end of file
+
+//----------------------------------------------------------------------------------
+// Check if given account is used by any bank_account.
+// Returns id of first bank_account using account_code, null otherwise.
+//
+// Keep in mind that direct posting to bank account is depreciated
+// because we have no way to select right bank account if
+// there is more than one using given gl account.
+//
+function is_bank_account($account_code)
+{
+ $sql= "SELECT id FROM ".TB_PREF."bank_accounts WHERE account_code=".db_escape($account_code);
+ $result = db_query($sql, "checking account is bank account");
+ if (db_num_rows($result) > 0) {
+ $acct = db_fetch($result);
+ return $acct['id'];
+ } else
+ return false;
+}
}
//---------------------------------------------------------------------------------------------
-function get_default_bank_account($curr)
+function get_default_bank_account($curr=null)
{
/* default bank account is selected as first found account from:
. default account in $curr if any
. first defined account in home currency
*/
$home_curr = get_company_pref('curr_default');
+ if (!isset($curr))
+ $curr = $home_curr;
$sql = "SELECT b.*, b.bank_curr_code='$home_curr' as fall_back FROM "
.TB_PREF."bank_accounts b"
return null;
}
+//----------------------------------------------------------------------------------
+
+function get_bank_account_currency($id)
+{
+ $sql= "SELECT bank_curr_code FROM ".TB_PREF."bank_accounts WHERE id=".db_escape($id);
+ $result = db_query($sql, "retreive bank account currency");
+
+ $myrow = db_fetch_row($result);
+ return $myrow[0];
+}
+
?>
\ No newline at end of file
return $row[0];
}
+/*
+ Return last exchange rate of $currency not later than $date.
+*/
+function get_last_exchange_rate($curr_code, $date_)
+{
+ $date = date2sql($date_);
+
+ $sql = "SELECT rate_buy, max(date_) as date_ FROM ".TB_PREF."exchange_rates WHERE curr_code = ".db_escape($curr_code)."
+ 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)
+ return false;
+
+ return db_fetch_row($result);
+}
+
//---------------------------------------------------------------------------------------------
function update_exchange_rate($curr_code, $date_, $buy_rate, $sell_rate)
//-----------------------------------------------------------------------------
-function get_sql_for_exchange_rates()
+function get_sql_for_exchange_rates($curr)
{
$sql = "SELECT date_, rate_buy, id FROM "
.TB_PREF."exchange_rates "
- ."WHERE curr_code=".db_escape($_POST['curr_abrev'])."
+ ."WHERE curr_code=".db_escape($curr)."
ORDER BY date_ DESC";
return $sql;
}
set_global_curr_code($_POST['curr_abrev']);
-$sql = get_sql_for_exchange_rates();
+$sql = get_sql_for_exchange_rates($_POST['curr_abrev']);
$cols = array(
_("Date to Use From") => 'date',
***********************************************************************/
include_once($path_to_root . "/gl/includes/gl_db.inc");
-//----------------------------------------------------------------------------------
-// Check if given account is used by any bank_account.
-// Returns id of first bank_account using account_code, null otherwise.
-//
-// Keep in mind that direct posting to bank account is depreciated
-// because we have no way to select right bank account if
-// there is more than one using given gl account.
-//
-function is_bank_account($account_code)
-{
- $sql= "SELECT id FROM ".TB_PREF."bank_accounts WHERE account_code=".db_escape($account_code);
- $result = db_query($sql, "checking account is bank account");
- if (db_num_rows($result) > 0) {
- $acct = db_fetch($result);
- return $acct['id'];
- } else
- return false;
-}
-
//----------------------------------------------------------------------------------
function is_company_currency($currency)
//----------------------------------------------------------------------------------
-function get_bank_account_currency($id)
-{
- $sql= "SELECT bank_curr_code FROM ".TB_PREF."bank_accounts WHERE id=".db_escape($id);
- $result = db_query($sql, "retreive bank account currency");
-
- $myrow = db_fetch_row($result);
- return $myrow[0];
-}
-
-//----------------------------------------------------------------------------------
-
-function get_customer_currency($customer_id)
-{
- $sql = "SELECT curr_code FROM ".TB_PREF."debtors_master WHERE debtor_no = ".db_escape($customer_id);
-
- $result = db_query($sql, "Retreive currency of customer $customer_id");
-
- $myrow=db_fetch_row($result);
- return $myrow[0];
-}
-
-//----------------------------------------------------------------------------------
-
-function get_supplier_currency($supplier_id)
-{
- $sql = "SELECT curr_code FROM ".TB_PREF."suppliers WHERE supplier_id = ".db_escape($supplier_id);
-
- $result = db_query($sql, "Retreive currency of supplier $supplier_id");
-
- $myrow=db_fetch_row($result);
- return $myrow[0];
-}
-
-//----------------------------------------------------------------------------------
-
function get_exchange_rate_from_home_currency($currency_code, $date_)
{
if ($currency_code == get_company_currency() || $currency_code == null)
return 1.0000;
- $date = date2sql($date_);
-
- $sql = "SELECT rate_buy, max(date_) as date_ FROM ".TB_PREF."exchange_rates WHERE curr_code = ".db_escape($currency_code)."
- AND date_ <= '$date' GROUP BY rate_buy ORDER BY date_ Desc LIMIT 1";
- $result = db_query($sql, "could not query exchange rates");
+ $rate = get_last_exchange_rate($currency_code, $date_);
- if (db_num_rows($result) == 0)
+ if (!$rate)
{
// no stored exchange rate, just return 1
display_error(
return 1.000;
}
- $myrow = db_fetch_row($result);
- return $myrow[0];
+ return $rate['rate_buy'];
}
//----------------------------------------------------------------------------------
$this->logged = true;
$this->last_act = time();
$this->timeout = session_timeout();
+ flush_dir(user_js_cache()); // refresh cache on login
}
}
return $this->logged;
add_js_source($js);
}
+function user_js_cache($id=null)
+{
+ global $path_to_root;
+
+ if (!$id)
+ $id = @$_SESSION['wa_current_user']->user;
+
+ if (!$id)
+ $id = 0; // before login
+ return $path_to_root.'/company/'.user_company().'/js_cache/'.$id;
+}
+
//--------------------------------------------------------------------------
function session_timeout()
function flush_dir($path, $wipe = false)
{
- $dir = opendir($path);
+ $dir = @opendir($path);
if(!$dir)
return;
return $ret;
}
+/*
+ Check for whether category is used in contacts.
+*/
+function is_crm_category_used($id)
+{
+ $row = get_crm_category($id);
+ $sql = "SELECT COUNT(*) FROM ".TB_PREF."crm_contacts WHERE type='".$row['type']."' AND action='".$row['action']."'";
+ $result = db_query($sql, "check relations for crm_contacts failed");
+ $contacts = db_fetch($result);
+ return $contacts[0];
+}
+
+
?>
\ No newline at end of file
return $row[0];
}
+//----------------------------------------------------------------------------
+//
+// Check if reference was not used so far (for other transaction than $trans_no)
+//
+function is_new_reference($ref, $type, $trans_no=0)
+{
+ $db_info = get_systype_db_info($type);
+ $db_name = $db_info[0];
+ $db_type = $db_info[1];
+ $db_trans = $db_info[2];
+ $db_ref = $db_info[3];
+
+ $ref = db_escape(trim($ref));
+ $type = db_escape($type);
+
+ if ($db_ref == null) { // journal or bank trans store references in refs table
+ $db_name = TB_PREF."refs";
+ $db_type = 'type';
+ $db_trans = 'id';
+ $db_ref = 'reference';
+ }
+
+ if ($db_type != null) {
+ $sql = "SELECT $db_ref FROM $db_name tbl
+ LEFT JOIN ".TB_PREF."voided v ON
+ tbl.$db_type=v.type AND tbl.$db_trans=v.id
+ WHERE $db_ref=$ref AND ISNULL(v.id)
+ AND tbl.$db_type=$type";
+ } else {
+ $sql = "SELECT $db_ref ref FROM $db_name tbl
+ LEFT JOIN ".TB_PREF."voided v ON
+ v.type=$type AND tbl.$db_trans=v.id
+ WHERE $db_ref=$ref AND ISNULL(v.id)";
+ }
+ if ($trans_no)
+ $sql .= " AND tbl.`$db_trans` != ".db_escape($trans_no);
+
+ $result = db_query($sql, "could not test for unique reference");
+
+ return (db_num_rows($result) == 0);
+
+}
+
+
?>
\ No newline at end of file
}
}
- if ($go_debug>1) {
- $bt = get_backtrace(true, 1);
- }
+ $bt = $go_debug>1 ? get_backtrace(true, 1) : array();
// error_reporting==0 when messages are set off with @
if ($errno & error_reporting()) {
}
$str .= "<br><br>";
- if ($go_debug)
+ if (!$go_debug)
error_log($str);
else {
if($msg)
--- /dev/null
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
+//
+// Copyright (c) 2003 Laurent Bedubourg
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// Authors: Laurent Bedubourg <laurent.bedubourg@free.fr>
+//
+
+//require_once "PEAR.php";
+
+define('GETTEXT_NATIVE', 1);
+define('GETTEXT_PHP', 2);
+
+function get_text_init($managerType = GETTEXT_NATIVE) {
+ global $GetText;
+ if (!isset($GetText)) {
+
+ if ($managerType == GETTEXT_NATIVE)
+ {
+ if (function_exists('gettext'))
+ {
+ $GetText = new gettext_native_support();
+ return;
+ }
+ }
+ // fail back to php support
+ $GetText = new gettext_php_support();
+ }
+}
+
+function raise_error($str) {
+ error_log($str);
+ return 1;
+}
+
+function is_error($err) {
+ return $err > 0;
+}
+
+/**
+* Interface to gettext native support.
+*
+* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
+* @access private
+*/
+class gettext_native_support
+{
+ var $_interpolation_vars = array();
+ var $domain_path;
+
+ /**
+ * Set gettext language code.
+ * @throws GetText_Error
+ */
+ function set_language($lang_code, $encoding)
+ {
+ putenv("LANG=$lang_code");
+ putenv("LC_ALL=$lang_code");
+ putenv("LANGUAGE=$lang_code");
+
+ //$set = setlocale(LC_ALL, "$lang_code");
+ //$set = setlocale(LC_ALL, "$encoding");
+
+ // cover a couple of country/encoding variants
+ $up = strtoupper($encoding);
+ $low = strtolower($encoding);
+ $lshort = strtr($up, '-','');
+ $ushort = strtr($low, '-','');
+
+ if ($lang_code == 'C')
+ $set = setlocale(LC_ALL,'C');
+ else
+ $set = setlocale(LC_ALL, $lang_code.".".$encoding,
+ $lang_code.".".$up, $lang_code.".".$low,
+ $lang_code.".".$ushort, $lang_code.".".$lshort);
+
+ setlocale(LC_NUMERIC, 'C'); // important for numeric presentation etc.
+ if ($set === false)
+ {
+ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') // don't do this test if server is WIN
+ return 0;
+ $str = sprintf('language code "%s", encoding "%s" not supported by your system',
+ $lang_code, $encoding);
+ //$err = new GetText_Error($str);
+ //return PEAR::raise_error($err);
+ return raise_error("1 " . $str);
+ }
+ //return 0;
+ }
+ /**
+ * Check system support for given language nedded for gettext.
+ */
+ function check_support($lang_code, $encoding)
+ {
+ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') // don't do this test if server is WIN
+ return true;
+ $old = setlocale(LC_CTYPE, '0'); // LC_MESSAGES does not exist on Win
+ $up = strtoupper($encoding);
+ $low = strtolower($encoding);
+ $lshort = strtr($up, '-','');
+ $ushort = strtr($low, '-','');
+
+ $test = setlocale(LC_ALL,
+ $lang_code.".".$encoding,
+ $lang_code.".".$up,
+ $lang_code.".".$low,
+ $lang_code.".".$ushort,
+ $lang_code.".".$lshort) !== false;
+ setlocale(LC_ALL, $old);
+ setlocale(LC_NUMERIC, 'C');
+ return $test;
+ }
+ /**
+ * Add a translation domain.
+ */
+ function add_domain($domain, $path=false, $version='')
+ {
+ if ($path === false)
+ $path = $this->domain_path;
+ if ($path === false)
+ $path = "./locale";
+ if ($domain == "")
+ $domain = "?";
+ if ($version) {
+ // To avoid need for apache server restart after change of *.mo file
+ // we have to include file version as part of filename.
+ // This is alternative naming convention: $domain = $version.'/'.$domain;
+ $domain .= '-'.$version;
+ }
+ bindtextdomain($domain, $path);
+ //bind_textdomain_codeset($domain, $encoding);
+ textdomain($domain);
+ }
+
+ /**
+ * Retrieve translation for specified key.
+ *
+ * @access private
+ */
+ function _get_translation($key)
+ {
+ return gettext($key);
+ }
+
+
+ /**
+ * Reset interpolation variables.
+ */
+ function reset()
+ {
+ $this->_interpolation_vars = array();
+ }
+
+ /**
+ * Set an interpolation variable.
+ */
+ function set_var($key, $value)
+ {
+ $this->_interpolation_vars[$key] = $value;
+ }
+
+ /**
+ * Set an associative array of interpolation variables.
+ */
+ function set_vars($hash)
+ {
+ $this->_interpolation_vars = array_merge($this->_interpolation_vars,
+ $hash);
+ }
+
+ /**
+ * Retrieve translation for specified key.
+ *
+ * @param string $key -- gettext msgid
+ * @throws GetText_Error
+ */
+ function gettext($key)
+ {
+ $value = $this->_get_translation($key);
+ if ($value === false) {
+ $str = sprintf('Unable to locate gettext key "%s"', $key);
+ //$err = new GetText_Error($str);
+ //return PEAR::raise_error($err);
+ return raise_error("2 " . $str);
+ }
+
+ while (preg_match('/\$\{(.*?)\}/sm', $value, $m)) {
+ list($src, $var) = $m;
+
+ // retrieve variable to interpolate in context, throw an exception
+ // if not found.
+ $var2 = $this->_get_var($var);
+ if ($var2 === false) {
+ $str = sprintf('Interpolation error, var "%s" not set', $var);
+ //$err = new GetText_Error($str);
+ //return PEAR::raise_error($err);
+ return raise_error("3 " . $str);
+ }
+ $value = str_replace($src, $var2, $value);
+ }
+ return $value;
+ }
+
+ /**
+ * Retrieve an interpolation variable value.
+ *
+ * @return mixed
+ * @access private
+ */
+ function _get_var($name)
+ {
+ if (!array_key_exists($name, $this->_interpolation_vars)) {
+ return false;
+ }
+ return $this->_interpolation_vars[$name];
+ }
+}
+
+
+/**
+* Implementation of get_text support for PHP.
+*
+* This implementation is abble to cache .po files into php files returning the
+* domain translation hashtable.
+*
+* @access private
+* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
+*/
+class gettext_php_support extends gettext_native_support
+{
+ var $_path = 'locale/';
+ var $_lang_code = false;
+ var $_domains = array();
+ var $_end = -1;
+ var $_jobs = array();
+
+ /**
+ * Set the translation domain.
+ *
+ * @param string $lang_code -- language code
+ * @throws GetText_Error
+ */
+ function set_language($lang_code, $encoding)
+ {
+ // if language already set, try to reload domains
+ if ($this->_lang_code !== false and $this->_lang_code != $lang_code)
+ {
+ foreach ($this->_domains as $domain)
+ {
+ $this->_jobs[] = array($domain->name, $domain->path);
+ }
+ $this->_domains = array();
+ $this->_end = -1;
+ }
+
+ $this->_lang_code = $lang_code;
+
+ // this allow us to set the language code after
+ // domain list.
+ while (count($this->_jobs) > 0)
+ {
+ list($domain, $path) = array_shift($this->_jobs);
+ $err = $this->add_domain($domain, $path);
+ // error raised, break jobs
+ /*if (PEAR::is_error($err)) {
+ return $err;
+ }*/
+ if (is_error($err))
+ {
+ return $err;
+ }
+ }
+ }
+ /**
+ * Check system support for given language (dummy).
+ */
+ function check_support($lang_code, $encoding)
+ {
+ return true;
+ }
+ /**
+ * Add a translation domain.
+ *
+ * @param string $domain -- Domain name
+ * @param string $path optional -- Repository path
+ * @throws GetText_Error
+ */
+ function add_domain($domain, $path = false, $version ='')
+ {
+ if ($path === false)
+ $path = $this->domain_path;
+ if ($path === false)
+ $path = "./locale";
+
+ if ($version) {
+ $domain .= '-'.$version;
+ }
+
+ if (array_key_exists($domain, $this->_domains))
+ {
+ return;
+ }
+
+ if (!$this->_lang_code)
+ {
+ $this->_jobs[] = array($domain, $path);
+ return;
+ }
+ // Don't fill the domains with false data, it increased the error.log
+ if (strpos($domain, $this->_lang_code) === false)
+ return;
+
+ $err = $this->_load_domain($domain, $path);
+ if ($err != 0)
+ {
+ return $err;
+ }
+
+ $this->_end++;
+ }
+
+ /**
+ * Load a translation domain file.
+ *
+ * This method cache the translation hash into a php file unless
+ * GETTEXT_NO_CACHE is defined.
+ *
+ * @param string $domain -- Domain name
+ * @param string $path optional -- Repository
+ * @throws GetText_Error
+ * @access private
+ */
+ function _load_domain($domain, $path = "./locale")
+ {
+ $src_domain = $path . "/$this->_lang_code/LC_MESSAGES/$domain.po";
+ $php_domain = $path . "/$this->_lang_code/LC_MESSAGES/$domain.php";
+
+ if (!file_exists($src_domain))
+ {
+ $str = sprintf('Domain file "%s" not found.', $src_domain);
+ //$err = new GetText_Error($str);
+ //return PEAR::raise_error($err);
+ return raise_error("4 " . $str);
+ }
+
+ $d = new gettext_domain();
+ $d->name = $domain;
+ $d->path = $path;
+ if (!file_exists($php_domain) || (filemtime($php_domain) < filemtime($src_domain)))
+ {
+
+ // parse and compile translation table
+ $parser = new gettext_php_support_parser();
+ $hash = $parser->parse($src_domain);
+ if (!defined('GETTEXT_NO_CACHE'))
+ {
+ $comp = new gettext_php_support_compiler();
+ $err = $comp->compile($hash, $src_domain);
+ /*if (PEAR::is_error($err)) {
+ return $err;
+ }*/
+ if (is_error($err))
+ {
+ return $err;
+ }
+ }
+ $d->_keys = $hash;
+ }
+ else
+ {
+ $d->_keys = include $php_domain;
+ }
+ $this->_domains[] = &$d;
+ }
+
+ /**
+ * Implementation of gettext message retrieval.
+ */
+ function _get_translation($key)
+ {
+ for ($i = $this->_end; $i >= 0; $i--)
+ {
+ if ($this->_domains[$i]->has_key($key))
+ {
+ return $this->_domains[$i]->get($key);
+ }
+ }
+ return $key;
+ }
+}
+
+/**
+* Class representing a domain file for a specified language.
+*
+* @access private
+* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
+*/
+class gettext_domain
+{
+ var $name;
+ var $path;
+
+ var $_keys = array();
+
+ function has_key($key)
+ {
+ return array_key_exists($key, $this->_keys);
+ }
+
+ function get($key)
+ {
+ return $this->_keys[$key];
+ }
+}
+
+/**
+* This class is used to parse gettext '.po' files into php associative arrays.
+*
+* @access private
+* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
+*/
+class gettext_php_support_parser
+{
+ var $_hash = array();
+ var $_current_key;
+ var $_current_value;
+
+ /**
+ * Parse specified .po file.
+ *
+ * @return hashtable
+ * @throws GetText_Error
+ */
+ function parse($file)
+ {
+ $this->_hash = array();
+ $this->_current_key = false;
+ $this->_current_value = "";
+
+ if (!file_exists($file))
+ {
+ $str = sprintf('Unable to locate file "%s"', $file);
+ //$err = new GetText_Error($str);
+ //return PEAR::raise_error($err);
+ return raise_error($str);
+ }
+ $i = 0;
+ $lines = file($file);
+ foreach ($lines as $line)
+ {
+ $this->_parse_line($line, ++$i);
+ }
+ $this->_store_key();
+
+ return $this->_hash;
+ }
+
+ /**
+ * Parse one po line.
+ *
+ * @access private
+ */
+ function _parse_line($line, $nbr)
+ {
+ $line = str_replace("\\\"", "'", $line); // Should be inside preg_match, but I couldn't find the solution. This works.
+ if (preg_match('/^\s*?#/', $line)) { return; }
+ if (preg_match('/^\s*?msgid \"(.*?)(?!<\\\)\"/', $line, $m)) {
+ $this->_store_key();
+ $this->_current_key = $m[1];
+ return;
+ }
+ if (preg_match('/^\s*?msgstr \"(.*?)(?!<\\\)\"/', $line, $m)) {
+ $this->_current_value .= $m[1];
+ return;
+ }
+ if (preg_match('/^\s*?\"(.*?)(?!<\\\)\"/', $line, $m)) {
+ $this->_current_value .= $m[1];
+ return;
+ }
+ }
+
+ /**
+ * Store last key/value pair into building hashtable.
+ *
+ * @access private
+ */
+ function _store_key()
+ {
+ if ($this->_current_key === false) return;
+ $this->_current_value = str_replace('\\n', "\n", $this->_current_value);
+ $this->_hash[$this->_current_key] = $this->_current_value;
+ $this->_current_key = false;
+ $this->_current_value = "";
+ }
+}
+
+
+/**
+* This class write a php file from a gettext hashtable.
+*
+* The produced file return the translation hashtable on include.
+*
+* @throws GetText_Error
+* @access private
+* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
+*/
+class gettext_php_support_compiler
+{
+ /**
+ * Write hash in an includable php file.
+ */
+ function compile(&$hash, $source_path)
+ {
+ $dest_path = preg_replace('/\.po$/', '.php', $source_path);
+ $fp = @fopen($dest_path, "w");
+ if (!$fp)
+ {
+ $str = sprintf('Unable to open "%s" in write mode.', $dest_path);
+ //$err = new GetText_Error($str);
+ //return PEAR::raise_error($err);
+ return raise_error($str);
+ }
+ fwrite($fp, '<?php' . "\n");
+ fwrite($fp, 'return array(' . "\n");
+ foreach ($hash as $key => $value)
+ {
+ $key = str_replace("'", "\\'", $key);
+ $value = str_replace("'", "\\'", $value);
+ fwrite($fp, ' \'' . $key . '\' => \'' . $value . "',\n");
+ }
+ fwrite($fp, ');' . "\n");
+ fwrite($fp, '?>');
+ fclose($fp);
+ }
+}
+
+/*
+ Set current gettext domain path
+*/
+function set_ext_domain($path='') {
+ global $path_to_root, $GetText;
+ static $domain_stack = array('');
+
+ if ($path) // save path on domain stack
+ array_unshift($domain_stack, $path);
+ else
+ {
+ array_shift($domain_stack);
+ $path = $domain_stack[0];
+ }
+
+ $lang_path = $path_to_root . ($path ? '/' : '') .$path.'/lang';
+ // ignore change when extension does not provide translation structure and test for valid gettext.
+ if (file_exists($lang_path) && isset($GetText))
+ $GetText->add_domain($_SESSION['language']->code,
+ $lang_path, $path ? '' : $_SESSION['language']->version);
+}
+?>
+++ /dev/null
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-//
-// Copyright (c) 2003 Laurent Bedubourg
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// Authors: Laurent Bedubourg <laurent.bedubourg@free.fr>
-//
-
-//require_once "PEAR.php";
-
-define('GETTEXT_NATIVE', 1);
-define('GETTEXT_PHP', 2);
-
-function get_text_init($managerType = GETTEXT_NATIVE) {
- global $GetText;
- if (!isset($GetText)) {
-
- if ($managerType == GETTEXT_NATIVE)
- {
- if (function_exists('gettext'))
- {
- $GetText = new gettext_native_support();
- return;
- }
- }
- // fail back to php support
- $GetText = new gettext_php_support();
- }
-}
-
-function raise_error($str) {
- error_log($str);
- return 1;
-}
-
-function is_error($err) {
- return $err > 0;
-}
-
-/**
-* Interface to gettext native support.
-*
-* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
-* @access private
-*/
-class gettext_native_support
-{
- var $_interpolation_vars = array();
- var $domain_path;
-
- /**
- * Set gettext language code.
- * @throws GetText_Error
- */
- function set_language($lang_code, $encoding)
- {
- putenv("LANG=$lang_code");
- putenv("LC_ALL=$lang_code");
- putenv("LANGUAGE=$lang_code");
-
- //$set = setlocale(LC_ALL, "$lang_code");
- //$set = setlocale(LC_ALL, "$encoding");
-
- // cover a couple of country/encoding variants
- $up = strtoupper($encoding);
- $low = strtolower($encoding);
- $lshort = strtr($up, '-','');
- $ushort = strtr($low, '-','');
-
- if ($lang_code == 'C')
- $set = setlocale(LC_ALL,'C');
- else
- $set = setlocale(LC_ALL, $lang_code.".".$encoding,
- $lang_code.".".$up, $lang_code.".".$low,
- $lang_code.".".$ushort, $lang_code.".".$lshort);
-
- setlocale(LC_NUMERIC, 'C'); // important for numeric presentation etc.
- if ($set === false)
- {
- if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') // don't do this test if server is WIN
- return 0;
- $str = sprintf('language code "%s", encoding "%s" not supported by your system',
- $lang_code, $encoding);
- //$err = new GetText_Error($str);
- //return PEAR::raise_error($err);
- return raise_error("1 " . $str);
- }
- //return 0;
- }
- /**
- * Check system support for given language nedded for gettext.
- */
- function check_support($lang_code, $encoding)
- {
- if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') // don't do this test if server is WIN
- return true;
- $old = setlocale(LC_CTYPE, '0'); // LC_MESSAGES does not exist on Win
- $up = strtoupper($encoding);
- $low = strtolower($encoding);
- $lshort = strtr($up, '-','');
- $ushort = strtr($low, '-','');
-
- $test = setlocale(LC_ALL,
- $lang_code.".".$encoding,
- $lang_code.".".$up,
- $lang_code.".".$low,
- $lang_code.".".$ushort,
- $lang_code.".".$lshort) !== false;
- setlocale(LC_ALL, $old);
- setlocale(LC_NUMERIC, 'C');
- return $test;
- }
- /**
- * Add a translation domain.
- */
- function add_domain($domain, $path=false, $version='')
- {
- if ($path === false)
- $path = $this->domain_path;
- if ($path === false)
- $path = "./locale";
- if ($domain == "")
- $domain = "?";
- if ($version) {
- // To avoid need for apache server restart after change of *.mo file
- // we have to include file version as part of filename.
- // This is alternative naming convention: $domain = $version.'/'.$domain;
- $domain .= '-'.$version;
- }
- bindtextdomain($domain, $path);
- //bind_textdomain_codeset($domain, $encoding);
- textdomain($domain);
- }
-
- /**
- * Retrieve translation for specified key.
- *
- * @access private
- */
- function _get_translation($key)
- {
- return gettext($key);
- }
-
-
- /**
- * Reset interpolation variables.
- */
- function reset()
- {
- $this->_interpolation_vars = array();
- }
-
- /**
- * Set an interpolation variable.
- */
- function set_var($key, $value)
- {
- $this->_interpolation_vars[$key] = $value;
- }
-
- /**
- * Set an associative array of interpolation variables.
- */
- function set_vars($hash)
- {
- $this->_interpolation_vars = array_merge($this->_interpolation_vars,
- $hash);
- }
-
- /**
- * Retrieve translation for specified key.
- *
- * @param string $key -- gettext msgid
- * @throws GetText_Error
- */
- function gettext($key)
- {
- $value = $this->_get_translation($key);
- if ($value === false) {
- $str = sprintf('Unable to locate gettext key "%s"', $key);
- //$err = new GetText_Error($str);
- //return PEAR::raise_error($err);
- return raise_error("2 " . $str);
- }
-
- while (preg_match('/\$\{(.*?)\}/sm', $value, $m)) {
- list($src, $var) = $m;
-
- // retrieve variable to interpolate in context, throw an exception
- // if not found.
- $var2 = $this->_get_var($var);
- if ($var2 === false) {
- $str = sprintf('Interpolation error, var "%s" not set', $var);
- //$err = new GetText_Error($str);
- //return PEAR::raise_error($err);
- return raise_error("3 " . $str);
- }
- $value = str_replace($src, $var2, $value);
- }
- return $value;
- }
-
- /**
- * Retrieve an interpolation variable value.
- *
- * @return mixed
- * @access private
- */
- function _get_var($name)
- {
- if (!array_key_exists($name, $this->_interpolation_vars)) {
- return false;
- }
- return $this->_interpolation_vars[$name];
- }
-}
-
-
-/**
-* Implementation of get_text support for PHP.
-*
-* This implementation is abble to cache .po files into php files returning the
-* domain translation hashtable.
-*
-* @access private
-* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
-*/
-class gettext_php_support extends gettext_native_support
-{
- var $_path = 'locale/';
- var $_lang_code = false;
- var $_domains = array();
- var $_end = -1;
- var $_jobs = array();
-
- /**
- * Set the translation domain.
- *
- * @param string $lang_code -- language code
- * @throws GetText_Error
- */
- function set_language($lang_code, $encoding)
- {
- // if language already set, try to reload domains
- if ($this->_lang_code !== false and $this->_lang_code != $lang_code)
- {
- foreach ($this->_domains as $domain)
- {
- $this->_jobs[] = array($domain->name, $domain->path);
- }
- $this->_domains = array();
- $this->_end = -1;
- }
-
- $this->_lang_code = $lang_code;
-
- // this allow us to set the language code after
- // domain list.
- while (count($this->_jobs) > 0)
- {
- list($domain, $path) = array_shift($this->_jobs);
- $err = $this->add_domain($domain, $path);
- // error raised, break jobs
- /*if (PEAR::is_error($err)) {
- return $err;
- }*/
- if (is_error($err))
- {
- return $err;
- }
- }
- }
- /**
- * Check system support for given language (dummy).
- */
- function check_support($lang_code, $encoding)
- {
- return true;
- }
- /**
- * Add a translation domain.
- *
- * @param string $domain -- Domain name
- * @param string $path optional -- Repository path
- * @throws GetText_Error
- */
- function add_domain($domain, $path = false, $version ='')
- {
- if ($path === false)
- $path = $this->domain_path;
- if ($path === false)
- $path = "./locale";
-
- if ($version) {
- $domain .= '-'.$version;
- }
-
- if (array_key_exists($domain, $this->_domains))
- {
- return;
- }
-
- if (!$this->_lang_code)
- {
- $this->_jobs[] = array($domain, $path);
- return;
- }
- // Don't fill the domains with false data, it increased the error.log
- if (strpos($domain, $this->_lang_code) === false)
- return;
-
- $err = $this->_load_domain($domain, $path);
- if ($err != 0)
- {
- return $err;
- }
-
- $this->_end++;
- }
-
- /**
- * Load a translation domain file.
- *
- * This method cache the translation hash into a php file unless
- * GETTEXT_NO_CACHE is defined.
- *
- * @param string $domain -- Domain name
- * @param string $path optional -- Repository
- * @throws GetText_Error
- * @access private
- */
- function _load_domain($domain, $path = "./locale")
- {
- $src_domain = $path . "/$this->_lang_code/LC_MESSAGES/$domain.po";
- $php_domain = $path . "/$this->_lang_code/LC_MESSAGES/$domain.php";
-
- if (!file_exists($src_domain))
- {
- $str = sprintf('Domain file "%s" not found.', $src_domain);
- //$err = new GetText_Error($str);
- //return PEAR::raise_error($err);
- return raise_error("4 " . $str);
- }
-
- $d = new gettext_domain();
- $d->name = $domain;
- $d->path = $path;
- if (!file_exists($php_domain) || (filemtime($php_domain) < filemtime($src_domain)))
- {
-
- // parse and compile translation table
- $parser = new gettext_php_support_parser();
- $hash = $parser->parse($src_domain);
- if (!defined('GETTEXT_NO_CACHE'))
- {
- $comp = new gettext_php_support_compiler();
- $err = $comp->compile($hash, $src_domain);
- /*if (PEAR::is_error($err)) {
- return $err;
- }*/
- if (is_error($err))
- {
- return $err;
- }
- }
- $d->_keys = $hash;
- }
- else
- {
- $d->_keys = include $php_domain;
- }
- $this->_domains[] = &$d;
- }
-
- /**
- * Implementation of gettext message retrieval.
- */
- function _get_translation($key)
- {
- for ($i = $this->_end; $i >= 0; $i--)
- {
- if ($this->_domains[$i]->has_key($key))
- {
- return $this->_domains[$i]->get($key);
- }
- }
- return $key;
- }
-}
-
-/**
-* Class representing a domain file for a specified language.
-*
-* @access private
-* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
-*/
-class gettext_domain
-{
- var $name;
- var $path;
-
- var $_keys = array();
-
- function has_key($key)
- {
- return array_key_exists($key, $this->_keys);
- }
-
- function get($key)
- {
- return $this->_keys[$key];
- }
-}
-
-/**
-* This class is used to parse gettext '.po' files into php associative arrays.
-*
-* @access private
-* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
-*/
-class gettext_php_support_parser
-{
- var $_hash = array();
- var $_current_key;
- var $_current_value;
-
- /**
- * Parse specified .po file.
- *
- * @return hashtable
- * @throws GetText_Error
- */
- function parse($file)
- {
- $this->_hash = array();
- $this->_current_key = false;
- $this->_current_value = "";
-
- if (!file_exists($file))
- {
- $str = sprintf('Unable to locate file "%s"', $file);
- //$err = new GetText_Error($str);
- //return PEAR::raise_error($err);
- return raise_error($str);
- }
- $i = 0;
- $lines = file($file);
- foreach ($lines as $line)
- {
- $this->_parse_line($line, ++$i);
- }
- $this->_store_key();
-
- return $this->_hash;
- }
-
- /**
- * Parse one po line.
- *
- * @access private
- */
- function _parse_line($line, $nbr)
- {
- $line = str_replace("\\\"", "'", $line); // Should be inside preg_match, but I couldn't find the solution. This works.
- if (preg_match('/^\s*?#/', $line)) { return; }
- if (preg_match('/^\s*?msgid \"(.*?)(?!<\\\)\"/', $line, $m)) {
- $this->_store_key();
- $this->_current_key = $m[1];
- return;
- }
- if (preg_match('/^\s*?msgstr \"(.*?)(?!<\\\)\"/', $line, $m)) {
- $this->_current_value .= $m[1];
- return;
- }
- if (preg_match('/^\s*?\"(.*?)(?!<\\\)\"/', $line, $m)) {
- $this->_current_value .= $m[1];
- return;
- }
- }
-
- /**
- * Store last key/value pair into building hashtable.
- *
- * @access private
- */
- function _store_key()
- {
- if ($this->_current_key === false) return;
- $this->_current_value = str_replace('\\n', "\n", $this->_current_value);
- $this->_hash[$this->_current_key] = $this->_current_value;
- $this->_current_key = false;
- $this->_current_value = "";
- }
-}
-
-
-/**
-* This class write a php file from a gettext hashtable.
-*
-* The produced file return the translation hashtable on include.
-*
-* @throws GetText_Error
-* @access private
-* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
-*/
-class gettext_php_support_compiler
-{
- /**
- * Write hash in an includable php file.
- */
- function compile(&$hash, $source_path)
- {
- $dest_path = preg_replace('/\.po$/', '.php', $source_path);
- $fp = @fopen($dest_path, "w");
- if (!$fp)
- {
- $str = sprintf('Unable to open "%s" in write mode.', $dest_path);
- //$err = new GetText_Error($str);
- //return PEAR::raise_error($err);
- return raise_error($str);
- }
- fwrite($fp, '<?php' . "\n");
- fwrite($fp, 'return array(' . "\n");
- foreach ($hash as $key => $value)
- {
- $key = str_replace("'", "\\'", $key);
- $value = str_replace("'", "\\'", $value);
- fwrite($fp, ' \'' . $key . '\' => \'' . $value . "',\n");
- }
- fwrite($fp, ');' . "\n");
- fwrite($fp, '?>');
- fclose($fp);
- }
-}
-
-/*
- Set current gettext domain path
-*/
-function set_ext_domain($path='') {
- global $path_to_root, $GetText;
- static $domain_stack = array('');
-
- if ($path) // save path on domain stack
- array_unshift($domain_stack, $path);
- else
- {
- array_shift($domain_stack);
- $path = $domain_stack[0];
- }
-
- $lang_path = $path_to_root . ($path ? '/' : '') .$path.'/lang';
- // ignore change when extension does not provide translation structure and test for valid gettext.
- if (file_exists($lang_path) && isset($GetText))
- $GetText->add_domain($_SESSION['language']->code,
- $lang_path, $path ? '' : $_SESSION['language']->version);
-}
-?>
--- /dev/null
+<?php
+/**********************************************************************
+ Copyright (C) FrontAccounting, LLC.
+ Released under the terms of the GNU General Public License, GPL,
+ as published by the Free Software Foundation, either version 3
+ of the License, or (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
+// Prevent register_globals vulnerability
+if (isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
+ die("Restricted access");
+@include_once($path_to_root . "/lang/installed_languages.inc");
+include_once($path_to_root . "/includes/lang/gettext.inc");
+
+class language
+{
+ var $name;
+ var $code; // eg. ar_EG, en_GB
+ var $encoding; // eg. UTF-8, CP1256, ISO8859-1
+ var $dir; // Currently support for Left-to-Right (ltr) and
+ // Right-To-Left (rtl)
+ var $version; // lang package version
+ var $is_locale_file;
+
+ function language($name, $code, $encoding, $dir = 'ltr')
+ {
+ global $dflt_lang;
+
+ $this->name = $name;
+ $this->code = $code ? $code : ($dflt_lang ? $dflt_lang : 'C');
+ $this->encoding = $encoding;
+ $this->dir = $dir;
+ }
+
+ function get_language_dir()
+ {
+ return "lang/" . $this->code;
+ }
+
+ function get_current_language_dir()
+ {
+ $lang = $_SESSION['language'];
+ return "lang/" . $lang->code;
+ }
+
+ function set_language($code)
+ {
+ global $path_to_root, $installed_languages, $GetText;
+
+ $lang = array_search_value($code, $installed_languages, 'code');
+ $changed = $this->code != $code || $this->version != @$lang['version'];
+
+ if ($lang && $changed)
+ {
+ $this->name = $lang['name'];
+ $this->code = $lang['code'];
+ $this->encoding = $lang['encoding'];
+ $this->version = @$lang['version'];
+ $this->dir = (isset($lang['rtl']) && $lang['rtl'] === true) ? 'rtl' : 'ltr';
+ $locale = $path_to_root . "/lang/" . $this->code . "/locale.inc";
+ $this->is_locale_file = file_exists($locale);
+ }
+
+ $GetText->set_language($this->code, $this->encoding);
+ $GetText->add_domain($this->code, $path_to_root . "/lang", $this->version);
+
+ // Necessary for ajax calls. Due to bug in php 4.3.10 for this
+ // version set globally in php.ini
+ ini_set('default_charset', $this->encoding);
+
+ if (isset($_SESSION['wa_current_user']) && $_SESSION['wa_current_user']->logged_in() && isset($_SESSION['App']) && $changed)
+ $_SESSION['App']->init(); // refresh menu
+ }
+}
+
+if (!function_exists("_"))
+{
+ function _($text)
+ {
+ global $GetText;
+ if (!isset($GetText)) // Don't allow using gettext if not is net.
+ return $text;
+
+ $retVal = $GetText->gettext($text);
+ if ($retVal == "")
+ return $text;
+ return $retVal;
+ }
+}
+?>
\ No newline at end of file
+++ /dev/null
-<?php
-/**********************************************************************
- Copyright (C) FrontAccounting, LLC.
- Released under the terms of the GNU General Public License, GPL,
- as published by the Free Software Foundation, either version 3
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
-***********************************************************************/
-// Prevent register_globals vulnerability
-if (isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
- die("Restricted access");
-@include_once($path_to_root . "/lang/installed_languages.inc");
-include_once($path_to_root . "/includes/lang/gettext.php");
-
-class language
-{
- var $name;
- var $code; // eg. ar_EG, en_GB
- var $encoding; // eg. UTF-8, CP1256, ISO8859-1
- var $dir; // Currently support for Left-to-Right (ltr) and
- // Right-To-Left (rtl)
- var $version; // lang package version
- var $is_locale_file;
-
- function language($name, $code, $encoding, $dir = 'ltr')
- {
- global $dflt_lang;
-
- $this->name = $name;
- $this->code = $code ? $code : ($dflt_lang ? $dflt_lang : 'C');
- $this->encoding = $encoding;
- $this->dir = $dir;
- }
-
- function get_language_dir()
- {
- return "lang/" . $this->code;
- }
-
- function get_current_language_dir()
- {
- $lang = $_SESSION['language'];
- return "lang/" . $lang->code;
- }
-
- function set_language($code)
- {
- global $path_to_root, $installed_languages, $GetText;
-
- $lang = array_search_value($code, $installed_languages, 'code');
- $changed = $this->code != $code || $this->version != @$lang['version'];
-
- if ($lang && $changed)
- {
- // flush cache as we can use several languages in one account
- flush_dir(company_path().'/js_cache');
-
- $this->name = $lang['name'];
- $this->code = $lang['code'];
- $this->encoding = $lang['encoding'];
- $this->version = @$lang['version'];
- $this->dir = (isset($lang['rtl']) && $lang['rtl'] === true) ? 'rtl' : 'ltr';
- $locale = $path_to_root . "/lang/" . $this->code . "/locale.inc";
- $this->is_locale_file = file_exists($locale);
- }
-
- $GetText->set_language($this->code, $this->encoding);
- $GetText->add_domain($this->code, $path_to_root . "/lang", $this->version);
-
- // Necessary for ajax calls. Due to bug in php 4.3.10 for this
- // version set globally in php.ini
- ini_set('default_charset', $this->encoding);
-
- if (isset($_SESSION['wa_current_user']) && $_SESSION['wa_current_user']->logged_in() && isset($_SESSION['App']) && $changed)
- $_SESSION['App']->init(); // refresh menu
- }
-}
-
-if (!function_exists("_"))
-{
- function _($text)
- {
- global $GetText;
- if (!isset($GetText)) // Don't allow using gettext if not is net.
- return $text;
-
- $retVal = $GetText->gettext($text);
- if ($retVal == "")
- return $text;
- return $retVal;
- }
-}
-?>
\ No newline at end of file
include_once($path_to_root . "/includes/db/connect_db.inc");
include_once($path_to_root . "/includes/types.inc");
-include_once($path_to_root . "/includes/systypes.inc");
include_once($path_to_root . "/includes/references.inc");
include_once($path_to_root . "/includes/db/comments_db.inc");
include_once($path_to_root . "/includes/db/sql_functions.inc");
if(!$go_debug) $text = js_compress($text);
- $file = fopen($fpath, 'w');
+ $file = force_open($fpath);
if (!$file) return false;
if (!fwrite($file, $text)) return false;
return fclose($file);
}
+/*
+ Open file for writing with creration of subfolders if needed.
+*/
+function force_open($fname)
+{
+ $file = pathinfo($fname);
+
+ $path = $fname[0] == '/' ? '/' : '';
+ $tree = explode('/', $file['dirname']);
+ foreach($tree as $level) {
+ $path .= $level;
+ if (!file_exists($path)) {
+ if (!mkdir($path)) {
+ return null;
+ }
+ }
+ $path .= '/';
+ }
+ return fopen($fname, 'w');
+}
+
function add_js_file($filename)
{
global $js_static;
$js ='';
foreach($js_static as $jsfile)
{
- $fpath = company_path().'/js_cache/'.$jsfile;
+ $cached_name = basename($jsfile);
+ $fpath = user_js_cache().'/'.$cached_name;
// compress also static files
if (!file_exists($fpath) || $go_debug)
cache_js_file($fpath, file_get_contents($js_path.$jsfile));
}
}
-//----------------------------------------------------------------------------
-//
-// Check if reference was not used so far (for other transaction than $trans_no)
-//
-function is_new_reference($ref, $type, $trans_no=0)
-{
- $db_info = get_systype_db_info($type);
- $db_name = $db_info[0];
- $db_type = $db_info[1];
- $db_trans = $db_info[2];
- $db_ref = $db_info[3];
-
- $ref = db_escape(trim($ref));
- $type = db_escape($type);
-
- if ($db_ref == null) { // journal or bank trans store references in refs table
- $db_name = TB_PREF."refs";
- $db_type = 'type';
- $db_trans = 'id';
- $db_ref = 'reference';
- }
-
- if ($db_type != null) {
- $sql = "SELECT $db_ref FROM $db_name tbl
- LEFT JOIN ".TB_PREF."voided v ON
- tbl.$db_type=v.type AND tbl.$db_trans=v.id
- WHERE $db_ref=$ref AND ISNULL(v.id)
- AND tbl.$db_type=$type";
- } else {
- $sql = "SELECT $db_ref ref FROM $db_name tbl
- LEFT JOIN ".TB_PREF."voided v ON
- v.type=$type AND tbl.$db_trans=v.id
- WHERE $db_ref=$ref AND ISNULL(v.id)";
- }
- if ($trans_no)
- $sql .= " AND tbl.`$db_trans` != ".db_escape($trans_no);
-
- $result = db_query($sql, "could not test for unique reference");
-
- return (db_num_rows($result) == 0);
-
-}
-
-
?>
\ No newline at end of file
$filename = $path_to_root."/tmp/faillog.php";
- if ((!file_exists($filename) && is_writable($path_to_root)) || is_writable($filename))
+ if ((!file_exists($filename) && is_writable($path_to_root.'/tmp')) || is_writable($filename))
{
file_put_contents($filename, $msg);
}
include_once($path_to_root . "/includes/current_user.inc");
include_once($path_to_root . "/frontaccounting.php");
include_once($path_to_root . "/admin/db/security_db.inc");
-include_once($path_to_root . "/includes/lang/language.php");
+include_once($path_to_root . "/includes/lang/language.inc");
include_once($path_to_root . "/config_db.php");
include_once($path_to_root . "/includes/ajax.inc");
include_once($path_to_root . "/includes/ui/ui_msgs.inc");
+++ /dev/null
-<?php
-/**********************************************************************
- Copyright (C) FrontAccounting, LLC.
- Released under the terms of the GNU General Public License, GPL,
- as published by the Free Software Foundation, either version 3
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
-***********************************************************************/
-
-//-----------------------------------------------------------------------------------------
-// Returns next transaction number.
-// Used only for transactions stored in tables without autoincremented key.
-//
-
-function get_next_trans_no ($trans_type){
-
- $st = get_systype_db_info($trans_type);
-
- if (!($st && $st[0] && $st[2])) {
- // this is in fact internal error condition.
- display_error('Internal error: invalid type passed to get_next_trans_no()');
- return 0;
- }
- $sql1 = "SELECT MAX(`$st[2]`) as last_no FROM $st[0]";
- if ($st[1] != null)
- $sql1 .= " WHERE `$st[1]`=".db_escape($trans_type);
-
- // check also in voided transactions (some transactions like location transfer are removed completely)
- $sql2 = "SELECT MAX(`id`) as last_no FROM ".TB_PREF."voided WHERE `type`=".db_escape($trans_type);
-
- $sql = "SELECT max(last_no) last_no FROM ($sql1 UNION $sql2) a";
- $result = db_query($sql,"The next transaction number for $trans_type could not be retrieved");
- $myrow = db_fetch_row($result);
-
- return $myrow[0] + 1;
-}
-
-//-----------------------------------------------------------------------------
-
-function get_systype_db_info($type)
-{
- switch ($type)
- {
- case ST_JOURNAL : return array("".TB_PREF."gl_trans", "type", "type_no", null, "tran_date");
- case ST_BANKPAYMENT : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
- case ST_BANKDEPOSIT : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
- case 3 : return null;
- case ST_BANKTRANSFER : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
- case ST_SALESINVOICE : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
- case ST_CUSTCREDIT : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
- case ST_CUSTPAYMENT : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
- case ST_CUSTDELIVERY : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
- case ST_LOCTRANSFER : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date");
- case ST_INVADJUST : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date");
- case ST_PURCHORDER : return array("".TB_PREF."purch_orders", null, "order_no", "reference", "ord_date");
- case ST_SUPPINVOICE : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
- case ST_SUPPCREDIT : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
- case ST_SUPPAYMENT : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
- case ST_SUPPRECEIVE : return array("".TB_PREF."grn_batch", null, "id", "reference", "delivery_date");
- case ST_WORKORDER : return array("".TB_PREF."workorders", null, "id", "wo_ref", "released_date");
- case ST_MANUISSUE : return array("".TB_PREF."wo_issues", null, "issue_no", "reference", "issue_date");
- case ST_MANURECEIVE : return array("".TB_PREF."wo_manufacture", null, "id", "reference", "date_");
- case ST_SALESORDER : return array("".TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date");
- case 31 : return array("".TB_PREF."service_orders", null, "order_no", "cust_ref", "date");
- case ST_SALESQUOTE : return array("".TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date");
- case ST_DIMENSION : return array("".TB_PREF."dimensions", null, "id", "reference", "date_");
- case ST_COSTUPDATE : return array("".TB_PREF."gl_trans", "type", "type_no", null, "tran_date");
- }
-
- display_db_error("invalid type ($type) sent to get_systype_db_info", "", true);
-}
-
-function get_systypes()
-{
- $sql = "SELECT * FROM ".TB_PREF."sys_types";
- $result = db_query($sql, "could not query systypes table");
- return $result;
-}
-
-?>
\ No newline at end of file
//
// Returns counterparty (supplier/customer) name for selected transaction.
//
-function get_counterparty_name($trans_type, $trans_no, $full=true)
+function get_counterparty_name($trans_type, $trans_no)
{
switch($trans_type)
{
function get_js_date_picker()
{
global $go_debug;
- $fpath = company_path().'/js_cache/'.'date_picker.js';
+ $fpath = user_js_cache().'/'.'date_picker.js';
if (!file_exists($fpath) || $go_debug) {
set_error_handler('error_handler' /*, errtypes */);
include_once($path_to_root . "/includes/current_user.inc");
-include_once($path_to_root . "/includes/lang/language.php");
+include_once($path_to_root . "/includes/lang/language.inc");
include_once($path_to_root . "/includes/ajax.inc");
include_once($path_to_root . "/includes/ui/ui_msgs.inc");
include_once($path_to_root . "/includes/prefs/sysprefs.inc");
//--------------------------------------------------------------------------------------
function update_work_order($woid, $loc_code, $units_reqd, $stock_id,
- $date_, $required_by, $memo_)
+ $date_, $required_by, $memo_, $old_stock_id, $old_qty)
{
begin_transaction();
$args = func_get_args();
'date_', 'required_by', 'memo_'), $args);
hook_db_prewrite($args, ST_WORKORDER);
- add_material_cost($_POST['old_stk_id'], -$_POST['old_qty'], $date_);
+ add_material_cost($old_stock_id, -$old_qty, $date_);
add_material_cost($stock_id, $units_reqd, $date_);
$date = date2sql($date_);
commit_transaction();
}
-function delete_work_order($woid)
+function delete_work_order($woid, $stock_id, $qty, $date)
{
begin_transaction();
hook_db_prevoid(ST_WORKORDER, $woid);
- add_material_cost($_POST['stock_id'], -$_POST['quantity'], $_POST['date_']);
+ add_material_cost($stock_id, -$qty, $date);
// delete the work order requirements
delete_wo_requirements($woid);
db_query($sql,"The work order could not be deleted");
delete_comments(ST_WORKORDER, $woid);
- add_audit_trail(ST_WORKORDER, $woid, $_POST['date_'], _("Canceled."));
+ add_audit_trail(ST_WORKORDER, $woid, $date, _("Canceled."));
commit_transaction();
}
commit_transaction();
}
-function get_sql_for_work_orders($outstanding_only, $all_items)
+function get_sql_for_work_orders($outstanding_only, $stock_id, $location = ALL_TEXT, $order = '', $overdue = false)
{
$sql = "SELECT
workorder.id,
$sql .= " AND workorder.closed=0";
}
- if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
+ if ($location != ALL_TEXT)
{
- $sql .= " AND workorder.loc_code=".db_escape($_POST['StockLocation']);
+ $sql .= " AND workorder.loc_code=".db_escape($location);
}
- if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
+ if ($order != '')
{
- $sql .= " AND workorder.wo_ref LIKE ".db_escape('%'.$_POST['OrderNumber'].'%');
+ $sql .= " AND workorder.wo_ref LIKE ".db_escape('%'.$order.'%');
}
- if (isset($_POST['SelectedStockItem']) && $_POST['SelectedStockItem'] != $all_items)
+ if ($stock_id != '')
{
- $sql .= " AND workorder.stock_id=".db_escape($_POST['SelectedStockItem']);
+ $sql .= " AND workorder.stock_id=".db_escape($stock_id);
}
- if (check_value('OverdueOnly'))
+ if ($overdue)
{
$Today = date2sql(Today());
return $sql;
}
-function get_sql_for_where_used()
+function get_sql_for_where_used($stock_id)
{
$sql = "SELECT
bom.parent,
WHERE bom.parent = parent.stock_id
AND bom.workcentre_added = workcentre.id
AND bom.loc_code = location.loc_code
- AND bom.component=".db_escape($_POST['stock_id']);
- return $sql;
+ AND bom.component=".db_escape($stock_id);
+ return $sql;
}
//--------------------------------------------------------------------------------------
function get_gl_wo_cost($woid, $cost_type)
"/manufacturing/manage/bom_edit.php?stock_id=" . $row["parent"]);
}
-$sql = get_sql_for_where_used();
+$sql = get_sql_for_where_used($_POST['stock_id']);
$cols = array(
_("Parent Item") => array('fun'=>'select_link'),
return number_format2($amount, $row['decimals']);
}
-$sql = get_sql_for_work_orders($outstanding_only, $all_items);
+$sql = get_sql_for_work_orders($outstanding_only, $_POST['SelectedStockItem'], $_POST['StockLocation'],
+ $_POST['OrderNumber'], check_value('OverdueOnly'));
$cols = array(
_("#") => array('fun'=>'view_link', 'ord'=>''),
{
update_work_order($selected_id, $_POST['StockLocation'], input_num('quantity'),
- $_POST['stock_id'], $_POST['date_'], $_POST['RequDate'], $_POST['memo_']);
+ $_POST['stock_id'], $_POST['date_'], $_POST['RequDate'], $_POST['memo_'],
+ $_POST['old_stk_id'], $_POST['old_qty']);
new_doc_date($_POST['date_']);
meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
}
{ //ie not cancelled the delete as a result of above tests
// delete the actual work order
- delete_work_order($selected_id);
+ delete_work_order($selected_id, $_POST['stock_id'], $_POST['quantity'], $_POST['date_']);
meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
}
}
date_row(_("Date") . ":", 'date_', '', true);
hidden('RequDate', '');
- $sql = "SELECT DISTINCT account_code FROM ".TB_PREF."bank_accounts";
- $rs = db_query($sql,"could not get bank accounts");
- $r = db_fetch_row($rs);
+ $bank_act = get_default_bank_account();
if (!isset($_POST['Labour']))
{
$_POST['Labour'] = price_format(0);
- $_POST['cr_lab_acc'] = $r[0];
+ $_POST['cr_lab_acc'] = $bank_act['account_code'];
}
+
amount_row($wo_cost_types[WO_LABOUR], 'Labour');
gl_all_accounts_list_row(_("Credit Labour Account"), 'cr_lab_acc', null);
if (!isset($_POST['Costs']))
{
$_POST['Costs'] = price_format(0);
- $_POST['cr_acc'] = $r[0];
+ $_POST['cr_acc'] = $bank_act['account_code'];
}
amount_row($wo_cost_types[WO_OVERHEAD], 'Costs');
gl_all_accounts_list_row(_("Credit Overhead Account"), 'cr_acc', null);
-
+
}
if (get_post('released'))
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
+// ------------------------------------------------------------------------------
+
+function get_supplier_details_to_order(&$order, $supplier_id)
+{
+ $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, supp.tax_algorithm,
+ supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1)
+ * (ov_amount + ov_gst + ov_discount),0)) as cur_credit,
+ terms.terms, terms.days_before_due, terms.day_in_following_month
+ FROM ".TB_PREF."suppliers supp
+ LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id
+ LEFT JOIN ".TB_PREF."payment_terms terms ON supp.payment_terms=terms.terms_indicator
+ WHERE supp.supplier_id = ".db_escape($supplier_id)."
+ GROUP BY
+ supp.supp_name";
+
+ $result = db_query($sql, "The supplier details could not be retreived");
+ $myrow = db_fetch($result);
+
+ $order->credit = $myrow["cur_credit"];
+ $order->terms = array(
+ 'description' => $myrow['terms'],
+ 'days_before_due' => $myrow['days_before_due'],
+ 'day_in_following_month' => $myrow['day_in_following_month'] );
+
+ $_POST['supplier_id'] = $supplier_id;
+ $_POST['supplier_name'] = $myrow["supp_name"];
+ $_POST['curr_code'] = $myrow["curr_code"];
+
+ $order->set_supplier($supplier_id, $myrow["supp_name"], $myrow["curr_code"],
+ $myrow["tax_group_id"], $myrow["tax_included"], $myrow["tax_algorithm"]);
+}
+
//----------------------------------------------------------------------------------------
function delete_po($po)
return db_query($sql,"The stock details for " . $stock_id . " could not be retrieved");
}
-function get_sql_for_po_search_completed($supplier_id=ALL_TEXT)
+function get_sql_for_po_search_completed($from, $to, $supplier_id=ALL_TEXT, $location=ALL_TEXT,
+ $order_number = '', $stock_id = '')
{
- global $order_number, $selected_stock_item;;
$sql = "SELECT
porder.order_no,
AND porder.supplier_id = supplier.supplier_id
AND location.loc_code = porder.into_stock_location ";
- if (isset($_GET['supplier_id']))
- $sql .= "AND supplier.supplier_id=".@$_GET['supplier_id']." ";
+ if ($supplier_id != ALL_TEXT)
+ $sql .= "AND supplier.supplier_id=".$supplier_id." ";
if (isset($order_number) && $order_number != "")
{
$sql .= "AND porder.reference LIKE ".db_escape('%'. $order_number . '%');
else
{
- $data_after = date2sql($_POST['OrdersAfterDate']);
- $date_before = date2sql($_POST['OrdersToDate']);
+ $data_after = date2sql($from);
+ $date_before = date2sql($to);
$sql .= " AND porder.ord_date >= '$data_after'";
$sql .= " AND porder.ord_date <= '$date_before'";
- if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != ALL_TEXT)
+ if ($location != ALL_TEXT)
{
- $sql .= " AND porder.into_stock_location = ".db_escape($_POST['StockLocation']);
+ $sql .= " AND porder.into_stock_location = ".db_escape($location);
}
if (isset($selected_stock_item))
{
- $sql .= " AND line.item_code=".db_escape($selected_stock_item);
+ $sql .= " AND line.item_code=".db_escape($stock_id);
}
if ($supplier_id != ALL_TEXT)
$sql .= " AND supplier.supplier_id=".db_escape($supplier_id);
-
- } //end not order number selected
+
+ }
$sql .= " GROUP BY porder.order_no";
return $sql;
-}
+}
-function get_sql_for_po_search($supplier_id=ALL_TEXT)
+function get_sql_for_po_search($from, $to, $supplier_id=ALL_TEXT, $location=ALL_TEXT)
{
global $all_items, $order_number, $selected_stock_item;;
}
else
{
- $data_after = date2sql($_POST['OrdersAfterDate']);
- $data_before = date2sql($_POST['OrdersToDate']);
+ $data_after = date2sql($from);
+ $data_before = date2sql($to);
$sql .= " AND porder.ord_date >= '$data_after'";
$sql .= " AND porder.ord_date <= '$data_before'";
- if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
+ if ($location != ALL_TEXT)
{
- $sql .= " AND porder.into_stock_location = ".db_escape($_POST['StockLocation']);
+ $sql .= " AND porder.into_stock_location = ".db_escape($location);
}
if (isset($selected_stock_item))
}
-function get_sql_for_supplier_allocation_inquiry()
+function get_sql_for_supplier_allocation_inquiry($from, $to, $filter, $supplier_id, $all=false)
{
- $date_after = date2sql($_POST['TransAfterDate']);
- $date_to = date2sql($_POST['TransToDate']);
+ $date_after = date2sql($from);
+ $date_to = date2sql($to);
$sql = "SELECT
trans.type,
AND trans.tran_date >= '$date_after'
AND trans.tran_date <= '$date_to'";
- if ($_POST['supplier_id'] != ALL_TEXT)
- $sql .= " AND trans.supplier_id = ".db_escape($_POST['supplier_id']);
- if (isset($_POST['filterType']) && $_POST['filterType'] != ALL_TEXT)
+ if ($supplier_id != ALL_TEXT)
+ $sql .= " AND trans.supplier_id = ".db_escape($supplier_id);
+
+ if ($filter != ALL_TEXT)
{
- if (($_POST['filterType'] == '1') || ($_POST['filterType'] == '2'))
+ if (($filter == '1') || ($filter == '2'))
{
$sql .= " AND trans.type = ".ST_SUPPINVOICE." ";
}
- elseif ($_POST['filterType'] == '3')
+ elseif ($filter == '3')
{
$sql .= " AND trans.type = ".ST_SUPPAYMENT." ";
}
- elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
+ elseif (($filter == '4') || ($filter == '5'))
{
$sql .= " AND trans.type = ".ST_SUPPCREDIT." ";
}
- if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
+ if (($filter == '2') || ($filter == '5'))
{
$today = date2sql(Today());
$sql .= " AND trans.due_date < '$today' ";
}
}
- if (!check_value('showSettled'))
+ if (!$all)
{
$sql .= " AND (round(abs(ov_amount + ov_gst + ov_discount) - alloc,6) != 0) ";
}
supp_account_no, bank_account, credit_limit, dimension_id, dimension2_id, curr_code,
payment_terms, payable_account, purchase_account, payment_discount_account, notes,
tax_group_id, tax_included, tax_algorithm)
- VALUES (".db_escape($_POST['supp_name']). ", "
+ VALUES (".db_escape($supp_name). ", "
.db_escape($supp_ref). ", "
.db_escape($address) . ", "
.db_escape($supp_address) . ", "
. " WHERE supplier_id=".db_escape($supplier_id);
return db_query($sql, "cannot update supplier's tax calculation algorithm");
}
+
+function get_supplier_currency($supplier_id)
+{
+ $sql = "SELECT curr_code FROM ".TB_PREF."suppliers WHERE supplier_id = ".db_escape($supplier_id);
+
+ $result = db_query($sql, "Retreive currency of supplier $supplier_id");
+
+ $myrow=db_fetch_row($result);
+ return $myrow[0];
+}
+
$cart->tax_overrides[$id] = user_numeric($_POST['mantax'][$id]); }
}
}
-// ------------------------------------------------------------------------------
-
-function get_supplier_details_to_order(&$order, $supplier_id)
-{
- $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, supp.tax_algorithm,
- supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1)
- * (ov_amount + ov_gst + ov_discount),0)) as cur_credit,
- terms.terms, terms.days_before_due, terms.day_in_following_month
- FROM ".TB_PREF."suppliers supp
- LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id
- LEFT JOIN ".TB_PREF."payment_terms terms ON supp.payment_terms=terms.terms_indicator
- WHERE supp.supplier_id = ".db_escape($supplier_id)."
- GROUP BY
- supp.supp_name";
-
- $result = db_query($sql, "The supplier details could not be retreived");
-
- $myrow = db_fetch($result);
- $order->credit = $myrow["cur_credit"];
- $order->terms = array(
- 'description' => $myrow['terms'],
- 'days_before_due' => $myrow['days_before_due'],
- 'day_in_following_month' => $myrow['day_in_following_month'] );
-
- $_POST['supplier_id'] = $supplier_id;
- $_POST['supplier_name'] = $myrow["supp_name"];
- $_POST['curr_code'] = $myrow["curr_code"];
-
- $order->set_supplier($supplier_id, $myrow["supp_name"], $myrow["curr_code"],
- $myrow["tax_group_id"], $myrow["tax_included"], $myrow["tax_algorithm"]);
-}
//---------------------------------------------------------------------------------------------------
{
/*If this is the first time the form loaded set up defaults */
- //$_POST['StkLocation'] = $_SESSION['UserStockLocation'];
- $sql = "SELECT delivery_address, phone FROM ".TB_PREF."locations WHERE loc_code=".db_escape($_POST['StkLocation']);
- $result = db_query($sql,"could not get location info");
-
- if (db_num_rows($result) == 1)
+ $loc_row = get_item_location(get_post('StkLocation'));
+ if ($loc_row)
{
- $loc_row = db_fetch($result);
$_POST['delivery_address'] = $loc_row["delivery_address"];
$Ajax->activate('delivery_address');
$_SESSION['PO']->Location = $_POST['StkLocation'];
$order_number = $_POST['order_number'];
}
-if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
- ($_POST['SelectStockFromList'] != $all_items))
-{
- $selected_stock_item = $_POST['SelectStockFromList'];
-}
-else
-{
- unset($selected_stock_item);
-}
-
//figure out the sql required from the inputs available
-$sql = get_sql_for_po_search($_POST['supplier_id']);
+$sql = get_sql_for_po_search($_POST['OrdersAfterDate'], $_POST['OrdersToDate'], $_POST['supplier_id'],
+ $_POST['StockLocation']);
//$result = db_query($sql,"No orders were returned");
if (isset($_GET['order_number']))
{
- $order_number = $_GET['order_number'];
+ $_POST['order_number'] = $_GET['order_number'];
}
//-----------------------------------------------------------------------------------
end_row();
end_table(1);
//---------------------------------------------------------------------------------------------
-if (isset($_POST['order_number']))
-{
- $order_number = $_POST['order_number'];
-}
-
-if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
- ($_POST['SelectStockFromList'] != ALL_TEXT))
-{
- $selected_stock_item = $_POST['SelectStockFromList'];
-}
-else
-{
- unset($selected_stock_item);
-}
-//---------------------------------------------------------------------------------------------
function trans_view($trans)
{
return get_trans_view_str(ST_PURCHORDER, $trans["order_no"]);
//---------------------------------------------------------------------------------------------
-$sql = get_sql_for_po_search_completed(!@$_GET['popup'] ? $_POST['supplier_id'] : ALL_TEXT);
+$sql = get_sql_for_po_search_completed(get_post('OrdersAfterDate'), get_post('OrdersToDate'),
+ @$_GET['popup'] ? ALL_TEXT : get_post('supplier_id'),
+ get_post('StockLocation'), get_post('order_number'), get_post('SelectStockFromList'));
$cols = array(
_("#") => array('fun'=>'trans_view', 'ord'=>''),
}
//------------------------------------------------------------------------------------------------
-$sql = get_sql_for_supplier_allocation_inquiry();
+$sql = get_sql_for_supplier_allocation_inquiry($_POST['TransAfterDate'],$_POST['TransToDate'],
+ $_POST['filterType'], $_POST['supplier_id'], check_value('showSettled'));
$cols = array(
_("Type") => array('fun'=>'systype_name'),
if (!in_array($this->formData['doctype'], array(ST_STATEMENT, ST_WORKORDER)))
{
- $id = $this->formData['payment_terms'];
- $sql = "SELECT terms, days_before_due FROM ".TB_PREF."payment_terms WHERE terms_indicator=".db_escape($id);
- $result = db_query($sql,"could not get paymentterms");
- $row = db_fetch($result);
+ $row = get_payment_terms($this->formData['payment_terms']);
$Payment_Terms = _("Payment Terms") . ': ' . $row["terms"];
if ($this->formData['doctype'] == ST_SALESINVOICE && $this->formData['prepaid'])
$this->formData['prepaid'] = ($row['days_before_due'] >= 0) ? 'final' : 'partial';
display_footer_exit();
} else
- check_edit_conflicts();
+ check_edit_conflicts(get_post('cart_id'));
//--------------------------------------------------------------------------------
display_footer_exit();
} else
- check_edit_conflicts();
+ check_edit_conflicts(get_post('cart_id'));
//-----------------------------------------------------------------------------
exit;
} else {
- check_edit_conflicts();
+ check_edit_conflicts(get_post('cart_id'));
if (!check_quantities()) {
display_error(_("Selected quantity cannot be less than quantity invoiced nor more than quantity not dispatched on sales order."));
//-----------------------------------------------------------------------------
-check_edit_conflicts();
+check_edit_conflicts(get_post('cart_id'));
if (isset($_GET['AddedID'])) {
hyperlink_params("$path_to_root/sales/inquiry/sales_deliveries_view.php", _("Select Another &Delivery For Invoicing"), "OutstandingOnly=1");
- $sql = "SELECT trans_type_from, trans_no_from FROM ".TB_PREF."cust_allocations
- WHERE trans_type_to=".ST_SALESINVOICE." AND trans_no_to=".db_escape($invoice_no);
- $result = db_query($sql, "could not retrieve customer allocation");
- $row = db_fetch($result);
-
- if ($row === false)
+ if (!db_num_rows(get_allocatable_from_cust_transactions(null, $invoice_no, $trans_type)))
hyperlink_params("$path_to_root/sales/customer_payments.php", _("Entry &customer payment for this invoice"),
"SInvoice=".$invoice_no);
return db_fetch($result);
}
-function get_sql_for_customer_branches()
+function get_sql_for_customer_branches($customer_id)
{
$sql = "SELECT "
."b.branch_code, "
WHERE b.tax_group_id=t.id
AND b.area=a.area_code
AND b.salesman=s.salesman_code
- AND b.debtor_no = ".db_escape($_POST['customer_id']);
+ AND b.debtor_no = ".db_escape($customer_id);
if (!get_post('show_inactive')) $sql .= " AND !b.inactive";
$sql .= " GROUP BY b.branch_code ORDER BY branch_ref";
}
//----------------------------------------------------------------------------------------
-
-function get_sql_for_customer_inquiry()
+function get_sql_for_customer_inquiry($from, $to, $cust_id = ALL_TEXT, $filter = ALL_TEXT)
{
- $date_after = date2sql($_POST['TransAfterDate']);
- $date_to = date2sql($_POST['TransToDate']);
+ $date_after = date2sql($from);
+ $date_to = date2sql($to);
$sql = "SELECT
trans.type,
debtor.curr_code,
(trans.ov_amount + trans.ov_gst + trans.ov_freight
+ trans.ov_freight_tax + trans.ov_discount) AS TotalAmount, ";
- if ($_POST['filterType'] != ALL_TEXT)
+ if ($filter != ALL_TEXT)
$sql .= "@bal := @bal+(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount), ";
// else
AND trans.tran_date <= '$date_to'
AND trans.branch_code = branch.branch_code";
- if ($_POST['customer_id'] != ALL_TEXT)
- $sql .= " AND trans.debtor_no = ".db_escape($_POST['customer_id']);
+ if ($cust_id != ALL_TEXT)
+ $sql .= " AND trans.debtor_no = ".db_escape($cust_id);
- if ($_POST['filterType'] != ALL_TEXT)
+ if ($filter != ALL_TEXT)
{
- if ($_POST['filterType'] == '1')
+ if ($filter == '1')
{
$sql .= " AND (trans.type = ".ST_SALESINVOICE.") ";
}
- elseif ($_POST['filterType'] == '2')
+ elseif ($filter == '2')
{
$sql .= " AND (trans.type = ".ST_SALESINVOICE.") ";
}
- elseif ($_POST['filterType'] == '3')
+ elseif ($filter == '3')
{
$sql .= " AND (trans.type = " . ST_CUSTPAYMENT
." OR trans.type = ".ST_BANKDEPOSIT." OR trans.type = ".ST_BANKPAYMENT.") ";
}
- elseif ($_POST['filterType'] == '4')
+ elseif ($filter == '4')
{
$sql .= " AND trans.type = ".ST_CUSTCREDIT." ";
}
- elseif ($_POST['filterType'] == '5')
+ elseif ($filter == '5')
{
$sql .= " AND trans.type = ".ST_CUSTDELIVERY." ";
}
- if ($_POST['filterType'] == '2')
+ if ($filter == '2')
{
$today = date2sql(Today());
$sql .= " AND trans.due_date < '$today'
return $sql;
}
-function get_sql_for_sales_deliveries_view($selected_customer, $selected_stock_item=null, $customer_id=ALL_TEXT)
+function get_sql_for_sales_deliveries_view($from, $to, $customer_id, $stock_item, $location, $delivery, $outstanding=false)
{
$sql = "SELECT trans.trans_no,
debtor.name,
AND trans.branch_code = branch.branch_code
AND trans.debtor_no = branch.debtor_no ";
- if ($_POST['OutstandingOnly'] == true) {
+ if ($outstanding == true) {
$sql .= " AND line.qty_done < line.quantity ";
}
//figure out the sql required from the inputs available
- if (isset($_POST['DeliveryNumber']) && $_POST['DeliveryNumber'] != "")
+ if ($delivery)
{
- $delivery = "%".$_POST['DeliveryNumber'];
- $sql .= " AND trans.trans_no LIKE ".db_escape($delivery);
+ $sql .= " AND trans.trans_no LIKE %".db_escape($delivery);
$sql .= " GROUP BY trans.trans_no";
}
else
{
- $sql .= " AND trans.tran_date >= '".date2sql($_POST['DeliveryAfterDate'])."'";
- $sql .= " AND trans.tran_date <= '".date2sql($_POST['DeliveryToDate'])."'";
+ $sql .= " AND trans.tran_date >= '".date2sql($from)."'";
+ $sql .= " AND trans.tran_date <= '".date2sql($to)."'";
- if ($selected_customer != -1)
- $sql .= " AND trans.debtor_no=".db_escape($selected_customer)." ";
+ if ($stock_item)
+ $sql .= " AND line.stock_id=".db_escape($stock_item)." ";
- if (isset($selected_stock_item))
- $sql .= " AND line.stock_id=".db_escape($selected_stock_item)." ";
+ if ($location != ALL_TEXT)
+ $sql .= " AND sorder.from_stk_loc = ".db_escape($location)." ";
- if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != ALL_TEXT)
- $sql .= " AND sorder.from_stk_loc = ".db_escape($_POST['StockLocation'])." ";
-
if ($customer_id != ALL_TEXT)
- $sql .= " AND trans.debtor_no = ".db_escape($customer_id);
+ $sql .= " AND trans.debtor_no = ".db_escape($customer_id);
$sql .= " GROUP BY trans.trans_no ";
return db_fetch($result);
}
-?>
\ No newline at end of file
+//----------------------------------------------------------------------------------
+
+function get_customer_currency($customer_id)
+{
+ $sql = "SELECT curr_code FROM ".TB_PREF."debtors_master WHERE debtor_no = ".db_escape($customer_id);
+
+ $result = db_query($sql, "Retreive currency of customer $customer_id");
+
+ $myrow=db_fetch_row($result);
+ return $myrow[0];
+}
+
$result = db_fetch(db_query($sql, "cannot retrieve sales invoices for sales order"));
return $result[0];
}
+
+//---------------------------------------------------------------------------------------------
+//
+// Mark/unmark sales order as template.
+//
+function sales_order_set_template($id, $status)
+{
+ $sql = "UPDATE ".TB_PREF."sales_orders SET type = ".db_escape($status)." WHERE order_no=".db_escape($id);
+ db_query($sql, "Can't change sales order type");
+}
Check if the cart was not destroyed during opening the edition page in
another browser tab.
*/
-function check_edit_conflicts($cartname='Items')
+function check_edit_conflicts($cart_id, $cartname='Items')
{
global $Ajax, $no_check_edit_conflicts;
- if ((!isset($no_check_edit_conflicts) || $no_check_edit_conflicts==0) && get_post('cart_id') && $_POST['cart_id'] != $_SESSION[$cartname]->cart_id) {
+ if ((!isset($no_check_edit_conflicts) || $no_check_edit_conflicts==0) && get_post('cart_id') && $cart_id != $_SESSION[$cartname]->cart_id) {
display_error(_('This edit session has been abandoned by opening sales document in another browser tab. You cannot edit more than one sales document at once.'));
$Ajax->activate('_page_body');
display_footer_exit();
&& floatcmp($row["TotalAmount"], $row["Allocated"]) != 0;
}
//------------------------------------------------------------------------------------------------
-$sql = get_sql_for_customer_inquiry();
+$sql = get_sql_for_customer_inquiry(get_post('TransAfterDate'), get_post('TransToDate'),
+ get_post('customer_id'), get_post('filterType'));
//------------------------------------------------------------------------------------------------
db_query("set @bal:=0");
if (isset($_GET['selected_customer']))
{
- $selected_customer = $_GET['selected_customer'];
+ $_POST['customer_id'] = $_GET['selected_customer'];
}
elseif (isset($_POST['selected_customer']))
{
- $selected_customer = $_POST['selected_customer'];
+ $_POST['customer_id'] = $_POST['selected_customer'];
}
-else
- $selected_customer = -1;
if (isset($_POST['BatchInvoice']))
{
end_table(1);
//---------------------------------------------------------------------------------------------
-if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
- ($_POST['SelectStockFromList'] != ALL_TEXT))
-{
- $selected_stock_item = $_POST['SelectStockFromList'];
-}
-else
-{
- $selected_stock_item = null;
-}
-
-//---------------------------------------------------------------------------------------------
function trans_view($trans, $trans_no)
{
return get_customer_trans_view_str(ST_CUSTDELIVERY, $trans['trans_no']);
$row["Outstanding"]!=0;
}
//------------------------------------------------------------------------------------------------
-$sql = get_sql_for_sales_deliveries_view($selected_customer, $selected_stock_item, $_POST['customer_id']);
+$sql = get_sql_for_sales_deliveries_view(get_post('DeliveryAfterDate'), get_post('DeliveryToDate'), get_post('customer_id'),
+ get_post('SelectStockFromList'), get_post('StockLocation'), get_post('DeliveryNumber'), get_post('OutstandingOnly'));
$cols = array(
_("Delivery #") => array('fun'=>'trans_view'),
"/sales/customer_invoice.php?InvoicePrepayments=" .$row['order_no'], ICON_DOC) : '';
}
-//---------------------------------------------------------------------------------------------
-// Update db record if respective checkbox value has changed.
-//
-function change_tpl_flag($id)
+$id = find_submit('_chgtpl');
+if ($id != -1)
{
- global $Ajax;
-
- $sql = "UPDATE ".TB_PREF."sales_orders SET type = !type WHERE order_no=$id";
-
- db_query($sql, "Can't change sales order type");
+ sales_order_set_template($id, check_value('chgtpl'.$id));
$Ajax->activate('orders_tbl');
}
-$id = find_submit('_chgtpl');
-if ($id != -1)
- change_tpl_flag($id);
-
if (isset($_POST['Update']) && isset($_POST['last'])) {
foreach($_POST['last'] as $id => $value)
if ($value != check_value('chgtpl'.$id))
- change_tpl_flag($id);
+ sales_order_set_template($id, !check_value('chgtpl'.$id));
}
$show_dates = !in_array($_POST['order_view_mode'], array('OutstandingOnly', 'InvoiceTemplates', 'DeliveryTemplates'));
echo customer_list('customer_id', null, false, true);
echo "</center><br>";
-$num_branches = db_customer_has_branches($_POST['customer_id']);
+$num_branches = db_customer_has_branches(get_post('customer_id'));
-$sql = get_sql_for_customer_branches();
+$sql = get_sql_for_customer_branches(get_post('customer_id'));
//------------------------------------------------------------------------------------------------
if ($num_branches)
submenu_print(_("&Print Sales Invoice"), ST_SALESINVOICE, $invoice."-".ST_SALESINVOICE, 'prtopt');
submenu_print(_("&Email Sales Invoice"), ST_SALESINVOICE, $invoice."-".ST_SALESINVOICE, null, 1);
set_focus('prtopt');
-
- $sql = "SELECT trans_type_from, trans_no_from FROM ".TB_PREF."cust_allocations
- WHERE trans_type_to=".ST_SALESINVOICE." AND trans_no_to=".db_escape($invoice);
- $result = db_query($sql, "could not retrieve customer allocation");
- $row = db_fetch($result);
+
+ $row = db_fetch(get_allocatable_from_cust_transactions(null, $invoice, ST_SALESINVOICE));
if ($row !== false)
- submenu_print(_("Print &Receipt"), $row['trans_type_from'], $row['trans_no_from']."-".$row['trans_type_from'], 'prtopt');
+ submenu_print(_("Print &Receipt"), $row['type'], $row['trans_no']."-".$row['type'], 'prtopt');
display_note(get_gl_view_str(ST_SALESINVOICE, $invoice, _("View the GL &Journal Entries for this Invoice")),0, 1);
display_footer_exit();
} else
- check_edit_conflicts();
+ check_edit_conflicts(get_post('cart_id'));
//-----------------------------------------------------------------------------
function copy_to_cart()
display_error( _("The item could not be updated because you are attempting to set the quantity ordered to less than 0, or the discount percent to more than 100."));
set_focus('qty');
return false;
- } elseif (!check_num('price', 0) && (!$SysPrefs->$allow_negative_prices() || $is_inventory_item)) {
+ } elseif (!check_num('price', 0) && (!$SysPrefs->allow_negative_prices() || $is_inventory_item)) {
display_error( _("Price for inventory item must be entered and can not be less than 0"));
set_focus('price');
return false;
if (get_company_pref('grn_clearing_act') === null) { // available form 2.3.1, can be not defined on pre-2.4 installations
set_company_pref('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, 0);
}
- if (get_company_pref('default_receival_required') === null) { // new in 2.4 installations
- set_company_pref('default_receival_required', 'glsetup.purchase', 'smallint', 6, 10);
- }
if (get_company_pref('default_quote_valid_days') === null) { // new in 2.3.23 installations
set_company_pref('default_quote_valid_days', 'glsetup.sales', 'smallint', 6, 30);
}
- if (get_company_pref('no_zero_lines_amount') === null) { // new in 2.4 installations
- set_company_pref('no_zero_lines_amount', 'glsetup.sales', 'tinyint', 1, '1');
- refresh_sys_prefs();
- }
- if (get_company_pref('show_po_item_codes') === null) { // new in 2.4 installations
- set_company_pref('show_po_item_codes', 'glsetup.purchase', 'tinyint', 1, '0');
- refresh_sys_prefs();
- }
- if (get_company_pref('accounts_alpha') === null) { // new in 2.4 installations
- set_company_pref('accounts_alpha', 'glsetup.general', 'tinyint', 1, '0');
- refresh_sys_prefs();
- }
- if (get_company_pref('loc_notification') === null) { // new in 2.4 installations
- set_company_pref('loc_notification', 'glsetup.inventory', 'tinyint', 1, '0');
- refresh_sys_prefs();
- }
- if (get_company_pref('print_invoice_no') === null) { // new in 2.4 installations
- set_company_pref('print_invoice_no', 'glsetup.sales', 'tinyint', 1, '0');
- refresh_sys_prefs();
- }
- if (get_company_pref('allow_negative_prices') === null) { // new in 2.4 installations
- set_company_pref('allow_negative_prices', 'glsetup.inventory', 'tinyint', 1, '1');
- refresh_sys_prefs();
- }
- if (get_company_pref('print_item_images_on_quote') === null) { // new in 2.4 installations
- set_company_pref('print_item_images_on_quote', 'glsetup.inventory', 'tinyint', 1, '0');
- refresh_sys_prefs();
- }
if (get_company_pref('bcc_email') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations
set_company_pref('bcc_email', 'setup.company', 'varchar', 100, '');
- refresh_sys_prefs();
}
if (get_company_pref('alternative_tax_include_on_docs') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations
set_company_pref('alternative_tax_include_on_docs', 'setup.company', 'tinyint', 1, '0');
- refresh_sys_prefs();
}
if (get_company_pref('suppress_tax_rates') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations
set_company_pref('suppress_tax_rates', 'setup.company', 'tinyint', 1, '0');
- refresh_sys_prefs();
}
-$result = $this->update_workorders() && $this->update_grn_rates() && $this->switch_database_to_utf($pref);
+ $result = $this->update_workorders() && $this->update_grn_rates() && $this->switch_database_to_utf($pref);
if ($result)
$result = $this->do_cleanup();
ALTER TABLE `0_users` ADD `use_date_picker` TINYINT(1) NOT NULL default '1' COMMENT 'Use Date Picker for all Date Values' AFTER `save_report_selections`;
ALTER TABLE `0_users` ADD `def_print_destination` TINYINT(1) NOT NULL default '0' COMMENT 'Default Report Destination' AFTER `use_date_picker`;
ALTER TABLE `0_users` ADD `def_print_orientation` TINYINT(1) NOT NULL default '0' COMMENT 'Default Report Orientation' AFTER `def_print_destination`;
+
+INSERT INTO `0_sys_prefs` VALUES('no_zero_lines_amount', 'glsetup.sales', 'tinyint', 1, '1');
+INSERT INTO `0_sys_prefs` VALUES('show_po_item_codes', 'glsetup.purchase', 'tinyint', 1, '0');
+INSERT INTO `0_sys_prefs` VALUES('accounts_alpha', 'glsetup.general', 'tinyint', 1, '0');
+INSERT INTO `0_sys_prefs` VALUES('loc_notification', 'glsetup.inventory', 'tinyint', 1, '0');
+INSERT INTO `0_sys_prefs` VALUES('print_invoice_no', 'glsetup.sales', 'tinyint', 1, '0');
+INSERT INTO `0_sys_prefs` VALUES('allow_negative_prices', 'glsetup.inventory', 'tinyint', 1, '1');
+INSERT INTO `0_sys_prefs` VALUES('print_item_images_on_quote', 'glsetup.inventory', 'tinyint', 1, '0');
+INSERT INTO `0_sys_prefs` VALUES('default_receival_required', 'glsetup.purchase', 'smallint', 6, '10');
`sticky_doc_date` tinyint(1) default '0',
`startup_tab` varchar(20) NOT NULL default '',
`transaction_days` smallint(6) NOT NULL default '30',
- 'save_report_selections' smallint(6) NOT NULL default '0',
- 'use_date_picker' tinyint(1) NOT NULL default '1',
- 'def_print_destination' tinyint(1) NOT NULL default '0',
- 'def_print_orientation' tinyint(1) NOT NULL default '0',
+ `save_report_selections` smallint(6) NOT NULL default '0',
+ `use_date_picker` tinyint(1) NOT NULL default '1',
+ `def_print_destination` tinyint(1) NOT NULL default '0',
+ `def_print_orientation` tinyint(1) NOT NULL default '0',
`inactive` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `user_id` (`user_id`)
`sticky_doc_date` tinyint(1) default '0',
`startup_tab` varchar(20) NOT NULL default '',
`transaction_days` smallint(6) NOT NULL default '30',
- 'save_report_selections' smallint(6) NOT NULL default '0',
- 'use_date_picker' tinyint(1) NOT NULL default '1',
- 'def_print_destination' tinyint(1) NOT NULL default '0',
- 'def_print_orientation' tinyint(1) NOT NULL default '0',
+ `save_report_selections` smallint(6) NOT NULL default '0',
+ `use_date_picker` tinyint(1) NOT NULL default '1',
+ `def_print_destination` tinyint(1) NOT NULL default '0',
+ `def_print_orientation` tinyint(1) NOT NULL default '0',
`inactive` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `user_id` (`user_id`)