Materialize.php
Wizard’s Toolkit functions for MaterializeCSS and HTML template methodology.
All rights reserved.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Tags
Table of Contents
- wtkMenu() : html
- Create data-driven menu based on Menu Set.
- wtkDisplayData() : html
- This receives form field HTML with tokens and replaces the @tokens@ with data.
- wtkFormLabel() : html
- This is called by many form-creating functions to generate the Label text.
- wtkFormText() : html
- Creates an input text field.
- wtkFormTextArea() : html
- Creates a textarea field.
- wtkFormRadio() : html
- Creates input form fields for type="radio".
- wtkFormCheckbox() : html
- Creates input form field for type="checkbox".
- wtkFormSwitch() : html
- Creates input form field for type="checkbox" but with Switch user interface
- wtkFormSelect() : html
- Creates html for Select drop list.
- wtkFormSelectFont() : html
- Similar to wtkFormSelect but this one shows font styles while displaying select drop list of fonts
- wtkFileUpload() : html
- Used to create file input field for uploading files.
- wtkFormFile() : html
- Used to create file input field for uploading files. Check to see whether to use wtkFileUpload instead.
- wtkUpdateBtns() : html
- Create cancel, save and possibly copy buttons. If read-only then instead shows a "Return" button.
- wtkPageList() : html
- By passing a SQL SELECT this will build a nice looking page.
- wtkChatList() : html
- Create list of chat data.
- wtkSaveChat() : html
- This creates HTML with saveChat JavaScript function. Used at bottom of chatEdit.php.
- wtkForumList() : html
- Create list of Forum data.
- wtkSendNoteForum() : html
- This creates HTML with sendNote JavaScript function. Used at bottom of forumEdit.php.
Functions
wtkMenu()
Create data-driven menu based on Menu Set.
wtkMenu(
string
$fncMenuSetName
[,
string
$fncSpecial =
'N' ]
) :
html
This uses the wtkMenuSets
data table and the child tables of wtkMenuGroups
, wtkMenuItems
,
and wtkPages
. This creates both the top-menu and in case the screen is
small, it creates the side-bar menu code as well.
The menu structures are available in the WTK /admin/ website.
Parameters
- $fncMenuSetName : string
-
must match
wtkMenuSets
.MenuName
- $fncSpecial : string = 'N'
-
defaults to 'N', if set to 'BreadCrumbs' then adds code for Breadcrumbs to use
Return values
html —of drop and side-menus
wtkDisplayData()
This receives form field HTML with tokens and replaces the @tokens@ with data.
wtkDisplayData(
string
$fncColName
,
string
$fncHtm
[,
string
$fncTable =
''
][
, string
$fncDefaultIfBlank =
''
][
, string
$fncPrepType =
'text'
]) :
html
This is called within other MaterializeCSS PHP functions. It sets class="active" for label when there is data in the form field.
wtkSearchReplace('<!-- @wtkMenu@ -->', wtkNavBar('Wizards Toolkit'));
Parameters
- $fncColName : string
-
data column name
- $fncHtm : string
-
that has tokens to be changed into data
- $fncTable : string = ''
-
defaults to '' blank; if passed then prepares field for WTK updating and saving
- $fncDefaultIfBlank : string = ''
-
defaults to ''; if currently no value in data, use this default
- $fncPrepType : string = 'text'
-
defaults to 'text' and used by wtkFormPrepUpdField
Tags
Return values
html —returns modified passed $fncHtm with data values
wtkFormLabel()
This is called by many form-creating functions to generate the Label text.
wtkFormLabel(
string
$fncLabel
,
string
$fncColName
) :
html
If a Label is passed it is returned directly. Otherwise this uses the Column Name and inserts spaces. Generally this will only be called by internal functions.
Parameters
- $fncLabel : string
-
can be passed '' blank value
- $fncColName : string
-
data column name like what was passed to wtkFormText
Return values
html —returns text to use as Label
wtkFormText()
Creates an input text field.
wtkFormText(
string
$fncTable
,
string
$fncColName
[,
string
$fncType =
'text'
][
, string
$fncLabel =
''
][
, string
$fncColSize =
'm6 s12'
][
, string
$fncRequired =
'N'
][
, string
$fncHelpText =
''
]) :
html
If a special Type is passed then additional validation and class styles are added. Special Types include:
- date
- time
- number
- tel
- timepicker
Parameters
- $fncTable : string
-
data table
- $fncColName : string
-
data column name
- $fncType : string = 'text'
-
becomes type="$fncType" and triggers enhancements of JS validation and class styles
- $fncLabel : string = ''
-
optionally passed, if not then uses $fncColName
- $fncColSize : string = 'm6 s12'
-
defaults to 'm6 s12'
- $fncRequired : string = 'N'
-
defaults to 'N'
- $fncHelpText : string = ''
-
defaults to '', pass to add
Tags
Return values
html —returns surrounding HTML for input form field
wtkFormTextArea()
Creates a textarea field.
wtkFormTextArea(
string
$fncTable
,
string
$fncColName
[,
string
$fncLabel =
''
][
, string
$fncColSize =
'm12 s12'
][
, string
$fncRequired =
'N'
][
, string
$fncHelpText =
''
]) :
html
Parameters
- $fncTable : string
-
data table
- $fncColName : string
-
data column name
- $fncLabel : string = ''
-
optionally passed, if not then uses $fncColName
- $fncColSize : string = 'm12 s12'
-
defaults to 'm6 s12'
- $fncRequired : string = 'N'
-
defaults to 'N'
- $fncHelpText : string = ''
-
defaults to '', pass to add
Tags
Return values
html —returns surrounding HTML for textarea
wtkFormRadio()
Creates input form fields for type="radio".
wtkFormRadio(
string
$fncTable
,
string
$fncColName
,
string
$fncLabel
,
array<string|int, mixed>
$fncValueArray
[,
string
$fncColSize =
'm6 s12'
]) :
html
Example calling method:
$pgValues = array(
'Male' => 'M',
'Female' => 'F',
'Uncertain' => 'U'
);
$pgHtm .= wtkFormRadio('pets', 'Gender', 'Pet Gender', $pgValues, 'm2 s6');
Parameters
- $fncTable : string
-
data table
- $fncColName : string
-
data column name
- $fncLabel : string
-
optionally passed, if not then uses $fncColName
- $fncValueArray : array<string|int, mixed>
-
must contain values
- $fncColSize : string = 'm6 s12'
-
defaults to 'm6 s12'
Tags
Return values
html —returns surrounding HTML for radio fields
wtkFormCheckbox()
Creates input form field for type="checkbox".
wtkFormCheckbox(
string
$fncTable
,
string
$fncColName
,
string
$fncLabel
,
array<string|int, mixed>
$fncValueArray
[,
string
$fncColSize =
'm6 s12'
]) :
html
The $pgValues array needs to pass what the value should be when 'checked' and when 'not' checked.
Example calling method:
$pgValues = array(
'checked' => 'Y',
'not' => 'N'
);
$pgHtm .= wtkFormCheckbox('pets', 'CanTreat', 'Allowed to give Treats', $pgValues, 'm3 s6');
Parameters
- $fncTable : string
-
data table
- $fncColName : string
-
data column name
- $fncLabel : string
-
optionally passed, if not then uses $fncColName
- $fncValueArray : array<string|int, mixed>
-
must contain values
- $fncColSize : string = 'm6 s12'
-
defaults to 'm6 s12'
Tags
Return values
html —returns surrounding HTML for checkbox field
wtkFormSwitch()
Creates input form field for type="checkbox" but with Switch user interface
wtkFormSwitch(
string
$fncTable
,
string
$fncColName
,
string
$fncLabel
,
array<string|int, mixed>
$fncValueArray
[,
string
$fncColSize =
'm6 s12'
]) :
html
The $pgValues array needs to pass what the value should be when 'checked' and when 'not' checked.
Example calling method:
$pgValues = array(
'checked' => 'Y',
'not' => 'N'
);
$pgHtm .= wtkFormSwitch('wtkShortURL', 'PasswordYN', 'Use Password', $pgValues, 'm2 s12');
Parameters
- $fncTable : string
-
data table
- $fncColName : string
-
data column name
- $fncLabel : string
-
optionally passed, if not then uses $fncColName
- $fncValueArray : array<string|int, mixed>
-
must contain values
- $fncColSize : string = 'm6 s12'
-
defaults to 'm6 s12'
Tags
Return values
html —returns surrounding HTML for checkbox field
wtkFormSelect()
Creates html for Select drop list.
wtkFormSelect(
string
$fncTable
,
string
$fncColName
,
string
$fncSQL
,
array<string|int, mixed>
$fncFilter
,
string
$fncDisplayField
,
string
$fncValueField
[,
string
$fncLabel =
''
][
, string
$fncColSize =
'm6 s12'
][
, string
$fncShowBlank =
'N'
]) :
html
The SQL query to use to generate a list of values and display values needs to be passed.
Example calling method:
$pgSQL = "SELECT
LookupValue
, LookupDisplay
FROM wtkLookups
WHERE LookupType
= 'USAstate' ORDER BY LookupValue
ASC";
$pgHtm .= wtkFormSelect('pets', 'State', $pgSQL, [], 'LookupDisplay', 'LookupValue','','m4 s6');
Parameters
- $fncTable : string
-
data table
- $fncColName : string
-
data column name
- $fncSQL : string
-
SQL query to retrieve value and display to show in select
- $fncFilter : array<string|int, mixed>
-
SQL PDO values if necessary or pass blank array []
- $fncDisplayField : string
-
column name from $fncSQL to display
- $fncValueField : string
-
column name from $fncSQL to use as value in options
- $fncLabel : string = ''
-
optionally passed, if not then uses $fncColName
- $fncColSize : string = 'm6 s12'
-
defaults to 'm6 s12'
- $fncShowBlank : string = 'N'
-
defaults to 'N'
Tags
Return values
html —returns surrounding HTML for checkbox field
wtkFormSelectFont()
Similar to wtkFormSelect but this one shows font styles while displaying select drop list of fonts
wtkFormSelectFont
(
string
$fncTable
,
string
$fncColName
,
string
$fncSQL
,
array<string|int, mixed>
$fncFilter
,
string
$fncDisplayField
,
string
$fncValueField
[,
string
$fncLabel =
''
][
, string
$fncColSize =
'm6 s12'
]) :
html
The SQL query to use to generate a list of values and display values needs to be passed.
Example calling method:
$pgSQL = "SELECT
LookupValue
, LookupDisplay
FROM wtkLookups
WHERE LookupType
= ? ORDER BY LookupDisplay
ASC";
$pgTmp .= wtkFormSelectFont('LandingPage', 'BodyFont', $pgSQL, ['Font'], 'LookupDisplay', 'LookupValue', 'Body Font', 'm6 s12');
Parameters
- $fncTable : string
-
data table
- $fncColName : string
-
data column name
- $fncSQL : string
-
SQL query to retrieve value and display to show in select
- $fncFilter : array<string|int, mixed>
-
SQL PDO values if necessary or pass blank array []
- $fncDisplayField : string
-
column name from $fncSQL to display
- $fncValueField : string
-
column name from $fncSQL to use as value in options
- $fncLabel : string = ''
-
optionally passed, if not then uses $fncColName
- $fncColSize : string = 'm6 s12'
-
defaults to 'm6 s12'
Tags
Return values
html —returns surrounding HTML for checkbox field
wtkFileUpload()
Used to create file input field for uploading files.
wtkFileUpload(string $fncTable, string $fncColPath, string $fncFilePath, string $fncFileName[, string $fncRefresh = '' ]) : html
Example calling method:
$pgCamera = wtkFileUpload('wtkUsers','FilePath','../imgs/user/','NewFileName','myPhoto');
$pgHtm = wtkReplace($pgHtm, '@wtkFileUpload@', $pgCamera);
Parameters
- $fncTable : string
-
data table
- $fncColPath : string
-
stuff
- $fncFilePath : string
- $fncFileName : string
-
stuff
- $fncRefresh : string = ''
-
defaults to '' blank
Return values
html —returns surrounding HTML for input type="file"
wtkFormFile()
Used to create file input field for uploading files. Check to see whether to use wtkFileUpload instead.
wtkFormFile(string $fncTable, string $fncColPath, string $fncFilePath, string $fncFileName[, string $fncLabel = '' ][, string $fncColSize = 'm6
s12' ][, string $fncRefresh = '' ][, string $fncAccept =
'accept="image/*"' ]) : html
Example calling method:
$pgHtm .= wtkFormFile('pets','FilePath','/imgs/pets/','NewFileName','Pet Photo','m4 s12');
Parameters
- $fncTable : string
-
data table
- $fncColPath : string
-
stuff
- $fncFilePath : string
- $fncFileName : string
-
stuff
- $fncLabel : string = ''
-
optionally passed, if not then uses $fncColName
- $fncColSize : string = 'm6 s12'
-
defaults to 'm6 s12'
- $fncRefresh : string = ''
-
defaults to '' blank
- $fncAccept : string = 'accept="image/*"'
-
defaults to 'accept="image/*"'
Return values
html —returns surrounding HTML for input type="file"
wtkUpdateBtns()
Create cancel, save and possibly copy buttons. If read-only then instead shows a "Return" button.
wtkUpdateBtns(string $fncReturnTo[, string $fncForm = 'wtkForm' ][, string $fncSave = '/wtk/lib/Save' ][, string $fncCopy = '' ]) : html
Example calling method:
$pgHtm .= wtkUpdateBtns('petList');
Parameters
- $fncReturnTo : string
-
which PHP page to return to; do not need to include '.php'
- $fncForm : string = 'wtkForm'
-
defaults to 'wtkForm'
- $fncSave : string = '/wtk/lib/Save'
-
defaults to '/wtk/lib/Save'
- $fncCopy : string = ''
-
defaults to '' blank; if not blank then shows Copy button
Return values
html —returns html with update and cancel buttons
wtkPageList()
By passing a SQL SELECT this will build a nice looking page.
wtkPageList(string $fncSQL, array<string|int,
mixed> $fncSqlFilter[, string $fncLink = '' ][, string $fnc2Rows = 'N' ]) : html
Expects SQL SELECT to contain: UID, Header, TopRight, Description and optionally Row2Left, Row2Right
if $fncLink then must have UID
in the SELECT result set.
Example calling method:
$pgSQL =<<<SQLVAR
SELECT e.UID
,
DATE_FORMAT(e.AddDate
, '$gloSqlDateTime') AS TopRight
,
e.Subject
AS Header
,
REPLACE(e.EmailBody
,' href="', ' href="#" title="') AS Description
FROM wtkEmailsSent e
WHERE e.SendToUserUID
= ?
ORDER BY e.UID
DESC
SQLVAR;
$pgHtm = '
$pgHtm .= '
$pgHtm .= wtkPageList($pgSQL, [$gloUserUID], '/wtk/messageDetail');
$pgHtm = wtkReplace($pgHtm, 'There is no data available.','no messages yet');
$pgHtm .= '
$pgHtm .= '
Parameters
- $fncSQL : string
-
SELECT query
- $fncSqlFilter : array<string|int, mixed>
-
array that has PDO names of fields and their values
- $fncLink : string = ''
-
defaults to '' blank, if passed then ajaxGo link is created
- $fnc2Rows : string = 'N'
-
defaults to 'N'; if 'Y' passed then 2nd row shows
Return values
html —returns html with update and cancel buttons
wtkChatList()
Create list of chat data.
wtkChatList(string $fncSQL, array<string|int,
mixed> $fncSqlFilter) : html
Example calling method:
$pgSQL =<<<SQLVAR
SELECT c.UID
, c.Message
, c.SendByUserUID
,
DATE_FORMAT(c.AddDate
, '$gloSqlDate') AS AddDate
FROM wtkChat
c
WHERE (c.SendToUserUID
= :ToUserUID
AND c.SendByUserUID
= :UserUID)
OR (c.SendByUserUID
= :ToUser2UID
AND c.SendToUserUID
= :User2UID)
ORDER BY c.UID
ASC
SQLVAR;
$pgSQL = wtkSqlPrep($pgSQL);
$pgSqlFilter = array (
'ToUserUID' => $gloId,
'UserUID' => $gloUserUID,
'ToUser2UID' => $gloId,
'User2UID' => $gloUserUID
);
$pgChat = wtkChatList($pgSQL, $pgSqlFilter);
Parameters
- $fncSQL : string
-
SELECT query
- $fncSqlFilter : array<string|int, mixed>
-
array that has PDO names of fields and their values
Return values
html —returns html with list of a chat discussion
wtkSaveChat()
This creates HTML with saveChat JavaScript function. Used at bottom of chatEdit.php.
wtkSaveChat(int $fncToUserUID) : html
Parameters
- $fncToUserUID : int
-
the
UID
of the wtkUsers you want to chat with
Return values
html —returns html with Javascript:saveChat($fncToUserUID)
wtkForumList()
Create list of Forum data.
wtkForumList(string $fncSQL, array<string|int,
mixed> $fncSqlFilter) : html
Example calling method:
$pgSQL =<<<SQLVAR
SELECT f.UID
, f.ForumMsg
, u.FilePath
, u.NewFileName
,
CONCAT(u.FirstName
, ' ', COALESCE(u.LastName
,'')) AS UserName
,
DATE_FORMAT(f.AddDate
, '$gloSqlDateTime') AS AddDate
FROM wtkForumMsgs
f
INNER JOIN wtkUsers
u ON u.UID
= f.UserUID
WHERE f.ForumUID
= ?
ORDER BY f.UID
ASC
SQLVAR;
$pgForum = wtkForumList($pgSQL, [$gloId]);
Parameters
- $fncSQL : string
-
SELECT query
- $fncSqlFilter : array<string|int, mixed>
-
array that has PDO names of fields and their values
Return values
html —returns html with list of a chat discussion
wtkSendNoteForum()
This creates HTML with sendNote JavaScript function. Used at bottom of forumEdit.php.
wtkSendNoteForum(int $fncParentUID[, string $fncVer = '' ]) : html
Parameters
- $fncParentUID : int
-
the
UID
of the wtkForum table - $fncVer : string = ''
-
defaults to ''; only needed if more than one needed on a page
Return values
html —returns html with Javascript:sendNote($fncToUserUID)