/*============================================================ 09/05/2006 A list of functions that I've created over a period of time This will probably grow as I need and will keep this upto date ============================================================*/ Please enter a To address"; } if($From=="") { $tmpMess="
  • Please enter a From address
  • "; } if($Subject=="") { $tmpMess="
  • Please enter a subject
  • "; } if($Body=="") { $tmpMess="
  • Please enter a body
  • "; } $Body=str_replace("\r\n","
    ",$Body); //Send the email $headers=""; if($Type==0) { $headers.= 'MIME-Version: 1.0' . "\r\n"; $headers.= 'Content-type: text/html; charset=is0-8859-1' . "\r\n"; } $headers.= 'From: From: ' . $From . "\r\n"; mail($To, $Subject, $Body, $headers) or die("Failed to send your email"); } /*================================================================================ SQL Values ================================================================================*/ public function SQLValue($sValue,$iType) { if(!empty($iType)) { if($sValue==='') { $sValue=NULL; } switch($iType) { case 1: $sValue="'".$sValue."',"; break; case 2: $sValue="'".$sValue."'"; break; case 3: $sValue.=","; break; } return $sValue; } else { echo "FUNCTION ERROR: SQLValue
    Please select a type"; exit(); } } /*================================================================================ Changes 1 = true / 2 || 0 = false ================================================================================*/ public function checkBox($sValue) { if(!isset($sValue)) { return "0"; } } /*================================================================================ Changes 1 = true / 2 || 0 = false ================================================================================*/ public function tf($sValue) { if(isset($sValue)) { switch($sValue) { case 1: //true $sValue='True'; break; case 2 && "0" : //false $sValue='False'; break; } return $sValue; } else { echo 'FUNCTION ERROR: tf
    Only pass 1 or 2 not ('.$sValue.')'; exit(); } } /*================================================================================ Sorts out checkbox by returning a string for checked or not ================================================================================*/ public function isChecked($iValue) { if(!isset($iValue)) { $this->displayError("ERROR: Function isChecked
    No value supplied"); } else { $sRet=""; switch($iValue) { case 1 : $sRet="checked=\"checked\""; break; } return $sRet; } } /*================================================================================ Date format ================================================================================*/ public function DateFormat($sValue,$iFormat=2) { $bGo='false'; $sMess=''; if(empty($sValue)) { $sMess='Please supply a date value to format (00001)'; } elseif(!empty($sValue) && $iFormat==4) { $sPattern='/(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[012])[\/](19|20)\d\d/'; if(preg_match($sPattern,$sValue,$match)) { $brk=explode('/',$sValue); $PutDate=$brk[2].'-'.$brk[1].'-'.$brk[0]; $bGo='true'; } else { echo 'FUNCTION ERROR: DateFormat
    Not a correct date format - '.$sValue.' - in regular expression (00002)'; exit(); } } elseif(!empty($sValue) && $iFormat!='') { $bGo='true'; } if($bGo=='true') { switch($iFormat) { case 1: $sValue=date("d/m/Y", strtotime($sValue)); break; case 2: $sValue=date("d/M/Y", strtotime($sValue)); break; case 3: $sValue=date("dmY", strtotime($sValue)); break; case 4: $sValue=$PutDate; break; case 5: $sValue=date("Y-m-d", strtotime($sValue)); break; case 6: $sValue=date("H:m:s", strtotime($sValue)); break; case 7: $sValue=date("d/M/Y - H:m:s", strtotime($sValue)); break; case 99: $sValue=date("H:00", strtotime($sValue)); break; } return $sValue; } else { echo 'FUNCTION ERROR: DateFormat
    '.$sMess; exit(); } } //================================================================================ // Get Current User //================================================================================ public function userID() { $arr=explode("\\",$_SERVER['REMOTE_USER']); return $arr[1]; } //================================================================================ // Validation checks //================================================================================ public function isValid($sValue,$iFormat) { if(!isset($sValue) || !isset($iFormat)) { $this->displayError("ERROR: function isValid
    No value ($sValue) or format ($iFormat) was sent"); } else { switch($iFormat) { case 1: //email if(!eregi(_EMAIL_PATTERN, $sValue)) $this->displayError("ERROR: Email ($sValue) is not valid"); break; case 2: //tel if(!eregi(_TEL_PATTERN,$sValue)) $this->displayError("ERROR: Telephone ($sValue) is not valid"); break; } } } //================================================================================ // Get the left/right number of characters from a string //================================================================================ public function getChar($Text,$iNum,$Type=0) { if(!isset($Text)) { $this->displayError("FUNCTION: getChar
    Please supply some text"); } if(!isset($iNum)) { $this->displayError("FUNCTION: getChar
    Please enter a numerical value"); } $iLen=strlen($Text); switch($Type) { case 1: $Text=substr($Text,0,$iNum); break; default: $Text=substr($Text,$iLen-$iNum,$iNum); } return $Text; } //================================================================================ // builds an array //================================================================================ public function accum($Array,$Key) { if(!array_key_exists($Key,$Array)) { $Array[$Key]=0; } $Array[$Key]++; } //================================================================================ // Function to break down returned records into an array //================================================================================ public function createArray($fs) { $arr=array(); if(mssql_num_rows($fs)>0) { while($g=mssql_fetch_array($fs)) { array_push($arr,$g[0]); } } return $arr; } //================================================================================ // Generate a unique code //================================================================================ public function genCode() { $sCode="0123456789abcdef"; $rndstring=''; for ($a = 0; $a <= strlen($sCode); $a++) { $b = rand(0, strlen($sCode) - 1); $rndstring .= $sCode[$b]; } return $rndstring; } //================================================================================ // Page redirect //================================================================================ public function PageRedirect($iDelay,$sFile,$sMess="") { echo($sMess); echo(""); } //================================================================================ // Create an A-Z link //================================================================================ public function createAZ($name="",$id="",$href="#") { $arrLet=explode(",","A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"); if($id!="") {$id=" id=\"$name\"";} //Build an A-Z list $sLink=""; for($i=0;$i".$arrLet[$i]."|"; } $sLink.="ALL"; return $sLink; } /*================================================================================ ================================================================================ File / Directory control ================================================================================ ================================================================================*/ //================================================================================ // Open a text file and return its contenct //================================================================================ function openFile($sFileName,$sMethod,$WriteText='') { if(!empty($sFileName)) { //echo realpath($sFileName); $file=fopen(realpath($sFileName),$sMethod) or die('Failed to open file'); return fread($file,filesize($sFileName)); } else { echo 'FUNCTION ERROR: openFile
    Please supply a file to open'; } } //================================================================================ // Check if a direcory exists and if not create it //================================================================================ public function createDir($sdirName,$sCode="0777") { $sPat="/[^a-zA-Z]{1,}/"; // Used to remove spaces / and _ from the folder names $tmpFolder=strtolower(preg_replace($sPat,"",$sdirName)); if(is_dir(_CAM_FOLDER.$tmpFolder)) { echo "Folder '$tmpFolder' already exists
    "; echo "Please go back and try again."; exit(); } mkdir(_CAM_FOLDER.$tmpFolder,$sCode); return $tmpFolder; } //================================================================================ // Deletes a directory //================================================================================ public function delDir($sdirName) { if(!is_dir(_CAM_FOLDER.$sdirName)) { echo "Folder '$sdirName' does not exist exists
    "; echo "Please go back and try again."; exit(); } rmdir(_CAM_FOLDER.$sdirName); } //================================================================================ // Deletes a directory //================================================================================ function deleteFiles($folder,$wild) { foreach(glob($folder.$wild) as $fn) { //echo $fn; unlink($fn); } } //================================================================================ // Function to check an email domain is valid, need to make use that the user // EVERYONE has access to cmd.exe and nslookup.exe //================================================================================ public function iisgetmxrr($sHostName, &$aMXHosts, &$aWeights = NULL) { $sNSLookup = shell_exec("nslookup -q=mx $sHostName 192.168.77.20 2>nul"); //echo $sNSLookup."
    "; preg_match_all("'^.*MX preference = (\d{1,10}), mail exchanger = (.*)$'simU", $sNSLookup, $aMXMatches); if (count($aMXMatches[2]) > 0) { array_multisort($aMXMatches[1], $aMXMatches[2]); $aMXHosts = $aMXMatches[2]; if (!is_null($aWeights)) { $aWeights = $aMXMatches[1]; } return true; } else { return false; } } //================================================================================ // Display error //================================================================================ public function displayError($sMess) { $page=$_SERVER["SCRIPT_NAME"]; echo $sMess."

    In page ".$page; echo '
    Please go back and try again'; exit(); } } ?>