'Default', 'basePath' => dirname(__FILE__) )); class audit_processowner_delay_mail { var $mysqlconfig; var $mysqldb; var $data_grid; var $from; function audit_processowner_delay_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) { //var_dump($sql); $rec=$this->mysqldb->fetchAll($sql); return $rec; } function get_pch_users($id) { $sql="Select PCHEmailid from audit_tracker_locationmaster a,audit_tracker_header b where a.id=b.location_id and b.id='$id';"; $rec= $this->fetchAll($sql); $tomail=$rec[0]['PCHEmailid']; //array_push($this->to,$tomail); // echo $this->to; // exit; return $this->to; } function send_mail($subject,$from,$to,$cc,$htmlbody) { $config = array('auth' => 'login', 'username' => 'it.support@metropolisindia.com', 'password' => 'ItDvlp@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) { 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 delay_mail() { global $g_user; global $g_sessionManager; $session= & atkSessionManager :: getSession(); $db= & atkGetDb(); $this->uid = $g_user["uid"]; $this->username = $g_user["userid"]; $sql="SELECT * from audit_tracker_details"; $rec=$db->getRows($sql); $id=$rec['id']; $cdate=$rec['cdate']; $current_date=date('y-m-d H:i:s'); $datediff=strtotime($current_date) - strtotime($cdate); if($datediff > 3 && $datediff < 4) { $location=$rec['location_id']['location']; $audit_from_date=$rec['audit_from_date']['day'].'-'.$rec['audit_from_date']['month'].'-'.$rec['audit_from_date']['year']; $audit_to_date=$rec['audit_to_date']['day'].'-'.$rec['audit_to_date']['month'].'-'.$rec['audit_to_date']['year']; $period_of_audit=$rec['period_of_audit']; $headbody.="Dear Sir/Madam,

Followings are Audit Observation :
Location $location
Period of audit $period_of_audit
Audit To Date $audit_to_date
Audit From Date $audit_from_date
"; $sql="SELECT distinct audit_process from audit_tracker_details where tracker_id='$id'"; $audit_pro=$db->getRows($sql); foreach($audit_pro as $keys=>$row) { $to=array(); $cc=array(); $rowbody=""; $audit_process=$row['audit_process']; $sql="Select a.period_of_audit, a.audit_from_date, a.audit_to_date, e.location as location, c.observation as type_of_observation, CASE WHEN b.risk=1 THEN 'Critical' WHEN b.risk=2 THEN 'High' WHEN b.risk=3 THEN 'Medium' ELSE 'Low/Suggestive' END as Risk, d.process as audit_process, b.audit_observations as audit_observations, b.audit_findings as audit_findings, b.implications as implications, b.recommendation_by_auditors as recommendation_by_auditors, b.process_owner_remarks as process_owner_remarks, f.emailid as emailid, concat(f.fname, ' ',f.lname) as owner_person, a.cdate as cdate, concat(g.fname, ' ',g.lname) as auditorname From audit_tracker_header a inner join audit_tracker_details b on b.tracker_id=a.id left join audit_tracker_observationmaster c on b.type_of_observation=c.id left join audit_tracker_processmaster d on b.audit_process=d.id left join audit_tracker_locationmaster e on a.location_id=e.id left join users f on b.users_uid=f.uid left join users g on a.cuid=g.uid WHERE a.id=$id and b.audit_process='$audit_process';"; $recs=$db->getRows($sql); foreach($recs as $keys=>$row) { $type_of_observation=$row['type_of_observation']; $risk=$row['risk']; $audit_process=$row['audit_process']; $type_of_observation=$row['type_of_observation']; $audit_observations=$row['audit_observations']; $audit_findings=$row['audit_findings']; $implications=$row['implications']; $recommendation_by_auditors=$row['recommendation_by_auditors']; $owner_person=$row['owner_person']; $auditorname=$row['auditorname']; $toemailid=$row['emailid']; $rowbody.=""; array_push($to,$toemailid); } $tailbody="
To update further details http://support.metropolisindia.com
Audit process Type Of Observation Audit Observations Recommendation by auditors Audit findings Implications Owner person
$audit_process $type_of_observation $audit_observations $recommendation_by_auditors $audit_findings $implications $owner_person




Please feel free to revert on below mentioned numbers in case of any query or information required."; //array_push($to,"laxmi.bhor@metropolisindia.com"); array_push($cc,"it.support@metropolisindia.com"); $this->get_pch_users($id); $subject="Audit Observation"; $from="it.support@metropolisindia.com"; //exit; $this->send_mail($subject,$from,$to,$cc,$headbody.$rowbody.$tailbody,$textbody); } } } $lm=new audit_processowner_delay_mail(); $lm->delay_mail(); echo "End Ok...!"; ?>