function redirect($sPage, $sError = "") { if ($sError != "") $_SESSION["Flag"] = $sError; if ($sPage == "") $sPage = SITE_URL; header("Location: $sPage"); exit( ); } function exitPopup($bRightsIssue = false, $sMessage = "") { $sClass = "error"; $sMessage = (($sMessage == "") ? "An ERROR occured while processing your request, please try again." : $sMessage); if ($bRightsIssue == true) { $sClass = "info"; $sMessage = "You don't have Rights to access the requested section. Please contact the Website Administrator for details."; } ?> exit( ); } function formValue($sValue) { return htmlentities($sValue, ENT_QUOTES, 'UTF-8'); } function formatDate($sDate, $sFormat = "d-M-Y") { if ($sDate == "" || $sDate == "0000-00-00" || $sDate == "1970-01-01" || $sDate == "0000-00-00 00:00" || $sDate == "0000-00-00 00:00:00" || $sDate == "1970-01-01 00:00:00") return ""; else return date($sFormat, strtotime($sDate)); } function formatTime($sTime, $sFormat = "h:i A") { if ($sTime == "" || $sTime == "00:00:00") return ""; else return date($sFormat, strtotime($sTime)); } function seconds2Time($iSeconds) { return (str_pad(intval(intval($iSeconds / 3600)), 2, "0", STR_PAD_LEFT).":".str_pad(intval(($iSeconds / 60) % 60), 2, "0", STR_PAD_LEFT).":".str_pad(intval($iSeconds % 60), 2, "0", STR_PAD_LEFT)); } function getTime($sTime) { if (trim($sTime) == "") return "00:00:00"; if (strlen($sTime) == 8 && $sTime{2} == ":" && $sTime{5} == ":") return $sTime; if (strlen($sTime) == 5 && $sTime{2} == ":") return "{$sTime}:00"; if (strlen($sTime) == 8 && $sTime{2} == ":" && $sTime{5} == " " && (strtoupper(substr($sTime, 6, 2)) == "AM" || strtoupper(substr($sTime, 6, 2)) == "PM")) { @list($sTime, $sAmPm) = @explode(" ", $sTime); if ($sAmPm == "PM") { @list($sHours, $sMinutes) = @explode(":", $sTime); if ($sHours!= 12) { $sHours = (intval($sHours) + 12); }else{ $sHours = (intval($sHours)); } return "{$sHours}:{$sMinutes}:00"; } return "{$sTime}:00"; } return date("h:i:00", strtotime($sTime)); } function formatNumber($sNumber, $bDecimals = true, $iDecimals = 2) { if ($bDecimals == false) $iDecimals = 0; return @number_format($sNumber, $iDecimals, '.', ','); } function createImage($sSrcFile, $sDestFile, $iImgWidth, $iImgHeight) { @list($iWidth, $iHeight, $sType, $sAttributes) = @getimagesize($sSrcFile); $fRatio = @($iWidth / $iHeight); $iPosition = @strrpos($sSrcFile, '.'); $sExtension = @substr($sSrcFile, $iPosition); switch($sExtension) { case '.jpg' : $objPicture = @imagecreatefromjpeg($sSrcFile); break; case '.jpeg' : $objPicture = @imagecreatefromjpeg($sSrcFile); break; case '.png' : $objPicture = @imagecreatefrompng($sSrcFile); break; case '.gif' : $objPicture = @imagecreatefromgif($sSrcFile); break; } // Resize, Cener & Crop if ($_SESSION['ImageResize'] == "C") { if (@($iImgWidth / $iImgHeight) > $fRatio) { $iNewWidth = $iImgWidth; $iNewHeight = @($iImgWidth / $fRatio); } else { $iNewWidth = ($iImgHeight * $fRatio); $iNewHeight = $iImgHeight; } $iMidX = @($iNewWidth / 2); $iMidY = @($iNewHeight / 2); $iLeft = @($iMidX - ($iImgWidth / 2)); $iTop = @($iMidY - ($iImgHeight / 2)); $objTemp = @imagecreatetruecolor($iNewWidth, $iNewHeight); if ($sExtension == ".png" || $sExtension == ".gif") { @imagealphablending($objTemp, false); @imagesavealpha($objTemp,true); @imagecolortransparent($objTemp, @imagecolorallocatealpha($objTemp, 0, 0, 0, 127)); } @imagecopyresampled($objTemp, $objPicture, 0, 0, 0, 0, $iNewWidth, $iNewHeight, $iWidth, $iHeight); $objThumb = @imagecreatetruecolor($iImgWidth, $iImgHeight); if ($sExtension == ".png" || $sExtension == ".gif") { @imagealphablending($objThumb, false); @imagesavealpha($objThumb,true); @imagecolortransparent($objThumb, @imagecolorallocatealpha($objThumb, 0, 0, 0, 127)); } @imagecopyresampled($objThumb, $objTemp, 0, 0, $iLeft, $iTop, $iImgWidth, $iImgHeight, $iImgWidth, $iImgHeight); } // Resize & Fit to Size else { $iNewWidth = $iImgWidth; $iNewHeight = $iImgHeight; $iLeft = 0; $iTop = 0; if (@($iNewWidth / $iNewHeight) > $fRatio) $iNewWidth = ($iNewHeight * $fRatio); else $iNewHeight = @($iNewWidth / $fRatio); if ($iNewWidth < $iImgWidth) $iLeft = @ceil(($iImgWidth - $iNewWidth) / 2); if ($iNewHeight < $iImgHeight) $iTop = @ceil(($iImgHeight - $iNewHeight) / 2); $objTemp = @imagecreatetruecolor($iNewWidth, $iNewHeight); if ($sExtension == ".png" || $sExtension == ".gif") { @imagealphablending($objTemp, false); @imagesavealpha($objTemp,true); @imagecolortransparent($objTemp, @imagecolorallocatealpha($objTemp, 0, 0, 0, 127)); } @imagecopyresampled($objTemp, $objPicture, 0, 0, 0, 0, $iNewWidth, $iNewHeight, $iWidth, $iHeight); $objThumb = @imagecreatetruecolor($iImgWidth, $iImgHeight); if ($sExtension == ".png" || $sExtension == ".gif") { @imagealphablending($objThumb, false); @imagesavealpha($objThumb,true); @imagecolortransparent($objTemp, @imagecolorallocatealpha($objThumb, 0, 0, 0, 127)); } else @imagefill($objThumb, 0, 0, @imagecolorallocate($objThumb, 255, 255, 255)); @imagecopy($objThumb, $objTemp, $iLeft, $iTop, 0, 0, $iNewWidth, $iNewHeight); } if ($sExtension == ".png") @imagepng($objThumb, $sDestFile, 9); else if ($sExtension == ".gif") @imagegif($objThumb, $sDestFile); else @imagejpeg($objThumb, $sDestFile, 100); @imagedestroy($objTemp); @imagedestroy($objThumb); @imagedestroy($objPicture); } function parseExamComments($sComments, $sStudent, $sRegistrationNo, $sGender) { $sComments = str_replace("[NAME]", strtoupper($sStudent), $sComments); $sComments = str_replace("[REGISTRATION_NO]", $sRegistrationNo, $sComments); $sComments = str_replace("[HE_SHE]", (($sGender == "Male") ? "HE" : "SHE"), $sComments); $sComments = str_replace("[HIS_HER]", (($sGender == "Male") ? "HIS" : "HER"), $sComments); $sComments = str_replace("[HIM_HER]", (($sGender == "Male") ? "Him" : "HER"), $sComments); $sComments = str_replace("[HIMSELF_HERSELF]", (($sGender == "Male") ? "HIMSELF" : "HERSELF"), $sComments); $sComments = str_replace("[MAN_WOMAN]", (($sGender == "Male") ? "MAN" : "WOMAN"), $sComments); $sComments = str_replace("[name]", strtolower($sStudent), $sComments); $sComments = str_replace("[registration_no]", $sRegistrationNo, $sComments); $sComments = str_replace("[he_she]", (($sGender == "Male") ? "he" : "she"), $sComments); $sComments = str_replace("[his_her]", (($sGender == "Male") ? "his" : "her"), $sComments); $sComments = str_replace("[him_her]", (($sGender == "Male") ? "him" : "her"), $sComments); $sComments = str_replace("[himself_herself]", (($sGender == "Male") ? "himself" : "herself"), $sComments); $sComments = str_replace("[man_woman]", (($sGender == "Male") ? "man" : "woman"), $sComments); $sComments = str_replace("[Name]", ucwords(strtolower($sStudent)), $sComments); $sComments = str_replace("[Registration_No]", $sRegistrationNo, $sComments); $sComments = str_replace("[He_She]", (($sGender == "Male") ? "He" : "She"), $sComments); $sComments = str_replace("[His_Her]", (($sGender == "Male") ? "His" : "Her"), $sComments); $sComments = str_replace("[Him_Her]", (($sGender == "Male") ? "Him" : "Her"), $sComments); $sComments = str_replace("[Himself_Herself]", (($sGender == "Male") ? "Himself" : "Herself"), $sComments); $sComments = str_replace("[Man_Woman]", (($sGender == "Male") ? "Man" : "Woman"), $sComments); return $sComments; } function getExcelCol($iColumn) { $iColumn = (($iColumn < 0) ? 0 : $iColumn); $sColumn = chr(($iColumn % 26) + 65); $iQuotient = @floor($iColumn / 26); while ($iQuotient > 0) { $sColumn .= chr(($iQuotient % 26) + (($iQuotient % 26) == 0 ? 90 : 64)); $iQuotient -= 26; $iQuotient = @ceil($iQuotient / 26); } return strrev($sColumn); } function getFeeBill($iBillId) { return str_pad($iBillId, 6, '0', STR_PAD_LEFT); } function calculateIncomeTax($iMonth, $iYear, $iAnnualSalary, $iPaidTax = 0, $sDob = "0000-00-00") { $iAnnualTax = calculateAnnualTax($iAnnualSalary, $iMonth, $iYear, $sDob); $iPayableTax = ($iAnnualTax - $iPaidTax); $iRemainingMonths = (($iMonth >= 7) ? (19 - $iMonth) : (7 - $iMonth)); $iMonthlyTax = @round($iPayableTax / $iRemainingMonths); if (@round($iMonthlyTax * $iRemainingMonths) > $iPayableTax) $iMonthlyTax -= @round(($iMonthlyTax * $iRemainingMonths) - $iPayableTax); else if (@round($iMonthlyTax * $iRemainingMonths) < $iPayableTax) $iMonthlyTax += @round($iPayableTax - ($iMonthlyTax * $iRemainingMonths)); return $iMonthlyTax; } function getAgeYears($sDob, $sToday = "") { if ($sToday == "" || $sToday == "0000-00-00") $sToday = date("Y-m-d"); @list($iYear, $iMonth, $iDay) = @explode("-", date("Y-n-j", strtotime($sToday))); @list($iDobYear, $sDobMonth, $sDobDay) = @explode("-", $sDob); $iDobMonth = intval($sDobMonth); $iDobDay = intval($sDobDay); $iYearDiff = ($iYear - $iDobYear); if ($iMonth <= $iDobMonth) { if ($iMonth == $iDobMonth) { if ($iDay < $iDobDay) $iYearDiff --; } else $iYearDiff --; } return $iYearDiff; } function numberToWord($iNumber) { if (($iNumber < 0) || ($iNumber > 999999999)) return $iNumber; $iMillions = @floor($iNumber / 1000000); /* Millions */ $iNumber -= $iMillions * 1000000; $iLacs = @floor($iNumber / 100000); /* Lac */ $iNumber -= $iLacs * 100000; $iThousands = @floor($iNumber / 1000); /* Thousands */ $iNumber -= $iThousands * 1000; $iHundreds = @floor($iNumber / 100); /* Hundreds */ $iNumber -= $iHundreds * 100; $iTens = @floor($iNumber / 10); /* Tens */ $iOnes = $iNumber % 10; /* Ones */ $sWords = ""; if ($iMillions > 0) $sWords .= (numberToWord($iMillions)." Million"); if ($iLacs > 0) $sWords .= ((($sWords != "") ? "" : " ").numberToWord($iLacs)." Lac "); if ($iThousands > 0) $sWords .= ((($sWords != "") ? "" : " ").numberToWord($iThousands)." Thousand "); if ($iHundreds > 0) $sWords .= ((($sWords != "") ? "" : " ").numberToWord($iHundreds)." Hundred "); $sOnes = array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"); $sTens = array("", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eigthy", "Ninety"); if ($iTens > 0 || $iOnes > 0) { if ($sWords != "") $sWords .= " and "; if ($iTens < 2) $sWords .= $sOnes[(($iTens * 10) + $iOnes)]; else { $sWords .= $sTens[$iTens]; if ($iOnes) $sWords .= ("-".$sOnes[$iOnes]); } } if ($sWords == "") $sWords = "zero"; return $sWords; } function showPaging($sPageUrl, $iPageCount, $iPageNo, $sParams = "") { if ($iPageCount <= 1) return; $sUrl = ("{$sPageUrl}?PageNo=[PageNo]".(($sParams != "") ? "&" : "").$sParams); ?>