<?php require_once($_SERVER['DOCUMENT_ROOT']."/libraries/php/classes/config.php"); //Basic configuration file. ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>UK - Environmental Health And Safety</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="libraries/css/style.css" type="text/css" />
<link rel="stylesheet" href="libraries/css/print.css" type="text/css" media="print" />
</head>
<body>
<div id="container">
<div id="mainNavigation">
<?php include($cDocroot."libraries/includes/inc_mainnav_0001.php"); ?>
</div>
<div id="subContainer">
<?php include("a_banner_0001.php"); ?>
<div id="subNavigation">
<?php include("a_subnav_0001.php"); ?>
</div>
<div id="content">
<p class="header">Welcome</p>
<p>Welcome to the University of Kentucky's Environmental Health And Safety Division. UK safety begins with you!</p>
<p class="sub_header">OUR MISSION</p>
<p>The EHS Division supports the University's teaching, research, and public service mission by promoting a safe, healthful, clean, and accessible campus environment.</p>
<p>The Division's programs are intended to provide safe and healthy conditions for work and study, protect the environment, and comply with applicable laws and regulations. The Division serves the University community by providing technical services, education and training, periodic audits, and compliance assistance.</p>
<?php include($cDocroot."libraries/includes/inc_updates_0001.php"); ?>
</div>
</div>
<div id="sidePanel">
<?php include($cDocroot."a_sidepanel_0001.php"); ?>
</div>
<div id="footer">
<?php include($cDocroot."libraries/includes/inc_footer_0001.php"); ?>
</div>
</div>
<div id="footerPad">
<?php include($cDocroot."libraries/includes/inc_footerpad_0001.php"); ?>
</div>
</body>
</html>
Month: May 2013
Class – Utility
<?php
class class_utility {
/*
Utility
Damon Vaughn Caskey
2013-01-09
Miscellaneous utility functions.
*/
public function utl_color_alternation($i, $cColorEven="#DDDDFF", $cColorOdd="#CECEFF")
{
/*
back_alt_0001 - https://www.caskeys.com/dc/?p=4900
Damon Vaughn Caskey
2012-10-18
Output alternating background colors for even/odd rows in tables or other types of layouts.
$i: Current row/location/count.
$cColorEven: Color to output if $i is an even number.
$cColorEven: Color to output if $i is an odd number.
*/
if($i%2) //Even number?
{
return $cColorEven; //Return even color.
}
else
{
return $cColorOdd; //Return odd color.
}
}
public function utl_get_get($cID, $cDefault=NULL)
{
/*
utl_get_get
Damon Vaughn Caskey
2013-01-01
Wrapper to obtain get value.
$cID: Index.
$cDefault: Default on not set.
*/
return $this->utl_validate_isset($_GET[$cID], $cDefault);
}
public function utl_get_post($cID, $cDefault=NULL)
{
/*
utl_get_post
Damon Vaughn Caskey
2013-01-01
Wrapper to obtain post value.
$cID: Index.
$cDefault: Default on not set.
*/
//echo $_POST[$cID];
return $this->utl_validate_isset($_POST[$cID], $cDefault);
}
public function utl_get_server_value($cID, $cDefault=NULL)
{
/*
utl_get_server_value
Damon Vaughn Caskey
2013-01-01
Wrapper to obtain server value.
$cID: Index.
$cDefault: Default on not set.
*/
return $this->utl_validate_isset($_SERVER[$cID], $cDefault);
}
public function utl_str_to_array($cList=NULL, $cDel=",")
{
/*
str_to_array
Damon Vaughn Caskey
2013-01-09
Break string into indexed array with no spaces.
$cList: List array to break up.
$cDel: Delimiter.
*/
/*
If list is populated remove spaces and break into array.
*/
if($cList) //List populated?
{
$cList = str_replace (" ", "", $cList); //Remove spaces.
$cList = explode($cDel, $cList); //Break into array.
}
/*
Return end result.
*/
return $cList;
}
public function utl_redirect($cURL=NULL)
{
/*
utl_redirect
Damon Vaughn Caskey
2013-01-09
Send header that redirects client to new page.
$cURL: Target address.
*/
/*
If headers haven't been sent, redirect user to an error page. Otherwise we'll just have to die and settle for a plain text message.
*/
if(headers_sent())
{
/*
Good coding will always avoid attempting to resend headers, but let's make sure to catch them here before PHP throws a nasty error.
*/
}
else
{
header('Location: '.$cURL);
return TRUE;
}
/*
Return end result.
*/
return FALSE;
}
public function utl_validate_email(&$cValue, $cDefault=NULL)
{
/*
utl_validate_email
Damon Vaughn Caskey
2013_01_01
Validate email variable.
$cValue: Email value.
$cDefault: Default on fail.
*/
if(filter_var($cValue, FILTER_VALIDATE_EMAIL))
{
list($user,$domaine)=explode("@", $cValue, 2);
if(!checkdnsrr($domaine, "MX")&& !checkdnsrr($domaine, "A"))
{
/*
Bad domain.
*/
$cValue = FALSE;
}
else
{
//Domain OK.
}
}
else
{
/*
Bad address.
*/
$cValue = FALSE;
}
if($cValue == FALSE)
{
$cValue = $cDefault;
}
return $cValue;
}
public function utl_validate_ip(&$cValue, $cDefault=NULL)
{
/*
utl_validate_ip
Damon Vaughn Caskey
2013-01-01
Validate ip variable.
$cValue: ip value.
$cDefault: Default on fail.
*/
$cValue = filter_var($cValue, FILTER_VALIDATE_IP);
if($cValue == FALSE)
{
$cValue = $cDefault;
}
return $cValue;
}
public function utl_validate_isset(&$cValue, $cDefault=NULL)
{
/*
utl_validate_isset
Damon Vaughn Caskey
2013-01-01
Return default if variable is not set.
$cValue: Value.
$cDefault: Default on not set.
*/
if(!isset($cValue))
{
$cValue = $cDefault;
}
return $cValue;
}
public function utl_if_exists($cValue, $cValPrefix=NULL, $cValCadence=NULL, $cAlt=NULL)
{
/*
utl_
Damon Vaughn Caskey
2013-01-01
Return self if self has a value, or $cAlt if $cValue is empty or null. Reduces need to retype and
potentiality mix up variable names or array keys twice in common "echo <X> if it has a value" situations.
Preconditions:
$cValue: Value to test and return if it exists.
$cValPrefix: Add to front of $cValue on return.
$cValCadence: Add to end of $cValue on return.
$cAlt: Value to return if $cValue is NULL.
*/
/* Vaiables */
$cReturn = $cAlt; //Final value to return.
/* Value exists? */
if($cValue)
{
/* Tack on additions and return value. */
$cReturn = $cValPrefix.$cValue.$cValCadence;
}
return $cReturn;
}
}
?>
Class – Training
<?php
class class_training
{
/*
constants
Damon Vaughn Caskey
2012_12_18
Global constants.
*/
private $oDB = NULL; //Class object: Database.
private $oDBA = NULL; //Class object: Database (answers).
private $oSes = NULL; //Class object: Session.
private $oUtl = NULL; //Class object: Filter.
private $oErr = NULL; //Class object: Error.
private $oFrm = NULL; //Class object: Forms.
private $cQuery = NULL;
private $cParams = NULL;
private $cTVarsTD = NULL; //Class variable ID array.
private $cTVars = NULL;
function __construct($oDep)
{
/*
Constructor
Damon Vaughn Caskey
2012_12_29
Class constructor.
*/
/* Import object dependencies. */
$this->oSes = $oDep['Ses'];
$this->oDB = $oDep['DB'];
$this->oFrm = $oDep['Frm'];
$this->oFil = $oDep['Fil'];
$this->oErr = $oDep['Err'];
$this->oDBA = new class_db(array('Utl' => $oDep['Utl'], 'Err' => $oDep['Err']));
/* Verify object dependencies. */
if(!$this->oDBA) trigger_error("Missing object dependency: Database (Ans).", E_USER_ERROR);
if(!$this->oDB) trigger_error("Missing object dependency: Database.", E_USER_ERROR);
if(!$this->oSes) trigger_error("Missing object dependency: Session.", E_USER_ERROR);
if(!$this->oFrm) trigger_error("Missing object dependency: Forms.", E_USER_ERROR);
if(!$this->oFil) trigger_error("Missing object dependency: Filter.", E_USER_ERROR);
if(!$this->oErr) trigger_error("Missing object dependency: Error.", E_USER_ERROR);
}
public function training_quiz_grade($cQuizID)
{
$cQuestionCount = NULL;
$cQuestionRight = NULL;
$val = NULL;
$iQueCnt = 0;
$cResponse = NULL;
$cQuizGradeStr = NULL;
$ans = 0;
$cPercentage = 0;
$cQuestionCount = $this->oSes->session_get('quiz_question_count');
$cQuestionRight = $this->oSes->session_get('quiz_answer_right');
$cQuestionRight = str_replace (" ", "", $cQuestionRight); //Remove spaces.
$cQuestionRight = explode(",", $cQuestionRight); //Break into array.
foreach($cQuestionRight as $val) //Loop array collection.
{
/* Increment counter. */
$iQueCnt++;
/* Get question response */
$cResponse = $this->oFil->utl_get_post("Q".$iQueCnt);
$cQuizGradeStr.= "Question ".$iQueCnt." response: ";
if (!$cResponse)
{
$cQuizGradeStr.= "No answer.<br/>";
}
else
{
if ($cResponse == $val)
{
$cQuizGradeStr.= $cResponse." - Correct.<br/>";
$ans++;
}
else
{
$cQuizGradeStr.= $cResponse." - Incorrect.<br/>";
}
}
}
$cPercentage = round(($ans / $iQueCnt)*100);
$cQuizGradeStr.= "<br />You answered ".$ans. " of ".$iQueCnt. " correctly (".$cPercentage."%).<br /><br />";
$array["ans"] = $ans;
$array["percentage"] = $cPercentage;
$array["text"] = $cQuizGradeStr;
return $array;
}
public function training_quiz_questions($cQuizID, $cOrder=NULL, $cQuantity=NULL)
{
/*
training_quiz_questions
Damon V. Caskey
2011_11_29
~2012_12_23: DB Class.
Populate question list and possible answers from database from Quiz ID.
$cQuizID: Quiz ID to get quiz questions from.
*/
$cQuizStr = NULL; //Final output string to be placed into page.
$QuestionID = NULL; //Current question ID in question loop.
$cQuestionCount = 0; //Include ID into question header.
$cQuestionRight = NULL;
if(!$cOrder)
{
$cOrder = NULL; //Order in table.
}
else if($cOrder == 1)
{
$cOrder = "ORDER BY question_order"; //User specified order.
}
else if($cOrder == 2)
{
$cOrder = "ORDER BY newid()"; //Random order
}
$cQuantity = $cQuantity ? "TOP ".$cQuantity : NULL;
/* Construct questions query string. */
$this->cQuery = "SELECT "
.$cQuantity
." *
FROM tbl_class_train_questions
WHERE fk_tbl_class_train_parameters_guid_id = ? "
.$cOrder;
/* Apply parameters. */
$this->cParams = array(&$cQuizID);
/* Execute questions query. */
$this->oDB->db_basic_select($this->cQuery, $this->cParams);
/* Construct answers query string. */
$this->cQuery = "SELECT
*
FROM tbl_class_train_answers
WHERE fk_tbl_class_train_questions_guid_id = ?
ORDER BY answer_order, value";
/* Apply parameters. */
$this->cParams = array(&$QuestionID);
while($this->oDB->db_line())
{
$QuestionID = $this->oDB->cDBLine["guid_id"];
/* Get answer set matching current question ID. */
$this->cParams = array(&$QuestionID);
/*Record answer array. First element will be blank. ( ", A, C, B, A, etc.") */
if($cQuestionRight)
{
$cQuestionRight .= ", " .$this->oDB->cDBLine["right_answer"];
}
else
{
$cQuestionRight = $this->oDB->cDBLine["right_answer"];
}
/* Build question string. */
$cQuizStr .="<p><span class='TrainQuestionHeader'>"
."Question ".++$cQuestionCount
."</span><br />"
."<span class='TrainQuestionText'>"
.$this->oDB->cDBLine["question"]
."</span><br />";
/* Execute answers query. */
$this->oDBA->db_basic_select($this->cQuery, $this->cParams);
while ($this->oDBA->db_line())
{
$cQuizStr .= "<input type='radio' name='Q"
.$cQuestionCount
."' value='"
.$this->oDBA->cDBLine["value"]
."' />"
."<span class='TrainQuestionAnswerHeader'>"
.$this->oDBA->cDBLine["value"]
.")</span> "
."<span class='TrainQuestionAnswerText'>"
.$this->oDBA->cDBLine["text"]
."</span><br />";
}
}
if(!$cQuizStr)
{
$cQuizStr = "<h2><span class='alert'>No questions available.</span></h2>";
}
$this->oSes->session_set('quiz_answer_right', $cQuestionRight);
$this->oSes->session_set('quiz_question_count', $cQuestionCount);
return $cQuizStr;
}
public function training_quiz_questions_setup($cQuizID, $cOrder=NULL, $cQuantity=NULL)
{
/*
class_quiz_questions_0003
Damon V. Caskey
2012_10_04
Create form to modifiy questions and answers.
$cQuizID: Quiz ID to get quiz questions from.
*/
$cQuizStr = NULL; //Final output string to be placed into page.
$cQuery = NULL; //Query string.
$cParams = NULL; //Parameter array.
$oDBA = NULL; //Database class object (answers).
$QuestionID = NULL; //Current question ID in question loop.
$cOrderLst = NULL; //Droplist values for question order.
$cAnswerValLst = NULL;
/* Initialize database class objects. */
$oDBA = new class_db(array("Utl" => $oUtl, "Err" => $oErr)); //Database class object (Answers).
/* Prepare answer dropdown list values */
$cAnswerValLst = array_merge(array("-" => "-"), range('A', 'Z'));
/* Construct questions query. */
$cQuery = "SELECT "
.$cQuantity
." *
FROM tbl_class_train_questions
WHERE fk_tbl_class_train_parameters_guid_id = ?
ORDER BY question_order";
/* Apply question parameters. */
$cParams = array(&$cQuizID);
/* Execute questions query */
$oDB->db_basic_select($cQuery, $cParams);
$cQuery = "SELECT
*
FROM tbl_class_train_answers
WHERE fk_tbl_class_train_questions_guid_id = ?
ORDER BY answer_order, value";
/* Apply answer parameters. */
$cParams = array(&$QuestionID);
/* Prepare question order dropdown list values */
$cOrderLst = range(1, $oDB->iDBRowCount);
while($oDB->db_line())
{
$QuestionID = $oDB->cDBLine["guid_id"];
$cAnswers = NULL;
$oDBA->db_basic_select($cQuery, $cParams);
while($oDBA->db_line())
{
$cAnswers .= "
<form name='frm_answer_update' id='frm_answer_update_".$oDBA->cDBLine["guid_id"]."' method='post' action='".$_SERVER['PHP_SELF']."#a_question_".$oDB->cDBLine["question_order"]."'>
<input type='hidden' name='EditMode' value='1' />
<input type='hidden' name='id_guid' value='".$oDBA->cDBLine["guid_id"]."' />
<table width='100%' border='0' cellspacing='0' cellpadding='2' bgcolor='#DDDDFF'>
<tr>
<td width='10%'>
<select name='frm_lst_answer_val' id='frm_lst_answer_val_".$oDBA->cDBLine["guid_id"]."'>"
.$this->oFrm->forms_select_options($cAnswerValLst, NULL, $oDBA->cDBLine["value"], FALSE).
"</select>
</td>
<td width='70%'><textarea name='frm_ta_answer_text' id='frm_ta_answer_text_".$oDBA->cDBLine["guid_id"]."' cols='35' rows='1'>".$oDBA->cDBLine["text"]."</textarea></td>
<td width='10%' align='center'><input type='image' src='/media/image/icon_save_0001.png' name='frm_btn_ans_save' id='frm_btn_save_ans_".$oDBA->cDBLine["guid_id"]."' value='Save' /></td>
<td width='10%' align='center'><input type='image' src='/media/image/icon_delete_0001.png' name='frm_btn_ans_delete' id='frm_btn_delete_ans_".$oDBA->cDBLine["guid_id"]."' value='Delete' /></td>
</tr>
</table>
</form><br />";
}
$cAnswers .= "<div id='new_answer_".$oDB->cDBLine["guid_id"]."'>
<form name='frm_answer_new' id='frm_answer_new_".$oDB->cDBLine["guid_id"]."' method='post' action='".$_SERVER['PHP_SELF']."#a_question_".$oDB->cDBLine["question_order"]."'>
<input type='hidden' name='EditMode' value='1' />
<input type='hidden' name='id_guid' value='".$oDB->cDBLine["guid_id"]."' />
<table width='100%' border='0' cellspacing='0' cellpadding='2' bgcolor='#DDDDFF'>
<tr>
<td width='10%'>
<select name='frm_lst_answer_val' id='frm_lst_answer_val_".$oDB->cDBLine["guid_id"]."' >"
.$this->oFrm->forms_select_options($cAnswerValLst, NULL, "-", FALSE).
"</select>
</td>
<td width='70%'><textarea name='frm_ta_answer_text' id='frm_ta_answer_text_".$oDB->cDBLine["guid_id"]."' cols='35' rows='1'></textarea></td>
<td width='20%' align='center'><input type='image' src='/media/image/icon_save_0001.png' name='frm_btn_ans_add' id='frm_btn_ans_add_".$oDB->cDBLine["guid_id"]."' value='Add' /></td>
</tr>
</table>
</form></div>";
$cQuizStr .= "
<br />
<div id='question_".$oDB->cDBLine["guid_id"]."'>
<table width='100%' border='0' cellspacing='0' cellpadding='0' bgcolor='#F0F0FF'>
<tr>
<td>
<a name='a_question_".$oDB->cDBLine["question_order"]."' id='a_question_".$oDB->cDBLine["question_order"]."'></a>
<form name='frm_question_update' id='frm_question_update_".$oDB->cDBLine["guid_id"]."' method='post' action='".$_SERVER['PHP_SELF']."#a_question_".$oDB->cDBLine["question_order"]."'>
<input type='hidden' name='EditMode' value='1' />
<input type='hidden' name='id_guid' value='".$oDB->cDBLine["guid_id"]."' />
<table width='100%' border='0' cellspacing='0' cellpadding='1' >
<tr>
<th colspan='2'><table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='77%' align='left'>Question
<select name='frm_lst_order' id='frm_lst_order_".$oDB->cDBLine["guid_id"]."'>"
.$this->oFrm->forms_select_options($cOrderLst, NULL, $oDB->cDBLine["question_order"], FALSE).
"</select>
</td>
<td width='11%'><input type='submit' name='frm_btn_que_save' id='frm_btn_que_save_".$oDB->cDBLine["guid_id"]."' value='Save' /></td>
<td width='12%'><input type='submit' name='frm_btn_que_delete' id='frm_btn_que_delete_".$oDB->cDBLine["guid_id"]."' value='Delete' onclick='return confirmSubmit()' /></td>
</tr>
</table></th>
</tr>
<tr>
<td><label for='frm_ta_question_val'>Question Text</label></td>
<td><textarea name='frm_ta_question_val' id='frm_ta_question_".$oDB->cDBLine["guid_id"]."' cols='45' rows='5'>".$oDB->cDBLine["question"]."</textarea></td>
</tr>
<tr>
<td><label for='frm_lst_right_answer'>Correct Response</label></td>
<td><select name='frm_lst_right_answer' id='frm_lst_right_answer_".$oDB->cDBLine["guid_id"]."' >"
.$this->oFrm->forms_select_options($cAnswerValLst, NULL, $oDB->cDBLine["right_answer"], FALSE).
"</select></td>
</tr>
</table>
</form><br />"
."<div id='answers_".$oDB->cDBLine["guid_id"]."'>"
.$cAnswers
."</div></td>
</tr>
</table></div>";
}
$cOrderLst[$oDB->iDBRowCount+1] = $oDB->iDBRowCount+1; //Add one more to the order list.
$cQuizStr .= "<br />
<div id='question_new'>
<table width='100%' border='0' cellspacing='0' cellpadding='0' bgcolor='#F0F0FF'>
<tr>
<td>
<a name='a_question_".($oDB->iDBRowCount+1)."' id='a_question_".($oDB->iDBRowCount+1)."'></a>
<form name='frm_question_new' id='frm_question_new' method='post' action='".$_SERVER['PHP_SELF']."#a_question_".($oDB->iDBRowCount+1)."'>
<input type='hidden' name='trigger_type' value='question_add' />
<input type='hidden' name='id_guid' value='".$oDBA->cDBLine["guid_id"]."' />
<input type='hidden' name='EditMode' value='1' />
<table width='100%' border='0' cellspacing='0' cellpadding='1' >
<tr>
<th colspan='2'><table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='77%' align='left'>Question
<select name='frm_lst_order' id='frm_lst_order_".$oDB->cDBLine["guid_id"]."'>"
.$this->oFrm->forms_select_options($cOrderLst, NULL, ($oDB->iDBRowCount+1), FALSE).
"</select>
</td>
<td width='11%'><input type='submit' name='frm_btn_que_add' id='frm_btn_que_add' value='Add' /></td>
</tr>
</table></th>
</tr>
<tr>
<td><label for='frm_ta_question_val'>Question Text</label></td>
<td><textarea name='frm_ta_question_val' id='frm_ta_question_val' cols='45' rows='5'></textarea></td>
</tr>
<tr>
<td><label for='frm_lst_right_answer'>Correct Response</label></td>
<td><select name='frm_lst_right_answer' id='frm_lst_right_answer' >"
.$this->oFrm->forms_select_options($cAnswerValLst, NULL, NULL, FALSE).
"</select></td>
</tr>
</table>
</form>
</td>
</tr>
</table></div>";
if(!$cQuizStr)
{
$cQuizStr = "<h2><span class='alert'>No questions available.</span></h2>";
}
return $cQuizStr;
}
public function training_class_record($cTrainingParams)
{
/*
training_class_record_0001
Damon Vaughn Caskey
2013-03-27 (Converted to function class_record_0001 include)
Inserts user variables into class participant database.
*/
$cQuery = NULL; //Query string.
$cParams = NULL; //Parameter array.
$cClassID = NULL; //Class ID.
$p_id = NULL; //Participant ID.
$listing_id = NULL; //Class listing ID.
/* Build query string. */
$cQuery ="MERGE INTO tbl_class_participant
USING
(SELECT ? AS Search_Col) AS SRC
ON
tbl_class_participant.account = SRC.Search_Col
WHEN MATCHED THEN
UPDATE SET
name_l = ?,
name_f = ?,
room = ?,
status = ?,
phone = ?,
department = ?,
supervisor_name_f = ?,
supervisor_name_l = ?
WHEN NOT MATCHED THEN
INSERT (account, name_l, name_f, room, status, phone, department, supervisor_name_f, supervisor_name_l)
VALUES (SRC.Search_Col, ?, ?, ?, ?, ?, ?, ?, ?)
OUTPUT INSERTED.id_int;";
/* Apply parameters. */
$cParams = array(&$cTrainingParams['account'],
&$cTrainingParams['name_l'],
&$cTrainingParams['name_f'],
&$cTrainingParams['room'],
&$cTrainingParams['status'],
&$cTrainingParams['phone'],
&$cTrainingParams['department'],
&$cTrainingParams['supervisor_name_f'],
&$cTrainingParams['supervisor_name_l'],
&$cTrainingParams['name_l'],
&$cTrainingParams['name_f'],
&$cTrainingParams['room'],
&$cTrainingParams['status'],
&$cTrainingParams['phone'],
&$cTrainingParams['department'],
&$cTrainingParams['supervisor_name_f'],
&$cTrainingParams['supervisor_name_l']);
/* Execute query. */
$this->oDB->db_basic_action($cQuery, $cParams, TRUE);
/* Get ID of created/updated record. */
$p_id = $this->oDB->cDBLine["id_int"];
/* User demographics have now been found or inserted. Now we will deal with class type, instructor and time. */
$cQuery = "INSERT INTO tbl_class
(class_type,
trainer_id,
class_date)
OUTPUT INSERTED.class_id
VALUES (?, ?, ?)";
$cParams = array(&$cTrainingParams['class'],
&$cTrainingParams['trainer'],
&$cTrainingParams['taken']);
/* Execute query. */
$this->oDB->db_basic_action($cQuery, $cParams, TRUE);
/* Get ID of new record. */
$cClassID = $this->oDB->cDBLine["class_id"];
/* Insert newly created id and participant id to class listing table. */
$cQuery = "INSERT INTO tbl_class_listing
(participant_id,
class_id)
OUTPUT INSERTED.id_int
VALUES (?, ?)";
$cParams = array(&$p_id,
&$cClassID);
/* Execute query. */
$this->oDB->db_basic_action($cQuery, $cParams, TRUE);
/* Get ID of new record. */
return $this->oDB->cDBLine["id_int"];
}
public function training_vars_get()
{
//foreach ($this->cClassVars as $key => $val)
//{
// $this
//}
}
}
Class – Tables
<?php
class class_tables {
/*
Tables
Damon Vaughn Caskey
2013-03-21
Miscellaneous table functions.
*/
public $cMarkup = NULL; //Resulting markup output. Typically a table.
private $oUtl = NULL; //Utility class object.
function __construct($oDep)
{
/*
Constructor
Damon Vaughn Caskey
2013_01_21
Class constructor.
*/
/* Import object dependencies. */
$this->oUtl = $oDep['Utl'];
/* Verify object dependencies. */
if(!$this->oUtl) trigger_error("Missing object dependency: Utility.", E_USER_ERROR);
}
public function tables_db_output($oDB, $bRowCount = TRUE, $cFieldSkip = NULL, $cAuxLink = array("Header" => NULL, "Link" => NULL, "Target" => "_blank", "Text" => "Go"), $cAuxLinkFields = NULL, $cRowStyle = NULL)
{
/*
tables_db_output
Damon Vaughn Caskey
2013-03-20
Create complete table markup from database query.
Preconditions:
Executed database query.
$oDB: Object with object variables populated by query.
$bRowCount: True = Display a row count preceding table.
$cFieldSkip['<fieldname>', ...]: Array of fields from query to skip when creating table.
$cAuxLink['Link', 'Text', 'Target']: Adds action link to end of table.
Link: Page name.
Target: Page target (_new, _blank, etc.)
Text: Text to display.
$cAuxLinkFields['<fieldname>', ...]: Fields to pass as part of action link.
$cRowStyle[even, odd]: Array to override default alternate row style.
Postconditions:
Populate and return $cMarkup with table markup string.
*/
$i = NULL; //Working counter.
$iRowCount = NULL; //Count of records retrieved by query.
$cOutput = NULL; //Output string.
$cFieldMetadata = NULL; //Metadata collection (field name, type, etc.) for database columns.
$cFieldMetaDataName = NULL; //Individual item name from metadata colelction.
$cFieldMetaDataValue = NULL; //Individual item value from metadata collection.
$iFields = NULL; //Field counter/index.
$cFieldName = NULL; //Field name array.
$cName = NULL; //Table markup write in: Field name.
$cValue = NULL; //Table markup write in: Field value.
$cLink = NULL; //Table markup write in: Action link.
/* Add extra markup if cAuxLink has a value, otherwise leave NULL. " */
if($cAuxLink["Link"] != NULL)
{
$cAuxLink["Link"] .= "?";
$cAuxLink["Header"] = $cAuxLink["Header"] != NULL ? "<th>".$cAuxLink["Header"]."</th>" : "<th>Action</th>";
}
if($bRowCount)
{
$iRowCount = $oDB->iDBRowCount;
$cOutput .= '<span class="row_count">' .$iRowCount. ' records found.</span><br/><br/>';
}
$cOutput .= '<div title="Table" class="overflow"><table border="0" cellpadding="5" cellspacing="0" bgcolor="#CCCCCC"><tr>';
/* Zero counter */
$i = 0;
/* Loop each column in query result. */
foreach($oDB->cDBMeta as $cFieldMetadata)
{
/* Loop coloumn metadata collection. */
foreach($cFieldMetadata as $cFieldMetaDataName => $cFieldMetaDataValue)
{
/* Column name? */
if($cFieldMetaDataName == 'Name')
{
/* Check field skip array before using this field name */
if(!in_array($cFieldMetaDataValue, $cFieldSkip))
{
/* Output to table header markup and populate name array. */
$cOutput .= "<th>".$cFieldMetaDataValue."</th>"; //Populate table header markup.
}
$cFieldName[$i] = $cFieldMetaDataValue; //Populate Name array.
/* Increment field count. */
$iFields++;
}
}
/* Increment counter. */
$i++;
}
$cOutput .= $cAuxLink["Header"];
/* Output query results as table. */
while($oDB->db_line(SQLSRV_FETCH_NUMERIC))
{
$cLink = $cAuxLink["Link"];
/* Increment line counter */
$iLine++;
/* Insert table row and style. */
$cOutput .= "<tr bgcolor='".$this->oUtl->utl_color_alternation($iLine)."'>";
for ($i = 0; $i < $iFields; $i++)
{
$cName = $cFieldName[$i];
$cValue = $oDB->cDBLine[$i];
/* Check field skip array before using this field. */
if(!in_array($cName, $cFieldSkip))
{
$cOutput .= "<td>".$cValue."</td>";
}
if($cLink != NULL)
{
if(in_array($cName, $cAuxLinkFields))
{
$cLink .= $cFieldName[$i]."=".$cValue."&";
}
}
}
if($cLink != NULL)
{
$cOutput .= '<td><a href="'.$cLink.'" target="'.$cAuxLink["Target"].'">'.$cAuxLink["Text"].'</a></td>';
}
}
$cOutput .= "</table><br/><br/></div>";
$this->cMarkup = $cOutput;
return $this->cMarkup;
}
}
?>
Class – Sessions
<?php
class class_sessions implements SessionHandlerInterface
{
/*
class_sessions
Damon Vaughn Caskey
2012_12_10
Override PHP's default session handling to store data in an MSSQL table.
*/
const c_iLife = 1440; //Default session time out (in seconds)
private $oDB = NULL; //Databse class object.
private $iLife = NULL; //Session time out.
function __construct($oDep, $iLife=self::c_iLife)
{
/*
Constructor
Damon Vaughn Caskey
2012_12_29
Class constructor.
*/
/* Set class vars. */
$this->iLife = $iLife; //Session time out.
/* Import object dependencies. */
$this->oDB = $oDep['DB'];
/* Verify object dependencies. */
if(!$this->oDB) trigger_error("Missing object dependency: Database.", E_USER_ERROR);
}
public function session_set($cID, $cValue=NULL)
{
/*
session_set
Damon Vaughn Caskey
2012_12_23
Wrapper to set value of a $_SESSION[] variable.
$cID: Session variable name/id.
$cValue: Value to set.
*/
$_SESSION[$cID] = $cValue;
}
public function session_get($cID)
{
/*
session_get
Damon Vaughn Caskey
2012_12_23
Wrapper to aquire value in a $_SESSION[] variable.
$cID: Session variable name/id.
*/
$cValue = NULL; //Value to return.
/* Get session value if any */
if(isset($_SESSION[$cID]))
{
$cValue = $_SESSION[$cID];
}
/* Return value. */
return $cValue;
}
public function open($savePath, $sessionName)
{
/*
open
Damon Vaughn Caskey
2012_12_10
Set database class object for other session functions. Called by PHP to open session.
$savePath: Path to locate session file. Unused.
$sessionName: Name of session file. Unused.
*/
/* Return TRUE. */
return true;
}
public function close()
{
/*
close
Damon Vaughn Caskey
2012_12_10
Filler; function is called by PHP to close session.
*/
/* Return TRUE. */
return true;
}
public function read($cID)
{
/*
read
Damon Vaughn Caskey
2012_12_10
Locate and read session data from database.
$cID = Session ID.
*/
$cData = NULL; //Final output.
$cQuery = NULL; //Query string.
$cTime = date(constants::c_cDateF); //Current time.
$cParams = NULL; //Parameter array.
/* Build query string. */
$cQuery = "SELECT session_data
FROM tbl_php_sessions
WHERE
session_id = ?
AND
expire > ?";
/* Apply parameters. */
$cParams = array(&$cID, &$cTime);
/* Execute query. */
$this->oDB->db_basic_select($cQuery, $cParams);
/* Get result and pass to local var(s). */
if($this->oDB->rDBResult)
{
/* Set line array. */
$this->oDB->db_line();
/* Get session data. */
$cData = $this->oDB->cDBLine['session_data'];
}
/* Return results. */
return $cData;
}
public function write($cID, $cData)
{
/*
write
Damon Vaughn Caskey
2012_12_10
Update or insert session data. Note that only ID, Expire, and Session Data are
required. Other data is to aid in debugging.
$cID = Session ID.
$cData = Session data.
*/
$cQuery = NULL; //Query string.
$cTime = NULL; //Current time.
$cLoc = $_SERVER["PHP_SELF"]; //Current file.
$cIP = $_SERVER['REMOTE_ADDR']; //Client IP address.
/* Calculate epirire time. */
$cTime = date(constants::c_cDateF, time()+$this->iLife);
/* Ensure IP string is <= 15. Anything over is a MAC or unexpected (and useless) value. */
$cIP = substr($cIP, 0, 15);
/* Build query string. */
$cQuery ="MERGE INTO tbl_php_sessions
USING
(SELECT ? AS Search_Col) AS SRC
ON
tbl_php_sessions.session_id = SRC.Search_Col
WHEN MATCHED THEN
UPDATE SET
session_data = ?,
expire = ?,
source = ?,
ip = ?
WHEN NOT MATCHED THEN
INSERT (session_id, session_data, expire, source, ip)
VALUES (SRC.Search_Col, ?, ?, ?, ?);";
/* Apply parameters. */
$cParams = array(&$cID,
&$cData,
&$cTime,
&$cLoc,
&$cIP,
&$cData,
&$cTime,
&$cLoc,
&$cIP);
/* Execute query. */
$this->oDB->db_basic_action($cQuery, $cParams);
/* Return TRUE. */
return true;
}
public function destroy($cID)
{
/*
destroy
Damon Vaughn Caskey
2012_12_10
Delete current session.
$cID: Session ID.
*/
$cQuery = NULL; //Query string.
$cParams = NULL; //Parameter array.
/* Build query string. */
$cQuery = "DELETE FROM tbl_php_sessions WHERE session_id = ?";
/* Apply parameters. */
$cParams = array(&$cID);
/* Execute query. */
$this->oDB->db_basic_action($cQuery, $cParams);
/* Return TRUE. */
return true;
}
public function gc($maxlifetime)
{
/*
gc (Garbage Cleanup)
Damon Vaughn Caskey
2012_12_10
Delete expired session data.
$maxlifetime: Expire time. Unused.
*/
$cTime = date(constants::c_cDateF); //Current time.
$cQuery = NULL; //Query string.
$cParams = NULL; //Parameter array.
/* Build query string. */
$cQuery = "DELETE FROM tbl_php_sessions WHERE expire < ?";
/* Apply parameters. */
$cParams = array(&$cTime);
/* Execute query. */
$this->oDB->db_basic_action($cQuery, $cParams);
/* Return TRUE. */
return true;
}
}
Class – Error
<?php
class class_error
{
/*
class_error
Damon Vaughn Caskey
2012_12_28
Error handler.
*/
const c_cDBEHost = "box406.bluehost.com"; //Error log DB host.
const c_cDBELName = "caskeysc_uk"; //Error log DB logical name.
const c_cDBEUser = "caskeysc_ehsinfo"; //Error log DB user.
const c_cDBEPword = "caskeysc_ehsinfo_user"; //Error log DB password.
const c_iETScript = 0; //Error type; general script errors.
const c_iETDB = 1; //Error type; datbase error.
private $cIP = NULL; //$_SERVER['REMOTE_ADDR']
private $cSource = NULL; //$_SERVER['PHP_SELF']
private $debug = 0;
private $oMail = NULL; //Class mail hanlder.
private $oUtl = NULL; //Utility functions.
public $cErrType = NULL; //Error number or user type.
public $cErrCode = NULL; //Error code.
public $cErrDetail = NULL; //Error detail (SQL string, parameters, user defined data...).
public $cErrFile = NULL; //File running at error time.
public $cErrLine = NULL; //Error line.
public $cErrMsg = NULL; //Error message.
public $cErrState = NULL; //State of server (ex. SQL State).
public $cErrTOE = NULL; //Time of error.
public $cErrVars = NULL; //String dump of variables.
public function __construct($oDep, $debug = 0)
{
/* Import object dependencies. */
$this->oMail = $oDep['Mail'];
$this->oUtl = $oDep['Utl'];
/* Verify object dependencies. */
if(!$this->oMail) trigger_error("Missing object dependency: Mail.", E_USER_ERROR);
if(!$this->oUtl) trigger_error("Missing object dependency: Utility.", E_USER_ERROR);
$this->debug = $debug;
set_error_handler(array($this, 'error_handle_start'));
register_shutdown_function(array(&$this, 'error_shutdown'));
}
public function error_fatal()
{
/*
error_fatal
Damon Vaughn Caskey
2012_12_30
Run final actions before exit on a fatal error.
*/
/*
If headers haven't been sent, redirect user to an error page. Otherwise we'll just have to die and settle for a plain text message.
*/
if($this->oUtl->utl_redirect("/a_errors/php.php")===FALSE)
{
die("I'm sorry; it appears an internal error has occurred while processing your request. The webmaster has been alerted and will resolve this issue as soon as possible.");
}
exit;
}
public function error_handle_start($cCode=NULL, $cMsg=NULL, $cFile=NULL, $cLine=NULL)
{
$this->error_handle($cCode, $cMsg, $cFile, $cLine, self::c_iETScript, NULL, NULL);
return true;
}
public function error_handle($cCode=NULL, $cMsg=NULL, $cFile=NULL, $cLine=NULL, $cType=self::c_iETScript, $cState=NULL, $cDetail=NULL)
{
/*
error_run
Damon Vaughn Caskey
2012_12_28
Run error mail and and log in single call.
$cCode: Error code/number.
$cMsg: Error message.
$cFile: PHP generated file name.
$cLine: Code line location.
$cType: User defined error type.
$cState: Server state (mostly for SQL errors).
$cDetail: User added detail.
*/
$iLevel = NULL;
$value = NULL;
$key = NULL;
$i = 0;
$this->cErrTOE = date(constants::c_cDateF);
$this->cIP = $_SERVER['REMOTE_ADDR'];
$this->cSource = $_SERVER['PHP_SELF'];
$this->cErrType = $cType;
$this->cErrFile = $cFile;
$this->cErrLine = $cLine;
$this->cErrState = $cState;
$this->cErrCode = $cCode;
$this->cErrMsg = $cMsg;
$this->cErrDetail = $cDetail;
$this->cErrVars = NULL;
/*
If logging in (/authenticate_0001.php) and error is suppressed then exit and do nothing.
LDAP libraries are bugged. EX: ldap_bind throws error 49 on bad password instead of returning FALSE as documented.
In PHP this can only be worked around by suppressing the error. Otherwise suppressing errors with @ is bad practice
that should be avoided at all costs. Its use will be ignored within any other file.
*/
$iLevel = error_reporting();
if (($iLevel == 0 || ($iLevel & $cCode) == 0) && $this->cSource == "/authenticate_0001.php")
{
return true;
}
if($this->cErrCode)
{
/*
Log error to database.
*/
//$this->error_log_db();
/*
If error is any type other than a notice then immediately end script and send an email alert to webmaster.
*/
switch ($this->cErrCode)
{
case E_USER_ERROR:
case E_USER_WARNING:
case E_ERROR:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
default:
if(isset($_GET))
{
foreach($_GET as $key => $value)
{
$this->cErrVars .= "GET[".$key."]: ".$value." || ";
}
}
if(isset($_POST))
{
foreach($_POST as $key => $value)
{
$this->cErrVars .= "POST[".$key."]: ".$value." || ";
}
}
if(isset($_SESSION))
{
foreach($_SESSION as $key => $value)
{
$this->cErrVars .= "SESSION[".$key."]: ".$value." || ";
}
}
$this->error_mail();
$this->error_fatal();
break;
case E_USER_NOTICE:
case E_NOTICE:
break;
}
}
}
public function error_log_db()
{
/*
error_db_log
Damon Vaughn Caskey
2012_12_28
Attempt to log error detail to database. Self contained to avoid recursive calls to database class.
*/
$rDBConn = NULL; //Connection reference to DB error log.
$cQuery = NULL; //Error query string.
$rDBStatement = NULL; //Prepared query reference.
$rDBConn = new mysqli(self::c_cDBEHost, self::c_cDBEUser, self::c_cDBEPword, self::c_cDBELName);
/* If the error log database connection was successful, insert each error to table. */
if (!$rDBConn->connect_error)
{
/* Build query string. */
$cQuery = "INSERT INTO tbl_gen_errors (toe, ip, type, source, file, line, state, code, vars, msg, details) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$rDBStatement = $rDBConn->prepare($cQuery);
/* Bind parameters. */
$rDBStatement->bind_param("sssssssssss", $this->cErrTOE, $this->cIP, $this->cErrType, $this->cSource, $this->cErrFile, $this->cErrLine, $this->cErrState, $this->cErrCode, $this->cErrVars, $this->cErrMsg, $this->cErrDetail);
/* Execute and close query. */
if($rDBStatement != false)
{
$rDBStatement->execute();
$rDBStatement->close();
}
/* Close DB connection. */
$rDBConn->close();
}
}
public function error_mail()
{
/*
error_mail
Damon Vaughn Caskey
2012_12_31
~2012_01_02: Array list upgrade.
Prepare and send an email error alert.
*/
$cMsg = NULL;
$cMsg = array(
"Time" => $this->cErrTOE,
"Type" => $this->cErrType,
"IP" => $this->cIP,
"Def. Source File" => $this->cSource,
"Source File" => $this->cErrFile,
"Line" => $this->cErrLine,
"State" => $this->cErrState,
"Code" => $this->cErrCode,
"Message" => $this->cErrMsg,
"Variables" => $this->cErrVars,
"Details" => $this->cErrDetail
);
$this->oMail->mail_send($cMsg, "Error Report");
}
public function error_shutdown()
{
/*
error_shutdown
Damon Vaughn Caskey
2012_12_31
Shutdown function to capture error types PHP will not normally allow custom error handlers to deal with.
*/
$cError = NULL; //Last error status.
/*
Get last error status.
*/
$cError = error_get_last();
$this->error_handle($cError['type'], $cError['message'], $cError['file'], $cError['line']);
}
}
Class – Mail
<?php
class class_mail
{
/*
class_mail - https://www.caskeys.com/dc/?p=5031
Damon Vaughn Caskey
2012_12_10
Mail handler.
*/
const c_bWMAlert = TRUE; //Send webmaster a blind copy?
const c_cEDefMsg = "..."; //Default message.
const c_cEHead = "MIME-Version: 1.0 \r\nContent-type: text/html; charset=iso-8859-1\r\n"; //Default email headers.
const c_cESubject = "From EHS Web"; //Default outgoing email subject.
const c_cEWMIn = "dvcask2@uky.edu"; //Default webmaster's incoming email address.
const c_cEWMOut = "ehs_noreply@uky.edu"; //Default address when server sends mail.
public function mail_send($cMsg=self::c_cEDefMsg, $cSubject=self::c_cESubject, $cTo=self::c_cEWMIn, $cFrom=self::c_cEWMOut, $cBcc=NULL, $bWMAlert=self::c_bWMAlert, $cHeader=self::c_cEHead, $cParams=NULL)
{
/*
mail_send
Damon Vaughn Caskey
2012_12_28
Send HTML mail with standard defaults.
$cMsg: Body of email.
$cSubject: Subject line.
$cTo: Outgoing address list.
$cFrom: Return address.
$cBcc: Blind carbon copy address list.
$bWMAlert: Send Bcc to webmaster.
$cHeader: Header information.
$cParams: Optional parameters.
*/
$cBody = NULL; //Final sting for message body.
/*
Insert From address to header.
*/
$cHeader .= "From: ".$cFrom. "\r\n";
/*
If Webmaster alert is on, insert address into Bcc and add to header. Otherwise just add Bcc to header as is.
*/
if($bWMAlert===TRUE)
{
$cHeader .= "Bcc: ".self::c_cEWMIn. ", ".$cBcc."\r\n";
}
else
{
$cHeader .= "Bcc: ".$cBcc."\r\n";
}
$cHeader .="\r\n";
/*
If message passed as a key array, break into list and output as table layout.
*/
if (is_array($cMsg))
{
/*
Initial html and table markup.
*/
$cBody = "<html>
<head>
<title>".$cSubject."</title>
</head>
<body>
<h1>".$cSubject."</h1>
<table cellpadding='3'>";
/*
Get each item in array and place into two column table row.
*/
foreach($cMsg as $key => $value)
{
$cBody .= "<tr><th>".$key.":</th><td>".$value."</td></tr>";
}
/*
Add closing markup.
*/
$cBody .= "</table>
</body>
</html>";
}
else
{
/*
Output message as is.
*/
$cBody = $cMsg;
}
/*
Run mail function.
*/
return mail($cTo, $cSubject, $cBody, $cHeader, $cParams);
}
}
?>
Class – Forms
<?php
class class_forms {
/*
Utility
Damon Vaughn Caskey
2013_01_21
Miscellaneous form input functions.
*/
/* Constants */
const FORMS_ID_USE_NAME = NULL; //Use name to generate ID.
const FORMS_ITEM_ADDITIONS_NONE = NULL; //No manual additions to generated item list.
const FORMS_LABEL_NONE = NULL; //No label for fieldset item.
const FORMS_LABEL_BLANK = 1; //Blank label for fieldset item.
const FORMS_LABEL_USE_ITEM_KEY = 2; //Use the item key of a field for its fieldset label or visible selection.
const FORMS_LABEL_USE_ITEM_NAME = 3; //Use the item name of a field for its fieldset label or visible selection.
const FORMS_LABEL_USE_ITEM_VALUE = 4; //Use the items value of a field for its fieldset label or visible selection.
const FORMS_LABEL_TYPE_FIELDSET = 0; //Fieldset label.
const FORMS_LABEL_TYPE_INLINE = 1; //Label text only; no formatting.
const FORMS_LEGEND_NONE = NULL; //No legend for fieldset.
const FORMS_QUERY_PARAMETERS_NONE = NULL; //No query parameters.
const FORMS_TYPE_RADIO = 0; //Radio type list.
const FORMS_TYPE_SELECT = 1; //Select type list.
const FORMS_VALUE_CURRENT_NONE = NULL; //Current (last selected) value.
const FORMS_VALUE_DEFAULT_NONE = NULL; //Default selected value.
const FORMS_VALUE_DEFAULT_NOW = -1; //Default to current time for specific field.
const FORMS_EVENTS_NONE = NULL; //No events attached to fieldset item.
const FORMS_READ_ONLY_OFF = FALSE;
const FORMS_READ_ONLY_ON = TRUE;
public $cItemsList = NULL; //Array of items list for select/radio/etc.
public $cFormElement = NULL; //Arracy to store completed element markup that will be placed in a fieldset.
public $cFormElementActions = NULL; //Array of actions tied to form element (onchange, onclick, etc.).
public $cFieldset = NULL; //Array of completed fieldset markups ready to echo into page.
public $cFieldsetAddsA = NULL; //Array of additional instructions, links, etc. that may be added to fieldset above items.
function __construct($oDep)
{
/*
Constructor
Damon Vaughn Caskey
2013-01-21
Class constructor.
*/
/* Import object dependencies. */
//$this->oUtl = $oDep['Utl'];
$this->oDB = $oDep['DB'];
//$this->Err = $oDep['Err'];
/* Verify object dependencies. */
//if(!$this->oUtl) trigger_error("Missing object dependency: Utility.", E_USER_ERROR);
if(!$this->oDB) trigger_error("Missing object dependency: Database.", E_USER_ERROR);
//if(!$this->Err) trigger_error("Missing object dependency: Errors.", E_USER_ERROR);
}
private function forms_events_markup($cEvents=self::FORMS_EVENTS_NONE)
{
/*
forms_events_markup
Damon Vaughn Caskey
2013-03-26
Prepare HTML markup string for fieldset form item events (onchange, onclick, etc.).
*/
if(isset($cEvents))
{
foreach ($cEvents as $cKey => $cValue)
{
$cEvent .= $cKey.'="'.$cValue.'"';
}
}
return $cEvent;
}
public function test()
{
echo self::FORMS_LABEL_USE_ITEM_VALUE;
}
private function forms_label_markup($iStyle=self::FORMS_LABEL_NONE, $iType=self::FORMS_LABEL_TYPE_FIELDSET, $cName=NULL, $cID=NULL, $cKey=NULL, $cValue=NULL)
{
/*
forms_label_markup
Damon Vaughn Caskey
2013-03-26
Prepare HTML markup string for fieldset form item labels.
Preconditions:
$cName: Name of item.
$cID: ID of item.
$cKey: Array key of item.
$cValue: Array value of item.
$iStyle: How to arrange label markup.
self::FORMS_LABEL_USE_ITEM_KEY = The item's Key will be used as a label.
self::FORMS_LABEL_USE_ITEM_VALUE = The item's Value will be used as label.
self::FORMS_LABEL_BLANK = The label will be left blank.
self::FORMS_LABEL_NONE = No label markuop at all.
Postconditions:
Return finished label markup string.
*/
$cClosing = NULL;
$cLabel = NULL;
if($iType == self::FORMS_LABEL_TYPE_FIELDSET)
{
/* Prepare opening label markup. */
$cLabel = '<div class="'.$cClass['Container_Label'].'"><label for="'.$cID.'">';
$cClosing = '</label></div>';
}
switch($iStyle)
{
case self::FORMS_LABEL_USE_ITEM_KEY:
$cLabel .= $cKey.$cClosing;
break;
case self::FORMS_LABEL_USE_ITEM_NAME:
$cLabel .= $cName.$cClosing;
break;
case self::FORMS_LABEL_USE_ITEM_VALUE:
$cLabel .= $cValue.$cClosing;
break;
case self::FORMS_LABEL_BLANK:
$cLabel .= $cClosing;
break;
case self::FORMS_LABEL_NONE:
$cLabel = NULL;
break;
default:
$cLabel .= $iStyle.$cClosing;
}
/* Return label markup string. */
return $cLabel;
}
public function forms_list_array_from_query($cQuery=NULL, $cParams=array(self::FORMS_QUERY_PARAMETERS_NONE), $cAddsT=self::FORMS_ITEM_ADDITIONS_NONE, $cAddsB=self::FORMS_ITEM_ADDITIONS_NONE){
/*
forms_list_array_from_query
Damon Vaughn Caskey
2012-12-19
Create list array directly from query results.
$iType: Select, options, etc.
$cQuery: SQL query string.
$cParams: Parameter array.
$cDefault: Default selection.
$cCurrent: Current selection.
$bKey: Use key as item label?
$cAddsT: Additional items to place at top of generated list.
$cAddsB: Additional items to place at bottom of generated list.
*/
$i = NULL; //Counter.
$cList = NULL; //Output string.
$cKey = NULL;
$cList = array();
/* Query for list items. */
$this->oDB->db_basic_select($cQuery, $cParams);
/* Populate list variable. */
while($this->oDB->db_line(SQLSRV_FETCH_NUMERIC))
{
/* Get key (used for items visible to user). */
$cKey = $this->oDB->cDBLine[1];
/* If fields exist beyond first key, append to a single key value. */
if($this->oDB->iDBFCount > 2)
{
/* Start with field #2 (third field) and append to key string until last field is reached. */
for($i = 2; $i <= ($this->oDB->iDBFCount-1); $i++)
{
$cKey .= "; ". $this->oDB->cDBLine[$i];
}
}
/* Populate list array using visible portion of list values as key. */
$cList[$cKey] = $this->oDB->cDBLine[0];
}
/* Merge Additions. (As of 5.4 array_merge() will always reorder indexes). */
if($cAddsT && is_array($cAddsT))
{
$cList = $cAddsT + $cList;
}
if($cAddsB && is_array($cAddsB))
{
$cList += $cAddsB;
}
$this->cItemsList = $cList;
/* Output final list value. */
return $this->cItemsList;
}
function forms_list_numeric($iType=NULL, $cQuery=NULL, $cParams=NULL, $cDefault=NULL, $cCurrent=NULL, $bKey=self::FORMS_LABEL_USE_ITEM_KEY, $iStart=0, $cAddsT=NULL, $cAddsB=NULL)
{
/*
forms_list_numeric
Damon V. Caskey
2012-12-19
Generate a simple numeric list with maximum value based number of rows returned by query.
$iType:
$cQuery: SQL query string.
$cParams: Parameter array.
$cDefault: Default selection.
$cCurrent: Current selection.
$bKey: Use key as item label?
$iStart: First numeric value of generated list.
$cAddsT: Additional items to place at top of generated list.
$cAddsB: Additional items to place at bottom of generated list.
*/
$i = NULL; //Counter.
$cList = NULL; //Item list array.
$cList = array();
$this->oDB->db_basic_select($cQuery, $cParams);
for($i = $iStart; $i <= $this->oDB->iDBRowCount; $i++)
{
$cList[$i] = $i;
}
/* Merge Additions. (As of 5.4 array_merge() will always reorder indexes). */
if($cAddsT && is_array($cAddsT))
{
$cList = $cAddsT + $cList;
}
if($cAddsB && is_array($cAddsB))
{
$cList += $cAddsB;
}
switch ($iType)
{
case self::FORMS_TYPE_RADIO:
//$this->cDLListCode = $this->forms_select_options($cList, $cDefault, $cCurrent, $bKey);
default:
$this->cDLListCode = $this->forms_select_options($cList, $cDefault, $cCurrent, $bKey);
}
return $this->cDLListCode;
}
public function forms_phone($cName=NULL, $cID=self::FORMS_ID_USE_NAME, $cLabel=self::FORMS_LABEL_NONE, $cDefault=array("cc" => "1", "ac" => "859", "lc" => NULL, "pn" => NULL), $cCurrent=self::FORMS_VALUE_CURRENT_NONE, $cClass=NULL, $cEvents=NULL)
{
/*
forms_phone
Damon Vaughn Caskey
2013-01-21
Output form phone input markup.
*/
$cMarkup = NULL; //Final markup to echo.
$cEvent = NULL; //Event string.
$cMarkup .='<div class="'.$cClass['Container_All'].'">';
/* Set ID to name? */
$cID = $cID != self::FORMS_ID_USE_NAME ? $cID : $cName;
/* If current value empty or NULL, set "No current" cosntant */
$cCurrent = $cCurrent ? $cCurrent : self::FORMS_VALUE_CURRENT_NONE;
$cDefault = $cDefault == self::FORMS_VALUE_DEFAULT_NONE ? NULL : $cDefault;
/* If no current value is available, use default. */
if(!$cCurrent || $cCurrent == self::FORMS_VALUE_CURRENT_NONE)
{
$cCurrent = $cDefault;
}
/* Parse event actions. */
$cEvent = $this->forms_events_markup($cEvents);
/* Prepare label markup. */
$cMarkup .= $this->forms_label_markup($cLabel, self::FORMS_LABEL_TYPE_FIELDSET, $cName, $cID, $cKey, $cValue);
$cMarkup .= '<div class="'.$cClass['Container_Item'].'"><input type="text" name="'.$cName.'_cc" id="'.$cID.'_cc" class="'.$cClass.'" value="'.$cDefault['cc'].'" size="1" maxlength="1" />
(
<input type="text" name="'.$cName.'_ac" id="'.$cID.'_ac" class="'.$cClass.'" value="'.$cDefault['ac'].'" size="3" maxlength="3" />
)
<input type="text" name="'.$cName.'_lc" id="'.$cID.'_lc" class="'.$cClass.'" value="'.$cDefault['lc'].'" size="3" maxlength="3" />
-
<input type="text" name="'.$cName.'_pn" id="'.$cID.'_pn" class="'.$cClass.'" value="'.$cDefault['pn'].'" size="4" maxlength="4" />
</div></div>';
/*
Return end result.
*/
return $cMarkup;
}
public function forms_radio($cName=NULL, $cID=self::FORMS_ID_USE_NAME, $iLabelStyle=self::FORMS_LABEL_USE_ITEM_KEY, $cList=array(NULL), $cDefault=NULL, $cCurrent=self::FORMS_VALUE_CURRENT_NONE, $cClass=array("Item" => "Standard"), $cEvents=NULL)
{
/*
forms_radio
Damon Vaughn Caskey
2013-03-24
*/
$cKey = NULL; //Array key.
$cValue = NULL; //Array value.
$cChecked = NULL; //Checked (default/current)?
$cMarkup = NULL; //Final markup to echo.
$cLabel = NULL; //Item label markup.
$cIDFinal = NULL; //Final ID inserted into markup.
$cEvent = NULL;
$cMarkup .='<div class="'.$cClass['Container_All'].'">';
/* Set ID to name? */
$cID = $cID != self::FORMS_ID_USE_NAME ? $cID : $cName;
/* If current value empty or NULL, set "No current" cosntant */
$cCurrent = $cCurrent ? $cCurrent : self::FORMS_VALUE_CURRENT_NONE;
/* Parse event actions. */
$cEvent = $this->forms_events_markup($cEvents);
foreach ($cList as $cKey => $cValue)
{
/* If $cValue matches $cCurrent, or $cCurrent not provided but $cValue matches $cDefault, add 'checked' to make this the default list item selected. */
if ($cCurrent == $cValue || ($cCurrent == self::FORMS_VALUE_CURRENT_NONE && $cValue == $cDefault))
{
$cChecked = 'checked="checked"';
}
else
{
$cChecked = NULL;
}
/* IDs must be unique, so we'll combine ID with value. */
$cIDFinal = $cID."_".$cValue;
/* Prepare label markup. */
$cMarkup .= $this->forms_label_markup($iLabelStyle, self::FORMS_LABEL_TYPE_FIELDSET, $cName, $cIDFinal, $cKey, $cValue);
$cMarkup .= '<div class="'.$cClass['Container_Item'].'"><input type="radio" name="'.$cName.'" id="'.$cIDFinal.'" value="'.$cValue.'" '.$cChecked.' '.$cEvent.' /></div>';
}
$cMarkup .= '</div>';
/*
Return end result.
*/
return $cMarkup;
}
public function forms_select($cName=NULL, $cID=self::FORMS_ID_USE_NAME, $iLabelStyle=self::FORMS_LABEL_USE_ITEM_KEY, $iKeyStyle=self::FORMS_LABEL_USE_ITEM_KEY, $cList=array(NULL => NULL), $cDefault=NULL, $cCurrent=self::FORMS_VALUE_CURRENT_NONE, $cClass=array("Item" => "Standard", "Container_All" => "Show Me"), $cEvents=NULL)
{
/*
forms_radio
Damon Vaughn Caskey
2013-03-24
*/
$cKey = NULL; //Array key.
$cValue = NULL; //Array value.
$cChecked = NULL; //Checked (default/current)?
$cMarkup = NULL; //Final markup to echo.
$cLabel = NULL; //Item label markup.
$cEvent = NULL;
$cItems = NULL; //Select options.
$cMarkup .='<div class="'.$cClass['Container_All'].'">';
/* Set ID to name? */
$cID = $cID != self::FORMS_ID_USE_NAME ? $cID : $cName;
/* Parse event actions. */
$cEvent = $this->forms_events_markup($cEvents);
if (!is_array($cList))
{
$cList = array(NULL => NULL);
}
foreach ($cList as $cKey => $cValue)
{
/* If $cValue matches $cCurrent, or $cCurrent not provided but $cValue matches $cDefault, add 'checked' to make this the default list item selected. */
if ($cCurrent == $cValue || ($cCurrent == self::FORMS_VALUE_CURRENT_NONE && $cValue == $cDefault))
{
$cChecked = 'selected';
}
else
{
$cChecked = NULL;
}
/* Prepare label markup. */
$cLabel = $this->forms_label_markup(self::FORMS_LABEL_USE_ITEM_KEY, self::FORMS_LABEL_TYPE_INLINE, $cName, $cID, $cKey, $cValue);
$cItems.='<option value="'.$cValue.'" '.$cChecked.'>' . $cLabel . '</option>';
}
/* Prepare label markup. */
$cLabel = $this->forms_label_markup($iLabelStyle, self::FORMS_LABEL_TYPE_FIELDSET, $cName, $cID, $cKey, $cValue);
$cMarkup .= $cLabel.'<div class="'.$cClass['Container_Item'].'"><select type="select" name="'.$cName.'" id="'.$cID.'" class="'.$cClass['Item'].'" '.$cEvent.'>'.$cItems.'</select></div></div>';
/*
Return end result.
*/
return $cMarkup;
}
public function forms_text($cName=NULL, $cID=self::FORMS_ID_USE_NAME, $cLabel=self::FORMS_LABEL_NONE, $cDefault=self::FORMS_VALUE_DEFAULT_NONE, $cCurrent=self::FORMS_VALUE_CURRENT_NONE, $cClass=array("Item" => "Standard"), $cEvents=NULL)
{
/*
forms_text
Damon Vaughn Caskey
2013-01-21
Output form text input markup.
*/
$cMarkup = NULL; //Final markup to echo.
$cEvent = NULL; //Event string.
$cMarkup .='<div class="'.$cClass['Container_All'].'">';
/* Set ID to name? */
$cID = $cID != self::FORMS_ID_USE_NAME ? $cID : $cName;
/* If current value empty or NULL, set "No current" cosntant */
$cCurrent = $cCurrent ? $cCurrent : self::FORMS_VALUE_CURRENT_NONE;
$cDefault = $cDefault == self::FORMS_VALUE_DEFAULT_NONE ? NULL : $cDefault;
/* If no current value is available, use default. */
if(!$cCurrent || $cCurrent == self::FORMS_VALUE_CURRENT_NONE)
{
$cCurrent = $cDefault;
}
/* Parse event actions. */
$cEvent = $this->forms_events_markup($cEvents);
/* Prepare label markup. */
$cMarkup .= $this->forms_label_markup($cLabel, self::FORMS_LABEL_TYPE_FIELDSET, $cName, $cID, $cKey, $cValue);
$cMarkup .= '<div class="'.$cClass['Container_Item'].'"><input type="text" name="'.$cName.'" id="'.$cID.'" class="'.$cClass['Item'].'" value="'.$cCurrent.'" '.$cEvent.' /></div></div>';
/*
Return end result.
*/
return $cMarkup;
}
public function forms_time($cName=NULL, $cID=self::FORMS_ID_USE_NAME, $cLabel=self::FORMS_LABEL_NONE, $cDefault=NULL, $cCurrent=NULL, $cOptions="{dateFormat: 'yy-mm-dd', timeFormat: 'HH:mm:ss', controlType: 'select', changeYear: true, constrainInput: true}", $cFunction="datetimepicker", $bReadOnly=self::FORMS_READ_ONLY_ON, $cClass=NULL, $cEvents=NULL)
{
/*
forms_time
Damon Vaughn Caskey
2013-01-21
Output form date/time input markup.
*/
$cMarkup = NULL; //Final markup to echo.
$cEvent = NULL; //Event string.
$cMarkup .='<div class="'.$cClass['Container_All'].'">';
/* Set ID to name? */
$cID = $cID != self::FORMS_ID_USE_NAME ? $cID : $cName;
/* If current value empty or NULL, set "No current" cosntant */
$cCurrent = $cCurrent ? $cCurrent : self::FORMS_VALUE_CURRENT_NONE;
$cDefault = $cDefault == self::FORMS_VALUE_DEFAULT_NONE ? NULL : $cDefault;
/* If no current value is available, use default. */
if(!$cCurrent || $cCurrent == self::FORMS_VALUE_CURRENT_NONE)
{
$cCurrent = $cDefault;
}
/* Parse event actions. */
$cEvent = $this->forms_events_markup($cEvents);
/* Prepare label markup. */
$cMarkup .= $this->forms_label_markup($cLabel, self::FORMS_LABEL_TYPE_FIELDSET, $cName, $cID, $cKey, $cValue);
$cMarkup .= "<script>$(function(){
$( '#".$cID."' ).".$cFunction."(".$cOptions.");
});</script>";
$cMarkup .= "<input type='text' name='".$cName."' id='".$cID."' value='".$cCurrent."'";
if ($bReadOnly==TRUE)
{
$cMarkup .= " readonly='readonly'";
}
$cMarkup .= " /></div>";
/* Return end result. */
return $cMarkup;
}
public function forms_fieldset($cID=NULL, $cLegend=self::FORMS_LEGEND_NONE, $cElements=array(NULL), $cAddOns=array(NULL), $cClass=array("Div"=>"table_row_0", "Fieldset"=>"Standard"))
{
/*
forms_fieldset
Damon Vaughn Caskey
2013-03-25
Arrage form input items into a fieldset.
$cID: Fieldset ID.
$cLegend: Legend label, if any.
$cElements: Markup of field list items (select lists, radio groups, text boxes, etc).
$cClass: Style classes.
*/
$cElementKey = NULL; //Single element key.
$cElementVal = NULL; //Single element value.
$cMarkup = '<div class="'.$cClass['Div'].'"><fieldset id="'.$cID.'" class="'.$cClass['Fieldset'].'">';
if($cLegend != self::FORMS_LEGEND_NONE)
{
$cMarkup .= '<legend>'.$cLegend.'</legend>';
}
foreach($cAddOns as $cElementKey => $cElementVal)
{
$cMarkup .= '<div class="'.$cElementKey.'">'.$cElementVal.'</div>';
}
foreach($cElements as $cElementKey => $cElementVal)
{
$cMarkup .= '<div class="'.$cElementKey.'">'.$cElementVal.'</div>';
}
$cMarkup .= '</fieldset></div>';
$this->cFieldset[$cID] = $cMarkup;
return $this->cFieldset[$cID];
}
}
?>
Class – Database

