You are on page 1of 71

Front Accounting

5 / 2 2 / 2 0 1 3
m. ali syaifudin
API Manual Reference

1

FRONTACCOUNTING API MANUAL ................................................................................... 5
Table of Contents ......................................................................................................................................... 5
UI Functions ................................................................................................................................................... 9
function page($title, $no_menu=false, $is_index=false, $onload="", $js="") ...................................................... 9
function end_page($no_menu=false, $is_index=false) ........................................................................................ 9
function display_error($msg, $center=true) ...................................................................................................... 10
function display_notification($msg, $center=true) ............................................................................................ 10
function display_heading($msg) ......................................................................................................................... 11
function display_heading2($msg) ....................................................................................................................... 11
function display_note($msg, $br=0, $br2=0, $extra="") .................................................................................... 11
function start_form($multi=false, $sid=false, $action="", $name="") ............................................................... 12
function end_form($breaks=0) ........................................................................................................................... 12
function start_table($extra="", $padding='2', $spacing='0') .............................................................................. 13
function end_table($breaks=0) .......................................................................................................................... 13
function table_header($labels)........................................................................................................................... 14
function start_row($param="") .......................................................................................................................... 14
function alt_table_row_color(&$k) .................................................................................................................... 14
function end_row() ............................................................................................................................................. 15
function edit_link_cell($param) .......................................................................................................................... 15
function delete_link_cell($param) ...................................................................................................................... 15
function br($num=1) ........................................................................................................................................... 15
function meta_forward($forward_to, $params="") ........................................................................................... 16
function hyperlink_back($center=true) .............................................................................................................. 16
function hyperlink_params($target, $label, $params, $center=true) ................................................................ 16
function hidden($name, $value)......................................................................................................................... 17
function submit($name, $value, $echo=true) .................................................................................................... 17
function submit_cells($name, $value, $extra="") .............................................................................................. 18
function submit_row($name, $value, $right=true, $extra="") ........................................................................... 18
function check($label, $name, $value, $submit_on_change=false) ................................................................... 19
function check_cells($label, $name, $value, $submit_on_change=false) .......................................................... 20
function check_row($label, $name, $value, $submit_on_change=false) .......................................................... 20
function label_cell($label, $params="") ............................................................................................................. 20
function amount_cell($label, $bold=false) ......................................................................................................... 21
function qty_cell($label, $bold=false) ................................................................................................................ 21
function label_cells($label, $value, $params="", $params2="") ........................................................................ 22
function label_row($label, $value, $params="", $params2="") ......................................................................... 22
function text_cells($label, $name, $value, $size="", $max="", $params="", $post_label="", $disabled="") .... 22
function text_row($label, $name, $value, $size, $max, $params="", $post_label="") ...................................... 22
function text_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null) ............. 23
function text_row_ex($label, $name, $size, $max=null, $value=null, $params=null, $post_label=null) ........... 23
function date_cells($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null).... 25
function date_row($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null) .... 25
function percent_row($label, $name, $init=null) ............................................................................................... 26
function amount_cells($label, $name, $init=null, $params=null, $post_label=null) ......................................... 26
2

function amount_row($label, $name, $init=null, $params=null, $post_label=null) .......................................... 26
function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null) ............................... 27
function textarea_cells($label, $name, $value, $cols, $rows, $params="") ....................................................... 28
function textarea_row($label, $name, $value, $cols, $rows, $params="") ....................................................... 28
function supplier_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false) ........ 29
function supplier_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false) ........ 29
function customer_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false) ..... 30
function customer_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false) ...... 30
function customer_branches_list_cells($label, $name, $selected_id, $all_option=false, $enabled=true,
$submit_on_change=false) ................................................................................................................................. 31
function customer_branches_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false) ................................................................................................................................. 31
function locations_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false) ...... 32
function locations_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false) ....... 32
function currencies_list_cells($label, $name, $selected_id) .............................................................................. 32
function currencies_list_row($label, $name, $selected_id) ............................................................................... 32
function fiscalyears_list_cells($label, $name, $selected_id) .............................................................................. 33
function fiscalyears_list_row($label, $name, $selected_id)............................................................................... 33
function dimensions_list_cells($label, $name, $selected_id, $no_option=false, $showname=null,
$showclosed=false, $showtype=0) ..................................................................................................................... 34
function dimensions_list_row($label, $name, $selected_id, $no_option=false, $showname=null,
$showclosed=false, $showtype=0) ..................................................................................................................... 34
function stock_items_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false) . 35
function stock_items_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false) .. 35
function stock_bom_items_list_cells($label, $name, $selected_id, $all_option=false,
$submit_on_change=false) ................................................................................................................................. 36
function stock_bom_items_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false) ................................................................................................................................. 36
function stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option=false,
$submit_on_change=false) ................................................................................................................................. 37
function stock_manufactured_items_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false) ................................................................................................................................. 37
function stock_purchasable_items_list_cells($label, $name, $selected_id, $all_option=false,
$submit_on_change=false) ................................................................................................................................. 38
function stock_purchasable_items_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false) ................................................................................................................................. 38
function stock_item_types_list_row($label, $name, $selected_id, $enabled=true) ......................................... 38
function stock_units_list_row($label, $name, $selected_id, $enabled=true) ................................................... 39
function stock_categories_list_cells($label, $name, $selected_id).................................................................... 40
function stock_categories_list_row($label, $name, $selected_id) .................................................................... 40
function tax_type_list_cells($label, $name, $selected_id, $all_option=false, $all_option_name=null,
$submit_on_change=false) ................................................................................................................................. 41
function tax_type_list_row($label, $name, $selected_id, $all_option=false, $all_option_name=null,
$submit_on_change=false) ................................................................................................................................. 41
function tax_groups_list_cells($label, $name, $selected_id, $submit_on_change=false) ................................ 41
function tax_groups_list_row($label, $name, $selected_id, $submit_on_change=false) ................................. 41
3

