start copy from cimac web

This commit is contained in:
2026-05-14 08:47:13 +02:00
commit dfc6ed40ae
3624 changed files with 899295 additions and 0 deletions
@@ -0,0 +1,909 @@
<?php
// version 2.02
/*
-----------------------------------------------------------------------------
- File Name:
- WAFV_Scripts_PHP.php
-
- Description:
- Shared functions for WA Form Validations - Server Side PHP
-
- This file contains proprietary and confidential information from WebAssist.com
- corporation. Any unauthorized reuse, reproduction, or modification without
- the prior written consent of WebAssist.com is strictly prohibited.
-
- Copyright 2004 WebAssist.com Corporation. All rights reserved.
-----------------------------------------------------------------------------
*/
function SaveFormToSession($theErrors, $valPage) {
$postVars = "";
$formVars = array_keys($_POST);
$loopInde = 0;
foreach ($formVars as $theKey) {
if (is_array($_POST[$theKey])) {
$toAdd = "";
for ($x=0; $x < count($_POST[$theKey]); $x++) {
if ($x != 0) {
$toAdd .= "&";
}
if(get_magic_quotes_gpc()){
$toAdd .= "WAVT_".($theKey)."[".$x."]=".( stripslashes( $_POST[$theKey][$x]) );
}
else{
$toAdd .= "WAVT_".($theKey)."[".$x."]=".($_POST[$theKey][$x]);
}
}
}
else{
if(get_magic_quotes_gpc()){
$toAdd = "WAVT_".($theKey)."=".( stripslashes( $_POST[$theKey] ) );
}
else{
$toAdd = "WAVT_".($theKey)."=".($_POST[$theKey]);
}
}
if ($loopInde != 0) {
$postVars .= "&";
}
$postVars .= $toAdd;
$loopInde++;
}
$postVars .= "&WAVT_".$valPage."_Errors=".substr($theErrors,1);
$_SESSION['WAVT_'.$valPage."_Errors"] = $postVars;
}
function PostResult($thePage, $theErrors, $valPage, $appendParams = true) {
$thePostURL = "";
SaveFormToSession($theErrors, $valPage);
if (isset($_GET["plugin_file"])) return;
$thePostURL .= $thePage;
$urlParams = "";
$schema = $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http';
$host = strlen($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:$_SERVER['SERVER_NAME'];
if (strpos($thePostURL,"://") === false) {
if (strpos($thePage,"/") !== 0) {
$thePostURL = substr($_SERVER["REQUEST_URI"],0,strrpos($_SERVER["REQUEST_URI"],"/")+1) . $thePostURL;
}
if (strpos($thePostURL,"?") !== false) {
$urlParams = substr($thePostURL,strpos($thePostURL,"?"));
$thePostURL = substr($thePostURL,0,strpos($thePostURL,"?"));
}
$thePostURL = $schema."://".str_replace("%2F","/",$host.rawurlencode($thePostURL)).$urlParams;
}
while (!(strpos($thePostURL,"/../") === false)) {
$thePostURL = substr($thePostURL, 0, strrpos(substr($thePostURL,0,strpos($thePostURL,"/../")),"/")+1).substr($thePostURL,strpos($thePostURL,"/../")+4);
}
if (strpos($thePage,"#") === false && $appendParams && isset($_SERVER['QUERY_STRING']) && ($_SERVER['QUERY_STRING'] != '')) {
if (strpos($thePostURL,"?") !== false) {
$thePostURL.= "&" . ($_SERVER['QUERY_STRING']);
} else {
$thePostURL.= "?" . ($_SERVER['QUERY_STRING']);
}
}
$thePostURL = str_replace("%23","#",$thePostURL);
header("Location: ". $thePostURL);
exit;
}
function WAtrimIt($theString,$leaveLeft,$leaveRight) {
if (!isset($leaveLeft) || $leaveLeft == 0) {
$theString = ltrim($theString);
}
if (!isset($leaveRight) || $leaveRight == 0) {
$theString = rtrim($theString);
}
return $theString;
}
function WAValidateAN($value,$allowUpper,$allowLower,$allowNumbers,$allowSpace,$extraChars,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
for ($x=0; $x < strlen($value); $x++) {
$charGood = false;
$nextChar = substr($value,$x,1);
$charCode = ord(substr($value,$x,1));
if ($allowLower) {
if ($charCode >= 97 && $charCode <= 122) {
$charGood = true;
}
}
if ($allowUpper) {
if ($charCode >= 65 && $charCode <= 90) {
$charGood = true;
}
}
if ($allowNumbers) {
if ($charCode >= 48 && $charCode <= 57) {
$charGood = true;
}
}
if ($allowSpace) {
if ($nextChar == " ") {
$charGood = true;
}
}
if ($extraChars != "") {
if (strpos(str_replace("&quot;",'"',$extraChars),$nextChar) !== false) {
$charGood = true;
}
}
if (!$charGood) {
$isValid = false;
$x = strlen($value);
}
}
if ($required && $value == "") $isValid = false;
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateCC($value,$allow,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
$accepted = "\r\n\t.- ";
if (!(!$required && $value == "")) {
$stripVal = "";
for ($x=0; $x < strlen($value); $x++) {
$charGood = false;
$nextChar = substr($value,$x,1);
$charCode = ord($nextChar);
if ($charCode >= 48 AND $charCode <= 57) {
$stripVal .= $nextChar;
} else {
if (strpos($accepted,$nextChar)==0) {
$isValid = false;
}
}
}
if (strlen($stripVal) < 13)
$isValid = false;
if ($isValid) {
if ($allow != "") {
$isValid = false;
$allow = explode(":",$allow);
foreach ($allow as $aStr) {
if ($aStr != "" && strpos($stripVal, $aStr) === 0) {
$isValid = true;
break;
}
}
}
}
if ($isValid) {
$isValid = WA_isCreditCard($stripVal);
}
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WA_isCreditCard($st) {
if ($st == 0)
return (false);
if (strlen($st) > 19)
return (false);
$sum = 0; $mul = 1; $l = strlen($st);
for ($i = 0; $i < $l; $i++) {
$digit = substr($st, $l-$i-1, 1);
$tproduct = $digit*$mul;
if ($tproduct >= 10)
$sum += ($tproduct % 10) + 1;
else
$sum += $tproduct;
if ($mul == 1)
$mul++;
else
$mul--;
}
if (($sum % 10) == 0)
return (true);
else
return (false);
}
function WAValidateDT($value,$doDate,$dateFormatStr,$dateMin,$dateMax,$doTime,$timeFormatStr,$timeMin,$timeMax,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
$Now = getdate();
$Today = mktime(0, 0, 0, date("n"), date("j"), date("Y"));
if (!(!$required && $value=="")) {
if ($value=="") {
$isValid = false;
}
if ($doDate) {
if ($dateFormatStr != "") {
if (preg_match("/".$dateFormatStr."/i", $value)==0) {
$isValid = false;
}
}
if ($isValid) {
$dateVar = WAGetDateFormat($value, $dateFormatStr);
if (strtotime($dateVar) === 0 || $dateVar == -1 || is_numeric($value) || ((strpos($value, "/") == strrpos($value, "/") && strpos($value, "/") != false)) || ((strpos($value, "-") == strrpos($value, "-") && strpos($value, "-") != false)))
$isValid = false;
if ($dateMin != "") {
$compareDay = WAGetDateFormat($dateMin, $dateFormatStr);
if ($compareDay == -1) {
eval("\$compareDay = ".str_replace("&quot;",'"',$dateMin));
}
if ($dateVar < $compareDay)
$isValid = false;
}
if ($dateMax != "") {
$compareDay = WAGetDateFormat($dateMax, $dateFormatStr);
if ($compareDay == -1) {
eval("\$compareDay = ".str_replace("&quot;",'"',$dateMax));
}
if ($dateVar > $compareDay)
$isValid = false;
}
}
}
if ($doTime) {
$isValid = WAValidateTheTime($doTime, $timeFormatStr, $value, $isValid, $timeMin, $timeMax);
}
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateTheTime($doTime, $timeFormatStr, $value, $isValid, $timeMin, $timeMax) {
if ($doTime) {
if ($timeFormatStr != "") {
if (preg_match("/".$timeFormatStr."/i", $value)==0) {
$isValid = false;
}
}
if (strpos($value, ":")===false) {
$isValid = false;
}
if ($isValid) {
$dateVar = strtotime($value);
$fullYear = date("Y", $dateVar);
if ($dateVar == -1)
$dateVar = strtotime("1/1/1 ".$value);
if ($dateVar == -1)
$isValid = false;
if ($timeMin != "") {
$Today = strtotime("1/1/1 ".$timeMin);
if (!$Today == -1) {
$Today = eval(str_replace("&quot;",'"',$timeMin));
}
$enterTime = (date("H", $dateVar)*360) + (date("i", $dateVar)*60) + date("s", $dateVar);
$minTime = (date("H", $Today)*360) + (date("i", $Today)*60) + date("s", $Today);
if ($enterTime < $minTime)
$isValid = false;
}
if ($timeMax != "") {
$Today = strtotime("1/1/1 ".$timeMax);
if ($Today == -1) {
$Today = eval(str_replace("&quot;",'"',$timeMax));
}
$enterTime = ($dateVar["hours"]*360) + ($dateVar["minutes"]*60) + $dateVar["seconds"];
$minTime = ($Today["hours"]*360) + ($Today["minutes"]*60) + $Today["seconds"];
if ($enterTime > $minTime)
$isValid = false;
}
}
}
return $isValid;
}
function WAGetDateFormat($value, $dateFormat) {
$isUSServ = (date("n", strtotime("1/2/2006")) == 1);
$tValue = $value;
$isEuroDate = (($dateFormat && strpos($dateFormat, "[12]\\d|3[0-1]") < strpos($dateFormat, "1[0-2]|") && strpos($dateFormat, "\\w*") === false) || (!$isUSServ));
if (($isEuroDate && $isUSServ) || (!$isEuroDate && !$isUSServ)) {
$datePattn = "/(\\d*)[-\\.\\/](\\d*)[-\\.\\/](\d*)/";
preg_match($datePattn, $tValue, $tMatch);
if ($tMatch && sizeof($tMatch)) {
if ($isEuroDate) {
$value = $tMatch[2] . "/" . $tMatch[1] . "/" . $tMatch[3];
}
else {
$value = $tMatch[1] . "/" . $tMatch[2] . "/" . $tMatch[3];
}
if (strpos($tValue, " ") !== false) {
$value .= substr($tValue, strpos($tValue, " "));
}
}
}
return strtotime(preg_replace("/[\.-]/", "/", $value));
}
function WAValidateEM($value,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
if (!(!$required && $value == "")) {
$knownDomsPat = "/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|cat|\w{2,2})$/";
$emailPat = "/^(.+)@(.+)$/";
$accepted = "[^\s\(\)><@,;:\\\"\.\[\]]+";
$quotedUser = "(\"[^\"]*\")";
$ipDomainPat = "/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/";
$section = "(".$accepted."|".$quotedUser.")";
$userPat = "/^".$section."(\\.".$section.")*$/";
$domainPat = "/^".$accepted."(\\.".$accepted.")*$/";
$theMatch = preg_match($emailPat,$value,$MatchVal);
$acceptedPat = "/^" . $accepted . "$/";
$userName = "";
$domainName = "";
if (!$theMatch) {
$isValid = false;
}
else {
$userName = $MatchVal[1];
$domainName = $MatchVal[2];
$domArr = explode(".",$domainName);
$IPArray = preg_match($ipDomainPat,$domainName,$ipMatch);
for ($x=0; $x < strlen($userName); $x++) {
if ((ord(substr($userName,$x,1)) > 127 && ord(substr($userName,$x,1)) < 192) || ord(substr($userName,$x,1)) > 255) {
$isValid = false;
}
}
for ($x=0; $x < strlen($domainName); $x++) {
if ((ord(substr($domainName,$x,1)) > 127 && ord(substr($domainName,$x,1)) < 192) || ord(substr($domainName,$x,1)) > 255) {
$isValid = false;
}
}
if (!preg_match($userPat,$userName)) {
$isValid = false;
}
if ($IPArray) {
for ($x=1; $x <= 4; $x++) {
if ($IPArray[x] > 255) {
$isValid = false;
}
}
}
for ($x=0; $x<sizeof($domArr); $x++) {
if (!preg_match($acceptedPat,$domArr[$x]) || strlen($domArr[$x]) == 0 || (strlen($domArr[$x]) < 2 && $x >= (sizeof($domArr)-2) && $x > 0)) {
$isValid = false;
}
}
if (count($domArr) < 2) {
$isValid = false;
}
}
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateEL($value,$minLength,$maxLength,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
if ($required && $value == "") $isValid = false;
if (!(!$required && $value == "")) {
if ((strlen($value) < $minLength) || (strlen($value) > $maxLength && $maxLength > 0)) {
$isValid = false;
}
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateFE($value,$extensions,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
$extensions = str_replace(", ",",",$extensions);
$ExtensionArr = explode(",",$extensions);
if (!(!$required && $value == "")) {
$isValid = false;
if (strrpos($value,".") > 0) {
$value = substr($value, strrpos($value,"."));
foreach ($ExtensionArr as $extension) {
$extension = str_replace(" ","",$extension);
if (strtolower($value) == strtolower($extension)) {
$isValid = true;
break;
}
}
}
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateLE($value1,$value2,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
if ($value1 != $value2 || ($required && $value1 == "")) {
$isValid = false;
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateNM($value,$minLength,$maxLength,$allowDecimals,$punctuationMarks,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
$theCheck = (11/10);
$trueDecimal = substr($theCheck,1,1);
if (!$punctuationMarks) {
if ($trueDecimal == ".") {
$punctuationMarks =",.";
} else {
$punctuationMarks =".,";
}
}
$theThousand = substr($punctuationMarks,0,1);
$theDecimal = substr($punctuationMarks,1,1);
$startVal = $value;
$decimalIndex = strlen($value);
if (strrpos($punctuationMarks, $trueDecimal)===false && strrpos($value, $trueDecimal) !== false) {
$isValid = false;
}
$tempValue = $value;
if ($theDecimal && strpos($value, $theDecimal) !== false) {
if (strpos($value, $theDecimal) != strrpos($value, $theDecimal)) {
$isValid = false;
}
else {
$decimalIndex = strpos($value, $theDecimal);
$tempValue = substr($value, 0, $decimalIndex);
}
}
if ($theThousand && $isValid && strpos($tempValue, $theThousand) !== false) {
if (strpos($tempValue, $theThousand) > 3 || strpos($tempValue, $theThousand) == 0) {
$isValid = false;
}
else {
$valArr = explode($theThousand,$tempValue);
for ($v=1; $v < sizeof($valArr); $v++) {
if (strlen($valArr[$v]) != 3) {
$isValid = false;
break;
}
}
$tempValue = implode("",$valArr);
}
}
if ($isValid && strpos($value, $theDecimal) !== false) {
$tempValue = $tempValue . substr($value, strpos($value, $theDecimal));
}
$value = $tempValue;
if ($isValid && $trueDecimal != $theDecimal && strpos($value, $theDecimal) !== false) {
$value = substr($value,0,strpos($value, $theDecimal)) . $trueDecimal . substr($value,strpos($value, $theDecimal)+1);
}
if ($isValid && !(!$required && $value=="")) {
for ($x=0; $x < strlen($value); $x++) {
$theDigit = substr($value, $x, 1);
if (!is_numeric($theDigit) && $theDigit != " " && $theDigit != "," && $theDigit != "." && $theDigit != "-") {
$isValid = false;
break;
}
}
if ($value == "") {
$isValid = false;
}
if (!is_numeric($value)) {
$isValid = false;
}
else {
if (($minLength !== "" && $minLength > $value) || ($maxLength !== "" && $maxLength < $value)) {
$isValid = false;
} else {
if ($allowDecimals !== "") {
$decCheck = strpos($startVal,$theDecimal);
$decCheck += $allowDecimals;
$decCheck += 2;
if (strpos($startVal,$theDecimal)!==false && ($decCheck <= strlen($startVal) || $allowDecimals === 0)) {
$isValid = false;
}
}
}
}
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidatePN($value,$areaCode,$international,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
$allowed = "*() -./_+".Chr(10).Chr(8);
$newVal = "";
if (!(!$required AND $value == "")) {
for ($x=0; $x < strlen($value); $x++) {
$z = substr($value,$x,1);
if (($z >= "0") && ($z <= "9")) {
$newVal = $newVal.$z;
} else {
if (strpos($allowed,$z) === false) {
$isValid = false;
}
}
}
if ($international) {
if (strlen($newVal) < 5) {
$isValid = false;
}
} else {
if (strlen($newVal) == 11) {
if (substr($newVal,0,1) != "1") {
$isValid = false;
}
} else {
if ((strlen($newVal) != 10 && strlen($newVal) != 7) || (strlen($newVal)==7 && $areaCode)) {
$isValid = false;
}
}
}
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateRX($value,$regExStr,$required,$number) {
$value = $value;
$WAFV_ErrorMessage = "";
$isValid = true;
$regExStr = str_replace("&quot;", '"', $regExStr);
if (!(!$required && $value=="")) {
$theMatch = preg_match($regExStr, $value);
if (!$theMatch) {
$isValid = false;
}
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateRQ($value,$trimWhite,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
if ($trimWhite) {
$value = WAtrimIt($value,0,0);
}
if (!isset($value) || $value === "") {
$isValid = false;
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateRT($value,$notAllowed,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
$augValue = " ".strtolower($value)." ";
$tempVal = $augValue;
if (!(!$required && $value=="")) {
$notAllowed = explode(", ", $notAllowed);
foreach ($notAllowed AS $x) {
if ($x != "") {
$notAllowedInfo = explode("|", $x);
$notAllowedInfo[0] = str_replace ("&quot;", "\"", $notAllowedInfo[0]);
$notAllowedInfo[1] = str_replace ("&quot;", "\"", $notAllowedInfo[1]);
if (!(strpos($tempVal, strtolower($notAllowedInfo[0]))===false)) {
$isValid = false;
break;
}
}
}
}
if ($required && $value=="")
$isValid = false;
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateSS($value,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
$allowed = "*() -./_\n\r+";
if (!(!$required && $value=="")) {
$newVal = "";
for ($x=0; $x < strlen($value); $x++) {
$z = substr($value, $x, 1);
if (($z >= "0") && ($z <= "9")) {
$newVal .= $z;
}
else {
if (strpos($allowed, $z) < 0) {
$isValid = false;
}
}
}
if (strlen($newVal) != 9) {
$isValid = false;
}
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateUnique($connName,$conn,$db,$tableName,$keyCol,$keyType,$keyValue,$filterCol,$filterType,$filterValue,$required,$number) {
$WAFV_ErrorMessage = ( ($required) ? WAValidateRQ($filterValue, true, $number) : "" );
if (!$WAFV_ErrorMessage) {
$isValid = true;
$WA_UniqueWhere = Validations_generateWhereClause(array($filterCol, $keyCol), array($filterType, $keyType), array($filterValue, $keyValue), array("=", "<>"));
$WA_UniqueSQL = "SELECT `".$keyCol."` FROM `".$tableName."` WHERE ".$WA_UniqueWhere->sqlWhereClause;
if (is_object($conn) && get_class($conn) == "mysqli") {
$WA_UniqueRS = mysqli_query($conn, $WA_UniqueSQL) or die(mysqli_error());
if ($WA_UniqueRS->num_rows > 0) {
$isValid = false;
}
} else {
mysql_select_db($db, $conn);
$WA_UniqueRS = mysql_query($WA_UniqueSQL, $conn) or die(mysql_error());
$WA_UniqueRows = mysql_num_rows($WA_UniqueRS);
if ($WA_UniqueRows) {
$isValid = false;
}
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
}
return $WAFV_ErrorMessage;
}
if (!function_exists("Validations_generateWhereClause")) {
class Validations_WhereClause {
var $sqlWhereClause;
function __construct($sqlWhereClause = "") {
$this->sqlWhereClause = $sqlWhereClause;
}
}
function Validations_generateWhereClause($fieldNameList, $columnTypeList, $fieldValueList, $comparisonList)
{
$obj = new Validations_WhereClause();
for ($i = 0; $i < sizeof($fieldNameList); $i++) {
$formVal = $fieldValueList[$i];
$WA_typesArray = explode(",", $columnTypeList[$i]);
$delim = ($WA_typesArray[0] != "none") ? $WA_typesArray[0] : "";
$altVal = ($WA_typesArray[1] != "none") ? $WA_typesArray[1] : "";
$emptyVal = ($WA_typesArray[2] != "none") ? $WA_typesArray[2] : "";
if ($formVal == "" || $formVal == "undefined") {
$formVal = $emptyVal;
} else {
if ($altVal != "") {
$formVal = $altVal;
} else if ($delim == "'") { // escape quotes
$formVal = "'".((!(preg_match("/(^|[^\\\\])'/", $formVal))) ? $formVal : addslashes($formVal));
if ($comparisonList[$i] == " LIKE ") $formVal .= "%";;
$formVal .= "'";
} else if ($delim == "") {
//numeric
if (is_numeric($formVal)) {
$formVal = "".floatval($formVal);
}
else {
$formVal = "0";
}
} else {
$formVal = $delim.Validations_clearOutSQLKeywords($formVal).$delim;
}
}
if (!($delim == "" && strpos($formVal,"()")>0)) {
if ($formVal == "NULL") {
$obj->sqlWhereClause .= (($i != 0) ? " AND " : "")."`". Validations_cleanUpColumnName($fieldNameList[$i])."`"." IS " .(($comparisonList[$i] == '<>')?"NOT ":"") .$formVal;
}
else {
$obj->sqlWhereClause .= (($i != 0) ? " AND " : "")."`". Validations_cleanUpColumnName($fieldNameList[$i])."`".Validations_cleanUpEquality($comparisonList[$i]).$formVal;
}
}
}
return $obj;
}
function Validations_cleanUpColumnName($colName) {
if (strpos($colName, ";") !== false) {
$colName = substr($colName, 0, strpos($colName, ";"));
}
if (strpos($colName, "(") !== false) {
$colName = substr($colName, 0, strpos($colName, "("));
}
if (strpos($colName, "=") !== false) {
$colName = substr($colName, 0, strpos($colName, "="));
}
return $colName;
}
function Validations_cleanUpEquality($tEquality) {
if (preg_replace('/^\\s*|\\s*$/', "", $tEquality) != "=") {
return Validations_cleanUpColumnName($tEquality);
}
return $tEquality;
}
function Validations_clearOutSQLKeywords($tString) {
if (strpos(strtolower($tString), "select") !== false) {
return "";
}
if (strpos(strtolower($tString), "drop") !== false) {
return "";
}
if (strpos(strtolower($tString), "alter") !== false) {
return "";
}
if (strpos(strtolower($tString), "create") !== false) {
return "";
}
if (strpos(strtolower($tString), "update") !== false) {
return "";
}
if (strpos(strtolower($tString), "insert") !== false) {
return "";
}
if (strpos(strtolower($tString), "delete") !== false) {
return "";
}
if (strpos(strtolower($tString), "'") !== false) {
return "";
}
if (strpos(strtolower($tString), "#") !== false) {
return "";
}
return $tString;
}
}
function WAValidateUR($value,$force,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
$valURL = $value;
if (!strpos($valURL, "://")===false) {
$valURL = substr($valURL, strpos($valURL, "://")+3);
}
if (strpos($valURL, "?")>0) {
$valURL = substr($valURL, 0,strpos($valURL, "?"));
}
if (!(!$required && preg_replace("/\s/", "", $valURL)=="")) {
if (strtolower($force) == "none") {
if (strpos($value, "://")!==false)
$isValid = false;
}
if (strpos($value, "?") != strrpos($value, "?") || !strpos($value, " ") === false) {
$isValid = false;
}
if ($isValid) {
if (!strpos($valURL, ";") === false || !strpos($valURL, "&") === false || !strpos($valURL, "=") === false || !strpos($valURL, ",") === false) {
$isValid = false;
}
}
if (strtolower($force) != "false" && strtolower($force) != "none" && $isValid) {
$force = preg_replace("/\\s*,\\s*/", ",", $force);
$force = explode(",", $force);
$isValid = false;
foreach ($force as $x) {
if (strpos(strtolower($value), strtolower($x))===0) {
$isValid = true;
break;
}
}
}
if ($isValid && strpos($valURL, ".") < 1)
$isValid = false;
if ($isValid) {
$tDomain = $valURL;
if (strpos($tDomain, ":") !== false) {
$tDomain = substr($tDomain, 0, strpos($tDomain, ":"));
$tPort = substr($valURL, strlen($tDomain)+1);
if (strpos($tDomain, "/") !== false) {
$isValid = false;
}
else {
if (strpos($tPort, "/") !== false) {
$tPort = substr($tPort, 0, strpos($tPort, "/"));
}
if (!is_numeric($tPort) && $tPort !== "") {
$isValid = false;
}
}
}
if ($isValid && strpos($tDomain, "/") !== false) {
$tDomain = substr($tDomain, 0, strpos($tDomain, "/"));
}
if ($isValid) {
$tDomainA = explode(".", $tDomain);
if (sizeof($tDomainA) < 2) {
$isValid = false;
}
else {
$ipMatch = "/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/";
if (preg_match($ipMatch,$tDomain)) {
if ($tDomainA[0] > 255 || $tDomainA[1] > 255 || $tDomainA[2] > 255 || $tDomainA[3] > 255) {
$isValid = false;
}
}
else {
if (strlen($tDomainA[sizeof($tDomainA)-1]) < 2 || strlen($tDomainA[sizeof($tDomainA)-2]) < 2) {
$isValid = false;
}
}
}
}
}
}
if ($isValid && $required && preg_replace("/\s/", "", $valURL)=="")
$isValid = false;
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
function WAValidateZC($value,$us5,$us9,$can6,$uk,$required,$number) {
$WAFV_ErrorMessage = "";
$isValid = true;
$allowed = "() -.\n\r";
$charVal = "";
if (!(!$required && $value=="")) {
$newVal = "";
$hasLetters = false;
for ($x=0; $x < strlen($value); $x++) {
$z = substr($value, $x, 1);
if (($z >= "0") && ($z <= "9")) {
$newVal .= $z;
$charVal .= "N";
}
else if (($uk || $can6) && ((($z >= "a") && ($z <= "z")) || (($z >= "A") && ($z <= "Z")))) {
$charVal .= "A";
$hasLetters = true;
}
else if (strpos($allowed, $z) < 0 || $x == 0 || $x == strlen($value)-1) {
$isValid = false;
}
}
$acceptPattern = ",";
if ($us5) {
$acceptPattern .= "NNNNN,";
}
if ($us9) {
$acceptPattern .= "NNNNNNNNN,";
}
if ($uk) {
$acceptPattern .= "ANNAA,ANNNAA,AANNAA,AANNNAA,ANANAA,AANANAA,";
}
if ($can6) {
$acceptPattern .= "ANANAN,";
}
if (strpos($acceptPattern,",".$charVal.",") === false)
$isValid = false;
if ($isValid && !$hasLetters && ($us5 || $us9)) {
if ($us5) {
$isValid = preg_match('/^\d{5}$/', $value);
}
if ($us9 && (($us5 && !$isValid) || !$us5)) {
$isValid = (preg_match('/^\d{5}[-\. ]\d{4}$/', $value) || preg_match('/^\d{9}$/', $value));
}
}
}
if (!$isValid) {
$WAFV_ErrorMessage .= ",".$number;
}
return $WAFV_ErrorMessage;
}
?>
@@ -0,0 +1,31 @@
<?php
@session_start();
function ValidatedField($page,$field,$encoded=true) {
$theFields= "";
$retVal = "";
if (isset($_SESSION["WAVT_".$page."_Errors"])) {
$theFields = "&".$_SESSION["WAVT_".$page."_Errors"];
}
if (strpos($theFields,"&WAVT_".$field."=") !== false) {
$retVal = substr($theFields,strpos($theFields,"&WAVT_".$field."=")+strlen("&WAVT_".$field."="));
} else if (strpos($theFields,"&WAVT_".$field."[0]=") !== false) {
$retVal = array();
$arrIndex = 0;
while (strpos($theFields,"&WAVT_".$field."[".$arrIndex."]=") !== false) {
$arrVal = substr($theFields,strpos($theFields,"&WAVT_".$field."[".$arrIndex."]=")+strlen("&WAVT_".$field."[".$arrIndex."]="));
if (strpos($arrVal,"&WAVT_") !== false) $arrVal = substr($arrVal,0,strpos($arrVal,"&WAVT_"));
$retVal[] = htmlspecialchars($arrVal);
$arrIndex++;
}
return $retVal;
}
if (strpos($retVal,"&WAVT_") !== false) {
$retVal = substr($retVal,0,strpos($retVal,"&WAVT_"));
}
if ($retVal == "" && $page == $field) {
$retVal = ValidatedField($page,$field."_Errors");
}
if ($encoded) $retVal = htmlspecialchars($retVal);
return $retVal;
}
?>
+78
View File
@@ -0,0 +1,78 @@
/*right triangle*/
.serverInvalidState {
display:none;
}
.validation-close {
font-size: 12px;
position: absolute;
right: 2px;
top: 2px;
cursor: pointer;
color: #FFFFFF;
border: 0px solid #FFFFFF;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px;
padding: 0px;
font-family: monospace;
font-weight: normal;
font-style: normal;
}
.Serene {
position:absolute;
padding:10px 15px 10px 5px ;
color:#FFFFFF;
background:#5d5c5c; /* default background for browsers without gradient support */
background-image: -webkit-gradient(linear, left top, right top, from(#5d5c5c), to(#5d5c5c));
background-image: -webkit-linear-gradient(left, #5d5c5c, #5d5c5c); /* For Chrome and Safari */
background-image: -moz-linear-gradient(left, #5d5c5c, #5d5c5c); /* For old Fx (3.6 to 15) */
background-image: -ms-linear-gradient(left, #5d5c5c, #5d5c5c); /* For pre-releases of IE 10*/
background-image: -o-linear-gradient(left, #5d5c5c, #5d5c5c); /* For old Opera (11.1 to 12.0) */
background-image: linear-gradient(to right, #5d5c5c, #5d5c5c); /* Standard syntax; must be last */
-webkit-border-radius:0px;
-moz-border-radius:0px;
border-radius:0px;
border: 0px solid #FFFFFF;
font-family: inherit;
font-size: inherit;
font-weight: undefined;
font-style: inherit;
max-width: 350em;
white-space: nowrap;
}
/* THE POINTER
------------------------------------------------------------------------------------------------------------------------------- */
.Serene-wrapper {
opacity:0.8;
position:absolute;
top:0;
left:0;
}
.Serene-before {
position:absolute;
border-style:solid;
display:block;
width:0;
border-width:20px 20px 20px 0; /* vary these values to change the angle of the vertex */
border-style:solid;
border-color:transparent #5d5c5c;
}
.Serene-after {
position:absolute;
content:"";
border:0;
border-width:0px 0 0 0px;
border-style:solid;
border-color:transparent #e0e0e0;
display:block;
width:0;
}
File diff suppressed because it is too large Load Diff
+815
View File
@@ -0,0 +1,815 @@
<?php
// version 2.31
if (!class_exists("WA_MySQLi_Query")) {
class WA_MySQLi_Query {
public function __construct($conn, $mrt = "mrt") {
$this->Action = "";
$this->UseAction = "";
$this->AffectedRows = 0;
$this->Connection = $conn;
$this->Debug = false;
$this->DieOnError = true;
$this->EncryptionAlgorithm = "blowfish";
$this->EncryptionKey = "Change Me";
$this->EncryptionMode = "cbc";
$this->Error = "";
$this->ErrorMessage = "There is an error in your SQL syntax.";
$this->ErrorNo = 0;
$this->FieldCount = 0;
$this->Filter = "";
$this->FilterValues = array();
$this->ID = 0;
$this->InsertID = 0;
$this->JavascriptRedirect = false;
$this->MRTField = $mrt;
$this->NumRows = 0;
$this->OnDuplicate = "";
$this->ParamColumns = array();
$this->ParamCount = 0;
$this->ParamDefaults = array();
$this->ParamTypes = array();
$this->ParamValues = array();
$this->Prepared = true;
$this->RelationalColumns = array();
$this->RelationalKeyColumn = false;
$this->RelationalRows = array();
$this->RelationalRowsFound = false;
$this->RepeatConditions = array();
$this->RepeatedParams = array();
$this->RepeatIndex = 0;
$this->SelectedResult = false;
$this->Salt = false;
$this->SaveAs = "";
$this->Statement = "";
$this->Table = "";
}
public function addFilter($filterColumn, $filterComparison, $filterType, $filterValue, $filterRepeat = false, $temporary = false) {
if ($filterType == 'i') {
if (strval(intval($filterValue)) != $filterValue) {
if ($this->Debug) {
die("incorrect INTEGER value: " . $filterValue);
} else {
die($this->ErrorMessage);
}
}
}
if ($filterType == 'd') {
if (strval(floatval($filterValue)) != $filterValue) {
if ($this->Debug) {
die("incorrect DOUBLE value: " . $filterValue);
} else {
die($this->ErrorMessage);
}
}
}
$this->FilterValues[] = array($filterColumn, $filterComparison, $filterType, $filterValue, $filterRepeat, $temporary);
}
private function addRelationalFilters() {
$filterValues = array();
for ($x=0; $x<sizeof($this->ParamColumns); $x++) {
if ($this->ParamColumns[$x][0] == $this->RelationalColumns[0] || $this->ParamColumns[$x][0] == $this->RelationalColumns[1]) {
$filterValues[] = array($this->ParamColumns[$x][0], "=", $this->ParamTypes[$x], $this->ParamValues[$x], false, true);
}
}
$this->FilterValues = $filterValues;
}
public function addRelationship($relationalParentColumn, $relationalChildColumn) {
$this->RelationalColumns = array($relationalParentColumn, $relationalChildColumn);
}
private function addQuerystring($url) {
if (empty($_SERVER['QUERY_STRING'])) return $url;
if (strpos($url,"?")!==false) return $url . "&" . $_SERVER['QUERY_STRING'];
return $url . "?" . $_SERVER['QUERY_STRING'];
}
public function bindColumn($paramColumn, $paramType, $paramValue, $paramDefault, $mrtParam = false) {
if ($this->isBound($paramColumn)) return;
if ($mrtParam && !is_array($paramValue)) {
$paramValue = array();
$toCheck = isset($_POST[$this->MRTField])?$_POST[$this->MRTField]:array();
for ($x=0; $x<sizeof($toCheck); $x++) {
if (isset($_POST[$mrtParam."_".$toCheck[$x]])) {
$paramValue[] = $_POST[$mrtParam."_".$toCheck[$x]];
} else {
$paramValue[] = "";
}
}
}
if (is_array($paramValue) && sizeof($paramValue) > 0) {
$this->RepeatedParams[] = array(sizeof($this->ParamColumns), $paramValue, false);
$paramValue = $paramValue[0];
}
$this->ParamColumns[] = array($paramColumn, false);
if ($paramType == "c") $paramType = "z";
$this->bindParam($paramType, $paramValue, $paramDefault);
}
private function bindDefault($paramType,$paramValue,$paramDefault) {
if ($paramValue === "" || $paramValue === NULL) {
if (($paramType == "d" || $paramType == "i") && $paramDefault == "WA_BLANK") $paramDefault = "WA_ZERO";
switch ($paramDefault) {
case "WA_BLANK":
case "WA_IGNORE":
case "WA_SKIP":
case "WA_DEFAULT":
case "WA_TIMESTAMP":
$paramValue = "";
break;
case "WA_NULL":
$paramValue = null;
break;
case "WA_CURRENT_TIMESTAMP":
$paramValue = date("Y-m-d H:i:s");
break;
case "WA_ZERO":
$paramValue = "0";
break;
case "WA_NO":
$paramValue = "N";
break;
default:
$paramValue = $paramDefault;
}
}
if ($paramType == "t") {
if ($paramValue) {
$hasTime = strpos($paramValue," ") !== false;
$paramValue = strtotime($paramValue);
if ($hasTime) {
$paramValue = date('Y-m-d H:i:s',$paramValue);
} else {
$paramValue = date('Y-m-d',$paramValue);
}
} else {
$paramValue = null;
}
} else if ($paramType == "c") {
$paramValue = "%" . $paramValue . "%";
} else if ($paramType == "b") {
$paramValue = $paramValue . "%";
} else if ($paramType == "e") {
$paramValue = "%" . $paramValue;
} else if ($paramType == "y") {
if ($paramValue) {
$paramValue = "Y";
} else {
$paramValue = "N";
}
} else if ($paramType == "n" || $paramType == "z") {
if ($paramValue) {
$paramValue = ($paramType == "n")?"-1":"1";
} else {
$paramValue = "0";
}
}
return $paramValue;
}
public function bindParam($paramType,$paramValue,$paramDefault="",$paramPosition=false) {
$paramArray = array($paramValue);
$isList = false;
if (strpos($paramType,"l")) {
$paramType = substr($paramType,0,1);
$paramArray = preg_split("/\s*\,\s*/", $paramValue);
$isList = true;
}
for ($x=0; $x<sizeof($paramArray); $x++) {
$paramValue = $paramArray[$x];
$paramValue = $this->bindDefault($paramType,$paramValue,$paramDefault);
if (($isList || sizeof($paramArray) > 1) && $x == 0) {
$sqlParts = explode("?",$this->Statement);
if (!preg_match("/\(\s*$/",$sqlParts[sizeof($this->ParamValues)]) && !preg_match("/^\s*\)/",$sqlParts[sizeof($this->ParamValues)+1])) {
$sqlParts[sizeof($this->ParamValues)] = $sqlParts[sizeof($this->ParamValues)] . "(";
$sqlParts[sizeof($this->ParamValues)+1] = ")" . $sqlParts[sizeof($this->ParamValues)+1];
}
$this->Statement = implode("?",$sqlParts);
}
if ($x>0) {
$sqlParts = explode("?",$this->Statement);
$sqlParts[sizeof($this->ParamValues)] = ", ?" . $sqlParts[sizeof($this->ParamValues)];
$this->Statement = implode("?",$sqlParts);
}
if ($paramPosition == false) {
$this->ParamTypes[] = $paramType;
$this->ParamValues[] = $paramValue;
$this->ParamDefaults[] = $paramDefault;
} else {
array_splice($this->ParamTypes, $paramPosition, 0, $paramType);
array_splice($this->ParamValues, $paramPosition, 0, $paramValue);
array_splice($this->ParamDefaults, $paramPosition, 0, $paramDefault);
}
}
}
public function checkRepeatConditions() {
for ($x=0; $x<sizeof($this->RepeatConditions); $x++) {
if (!(isset($_POST[$this->RepeatConditions[$x] . $this->RepeatIndex]) || isset($_GET[$this->RepeatConditions[$x] . $this->RepeatIndex]))) return false;
}
return true;
}
private function clearRepeatedFilters() {
for ($x=sizeof($this->RepeatedParams)-1; $x>=0; $x--) {
if ($this->RepeatedParams[$x][2]) {
array_splice($this->ParamValues, $this->RepeatedParams[$x][0], 1);
array_splice($this->ParamTypes, $this->RepeatedParams[$x][0], 1);
array_splice($this->ParamDefaults, $this->RepeatedParams[$x][0], 1);
array_splice($this->RepeatedParams, $x, 1);
}
}
}
private function clearTemporaryFilters() {
for ($x=sizeof($this->FilterValues)-1; $x>=0; $x--) {
if ($this->FilterValues[$x][5]) {
array_pop($this->ParamValues);
array_pop($this->ParamTypes);
array_pop($this->ParamDefaults);
array_pop($this->FilterValues);
}
}
}
private function clearTemporaryColumns() {
for ($x=sizeof($this->ParamColumns)-1; $x>=0; $x--) {
if ($this->ParamColumns[$x][1]) {
array_splice($this->ParamColumns, $x, 1);
array_splice($this->ParamTypes, $x, 1);
array_splice($this->ParamDefaults, $x, 1);
array_splice($this->ParamValues, $x, 1);
}
}
}
public function createStatement() {
$this->UseAction = $this->Action;
if (strtolower($this->UseAction) == "relational") {
if (!$this->RelationalRowsFound) {
$this->RelationalRowsFound = true;
if (!class_exists("WA_MySQLi_RS")) require(dirname(__FILE__) . "/" . "rsobj.php");
$KeyRS = new WA_MySQLi_RS("KeyRS",$this->Connection,0);
$KeyRS->setQuery("SHOW KEYS FROM " . $this->Table ." WHERE Key_name = 'PRIMARY'");
$KeyRS->execute();
$this->RelationalKeyColumn = $KeyRS->getColumnVal("Column_name");
if (!$this->RelationalKeyColumn) {
$ReplaceDelete = new WA_MySQLi_Query($this->Connection);
$ReplaceDelete->setQuery("DELETE FROM " . $this->Table);
if (sizeof($ReplaceDelete->FilterValues) >= 1) {
$ReplaceDelete->setFilter();
$ReplaceDelete->execute();
}
} else {
if (!$this->SelectedResult) {
$RelationalRS = new WA_MySQLi_RS("RelationalRS",$this->Connection,0);
$RelationalRS->setQuery("SELECT " . $this->RelationalColumns[1] . ", " .$this->RelationalKeyColumn. " FROM " . $this->Table);
$RelationalRS->FilterValues = array($this->getParentFilterFromRelational());
$RelationalRS->setFilter();
$RelationalRS->execute();
$this->SelectedResult = $RelationalRS;
}
for ($x=0; $x<sizeof($this->SelectedResult->Results); $x++) {
$this->RelationalRows[] = array($this->SelectedResult->Results[$x][$this->RelationalColumns[1]], false, $this->SelectedResult->Results[$x][$this->RelationalKeyColumn]);
}
}
}
$relationalChildValue = -1;
for ($x=0; $x<sizeof($this->ParamColumns); $x++) {
if ($this->ParamColumns[$x][0] == $this->RelationalColumns[1]) {
if (empty($this->ParamValues[$x])) {
$this->Statement = "";
return;
}
$relationalChildValue = $this->ParamValues[$x];
}
if ($this->ParamColumns[$x][0] == $this->RelationalColumns[0] && empty($this->ParamValues[$x])) {
$this->Statement = "";
return;
}
}
$childFound = false;
for ($x=0; $x<sizeof($this->RelationalRows); $x++) {
if ($relationalChildValue == $this->RelationalRows[$x][0]) {
$this->RelationalRows[$x][1] = true;
$childFound = true;
break;
}
}
if ($childFound) {
$this->addRelationalFilters();
$this->UseAction = "update";
} else {
$this->UseAction = "insert";
}
}
if (strtolower($this->UseAction) == "conditional") {
if (sizeof($this->FilterValues) > 0) {
if (!class_exists("WA_MySQLi_RS")) require(dirname(__FILE__) . "/" . "rsobj.php");
$ConditionalRS = new WA_MySQLi_RS("ConditionalRS",$this->Connection,1);
$ConditionalRS->setQuery("SELECT Count(*) AS RowCount FROM " . $this->Table);
$ConditionalRS->FilterValues = $this->FilterValues;
$ConditionalRS->setFilter();
$ConditionalRS->execute();
if ($ConditionalRS->getColumnVal("RowCount")) {
$this->UseAction = "update";
} else {
$this->FilterValues = array();
$this->UseAction = "insert";
}
} else {
$this->UseAction = "insert";
}
}
if (strtolower($this->UseAction) == "replace") {
if (sizeof($this->FilterValues) > 0) {
$ReplaceDelete = new WA_MySQLi_Query($this->Connection);
$ReplaceDelete->setQuery("DELETE FROM " . $this->Table);
$ReplaceDelete->FilterValues = $this->FilterValues;
$ReplaceDelete->setFilter();
$ReplaceDelete->execute();
}
$this->UseAction = "insert";
}
switch (strtolower($this->UseAction)) {
case "update":
$Columns = "";
$this->Statement = "UPDATE " . $this->Table . " SET ";
$oneAdded = false;
for ($x=0; $x<sizeof($this->ParamColumns); $x++) {
if (!(($this->ParamDefaults[$x] == "WA_IGNORE" || $this->ParamDefaults[$x] == "WA_SKIP") && ($this->ParamValues[$x] === "" || $this->ParamValues[$x] === false || $this->ParamValues[$x] === null))) {
if ($Columns != "") $Columns .= ", ";
$columnRef = $this->ParamColumns[$x][0];
if (strpos($columnRef,"`") == false && strpos($columnRef,"(") == false) $columnRef = '`'.$columnRef.'`';
$colPlaceholder = "?";
if ($this->ParamDefaults[$x] == "WA_DEFAULT" && ($this->ParamValues[$x] === "" || $this->ParamValues[$x] === null || $this->ParamValues[$x] === false)) $colPlaceholder = "DEFAULT";
if ($this->ParamDefaults[$x] == "WA_TIMESTAMP" && $this->ParamValues[$x] == "") $colPlaceholder = "SYSDATE()";
$Columns .= $columnRef . " = " . $colPlaceholder;
$oneAdded = true;
}
}
if (!$oneAdded) {
$this->Statement = false;
return;
}
$this->Statement .= $Columns;
break;
case "insert":
$Columns = "";
$Values = "";
$this->Statement = "INSERT ".($this->OnDuplicate == "ignore"?"IGNORE":"INTO")." " . $this->Table . " (";
$oneAdded = false;
$onDuplicate = "";
for ($x=0; $x<sizeof($this->ParamColumns); $x++) {
if (!(($this->ParamDefaults[$x] == "WA_IGNORE" || $this->ParamDefaults[$x] == "WA_SKIP") && ($this->ParamValues[$x] === "" || $this->ParamValues[$x] === null || $this->ParamValues[$x] === false))) {
if ($Columns != "") {
$Columns .= ", ";
$Values .= ", ";
}
$columnRef = $this->ParamColumns[$x][0];
if (strpos($columnRef,"`") == false && strpos($columnRef,"(") == false) $columnRef = '`'.$columnRef.'`';
$Columns .= $columnRef;
if ($this->ParamDefaults[$x] == "WA_DEFAULT" && ($this->ParamValues[$x] === "" || $this->ParamValues[$x] === null || $this->ParamValues[$x] === false)) {
$addValue = "DEFAULT";
} else if ($this->ParamDefaults[$x] == "WA_TIMESTAMP") {
$addValue = "SYSDATE()";
} else {
$addValue = "?";
}
$Values .= $addValue;
if ($this->OnDuplicate == "update") {
if ($onDuplicate != "") $onDuplicate .= ", ";
$onDuplicate .= $columnRef ."=" . $addValue;
}
$oneAdded = true;
}
}
if (!$oneAdded) {
$this->Statement = false;
return;
}
$this->Statement .= $Columns . ") VALUES (" . $Values . ")";
if ($this->OnDuplicate == "update") {
$this->ParamTypes= array_merge($this->ParamTypes, $this->ParamTypes);
$this->ParamValues = array_merge($this->ParamValues, $this->ParamValues);
$this->ParamDefaults = array_merge($this->ParamDefaults, $this->ParamDefaults);
$onDuplicate = " ON DUPLICATE KEY UPDATE " . $onDuplicate;
}
$this->Statement .= $onDuplicate;
break;
case "delete":
$this->Statement = "DELETE FROM " . $this->Table;
if (sizeof($this->ParamColumns) > 0) $this->Statement .= " WHERE ";
for ($x=0; $x<sizeof($this->ParamColumns); $x++) {
if ($x!=0) $this->Statement .= " AND ";
$columnRef = $this->ParamColumns[$x][0];
if (strpos($columnRef,"`") == false && strpos($columnRef,"(") == false) $columnRef = '`'.$columnRef.'`';
$colPlaceholder = "?";
$this->Statement .= $columnRef . " = " . $colPlaceholder;
}
break;
}
$this->setFilter();
}
public function debugSQL() {
$statement = $this->Statement;
$paramLen = 1;
for ($x=0; $x<sizeof($this->ParamValues); $x++) {
if (is_array($this->ParamValues[$x])) $paramLen = sizeof($this->ParamValues[$x]);
}
for ($x=0; $x<$paramLen; $x++) {
$params = ($this->getParams($x));
$paramTypes = $params[0];
$startStatement = "";
$endStatement = $statement;
for ($x=0; $x<strlen($paramTypes); $x++) {
$pos = strpos($endStatement, "?");
if ($pos !== false) {
$replace = $this->getSQLValue($params[$x+1],$paramTypes[$x],true);
$startStatement .= substr($endStatement,0,$pos) . $replace;
$endStatement = substr($endStatement, $pos + 1);
}
}
$statement = $startStatement . $endStatement;
}
$statement = $startStatement . $endStatement;
return $statement;
}
public function execute($allowTableOverwrite=false) {
$shouldRun = true;
$startStatement = $this->Statement;
while ($this->incrementRepeat()) {
if (sizeof($this->RepeatedParams) > 0) {
if (!$this->checkRepeatConditions()) {
continue;
}
$this->clearRepeatedFilters();
$this->resetRepeated();
}
if (!$startStatement) {
$this->clearTemporaryColumns();
$this->createStatement();
if (!$this->Statement) continue;
if ((strtolower($this->UseAction) == "delete" || strtolower($this->UseAction) == "update") && strpos($this->Statement," WHERE ") === false && !$allowTableOverwrite) {
continue;
}
}
if (in_array("WA_SKIP",$this->ParamValues)) continue;
if (!$this->Prepared) {
$statement = $this->Statement;
if (sizeof($this->ParamValues) > 0) {
$paramLen = 1;
for ($x=0; $x<sizeof($this->ParamValues); $x++) {
if (is_array($this->ParamValues[$x])) $paramLen = sizeof($this->ParamValues[$x]);
}
for ($x=0; $x<$paramLen; $x++) {
$params = ($this->getParams($x));
$paramTypes = $params[0];
$startStatement = "";
$endStatement = $statement;
for ($x=0; $x<strlen($paramTypes); $x++) {
$pos = strpos($endStatement, "?");
if ($pos !== false) {
$replace = $this->getSQLValue($params[$x+1],$paramTypes[$x]);
$startStatement .= substr($endStatement,0,$pos) . $replace;
$endStatement = substr($endStatement, $pos + 1);
}
}
$statement = $startStatement . $endStatement;
}
}
$query = $this->Connection->query($statement);
if ($query == false) {
if ($this->Debug) {
die($this->debugSQL() . "<BR><BR>" . mysqli_error($this->Connection));
} else {
if ($this->DieOnError) {
die($this->ErrorMessage);
} else {
$this->Error = $this->debugSQL() . "<BR><BR>" . mysqli_error($this->Connection);
}
}
} else {
$query = false;
}
} else {
if (sizeof($this->ParamTypes) && strpos($this->Statement,"?") !== false) {
$query = $this->Connection->Prepare($this->Statement);
if ($query == false) {
if ($this->Debug) {
die($this->debugSQL() . "<BR><BR>" . mysqli_error($this->Connection));
} else {
if ($this->DieOnError) {
die($this->ErrorMessage);
} else {
$this->Error = $this->debugSQL() . "<BR><BR>" . mysqli_error($this->Connection);
}
}
}
$paramLen = 1;
for ($x=0; $x<sizeof($this->ParamValues); $x++) {
if (is_array($this->ParamValues[$x])) $paramLen = sizeof($this->ParamValues[$x]);
}
for ($x=0; $x<$paramLen; $x++) {
call_user_func_array(array($query, "bind_param"),$this->paramRefs($this->getParams($x)));
$query->execute();
if ($query->errno) {
if ($this->Debug) {
die($this->debugSQL() . "<BR><BR>" . $query->error);
} else {
if ($this->DieOnError) {
die($this->ErrorMessage);
} else {
$this->Error = $this->debugSQL() . "<BR><BR>" . mysqli_error($this->Connection);
}
}
}
}
$this->clearTemporaryFilters();
} else {
$query = $this->Connection->query($this->Statement);
if ($query == false) {
if ($this->Debug) {
die($this->debugSQL() . "<BR><BR>" . mysqli_error($this->Connection));
} else {
if ($this->DieOnError) {
die($this->ErrorMessage);
} else {
$this->Error = $this->debugSQL() . "<BR><BR>" . mysqli_error($this->Connection);
}
}
} else {
$query = false;
}
}
}
if ($this->SaveAs != "" && strtolower($this->UseAction) == "insert") {
@session_start();
$_SESSION[$this->SaveAs] = $query?$query->insert_id:$this->Connection->insert_id;
}
$this->AffectedRows = $query?$query->affected_rows:$this->Connection->affected_rows;
$this->AffectedRows = ($this->AffectedRows===-1)?0:$this->AffectedRows;
$this->InsertID = $query?$query->insert_id:$this->Connection->insert_id;
$this->NumRows = $query?$query->num_rows:0;
$this->ParamCount = $query?$query->param_count:0;
$this->FieldCount = $query?$query->field_count:$this->Connection->field_count;
if (!$this->Error) $this->Error = $query?$query->error:$this->Connection->error;
$this->ErrorNo = $query?$query->errno:$this->Connection->errno;
$this->ID = $query?$query->id:$this->Connection->thread_id;
if ($query && method_exists($query,"close")) $query->close();
}
if (sizeof($this->RelationalRows)) {
$this->addRelationalFilters();
for ($x=0; $x<sizeof($this->RelationalRows); $x++) {
if ($this->RelationalRows[$x][1] == false) {
$CleanUpQuery = new WA_MySQLi_Query($this->Connection);
$CleanUpQuery->Statement = "delete FROM " . $this->Table . " WHERE " . $this->RelationalKeyColumn . " = " . $this->RelationalRows[$x][2];
$CleanUpQuery->execute();
}
}
}
}
private function getChildFilterFromRelational($row) {
for ($x=0; $x<sizeof($this->ParamColumns); $x++) {
if ($this->ParamColumns[$x][0] == $this->RelationalColumns[1]) {
return array($this->RelationalColumns[1], "=", $this->ParamTypes[$x], $this->RelationalRows[$row][0], false, true);
}
}
return array($this->RelationalColumns[0], "=", "i", "-1", false, true);
}
public function getSalt() {
$isStrong = false;
$this->Salt = base64_encode(openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->EncryptionAlgorithm),$isStrong));
}
public function getEncryptedVal($val) {
$retVal = $val;
$salt = "";
if ($this->Salt) $salt = base64_decode($this->Salt);
if ($retVal !== "") {
$retVal = base64_encode(openssl_encrypt($val,$this->EncryptionAlgorithm,$this->EncryptionKey, OPENSSL_RAW_DATA, $salt));
}
return $retVal;
}
private function getParentFilterFromRelational() {
for ($x=0; $x<sizeof($this->ParamColumns); $x++) {
if ($this->ParamColumns[$x][0] == $this->RelationalColumns[0]) {
return array($this->RelationalColumns[0], "=", $this->ParamTypes[$x], $this->ParamValues[$x], false, true);
}
}
return array($this->RelationalColumns[0], "=", "i", "-1", false, true);
}
private function getParams($index) {
$useParams = array();
$useTypes = array();
for ($x=0; $x<sizeof($this->ParamValues); $x++) {
$paramVal = is_array($this->ParamValues[$x])?$this->ParamValues[$x][$index]:$this->ParamValues[$x];
if (!(($paramVal === "" || $paramVal === null || $paramVal === false) && ($this->ParamDefaults[$x] == "WA_DEFAULT" || $this->ParamDefaults[$x] == "WA_IGNORE" || $this->ParamDefaults[$x] == "WA_SKIP" || $this->ParamDefaults[$x] == "WA_TIMESTAMP"))) {
$useParams[] = $paramVal;
$typesVal = $this->ParamTypes[$x];
if ($typesVal == "t" || $typesVal == "c" || $typesVal == "b" || $typesVal == "e" || $typesVal == "y") {
$typesVal = "s";
} else if ($typesVal == "n" || $typesVal == "z") {
$typesVal = "i";
} else if ($typesVal != "i" && $typesVal != "d" && $typesVal != "s" && $typesVal != "b") {
$typesVal = "s";
}
$useTypes[] = $typesVal;
}
}
return array_merge(array(implode("",$useTypes)), $useParams);
}
public function getSelected() {
if (!$this->SelectedResult) {
$RelationalRS = new WA_MySQLi_RS("RelationalRS",$this->Connection,0);
$RelationalRS->setQuery("SELECT " . $this->RelationalColumns[1] . ($this->RelationalKeyColumn?", " .$this->RelationalKeyColumn:""). " FROM " . $this->Table);
$RelationalRS->FilterValues = array($this->getParentFilterFromRelational());
$RelationalRS->setFilter();
$RelationalRS->execute();
$this->SelectedResult = $RelationalRS;
}
return $this->SelectedResult->getColumnArray($this->RelationalColumns[1]);
}
public function getSQLValue($val,$type,$forDebug=false) {
if (is_null($val)) {
$retval = "NULL";
} else if ($type == 'i') {
if (!$forDebug && strval(intval($val)) != $val) {
if ($this->Debug) {
die($this->debugSQL() . "<BR><BR>" . "Truncated incorrect INTEGER value: " . $val);
} else {
die($this->ErrorMessage);
}
}
$retval = intval($val);
} else if ($type == 'd') {
if (!$forDebug && strval(floatval($val)) != $val) {
if ($this->Debug) {
die($this->debugSQL() . "<BR><BR>" . "Truncated incorrect DOUBLE value: " . $val);
} else {
die($this->ErrorMessage);
}
}
$retval = floatval($val);
} else {
$retval = "'" . mysqli_real_escape_string($this->Connection,$val) . "'";
}
return $retval;
}
private function incrementRepeat() {
$this->RepeatIndex++;
$totalRepeats = 1;
// check action
if ($this->Action == "relational" && sizeof($this->RepeatedParams)>0) {
$totalRepeats = sizeof($this->RepeatedParams[0][1]);
} else {
for ($x=0; $x<sizeof($this->RepeatedParams); $x++) {
$totalRepeats *= sizeof($this->RepeatedParams[$x][1]);
}
}
return ($this->RepeatIndex <= $totalRepeats);
}
public function isBound($column) {
for ($x=0; $x<sizeof($this->ParamColumns); $x++) {
if ($this->ParamColumns[$x][0] == $column) return true;
}
return false;
}
public function paramRefs($arr) {
if (strnatcmp(phpversion(),'5.3') >= 0) {
$refs = array();
foreach($arr as $key => $value) $refs[$key] = &$arr[$key];
return $refs;
}
return $arr;
}
public function redirect($url,$keepQuerystring=false) {
if ($url) {
$url = str_replace("[InsertID]",$this->InsertID,$url);
$url = str_replace("[Insert_ID]",$this->InsertID,$url);
if ($keepQuerystring) {
if ($this->JavascriptRedirect) {
echo('<script>document.location.href="'.$this->addQuerystring($url).'";</script>');
} else {
header("location: " . $this->addQuerystring($url));
}
}
if ($this->JavascriptRedirect) {
echo('<script>document.location.href="'.$url.'";</script>');
} else {
header("location: " . $url);
}
die();
}
}
private function resetCombinations($arrays, $i = 0) {
if (!isset($arrays[$i])) {
return array();
}
if ($i == count($arrays) - 1) {
return $arrays[$i];
}
if ($this->Action === "relational") {
for ($x=0; $x<sizeof($arrays[0]); $x++) {
$row = array();
for ($y=0; $y<sizeof($arrays); $y++) {
$row[] = $arrays[$y][$x];
}
$result[] = $row;
}
} else {
$tmp = $this->resetCombinations($arrays, $i + 1);
$result = array();
foreach ($arrays[$i] as $v) {
foreach ($tmp as $t) {
$result[] = is_array($t) ?
array_merge(array($v), $t) :
array($v, $t);
}
}
}
return $result;
}
public function resetRepeated() {
$index = 0;
$combinations = array();
for ($x=0; $x<sizeof($this->RepeatedParams); $x++) {
$combinations[] = $this->RepeatedParams[$x][1];
}
$allParams = $this->resetCombinations($combinations);
for ($x=0; $x<sizeof($this->RepeatedParams); $x++) {
$newVal = $allParams[$this->RepeatIndex-1];
if (is_array($newVal)) $newVal = $newVal[$x];
if ($this->RepeatedParams[$x][2]) {
$this->bindParam($this->ParamColumns[$this->RepeatedParams[$x][0]],$this->ParamTypes[$this->RepeatedParams[$x][0]],$newVal,$this->ParamDefaults[$this->RepeatedParams[$x][0]]);
} else {
$this->ParamValues[$this->RepeatedParams[$x][0]] = $this->bindDefault($this->ParamTypes[$this->RepeatedParams[$x][0]],$newVal,$this->ParamDefaults[$this->RepeatedParams[$x][0]]);
}
}
}
public function saveInSession($varname) {
$this->SaveAs = $varname;
}
public function setFilter() {
if (sizeof($this->FilterValues) > 0) {
$this->Statement .= " WHERE ";
for ($x=0; $x<sizeof($this->FilterValues); $x++) {
if (!is_array($this->FilterValues[$x][3])) {
$filterValues = array($this->FilterValues[$x][3]);
} else {
$filterValues = $this->FilterValues[$x][3];
}
for ($y=0; $y<sizeof($filterValues); $y++) {
if ($x>0 && $y==0) $this->Statement .= " AND ";
if (sizeof($filterValues)>1 && $y==0) $this->Statement .= "(";
if ($y>0) $this->Statement .= ($this->FilterValues[$x][1] == "<>" || strtoupper($this->FilterValues[$x][1]) == "IS NOT")?" AND ":" OR ";
if ($this->FilterValues[$x][4]) $this->RepeatedParams[] = array(sizeof($this->ParamValues),$this->FilterValues[$x][4],true);
$columnRef = $this->FilterValues[$x][0];
if (strpos($columnRef,"`") == false && strpos($columnRef,"(") == false) $columnRef = '`'.$columnRef.'`';
if (strtoupper($this->FilterValues[$x][1]) == "IS" || strtoupper($this->FilterValues[$x][1]) == "IS NOT") {
$this->Statement .= $columnRef . " " . $this->FilterValues[$x][1] . " NULL";
} else {
$this->Statement .= $columnRef . " " . $this->FilterValues[$x][1] . " ?";
$this->bindParam($this->FilterValues[$x][2], strval($filterValues[$y]), "");
}
}
if (sizeof($filterValues)>1) $this->Statement .= ")";
}
}
}
public function setQuery($statement) {
$this->Statement = $statement;
}
public function setRepeatCondition($conditionalField) {
$this->RepeatConditions[] = $conditionalField;
}
}
}
?>
File diff suppressed because it is too large Load Diff