Current File : /home/inlingua/www/icentex/general_admin_leave/leaves_non_teach.main.php
<?php
ob_start();
session_start();
date_default_timezone_set('Asia/Calcutta');
// Copyright, Panalink Infotech Limited. Created on: 17-03-2011

// Include the database connection details
require('../dbConnection.php');

// Include common functions
require('../commonFunc.php');

// Include common functions
require('../globalVars.php');

require("../class.phpmailer.php");
// Setup table name, configuration and data entry form
$tableName = "leaves_non_teach";
$tableConf = $tableName . ".conf.php";
$dataForm = $tableName . ".form.php";
$viewForm = $tableName . ".view.php";

// Include table configuration details
require($tableConf);

function DateArray($dat1,$dat2)
{
$dateMonthYearArr = array();
$fromDateTS = strtotime($dat1);
$toDateTS = strtotime($dat2);

for ($currentDateTS = $fromDateTS; $currentDateTS <= $toDateTS; $currentDateTS += (60 * 60 * 24)) {
// use date() and $currentDateTS to format the dates in between
$currentDateStr = date("Y-m-d",$currentDateTS);
$dateMonthYearArr[] = $currentDateStr;
//print $currentDateStr.�<br />�;
}
return $arraystr=implode("#",$dateMonthYearArr);
}





// Include the table handler class
require('../dbHandler.class.php');
$dbObject = new dbHandler();
$dbObject->setTableName($tableName);
$dbObject->setDbFieldList($dbFieldList);
$dbObject->setKeyFieldName("id");
$dbObject->connect();

// Retrieve parameters from request
$dbObject->getDbFieldsFromRequest();

$queryLWC= "SELECT COUNT( id ) AS tot FROM leaves_non_teach leav INNER JOIN timesheet_user user ON leav.timesheet_user_id = user.recNo  
      WHERE (user.superwiser =".$_SESSION['id']." and  leav.status = 'waiting'  ) ||(user.manager =".$_SESSION['id']." and leav.status = 'waiting'  or   leav.status = 'remarks'  )"; 
$resultLWC=mysqli_query($conn,$queryLWC);
$numLWC=mysqli_fetch_array($resultLWC);

$tomail_array=array();
//$query_tomail = "SELECT email,name FROM timesheet_user where recNo ='235' ";
//$query_tomail = "SELECT email,name FROM timesheet_user where recNo='259' || recNo='273'";
/*$query_tomail = "SELECT email,name FROM timesheet_user where recNo='273'";
$tomail_exec=mysqli_query($conn,$query_tomail);
while($result_tomail=mysqli_fetch_array($tomail_exec))
{
array_push($tomail_array,$result_tomail['email']);
}*/


$currentMode = "";
$formPrompt = "";
$succFailMesg = "";
$showResult = "N";

$action = $_REQUEST['aC'];
if (($action == "")  || ($action == "sA"))
{	// Set 'Add' mode in dataform
	$currentMode = "Add"; $succFailMesg = "<b>Add details</b>&nbsp;&nbsp;&nbsp;&nbsp;[<a href='javascript:history.back()'>Back</a>]<br>";
}
else if ($action == "Add")
{	$currentMode = "Add"; 

$reqFields = array("fromDate|From Date","toDate|To Date","noofdays|No Of Days");
	
	$blankFields = "";
	foreach ($reqFields as $reqField)
	{	list($field,$prompt) = explode('|',$reqField);
		if ($_REQUEST[$field] == "") { $blankFields .= "'". $prompt . "', ";}
	} 

	// Perform check for duplicate entry
	if($dbObject->Exists("id", $_REQUEST["id"]))
	{	$succFailMesg = "<b>Could not add details, record with this key exists.</b><br>";	
		$showResult = "N"; // Show dataentry form again
	}
	elseif ($blankFields != "")
	{	
	
	$succFailMesg = "<font color='#da0000'><b>No values entered for $blankFields please enter or select value</b><br></font>";	
		$showResult = "N"; // Show dataentry form again
	}
	else
	{	//$today = date("Y-m-d");
	    $instructor=$_SESSION['id'];
	    $dbObject->setDbField("timesheet_user_id",$instructor);
		$dbObject->setDbField("reasons",addslashes($_REQUEST['reasons']));		
		$dbObject->setDbField("classAffected",addslashes($_REQUEST['classAffected']));		
		$dbObject->setDbField("subByWhom",addslashes($_REQUEST['subByWhom']));		
		$dbObject->setDbField("compensated",addslashes($_REQUEST['compensated']));
		
		$leaveAppliedDate=date("Y-m-d H:i:s");
	    $dbObject->setDbField("leaveAppliedDate",$leaveAppliedDate);
		
	    $dbObject->setDbField("waitingDate",$leaveAppliedDate);
		
		$strD=DateArray($_REQUEST['fromDate'],$_REQUEST['toDate']);
		$dbObject->setDbField("date_str",$strD);
		
		if($_REQUEST['classAffected']=="" || $_REQUEST['IsclassesSubstituted']=='Other')
		{
		
		$dbObject->setDbField("IsclassesSubstituted",'');
		}
		
		
		$dbObject->Save();
		$succFailMesg = "<b>Details added successfully</b><br>";
		$showResult = "Y"; // Goto result part in dataform
		$st="waiting";
	}
}
else if ($action == "sM")
{	// Set 'Update' mode in dataform
	$currentMode = "Update";
/*	$isremarks=true
	if($_GET['isremarks']=="true")
	{
		
	}*/
    $succFailMesg = "<b>Modify details</b>&nbsp;&nbsp;&nbsp;&nbsp;[<a href='javascript:history.back()'>Back</a>]<br>";
	// Retrieve record first
	if ($dbObject->Retrieve("id",$_REQUEST["kV"]))
	{ ; }
	else { $succFailMesg = "<b>Could not retrieve details. Contact system administrator</b><br>"; }

}