function item_tax_types_list_cells($label, $name, $selected_id) ...................................................................... 42
function item_tax_types_list_row($label, $name, $selected_id) ...................................................................... 42
function shippers_list_cells($label, $name, $selected_id) ................................................................................. 43
function shippers_list_row($label, $name, $selected_id) .................................................................................. 43
function sales_persons_list_cells($label, $name, $selected_id) ........................................................................ 43
function sales_persons_list_row($label, $name, $selected_id) ......................................................................... 43
function sales_areas_list_cells($label, $name, $selected_id) ............................................................................ 44
function sales_areas_list_row($label, $name, $selected_id) ............................................................................. 44
function workorders_list_cells($label, $name, $selected_id) ............................................................................ 45
function workorders_list_row($label, $name, $selected_id) ............................................................................. 45
function payment_terms_list_cells($label, $name, $selected_id) ..................................................................... 45
function payment_terms_list_row($label, $name, $selected_id) ...................................................................... 45
function credit_status_list_cells($label, $name, $selected_id).......................................................................... 46
function credit_status_list_row($label, $name, $selected_id) .......................................................................... 46
function sales_types_list_cells($label, $name, $selected_id) ............................................................................ 47
function sales_types_list_row($label, $name, $selected_id) ............................................................................. 47
function movements_types_list_cells($label, $name, $selected_id) ................................................................. 47
function movement_types_list_row($label, $name, $selected_id) ................................................................... 47
function bank_trans_types_list_cells($label, $name, $selected_id) .................................................................. 48
function bank_trans_types_list_row($label, $name, $selected_id)................................................................... 48
function workcenter_list_cells($label, $name, $selected_id, $all_option=false) .............................................. 48
function workcenter_list_row($label, $name, $selected_id, $all_option=false) ............................................... 48
function bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change=false) .......................... 49
function bank_accounts_list_row($label, $name, $selected_id, $submit_on_change=false) ........................... 49
function class_list_cells($label, $name, $selected_id, $submit_on_change=false) ........................................... 50
function class_list_row($label, $name, $selected_id, $submit_on_change=false) ........................................... 50
function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false,
$show_group=false, $on_change="") ................................................................................................................. 51
function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false,
$show_group=false, $on_change="") ................................................................................................................. 51
function yesno_list_cells($label, $name, $selected_id, $name_yes="", $name_no="",
$submit_on_change=false) ................................................................................................................................. 52
function yesno_list_row($label, $name, $selected_id, $name_yes="", $name_no="",
$submit_on_change=false) ................................................................................................................................. 52
function languages_list_cells($label, $name, $selected_id) .............................................................................. 53
function languages_list_row($label, $name, $selected_id) ............................................................................... 53
function number_list_cells($label, $name, $selected_id, $from, $to) ............................................................... 53
function number_list_row($label, $name, $selected_id, $from, $to) ............................................................... 53
Javascript Functions ................................................................................................................................. 55
function get_js_go_back() .................................................................................................................................. 55
function get_js_open_window($width, $height) ............................................................................................... 55
function get_js_date_picker() ............................................................................................................................. 55
function alert($msg) ........................................................................................................................................... 55
Database Functions (low level) .......................................................................................................... 57
4

function db_query($sql, $err_msg) .................................................................................................................... 57
function db_fetch_row($result).......................................................................................................................... 57
function db_fetch($result) .................................................................................................................................. 57
function db_num_rows($result) ......................................................................................................................... 58
function db_num_fields($result) ........................................................................................................................ 58
function db_insert_id() ....................................................................................................................................... 58
function begin_transaction ................................................................................................................................. 59
function commit_transaction ............................................................................................................................. 59
function cancel_transaction ............................................................................................................................... 59
Database Functions (high level) ........................................................................................................ 60
Date functions ............................................................................................................................................. 61
function is_date($date_) .................................................................................................................................... 61
function today() .................................................................................................................................................. 61
function now() .................................................................................................................................................... 61
function is_date_in_fiscalyear($date, $convert=false) ...................................................................................... 61
function begin_fiscalyear() ................................................................................................................................. 62
function end_fiscalyear() .................................................................................................................................... 62
function begin_month($date) ............................................................................................................................ 62
function end_month($date) ............................................................................................................................... 62
function add_days($date, $days)........................................................................................................................ 63
function add_months($date, $months) .............................................................................................................. 63
function add_years($date, $years) ..................................................................................................................... 64
function sql2date($date) .................................................................................................................................... 64
function date2sql($date) .................................................................................................................................... 64
function date1_greater_date2($date1, $date2) ................................................................................................. 65
Formatting Functions ............................................................................................................................... 66
function number_format2($number, $decimals=0) ........................................................................................... 66
Example Page .............................................................................................................................................. 67


5

FrontAccounting API Manual
Copyright 2007 by JH Global Consulting LLC

When you are changing something inside FrontAccounting or you are writing an add-on
module you typically need an overview over the functions you can use to get your
changes/modules to look the same way as FrontAccounting.
You will need some database routines, some UI routines when creating forms for adapting
data from your user, some routines for displaying the data to the user. You will also need
some date conversions functions, amount formatting functions that automatically follow the
underlying settings for FrontAccounting.
The functions presented here are only a small selection of the functions inside
FrontAccounting. They are the most commonly used, however, please have a closer look
inside the referenced files. Even for understanding the behavior of the functions it is a good
idea to study the routines carefully.
Table of Contents
UI Functions
o page
o end_page
o display_error
o display_notification
o display_heading
o display_heading2
o display_note
o start_form
o end_form
o start_table
o end_table
o table_header
o start_row
o alt_table_row_color
o end_row
o edit_link_cell
o delete_link_cell
o br
o meta_forward
o hyperlink_back
o hyperlink_params
o hidden
o submit
o submit_cells
o submit_row
o check
o check_cells
o check_row
6

