Document toolboxDocument toolbox

PHP Helper functions

Here you can find the various helper functions in Microbizz.

Please note, this page only contains the methods that has some documentation.

UI elements

abut(id,text,link,extra)

Convenience fn for generating an <a> button-like thing for buttonlane

params

  • string $id - ID (and name) for the element

  • string $text - Text to display

  • string $link - Optional link

  • string $extra - Additional junk to include in the <a>

example

abut("linkid", "This is a link", "https://google.dk", "junk");

Will result in:

<a id='linkid' name='linkid' junk href="https://google.dk">This is a link</a>

box(type,class,id,modcode)

Render the start of a box. Use boxend() to end the box.

params

  • type - Type of box, 1-9 include a shadow

  • class - Additional classes to add to the box

  • id - An id to assign to the box

  • modcode - An modcode, if specified then the box will have an icon

Example

box(1, 'aclass', 'theidofthebox', 'todo');
// Content
boxend();

buttonlane(buttons,opts)

Renders a buttonlane, uses LayoutButtons::lane().

params

  • buttons - List of buttons

  • opts - Various options

popupinfo(title,rows)

Generates a table for displaying object info in a tooltip/popup/etc

params

  • string $title

  • array $rows


bar($width, $height, $data)

Renders a bar visually representing the rate between several values. The entire width of the bar, represents the sum of all values in $data, and each individual value is then shown with their width respective to the total width. The following code:

1 bar(300, 15, array('red' => 20, 'yellow' => 10, 'green' => 10));

would render a bar, where the red area is 150 pixels wide, and both the yellow and green are each 75 pixels wide.

$width

Pixel width of the bar

$height

Pixel height of the bar

$data

Array of data values, hashed by their color representation.

head(...)

Render a page head. Remember to finish page with pageend()

Options

  • nosave - don't remember the location of this page

  • customheader - anything to place inbetween the <head></head>-tags

  • naked - Don't render any page elements

  • mapload - If set to 'leaflet' then load the leaflet map library. If set to true, then load the Cloudmade map library.

  • forcemod - Force header to behave as in given module

  • modal - Indicates that this page is modal, meaning that it can return to the last called non-modal page when finished

  • notracking - Prohibits tracking in all cases

  • bypassssl - Bypass SSL for this specific page

  • punymce - Load the puny_mce editor

  • googletracker - Microbizz uses Google analytics for web page statistics. If this option is given, a tracking code is included, to exclude people who continues directly to the Microbizz login from these statistics.

Example

$title = "Page title";
$script = array("file.js", "file2.js");
$css = array("file.css", "file2.css");
head($title, $script = false, $css = false, $options = array())

searchbut(id,formname,abort,options)

Create a search button that will submit a form when clicked; the button will have the title "Search" unless otherwise specified in the options; the button triggers the "mbstartsearch" javascript event when clicked.

params

  • string $id - The ID of the button, must be unique
  • string $formname - The name of the form to submit
  • string $abort - True if the button should support the 'abort search' functionality
  • array $options - Various options [ title ]

abort search functionality

The 'abort search' functionality works with forms whose result is displayed in Tabulator; it requires that the form has been informed about the ID of the search button, using eg. $form→setSearchButton('#searchbuttonid').

When the button is clicked and the form is submitted, the button text will change to "Abort". When the search ends, the button text changes back. Clicking on the button whilst it displays "Abort" will cause a message to be sent to MB to inform the table  provider script to abort the search. The table provider script should call Uuid::clear() when it starts and when it ends, and should also call session_write_close(), and it should regularly call Uuid::hasClosed() to check if the search should be aborted.

The search is aborted by calling the script obj/Uuid/php/clsoedpage.php. The same script is also called when the page is closed.

submitlink(txt,formname,objective)

Convenience for generating a link for form submission

params

  • string $txt - Text on button

  • string $formname - Form to submit

  • string $objective - Set form objective to this before submit

example

submitlink("A link", "testform", "save");

Will result in:

<a href="#" class="formsubmitbutton formobjectivesave formreftestform">A link</a>

resetbut(id,formname,options)

Create a "Reset" button that will clear a form when clicked. The button triggers the "mbformreset" javascript event on the form.

params

  • string $id - The ID of the button, must be unique
  • string $formname - The name of the form to clear
  • array $options - Various options: title - the text in the button, defaults - an array with the default values for some of the fields in the form

savebut(id,formname,options)

Create a "Save" button that will submit a form when clicked.

params

  • string $id - The ID of the button, must be unique
  • string $formname - The name of the form to submit
  • array $options - Various options [ title, objective ]

mhead(...)

Render a page head for mobile version. Remember to finish page with pageend()

Options

  • see head

Example

$title = "Page title";
$script = array("file.js", "file2.js");
$css = array("file.css", "file2.css");
mhead($title, $script = false, $css = false, $options = array())

getTextColor(colr)

Get a fitting text color for a given background color

params

  • string $color - Hex color code, #RRGGBB

tripletable(col1,col2,col3,totalwidth,withids)

Render data nicely in three columns, uses the class LayoutTriple.

params

  • array<string> $col1 - Data in column 1 hashed by header titles

  • array<string> $col2 - Data in column 2 hashed by header titles

  • array<string> $col3 - Data in column 3 hashed by header titles

  • int $totalwidth - The total width of the construction

  • string $withids - If set then each element will be given an ID based on the first part of a title (up to first '|')

tabs(tabid,panels,ext,defaulttab,neverdefault)

Initialise the tabs. This is a wrapper for LayoutTab, see the code for details about parameters.