else if ($action == "Update")
{	$currentMode = "Update"; 
	$showResult = "Y";
	 // Goto result part in dataform 
	     //$instructor=$_SESSION['id'];
	     // $dbObject->setDbField("timesheet_user_id",$instructor);
		
		//$disapproveSelfDate=date("Y-m-d H:i:s");
	    //$dbObject->setDbField("disapproveSelfDate",$disapproveSelfDate);
		
		//$strD=DateArray($_REQUEST['fromDate'],$_REQUEST['toDate']);
		//$dbObject->setDbField("status",'calSelf');
		if($_REQUEST['classAffected']=="" || $_REQUEST['IsclassesSubstituted']=='Other')
		{ 
		   $dbObject->setDbField("IsclassesSubstituted",'');
		}
	
	if ($dbObject->Update("id",$_REQUEST["kV"]))
	{	
	
	$succFailMesg = "<b>Details modified successfully</b><br>"; 
	$st=$_REQUEST['st'];
	}
	else
	{	$succFailMesg = "<b>Could not modify details. Contact system administrator</b><br>" ; }
}
else if ($action == "approved")
{	$currentMode = "approved"; 
	$showResult = "Y"; // Goto result part in dataform 
	 //$instructor=$_SESSION['id'];
	   // $dbObject->setDbField("timesheet_user_id",$instructor);
		
		$approveDate=date("Y-m-d H:i:s");
	    $dbObject->setDbField("approveDate",$approveDate);
		$dbObject->setDbField("approval_remarks",$_REQUEST['approval_remarks']);
		//$strD=DateArray($_REQUEST['fromDate'],$_REQUEST['toDate']);
		$dbObject->setDbField("status",'approved');
	
	if ($dbObject->Update("id",$_REQUEST["kV"]))
	{	
	///	////////////////////////////////Mail function///////////////////////////////////////////	
	$query_leaves = "SELECT l.fromDate,l.toDate, l.noofdays, u.name,u.email FROM leaves_non_teach l left join timesheet_user u on l.timesheet_user_id=u.recNo where l.id='".$_REQUEST['kV']."'  ";
	$leaves_exec=mysqli_query($conn,$query_leaves);
	$result_leaves=mysqli_fetch_array($leaves_exec);	
	
	$fromdate1=explode("-",$result_leaves['fromDate']);
	$todate1=explode("-",$result_leaves['toDate']);
	$fdate1= date("d F Y", mktime(0, 0, 0, $fromdate1[1], $fromdate1[2], $fromdate1[0]));
	$tdate1= date("d F Y", mktime(0, 0, 0, $todate1[1], $todate1[2], $todate1[0]));
	//$message.="The details are as follows: <br>Period - From : ".$fdate1." to ".$tdate1." <br>";
	//$message.="No. Of Days :".$result_leaves['noofdays']."<br>";
	
	$IsclassesSubstituted=$_REQUEST['IsclassesSubstituted'];
    $emergencyLeave=$_REQUEST['emergencyLeave'];
    ////////////No==compensated/////
		if($emergencyLeave=='Yes' && $IsclassesSubstituted=='No')
		{
		$addmsg='<br><b>Note :</b> "The following leaves are emergency and compensated and  not applicable for salary and leave deduction"';
		}
		else if($emergencyLeave=='Yes' && $IsclassesSubstituted=='Yes')
		{
		$addmsg='<br><b>Note :</b> "The following leaves are emergency and substiuted and  applicable for salary and leave deduction"';
		}
		else 
		{
		$addmsg='';
		}
	
	
	$message="Dear ".$result_leaves['name']." <br> Your applied leave from : ".$fdate1." to ".$tdate1." has been approved<br>";
	
	$message.=$addmsg;
	$message .="<br><br>Thanking You<br>HR Department Inlingua";
	//$fromEmail= "mttd@inlinguanewdelhi.com";
	$fromEmail= "service@inlinguanewdelhi.com";
	$fromName="Inlingua Leave Admin";
	
	array_push($tomail_array,"hrd@inlinguanewdelhi.com");
    array_push($tomail_array,"amttd@inlinguanewdelhi.com");
	//array_push($tomail_array,"anil@inlinguanewdelhi.com");
	//array_push($tomail_array,"vikas@panalinks.com");
	//array_push($tomail_array,"thevikasumrao@gmail.com");
	$to=$result_leaves['email'];
	array_push($tomail_array,$to);
	
	
	/*
	       $domain = "inlinguanewdelhi.com";

		    $smtpHost = "mail.$domain";

		    $smtpUser = "shrikant@$domain";

		    $smtpPassword = "Noida007";
			*/
	$domain = "inlinguanewdelhi.in";

		    $smtpHost = "mail.$domain";

		    $smtpUser = "admin@$domain";

		    $smtpPassword = "5B&vp7pgm7flABvi";		
			
	
	//$subject="Leave approved -".$fdate1." to ".$tdate1;
	$subject="Leave approved-".$fdate1." to ".$tdate1."-".$result_leaves['name'];
	
	$mail = new PHPMailer();

        if($mail_type=="S")
        {
	$mail->IsSMTP();              // set mailer to use SMTP
        
        }

        if($mail_type=="N")
        {
	$mail->IsMail();
        }
        
        if($mail_type=="S")
        {
	$mail->Host = $smtpHost;  // specify main and backup server
	$mail->SMTPAuth = true;     // turn on SMTP authentication
	$mail->Username = $smtpUser;  // SMTP username
	$mail->Password = $smtpPassword; // SMTP password
        }	

	$mail->From = $fromEmail;
	$mail->FromName = $fromName;
	//foreach ($to as $toAddress) 
	//{
	 //$toAddress;
		foreach ($tomail_array as $toAddress) 
           {
	 //$toAddress;
	$mail->AddAddress($toAddress, "");
             }
	//}

	$mail->IsHTML(true);               // set email format to HTML
	$mail->Subject = $subject;
	$mail->Body    = $message;
	//$mail->AddReplyTo("umraovikas@gmail.com","");
	//$mail->AddAttachment($path);
		
	if(!$mail->Send())
	{
    echo "Message could not be sent on mailid: <font color='red'>'".$to."'</font><br>";
	echo "Please check the emailId.<br>";
    //echo "Mailer Error: " . $mail->ErrorInfo;
    //exit;
	}
////////////////////////////////////////////Mail function//////////////////////////////////////////////////////////////	

	$succFailMesg = "<b>Details modified successfully</b><br>"; 
	$st="approved";
	}
	else
	{	$succFailMesg = "<b>Could not modify details. Contact system administrator</b><br>" ; }
}
else if ($action == "disapproved")
{	$currentMode = "disapproved"; 
	$showResult = "Y"; // Goto result part in dataform
		
	 //$instructor=$_SESSION['id'];
	 // $dbObject->setDbField("timesheet_user_id",$instructor);
		
		$disapproveDate=date("Y-m-d H:i:s");
	    $dbObject->setDbField("disapproveDate",$disapproveDate);
		
		//$strD=DateArray($_REQUEST['fromDate'],$_REQUEST['toDate']);
		$dbObject->setDbField("status",'disapproved');
	
	if ($dbObject->Update("id",$_REQUEST["kV"]))
	{	
	///	////////////////////////////////Mail function///////////////////////////////////////////	
	$query_leaves = "SELECT l.fromDate,l.toDate, l.noofdays,u.name, u.email FROM leaves_non_teach l left join timesheet_user u on l.timesheet_user_id=u.recNo where l.id='".$_REQUEST['kV']."'  ";
	$leaves_exec=mysqli_query($conn,$query_leaves);
	$result_leaves=mysqli_fetch_array($leaves_exec);	
	
	$fromdate1=explode("-",$result_leaves['fromDate']);
	$todate1=explode("-",$result_leaves['toDate']);
	$fdate1= date("d F Y", mktime(0, 0, 0, $fromdate1[1], $fromdate1[2], $fromdate1[0]));
	$tdate1= date("d F Y", mktime(0, 0, 0, $todate1[1], $todate1[2], $todate1[0]));
	//$message.="The details are as follows: <br>Period - From : ".$fdate1." to ".$tdate1." <br>";
	//$message.="No. Of Days :".$result_leaves['noofdays']."<br>";
	$message="Dear ".$result_leaves['name']." <br> Your applied leave from  : ".$fdate1." to ".$tdate1." has been disapproved.<br>For any queries please contact    Administrator.<br><br>";
	$message .="Thanking You<br>HR Department Inlingua";
	//$fromEmail= "mttd@inlinguanewdelhi.com";
	$fromEmail= "icentex@inlinguanewdelhi.com";
	//$fromEmail= "aditti@inlinguanewdelhi.com";
	$fromName="Inlingua Leave Admin";
	//$to=$result_leaves['email'];
	$to=$result_leaves['email'];
	array_push($tomail_array,$to);
	
	 $domain = "inlinguanewdelhi.in";

		    $smtpHost = "mail.$domain";

		    $smtpUser = "admin@$domain";

		    $smtpPassword = "5B&vp7pgm7flABvi";
	
	//$subject="Leave disapproved -".$fdate1." to ".$tdate1;
	$subject="Leave disapproved-".$fdate1." to ".$tdate1."-".$result_leaves['name'];
	$mail = new PHPMailer();

       if($mail_type=="S")
        {
	$mail->IsSMTP();              // set mailer to use SMTP
        
        }

        if($mail_type=="N")
        {
	$mail->IsMail();
        }
        
        if($mail_type=="S")
        {
	$mail->Host = $smtpHost;  // specify main and backup server
	$mail->SMTPAuth = true;     // turn on SMTP authentication
	$mail->Username = $smtpUser;  // SMTP username
	$mail->Password = $smtpPassword; // SMTP password
        }

	$mail->From = $fromEmail;
	$mail->FromName = $fromName;
	
	foreach ($tomail_array as $toAddress) 
           {
	 //$toAddress;
	$mail->AddAddress($toAddress, "");
             }

	$mail->IsHTML(true);               // set email format to HTML
	$mail->Subject = $subject;
	$mail->Body    = $message;
	//$mail->AddReplyTo("umraovikas@gmail.com","");
	//$mail->AddAttachment($path);
		
	if(!$mail->Send())
	{
    echo "Message could not be sent on mailid: <font color='red'>'".$to."'</font><br>";
	echo "Please check the emailId.<br>";
    //echo "Mailer Error: " . $mail->ErrorInfo;
    //exit;
	}
////////////////////////////////////////////Mail function//////////////////////////////////////////////////////////////	

	$succFailMesg = "<b>Details modified successfully</b><br>"; 
	$st="disapproved";
	}
	else
	{	$succFailMesg = "<b>Could not modify details. Contact system administrator</b><br>" ; }
}