o label_cell
o amount_cell
o qty_cell
o label_cells
o label_row
o text_cells
o text_cells_ex
o text_row
o text_row_ex
o date_cells
o date_row
o percent_row
o amount_cells
o amount_row
o small_amount_cells
o textarea_cells
o textarea_row
o supplier_list_cells
o supplier_list_row
o customer_list_cells
o customer_list_row
o customer_branches_list_cells
o customer_branches_list_row
o locations_list_cells
o locations_list_row
o currencies_list_cells
o currencies_list_row
o fiscalyears_list_cells
o fiscalyears_list_row
o dimensions_list_cells
o dimensions_list_row
o stock_items_list_cells
o stock_items_list_row
o stock_bom_items_list_cells
o stock_bom_items_list_row
o stock_manufactured_items_list_cells
o stock_manufactured_items_list_row
o stock_purchasable_items_list_cells
o stock_purchasable_items_list_row
o stock_item_types_list_row
o stock_units_list_row
o stock_categories_list_cells
o stock_categories_list_row
o tax_types_list_cells
o tax_types_list_row
o tax_groups_list_cells
o tax_groups_list_row
o item_tax_types_list_cells
o item_tax_types_list_row
o shippers_list_cells
o shippers_list_row
o sales_persons_list_cells
o sales_persons_list_row
7

o sales_areas_list_cells
o sales_areas_list_row
o workorders_list_cells
o workorders_list_row
o payment_terms_list_cells
o payment_terms_list_row
o credit_status_list_cells
o credit_status_list_row
o sales_types_list_cells
o sales_types_list_row
o movements_types_list_cells
o movement_types_list_row
o bank_trans_types_list_cells
o bank_trans_types_list_row
o workcenter_list_cells
o workcenter_list_row
o bank_accounts_list_cells
o bank_accounts_list_row
o class_list_cells
o class_list_row
o gl_all_accounts_list_cells
o gl_all_accounts_list_row
o yesno_list_cells
o yesno_list_row
o languages_list_cells
o languages_list_row
o number_list_cells
o number_list_row
Javascript Functions
o get_js_go_back
o get_js_open_window
o get_js_date_picker
o alert
Database Functions (low level)
o db_query
o db_fetch_row
o db_fetch
o db_num_rows
o db_num_fields
o db_insert_id
o begin_transaction
o commit_transaction
o cancel_transaction
Database Functions (high level)
Date Functions
o is_date
o today
o now
o is_date_in_fiscalyear
o begin_fiscalyear
o end_fiscalyear
o begin_month
o end_month
8

o add_days
o add_months
o add_years
o sql2date
o date2sql
o date1_greater_date2
Formatting Functions
o number_format2
Example Page

9

UI Functions

function page($title, $no_menu=false, $is_index=false, $onload="", $js="")
Action: Prints the page title and the header of the page.

Return value: None

File: /includes/main.inc

Parameters:
$title The page
title
$no_menu If true,
no menu
line is
printed.
Set to
true for
popup
windows.
$is_index If true,
no title
line is
displayed
$onload If set,
the given
javascript
code is
run on
load.
$js If set,
the
javascript
code is
included
in the
header.

function end_page($no_menu=false, $is_index=false)
Action: Prints the page footer of the page.

Return value: None

File: /includes/main.inc

Parameters:
10

$no_menu If true,
no
power
urls are
printed.
Set to
true for
popup
windows.
$is_index Not used
at the
moment.

function display_error($msg, $center=true)
Action: Prints an error string in bold and with bgcolor #ffcccc, optional centered.

Return value: None

File: /includes/ui/ui_msg.inc

Parameters:
$msg The error
message
string to
be
printed.
$center If true,
the
message
is
centered.

function display_notification($msg, $center=true)
Action: Prints a notifications string in bold and with bgcolor #ccffcc, optional centered.

Return value: None

File: /includes/ui/ui_msg.inc

Parameters:
$msg The
notification
message
string to
be printed.
$center If true, the
11

message
is
centered.

function display_heading($msg)
Action: Prints a centered heading string in bold.

Return value: None

File: /includes/ui/ui_msg.inc

Parameters:
$msg The
heading
string
to be
printed.

function display_heading2($msg)
Action: Prints a centered alternative heading string in bold.

Return value: None

File: /includes/ui/ui_msg.inc

Parameters:
$msg The
heading
string
to be
printed.

function display_note($msg, $br=0, $br2=0, $extra="")
Action: Prints a centered note in normal text with optional break lines before and after.

Return value: None

File: /includes/ui/ui_msg.inc

Parameters:
$msg The
heading
string to
be
12

printed.
$br Number
of break
lines
before
the
message.
$br2 Number
of break
lines
after the
message.
$extra Extra
values,
style or
class to
be put in
a span.

function start_form($multi=false, $sid=false, $action="", $name="")
Action: Prints the start of a form.

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
$multi true = fields for
uploading, false =
normal form
$sid true = SID (session id)
is included in the
action, false = nothing
is included
$action The action URL when
submitted. Empty
string =
$_SERVER['PHP_SELF']
$name The name of the form.

function end_form($breaks=0)
Action: Prints the end of the form.

Return value: None

File: /includes/ui/ui_controls.inc
13


Parameters:
$breaks Number
of
break
lines
inside
the
form

function start_table($extra="", $padding='2', $spacing='0')
Action: Prints the start of a centered table.

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
$extra Extra
parameters
ex. style
$padding The value
of the cell
paddings,
default is 2
$spacing The value
of the cell
spacing,
default is 2

function end_table($breaks=0)
Action: Prints the end of a centered table.

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
$breaks Number
of
break
lines
after
the
table
14


function table_header($labels)
Action: Prints the table headers from an array of labels.

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
$labels An
array
of
labels
for the
table
header

function start_row($param="")
Action: Prints the start of a table row.

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
$param Parameters
to the
table row
(tr)

function alt_table_row_color(&$k)
Action: Prints the start of a table row and with alternative background colors.

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
$k The k
value of
the row.
Set this
value to 0
before the
loop.
15


