PHP Functions

From nuBuilderPro
Jump to: navigation, search



This function adds a CSS file to the current page for custom styling of elements. A time-stamp is always added so that changes have an immediate effect.

Parameters :

$pFile: The name of the CSS file.


Fetches the column names of the specified table

Parameters :

$table : Name of the table


Fetches the data from the result of a query as an array indexed by both the column name and the column number.

Parameters :

$qry : The PHP Data Object as returned by nuRunQuery($sql).


Fetches a row of a query as an object with property names being the names of the columns of the prepared query object.

Parameters :

$qry : The PHP Data Object as returned by nuRunQuery($sql).


Fetches each row as an array indexed by the column numbers.

Parameters :

$qry : The PHP Data Object as returned by nuRunQuery($sql).


Obtains an array of fields from a query

Parameters :

$o : A PDO (PHP Data Object) generated by using the nuRunQuery function on an SQL statement.

db_is_auto_id($t, $p)

Checks to see if the field $p has the property of auto incrementing in table $t

Parameters :

$t : The table to check

$p : The field within the table to test


Returns the number of rows within the prepared SQL object

Parameters :

$o : A PDO (PHP Data Object)


Sets up the database for use and creates a garbage collect timeout for the session.


This function adds a Javascript file to the current page for execution. A timestamp is always added so that changes have an immediate effect.

Parameters :

$pFile: The name of the Javascript file.


This function adds Javascript to the nuBuilder system. The Javascript is added to a global variable, this will allow the Javascript to be accessed from anywhere within nuBuilder.


$js: A string of Javascript code to be added to the system.

nuBuildHashData($J , $T)

This function builds the hash array which allows the hashed variables to be used.

Parameters :

$J: The array of variables to be hashed.

$T: The value to set #TABLE_ID# to.

nuBuildReport($PDF, $REPORT, $TABLE_ID)

Builds a report from Report Builder specifications by the user

Parameters :

$PDF : The PDF file object

$REPORT : Data from the report builder

$TABLE_ID : ID of the table being used

nuBuildTable($f, $p, $hashData)

Fetches the data that would be on page $p of the Browse Form of the Form with ID $f and places it in a table to be fetched when the Browse Form is loaded.

Parameters :

$f : The form ID

$p : The page number

$hashdata : The current hashdata for the session


Deletes debug logs from nuDebug() which are older than 2 days from the zzzsys_debug


Creates a file in the /tmp directory of the webroot, with the name of the table $c and contains data from $c

Parameters :

$c : Table containing data


This function is run to place a debug message inside of the zzzsys_debug table. It is used to see what is happening during execution time and the message is any string.

Parameters :

$t: The debug message to be saved.


$sql = "SELECT * FROM customer WHERE customer_id = '#customer_id#'";


This will place the SQL query into the zzzsys_debug table for viewing.


Appends $message to $GLOBALS['ERRORS']. This will then be displayed in an alert when returning the request.

If there are any error messages a record will not be updated or deleted.

Parameters :

$message : A descriptive string for the error message to add.

nuDownload($id, $sql = "")

Downloads a file from a blob stored in a table

Parameters :

$id : The primary key of the record in zzzsys_file which stores the file to download.

$sql : The SQL string to use if downloading the file from a different table.


<source lang="php">

$s = "

SELECT zper_file_type AS file_type, zper_file_name AS file_name, zper_file_blob AS file_blob FROM zzz_person WHERE zzz_person_id = '#RECORD_ID#'


nuDownloadFile(, $s); </source>

nuEmail($pPDForPHP, $pEmailTo, $pSubject, $pMessage, $hashData)

Sends an email depending on the parameters If a report code is defined, it sends a PDF as an attachment to the Email If there is a PHP code, file type and email contents is dependent on the PHP code If no PDF or PHP code is defined, Sends a normal email with the message

Parameters :

$PDForPHP : Code of a report or PHP Code, can be empty string to send normal email

$pEmailTo : Target Email address to send to

$pSubject : The subject of the email

$pMessage : The message body of the email

$hashData : Generating the PDF report will require the hash data of the form

nuEmailGetReportFile($request [, $request_url = null])

Returns the PDF generated by nuRunPDF() as a file

Parameters :

$request : The JSON ID as a parameter for nuRunPDF.php

$request_url : The URL link to nuBuilder with the task to do, set to null to create URL using $request

nuEmailValidateAddress($email) Validates a given email address $email.

A valid email address is of the form local@domain where:

  • Length of local is between 1 and 64 inclusive.
  • Length of domain is between 1 and 255 inclusive.
  • Local does not start or end with a period.
  • Local does not have 2 periods consecutively.
  • Domain only contains letters, numbers, hyphens and periods.
  • Domain does not have 2 periods consecutively.
  • Local contains valid characters only unless quoted.
  • Domain was not found by DNS request.

