Current File : /home/inlingua/public_html/faridabad/icentex/admin_procedures/message_send_oldbckup.php
<?php
session_start();
// Copyright, Panalink Infotech Limited. Created on: 22-05-2010

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

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

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

//////////////////###Function####/////////////
function createKey($length=6) {
	$chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~#@^$";
	$i = 0;
	$password = "";
	while ($i <= $length) {
		$password .= $chars{mt_rand(0,strlen($chars))};
		$i++;
	}
	
	$mTime = str_replace(".","",microtime(true));
	$mTime = str_replace(" ","-",$mTime);
	$key = $mTime . "-" . $password;
	
	return $key;
}
/////////////////###Function####//////////////


// Setup table name, configuration and data entry form
$tableName = "messages";
$tableConf = $tableName . ".conf.php";
//$dataForm = $tableName . ".form.php";
//$viewForm = $tableName . ".view.php";

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


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

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


$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=="Send")
{

$to=$_POST['to'];
$to1=explode(",",$to);

$msg1=addslashes($_REQUEST['message']);
$subject=addslashes($_POST['subject']);
$uniqueKey=createKey();

$dbObject->setDbField("message_id","".$uniqueKey."");
$dbObject->setDbField("send_to","".$to."");
$dbObject->setDbField("extra_emails","".$_REQUEST['extra_emails']."");
$dbObject->setDbField("title","".$subject."");
$dbObject->setDbField("message","".$msg1."");
$dbObject->setDbField("from_send",$_SESSION['id']);
$dbObject->setDbField("created",date("Y-m-d H:i:s"));
   
if($to!="" && $msg1!="" && $subject!="")
{

$dbObject1 = new dbHandler();
$dbObject1->connect();

      $emailids=array();
      foreach($to1 as $val)
		{
		
		if(trim($val)=="Hourly")
		{
		$queryUsers="select * from timesheet_user where usertype='user' && pay_type='Hourly' && status='Active'";
		}
		elseif(trim($val)=="Fixed")
		{
		$queryUsers="select * from timesheet_user where usertype='user' && pay_type='Fixed salaried' && status='Active'";
		}
		else if(trim($val)=="FD")
		{
		$queryUsers="select * from timesheet_user where usertype='FD' && status='Active'";
		}
		
		$selectedRecords1 = $dbObject1->Select($queryUsers);
		while($objectData1=$dbObject1->SelectNext())
              {
			  $emailids[]=$objectData1['email'];
              $dbObject->setDbField("to_send",$objectData1['recNo']); 
			  $dbObject->Save();
              }
		
		}
		
$etc=$_REQUEST['extra_emails'];
if($etc!="")
{
$etc1=explode(",",$etc);
foreach($etc1 as $val1)
{
$emailids[]=$val1;
}
}		

//print_r($emailids);
		
require("../class.phpmailer.php");


$message="Hi,<br>".nl2br($_REQUEST['message'])."";

$fromEmail= "icentex@inlinguanewdelhi.in";
$fromName="i-centex Inlingua Update";

//$to=$numuser[email];

$subject=$subject;

if($_REQUEST['sendmail']!="1" && $etc!="")
{
$_REQUEST['sendmail']=1;
$emailids=array();
$emailids=$etc1;
}

if($_REQUEST['sendmail']=="1")
{




foreach ($emailids as $toAddress) 
{


$mail = new PHPMailer();

$domain = "inlinguanewdelhi.in";
$smtpHost = "mail.$domain";
$smtpUser = "admin@$domain";
$smtpPassword = "qftW&525";


       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;


	//$toAddress;
	$mail->AddAddress($toAddress, "");



$mail->IsHTML(true);               // set email format to HTML
 

$mail->Subject = $subject;
$mail->Body    = $message;

		
if(!$mail->Send())
{
    echo "Message could not be sent on mailid: <font color='red'>'".$toAddress."'</font><br>";
	echo "Please check the emailId.<br>";
    //echo "Mailer Error: " . $mail->ErrorInfo;
	echo $_SESSION['error'].="".$mail->ErrorInfo."<br>";
    //exit;
}

}
	
}
		
}		
		
		
header("Location:private_messages.php");
}
elseif($action=="Delete")
{
    $delete_array=$_REQUEST['mID'];
	
	$dbObject->setDbField("to_deleted",1);
	
	$dbObject->setDbField("to_ddate",date("Y-m-d H:i:s"));
	
	foreach($delete_array as $val)
	{
	
	if ($dbObject->Update("recNo",$val))
	{	
	$succFailMesg = "<b>Details deleted successfully</b><br>"; 
	}
	else
	{	
	$succFailMesg = "<b>Could not delete details. Contact System administrator</b><br>" ; 
	}
	
	}
	
	header("Location:private_messages.php");
}
else if($action=="view")
{
   $viewid=$_REQUEST['mid'];
   $dbObject->setDbField("to_viewed",1);
   $dbObject->setDbField("to_vdate",date("Y-m-d H:i:s"));
    if($_REQUEST['send']!="Y")
	{
	
    if ($dbObject->Update("recNo",$viewid))
	{	
	$succFailMesg = "<b>Details deleted successfully</b><br>"; 
	}
	else
	{	
	$succFailMesg = "<b>Could not delete details. Contact System administrator</b><br>" ; 
	}
	
	}
	
header("Location:private_messages.php?p=view&mid=".$viewid."");
}

?>