function end_row()
Action: Prints the end of a table row.

Return value: None

File: /includes/ui/ui_controls.inc

function edit_link_cell($param)
Action: Prints an edit link with GET params.

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
$param Prints the GET params
that is added to the
$_SERVER['PHP_SELF'].

function delete_link_cell($param)
Action: Prints a delete link with GET params.

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
$param Prints the GET params
that is added to the
$_SERVER['PHP_SELF'].

function br($num=1)
Action: Prints break lines, default is 1.

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
$num Print a
number
of
break
16

lines,
default
is 1

function meta_forward($forward_to, $params="")
Action: Prints the HTML for forwarding the user to another URL.

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
$forward_to The URL
that the
user is
forwarded
to.
$params Optional
parameters
(GET)
added to
the URL

function hyperlink_back($center=true)
Action: Prints a back link

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
$center The link
is
centered
if value
is true

function hyperlink_params($target, $label, $params, $center=true)
Action: Prints a link and a label with GET parameters

Return value: None

File: /includes/ui/ui_controls.inc

Parameters:
17

$target The
URL-link
$label The
label-
value of
the link
$params The GET
params
to be
added
to the
URL-link
$center If the
link
should
be
centered
(default
true)

function hidden($name, $value)
Action: Prints an input type hidden with name and value.

Return value: None

File: /includes/ui/ui_input.inc

Parameters:
$name The
name
of the
hidden
field.
$value The
value
of the
hidden
field.

function submit($name, $value, $echo=true)
Action: Prints a submit button or returns a string with name and value and optional
printed.

Return value: If $echo is false the entire html string is returned instead.

File: /includes/ui/ui_input.inc
18


Parameters:
$name The
name of
the
submit
button.
$value The
value of
the
submit
button.
$echo If this
value is
true the
submit
button is
printed,
otherwise
the HTML
is
returned.

function submit_cells($name, $value, $extra="")
Action: Prints a submit button inside a TD.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$name The name
of the
submit
button.
$value The value
of the
submit
button.
$extra Parameters
to the TD.

function submit_row($name, $value, $right=true, $extra="")
Action: Prints a submit button inside a TR-TD.

Return value: None.
19


File: /includes/ui/ui_input.inc

Parameters:
$name The name
of the
submit
button.
$value The value
of the
submit
button.
$right If this is
true, an
extra,
empty TD
is printed.
$extra Parameters
to the TD.

function check($label, $name, $value, $submit_on_change=false)
Action: Prints a checkbox with an optional label.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$label If this is
not null,
a label is
printed in
front of
the
checkbox.
$name The name
of the
checkbox.
$value The value
of the
checkbox.
$submit_on_change If this is
true, the
form is
submitted
when
20

clicking
the
checkbox.

function check_cells($label, $name, $value, $submit_on_change=false)
function check_row($label, $name, $value, $submit_on_change=false)
Action: Prints a checkbox with an optional label inside a TD or TR-TD.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$label If this is
not null,
a label is
printed in
a TD
before
the
checkbox.
$name The name
of the
checkbox.
$value The value
of the
checkbox.
$submit_on_change If this is
true, the
form is
submitted
when
clicking
the
checkbox.

function label_cell($label, $params="")
Action: Prints a label (text) inside a TD.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$label A label is
21

printed in
a TD.
$params Parameters
to the TD.

function amount_cell($label, $bold=false)
Action: Prints a user formatted, right aligned amount inside a TD.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$label The
amount
to be
printed
in a
TD.
$bold If this
is true,
the
amount
is
printed
in bold.

function qty_cell($label, $bold=false)
Action: Prints a user formatted, right aligned quantity inside a TD.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$label The
quantity
to be
printed
in a TD.
$bold If this is
true,
the
quantity
is
printed
22

in bold.

function label_cells($label, $value, $params="", $params2="")
function label_row($label, $value, $params="", $params2="")
Action: Prints a value (text) inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$label If this is
not null, a
label is
printed in
a TD.
$value The value
is printed
in a TD.
$params Parameters
to the label
TD.
$params2 Parameters
to the
value TD.

function text_cells($label, $name, $value, $size="", $max="", $params="", $post_label="",
$disabled="")
function text_row($label, $name, $value, $size, $max, $params="", $post_label="")
Action: Prints an input text box inside a TD or TR-TD with an optional label TD and optional
post label and optional disabled.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the input
23

text box.
$value If $value is
null and the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.
$size If $size is
not empty a
size is set.
$max If $max is
not empty a
maxlength
is set.
$params Parameters
to the label
TD.
$post_label If
$post_label
is not empty
a label is
printed after
the input
box.
$disabled The value of
$disabled is
printed just
after the
input. Can
be used for
extra
parameters
for the input
box.

function text_cells_ex($label, $name, $size, $max=null, $init=null, $params=null,
$post_label=null)
function text_row_ex($label, $name, $size, $max=null, $value=null, $params=null,
$post_label=null)
Action: Like text_cells, but if $init is not null, the POST[name] is set to $init, otherwise
POST[name] is set to an empty string. The value is set to POST[name].

Return value: None.
24


File: /includes/ui/ui_input.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the input
text box.
$size If $size is
not empty a
size is set.
$max If $max is
not set, the
maxlength is
set to $size.
$init If $init is not
set, the
POST[name]
is set to
$init,
otherwise
POST[name]
is set to an
empty string.
The value is
set to
POST[name].
$params Parameters
to the label
TD.
$post_label If
$post_label
is not empty
a label is
printed after
the input
box.

25

function date_cells($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0,
$params=null)
function date_row($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0,
$params=null)
Action: Like text_cells, but if $init is not null, the POST[name] is set to $init, otherwise
POST[name] is set to today's date.
The value is set to POST[name]. The date values are user formatted. If the global variable,
$use_date_picker, is set
a date picker is is placed after the input box, where you can alter the date values.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the input
text box.
$init If $init is not
set, the
POST[name]
is set to
$init,
otherwise
POST[name]
is set to
today's date.
The value is
set to
POST[name].
$inc_days If $init is not
set, you can
add an initial
day value.
Negative
values are
allowed.
$inc_months If $init is not
set, you can
add an initial
month value.
Negative
values are
allowed.
26

