| Current Path : /var/www/html/mmishra/indem/pks-ec/mbaentrance/website/includes/ |
| Current File : /var/www/html/mmishra/indem/pks-ec/mbaentrance/website/includes/function.inc.php |
<?php
//**** SITE FUNCTIONS ****//
function validate_admin() // Admin Validation
{
if($_SESSION['sess_admin_id'] == '')
{
$_SESSION['sessMsg'] = " Please login to administration suit. ";
header("location: adminLogin.php");
exit();
}
}
function validate_user() // User Validation
{
if(!($_SESSION['sess_id'] ))
{
if($_POST)
{
$_SESSION['post_value']=$_POST;
}
$_SESSION['go'] = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']){ $_SESSION['go'].="?".$_SERVER['QUERY_STRING']; }
$_SESSION['sessMsg'] = " You Need to login first. ";
header("location: index.php");
exit();
}
}
function validate_user_admin() // User and Admin Validation
{
if(!($_SESSION['sess_id']||$_SESSION['sess_admin_id']))
{
if($_POST)
{
$_SESSION['post_value']=$_POST;
}
$_SESSION['go'] = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']){ $_SESSION['go'].="?".$_SERVER['QUERY_STRING']; }
$_SESSION['sessMsg'] = " You Need to login first. ";
header("location: index.php");
exit();
}
}
function displaySessMesg()
{
$msg = "<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" align=\"center\">
<tr>
<td height='25' class='error'>$_SESSION[sessMsg]</td>
</tr>
</table>";
if($_SESSION['sessMsg']!= '')
{
echo $msg;
$_SESSION['sessMsg'] = "";
}
}
function dopaging($sql,$limit)
{
global $nume ;
global $pagingLimit ;
$pagingLimit = $limit ;
if($_REQUEST[nop])
{
$start=$pagingLimit*$_REQUEST[nop]-$pagingLimit;
}
else
{
$start=0;
}
global $checkStart;
$checkStart=$start+1;
$row=mysql_query($sql);
$nume=mysql_num_rows($row);
$sql = "$sql limit $start, $pagingLimit";
return $sql;
}
function rightPaging()
{
global $nume ;
global $pagingLimit ;
$pageName = basename($_SERVER['PHP_SELF']);
$str = "";
foreach( $_GET as $key=>$value)
{
if ($key=="nop")
{}
else
$str = $str."&".$key."=".$value;
}
foreach( $_POST as $key=>$value)
{
if ($key=="nop")
{}
else
$str = $str."&".$key."=".$value;
}
$pN = $_GET['nop'];
if($nume%$pagingLimit)
{
$nop=$nume/$pagingLimit;
$nop=ceil($nop);
}
else
{
$nop=$nume/$pagingLimit;
}
for($n=1;$n<=$nop;$n++)
{
if(($pN==$n) || ($n=='1' && !$pN && $nop!=1))
{
echo "<span class=\"nrml-txt4\">$n</span> ";
}
else
{
echo "<a href=\"$pageName?nop=$n&$str\" class=\"toplink\"><u>";
if($nop>1)
{
echo $n;
}
echo "</u></a> ";
}
}
}
function isFieldDuplicate($tableName='',$fieldName='',$filedValue='',$autoIdName='',$autoIdValue='',$isNullAllowed=false,$extra='')
{
$sql = " select * from $tableName where $fieldName = '$filedValue'";
if($autoIdName != '' and $autoIdValue != '')
{
$sql.= " and $autoIdName != '$autoIdValue' " ;
}
if($extra != '')
{
$sql.=" $extra ";
}
$isDuplicate = getSingleResult($sql);
if($isNullAllowed and $filedValue == '')
{
$isDuplicate = false ;
}
if($isDuplicate)
{
return true ;
}
else
{
return false ;
}
}
function getSingleResult($query)
{
$response = "";
global $LOCAL_MODE;
global $SUPPORT_EMAIL;
global $SITE_SUPPORT;
global $SITE_FULL_NAME;
if($LOCAL_MODE)
{
$result = mysql_query($query) or die("<center>An Internal Error has Occured. Please report following error to the webmaster.<br><br>".$query."<br><br>".mysql_error()."'</center>");
if ($line = mysql_fetch_array($result)) {
$response = $line[0];
}
}
else
{
$tm = mysql_query($query);
if($tm) {
if ($line = mysql_fetch_array($tm)) {
$response = $line[0];
}
}
else {
$errMsg="There is an error encountered in ".$SITE_FULL_NAME."<br><font size=2 color=red>You have an error(<font color=black>". mysql_error() . "</font>) in executing query : " . $query . " in file " . __FILE__ . " at line " . __LINE__ . "</font> on Page : ".$_SERVER['PHP_SELF'];
send_mail($SUPPORT_EMAIL,$subject='Error Message',$errMsg,$SITE_SUPPORT,'Error Message',$html=true);
header("location:mantinancePage.php");
exit();
}
}
return $response;
}
function send_mail($email_to,$subject,$message,$from_email,$from_name='',$html=false)
{
if($from_name == '')
{
$from_name=$from_email;
}
$headers1= "";
if($html)
{
$headers1.= "Content-type: text/html; charset=iso-8859-1\r\n";
}
else
{
$headers1.= "Content-type: text/plain; charset=iso-8859-1\r\n";
}
$headers1.= "From: $from_email\r\n";
@mail($email_to,$subject,$message,$headers1);
}
function getThumbName($picName,$type)
{
if($type == '1')
{
$thumbName = preg_replace("/\.([a-zA-Z]{3,4})$/","_thumb1.jpg",$picName);
}
elseif($type == '2')
{
$thumbName = preg_replace("/\.([a-zA-Z]{3,4})$/","_thumb2.jpg",$picName);
}
elseif($type == '3')
{
$thumbName = preg_replace("/\.([a-zA-Z]{3,4})$/","_thumb3.jpg",$picName);
}
elseif($type == '4')
{
$thumbName = preg_replace("/\.([a-zA-Z]{3,4})$/","_thumb4.jpg",$picName);
}
elseif($type == '5')
{
$thumbName = preg_replace("/\.([a-zA-Z]{3,4})$/","_thumb5.jpg",$picName);
}
return $thumbName;
}
function imgUpload($input,$location,$isThumb=false,$thWidth=100,$thHeight=100,$maxWidth='',$maxHeight='',$maxSize='',$chkExt='',$fieldName='')
{
$flag=false;
$return = array();
if($input['name']=="")
{
$return[0]=false;
$return[1]="Image name not found in form object!";
return $return;
}
else if($maxWidth!="" && $maxHeight!="")
{
list($w,$h,$type,$att)=@getimagesize($input['tmp_name']);
if($w <= $maxWidth && $h <= $maxHeight)
{
$flag=true;
}
else
{
$return[0]=false;
$return[1]="Image width or height did not matched. Image size should be less then ".$maxWidth."x".$maxHeight." !";
return $return;
}
}
else if($maxSize!="")
{
if($input['size'] <= $maxSize )
{
$flag=true;
}
else
{
$return[0]=false;
$return[1]="Image size exceed than maximum size=".$maxSize." !";
return $return;
}
}
else
{
$flag=true;
}
if($flag)
{
//echo $location;
if(!is_dir($location))
{
mkdir($location,0777);
}
$Ext=explode(".",$input['name']);
$ext=$Ext[count($Ext)-1];
if(is_array($chkExt))
{
if(in_array($ext,$chkExt))
{
$ranno1=getRandomStr(7);
$filen=$ranno1.".".$ext;
$filename=$location.$ranno1.".".$ext;
$tempfile=$input['tmp_name'];
if(!copy($tempfile,$filename)) {
$return[0]=false;
$return[1]="Problem in file. Cannot be copied!";
return $return;
}
if($isThumb)
{
$image = resizeImg($filename, $thWidth ,$thHeight, false, 100, 0,"_thumb");
$image = resizeImg($filename, '65' , '60', false, 100, 0,"_thumbS");
$image = resizeImg($filename, '138' , '182', false, 100, 0,"_thumbM");
$image = resizeImg($filename, '269' , '247', false, 100, 0,"_thumbL");
}
$return[0]=true;
$return[1]=$filen;
$return[2]=$ranno1."_thumb.jpg";
return $return;
}
else
{
$strExt = @implode(",",$chkExt);
$return[0]=false;
if($fieldName)
{
$return[1]="Please upload valid file. You can only upload ".$fieldName." with extension ".$strExt;
}
else
{
$return[1]="Please upload valid file. You can only upload file with extension ".$strExt;
}
return $return;
}
}
}
}
function getUserName($userId)
{
$sql="Select userName from tbl_register where userId='$userId'";
$userName=getSingleResult($sql);
return $userName;
}
function getRandomStr($length) {
// if you want extended ascii, then add the characters to the array
$characters = array('0','1','2','3','4','5','6','7','8','9');
$random_str = "";
for ($i = 0; $i < $length; $i++) {
srand((double)microtime()*1000000);
$random_chr = round(rand(0, count($characters)-1));
$random_str .= $characters[$random_chr];
}
return ($random_str);
}
function getCountrycombo($comboName='',$class='',$selectedValue='',$extra='')
{
$sqlSelect="select *from tbl_country order by countryId asc";
$result=$this->mysql_query($sqlSelect);
$combo="<select name='$comboName' id='$comboName' $extra";
if($class!='')
{
$combo.="class='$class'>";
}
else
{
$combo.=">";
}
$combo.="<option value='' selected>----Selected Any----</option>";
while($row=mysql_fetch_array($result))
{
if($selectedValue==$row['country'])
{
$selectedText= "selected";
}
else
{
$selectedText="";
}
$combo.="<option value='$row[country]' $selectedText > $row[country] </option>";
}
$combo.="</select>";
return $combo;
}
function getUsercombo($comboName='',$class='',$selectedValue='',$extra='')
{
//echo $selectedValue; exit;
$sqlSelect="select * from tbl_register order by userId asc";
$result=mysql_query($sqlSelect);
$combo="<select name='$comboName' id='$comboName' $extra";
if($class!='')
{
$combo.="class='$class'>";
}
else
{
$combo.=">";
}
$combo.="<option value='' selected>----Selected Any----</option>";
while($row=mysql_fetch_array($result))
{ //echo $selectedValue;
if($selectedValue==$row['userId'])
{
$selectedText= "selected";
}
else
{
$selectedText="";
}
$combo.="<option value='$row[userId]' $selectedText > $row[userName] </option>";
}
$combo.="</select>";
return $combo;
}
function getComboSimple($arrName,$comboName='',$class='',$selectedValue = '', $extra = '')
{
$combo="<select name='$comboName' id='$comboName' $extra ";
if($class != '')
{
$combo.="class='$class' >";
}else
{
$combo.=">";
}
$combo.="<option value='' selected>--Select Any--</option>";
foreach($arrName as $key=>$value)
{
if ($selectedValue == $key)
{
$selectedText = "selected";
}
else
{
$selectedText = '';
}
$combo.="<option value='$key' $selectedText > $value </option>";
}
$combo.="</select>";
return $combo ;
}
function concatSql($isSql=false,$sqlVal='',$tblField='',$requestField='',$method='',$whCondition='and',$whOpreator='=')
{
if($isSql)
{
$sql= $sqlVal ;
}
else
{
if($tblField != '' && $requestField != '' && $method != '')
{
$arrMethod = array
(
'get'=>$_GET[$requestField],
'post'=>$_POST[$requestField],
'request'=>$_REQUEST[$requestField]
);
$tmpVar = $arrMethod[$method];
if($tmpVar != '')
{
if($whOpreator == 'like')
{
$sql = $whCondition." ".$tblField." ".$whOpreator." '%".$tmpVar."%' ";
}
else
{
$sql = $whCondition." ".$tblField." ".$whOpreator." '".$tmpVar."' ";
}
}
}
}
return $sql;
}
function dateCombo($name='',$class,$selected='')
{
if($name == '')
{
$name = "date_combo";
}
$dcombo="<select name='$name' class='$class'>";
$dcombo.="<option value='00'>DD</option>";
for($i=1;$i<=31;$i++)
{
$day_val=date("d",mktime(0,0,0,1,$i,date("Y")));
$dcombo.="<option value='$day_val' ";
//echo $selected;
if(abs($i)==$selected)
{
$dcombo.="selected ";
}
if($i<10)
{
$i="0".$i;
}
$dcombo.=">$i</option>";
}
$dcombo.="</select>";
return $dcombo ;
}
function dateComboByYrMonth($name='',$class,$selected='',$selectedMonth='',$selectedYear='')
{
if($name == '')
{
$name = "date_combo";
}
if($selectedMonth && $selectedYear)
{
$mth=$selectedMonth+1;
$yr=$selectedYear;
}
else
{
$mth=date("m")+1;
$yr=date("Y");
}
$daynum = date("t",mktime(0,0,0,$mth,0,$yr));
$dcombo="<select name='$name' class='$class'>";
$dcombo.="<option value='00'>DD</option>";
for($i=1;$i<=$daynum;$i++)
{
$day_val=date("d",mktime(0,0,0,1,$i,date("Y")));
$dcombo.="<option value='$day_val' ";
if(abs($i)==$selected)
{
$dcombo.="selected ";
}
if($i<10)
{
$i="0".$i;
}
$dcombo.=">$i</option>";
}
$dcombo.="</select>";
return $dcombo ;
}
function monthCombo($name='',$class,$selected='')
{
if($name == '')
{
$name = "month_combo";
}
//$j=$start_month;
$mcombo="<select name='$name' class='$class'>";
$mcombo.="<option value='00'>MM</option>";
for($i=1;$i<=12;$i++)
{
$mon=date("M",mktime(0,0,0,$i,1,date("Y")));
$mon_val=date("m",mktime(0,0,0,$i,1,date("Y")));
$mcombo.="<option value='$mon_val' ";
if($mon_val==$selected)
{
$mcombo.="selected ";
}
$mcombo.=">$mon</option>";
}
$mcombo.="</select>";
return $mcombo ;
}
function yearCombo($name='',$start_year='',$end_year='',$class,$selected='')
{
if($name == '')
{
$name = "year_combo";
}
if($end_year=="")
{
$end_year=date(Y);
}
$ycombo="<select name='$name' class='$class'>";
$ycombo.="<option value='0000'>YY</option>";
for($i=$start_year;$i<=$end_year;$i++)
{
$ycombo.="<option value='$i' " ;
if($i==$selected)
{
$ycombo.= "selected";
}
$ycombo.="> $i </option>";
}
$ycombo.="</select>";
return $ycombo ;
}
function isFieldDuplicateEntry($studentName='',$fatherName='',$dob='',$autoIdName='',$autoIdValue='',$isNullAllowed=false,$extra='')
{
$sql = " select * from tbl_record where studentName = '$studentName' && fatherName='$fatherName' && dob='$dob'";
if($autoIdName != '' and $autoIdValue != '')
{
$sql.= " and $autoIdName != '$autoIdValue' " ;
}
if($extra != '')
{
$sql.=" $extra ";
}
//echo $sql;
$sqlResult = mysql_query($sql);
if ($lineRecord = mysql_fetch_array($sqlResult))
{
$isDuplicate = $lineRecord[0];
}
if($isNullAllowed and $filedValue == '')
{
$isDuplicate = false ;
}
if($isDuplicate)
{
return true ;
}
else
{
return false ;
}
}
function getRollNoCountRecordId($districtName)
{
$sqlSelectQuery="Select count(recordId) from tbl_record where districtName='$districtName'";;
$sqlResultQuery=mysql_query($sqlSelectQuery);
if ($line = mysql_fetch_array($sqlResultQuery))
{
$countRecord = $line[0];
}
return $countRecord;
}
function getRollNoByDistrictName($districtName,$countRecord)
{
$rollNo=incRollNo($districtName,$countRecord);
$recordId=getRecordByRollNoGiven($rollNo);
//echo "-->";
if($recordId)
{
$countRecordRollNo=$countRecord+1;
$countRecordRollNo=str_pad($countRecordRollNo, 4, "0", STR_PAD_LEFT);
$rollNo1=$districtName.'-'.$countRecordRollNo;
$rollNo=getRollNoByDistrictName($districtName,$countRecordRollNo);
}
else
{
$rollNo=$rollNo;
}
return $rollNo;
//exit;
}
function incRollNo($districtName,$countRecord)
{
//$countRecord=getRollNoCountRecordId;
$countRecordRollNo=$countRecord+1;
$countRecordRollNo=str_pad($countRecordRollNo, 4, "0", STR_PAD_LEFT);
$rollNo=$districtName.'-'.$countRecordRollNo;
return $rollNo;
}
function getRecordByRollNoGiven($rollNo)
{
$sqlRoll="SELECT recordId from tbl_record where rollNo='$rollNo'";
$sqlResultRoll=mysql_query($sqlRoll);
if ($lineRecord = mysql_fetch_array($sqlResultRoll))
{
$recordId = $lineRecord[0];
}
return $recordId;
}
function getDistrictNameByCode($districtCode)
{
$sqlDisName="SELECT districtName from tbl_district where districtCode='$districtCode'";
$sqlResultDN=mysql_query($sqlDisName);
if ($lineRecord = mysql_fetch_array($sqlResultDN))
{
$districtName = $lineRecord[0];
}
return $districtName;
}
function getDateFormat($value)
{
if(strstr($value,"-"))
{
$fromTs=strtotime($value);
}
else
{
$fromTs=$value;
}
return date("M j, Y",$fromTs);
}
function getDistrictName($code)
{
$sql="Select districtName from tbl_district where districtCode='$code'";
$userName=getSingleResult($sql);
return $userName;
}
?>