Returns true if the email is valid

Parameters :

$email: An email address


This function returns true if an error has occurred. This is used to ensure that if an error occurs the program is able to stop before committing erroneous data to the database.


Fetches the property of the current form referenced by $field


$field: The field name to fetch the value for.


Creates an array of key-value pairs of all of the data required for the edit form of the record_id in the global variables.


Only run from inside Before Browse so that Columns can be summed and used as with Javascript, here nuBrowseColumnTotal().


Places the form properties of the form with form ID equal to $formID into the currentForm record of the GLOBALS array.


$formID: The ID of the current form.


Returns subform data as JSON string including Primary Key, row order and if being deleted.

It can be used in ..

  • Before Save
  • After Save
  • Before Delete
  • After Delete


$formName: The name of the subform.


<source lang="javascript">

[ { "btn_zite_zzz_product_service_id" : "",

   "codezite_zzz_product_service_id" : "RL30",
   "descriptionzite_zzz_product_service_id" : "30 cm Ruler",
   "nuDelete" : false,
   "nuIndex" : 0,
   "nuPrimaryKey" : "54c8551569c0f91",
   "zite_cost" : "1.00",
   "zite_description" : "30 cm Ruler",
   "zite_tax_percent" : "10.00",
   "zite_units" : "2.00",
   "zite_zzz_product_service_id" : "54c85436d3b9ea5"
 { "btn_zite_zzz_product_service_id" : "",
   "codezite_zzz_product_service_id" : "RL100",
   "descriptionzite_zzz_product_service_id" : "1m Ruler",
   "nuDelete" : false,
   "nuIndex" : 1,
   "nuPrimaryKey" : "54c855157221c8b",
   "zite_cost" : "3.00",
   "zite_description" : "1m Ruler",
   "zite_tax_percent" : "10.00",
   "zite_units" : "2.00",
   "zite_zzz_product_service_id" : "54c8546ac5cbc99"
 { "btn_zite_zzz_product_service_id" : "",
   "codezite_zzz_product_service_id" : "",
   "descriptionzite_zzz_product_service_id" : "",
   "nuDelete" : true,
   "nuIndex" : 2,
   "nuPrimaryKey" : "",
   "zite_cost" : "",
   "zite_description" : "",
   "zite_tax_percent" : "",
   "zite_units" : "",
   "zite_zzz_product_service_id" : ""




Adds a Javascript function nuTranslate to translate from English to the set language.

The nuTranslate function takes in a string which is then checked against the English strings that have been translated and if it has, will return the translated word, if it has not been translated it will return itself.


This function generates a new unique identifier to use as primary keys for tables.

nuLogin($user, $password)

This function is used to login a particular user into nuBuilder and creates a new session for them to use.

Parameters :

$user : The user to login as.

$password : The password for the user.


Updates the position of the object on a form within the database using the movement information.

Parameters :

$moves : A string with movement information for the objects.

$moves is structured like so: "o1->top,o1->left,o1->objectID|o2->top,o2->left,o2->objectID|..."


Creates a new primary key for an entry to the table and returns it.

Parameters :

$t : The table used to create a next number from.

The table structure of $t should be as follows..

<source lang="sql">

CREATE TABLE invoice_number (

 extra_field varchar(25) NOT NULL,
 KEY extra_field (extra_field)



nuPDForPHPParameters($hashdata, [$validate = ])

Encodes all of the data for a print PDF call or run PHP call into a JSON string and places it into the zzzsys_debug table and returns the primary key of that entry.


$data: An array of data obtained from either an edit form or a table row.

$validate : A string used to validate whether the user has access to the report.

The JSON encoded string is built from a key-value pair array, which contains a copy of $hashData and the required PHP or Report record. If the current user does not have access to the PHP Code or the Report then an error message is generated and the function returns with no value.

nuReplaceHashes($str, $arr)

This function goes through $str and replaces any hash variables with their values.

This function also sets the latest_hashdata field of the global variable array to $arr.

Parameters :

$str : The string to process by replacing any hash variables with their values.

$arr : A key-value array which stores the value of each of the hash-variables.


This function is used to load PHP code found under PHP Code

Parameters :

$code  : The code of the 'PHP Code snippet'.



nuRunQuery([$sql = ] [, $variables = array()] [,$isInsert = false])

This function is to be used to access the database. If it is passed a SQL statement it will prepare the statement and then execute it. The results of the query can be fetched using the db_fetch_ family of functions below.

If the SQL statement is not defined or no parameters are passed to the function, then an array containing information about the database such as:

  • The database host
  • The name of the database
  • The username for the database.
  • The password for the user to access the database.

This is in the format of

<source lang="php">

Array (

  [0] =>
  [1] => site_c
  [2] => root
  [3] => root123

) </source>

If the SQL statement contains ? symbols then the variables array must have the values to be used for each ? in the query.

Parameters :

$sql : The SQL code to run.

$variables : An array of values that will replace ?s.

$isInsert : If true, returns the id of the last inserted entry. Else returns the results of the SQL query.


nuRunQuery("SELECT * FROM cars WHERE car_reg = 'AAA111'");


nuRunQuery("SELECT * FROM cars WHERE car_reg = ? ", array('AAA111'));

(when variables are specified PHP takes care of formatting the value into a string)

nuSaveForm($d, $hashData)

Goes through each of the fields on a form and saves them to the appropriate fields in the database.

Parameters :

$d : All of the form data to be saved to the database.

$hashData : Hash data of the current form

nuSendEmail($to, [,$from] [,$fromname] [,$content] [,$subject] [,$filelist])

Sets the required configuration variables for sending emails for an instance of phpmailer. These configuration variables will be set in accordance to the input parameters and the global setup configuration.

After setting all of the configuration the email is sent to $to. If an error has occurred the function returns false, as well as the error message. Else the function will return true and a confirmation message of "Message sent successfully" will be returned.

Parameters :

$to : The email to send to

$from : Adds a from email address for replying

$replytoname : The name of the sender

$content : The email body

$subject : The subject header of the email to send

$filelist : An array of file attachments to send


Updates the session in the global array to reflect the new session id $i, and returns the session properties in an array.


$i: The session ID

nuSet_SESSION($id, $user)

This function sets the session that nuBuilder is in.

Parameters :

$id : The id of the session to set to.

$user : The user for the session.

nuSubformArray($subform [,$all = true])

This function can be run in Before Save, After Save or After Delete. It returns an array of each row's prefix that will be added or updated.

Parameters :

$subform: The name of the subform.

$all: True = Selects all rows in the subform. False = Ignores rows ticked for deletion.

Returns an array of all the prefixes used in this subform.


["phpAccess0000", "phpAccess0001", "phpAccess0002", "phpAccess0003", "phpAccess0004", "phpAccess0005", "phpAccess0006", "phpAccess0007"]

This allows the developer to loop through an entire subform obtaining the Prefix keys.


Sets the global nu_time variable to a given message along with current time-stamp


$message: The message to tag with a time-stamp before store in nu_time global variable.


Converts an upload error code to an error message.


$code: The upload error code that has occurred.

nuV([$pElement = NULL] [, $pValue = NULL])

This function allows the fetching and modification of global variables.

Parameters :

$pElement: The name of the variable to be accessed, if NULL returns all variables.

$pValue : The new value of the variable.

nuValidateRecord($r, $hashData)

Checks the record to see if it is valid.

A valid record is either new or one that is already stored on the database.

Parameters :

$r : An array containing the record contents

$hashData : The current hashdata for nuBuilder session.

nuValidateUser($session, $hashData)

Logs the user's session and checks the access permissions for the user in terms of the current requested task.

Parameters :

$session : Movement information for an object

$hashdata : The current hashdata for nuBuilder session

nuValidField($FIELD, $validFields, $formInfo, $primary_key, $ROW, $mainForm, $parentID)

Checks to see if a field on a form has valid input.

If a field is invalid an error with the appropriate message is returned. If the field is valid an empty array is returned.

Parameters :

$FIELD : The field of a form to validate.

$validFields : An array of validation checks including:

  • no_blanks
  • no_duplicates
  • format

$formInfo : A hashed array that provides information about the form being validated, including table names, primary keys.

$primary_key : The primary key of the database entry being validated.

$ROW : The row of the subform being validated.

$mainForm : True is if the object is on a main form, false if object is on a subform.

$parentID : The primary key of the parent form of the field.

nuSendEmail($to, $from, $fromname, $content, $subject, $filelist, $html = false)

Sends an email using the settings store in Setup->System Setup ->Email Settings

Parameters :

$to : The email address you want the message to go to

$from : The email address you want to appear in the email header

$fromname : The name you want to appear in the email header

$content : The content of the message, if the last parameter $html is set true, then you can include html content

$subject : The email subject you want to appear in the email header

$filelist : If you do not want to send attachments, you must still supply an empty army here, if you do want to send attachments, this array needs in the following format $filename=>$filesource

$html : so the true or false

/* nuSendEmail($to, $from, $fromname, $content, $subject, $filelist, $html = false) */