Current File : /home/inlingua/public_html/noida/icentex/admin_leave/leaves.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";
$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 where status='waiting'";
$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> [<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) = split('\|',$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"; $succFailMesg = "<b>Modify details</b> [<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);
//$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 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.in";
//array_push($tomail_array,"vikas@panalinks.in");
$fromEmail= "admin@inlinguanewdelhi.in";
$fromName="Inlingua Leave Admin";
//array_push($tomail_array,"sandeep.d@infocityhosting.in");
//array_push($tomail_array,"admin@inlinguanewdelhi.com");
array_push($tomail_array,"hrd@inlinguanewdelhi.com");
array_push($tomail_array,"service@inlinguanewdelhi.com");
array_push($tomail_array,"amttd@inlinguanewdelhi.com");
$to=$result_leaves['email'];
array_push($tomail_array,$to);
$domain = "inlinguanewdelhi.in";
//$smtpHost = "mail.$domain";
$smtpHost ="smtp.inlinguanewdelhi.in;smtp1.inlinguanewdelhi.in;smtp2.inlinguanewdelhi.in;smtp02.inlinguanewdelhi.in";
$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->SMTPSecure = 'tls';
$mail->Priority = 1;
}
$mail->From = $fromEmail;
$mail->FromName = $fromName;
//foreach ($to as $toAddress)
//{
//$toAddress;
foreach ($tomail_array as $toAddress)
{
//$toAddress;
$mail->AddAddress(trim($toAddress), "");
}
//}
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
//$mail->AddReplyTo("umraovikas@gmail.in","");
//$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;*/
}
else
{
echo "Email Send Sucesfully To".$to;
}
////////////////////////////////////////////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 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=" 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.in";
$fromEmail= "admin@inlinguanewdelhi.in";
//$fromEmail= "aditti@nd.inlingua.in";
$fromName="Inlingua Leave Admin";
//$to=$result_leaves['email'];
$to=$result_leaves['email'];
array_push($tomail_array,$to);
array_push($tomail_array,'admin@inlinguanewdelhi.in');
$domain = "inlinguanewdelhi.in";
//$smtpHost = "mail.$domain";
$smtpHost ="smtp.inlinguanewdelhi.in;smtp1.inlinguanewdelhi.in;smtp2.inlinguanewdelhi.in;smtp02.inlinguanewdelhi.in";
$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.in","");
//$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 == "sD")
{ $currentMode = "Delete"; $succFailMesg = "<b>Delete details</b> [<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 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;
?>