public function onSendMail($sender, $param) { $mailer = new TMailer(); $mailer->setObject($this->object->SafeText); $mailer->setBody($this->Body->Text); $recipient = array(); if ($this->send_groups->getChecked()) { $indices = $this->groups->SelectedIndices; $result = ''; foreach ($indices as $index) { $item = $this->groups->Items[$index]; $cmd = $this->db->createCommand("SELECT u.id, email1, email2 FROM hr_user AS u LEFT JOIN hr_user_group_attribution AS uga ON uga.id_user=u.id WHERE uga.id_group=" . $item->Value); $query = $cmd->query(); $data = $query->readAll(); foreach ($data as $d) { if ($d['email1'] != '') { $recipient[$d['id']] = $d['email1']; } elseif ($d['email2'] != '') { $recipient[$d['id']] = $d['email2']; } } } } if ($this->send_users->getChecked()) { $indices = $this->users->SelectedIndices; $result = ''; foreach ($indices as $index) { $item = $this->users->Items[$index]; $cmd = $this->db->createCommand("SELECT email1, email2 FROM hr_user WHERE id=" . $item->Value); $query = $cmd->query(); $data = $query->read(); if ($data['email1'] != '') { $recipient[$item->Value] = $data['email1']; } elseif ($data['email2'] != '') { $recipient[$item->Value] = $data['email2']; } } } foreach ($recipient as $r) { $mailer->addRecipient($r); } if ($this->attachment->HasFile) { $this->attachment->saveAs('.' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . $this->attachment->FileName); $mailer->addAttachment('.' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . $this->attachment->FileName, $this->attachment->FileName); } $res = $mailer->sendHtmlMail($this->mailing->getChecked()); if ($this->attachment->HasFile) { unlink('.' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . $this->attachment->FileName); } if ($res) { $pBack = array('okMsg' => Prado::localize('The mail was delivered successfully')); $this->Response->redirect($this->Service->constructUrl('components.easymailing.easymailing', $pBack)); } else { $pBack = array('koMsg' => Prado::localize('The mail was not delivered successfully')); $this->Response->redirect($this->Service->constructUrl('components.easymailing.easymailing', $pBack)); } }
/** * @param array $param parameters of the notification * @return string return the result * @soapmethod */ public function sendMail($param) { $ret = ""; $p_tmp = array(); foreach ($param as $p) { $key = ""; foreach ($p as $k => $v) { if ($k == "key") { $key = $v; } if ($k == "value") { $p_tmp[$key] = $v; $ret .= $key . ":" . $v . ","; } } } $param = $p_tmp; $type = $param["type"]; $code = $param["code"]; $userId = false; $serialNumber = false; $entryId = false; $object = false; switch ($type) { case "ALARM": $object = $param["object"]; break; case "ACCESS": $userId = $param["userId"]; $serialNumber = $param["serialNumber"]; $entryId = $param["entryId"]; break; default: return "Type mismatch"; } $app = Prado::getApplication(); $db = $app->getModule('horuxDb')->DbConnection; $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); $db->Active = true; $sql = "SELECT * FROM hr_notification"; $cmd = $db->createCommand($sql); $data = $cmd->query(); $data = $data->readAll(); foreach ($data as $notification) { $not_id = $notification['id']; $emails = explode(',', $notification['emails']); $sql = "SELECT su.email FROM hr_notification_su AS nsu LEFT JOIN hr_superusers AS su ON su.id=nsu.id_superuser WHERE nsu.id_notification={$not_id}"; $cmd = $db->createCommand($sql); $sus = $cmd->query(); $sus = $sus->readAll(); foreach ($sus as $su) { $emails[] = $su['email']; } $sql = "SELECT * FROM hr_notification_code WHERE id_notification={$not_id} AND type='{$type}' AND code='{$code}'"; $cmd = $db->createCommand($sql); $ncode = $cmd->query(); $ncode = $ncode->read(); if ($ncode) { $mailer = new TMailer(); if ($type == "ALARM") { if ($object > 0) { $sql = "SELECT * FROM hr_device WHERE id={$object}"; $cmd = $db->createCommand($sql); $device = $cmd->query(); $device = $device->read(); $device = $device['name']; } else { $device = ""; } $site = ""; $sql = "SELECT * FROM hr_site WHERE id=1"; $cmd = $db->createCommand($sql); $site = $cmd->query(); $site = $site->read(); $site = $site['name']; $sql = "SELECT * FROM hr_install WHERE `default`=1 AND type='language'"; $cmd = $db->createCommand($sql); $data = $cmd->query(); $data = $data->read(); $lang = $data['param']; Prado::getApplication()->getGlobalization()->setCulture($lang); $body = ""; $body = file_get_contents("./protected/webservice/notification/alarm/{$lang}/{$code}.txt"); $body = str_replace("%site%", $site, $body); $body = str_replace("%device%", $device, $body); $body = str_replace("%date%", date("d.m.y"), $body); $body = str_replace("%time%", date("H:i:s"), $body); switch ($code) { case 900: $mailer->setObject(Prado::localize("Horux notification: Horux Controler seems to be down")); break; case 1001: $mailer->setObject(Prado::localize("Horux notification: Antivandale acivated on {device}", array('device' => $device))); break; case 1002: $mailer->setObject(Prado::localize("Horux notification: Antivandale cleared on {device}", array('device' => $device))); break; case 1003: $mailer->setObject(Prado::localize("Horux notification: Device communication opened on {device}", array('device' => $device))); break; case 1004: $mailer->setObject(Prado::localize("Horux notification: Device communication closed on {device}", array('device' => $device))); break; case 1005: $mailer->setObject(Prado::localize("Horux notification: Device ajar on {device}", array('device' => $device))); break; case 1006: $mailer->setObject(Prado::localize("Horux notification: End device ajar on {device}", array('device' => $device))); break; case 1007: $mailer->setObject(Prado::localize("Horux notification: Door forced on {device}", array('device' => $device))); break; case 1008: $mailer->setObject(Prado::localize("Horux notification: Too many PIN on {device}", array('device' => $device))); break; case 1009: $mailer->setObject(Prado::localize("Horux notification: Temperature alarm on {device}", array('device' => $device))); break; case 1010: $mailer->setObject(Prado::localize("Horux notification: Memory full on {device}", array('device' => $device))); break; case 1011: $mailer->setObject(Prado::localize("Horux notification: Memory warning on {device}", array('device' => $device))); break; case 1012: $mailer->setObject(Prado::localize("Horux notification: Memory key inserted error on {device}", array('device' => $device))); break; case 1013: $mailer->setObject(Prado::localize("Horux notification: Memory key removed error on {device}", array('device' => $device))); break; case 1014: $mailer->setObject(Prado::localize("Horux notification: Device antenna enabled on {device}", array('device' => $device))); break; case 1015: $mailer->setObject(Prado::localize("Horux notification: Device antenna disabled on {device}", array('device' => $device))); break; case 1016: $mailer->setObject(Prado::localize("Horux notification: Device connection not opened on {device}", array('device' => $device))); break; case 1017: $mailer->setObject(Prado::localize("Horux notification: Device communicaiton error on {device}", array('device' => $device))); break; case 1102: $mailer->setObject(Prado::localize("Horux notification: HOLDUP PIN CODE")); break; case 1200: $mailer->setObject(Prado::localize("Horux notification: Cannot start Horux XMLRPC server")); break; case 1300: $mailer->setObject(Prado::localize("Horux notification: Reload database...")); break; case 1301: $mailer->setObject(Prado::localize("Horux notification: Database reloaded")); break; } } if ($type == "ACCESS") { $user = ""; if ($userId && $userId > 0) { $sql = "SELECT * FROM hr_user WHERE id={$userId}"; $cmd = $db->createCommand($sql); $user = $cmd->query(); $user = $user->read(); $user = $user['name'] . ' ' . $user['firstname']; } $deviceName = ""; if ($entryId && $entryId > 0) { $sql = "SELECT * FROM hr_device WHERE id={$entryId}"; $cmd = $db->createCommand($sql); $entryId = $cmd->query(); $entryId = $entryId->read(); $deviceName = $entryId['name']; } $site = ""; $sql = "SELECT * FROM hr_site WHERE id=1"; $cmd = $db->createCommand($sql); $site = $cmd->query(); $site = $site->read(); $site = $site['name']; $sql = "SELECT * FROM hr_install WHERE `default`=1 AND type='language'"; $cmd = $db->createCommand($sql); $data = $cmd->query(); $data = $data->read(); $lang = $data['param']; Prado::getApplication()->getGlobalization()->setCulture($lang); $body = ""; $body = file_get_contents("./protected/webservice/notification/access/{$lang}/{$code}.txt"); $body = str_replace("%user%", $user, $body); $body = str_replace("%site%", $site, $body); $body = str_replace("%device%", $deviceName, $body); $body = str_replace("%key%", $serialNumber, $body); $body = str_replace("%date%", date("d.m.y"), $body); $body = str_replace("%time%", date("H:i:s"), $body); switch ($code) { case 0: $mailer->setObject(Prado::localize("Horux notification: Access by {user}", array('user' => $user))); break; case 1: $mailer->setObject(Prado::localize("Horux notification: Acces bloked - Key blocked")); break; case 2: $mailer->setObject(Prado::localize("Horux notification: Acces bloked - Key unknown")); break; case 3: $mailer->setObject(Prado::localize("Horux notification: Acces bloked - Key not attributed")); break; case 4: $mailer->setObject(Prado::localize("Horux notification: Acces bloked - User not in a group")); break; case 5: $mailer->setObject(Prado::localize("Horux notification: Acces bloked - Key blocked during the week-end")); break; case 6: $mailer->setObject(Prado::localize("Horux notification: Acces bloked - Key blocked during the non working day")); break; case 7: $mailer->setObject(Prado::localize("Horux notification: Acces bloked - Out of date")); break; case 8: $mailer->setObject(Prado::localize("Horux notification: Acces bloked - Out of time")); break; case 9: $mailer->setObject(Prado::localize("Horux notification: Acces bloked - No access right defined for the group")); break; case 11: $mailer->setObject(Prado::localize("Horux notification: Acces bloked - User blocked")); break; } } foreach ($emails as $email) { $mailer->addRecipient($email); } $mailer->setBody($body); $mailer->sendTextMail(true); } } return "ok"; }
public function onDelete($sender, $param) { $cbs = $this->findControlsByType("TActiveCheckBox"); $nDelete = 0; $koMsg = ''; $cbChecked = 0; foreach ($cbs as $cb) { if ((bool) $cb->getChecked() && $cb->Value != "0") { $cbChecked++; } } if ($cbChecked == 0) { $koMsg = Prado::localize('Select one item'); } else { foreach ($cbs as $cb) { if ((bool) $cb->getChecked() && $cb->Value != "0") { $cmd = $this->db->createCommand("SELECT * FROM hr_timux_request WHERE id =:id"); $cmd->bindValue(":id", $cb->Value); $query = $cmd->query(); $data = $query->read(); if ($data['state'] == 'draft') { $cmd = $this->db->createCommand("DELETE FROM hr_timux_request WHERE id =:id"); $cmd->bindValue(":id", $cb->Value); if ($cmd->execute()) { $nDelete++; } $cmd = $this->db->createCommand("DELETE FROM hr_timux_request_leave WHERE request_id =:id"); $cmd->bindValue(":id", $cb->Value); $cmd->execute(); } else { if ($data['state'] != 'refused') { $cmd = $this->db->createCommand("UPDATE hr_timux_request SET state='canceled' WHERE id =:id"); $cmd->bindValue(":id", $cb->Value); if ($cmd->execute()) { $nDelete++; $cmd = $this->db->createCommand("SELECT * FROM hr_timux_request_workflow WHERE request_id=:id"); $cmd->bindValue(":id", $cb->Value); $query = $cmd->query(); $data = $query->readAll(); $mailer = new TMailer(); foreach ($data as $d) { $user_id = $d['user_id']; $cmd = $this->db->createCommand("SELECT u.email1, u.email2, su.email AS email3 FROM hr_user AS u LEFT JOIN hr_superusers AS su ON su.user_id=u.id WHERE u.id=:id"); $cmd->bindValue(":id", $user_id); $query = $cmd->query(); $data2 = $query->read(); if ($data2['email1'] != '' || $data2['email2'] != '' || $data2['email3'] != '') { if ($data2['email2'] != '') { $mailer->addRecipient($data2['email2']); } elseif ($data2['email3'] != '') { $mailer->addRecipient($data2['email3']); } elseif ($data2['email1'] != '') { $mailer->addRecipient($data2['email1']); } } } $mailer->setObject(Prado::localize("Leave request canceled")); $body = Prado::localize("The leave request from {name} was canceled<br/><br/>Timux", array('name' => $this->employee->getFullName())); $mailer->setBody($body); $mailer->sendHtmlMail(); $cmd = $this->db->createCommand("DELETE FROM hr_timux_request_workflow WHERE request_id =:id"); $cmd->bindValue(":id", $cb->Value); $cmd->execute(); } } } //$this->log("Delete the key: ".$data['serialNumber']); } } } if ($koMsg !== '') { $pBack = array('koMsg' => $koMsg); } else { $pBack = array('okMsg' => Prado::localize('{n} leave request was deleted/canceled', array('n' => $nDelete))); } $this->Response->redirect($this->Service->constructUrl('components.timuxuser.leaverequest.leaverequest', $pBack)); }
protected function sendEmail($lastId) { $cmd = $this->db->createCommand("SELECT * FROM hr_timux_request_workflow WHERE request_id=:id"); $cmd->bindValue(":id", $lastId); $query = $cmd->query(); $data = $query->readAll(); $mailer = new TMailer(); foreach ($data as $d) { $user_id = $d['user_id']; $cmd = $this->db->createCommand("SELECT u.email1, u.email2, su.email AS email3 FROM hr_user AS u LEFT JOIN hr_superusers AS su ON su.user_id=u.id WHERE u.id=:id"); $cmd->bindValue(":id", $user_id); $query = $cmd->query(); $data2 = $query->read(); if ($data2['email1'] != '' || $data2['email2'] != '' || $data2['email3'] != '') { if ($data2['email2'] != '') { $mailer->addRecipient($data2['email2']); } elseif ($data2['email3'] != '') { $mailer->addRecipient($data2['email3']); } elseif ($data2['email1'] != '') { $mailer->addRecipient($data2['email1']); } } } $mailer->setObject(Prado::localize("New Leave request")); $body = Prado::localize("A new leave request from {name} was added in your validation task<br/><br/>Timux", array('name' => $this->employee->getFullName())); $mailer->setBody($body); $mailer->sendHtmlMail(); }
protected function saveData() { $cmd = $this->db->createCommand("UPDATE `hr_timux_request` SET\n modifyDate=CURDATE(),\n modifyUserId=:modifyUserId,\n state=:state,\n remark=:remark\n WHERE id=:id\n ;"); $cmd->bindValue(":modifyUserId", $this->userId, PDO::PARAM_STR); $remark = $this->remark->Text; $remark .= "<hr>"; $remark .= $this->myremark->Text; $cmd->bindValue(":remark", $remark, PDO::PARAM_STR); $validation = ''; if ($this->refuse->getChecked()) { $validation = 'refused'; } if ($this->validate->getChecked()) { $cmd2 = $this->db->createCommand("SELECT * FROM hr_timux_request_workflow WHERE request_id =:id"); $cmd2->bindValue(":id", $this->id->Value, PDO::PARAM_INT); $query = $cmd2->query(); $data = $query->read(); $validatorLevel = $data['validatorLevel']; $cmd2 = $this->db->createCommand("SELECT u.id, u.department, CONCAT(u.name, ' ', u.firstname) AS employee FROM hr_timux_request AS tr LEFT JOIN hr_timux_request_leave AS rl ON rl.request_id=tr.id LEFT JOIN hr_user AS u ON u.id=tr.userId WHERE tr.id=:id"); $cmd2->bindValue(":id", $this->id->Value, PDO::PARAM_INT); $query = $cmd2->query(); $data = $query->read(); $department = $data['department']; $fullName = $data['employee']; $employeeId = $data['id']; $cmd2 = $this->db->createCommand("SELECT * FROM hr_timux_workflow WHERE departmentId=:id OR departmentId=0"); $cmd2->bindValue(":id", $department, PDO::PARAM_INT); $query = $cmd2->query(); $data = $query->read(); $v = array(0, 0, 0); $level = 2; switch ($validatorLevel) { case 1: $v[0] = $data['validator2']; $v[1] = $data['validator21']; $v[2] = $data['validator22']; $level = 2; break; case 2: $v[0] = $data['validator3']; $v[1] = $data['validator31']; $v[2] = $data['validator32']; $level = 3; break; case 3: break; } $isNextValidator = false; foreach ($v as $s) { if ($s != 0) { $isNextValidator = true; } } if ($isNextValidator) { $cmd2 = $this->db->createCommand("DELETE FROM hr_timux_request_workflow WHERE request_id =:id"); $cmd2->bindValue(":id", $this->id->Value); $cmd2->execute(); foreach ($v as $s) { if ($s != 0) { $cmd2 = $this->db->createCommand("INSERT `hr_timux_request_workflow` SET\n request_id=:request_id,\n user_id=:user_id,\n validatorLevel=:validatorLevel\n ;"); $cmd2->bindValue(":request_id", $this->id->Value, PDO::PARAM_STR); $cmd2->bindValue(":user_id", $s, PDO::PARAM_STR); $cmd2->bindValue(":validatorLevel", $level, PDO::PARAM_STR); $cmd2->execute(); } } $cmd2 = $this->db->createCommand("SELECT * FROM hr_timux_request_workflow WHERE request_id=:id"); $cmd2->bindValue(":id", $this->id->Value); $query = $cmd2->query(); $data = $query->readAll(); $mailer = new TMailer(); foreach ($data as $d) { $user_id = $d['user_id']; $cmd2 = $this->db->createCommand("SELECT u.email1, u.email2, su.email AS email3 FROM hr_user AS u LEFT JOIN hr_superusers AS su ON su.user_id=u.id WHERE u.id=:id"); $cmd2->bindValue(":id", $user_id); $query = $cmd2->query(); $data2 = $query->read(); if ($data2['email1'] != '' || $data2['email2'] != '' || $data2['email3'] != '') { if ($data2['email2'] != '') { $mailer->addRecipient($data2['email2']); } elseif ($data2['email3'] != '') { $mailer->addRecipient($data2['email3']); } elseif ($data2['email1'] != '') { $mailer->addRecipient($data2['email1']); } } } $mailer->setObject(Prado::localize("New Leave request")); $body = Prado::localize("A new leave request from {name} was added in your validation task<br/><br/>Timux", array('name' => $fullName)); $mailer->setBody($body); $mailer->sendHtmlMail(); $validation = 'validating'; } else { $mailer = new TMailer(); $cmd2 = $this->db->createCommand("SELECT u.email1, u.email2, su.email AS email3 FROM hr_user AS u LEFT JOIN hr_superusers AS su ON su.user_id=u.id WHERE u.id=:id"); $cmd2->bindValue(":id", $employeeId); $query = $cmd2->query(); $data2 = $query->read(); if ($data2['email1'] != '' || $data2['email2'] != '' || $data2['email3'] != '') { if ($data2['email2'] != '') { $mailer->addRecipient($data2['email2']); } elseif ($data2['email3'] != '') { $mailer->addRecipient($data2['email3']); } elseif ($data2['email1'] != '') { $mailer->addRecipient($data2['email1']); } } $mailer->setObject(Prado::localize("Leave request validated")); $body = Prado::localize("{name}<br/><br>Your leave request was validated<br/><br/>Timux", array('name' => $fullName)); $mailer->setBody($body); $mailer->sendHtmlMail(); $cmd2 = $this->db->createCommand("DELETE FROM hr_timux_request_workflow WHERE request_id =:id"); $cmd2->bindValue(":id", $this->id->Value); $cmd2->execute(); $validation = 'validate'; } } $cmd->bindValue(":state", $validation, PDO::PARAM_STR); $cmd->bindValue(":id", $this->id->Value, PDO::PARAM_STR); $res1 = $cmd->execute(); if ($validation == 'refused') { $cmd = $this->db->createCommand("DELETE FROM hr_timux_request_workflow WHERE request_id =:id"); $cmd->bindValue(":id", $this->id->Value); $cmd->execute(); $cmd2 = $this->db->createCommand("SELECT u.id, u.department, CONCAT(u.name, ' ', u.firstname) AS employee FROM hr_timux_request AS tr LEFT JOIN hr_timux_request_leave AS rl ON rl.request_id=tr.id LEFT JOIN hr_user AS u ON u.id=tr.userId WHERE tr.id=:id"); $cmd2->bindValue(":id", $this->id->Value, PDO::PARAM_INT); $query = $cmd2->query(); $data = $query->read(); $department = $data['department']; $fullName = $data['employee']; $employeeId = $data['id']; $mailer = new TMailer(); $cmd2 = $this->db->createCommand("SELECT u.email1, u.email2, su.email AS email3 FROM hr_user AS u LEFT JOIN hr_superusers AS su ON su.user_id=u.id WHERE u.id=:id"); $cmd2->bindValue(":id", $employeeId); $query = $cmd2->query(); $data2 = $query->read(); if ($data2['email1'] != '' || $data2['email2'] != '' || $data2['email3'] != '') { if ($data2['email2'] != '') { $mailer->addRecipient($data2['email2']); } elseif ($data2['email3'] != '') { $mailer->addRecipient($data2['email3']); } elseif ($data2['email1'] != '') { $mailer->addRecipient($data2['email1']); } } $mailer->setObject(Prado::localize("Leave request refused")); $body = Prado::localize("{name}<br/><br>Your leave request was refused<br/><br/>Timux", array('name' => $fullName)); $mailer->setBody($body); $mailer->sendHtmlMail(); } return $res1; }
protected function sendEmail($requestId, $object, $body) { $cmd = $this->db->createCommand("SELECT * FROM hr_timux_request_workflow WHERE request_id=:id"); $cmd->bindValue(":id", $requestId); $query = $cmd->query(); $data = $query->readAll(); $mailer = new TMailer(); foreach ($data as $d) { $user_id = $d['user_id']; $cmd = $this->db->createCommand("SELECT u.email1, u.email2, su.email AS email3 FROM hr_user AS u LEFT JOIN hr_superusers AS su ON su.user_id=u.id WHERE u.id=:id"); $cmd->bindValue(":id", $user_id); $query = $cmd->query(); $data2 = $query->read(); if ($data2['email1'] != '' || $data2['email2'] != '' || $data2['email3'] != '') { if ($data2['email2'] != '') { $mailer->addRecipient($data2['email2']); } elseif ($data2['email3'] != '') { $mailer->addRecipient($data2['email3']); } elseif ($data2['email1'] != '') { $mailer->addRecipient($data2['email1']); } } } $mailer->setObject($object); $mailer->setBody($body); $mailer->sendHtmlMail(); }