'Default', 'basePath' => dirname(__FILE__) )); class sop_monthly_mail { var $mysqlconfig; var $mysqldb; var $data_grid; var $from; var $to; var $cc; var $camp_id; var $filter; var $adddetails; function sop_monthly_mail() { $this->from="it.support@metropolisindia.com"; $this->mysqlconfig = new Zend_Config( array( 'database' => array( 'adapter' => 'Pdo_Mysql', 'params' => array( 'host' => 'localhost', 'dbname' => 'intranet', 'username' => 'root', 'password' => 'metropolisitteam', ) ) ) ); $this->mysqldb = Zend_Db::factory($this->mysqlconfig->database); $this->mysqldb->setFetchMode(Zend_Db::FETCH_ASSOC); } function fetchAll($sql) { $rec=$this->mysqldb->fetchAll($sql); return $rec; } function execute($sql) { $this->mysqldb->query($sql); } function send_mail($subject,$from,$to,$cc,$body,$textbody) { $config = array('auth' => 'login', 'username' => 'it.support@metropolisindia.com', 'password' => 'metropolis', '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); } // array_push($cc,"sneha.anaokar@metropolisindia.com"); } $mail->setSubject((string)$subject); //$mail->setBodyText((string)$textbody); $mail->setBodyHtml((string)$body); try { // var_dump($to); // var_dump($subject,$from,$to,$cc,$body,$textbody); // exit; $mail->send($tr); } catch (Exception $e) { array_push($to,"it.support@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 emp_email($uid) { // var_dump($uid); $sql="SELECT emailid FROM users WHERE uid=$uid"; $rec=$this->mysqldb->fetchAll($sql); $validator = new Zend_Validate_EmailAddress(); if ($validator->isValid(trim($rec[0]["emailid"]))) { array_push($this->to,$rec[0]["emailid"]); } return $this->to; } function rep_head($uid) { // var_dump($uid); $sql="SELECT a.emailid FROM users a,hr_new_newuser b WHERE a.uid=b.reporting_head1 and b.uid=$uid"; $rec=$this->mysqldb->fetchAll($sql); $validator = new Zend_Validate_EmailAddress(); if ($validator->isValid(trim($rec[0]["emailid"]))) { array_push($this->cc,$rec[0]["emailid"]); var_dump($this->cc); } return $this->cc; } function sop_monthly_rem() { $sql="SELECT a.uid, a.firstname as emp_fname, a.lastname as emp_lname, a.userid , a.department, DATE_FORMAT(a.joindate,'%d %b %y') AS doj, a.designation as emp_desg, b.department as emp_dept, c.fname as rep1_fname, c.lname as rep1_lname, c.emailid as rep1_emailid, d.fname as rep2_fname, d.lname as rep2_lname, d.emailid as rep2_emailid, e.total_cnt , f.read_cnt FROM hr_new_newuser a left join mail_department_mast b on a.department=b.dept_id left join users d on a.reporting_head2=d.uid left join users c on a.reporting_head1=c.uid inner join(select c.users_uid , count(b.sop_dept_id) as total_cnt from hrpms.sopnew_upload a inner join hrpms.sop_department_mapping b on a.department_id = b.sop_dept_id inner join intranet.new_custsup_departmentuser c on b.email_dept_id = c.dept_id group by c.users_uid) e on a.uid = e.users_uid left join(select c.users_uid , count(b.sop_dept_id) as read_cnt from hrpms.sopnew_upload a inner join hrpms.sop_department_mapping b on a.department_id = b.sop_dept_id inner join intranet.new_custsup_departmentuser c on b.email_dept_id = c.dept_id inner join hrpms.sop_new_read_status d on a.id = d.sop_id and c.users_uid = d.users_uid group by c.users_uid) f on a.uid = f.users_uid WHERE `welcome_mail_freeze`=1 and second_mailfreeze=1 and third_mailfreeze=1 and fourth_mailfreeze=1 and DATEDIFF(CURDATE(), joindate) >28 and e.total_cnt !=f.read_cnt ; "; $rec=$this->mysqldb->fetchAll($sql); $subject=" SOP Online Module Clearance- Monthly Reminder"; // var_dump("in each".$val["uid"]); //employee details $c=0; foreach($rec as $k=>$val) { $emp_name=$val['emp_fname'].' '.$val['emp_lname']; $desg=$val['emp_desg']; $emp_emailid=$val['userid'].'@metropolisindia.com'; $uid=$val['uid']; $emp_dept=$val['emp_dept']; $doj=$val['doj']; //reporting head 1 details $head1_name=$val['rep1_fname'].' '.$val['rep1_lname']; $head1_email=$val['rep1_emailid']; //reporting head 2 details $head2_name=$val['rep2_fname'].' '.$val['rep2_lname']; $head2_email=$val['rep2_emailid']; $body="

Dear $head1_name "; if($head2_name) { $body.="/ $head2_name,"; } else { $body.=","; } } $body.="

The following members of your team are yet to go through the departmental SOPs:

"; var_dump("in each ".$val['emp_fname']); foreach($rec as $k=>$val) { $c++; $emp_name=$val['emp_fname'].' '.$val['emp_lname']; $desg=$val['emp_desg']; $emp_emailid=$val['userid'].'@metropolisindia.com'; $uid=$val['uid']; $emp_dept=$val['emp_dept']; $doj=$val['doj']; //reporting head 1 details $head1_name=$val['rep1_fname'].' '.$val['rep1_lname']; $head1_email=$val['rep1_emailid']; //reporting head 2 details $head2_name=$val['rep2_fname'].' '.$val['rep2_lname']; $head2_email=$val['rep2_emailid']; $body.=""; }var_dump("in each ".$val['emp_fname']); $body.="
Sr.no Name Department Designation Doj
$c $emp_name $emp_dept $desg $doj


Several reminders haven been sent previously. This is an important mandate initiated by Top Management and compliance to this is compulsory.

Requesting you to kindly close the same in the next 2 days.

Please get in touch with your regional HR for any queries.

Thanks You,
Human Resources Team "; // var_dump($body); $this->to=array(); $this->cc=array(); array_push($this->cc,"it.support@metropolisindia.com"); array_push($this->to,$head1_email); array_push($this->to,$head2_email); array_push($this->cc,$emp_emailid); //array_push($this->to,"himanshu.bhatia@metropolisindia.com"); //var_dump($subject,$from,$this->to,$this->cc,$body,$textbody); $this->send_mail($subject,$this->from,$this->to,$this->cc,$body,''); $sql="UPDATE hr_new_newuser SET monthly_sopmailfreeze=1,monthly_maildate=now() WHERE uid='$uid';"; $this->execute($sql); } } $lm=new sop_monthly_mail(); $lm->sop_monthly_rem(); ?>