Current File : /home/inlingua/public_html/faridabad/icentex/general_leave/leaves_main_backup.php |
<?php
ob_start();
session_start();
//error_reporting(-1);
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_non_teach where status='waiting' && timesheet_user_id='".$_SESSION['id']."'";
$resultLWC=mysqli_query($conn,$queryLWC);
$numLWC=mysqli_fetch_array($resultLWC);
////////////////////////////////////////Tomail array///////////////////////////////////////////////////////////
$tomail_array=array();
//$query_tomail = "SELECT email,name FROM timesheet_user where recNo ='235' ";
//$query_tomail = "SELECT email,name FROM timesheet_user where recNo='273' || recNo='259'";
$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']);
}
array_push($tomail_array,"aditti@nd.inlingua.in");
//array_push($tomail_array,"vikasumrao@sify.com");
//////////////////////////////////////////to mail array///////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$query_mail = "SELECT email,name FROM timesheet_user where recNo='".$_SESSION['id']."' and usertype='user' and status='Active'";
$mail_exec=mysqli_query($conn,$query_mail);
$result_mail=mysqli_fetch_array($mail_exec);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$currentMode = "";
$formPrompt = "";
$succFailMesg = "";
$showResult = "N";
$action = $_REQUEST['aC'];
if (($action == "") || ($action == "sA"))
{ // Set 'Add' mode in dataform
$currentMode = "Apply"; $succFailMesg = "<b>Add details</b> [<a href='javascript:history.back()'>Back</a>]<br>";
}
else if ($action == "Apply")
{ $currentMode = "Apply";
$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>";
////////////////////////////////Mail function///////////////////////////////////////////
$message=$result_mail['name']." has applied for Leave.<br>";
$fromdate1=explode("-",$_REQUEST['fromDate']);
$todate1=explode("-",$_REQUEST['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]));
$IsclassesSubstituted=$_REQUEST['IsclassesSubstituted'];
$emergencyLeave=$_REQUEST['emergencyLeave'];
////////////No==compensated/////
if($emergencyLeave=='Yes' && $IsclassesSubstituted=='No')
{
$addmsg='<br><b>Note :</b> "The following leaves_non_teach are emergency off and compensated and not applicable for salary and/or leave deduction"';
}
else if($emergencyLeave=='Yes' && $IsclassesSubstituted=='Yes')
{
$addmsg='<br><b>Note :</b> "The following leaves_non_teach are emergency off and substituted and applicable for salary and/or leave deduction"';
}
else
{
$addmsg='';
}
$message.="The details are as follows: <br>Period - From : ".$fdate1." to ".$tdate1." <br>";
$message.="No. Of Days :".$_REQUEST['noofdays']."<br>Reason :".$_REQUEST['reasons']."<br>";
$message.=$addmsg;
$message .="<br><br>Regards,<br>iCentex Administrator";
//$fromEmail=$result_mail['email'];
//$fromEmail="mttd@inlinguanewdelhi.com";
$fromEmail= "icentex@inlinguanewdelhi.com";
$fromName=$result_mail['name'];
$to=$tomail_array;
$subject="Leave Applied-".$fdate1." to ".$tdate1."-".$result_mail['name'];
$domain = "inlinguanewdelhi.com";
$smtpHost = "mail.$domain";
$smtpUser = "shrikant@$domain";
$smtpPassword = "Noida007";
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
//$mail->IsMail();
$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;
$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//////////////////////////////////////////////////////////////
$message1="Dear ".$result_mail['name'].",<br><br>You have successfully applied for leave.<br>";
$message1.="The details are as follows: <br>Period - From : ".$fdate1." to ".$tdate1." <br>";
$message1.="No. Of Days :".$_REQUEST['noofdays']."<br>Reason :".$_REQUEST['reasons']."<br>";
$message1.=$addmsg;
$message1.='<br><br>If you wish to make any changes, please cancel your leave and re-apply.';
$message1 .="<br><br>Thanking You<br>iCentex Administrator";
//$fromEmail1="mttd@inlinguanewdelhi.com";
//$fromEmail1="vikasumrao@sify.com";
$fromEmail1="icentex@inlinguanewdelhi.com";
$to1=$result_mail['email'];
$mail1 = new PHPMailer();
//$mail1->IsMail();
$mail1->IsSMTP();
$mail1->Host = $smtpHost; // specify main and backup server
$mail1->SMTPAuth = true; // turn on SMTP authentication
$mail1->Username = $smtpUser; // SMTP username
$mail1->Password = $smtpPassword; // SMTP password
$mail1->From = $fromEmail1;
$mail1->FromName = "Inlingua Leave Admin";
$mail1->AddAddress($to1, "");
$mail1->IsHTML(true); // set email format to HTML
$mail1->Subject = $subject;
$mail1->Body = $message1;
if(!$mail1->Send())
{
echo "Message could not be sent on mailid: <font color='red'>'".$to1."'</font><br>";
echo "Please check the emailId.<br>";
//echo "Mailer Error: " . $mail1->ErrorInfo;
//exit;
}
$showResult = "Y"; // Goto result part in dataform
$st="waiting";
}
}
else if ($action == "sM")
{ // Set 'Update' mode in dataform
$currentMode = "Update"; $succFailMesg = "<b>Cancel 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 ($dbObject->Update("id",$_REQUEST["kV"]))
{
////////////////////////////////Mail function///////////////////////////////////////////
$query_leaves = "SELECT fromDate,toDate, noofdays FROM leaves_non_teach where id='".$_REQUEST['kV']."' ";
$leaves_exec=mysqli_query($conn,$query_leaves);
$result_leaves=mysqli_fetch_array($leaves_exec);
$message=$result_mail['name']." has canceled his/her applied leave from : ".$fdate1." to ".$tdate1."<br>";
$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=$result_mail['name']." has canceled his/her applied leave from : ".$fdate1." to ".$tdate1."<br><br>";
$message .="Thanking You<br>".$result_mail['name'];
$fromEmail=$result_mail['email'];
// $fromEmail="mttd@inlinguanewdelhi.com";
$fromName=$result_mail['name'];
$to=$tomail_array;
$subject="Leave self canceled-".$fdate1." to ".$tdate1."-".$result_mail['name'];
$domain = "inlinguanewdelhi.com";
$smtpHost = "mail.$domain";
$smtpUser = "shrikant@$domain";
$smtpPassword = "Noida007";
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
//$mail->IsMail();
$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;
$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="calSelf";
}
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;
// Retrieve record first
if ($dbObject->Retrieve("id",$_REQUEST["kV"]))
{ ; }
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;
?>