$inc_years If $init is not
set, you can
add an initial
year value.
Negative
values are
allowed.
$params Parameters
to the label
TD.

function percent_row($label, $name, $init=null)
Action: Prints a percent input text box, with a '%' label after, inside a TR-TD with an
optional label TD.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the input
text box.
$init If $init is
null and the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

function amount_cells($label, $name, $init=null, $params=null, $post_label=null)
function amount_row($label, $name, $init=null, $params=null, $post_label=null)
Action: Prints an amount input text box (max 15 digits) inside a TD or TR-TD with an
optional label TD.

Return value: None.

File: /includes/ui/ui_input.inc
27


Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the input
text box.
$init If $init is
null and the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.
$params The
$params to
the $label
TD.
$post_label The
$post_label
after the
input box.

function small_amount_cells($label, $name, $init=null, $params=null, $post_label=null)
Action: Prints an small amount input text box (max 12 digits) inside a TD or TR-TD with an
optional label TD.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the input
text box.
$init If $init is
null and the
28

POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.
$params The
$params to
the $label
TD.
$post_label The
$post_label
after the
input box.

function textarea_cells($label, $name, $value, $cols, $rows, $params="")
function textarea_row($label, $name, $value, $cols, $rows, $params="")
Action: Prints a multi line text box inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_input.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the textarea
box.
$value If $value is
null and the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.
$cols The width in
characters
of the
29

textarea
box.
$rows The number
of rows in
the textarea
box.
$params The
$params to
the $label
TD.

