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)); } }
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(); }