Source Location: /php/global_functions.php
global_functions.php
Take care to consider where would be the best place for you function, preferably put it in the module. Only include it in here if it is genuinely global.
PHP versions 4 and 5
LICENSE: ARK - The Archaeological Recording Kit. An open-source framework for displaying and working with archaeological data Copyright (C) 2008 L - P : Partnership Ltd. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License 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 GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
global_functions.php
Take care to consider where would be the best place for you function, preferably put it in the module. Only include it in here if it is genuinely global.
PHP versions 4 and 5
LICENSE: ARK - The Archaeological Recording Kit. An open-source framework for displaying and working with archaeological data Copyright (C) 2008 L - P : Partnership Ltd. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License 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 GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
array addAction(
int $actiontype, string $itemkey, string $itemvalue, $actorkey, $actorvalue, string $cre_by, string $cre_on, string $actor_itemkey, string $actor_itemvalue)
[line 475]
adds actions to cor_tbl_action
[ Top ]
array addAttr(
string $attribute, string $itemkey, string $itemvalue, string $cre_by, string $cre_on, [boolean $bv = FALSE])
[line 583]
gives add functionality for attributes
0.6
NOTE: since 0.6 this has taken add functionality from edtAttr()
NOTE: this adds to the cor_tbl_attribute. It does not add to the look up table of attributes.
[ Top ]
array addDate(
string $datetype, string $itemkey, string $itemvalue, string $date, string $cre_by, string $cre_on)
[line 714]
adds dates
[ Top ]
array addFile(
string $itemkey, string $itemvalue, int $file, string $cre_by, string $cre_on)
[line 1473]
makes insert queries for the dataclass file
[ Top ]
array addFiles(
array $files, $itemvalue, string $orig_dir, string $target_dir, string $itemval)
[line 5171]
DEPRECATED SHOULD USE addFile() INSTEAD moves a file or files from the current location and renames as appropriate
[ Top ]
array addItemKey(
$itemkey, $itemvalue, string $cre_by, string $cre_on, [string $modtype = FALSE], string $mod_short, string $mod_cd_val, string $mod_no_val, string $ste_cd)
[line 332]
inserts the database entry for an itemkey in all modules
[ Top ]
array addMarkup(
string $nname, string $markup, string $lang, string $description, string $cre_by, string $cre_on, [ $dry_run = FALSE])
[line 817]
adds markup
[ Top ]
void addNumber(
string $numtype, string $itemkey, string $itemvalue, string $num, string $cre_by, string $cre_on)
[line 931]
adds a number
[ Top ]
array addSpan(
string $spantype, string $itemkey, string $itemvalue, string $beg, string $end, string $cre_by, string $cre_on)
[line 1034]
adds a span to cor_tbl_span
[ Top ]
array addSpanAttr(
int $span_id, int $spanlabel, string $cre_by, string $cre_on)
[line 1140]
adds a label for a span
0.3
took over add functionality from edtSpanAttr()
bear in mind that this means of attributing frags is now deprecated the correct method is to use chains. However this lives on in the matrix this function could be modified to act as a means to easily chain stuff
[ Top ]
array addTxt(
string $txttype, string $itemkey, string $itemvalue, string $txt, string $lang, string $cre_by, string $cre_on)
[line 1214]
makes insert queries for the dataclass txt
[ Top ]
array addXmi(
string $itemkey, string $itemvalue, string $xmi_itemkey, string $list, string $ste_cd, string $cre_by, string $cre_on)
[line 1344]
loops over a list of item numbers
0.3
Note: The $ste_cd should only be sent if you are sending mod_no's (that is the number without a site code appended). If you are sending fully resolved itemvalues be sure to set this FALSE
Note 2: This has now been updated since version 0.6 to allow for a mixture of numbers and fully resolved itemvalues. It will only append the site code if the value is numeric
[ Top ]
void arraySetCurrent(
&$array, string $key, array $array)
[line 5086]
sets the pointer of an array to the given key
[ Top ]
void array_diff_key(
)
[line 5508]
[ Top ]
browser browserDetect(
)
[line 5261]
works out which browser a user is using
0.6
Note: This used to be used as an include script from v0.1 to 0.6, the code may not yet be fully working. Also as a dev note, this code ought to be improved to help detect version numbers as the principle browser problem is MSIE-6
[ Top ]
void chkCxtSpanlabel(
$ste_cd, $beg, $end, $spanlabelid, $conf_tvclab)
[line 2506]
[ Top ]
boolean chkModType(
string $mod)
[line 2396]
checks if a module is using types
[ Top ]
void chkTranslation(
string $dataclass, int $frag_id)
[line 2363]
checks if a piece of markup or an alias has translations
[ Top ]
boolean compareSpans(
array $span1, array $span2, [boolean $reverse = FALSE])
[line 5414]
compares two numeric spans to see if they coincide
[ Top ]
void createthumb(
string $name, string $filename, string $new_w, string $new_h)
[line 2886]
creates thumbnails for images
[ Top ]
string dateNow(
string $date)
[line 5391]
sets blank dates to NOW()
[ Top ]
string dateSelect(
string $type, string $fields, string $datetype, [string $date = FALSE])
[line 4956]
makes up a date select element for forms
0.2
Current fields: dd - day expressed as two digits mm - month expressed as two digits yr - year expressed as 4 digits
Current types: text - gives the fields as plain text input fields
[ Top ]
void dbConnect(
$sql_server, $sql_user, $sql_pwd, $ark_db)
[line 5326]
connects to a MySQL db
0.6
Note: this db connect function was an inc script from v0.1 to 0.6, it would be worth putting something a little bit tidier in here.
[ Top ]
void ddActor(
$dd_name, $actor_mod, $elem, $elemclass, $top_id, $top_val, [ $actor_group = FALSE])
[line 1960]
returns a drop down menu of actors
0.6
this function presupposes that you are using a module to contain your actor data
[ Top ]
void ddAlias(
int $top_id, mixed $top_val, string $lut, string $lang, string $dd_name, string $order, string $return_mode, [string $id_col = 'id'])
[line 2169]
provides a dropdown menu with language independant aliases. Creates a dd menu with an 'id | alias' type setup
[ Top ]
void ddAttr(
$top_id, $top_val, $lang, $attributetype, $return_mode)
[line 2277]
[ Top ]
string ddSimple(
string $top_id, string $top_val, string $lut, string $nickname, string $dd_name, string $order, [string $return_mode = FALSE], [string $id_col = FALSE])
[line 2028]
makes a simple dropdown menu from the db
0.1
NOTE: makes a simple dd menu with an 'id | nickname' type of set up
NOTE: do NOT use print mode anymore. this method is deprecated and will soon be abolished
[ Top ]
string ddUnique(
string $top_id, string $top_val, string $lut, string $nickname, string $dd_name, string $order, [string $id_col = FALSE])
[line 2108]
makes a dropdown of unique items menu from the db
0.1
NOTE: makes a simple dd menu with an 'id | nickname' type of set up
[ Top ]
array delFrag(
string $class, int $frag_id, $cre_by, $cre_on)
[line 1713]
deletes fragments from the main class tables
delete functionality removes the row from the main table and logs this. in theory this permits rollbacks and revision history
[ Top ]
array dirList(
string $directory, [string $extension = FALSE])
[line 2845]
reads out the contents of a directory into an array
[ Top ]
void dynLink(
string $dir, string $name, string $value)
[line 1838]
makes up those nice chevron links to move up and down records
0.2
FIXME: this function needs to be altered to return an xhtml string rather than printing direct
[ Top ]
array edtAction(
int $action_id, $actorkey, $actorvalue, string $cre_by, string $cre_on, string $actor_itemkey, string $actor_itemvalue)
[line 525]
edits actions
0.3
since 0.6 this has lost it's add/del functionality
[ Top ]
array edtAttr(
string $attribute, boolean $bv, string $frag_id, string $cre_by, string $cre_on)
[line 658]
edits an attribute
this functionality is largely of use when using the boolean properties of attributes. as with all the edt and del functions this may only act on a specific frag id which is required. This edit functionality refers to the cor_tbl_attribute not to the lookup which is edited elsewhere
0.1
NOTE: that since 0.6 this function has lost add and del functionality
[ Top ]
array edtDate(
string $date, string $date_id, string $cre_by, string $cre_on)
[line 765]
edits dates
0.2
NOTE 1: Only specific frags may be edited - identified by row id
NOTE 2: Since v0.6 this function has lost add and del functionality
[ Top ]
array edtFile(
string $itemkey, string $itemvalue, string $files, string $cre_by, string $cre_on)
[line 1532]
edits one or many files
0.6
items in the list are checked against a result from the database. if items match exactly they are skipped. If they are not present in the db an add query is requested. If items are present in the db but not in the list a delete query is requested.
[ Top ]
array edtItemKey(
$itemkey, $itemvalue, string $cre_by, string $cre_on, [string $modtype = FALSE], string $mod_short, string $mod_cd_val, string $mod_no_val, string $ste_cd)
[line 403]
updates the database entry for an itemkey in all modules
0.5
FIXME: Currently this is set to simply ignore edits to the cre_on this is to avoid some disturbing behavior in the matrix.
[ Top ]
array edtMarkup(
string $id, string $nname, string $markup, string $lang, string $description, string $cre_by, string $cre_on, [ $dry_run = FALSE])
[line 875]
edits markup
0.6
NOTE 1: Only specific frags may be edited - identified by row id
NOTE 2: Since v0.6 this function has lost add and del functionality
[ Top ]
array edtNumber(
string $num_id, string $num, string $cre_by, string $cre_on)
[line 983]
edits a number
0.3
NOTE 1: Only specific frags may be edited - identified by row id
NOTE 2: Since v0.6 this function has lost add and del functionality
[ Top ]
array edtSpan(
string $span_id, string $beg, string $end, string $cre_by, string $cre_on)
[line 1088]
edits a span in cor_tbl_span
0.3
NOTE 1: Only specific frags may be edited - identified by row id
NOTE 2: Since v0.6 this function has lost add and del functionality
FIXME: edtSpan is incomplete must be fixed
[ Top ]
void edtSpanAttr(
$span_id, $spanlabel, $cre_by, $cre_on)
[line 1188]
in theory this would edit a span attribute (unlikey)
0.3
lost add functionality and never had edt functionality anyway consider removing
[ Top ]
array edtTxt(
string $txt_id, string $txt, string $lang, string $cre_by, string $cre_on)
[line 1276]
makes update queries for the dataclass txt
0.1
NOTE 1: Only specific frags may be edited - identified by row id
NOTE 2: It is anticipated that you will supply the $conf_log_XXX variable to the $log value However this does provide the option to override the conf setting in the process script Do this by specifying on/off rather than simply sending the conf
NOTE 3: Since v0.6 this function has lost add and del functionality
[ Top ]
array edtXmi(
string $itemkey, string $itemvalue, string $xmi_itemkey, string $list, string $ste_cd, string $cre_by, string $cre_on)
[line 1418]
edits one or many XMI links
0.6
items in the list are checked against a result from the database. if items match exactly they are skipped. If they are not present in the db an add query is requested. If items are present in the db but not in the list a delete query is requested.
Note: notes in addXmi also apply here
[ Top ]
void feedBk(
string $type)
[line 132]
output feedback to the user
0.3
DEV NOTE: The code from the two include files now ought to be formally brought in as a function. The calls should be cleaned up to pass the array to this func which should then unset the arrays. In the meantime, this function is basically just a placeholder for an idea
[ Top ]
string frmElem(
array $field, string $itemkey, [ $itemvalue = FALSE], [array $defaults = FALSE], string $value)
[line 4427]
returns a form element appropriate for a given field
this function does NOT go to the DB, send current values TO this func inside the field. Consider using resFdCurr() to pull the values
In order to return relevant form element this needs to handle various options: 1- The form is blank 2- The form is an edit and therefore needs filling with the current details
If a field already has data, this needs to be processed by the subform and passed into the field array as 'current'
In the case of keys and modtypes the decision about the form elem to return is currently based on the presence/absence of the key/val pair
For other dataclasses the decision must be based on other factors at the top of each class
In the case of attributes, there is usually just a single drop down to handle 1- There is a menu to add attrs to the record 2- There is a menu to add attrs but we want to specify a default Bear in mind that a subform will have to be able to list out existing attrs and offer delete functionality. In addition, we will need to be able to offer functionality to add new attributes of a given type
This only returns the form element not a wrapper so it could be used to return form elements into other types of forms This presupposes that the rest of the form is being correctly setup
[ Top ]
array getLinkedFiles(
string $itemkey, string $itemval, string $dir, $processed)
[line 5227]
checks to see if we have any files linked to this itemvalue
[ Top ]
void getLogVars(
$ref, $refid, $type)
[line 1775]
[ Top ]
string getSfState(
string $column, string $view_state, string $edit_state)
[line 5049]
gets the state of subform
used to put together the 'state' of a subform. This state variable can then be used to inform a subform how it should render output (e.g. if the return state is "p_max_edit" then the subform would know that it has to render the output as if the the form was in a primary column, maximised and being edited)
for further info on the different return states see the wiki
[ Top ]
string getStylesheet(
string $browser)
[line 5293]
chooses the correct stylesheet dependent on the detected browser
0.6
Note: This used to be used as an include script from v0.1 to 0.6.
[ Top ]
string getWebHost(
)
[line 5486]
returns the fully resolved web host (including port)
[ Top ]
boolean in_array_multi(
string $needle, array $haystack)
[line 5111]
checks for a var in a multidim array
[ Top ]
void isItemkey(
string $key)
[line 291]
runs a quick and dirty check on a string to see if it is in the format xxx_cd. Returns TRUE if it matches the pattern and FALSE if not
[ Top ]
array itemValNatSort(
array $a, array $b)
[line 3910]
sorts itemvals into natural order
0.5
NOTE: This function is used by the uasort() function which acts as a wrapper
[ Top ]
array loadFiles(
string $dir)
[line 5135]
lists files in a directory and returns the information as an array
[ Top ]
void logCmplxEvent(
$event, $ref, $refid, $vars, $cre_by, $cre_on)
[line 1861]
[ Top ]
void logEvent(
$event, $vars, $cre_by, $cre_on)
[line 1891]
[ Top ]
void makeUsername(
$firstname, $lastname, $init, $type)
[line 2544]
[ Top ]
string mkChat(
array $snip_array)
[line 2932]
makes up the chat style output for searches
[ Top ]
$var mkLeftPanelLink(
array $left_panel)
[line 3860]
takes the left panel array from the settings file and creates a link
[ Top ]
string mkNavItem(
string $mode, string $button, string $item_key, string $default, [string $link = FALSE])
[line 3305]
makes an itemvalue jumper
0.6
NOTE: This has been available as a script (inc_itemkey_nav.php) since at least version 0.2. The original script was intended to do more that just present a navigation tool, it was supposed to handle the request of the itemvalue and also set up errors if this was missing. For this reason, calls to this function may need to be wrapped correctly in order to not break expected behaviour further down the parse order.
[ Top ]
string mkNavLang(
[string $qstr = FALSE])
[line 3219]
makes up a navigation list for languages
0.6
NOTE: This has been available as a script (inc_itemkey_nav.php) since at least version 0.2.
[ Top ]
string mkNavMain(
array $pages, [array $links = FALSE], [ $hide = FALSE])
[line 3160]
makes up ARK main navigation bar
0.6
NOTE 1: this function existed in script form as inc_main_nav.php since 0.1
NOTE 2: this function makes up the nav bar from two arrays. The first is an array of pages that are authorised for this viewer. The second is a array of links configured by the admin and held in the settings file
NOTE 3: the info arrays will be outputted in the order pages -> links. The arrays should be in the format array('file' => X, 'vars' => X, 'label' => X)
NOTE 4: the pages array is generally created by inc_auth
FIX ME: this needs a better means of selecting the active page
[ Top ]
void mkNavPage(
string $page, string $total, string $url)
[line 2634]
makes out a navigation tool for the paged results
0.3
NOTE: Since 0.6 this function is renamed mkNavPage() from printPagingNav(). It also now returns a resolved XHTML string and does not print to screen
[ Top ]
void mkNavRows(
$perpage, $label, $go)
[line 2667]
makes a navigation box to select the number of rows per page in paged result sets
0.6
This has been available as a script (inc_pagination_nav.php) from 0.3 to 0.6
[ Top ]
string mkResMeta(
array $item_meta)
[line 3002]
makes up the item meta for chat style output for searches
[ Top ]
$var mkSearchBox(
)
[line 3757]
makes the freetext search box for any page in ark
v0.6
Note that this existed as the script inc_search_box.php since v0.4 use of the inc is now deprecated
[ Top ]
void mkSearchSimple(
$prefix, $link_vars, [ $mod = FALSE], [ $meta_display = FALSE], string $msrc)
[line 3597]
makes a simple search window
NOTE: This is largely a wrapper and display function
NOTE: This is ideally suited to use in subforms
[ Top ]
string mkSearchType(
$modes, $name, string $item_key, string $default, $width, [string $link = FALSE], string $mode, string $button)
[line 3379]
makes an searchbox
[ Top ]
$var mkSteCdNav(
)
[line 3797]
makes the site code navigator for use in forms
v0.6
Note that this existed as the script inc_ste_cd_nav.php since v0.4 use of the inc is now deprecated
[ Top ]
string mkTitle(
string $itemkey, string $itemval, array $title_vars)
[line 3033]
makes up titles or citations from various elements
[ Top ]
void mkTl(
array $ranges, int $tl_width)
[line 3442]
makes an xhtml timeline out of a getSpan() result
[ Top ]
string modBr(
string $key, string $val, array $conf_br)
[line 2454]
returns a resolved xhtml string wrapping an item
0.6
NOTE 1: This existed as a context specific function until 0.6
NOTE 2: The array of wrap tags needs to be set up as follows: Set this up in mod_MOD_settings. This example sets rounded brackets for modtype 1 and square brackets for modtype 2 $conf_br = array( 'type_1_L' => '(', 'type_1_R' => ')', 'type_2_L' => '[', 'type_2_R' => ']', 'type_3_L' => '', 'type_3_R' => '*' );
[ Top ]
void outpList(
string $list_type, string $list_id, string $list_class, string $item_class, array $values, string $return_mode)
[line 1927]
returns an xhtml list from a php array
0.4
FIXME: Remove the output mode and simply return a string
[ Top ]
array pageResults(
array $search_results, array $page, array $limit)
[line 2578]
pages a results array for display
[ Top ]
void printError(
array $error)
[line 5370]
prints out the human readable error element ('vars')
0.6
Note: this error print function was an inc script from v0.1 to 0.6
[ Top ]
void printPre(
array $array)
[line 3888]
runs print_r within
[ Top ]
int processFiles(
string $dir, string $batch, string $module, string $cre_by, string $cre_on, [array $size = array('arkthumb_width' => 150, 'arkthumb_height' => 150,'webthumb_width' => 500,'webthumb_height' => 500)], [string $orig_file_dir = FALSE])
[line 1586]
processes a set of files (thumbnailing, registering and renaming)
[ Top ]
array registerFile(
array $file, string $batch, string $module, string $cre_by, string $cre_on)
[line 1664]
registers a file
[ Top ]
void reqArkVar(
string $var, [string $default = FALSE])
[line 93]
handles a setup procedure for vars which is common in ARK. This
checks for the var in the querystring, then in the session then for a default. The var if set is saved into the session. Returns FALSE if the var cant be set
[ Top ]
void reqQst(
array $array, string $var)
[line 60]
cleanly requests a var from an array and returns false if relevant
typically this is used to request from the querystring or session. Using this function will avoid unwanted e_notices for unset variables as it returns FALSE to your var thereby setting it
[ Top ]
array resFdCurr(
array $field, string $itemkey, string $itemvalue)
[line 4258]
returns the current contents of a field in an array with the frag id
0.6
DEV NOTE: this function can be used as an alternative to resTblTd but bear in mind that it returns the data unmarked up and in an array
[ Top ]
string resTblTd(
array $field, string $itemkey, string $itemvalue)
[line 4052]
returns the contents of a field in display mode
0.5
DEV NOTE: this function needs to be renamed as it can handle any fields not just table fields. This was developed to do table cell contents
[ Top ]
array resTblTh(
array $fields, [string $mode = FALSE])
[line 3976]
makes up form and table headers
makes up headers for forms and tables. Creates aliases for the fields/columns and returns this information into the fields array. By default the function. prints a table header row containing the headers. If mode is set to silent the function simply processes and returns the aliased fields array
[ Top ]
$sf_nav sfNav(
string $sf_title, string $col_no, string $sf_id, array $disp_cols)
[line 2694]
returns a navigation bar for a subform
[ Top ]
array sortResArr(
array $results_array, [string $type = FALSE], [ $col = FALSE])
[line 3932]
sorts multidim arrays on a given column (eg the results array by score)
0.4
NOTE: the types of sort are: default(FALSE), ITEMVAL and SORT_ASC
[ Top ]
string splitDate(
string $rawdate, string $datestyle)
[line 219]
splits a date
[ Top ]
string splitItemkey(
string $itemkey)
[line 190]
splitItemkey() splits an itemkey and returns only the three letter mod code
[ Top ]
string splitItemval(
string $itemval, [string $ste_cd = FALSE])
[line 157]
splitItemval() splits an itemval and returns only the number. If TRUE is supplied to the $ste_cd param it will return the site code instead of the number
[ Top ]
array thumbnailFiles(
array $files, $file_dir, string $thumb_dir, string $webthumb_dir, [int $thumb_width = 120], [int $thumb_height = 80], [int $webthumb_width = 400], [int $webthumb_height = 300])
[line 5201]
thumbnails a file or files
[ Top ]