params

  • string $tabid - A unique ID across the system for this tabset

  • array $panels - List of tabs to display

  • string $ext

  • string $defaultab

  • array $neverdefault

pageend()

Renders a page end.

popup(id,points,selectable)

Renders a popupmenu

params

  • string $id - DOM id of popupmenu

  • array<string> $points - Items in the menu, hashed by their DOM ids.

  • bool $selectable - If the menu items should be selectable

Other

getOS()

This method, can tell you which browser/OS the UA string is.

params

  • String $string - The string to get the UA from

Common example:

$os = getOS($_SERVER['HTTP_USER_AGENT']);

includescripts(scripts)

This method lets you include an array of javascript files.

Example

$scripts = array(
    "file.js",
    "file2.js"
);
 
includescripts($scripts);

includeccs(files)

This method lets you include an array of javascript files.

Example

$files= array(
    "file.css",
    "file2.css"
);
 
includeccs($files);

postScript(file)

Include a javascript or CSS file after head() has been called.

This generates a <div> containing the name of the file; the <div> is detected and handled by javascript.

js_arg(name, value)

Indicate that a value should be transferred to javascript. When pageend() or tpend() or tabend() is called, all the stored values are output in a <div>; javascript checks for this <div> and loads the values into the javascript object named mbargs.

js_args(namevalues)

Like js_arg() but the argument is an array of values hashed by their names.

millisecs()

Get a string with current time incl. milliseconds, for timing

now()

Convenience-function for the time right now

objective(test)

Test if the current objective, is as given.

params

  • String $test Objective to test against


rnow()

Convenience-function for the time right now

rtoday()

Convenience-function for todays unadjusted date


today()

Convenience-function for todays adjusted day

valalt(val,alt)

Returns $val, or $alt if $val is not set.

params

  • Mixed $val

  • Mixed $alt


exchange(a,b)

Exchange the content of two variables in place

params

  • mixed $a - Variable 1

  • mixed $b - Variable 2


ensure_int_array(arr)

Return a copy of the passed array where everything but valid integer values are removed

params

  • array $arr - Any array

returnfrommodal()

Use the modal function to return to the last non-modal page

ajax_loader(delay)

Render ajax loader

params

  • integer $delay

distance(lat1,lon1,lat2,lon2)

Return the distance between two coordinates in meters

params

  • double $lat1

  • double $lon1

  • double $lat2

  • double $lon2

$currency = showcurrency()

See Intl class

Returns the currency code used in this contract.

Conversion

clock2min(clock)

Convert hours on the form HH::MM to minutes

params

  • string $clock Hours

$nicepercent = number2percent($number)

80,12 % = number2percent(0.8012);

min2clock(time)

Convert minutes to hours on the form HH:MM

params

  • int $time - Minutes

min2hour(time,display)

Convert minutes into hours as a decimal count, eg. 2h30 becomes “2.5”, uses '.' as decimal point unless $display is set

params

  • int $time Minutes

  • bool $display True to return a format for display or Excel, ie. with language dependant decimal point

min2string

Convert minutes to a readable duration like “5 hours and 23 minutes”

params

  • int $time Minutes

nicepercent(number)

Show a decimal number as a nice percent, using ',' as decimal point

params

  • double $number

showamount(val)

See Intl class

Show an amount, with language dependant decimal point, see Intl::formatCurrency() for details.

params

  • int $val - Amount in ører

parseamount(v)

See Intl class

Convert a formatted value to a number; handles thousand separators, language etc. See Intl::unformatCurrency() for details.

params

  • string $v - Value returned from showamount() or similar

decformat(v,numdecs)

Format a value according to language

params

  • Float $v

  • Int $numdecs

mnf(val)

See Intl class

Format a number as 100.000.000

params

  • float $val

mnfdec(val)

See Intl class

Format a number as 100.000.000,00

params

  • float $val

mnfdec0(val)

See Intl class

Format a number using mnf() for ints and mnfdec() for floats

params

  • float $val

number2percent(number)

Displays a fraction as a percentage. 0.08 = 8 %

params

  • double $number

Text

$finaltext = valalt($text, $alternative = “”)

Returns $text unless $text evaluates to false, then return $alternative. If $alternative isn't provided a default text “not set” is returned.

$newtext = htmlent($text)

Convenience for htmlentities($text,ENT_COMPAT,'UTF-8') and must always be used.

htmlent(str)

A wrapper of htmlentities producing UTF-8 characters.

params

  • String $str - String to encode.

ensure_safe_string_array(arr)

Return a copy of the passed array where all values have been encoded for safe sql-usage and furthermore is wrapped in quotes

params

  • array $arr - Any array

striptags(txt)

Strip tags but leave comments; for use with eg. “<!– 2015-05-15 –><span>15-05-2015</span>”

params

  • string $txt

mnl2br(text)

Replaces newline to <br> in a text which can already contain html, preventing a <br> followed by a newline (or vice versa) from turning into a double line break

params

  • string $text - Input

arraytotext(elements,ashtml)

Turn a array into a nice text where each element in the array is a line, if and only if, the line is not empty.

params

  • array $elements - The elements to create the text from

  • boolean $ashtml - If true, return the text as html with <br> line breaks

warning($text)

Outputs $text in a system warning context.

remove_emoji(text)

Remove emoji chars from UTF-8

params

  • String $text

error($text)

Output $text in a system error context.

simplestring(str)

Simplifies a string

params

  • String $str

text2html(text)

Converts a plain text to HTML, by replacing newlines with breaks, making links clickable and so on

params

  • String $txt