function supplier_list_cells($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
function supplier_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
Action: Prints a supplier listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name
of the list
box.
$selected_id If
$selected_id
is null and
the
POST[name
] is not set
an empty
value is set,
otherwise
the
POST[name
] value is
set.
$all_option If true, All is
the first
choice.
$submit_on_chang If true, the
30

e form is
submitted
on change.

function customer_list_cells($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
function customer_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
Action: Prints a customer listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name
of the list
box.
$selected_id If
$selected_id
is null and
the
POST[name
] is not set
an empty
value is set,
otherwise
the
POST[name
] value is
set.
$all_option If true, All is
the first
choice.
$submit_on_chang
e
If true, the
form is
submitted
on change.

31

function customer_branches_list_cells($label, $name, $selected_id, $all_option=false,
$enabled=true, $submit_on_change=false)
function customer_branches_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
Action: Prints a customer branch listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.
$all_option If true, All is
the first
choice.
$enabled If true, only
disable_tran
s = 0 are
shown.
$submit_on_chang
e
If true, the
form is
submitted
on change.

32

function locations_list_cells($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
function locations_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
Action: Prints a locations listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name
of the list
box.
$selected_id If
$selected_id
is null and
the
POST[name
] is not set
an empty
value is set,
otherwise
the
POST[name
] value is
set.
$all_option If true, All
locations is
the first
choice.
$submit_on_chang
e
If true, the
form is
submitted
on change.

function currencies_list_cells($label, $name, $selected_id)
function currencies_list_row($label, $name, $selected_id)
Action: Prints a currencies listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

33

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

function fiscalyears_list_cells($label, $name, $selected_id)
function fiscalyears_list_row($label, $name, $selected_id)
Action: Prints a fiscal years listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
34

the
POST[name]
value is set.

function dimensions_list_cells($label, $name, $selected_id, $no_option=false, $showname=null,
$showclosed=false, $showtype=0)
function dimensions_list_row($label, $name, $selected_id, $no_option=false, $showname=null,
$showclosed=false, $showtype=0)
Action: Prints a dimensions listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.
$no_option If true, an
All
Dimensions
is the first
choise.
$showname If true, the
dimension
name is
shown.
$showclosed If true, the
closed
dimensions
are shown
35

as well.
$showtype Will only
show the
dimension
type.

function stock_items_list_cells($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
function stock_items_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
Action: Prints a stock items listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name
of the list
box.
$selected_id If
$selected_id
is null and
the
POST[name
] is not set
an empty
value is set,
otherwise
the
POST[name
] value is
set.
$all_option If true, All
stock items
is the first
choice.
$submit_on_chang
e
If true, the
form is
submitted
on change.

36

function stock_bom_items_list_cells($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
function stock_bom_items_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
Action: Prints a stock bom (bill of material) items listbox inside a TD or TR-TD with an
optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name
of the list
box.
$selected_id If
$selected_id
is null and
the
POST[name
] is not set
an empty
value is set,
otherwise
the
POST[name
] value is
set.
$all_option If true, All
stock bom
items is the
first choice.
$submit_on_chang
e
If true, the
form is
submitted
on change.

37

function stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
function stock_manufactured_items_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
Action: Prints a stock manufactured items listbox inside a TD or TR-TD with an optional
label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.
$all_option If true, All
stock
manufacture
d items is
the first
choice.
$submit_on_chang
e
If true, the
form is
submitted
on change.

38

function stock_purchasable_items_list_cells($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
function stock_purchasable_items_list_row($label, $name, $selected_id, $all_option=false,
$submit_on_change=false)
Action: Prints a stock purchasable items listbox inside a TD or TR-TD with an optional label
TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name
of the list
box.
$selected_id If
$selected_id
is null and
the
POST[name
] is not set
an empty
value is set,
otherwise
the
POST[name
] value is
set.
$all_option If true, All
stock
purchasable
items is the
first choice.
$submit_on_chang
e
If true, the
form is
submitted
on change.

function stock_item_types_list_row($label, $name, $selected_id, $enabled=true)
Action: Prints a stock item types listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

39

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.
$enabled If true, the
form is
submitted
on change,
else the
listbox is
disabled.

function stock_units_list_row($label, $name, $selected_id, $enabled=true)
Action: Prints a stock units listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
40

the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.
$enabled If true, the
form is
submitted
on change,
else the
listbox is
disabled.

function stock_categories_list_cells($label, $name, $selected_id)
function stock_categories_list_row($label, $name, $selected_id)
Action: Prints a stock categories listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

41

function tax_type_list_cells($label, $name, $selected_id, $all_option=false,
$all_option_name=null, $submit_on_change=false)
function tax_type_list_row($label, $name, $selected_id, $all_option=false,
$all_option_name=null, $submit_on_change=false)
Action: Prints a tax type listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label is
printed in a
TD.
$name The name of
the list box.
$selected_id If $selected_id
is null and the
POST[name] is
not set an
empty value is
set, otherwise
the
POST[name]
value is set.
$all_option If true, All
stock
purchasable
items is the
first choice.
$all_option_nam
e
If not null, the
$all_option_na
me is printed.
$submit_on_cha
nge
If true, the
form is
submitted on
change.

function tax_groups_list_cells($label, $name, $selected_id, $submit_on_change=false)
function tax_groups_list_row($label, $name, $selected_id, $submit_on_change=false)
Action: Prints a tax type listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

42

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name
of the list
box.
$selected_id If
$selected_id
is null and
the
POST[name
] is not set
an empty
value is set,
otherwise
the
POST[name
] value is
set.
$submit_on_chang
e
If true, the
form is
submitted
on change.

function item_tax_types_list_cells($label, $name, $selected_id)
function item_tax_types_list_row($label, $name, $selected_id)
Action: Prints an item tax types listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
43

is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

function shippers_list_cells($label, $name, $selected_id)
function shippers_list_row($label, $name, $selected_id)
Action: Prints a shippers listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

function sales_persons_list_cells($label, $name, $selected_id)
function sales_persons_list_row($label, $name, $selected_id)
Action: Prints a sales persons listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

44

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

function sales_areas_list_cells($label, $name, $selected_id)
function sales_areas_list_row($label, $name, $selected_id)
Action: Prints a sales areas listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
45

the
POST[name]
value is set.

function workorders_list_cells($label, $name, $selected_id)
function workorders_list_row($label, $name, $selected_id)
Action: Prints a workorders listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

function payment_terms_list_cells($label, $name, $selected_id)
function payment_terms_list_row($label, $name, $selected_id)
Action: Prints a payment terms listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
46

a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

function credit_status_list_cells($label, $name, $selected_id)
function credit_status_list_row($label, $name, $selected_id)
Action: Prints a credit status listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

47

function sales_types_list_cells($label, $name, $selected_id)
function sales_types_list_row($label, $name, $selected_id)
Action: Prints a sales types listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

function movements_types_list_cells($label, $name, $selected_id)
function movement_types_list_row($label, $name, $selected_id)
Action: Prints a movements types listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
48

is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

function bank_trans_types_list_cells($label, $name, $selected_id)
function bank_trans_types_list_row($label, $name, $selected_id)
Action: Prints a bank transaction types listbox inside a TD or TR-TD with an optional label
TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

function workcenter_list_cells($label, $name, $selected_id, $all_option=false)
function workcenter_list_row($label, $name, $selected_id, $all_option=false)
Action: Prints a workcenter listbox inside a TD or TR-TD with an optional label TD.

Return value: None.
49


File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.
$all_option If true, All is
the first
choice.

function bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change=false)
function bank_accounts_list_row($label, $name, $selected_id, $submit_on_change=false)
Action: Prints a bank accounts listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name
of the list
box.
$selected_id If
$selected_id
is null and
50

the
POST[name
] is not set
an empty
value is set,
otherwise
the
POST[name
] value is
set.
$submit_on_chang
e
If true, the
form is
submitted
on change.

function class_list_cells($label, $name, $selected_id, $submit_on_change=false)
function class_list_row($label, $name, $selected_id, $submit_on_change=false)
Action: Prints an account class listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name
of the list
box.
$selected_id If
$selected_id
is null and
the
POST[name
] is not set
an empty
value is set,
otherwise
the
POST[name
] value is
set.
$submit_on_chang
e
If true, the
form is
submitted
51

on change.

function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false,
$show_group=false, $on_change="")
function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false,
$show_group=false, $on_change="")
Action: Prints an account class listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is
not null, a
label is
printed in a
TD.
$name The name
of the list
box.
$selected_id If
$selected_i
d is null
and the
POST[name
] is not set
an empty
value is
set,
otherwise
the
POST[name
] value is
set.
$skip_bank_account
s
If true, the
bank
accounts
are not
shown.
$show_group If true, the
bank
account
groups are
shown.
$on_change If set, the
52

on_change
value is
printed.

function yesno_list_cells($label, $name, $selected_id, $name_yes="", $name_no="",
$submit_on_change=false)
function yesno_list_row($label, $name, $selected_id, $name_yes="", $name_no="",
$submit_on_change=false)
Action: Prints a yesno listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name
of the list
box.
$selected_id If
$selected_id
is null and
the
POST[name
] is not set
an empty
value is set,
otherwise
the
POST[name
] value is
set.
$name_yes If set, the
value is
printed, else
'Yes' is
printed.
$name_no If set, the
value is
printed, else
'No' is
printed.
$submit_on_chang If true, the
53

e form is
submitted
on change.

function languages_list_cells($label, $name, $selected_id)
function languages_list_row($label, $name, $selected_id)
Action: Prints a languages listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.

function number_list_cells($label, $name, $selected_id, $from, $to)
function number_list_row($label, $name, $selected_id, $from, $to)
Action: Prints a numbered listbox inside a TD or TR-TD with an optional label TD.

Return value: None.

File: /includes/ui/ui_lists.inc

Parameters:
$label If this is not
null, a label
is printed in
54

a TD.
$name The name of
the list box.
$selected_id If
$selected_id
is null and
the
POST[name]
is not set an
empty value
is set,
otherwise
the
POST[name]
value is set.
$from From value
(included).
$to To value
(included).


55

Javascript Functions

function get_js_go_back()
Action: Gets Javascript code for a 'Back' link. Popups are closed, normal windows are going
back.

Return value: Javascript code.

File: /includes/ui/ui_view.inc

function get_js_open_window($width, $height)
Action: Gets Javascript code for a centered Popup window.

Return value: Javascript code.

File: /includes/ui/ui_view.inc

Parameters:
$width The
width of
the
Popup
window.
$height The
height
of the
Popup
window.

function get_js_date_picker()
Action: Gets Javascript code for a date picker. If the global variable $use_date_picker is
set, this code is needed.
If the global variable $date_system is set to 0, the Gregorian Calendar is used. A value of 1
will show the Jalali Calendar
and a value of 2 will show the Islamic Calendar.

Return value: Javascript code.

File: /includes/ui/ui_view.inc

function alert($msg)
Action: Prints Javascript code for an alert popup. Can be used as a debugging feature.

Return value: None.

56

File: /includes/ui/ui_view.inc

Parameters:
$msg Shows
the
message
in a
javascript
alert box.


57

Database Functions (low level)

function db_query($sql, $err_msg)
Action: Send an SQL statement to MySql server.

Return value: A result set.

File: /includes/db/connect_db.inc

Parameters:
$sql An SQL
statement,
like
SELECT,
INSERT,
UPDATE,
DELETE.
$err_msg You can
supply an
error
message if
the action
fails.

function db_fetch_row($result)
Action: Fetches the next row array from the result set in db_query.

Return value: A row array that is numeric, i.e. $row[0], $row[1] ans so on.

File: /includes/db/connect_db.inc

Parameters:
$result The result
set
returned
from
db_query.

function db_fetch($result)
Action: Fetches the next row array from the result set in db_query.

Return value: A row array that is field based, i.e. $row['id'], $row['name'] ans so on.

File: /includes/db/connect_db.inc
58


Parameters:
$result The result
set
returned
from
db_query.

function db_num_rows($result)
Action: Fetches the number of rows in the result set in db_query.

Return value: A number of rows in the result set.

File: /includes/db/connect_db.inc

Parameters:
$result The result
set
returned
from
db_query.

function db_num_fields($result)
Action: Fetches the number of fields in the result set in db_query.

Return value: A number of fields in the result set.

File: /includes/db/connect_db.inc

Parameters:
$result The result
set
returned
from
db_query.

function db_insert_id()
Action: Gets the inserted id from the last INSERT INTO statement.

Return value: The inserted id value.

File: /includes/db/connect_db.inc

59

function begin_transaction
Action: Logs the transactions during a critical operation. Use transactions if you need to
keep several INSERT, DELETE or UPDATE
statements tied together

Return value: None.

File: /includes/db/sql_functions.inc

function commit_transaction
Action: Commits the transactions since begin_transaction. Use transactions if you need to
keep several INSERT, DELETE or UPDATE
statements tied together

Return value: None.

File: /includes/db/sql_functions.inc

function cancel_transaction
Action: Cancels (rolls back) the transactions since begin_transaction. Use transactions if
you need to keep several INSERT, DELETE or UPDATE
statements tied together

Return value: None.

File: /includes/db/sql_functions.inc


60

Database Functions (high level)


61

Date functions

function is_date($date_)
Action: Checks if $date_ is a valid date based on the current formatting.

Return value: True if $date_ is a valid date, otherwise false.

File: /includes/date_functions.inc

Parameters:
$date_ The
formatted
date
value to
be
tested.

function today()
Action: Returns a formatted date value based on the current setting.

Return value: Returns a formatted date value based on the current setting.

File: /includes/date_functions.inc

function now()
Action: Returns a formatted time value based on the current setting.

Return value: Returns a formatted time value based on the current setting.

File: /includes/date_functions.inc

function is_date_in_fiscalyear($date, $convert=false)
Action: Checks if $date is inside the current fiscal year.

Return value: True if $date is inside the current fiscal year, otherwise false.

File: /includes/date_functions.inc

Parameters:
$date The
formatted
date
value to
be
62

tested.
$convert You can
test a
non-
formatted
SQL
value
directly if
this value
is true.

function begin_fiscalyear()
Action: Returns the formatted beginning date of the current fiscal year.

Return value: Returns the formatted beginning date of the current fiscal year.

File: /includes/date_functions.inc

function end_fiscalyear()
Action: Returns the formatted ending date of the current fiscal year.

Return value: Returns the formatted ending date of the current fiscal year.

File: /includes/date_functions.inc

function begin_month($date)
Action: Returns the formatted first day of the month based on the $date value.

Return value: Returns the formatted first day of the month based on the $date value.

File: /includes/date_functions.inc

Parameters:
$date The
formatted
date
value.

function end_month($date)
Action: Returns the formatted last day of the month based on the $date value.

Return value: Returns the formatted last day of the month based on the $date value.

File: /includes/date_functions.inc

Parameters:
63

$date The
formatted
date
value.

function add_days($date, $days)
Action: Returns the formatted new date after adding $days. $days can be negative.

Return value: Returns the formatted new date after adding $days. $days can be negative.

File: /includes/date_functions.inc

Parameters:
$date The
formatted
date
value.
$days Number
of days
to add.
$days
can be
negative.

function add_months($date, $months)
Action: Returns the formatted new date after adding $months. $months can be negative.

Return value: Returns the formatted new date after adding $months. $months can be
negative.

File: /includes/date_functions.inc

Parameters:
$date The
formatted
date
value.
$months Number
of
months
to add.
$months
can be
negative.

64

function add_years($date, $years)
Action: Returns the formatted new date after adding $years. $years can be negative.

Return value: Returns the formatted new date after adding $years. $years can be
negative.

File: /includes/date_functions.inc

Parameters:
$date The
formatted
date
value.
$years Number
of years
to add.
$years
can be
negative.

function sql2date($date)
Action: Returns the formatted date from the MySql date value YYYY/MM/DD.

Return value: Returns the formatted date from the MySql date value YYYY/MM/DD.

File: /includes/date_functions.inc

Parameters:
$date The
MySql
date
value.

function date2sql($date)
Action: Returns the MySql date value YYYY/MM/DD from the formatted date.

Return value: Returns the MySql date value YYYY/MM/DD from the formatted date.

File: /includes/date_functions.inc

Parameters:
$date The
formatted
date
value.
65


function date1_greater_date2($date1, $date2)
Action: Returns true if the formatted $date1 value is greater than the formatted $date2
value.

Return value: Returns true if the formatted $date1 value is greater than the formatted
$date2 value.

File: /includes/date_functions.inc

Parameters:
$date1 The first
formatted
date
value.
$date2 The
second
formatted
date
value.


66

Formatting Functions

function number_format2($number, $decimals=0)
Action: Returns the formatted number value, based on the current user settings.

Return value: Returns the formatted number value, based on the current user settings.

File: /includes/current_user.inc

Parameters:
$number The
number to
be
formatted.
$decimals The
number of
decimals.


67

Example Page

<?php

$page_security = 3;
$path_to_root="../..";
include($path_to_root . "/includes/session.inc");

page(_("Sales Persons"));

include($path_to_root . "/includes/ui.inc");

if (isset($_GET['selected_id']))
{
$selected_id = strtoupper($_GET['selected_id']);
}
elseif (isset($_POST['selected_id']))
{
$selected_id = strtoupper($_POST['selected_id']);
}

//---------------------------------------------------------------------------
---------------------

if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
{

//initialise no input errors assumed initially before we test
$input_error = 0;

if (strlen($_POST['salesman_name']) == 0)
{
$input_error = 1;
display_error(_("The sales person name cannot be empty."));
}

if ($input_error != 1)
{
if (isset($selected_id))
{
/*selected_id could also exist if submit had not been clicked
this code would not run in this case cos
submit is false of course see the delete code below*/

$sql = "UPDATE ".TB_PREF."salesman SET salesman_name='" .
$_POST['salesman_name'] . "',
salesman_phone='" . $_POST['salesman_phone'] . "',
salesman_fax='" . $_POST['salesman_fax'] . "',
salesman_email='" . $_POST['salesman_email'] . "'
WHERE salesman_code = '$selected_id'";
}
else
{
/*Selected group is null cos no item selected on first time
round so must be adding a record must be
68

submitting new entries in the new Sales-person form */
$sql = "INSERT INTO ".TB_PREF."salesman (salesman_name,
salesman_phone, salesman_fax, salesman_email)
VALUES ('" . $_POST['salesman_name'] . "', '" .
$_POST['salesman_phone'] . "',
'" . $_POST['salesman_fax'] . "', '" .
$_POST['salesman_email'] . "')";
}

//run the sql from either of the above possibilites
db_query($sql,"The insert or update of the salesperson failed");

meta_forward($_SERVER['PHP_SELF']);
}
}
if (isset($_GET['delete']))
{
//the link to delete a selected record was clicked instead of the
submit button

// PREVENT DELETES IF DEPENDENT RECORDS IN 'debtors_master'

$sql= "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE
salesman='$selected_id'";
$result = db_query($sql,"check failed");
$myrow = db_fetch_row($result);
if ($myrow[0] > 0)
{
display_error("Cannot delete this sales-person because
branches are set up referring to this sales-person - ".
"first alter the branches concerned.");
}
else
{
$sql="DELETE FROM ".TB_PREF."salesman WHERE
salesman_code='$selected_id'";
db_query($sql,"The sales-person could not be deleted");

meta_forward($_SERVER['PHP_SELF']);
}
}

//---------------------------------------------------------------------------
---------------------

$sql = "SELECT * FROM ".TB_PREF."salesman";
$result = db_query($sql,"could not get sales persons");

start_table("$table_style width=40%");
$th = array(_("Name"), _("Phone"), _("Fax"), _("Email"), "", "");
table_header($th);

$k = 0;

while ($myrow = db_fetch($result))
{

69

alt_table_row_color($k);

label_cell($myrow["salesman_name"]);
label_cell($myrow["salesman_phone"]);
label_cell($myrow["salesman_fax"]);
label_cell($myrow["salesman_email"]);
edit_link_cell(SID . "selected_id=" . $myrow["salesman_code"]);
delete_link_cell(SID . "selected_id=" . $myrow["salesman_code"].
"&delete=1");
end_row();

} //END WHILE LIST LOOP

end_table();

//---------------------------------------------------------------------------
---------------------

hyperlink_no_params($_SERVER['PHP_SELF'], _("New Sales Person"));

//---------------------------------------------------------------------------
---------------------

start_form();

if (isset($selected_id))
{
//editing an existing Sales-person
$sql = "SELECT * FROM ".TB_PREF."salesman WHERE
salesman_code='$selected_id'";

$result = db_query($sql,"could not get sales person");
$myrow = db_fetch($result);

$_POST['salesman_name'] = $myrow["salesman_name"];
$_POST['salesman_phone'] = $myrow["salesman_phone"];
$_POST['salesman_fax'] = $myrow["salesman_fax"];
$_POST['salesman_email'] = $myrow["salesman_email"];

hidden('selected_id', $selected_id);
}

start_table("$table_style2 width=40%");

text_row_ex(_("Sales person name:"), 'salesman_name', 30);
text_row_ex(_("Telephone number:"), 'salesman_phone', 20);
text_row_ex(_("Fax number:"), 'salesman_fax', 20);
text_row_ex(_("Email:"), 'salesman_email', 40);

end_table(1);

submit_add_or_update_center(!isset($selected_id));

end_form();

end_page();

70

?>

You might also like