Update: This class file has been replaced with the Yukon Database Control Library and migrated to github. Please click here and check it out, thanks!
Class – Config
<?php
/*
Configuration file. This should be added to all PHP scripts to set up commonly used includes, functions, objects, variables and so on.
*/
$iReqTime = $_SERVER['REQUEST_TIME_FLOAT'];
$cDocroot = NULL; //Document root.
$oDB = NULL; //Database class object.
$oErr = NULL; //Error class object.
$oMail = NULL; //E-Mail handler class object.
$oSes = NULL; //Session handler class object.
$oUtl = NULL; //Utility class object.
$oFrm = NULL; //Forms class object.
/* Get needed includes. */
require_once("access.php"); //Account based access.
require_once("constants.php"); //Global constants.
require_once("database.php"); //Database handler.
require_once("forms.php"); //Forms handler.
require_once("error.php"); //Error handler.
require_once("mail.php"); //Mail handler.
require_once("sessions.php"); //Session handler.
require_once("tables.php"); //Table handler.
require_once("utility.php"); //Utility functions.
/* Initialize class objects */
$oUtl = new class_utility(); //Utility functions.
$oMail = new class_mail(); //E-Mail handler.
$oErr = new class_error(array("Mail" => $oMail, "Utl" => $oUtl)); //Error handler.
$oDB = new class_db(array("Utl" => $oUtl, "Err" => $oErr)); //Database handler.
$oSes = new class_sessions(array("DB" => $oDB)); //Session handler.
$oAcc = new class_access(array("DB" => $oDB, "Ses" => $oSes, "Utl" => $oUtl)); //Account based access.
$oTbl = new class_tables(array("Utl"=>$oUtl)); //Tables handler.
$oFrm = new class_forms(array("DB"=>$oDB)); //Forms handler.
$cDocroot = $oUtl->utl_get_server_value('DOCUMENT_ROOT')."/";
/* Replace default session handler. */
session_set_save_handler($oSes, true);
/* If session not started, initialize. */
if(session_status()==PHP_SESSION_NONE)
{
session_start();
}
?>