else if ($action == "remarks")
{	$currentMode = "remarks"; 
	$showResult = "Y"; // Goto result part in dataform
		
	 //$instructor=$_SESSION['id'];
	 // $dbObject->setDbField("timesheet_user_id",$instructor);
		
		$disapproveDate=date("Y-m-d H:i:s");
	    $dbObject->setDbField("disapproveDate",$disapproveDate);
		
		//$strD=DateArray($_REQUEST['fromDate'],$_REQUEST['toDate']);
		$dbObject->setDbField("status",'remarks');
	
	if ($dbObject->Update("id",$_REQUEST["kV"]))
	{
	$succFailMesg = "<b>Details modified successfully</b><br>"; 
	$st="disapproved";
	}
	else
	{	$succFailMesg = "<b>Could not modify details. Contact system administrator</b><br>" ; }
}

else if ($action == "sD")
{	$currentMode = "Delete"; $succFailMesg = "<b>Delete details</b>&nbsp;&nbsp;&nbsp;&nbsp;[<a href='javascript:history.back()'>Back</a>]<br>";
	// Retrieve record first
	if ($dbObject->Retrieve("id",$_REQUEST["kV"]))
	{ ; }
	else { $succFailMesg = "<b>Could not retrieve details. Contact system administrator</b><br>"; }
}
else if ($action == "Delete")
{	$showResult = "Y"; // Goto result part in dataform
	
	if ($dbObject->Delete("id",$_REQUEST["kV"]))
	{	$succFailMesg = "<b>Details deleted successfully</b><br>"; }
	else
	{	$succFailMesg = "<b>Could not delete details. Contact System administrator</b><br>" ; }
}
else if ($action == "sV")
{	// Set 'View' mode 
	$currentMode = "View"; $succFailMesg = "<b>View details(<a href='javascript:history.back();'>Back</a>)</b><br>";
	$dataForm = $viewForm;
	
	$sqlQuery1 = "SELECT a.*,b.name FROM leaves_non_teach a left join timesheet_user b on a.timesheet_user_id=b.recNo where a.id='".$_REQUEST['kV']."'";
	
	// Retrieve record first
	if ($dbObject->Retrieve_join($sqlQuery1))
	{ ; }
	else { $succFailMesg = "<b>Could not retrieve details. Contact system administrator</b><br>"; }

}
else
{	echo "Nothing to do !";
	return;
}

// Load the data entry or  view entry form
require($dataForm);

$dbObject->CloseConnection();
return;


?>