 |
 |
 |
 |

VConsole Built In PHP Functions
Introduction To PHP Functions.
The core of VConsole is built on a series of powerful PHP functions that allow you to do all sorts of things. Unlike the javascript functions, the PHP functions are designed for you to actually use them in your
module, function, and action files. In addition, you can even create your own PHP libraries that can be included in VConsole. (See Building PHP Libraries for more information.)
PHP Function Code Hints And Color Coding.
If you are using Dreamweaver® to code your PHP module and action files, and you have the VConsole Developer Tools Extension installed, you may notice that you will get code hints when calling these functions. The great thing about this is that you can see at a glance what arguments are required and what they should be. You can also recognize a VConsole function easily because all VConsole built in functions are color coded purple. Also, you get lots of great features with the toolkit that allow you to quickly create your VConsole application like dialog boxes for creating datamanager fields or field filters and lots more. Check out the "Developing With Dreamweaver" section for more details.
Built In PHP Functions.
All the functions listed below show the function name along with a brief description of what the function does, what the arguments should be, what is returned, and any other valuable information. When specifying each function, we also provide a list of arguments along with data types. Any argument that is encapsulated in square brackets is optional. Here is a list of all the data types and what they mean:
- string - The parameter is expected to be a string.
- int - The parameter is expected to be an integer or whole number.
- bool - The parameter is expected to be true or false. You can pass any value, but the only thing that matters is if it evaluates to true or false.
- varref - The parameter is expected to be a variable. This variable may be populated, overwritten, or modified by the function and can be read and used once the function returns.
- array - The parameter is expected to be an array. What the array should contain or the structure of the array depends on the function.
- float - The parameter is expected to be a floating point number. Basically any number with or without a decimal point.
- choice - The parameter is expected to be 1 of a predefined set of choices. The valid choices are shown in the code hint.
- arrayref - The parameter is expected to be an array. This array may be populated, overwritten, or modified by the function and can be read and used once the function returns.
- regex - The parameter is expected to be a regular expression that can be passed to preg_match() as the first parameter.
- mixed - The parameter is expected to be any type of data that is understood by the print_r() php function. It can be a variable, an array, a multi-dimensional array, or an object.
- void - No parameters are expected
Record IDs - Many of the functions in this section refer to record ids (or record id). A record id is the value of the primary key field in the MySQL table for the record in question. The MySQL primary key field does not have to be named "id"
- build_pageselector(int $current_page, int $total_pages)
- check_browser_compat(void)
- check_email(string $email, varref &$error[, bool $dnscheck=true])
- check_email_domain(string $email, varref &$error[, bool $dnscheck=true])
- check_action_permission([string $module=false][, string $action=false][, bool $return=false])
- check_module_permission([string $module=false][, bool $return=false])
- check_permissions(void)
- create_main_menu(array $menus[, array $rightclickmenus=false][, bool $returnfirstmenu=false])
- Description - This function is responsible for creating the top main drop down menus as well as all the right click menus.
- Used - This function is used whenever the application builds or changes drop down menu items.
- Arguments
- $menus - array. A multi-dimensional array that describes what menus to create for the main top menu. See the example for the data structure definition.
- $rightclickmenus - array. Optional. A multi-dimensional array that describes what menus to create for the right click menus
- $returnfirstmenu - bool. Optional. If set to true, then just the HTML menu content for the first menu will be returned.
- Returns - string. If $returnfirstmenu is set to true, then this returns just the HTML menu content for the first menu. If not, then false is returned.
- If $returnfirstmenu is set to false, then the $OUT['TOPMENU'] and $OUT['MENUSYSTEM'] variables are populated with the entire HTML menu data.
<?php
$menus = array(
'file' => array(
'title' => 'File',
'help' => 'This shows when you are over the title',
'menuitems' => array(
array(
'image' => 'icon_ok',
'label' => 'Label',
'active' => 0,
'link' => 'link',
'separator' => 'after',
'header' => true,
'menuitems' => array(
)
),
)
),
);
$menu = create_main_menu($menus, false, true);
?>
- createXFDF(string $file, array $keys_values[, string $enc='UTF-8'])
- Description - Takes an associative array and returns an XFDF formatted string that points to a PDF file. The return value should be written out to disk and then used to populate a PDF form.
- Used - This function is used when generating a PDF form from a datamanager record.
- Arguments
- $file - string. The path to the PDF file that contains the form that you want to populate.
- $keys_values array. The associative array that contains the key / value pairs to populate the PDF form with. Keys should be named after form field names and values will be the populated value of the form field.
- $enc - String. Optional. The encoding attribute of the <?xml> tag.
- Returns - string. The XFDF formatted output that can be written out to file to create the XFDF file.
<?php
$fields = array(
'field1' => 'Value 1',
'field2' => 'December 31st',
'field3' => 'WOW, This is great.'
);
$xfdf = createXFDF('test.pdf', $fields);
$fh = fopen('tmp/test.xfdf', 'w');
fwrite($fh, $xfdf);
fclose($fh);
?>
- currency(float $amount[, choice $type='USD' USD|NUM|USTR])
- datamanager(array $data_structure[, bool $noreindex=false])
- datamanager_formatfield_text(array $rowdata, string $fieldname)
- datamanager_formatfield_textarea(array $rowdata, string $fieldname)
- datamanager_formatfield_time(array $rowdata, string $fieldname)
- datamanager_formatfield_calendarmonth(array $rowdata, string $fieldname)
- datamanager_formatfield_number(array $rowdata, string $fieldname)
- datamanager_formatfield_color(array $rowdata, string $fieldname)
- datamanager_formatfield_wysiwyg(array $rowdata, string $fieldname)
- datamanager_formatfield_wysiwyg_help(array $rowdata, string $fieldname)
- Description - This function takes the record data from a datamanager MySQL query and formats a field for display in a hover help box.
- Used - When the user creates an extra column and that column is a Rich Text field.
- Arguments
- $rowdata - array. The associative array for the record from the datamanager MySQL query. It can also easily be just an associative array that you create.
- $fieldname - string. The name of the MySQL field that you want to format and return. This should be the name of the key that contains the value that you want to format.
- Returns - string. The formatted text. (This function returns the exact text as in the value of the array. No change is made. This function does not do anything at this time)
- datamanager_formatfield_checkbox(array $rowdata, string $fieldname)
- datamanager_formatfield_phone(array $rowdata, string $fieldname)
- datamanager_formatfield_email(array $rowdata, string $fieldname)
- datamanager_formatfield_url(array $rowdata, string $fieldname)
- datamanager_formatfield_hasattachments(array $rowdata, array $dms)
- datamanager_formatfield_hasattachments_help(array $rowdata, array $dms)
- datamanager_getrecord(array $dms, int $rowid)
- datamanager_getselected([bool $del=false])
- datamanager_integrate_extrafields(arrayref &$dms[, string $module=false])
- db_connect([bool $return=false])
- Description - Connects to a MySQL database.
- Used - This function is called on every access to the software to connect to the database.
- Arguments
- $return - bool. Optional. If set to true and the connection fails, then the function returns false. If set to false and connection fails, the function doesn't return. Instead an error message is printed and the program exits.
- Returns - bool. true on a successful connection or false on an unsuccessful connection (if $return is set to true)
- This function relies on the global variables that are set in the config.php file in order to connect.
If you want to connect to a different database other than the VConsole MySQL database, then do not use this function as it will invalidate the database handle. Instead, use normal database connection methods.
<?php
db_connect();
?>
- db_query(string $query, varref &$dbresult)
- Description - Executes a database query to the main VConsole database. (Use the mysql_query() php if you want to query any other database that you connected to)
- Used - This function is called every time there is a query to the database.
- Arguments
- $query - string. The SQL query to execute. It can be any kind of query.
- $dbresult - varref. The database result handle will be stored in the variable that you set here.
- Returns - string. If the query is an INSERT statement, then the primary key of the record that was just inserted is returned. Otherwise true is returned.
<?php
db_query("SELECT * FROM `table`", $dbr);
while ($record = mysql_fetch_assoc($dbr)) {
echo "Got Record: {$record['id']}<br />\n";
}
$id = db_query("INSET INTO `table` SET
`name` = 'Test Name'", $dbr);
?>
- db_quote(string $string[, bool $noescape=false])
- db_select(string $dbname)
- debug(mixed $data)
- delete_searchindex(string $module, string $table_name[, string $table_index_field='id'])
- Description - This function will delete any datamanager search indexes that do not exist in the data table.
- Used - This function is used when any datamanager record is deleted.
- Arguments
- $module - string. The name of the module to delete search indexes for
- $table_name - string. The name of the data table to delete search indexes for
- $table_index_field - string. Optional. The name of the primary key for the table. Defaults to 'id'
- Returns - bool. Always returns false.
- IMPORTANT: If you do not call this function when a datamanager record is deleted, the search index table will continue to grow and never get any smaller. Searching speed will degrade with time.
<?php
db_query("DELETE FROM `test_table` WHERE `id` = 5", $dbr);
delete_searchindex('test', 'test_table', 'id');
?>
- forcesecure(void)
- format_filesize(int $size_in_bytes)
- format_mysqldate(string $format, string $date|'NOW()')
- FusionChartsExists(void)
- gauge(string $width, int %$fill[, int %$maxsafe=false][, string $help=false])
- gauge_big(int $width, int %$fill)
- generate_field(array $field, string $defaultval[, string $uploadtmpfile=false])
- Description - This function generates the HTML code for any type of field that is used by the wizardmanager, propertiesmanager, or inline edit.
- Used - This function is used any time the wizardmanager, propertiesmanager, inline edit is called. (You would not normally call this function directly as the wizardmanager(), propertiesmanager(), and datamanager() functions call this function internally.)
- Arguments
- $field - array. An array that contains the field definition for the field.
array(
'type' => [type],
'name' => [name],
'fhelp' => [field help on hover],
'fielddata' => [fielddata array], // Different for each field
)
- $defaultval - string. The default value for the field
- $uploadtmpfile - string. Optional. The path to an existing file. This argument is only used with file fields and if the file specified in this argument exists, then a simple message stating that the file has already been uploaded is postpended to the field.
- Returns - string. The HTML code for the field.
- Since this function is normally not called directly, we will not show an example of how to call it.
- generate_password([int $length=false])
- get_config(void)
- Description - This function simply includes the config.php file and if the file does not exist, it initiates the installation procedure.
- Used - This is used on every access to the software.
- Arguments - None
- Returns - bool. Always returns false.
- Since this function is not used except to include the config.php file (which is already included by the time your module files are executed) we will not show an example of how to call it.
- get_content_type(string $fileextension)
- get_dms_array(string $module)
- get_module_list(void)
- Description - This function is responsible for generating the HTML for the top navigation bar. (The bar that contains the list of modules)
- Used - This function is used on every access of the software to get the current module list that displays in the top navigation bar.
- Arguments - None
- Returns - string. The HTML code that is displayed in the top navigation bar.
- Since this function is not useful other than generating the HTML code for the top navigation bar, which is generated before your module files are executed, we will not show an example of how to call it.
- get_params(void)
- get_url(string $url[, string $postvars])
- getimage(string $imagename[, string $align='absmiddle'][, int alpha=100])
- has_permission(string $module)
- Description - This function is depreciated and no longer functions since VConsole V4.0. Use the check_module_permission() function instead.
- help_format(string $helptext[, bool $breaks=true])
- hierarchical_add(string $table, int $parent, varref &$err[, string $index='id'][, string|resource $dbhandle=false])
- hierarchical_delete(string $table, int $id, varref &$err[, string $index='id'][, bool $sub=true][, string|resource $dbhandle=false])
- hierarchical_moveto(string $table, int $id, int $moveto, varref &$err[, string $index='id'][, string|resource $dbhandle=false])
- hierarchical_setorder(string $table, int $id, int $order, varref &$err[, string $index='id'][, string|resource $dbhandle=false])
- hierarchical_nl_add(string $table, int $parent, varref &$err[, string $index='id'][, string|resource $dbhandle=false])
- Description - This function adds a record to a MySQL table that contains nested set hierarchical data. IT DOES NOT LOCK THE TABLE like the hierarchcal_add() function does. (See "Managing Hierarchical Data" for more information). It will perform all the functions as described in the "Adding A Record" section including rearranging all the lft, rgt, and optionally depth values of the table (if a depth field is present in the table). The table MUST contain a lft and rgt field in order for this function to work properly otherwise you will get a MySQL query error. The table can optionally contain a depth field to keep track of the depth of a record. (We recommend having a depth field because you will get a huge performance boost when the table has a lot of records.) Depending on how you use your hierarchical table, we also recommend indexing the lft, rgt, and depth fields.
- Used - This function is not used in the default installation of VConsole. However, you can use it to add a record to a hierarchical data table.
- Arguments
- $table - string. Should be the name of the MySQL table to add the record to.
- $parent - int. Should be the primary index of the record that should be the parent of the new record. The new record will be added as the last child of the record that is specified here.
- $err - varref. A variable should be passed that will be populated with the error message in case of failure.
- $index - string. Optional. If set, this should be the MySQL field name of the primary index for the table. This defaults to 'id' if not set.
- $dbhandle - string or resource. This should be set to the database handle to use when adding the record to the table. Only advanced users should attempt to use this parameter.
- Returns - int. This function returns the id of the primary index for the record that was added. The record is always added with no data. You should use the return value of this function to update the record with the data that you want it to have.
- hierarchical_nl_delete(string $table, int $id, varref &$err[, string $index='id'][, bool $sub=true][, string|resource $dbhandle=false])
- Description - This function deletes a record from a MySQL table that contains nested set hierarchical data. IT DOES NOT LOCK THE TABLE like the hierarchcal_delete() function does. (See "Managing Hierarchical Data" for more information). It will perform all the functions as described in the "Deleting A Record" section including rearranging all the lft, rgt, and optionally depth values of the table (if a depth field is present in the table). The table MUST contain a lft and rgt field in order for this function to work properly otherwise you will get a MySQL query error. The table can optionally contain a depth field to keep track of the depth of a record. (We recommend having a depth field because you will get a huge performance boost when the table has a lot of records.) Depending on how you use your hierarchical table, we also recommend indexing the lft, rgt, and depth fields.
- Used - This function is not used in the default installation of VConsole. However, you can use it to delete a record from a hierarchical data table.
- Arguments
- $table - string. Should be the name of the MySQL table to delete the record from.
- $id - int. Should be the primary index of the record to delete.
- $err - varref. A variable should be passed that will be populated with the error message in case of failure.
- $index - string. Optional. If set, this should be the MySQL field name of the primary index for the table. This defaults to 'id' if not set.
- $sub - bool. Optional. If set to false, then all sub branches are not deleted and instead promoted to the level of the deleted branch. If set to true or not specified, then all sub branches will also be deleted.
- $dbhandle - string or resource. This should be set to the database handle to use when performing this operation. Only advanced users should attempt to use this parameter.
- Returns - bool. This function returns true on success or false on failure. If it returns false, then $err will be populated with a reason why.
- hierarchical_nl_moveto(string $table, int $id, int $moveto, varref &$err[, string $index='id'][, string|resource $dbhandle=false])
- Description - This function takes care of moving a record (and all children) to a new parent in a MySQL table that contains nested set hierarchical data. IT DOES NOT LOCK THE TABLE like the hierarchcal_moveto() function does. (See "Managing Hierarchical Data" for more information). It will perform all the functions necessary to move a record (and all children) to a new parent including rearranging all the lft, rgt, and optionally depth values of the table (if a depth field is present in the table). The table MUST contain a lft and rgt field in order for this function to work properly otherwise you will get a MySQL query error. The table can optionally contain a depth field to keep track of the depth of a record. (We recommend having a depth field because you will get a huge performance boost when the table has a lot of records.) Depending on how you use your hierarchical table, we also recommend indexing the lft, rgt, and depth fields.
- Used - This function is not used in the default installation of VConsole. However, you can use it to move a record to a new parent in a hierarchical data table.
- Arguments
- $table - string. Should be the name of the MySQL table in which to move the record.
- $id - int. Should be the primary index of the record to move.
- $moveto - int. Should be the primary index of the record that the record (and all children) should be moved under. The record specified in the $id parameter will be set as the last child of the record that is specified here.
- $err - varref. A variable should be passed that will be populated with the error message in case of failure.
- $index - string. Optional. If set, this should be the MySQL field name of the primary index for the table. This defaults to 'id' if not set.
- $dbhandle - string or resource. This should be set to the database handle to use when performing this operation. Only advanced users should attempt to use this parameter.
- Returns - bool. This function returns true on success or false on failure. If it returns false, then $err will be populated with a reason why.
- hierarchical_nl_setorder(string $table, int $id, int $order, varref &$err[, string $index='id'][, string|resource $dbhandle=false])
- Description - This function takes care of setting the order of a record within the parent record in a MySQL table that contains nested set hierarchical data. IT DOES NOT LOCK THE TABLE like the hierarchcal_setorder() function does. (See "Managing Hierarchical Data" for more information). It will perform all the functions necessary to move a record (and all children) to a new order within the parent including rearranging all the lft, rgt, and optionally depth values of the table (if a depth field is present in the table). The table MUST contain a lft and rgt field in order for this function to work properly otherwise you will get a MySQL query error. The table can optionally contain a depth field to keep track of the depth of a record. (We recommend having a depth field because you will get a huge performance boost when the table has a lot of records.) Depending on how you use your hierarchical table, we also recommend indexing the lft, rgt, and depth fields.
- Used - This function is not used in the default installation of VConsole. However, you can use it to move a record to a new order within the parent in a hierarchical data table.
- Arguments
- $table - string. Should be the name of the MySQL table in which to set the order of the record.
- $id - int. Should be the primary index of the record to set the order of.
- $order - int. Should be a positive integer or 0. If set to 0, then the record will be set as the last child of its current parent. If set to 1 or higher, then this will be the order that will be set under the current parent. For example, if you set 1 then the record will be set as the first child of its current parent.
- $err - varref. A variable should be passed that will be populated with the error message in case of failure.
- $index - string. Optional. If set, this should be the MySQL field name of the primary index for the table. This defaults to 'id' if not set.
- $dbhandle - string or resource. This should be set to the database handle to use when adding the record to the table. Only advanced users should attempt to use this parameter.
- Returns - bool. This function returns true on success or false on failure. If it returns false, then $err will be populated with a reason why.
- html_print_r(mixed $value[, bool $return=false])
- htmltotext(string $html[, int $maxwidth=false])
- Description - This function takes HTML code and formats it as plain text. It does everything it possibly can to make sure that the plain text looks as close to the HTML as possible.
- Used - This function is not used in the default installation of VConsole. However, you can use it for your own purposes.
- Arguments
- $html - string. This should be set to the HTML string that you want formatted as plain text.
- $maxwidth - int. Optional. If set, then the plain text will have a maximum character width and wrapping will occur beyond the character width set here.
- Returns - string. The plain text that is a result of the conversion from HTML to plain text.
- make_datamanager_menu(array $dms)
- Description - This function is responsible for creating all the drop down menus that are required in a datamanager module. This includes all the top menu bar drop down menus as well as all the right click menus.
- Used - This function is used internally in the datamanager() function to create all the associated drop down menus.
- Arguments
- $dms - array. The $dms data structure for the module. You can get the $dms data structure by calling the get_dms_array() function.
- Returns - bool. This function always returns false.
- When called, the $OUT['TOPMENU'] and $OUT['MENUSYSTEM'] variables are populated with the entire HTML menu data required by the datamanager module.
- You usually won't ever need to call this function unless you just want to check out the $OUT['TOPMENU'] and $OUT['MENUSYSTEM'] global variables before calling the datamanager() function.
<?php
$dms = get_dms_array($_SESSION[ 'module']);
make_datamanager_menu($dms);
global $OUT;
html_print_r($OUT);
?>
- make_favorites_menu(void)
- Description - This function is responsible for creating the data structure that is required to create the "Favorites" drop down menu. The menu is populated based on each individual user's favorite items.
- Used - This function is called whenever the "Favorites" drop down menu needs to be created or modified.
- Arguments - None
- Returns - array. The data structure that is passed off to the create_main_menu() function in order to create the "Favorites" drop down menu.
- You usually won't ever need to call this function unless you just want to check out data structure or the HTML code for the menu.
- make_main_menu(void)
- Description - This function is responsible for creating all the drop down menus that are required in a non-datamanager module. This includes all the top menu bar drop down menus as well as all the right click menus.
- Used - This function is called to initially build the top main menu when the user accesses the software. It is also called to update the top main menu when needed.
- Arguments - None
- Returns - bool. This function always returns false.
- When called, the $OUT['TOPMENU'] and $OUT['MENUSYSTEM'] variables are populated with the entire HTML menu data required by the top main menu.
- You usually won't ever need to call this function unless you just want to check out the $OUT['TOPMENU'] and $OUT['MENUSYSTEM'] global variables.
- make_path_menu(void)
- Description - This function is responsible for creating the data structure that is required to create the "Path" fly out menus (Under "Main Menu" > "Home")
- Used - This function is called to initially build the "Path" fly out menus when the user accesses the software.
- Arguments - None
- Returns - array. The data structure that is passed off to the create_main_menu() function in order to create the "Path" fly out menus.
- You usually won't ever need to call this function unless you just want to check out the data structure or the HTML code for the menu.
- notify_suppot(string $msg[, string|array $toemail='VSource'][, string $subject='Problem on members site'][, string $from=false][, string $vmsg=false][, bool $noerror=false])
- Description - This function is designed to notify support of a problem with the software. When called, this function will call the debug() function and dump the entire current state of the software including all variables. It will then send an email to the address of your choice and finally, it will set an error message if you choose to do so.
- Used - This function is not used in the default code base.
- Arguments
- $msg - string. A simple message to store in the vc_debug table. If this argument evaluates to false, then the debug() function is not called. Always pass something here.
- $toemail - string|array. Optional. This variable determines where the notification email is sent. It can be a single email address or an array of email addresses.
- $subject - string. Optional. The subject for the notification email.
- $from - string. Optional. The from email address for the notification email.
- $vmsg - string. Optional. If set, then this is placed in the body of the notification email.
- $noerror - bool. Optional. If set to true, then no error is displayed to the user and the user never knows that anything happened. If set to false (default), then an error message is set that lets the user know that a problem has occurred and that support has been notified.
- Returns - bool. Always returns true
<?php
global $GLOB;
$msg = 'User did not enter YES';
$to = 'test@test.com';
$subject = 'Invalid Response';
$from = $GLOB['login']['email'];
$vmsg = $msg;
if (!preg_match('/yes/i', $_REQUEST['field'])) {
notify_support($msg, $to, $subject, $from, $vmsg);
}
?>
- parse_template(string $template_file[, string $where='STDOUT'][, array $private=false])
- Description - This function searches a file for variables identified as ||VARIABLE|| and substitutes the value with the corresponding key from the global associative arrays $OUT, $PARAMS, $_SESSION, and $_SERVER . (The arrays are checked in this order). Lines beginning with 0: will only be printed if a variable appears on that line and has a value in one of the mentioned arrays.
- Used - This function is used to output the interface. All the files in the vconsole/skins/vsource/templates/ folder are used as templates.
- Arguments
- $template_file - string. The path to the file to use as a template.
- $where - string. Optional. Where to output the results.
- STDOUT - The results will be sent to the browser.
- RETURN - The results will be returned
- >path_to_file - The results will be written to the file at path_to_file. The file is overwritten.
- >>path_to_file - The results will be appended to the file at path_to_file. The file is not overwritten. The results are appended to the end of the file.
- $private - array. Optional. An associative array that contains name - value pairs to use in the variable substitution. This array will be checked before $OUT, $PARAMS, $_SESSION, or $_SERVER and if a variable match is found, it is used instead of any of the other global arrays.
- Returns - string. If $where is set to RETURN, then the results are returned as a string, otherwise true is returned if the operation was successful or false is returned if not successful.
- If false is returned, then $GLOB['Error_Message'] contains the error message of why the operation failed.
<?php
$string = "This is a file that
I want to be parsed<br />
The first variable is ||VAR1||
0: This line should not be output ||VAR2||
0: This line is output. ||VAR3||
The fourth line - ||VAR4||";
$file = "tmp/template.htm";
$fh = fopen($file, 'w');
fwrite($fh, $string);
fclose($fh);
$private = array(
'VAR1' => 'Variable 1',
'VAR3' => 'Var3 Exists'
);
$OUT[ 'VAR4'] = 'Testing 123';
$results = parse_template($file, 'RETURN', $private);
$success = parse_template($file, '>tmp/out.htm', $private);
if ($success) {
} else {
global $GLOB;
set_message( 'error', $GLOB[ 'Error_Message']);
}
?>
- propertiesmanager(array $data)
- Description - This function will deliver a GUI interface to the user that gives them a list of property tabs along with 1 or more form fields per tab so that the user can input data. The validated results are returned.
- Used - This function is not used in the VConsole code base.
- Arguments
- Returns - array. An array of all the field name - value pairs. The results are validated according to the validation parameters in the $data array. See The Properties Manager for an example of how to use this function.
- require_library(string $folder_name)
- searchindex(string $module, int $rowid[, array $data_manager_structure=false])
- Description - Indexes a datamanager record so that it is found when the user performs a text search (Only used for text searching)
- Used - Every time a datamanager record is added or modified.
- Arguments
- $module - string. The name of the datamanager module to perform the index for.
- $rowid - int. The record id (primary key) for the record to index.
- $data_manager_structure - array. Optional. The datamanager $dms data structure as defined in the dms.php file. If not provided, then the data structure is retrieved using get_dms_array($module)
- Returns - bool. Always returns true.
<?php
$id = db_query("INSERT INTO `table` SET
`field1` = 'test', `field2` = 'test2'", $dbr);
searchindex($_SESSION['module'], $id);
?>
- send_email(string|array $to, string $subject, string $body[, string $from=false][, string $fromname=false][, string $altbody=false][, bool $html=false][, string|array $attach=false])
- Description - Sends 1 or more emails.
- Used - Not used in the default VConsole code base.
- Arguments
- $to - string|array. The email address or addresses to send email to. It be a single email address or an array of email addresses.
- $subject - string. The subject for the email.
- $body - string. The message body (HTML OK)
- $from - string. Optional. If set, this will be the from email address.
- $fromname - string. Optional. If set, this will be the from name.
- $altbody - string. Optional. If set, this will be the plain text alternative for the email. Use to give users with older email clients a plain text alternative. (Should only be set if $html is set to true)
- $html - bool. Optional. If set to true, the $body will be treated as HTML code. If set to false, then HTML will be treated as plain text.
- $attach - string|array. Optional. This should be the path to a file to attach or an array of file paths to attach to the email. The file(s) must exist.
- Returns - bool. Returns true if the email was sent successfully or false otherwise.
- If sending fails, then an error message is set with the set_message() function.
- If $PARAMS['USESMTP'] evaluates to false, then the PHP mail() function is used to send the email. Otherwise, an SMTP server is used to send the email. To modify the SMTP server parameters, please modify the records in the vc_console-params table. Here is a list of the parameters and what they do.
- USESMTP - Set the value of this record to 1 to use an SMTP server or 0 to use the PHP mail() function to send the email(s)
- SMTPSERVER - Set the value of this record to the SMTP server to use to send the email(s)
- SMTPUSER - Set the value of this record to the SMTP user to use to login to the SMTP sever.
- SMTPPASS - Set the value of this record to the password to use to login to the SMTP server.
- SMTPPORT - Set the value of this record to the port to use to communicate with the SMTP server. (Usually 25)
- Sending mail over secure SMTP is not supported at this time.
<?php
$to = array('test@test.com', 'test2@test.com');
$sub = 'Testing Email';
$bdy = "Testing Email Body<br />Second Line.";
$frm = 'from@test.com';
$fmn = 'Test User';
$alt = "Testing Email Body\nSecond Line.";
$htm = true;
$att = array(
'tmp/attachment1.pdf',
'tmp/attachment2.pdf'
);
if (!send_email($to,$sub,$bdy,$frm,$fmn,$alt,$htm,$att)){
} else {
}
?>
- send_error(string $msg)
- send_login([string $msg=''][, string $type=false])
- send_output(void)
- Description - This function takes care of drawing the user interface and / or sending output to the AJAX engine. It uses some condition checking to determine what to output to the user.
- Used - This function is used when a module file returns control to the main VConsole program. It is used to draw the interface to the browser and / or output the correct text to the AJAX engine.
- Arguments - None
- Returns - This function does not return.
- You should never have to call this function as all you need to do is call return() from your module file and it is called automatically.
- send_stationary(string|array $toemail, string $subject, string $body[, string $fromemail=false][, string $fromname=false][, string $altbody=false][, bool $noreply=false][, string|array $attach=false])
- Description - This PHP function works almost like the send_email() function, except that it will send a formatted email using the stationary HTML template file. See Sending Email for more information.
- Used - This function is not used in the default code base.
- Arguments
- $toemail - string|array. The email address or addresses to send email to. It be a single email address or an array of email addresses.
- $subject - string. The subject for the email.
- $body - string. The message body in HTML (This is always interpreted as HTML)
- $fromemail - string. Optional. The from email address.
- $fromname - string. Optional. The from name.
- $altbody - string. Optional. If set, this will be the plain text alternative for the email. Use to give users with older email clients a plain text alternative.
- $noreply - bool. Optional. If set to true, then a "Do Not Reply" message is added to both the $body and $altbody arguments. (Try setting this to true to see the results)
- $attach - string|array. Optional. This should be the path to a file to attach or an array of file paths to attach to the email. The file(s) must exist.
- Returns - bool. Returns true if the email was sent successfully or false otherwise.
- This function actually calls the send_email() function to send out the email(s). See the notes on that function to determine whether the email is sent using the PHP mail() function or an SMTP server.
<?php
$to = array('test@test.com', 'test2@test.com');
$sub = 'Testing Email';
$bdy = "Testing Email Body<br />Second Line.";
$frm = 'from@test.com';
$fmn = 'Test User';
$alt = "Testing Email Body\nSecond Line.";
$att = array(
'tmp/attachment1.pdf',
'tmp/attachment2.pdf'
);
if (!send_stationary($to,$sub,$bdy,$frm,$fmn,$alt,false,$att)){
} else {
}
?>
- set_message(choice $type info|success|warn|error, string $msg[, string $errorfield=false])
- set_vars(void)
- Description - This function sets a bunch of global variables
- Used - This function is called on every access to the software.
- Arguments - None
- Returns - bool. Always returns false
- There is no need to call this function unless you delete a global variable and then need to set it again.
- validate_field(array $field, string $val, arrayref &$msg[, int $recid=false][, string $confval=false][, array $filerec=false][, array $selected=false])
- Description - This is the higher level function that calls the validate_input() function. This function is called by some even higher level functions - wizardmanager() and propertiesmanager(). This function validates input from a wizardmanager or propertiesmanager field.
- Used - This function is used whenever the user submits input from a propertiesmanager or wizardmanager interface.
- Arguments
- $field - array. The field definition array as passed to the wizardmanager() or propertiesmanager() functions
- $val - string. The input value to validate against.
- $msg - arrayref. This will be populated with an array of error messages if validation fails. There will be 1 error message per failing condition. If the value must be at least 5 characters and must start with a letter, and the $value is 6we, there will be 2 error messages set.
- $recid - int. Optional. The record id to check against. This value is used only for "unique" validations so that every record is checked for duplicates except itself.
- $confval - string. Optional. The value of the confirmation field. This argument is only used for "confirmation field" validations. (If you want the user to type in the password twice, set this value to the value of the 2nd password field.)
- $filerec - array. Optional. The file associative array that is retrieved from the upload record from the vc_fileuploads-files table. This argument is only used for file upload fields.
- $selected - array. Optional. This argument is currently not used.
- Returns - bool. If validation succeeds, then true is returned, otherwise, false is returned.
- You should never need to call this function as it is only applicable from within the wizardmanager() and propertiesmanager() functions so we will not show an example of how to call this function.
- validate_input(varref &$error_msg, string $value, string $fieldname[, bool $seterror=false][, string $errorfield=false][, bool $required=false][, string $type=false][, int $minlength=false][, int $maxlength=false][, float $minnum=false][, float $maxnum=false][, regex $match=false][, regex $nomatch=false])
- Description - This function is responsible for validating form fields that are used in the wizardmanager() and propertiesmanager() functions.
- Used - This function is called internally from the validate_field() function. This is the low level function that takes care of validating user input.
- Arguments
- $error_msg - varref. This will be set to the error message if validation fails. This can be sent to the user.
- $value - string. The value of the field to validate against. (User's input)
- $fieldname - string. The human readable field label. Example: "First Name"
- $seterror - bool. Optional. If true, and validation fails, then the set_message() function will be called to set the error message that is populated into the $error_msg argument. In other words, if set to true, then both $error_message is set AND set_message() is called.
- $errorfield - string. Optional. Set to the error field argument to send to the set_message() function. See the set_message() function above.
- $required - bool. Optional. If set to true, then the $value argument must have a string length of at least 1 in order for validation to succeed.
- $type - string. Optional. Set to the type of validation to perform. (See The Wizardmanager for explanations on what this should be. Look for the <content_type> parameter.)
- $minlength - int. Optional. Set to the minimum string length that $value must be in order for validation to succeed.
- $maxlength - int. Optional. Set to the maximum string length that $value can be in order for validation to succeed.
- $minnum - int. Optional. Set to the minimum numerical value that $value must evaluate to in order for validation to succeed.
- $maxnum - int. Optional. Set to the maximum numerical value that $value can evaluate to in order for validation to succeed.
- $match - regex. Optional. Set to the regular expression that $value MUST match in order for validation to succeed.
- $nomatch - regex. Optional. Set to the regular expression that $value MUST NOT match in order for validation to succeed.
- Returns - bool. This returns true if validation succeeded and $value conforms to all the conditions set by the other arguments. It returns false otherwise.
<?php
$value = 'val1';
if (!validate_input($err, $value, 'Value', false, false, true, false, 5)) {
} else {
}
?>
- validate_group(array $data[, bool $continue_after_fail=false])
- Description - This function will call the validate_input() function over and over for each array that is passed in as $data. You can use this function to do a low level validation of a group of input values at once. It is equivilent to calling validate_input() within a loop.
- Used - This function is not used in the default code base.
- Arguments
- $data - array. This argument should be an array of arrays. Each array in this array should conform to the arguments that are passed to the validate_input() function starting with the fieldname.. We will give an example below.
- $continue_after_fail - bool. Optional. If set to true, then if a field fails to validate, validation of the rest of the fields continues. Otherwise, it stops.
- Returns - bool. It returns true if all fields passed validation, otherwise it returns false.
<?php
$fields = array(
array('val1', 'Value', false, false, true, false, 3),
array('val2', 'Value2', false, false, true, false, 5)
);
if (validate_group($fields)) {
} else {
}
?>
- validate_login(void)
- Description - This function validates the user's login. It is responsible for checking usernames and passwords, for creating login sessions, and for making sure that a user's session is still valid on every access to the software.
- Used - This function is used on every access to the software.
- Arguments - None
- Returns - bool. This function always returns false.
- If a user's login credentials or session is not valid, then the send_login() function is called which never returns.
- You should never need to call this function so we will not show an example.
- wizardmanager(array $data_structure)
- Description - This function will deliver a GUI interface to the user that takes them step by step through a wizard process so that the user can input data. The validated results are returned.
- Used - This function is used for creating new users, creating new groups, creating new accounts, changing passwords, and more.
- Arguments
- Returns - array. An array of all the step numbers which contain all the field name - value pairs. The results are validated according to the validation parameters in the $data_structure array. See The Wizard Manager for an example of how to use this function.
- XML_unserialize(string $xml)
- XML_serialize(array $data)
Image Manipulation Functions.
There are other PHP functions that exist that have to do with image manipulation. Please see Image Manipulation here to check out these functions and what they do.
NEXT: PHP Function Libraries
COMMENTS There are no comments at this time.
|
|
 |
 |
 |
|