'Default', 'basePath' => dirname(__FILE__) )); class camp_lupins_mails { var $mysqlconfig; var $mysqldb; var $data_grid; var $from; function camp_lupins_mails() { $this->from="lupinarogya@metropolisindia.com"; $this->mysqlconfig = new Zend_Config( array( 'database' => array( 'adapter' => 'Pdo_Mysql', 'params' => array( 'host' => 'localhost', 'dbname' => 'ctcamps', 'username' => 'root', 'password' => 'metropolisitteam', ) ) ) ); $this->mysqldb = Zend_Db::factory($this->mysqlconfig->database); $this->mysqldb->setFetchMode(Zend_Db::FETCH_ASSOC); } function fetchAll($sql) { //var_dump($sql); $rec=$this->mysqldb->fetchAll($sql); return $rec; } function execute($sql) { // var_dump($sql); $this->mysqldb->query($sql); } function get_asm_users($hq_id) { $validator = new Zend_Validate_EmailAddress(); $sql1="SELECT DISTINCT email_id_of_me FROM masters_lupins WHERE hq_id='hq_id'"; $me_rec=$this->fetchAll($sql1); foreach($me_rec as $k=>$email) { if ($validator->isValid(trim($email['email_id_of_me']))) { array_push($this->to,$email['email_id_of_me']); } } $sql="SELECT DISTINCT email_id_of_asm FROM masters_lupins WHERE hq_id='$hq_id'"; $asm_rec=$this->fetchAll($sql); foreach($asm_rec as $k=>$email) { if ($validator->isValid(trim($email['email_id_of_asm']))) { array_push($this->to,$email['email_id_of_asm']); } } return $this->to; // echo $this->to; // exit; } function get_sister_users($hq_id) { $validator = new Zend_Validate_EmailAddress(); $sql="SELECT a.email_id from users a inner join lupinssister_headquarters b on (a.uid=b.uid) WHERE b.headquarters='$hq_id'"; $lab_users=$this->fetchAll($sql); foreach($lab_users as $k=>$email) { if ($validator->isValid(trim($email['email_id']))) { array_push($this->to,$email['email_id']); } } // echo $this->to; // exit; return $this->to; } function get_head_users($zone) { $validator = new Zend_Validate_EmailAddress(); $sql="SELECT email_id FROM sponcerer_heads WHERE SPON_ID='6' and zone = '$zone' and uid not in ('4','54','2')"; $mum_users=$this->fetchAll($sql); foreach($mum_users as $k=>$email) { if ($validator->isValid(trim($email['email_id']))) { array_push($this->cc,$email['email_id']); } } return $this->cc; // echo $this->cc; // exit; } function send_mail($subject,$from,$to,$cc,$htmlbody,$textbody) { $config = array('auth' => 'login', 'username' => 'lupinarogya@metropolisindia.com', 'password' => 'Lup@#2015', 'ssl' => 'tls'); $tr = new Zend_Mail_Transport_Smtp('192.168.23.66' , $config); Zend_Mail::setDefaultTransport($tr); $mail = new Zend_Mail(); $mail->setFrom((string)$from); foreach ($to as &$value) { $mail->addTo((string)$value); } if (isset($cc)) { foreach ($cc as &$value) { $mail->addCc((string)$value); } } $mail->setSubject((string)$subject); // $mail->setBodyText((string)$textbody); $mail->setBodyHtml((string)$htmlbody); try { $mail->send($tr); } catch (Exception $e) { array_push($to,"aquil.faruqui@metropolisindia.com"); foreach ($to as &$value) { $mail->addTo((string)$value); } $subject="Mail Not Sent Due to Incorrect Email"; $mail->send($tr); echo 'Caught exception: ', $e->getMessage(), "\n"; } } function adddetails($zone) { $details="

Kindly revert on the below mentioned numbers incase of any queries or clarifications

"; $details.="

Ms. Aparna Shirodkar
Deputy Manager - Clinical Research
02230840739 / 740

"; $details.="

Mr. Suhas Shinde
Coordinator - Clinical Research,
02230840739 / 02233143288

This Is An Auto Generated Email. Kindly Do Not Reply

"; //var_dump($bodyhtml);exit; return $details; } function prepare_table_hqwise_reminder($zone, $phlebo, $reason) { // $bodyhtml="

Dear All,

//

Please note the following Lupin Arogya camps are scheduled on ".$secondDay.".

"; $bodyhtml.=" "; if($phlebo==1){$bodyhtml.="";} if($reason==1){$bodyhtml.="";} $bodyhtml.=""; $sql=" SELECT c.zone, c.region, c.headquarters, a.doctor_name, date_format(a.camp_date,'%d-%b-%Y %h:%i %p') as camp_date, date_format(a.camp_intimation,'%d-%b-%Y %h:%i %p') as intimation_date, DATEDIFF(a.camp_date,a.camp_intimation) as intimation_days, a.venue_address as venue_address, a.no_of_patients, date_format(ADDDATE(CURDATE(),INTERVAL 2 DAY),'%d-%b-%Y') as secondDay, CONCAT(a.phlebotomist_name,'-','0',SUBSTRING(a.phlebotomist_number, -10)) as phle, a.comments, CONCAT(a.me_name,'-','0',SUBSTRING(a.contact_no_of_me, -10)) as pa, CONCAT(a.name_of_asm,'-','0',SUBSTRING(a.contact_no_of_asm, -10)) as asm FROM lupins_camps a INNER JOIN masters_lupins b ON (a.headquarters=b.id) INNER JOIN lupins_headquarters c ON (b.hq_id=c.hq_id) WHERE a.camp_status not in ('1','4','5') and c.zone='$zone' and date(a.camp_date)= ADDDATE(CURDATE(),INTERVAL 2 DAY) ORDER BY c.headquarters "; $newrec=$this->fetchAll($sql); if($newrec) { foreach($newrec as $m=>$data) { $zone=$data['zone']; $region=$data['region']; $headquarters=$data['headquarters']; $doctor_name=$data['doctor_name']; $camp_date=$data['camp_date']; $secondDay=$data['secondDay']; $intimation_date=$data['intimation_date']; $intimation_days=$data['intimation_days']; $venue_address=$data['venue_address']; $no_of_patients=$data['no_of_patients']; if($phlebo==1){$phle=$data['phle'];} if($reason==1){$comments=$data['comments'];} $pa=$data['pa']; $asm=$data['asm']; $bodyhtml.=" "; if($phlebo==1){$bodyhtml.="";} if($reason==1){$bodyhtml.="";} $bodyhtml.=""; } $bodyhtml.="
ZONE REGION HEAD QUARTERS DOCTOR NAME CAMP DATE & TIME INTIMATION DATE & TIME INTIMATION DAYS CAMP ADDRESSPHLEBOTOMIST NAME & NUMBERREASON FOR CHANGE IN SCHEDULETOTAL PATIENTS ME NAME & NUMBER ASM NAME & NUMBER
$zone $region $headquarters $doctor_name $camp_date $intimation_date $intimation_days $venue_address$phle$comments$no_of_patients $pa $asm
"; } else { $bodyhtml="Dear All,
No camps are scheduled for tommorrow."; } return $bodyhtml; } function camp_lupin_reminder() { $sql="SELECT DISTINCT c.zone,c.headquarters AS headquarters,b.hq_id as hq_id ,date_format(ADDDATE(CURDATE(),INTERVAL 2 DAY),'%d-%b-%Y') as secondDay FROM lupins_camps a INNER JOIN masters_lupins b ON (a.headquarters=b.id) INNER JOIN lupins_headquarters c ON (b.hq_id=c.hq_id) WHERE a.freeze=1 and date(a.camp_date)= ADDDATE(CURDATE(),INTERVAL 2 DAY) ORDER BY c.headquarters "; $rec=$this->fetchAll($sql); foreach($rec as $k=>$row) { $this->to=array(); $this->cc=array(); $camp_id=$row['camp_id']; $zone=$row['zone']; $headquarters=$row['headquarters']; $hq_id=$row['hq_id']; $secondDay=$row['secondDay']; $subject="Lupin Camp Reminder for - $zone"; $bodyhtml="

Dear Lupin Team,

Please note the following Lupin camp are scheduled on ".$secondDay.".

"; $bodyhtml.=$this->prepare_table_hqwise_reminder($zone,1,0); $bodyhtml.=$this->adddetails($zone); //$this->get_asm_users($hq_id); $this->get_head_users($zone); // $this->to=implode(",",$this->get_asm_users($hq_id)); // $this->to=implode(",",$this->get_sister_users($hq_id)); // $this->cc=implode(",",$this->get_head_users($zone)); // $asm_users=implode(",",$this->get_asm_users($hq_id)); // $sister_users=implode(",",$this->get_sister_users($hq_id)); // $head_users=implode(",",$this->get_head_users($zone)); // $bodyhtml.="

asm_users ".$asm_users."

//

sister_users ".$sister_users."

//

head_users ".$head_users."

"; //array_push($this->cc,"sayli.rane@metropolisindia.com","siddhesh.chavan@metropolisindia.com"); array_push($this->cc,"it.support@metropolisindia.com"); // } $this->send_mail($subject,$this->from,$this->to,$this->cc,$bodyhtml,$textbody); // $this->send_mail($subject,$this->from,$this->cc,$this->cc,$bodyhtml,$textbody); } } function camp_sisterlab_reminder() { $sql="SELECT DISTINCT c.zone,c.headquarters AS headquarters,b.hq_id as hq_id FROM lupins_camps a INNER JOIN masters_lupins b ON (a.headquarters=b.id) INNER JOIN lupins_headquarters c ON (b.hq_id=c.hq_id) WHERE a.freeze=1 and date(a.camp_date)= ADDDATE(CURDATE(),INTERVAL 1 DAY) ORDER BY c.headquarters "; $rec=$this->fetchAll($sql); foreach($rec as $k=>$row) { $this->to=array(); $this->cc=array(); $camp_id=$row['camp_id']; $zone=$row['zone']; $headquarters=$row['headquarters']; $hq_id=$row['hq_id']; $subject="Lupin Camp Reminder for - $headquarters"; // $bodyhtml="

Dear Metropolis Team,

//

Please note the following Lupin camp are Scheduled for Tommorrow. Kindly check Phlebotomist details.

"; $campdtls.=$this->prepare_table_hqwise_reminder($hq_id,1,0); $details.=$this->adddetails($zone); $bodyhtml.=$campdtls; $bodyhtml.=$details; // $this->get_sister_users($hq_id); // $this->get_head_users($zone); // $this->to=implode(",",$this->get_asm_users($hq_id)); // $this->to=implode(",",$this->get_sister_users($hq_id)); // $this->cc=implode(",",$this->get_head_users($zone)); // $asm_users=implode(",",$this->get_asm_users($hq_id)); // $sister_users=implode(",",$this->get_sister_users($hq_id)); // $head_users=implode(",",$this->get_head_users($zone)); // $bodyhtml.="

asm_users ".$asm_users."

//

sister_users ".$sister_users."

//

head_users ".$head_users."

"; //array_push($this->cc,"sayli.rane@metropolisindia.com","siddhesh.chavan@metropolisindia.com"); array_push($this->cc,"it.support@metropolisindia.com"); // echo $this->from; // echo $this->to; // } $this->send_mail($subject,$this->from,$this->to,$this->cc,$bodyhtml,$textbody); //-------COmmented on 2016-03-19 // $this->send_mail($subject,$this->from,$this->cc,$this->cc,$bodyhtml,$textbody); } } function prepare_five_days_reminder($hq_id, $phlebo, $reason) { $bodyhtml=" "; if($phlebo==1){$bodyhtml.="";} if($reason==1){$bodyhtml.="";} $bodyhtml.=""; $sql=" SELECT c.zone, c.region, c.headquarters, a.doctor_name, date_format(a.camp_date,'%d-%b-%Y %h:%i %p') as camp_date, date_format(a.camp_intimation,'%d-%b-%Y %h:%i %p') as intimation_date, DATEDIFF(a.camp_date,a.camp_intimation) as intimation_days, a.venue_address as venue_address, a.no_of_patients, CONCAT(a.phlebotomist_name,'-','0',SUBSTRING(a.phlebotomist_number, -10)) as phle, a.comments, CONCAT(a.me_name,'-','0',SUBSTRING(a.contact_no_of_me, -10)) as pa, CONCAT(a.name_of_asm,'-','0',SUBSTRING(a.contact_no_of_asm, -10)) as asm FROM lupins_camps a INNER JOIN masters_lupins b ON (a.headquarters=b.id) INNER JOIN lupins_headquarters c ON (b.hq_id=c.hq_id) WHERE b.hq_id='$hq_id' and date(a.camp_date)= ADDDATE(CURDATE(),INTERVAL 5 DAY) ORDER BY c.headquarters "; $newrec=$this->fetchAll($sql); foreach($newrec as $m=>$data) { $zone=$data['zone']; $region=$data['region']; $headquarters=$data['headquarters']; $doctor_name=$data['doctor_name']; $camp_date=$data['camp_date']; $intimation_date=$data['intimation_date']; $intimation_days=$data['intimation_days']; $venue_address=$data['venue_address']; $no_of_patients=$data['no_of_patients']; if($phlebo==1){$phle=$data['phle'];} if($reason==1){$comments=$data['comments'];} $pa=$data['pa']; $asm=$data['asm']; $bodyhtml.=" "; if($phlebo==1){$bodyhtml.="";} if($reason==1){$bodyhtml.="";} $bodyhtml.=""; } $bodyhtml.="
ZONE REGION HEAD QUARTERS DOCTOR NAME CAMP DATE & TIME INTIMATION DATE & TIME INTIMATION DAYS CAMP ADDRESSPHLEBOTOMIST NAME & NUMBERREASON FOR CHANGE IN SCHEDULETOTAL PATIENTS ME NAME & NUMBER ASM NAME & NUMBER
$zone $region $headquarters $doctor_name $camp_date $intimation_date $intimation_days $venue_address$phle$comments$no_of_patients $pa $asm
"; return $bodyhtml; } function camp_lupin_five_days_reminder() { $sql="SELECT DISTINCT c.zone, c.headquarters AS headquarters, b.hq_id as hq_id, date_format(ADDDATE(CURDATE(),INTERVAL 5 DAY),'%d-%b-%Y') as fifthDay FROM lupins_camps a INNER JOIN masters_lupins b ON (a.headquarters=b.id) INNER JOIN lupins_headquarters c ON (b.hq_id=c.hq_id) WHERE a.freeze=1 and date(a.camp_date)= ADDDATE(CURDATE(),INTERVAL 5 DAY) ORDER BY c.headquarters"; // ADDDATE(CURDATE(),INTERVAL 5 DAY) As fifthDay $rec=$this->fetchAll($sql); foreach($rec as $k=>$row) { $this->to=array(); $this->cc=array(); $camp_id=$row['camp_id']; $fifthDay=$row['fifthDay']; $zone=$row['zone']; $headquarters=$row['headquarters']; $hq_id=$row['hq_id']; // $subject="Lupin Camp Reminder to fill the Phlebotomist details for - $headquarters"; $subject="Reminder of Lupin Camp on ".$fifthDay." for - ".$headquarters; $bodyhtml="

Dear Metropolis Team,

Kindly consider this as a gentle reminder to fill the Phlebotomist details of below mentioned Lupin camps Scheduled on $fifthDay.

"; $bodyhtml.=$this->prepare_five_days_reminder($hq_id,1,0); $bodyhtml.=$this->adddetails($zone); //$this->get_sister_users($hq_id); // $this->get_head_users($zone); // $this->to=implode(",",$this->get_sister_users($hq_id)); // $this->cc=implode(",",$this->get_head_users($zone)); // $sister_users=implode(",",$this->get_sister_users($hq_id)); // $head_users=implode(",",$this->get_head_users($zone)); // // $bodyhtml.="

sister_users ".$sister_users."

//

head_users ".$head_users."

"; // array_push($this->cc,"sneha.anaokar@metropolisindia.com"); // array_push($this->cc,"sayli.rane@metropolisindia.com","siddhesh.chavan@metropolisindia.com"); array_push($this->cc,"it.support@metropolisindia.com"); // echo $this->from; // echo $this->to; $this->send_mail($subject,$this->from,$this->to,$this->cc,$bodyhtml,$textbody); //-------COmmented on 2016-03-19 // $this->send_mail($subject,$this->from,$this->cc,$this->cc,$bodyhtml,$textbody); } } } $lm=new camp_lupins_mails(); $lm->camp_lupin_reminder(); //$lm->camp_sisterlab_reminder(); //$lm->camp_lupin_five_days_reminder(); echo "End Ok...!"; ?>