public function pushMail($subject, $message, $address, $priority) { if (isset($address['email']) && isset($address['name'])) { $email = new Emails(); $email->email_subject = $subject; $email->email_body = $message; $email->email_priority = $priority; $email->email_toName = $address['name']; $email->email_toMail = $address['email']; $email->save(false); } else { for ($i = 0; $i < count($address); $i++) { $email = new Emails(); $email->email_subject = $subject; $email->email_body = $message; $email->email_priority = $priority; if (is_array($address[$i])) { $email->email_toName = $address[$i]['name']; $email->email_toMail = $address[$i]['email']; $email->save(false); } else { $email->email_toName = str_replace('"', '', $address[$i]); $email->email_toMail = str_replace('"', '', $address[$i]); $email->save(false); } } } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Emails(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Emails'])) { $model->attributes = $_POST['Emails']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionAddEmail() { if(isset($_POST['url'])) { $email = Emails::model()->find(array('condition'=>'email = :email', 'params'=>array(':email'=>$_POST['url']))); if($email) { echo Yii::t('main', 'Такий email уже використовується'); }else{ $email = new Emails(); $email->email = $_POST['url']; if($email->save()) echo Yii::t('main', 'Дякуэмо за підписку!'); } } }
function track_email($user_name, $password, $contact_ids, $date_sent, $email_subject, $email_body) { if (authentication($user_name, $password)) { global $current_user; global $adb; global $log; require_once 'modules/Users/Users.php'; require_once 'modules/Emails/Emails.php'; $current_user = new Users(); $user_id = $current_user->retrieve_user_id($user_name); $query = "select email1 from vtiger_users where id =?"; $result = $adb->pquery($query, array($user_id)); $user_emailid = $adb->query_result($result, 0, "email1"); $current_user = $current_user->retrieveCurrentUserInfoFromFile($user_id); $email = new Emails(); //$log->debug($msgdtls['contactid']); $emailbody = str_replace("'", "''", $email_body); $emailsubject = str_replace("'", "''", $email_subject); $datesent = substr($date_sent, 1, 10); $mydate = date('Y-m-d', $datesent); $mydate = DateTimeField::convertToDBFormat($mydate); $email->column_fields[subject] = $emailsubject; $email->column_fields[assigned_user_id] = $user_id; $email->column_fields[date_start] = $mydate; $email->column_fields[description] = $emailbody; $email->column_fields[activitytype] = 'Emails'; $email->plugin_save = true; $email->save("Emails"); $query = "select fieldid from vtiger_field where fieldname = 'email' and tabid = 4 and vtiger_field.presence in (0,2)"; $result = $adb->pquery($query, array()); $field_id = $adb->query_result($result, 0, "fieldid"); $email->set_emails_contact_invitee_relationship($email->id, $contact_ids); $email->set_emails_se_invitee_relationship($email->id, $contact_ids); $email->set_emails_user_invitee_relationship($email->id, $user_id); $sql = "select email from vtiger_contactdetails inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_contactdetails.contactid where vtiger_crmentity.deleted =0 and vtiger_contactdetails.contactid=?"; $result = $adb->pquery($sql, array($contact_ids)); $camodulerow = $adb->fetch_array($result); if (isset($camodulerow)) { $emailid = $camodulerow["email"]; //added to save < as $lt; and > as > in the database so as to retrive the emailID $user_emailid = str_replace('<', '<', $user_emailid); $user_emailid = str_replace('>', '>', $user_emailid); $query = 'insert into vtiger_emaildetails values (?,?,?,?,?,?,?,?)'; $params = array($email->id, $emailid, $user_emailid, "", "", "", $user_id . '@-1|' . $contact_ids . '@' . $field_id . '|', "THUNDERBIRD"); $adb->pquery($query, $params); } return $email->id; } }
public function actionIndex() { $recipients = $_POST['recipients']; $title = $_POST['title']; $message = $_POST['message']; $profile_url = 'http://' . $_SERVER['SERVER_NAME'] . '/user/profile/edit'; $message_ps = '<br><br>' . ProjectModule::t('You can unsubscribe...') . ':'; $message_ps .= '<br><a href="' . $profile_url . '">' . $profile_url . '</a>'; if ($recipients && $message && $title) { if ($recipients == 'executors') { $role = 'Author'; } elseif ($recipients == 'customers') { $role = 'Customer'; } //$users = User::model()->findAllCustomers(); $users = User::model()->resetScope()->Role($role)->with(array('profile' => array('select' => array('profile.general_mailing'))))->findAll(); foreach ($users as $user) { if (!$user->profile || $user->profile->general_mailing == 1) { $email = new Emails(); $email->to = $user->email; $email->subject = $title; $email->body = $message . $message_ps; $email->type = 0; $email->dt = time(); $email->save(); //print_r( $user ); //echo $email->body; //echo '<br>'; } } //print_r($users); $title = ''; $message = ''; $recipients = null; $result = ProjectModule::t('Your message is sending...'); } else { $result = ProjectModule::t('Something wrong...'); } $this->render('index', array('title' => $title, 'message' => $message, 'recipients' => $recipients, 'result' => $result)); }
/** * Create new Email record (and link to given record) including attachments * @global Users $current_user * @global PearDataBase $adb * @param MailManager_Message_Model $mailrecord * @param String $module * @param CRMEntity $linkfocus * @return Integer */ function __CreateNewEmail($mailrecord, $module, $linkfocus) { global $current_user, $adb; if (!$current_user) { $current_user = Users::getActiveAdminUser(); } $handler = vtws_getModuleHandlerFromName('Emails', $current_user); $meta = $handler->getMeta(); if ($meta->hasWriteAccess() != true) { return false; } $focus = new Emails(); $focus->column_fields['activitytype'] = 'Emails'; $focus->column_fields['subject'] = $mailrecord->_subject; if (!empty($module)) { $focus->column_fields['parent_type'] = $module; } if (!empty($linkfocus->id)) { $focus->column_fields['parent_id'] = "{$linkfocus->id}@-1|"; } $focus->column_fields['description'] = $mailrecord->getBodyHTML(); $focus->column_fields['assigned_user_id'] = $current_user->id; $focus->column_fields["date_start"] = date('Y-m-d', $mailrecord->_date); $focus->column_fields["email_flag"] = 'MailManager'; $from = $mailrecord->_from[0]; $to = $mailrecord->_to[0]; $cc = !empty($mailrecord->_cc) ? implode(',', $mailrecord->_cc) : ''; $bcc = !empty($mailrecord->_bcc) ? implode(',', $mailrecord->_bcc) : ''; //emails field were restructured and to,bcc and cc field are JSON arrays $focus->column_fields['from_email'] = $from; $focus->column_fields['saved_toid'] = $to; $focus->column_fields['ccmail'] = $cc; $focus->column_fields['bccmail'] = $bcc; $focus->save('Emails'); $emailid = $focus->id; // TODO: Handle attachments of the mail (inline/file) $this->__SaveAttachements($mailrecord, 'Emails', $focus); return $emailid; }
public function actionSend() { $model = new Emails(); $this->_prepairJson(); $orderId = $this->_request->getParam('orderId'); $typeId = $this->_request->getParam('typeId'); $back = $this->_request->getParam('back'); $cost = $this->_request->getParam('cost'); $order = Zakaz::model()->findByPk($orderId); $arr_type = array(Emails::TYPE_18, Emails::TYPE_19, Emails::TYPE_20, Emails::TYPE_21, Emails::TYPE_22, Emails::TYPE_23, Emails::TYPE_24); if (in_array($typeId, $arr_type)) { $user = User::model()->findByPk($order->executor); } else { $user = User::model()->findByPk($order->user_id); } $model->to_id = $user->id; $profile = Profile::model()->findAll("`user_id`='{$user->id}'"); $rec = Templates::model()->findAll("`type_id`='{$typeId}'"); $title = $rec[0]->title; $model->name = $profle->firstname; if (strlen($model->name) < 2) { $model->name = $user->username; } $model->login = $user->username; $model->num_order = $orderId; $model->page_order = 'http://' . $_SERVER['SERVER_NAME'] . '/project/chat?orderId=' . $orderId; $model->message = $rec[0]->text; $model->price_order = $cost; $this->sum_order = $cost; $model->sendTo($user->email, $rec[0]->text, $typeId); $model->save(); /* if (!isset($back)) $back = 'index'; $this->render($back, [ 'model'=>$model ]); */ }
function AddMessageToContact($username, $session, $contactid, $msgdtls) { if (!validateSession($username, $session)) { return null; } global $current_user; global $adb; require_once 'modules/Users/Users.php'; require_once 'modules/Emails/Emails.php'; $current_user = new Users(); $user_id = $current_user->retrieve_user_id($username); $query = "select email1 from vtiger_users where id = ?"; $result = $adb->pquery($query, array($user_id)); $user_emailid = $adb->query_result($result, 0, "email1"); $current_user = $current_user->retrieveCurrentUserInfoFromFile($user_id); foreach ($msgdtls as $msgdtl) { if (isset($msgdtl)) { $email = new Emails(); //$log->debug($msgdtls['contactid']); $email_body = str_replace("'", "''", $msgdtl['body']); $email_body = str_replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">', " ", $email_body); $email_subject = str_replace("'", "''", $msgdtl['subject']); $date_sent = getDisplayDate($msgdtl['datesent']); $email->column_fields[subject] = $email_subject; $email->column_fields[assigned_user_id] = $user_id; $email->column_fields[date_start] = $date_sent; $email->column_fields[description] = $email_body; $email->column_fields[activitytype] = 'Emails'; $email->column_fields[email_flag] = 'SENT'; $email->plugin_save = true; $email->save("Emails"); $query = "select fieldid from vtiger_field where fieldname = 'email' and tabid = 4 and vtiger_field.presence in (0,2)"; $result = $adb->pquery($query, array()); $field_id = $adb->query_result($result, 0, "fieldid"); $email->set_emails_contact_invitee_relationship($email->id, $contactid); $email->set_emails_se_invitee_relationship($email->id, $contactid); $email->set_emails_user_invitee_relationship($email->id, $user_id); return $email->id; } else { return ""; } } }
/** * @param $context \Workflow\VTEntity * @return mixed */ public function handleTask(&$context) { global $adb, $current_user; global $current_language; if (defined("WF_DEMO_MODE") && constant("WF_DEMO_MODE") == true) { return "yes"; } if (!class_exists("Workflow_PHPMailer")) { require_once "modules/Workflow2/phpmailer/class.phpmailer.php"; } #$result = $adb->query("select user_name, email1, email2 from vtiger_users where id=1"); #$from_email = "*****@*****.**"; #$from_name = "Stefan Warnat"; $module = $context->getModuleName(); $et = new \Workflow\VTTemplate($context); $to_email = $et->render(trim($this->get("recepient")), ","); # $connected = $this->getConnectedObjects("Absender"); if (count($connected) > 0) { $from_name = trim($connected[0]->get("first_name") . " " . $connected[0]->get("last_name")); $from_email = $connected[0]->get("email1"); } else { $from_name = $et->render(trim($this->get("from_name")), ","); # $from_email = $et->render(trim($this->get("from_mail")), ","); # } $cc = $et->render(trim($this->get("emailcc")), ","); # $bcc = $et->render(trim($this->get("emailbcc")), ","); # /** * Connected BCC Objects * @var $connected */ $connected = $this->getConnectedObjects("BCC"); $bccs = $connected->get("email1"); if (count($bccs) > 0) { $bcc = array($bcc); foreach ($bccs as $bccTMP) { $bcc[] = $bccTMP; } $bcc = trim(implode(",", $bcc), ","); } if (strlen(trim($to_email, " \t\n,")) == 0 && strlen(trim($cc, " \t\n,")) == 0 && strlen(trim($bcc, " \t\n,")) == 0) { return "yes"; } $storeid = trim($this->get("storeid", $context)); if (empty($storeid) || $storeid == -1 || !is_numeric($storeid)) { $storeid = $context->getId(); } $embeddedImages = array(); $content = $this->get("content"); $subject = $this->get("subject"); #$subject = utf8_decode($subject); #$content = utf8_encode($content); $content = html_entity_decode(str_replace(" ", " ", $content), ENT_QUOTES, "UTF-8"); #$subject = html_entity_decode(str_replace(" ", " ", $subject), ENT_QUOTES, "UTF-8"); $subject = $et->render(trim($subject)); $content = $et->render(trim($content)); $mailtemplate = $this->get("mailtemplate"); if (!empty($mailtemplate) && $mailtemplate != -1) { if (strpos($mailtemplate, 's#') === false) { $sql = "SELECT * FROM vtiger_emailtemplates WHERE templateid = " . intval($mailtemplate); $result = $adb->query($sql); $mailtemplate = $adb->fetchByAssoc($result); $content = str_replace('$mailtext', $content, html_entity_decode($mailtemplate["body"], ENT_COMPAT, 'UTF-8')); $content = Vtiger_Functions::getMergedDescription($content, $context->getId(), $context->getModuleName()); } else { $parts = explode('#', $mailtemplate); switch ($parts[1]) { case 'emailmaker': $templateid = $parts[2]; $sql = 'SELECT body, subject FROM vtiger_emakertemplates WHERE templateid = ?'; $result = $adb->pquery($sql, array($templateid)); $EMAILContentModel = \EMAILMaker_EMAILContent_Model::getInstance($this->getModuleName(), $context->getId(), $current_language, $context->getId(), $this->getModuleName()); $EMAILContentModel->setSubject($adb->query_result($result, 0, 'subject')); $EMAILContentModel->setBody($adb->query_result($result, 0, 'body')); $EMAILContentModel->getContent(true); $embeddedImages = $EMAILContentModel->getEmailImages(); $subject = $EMAILContentModel->getSubject(); $content = $EMAILContentModel->getBody(); break; } } } #$content = htmlentities($content, ENT_NOQUOTES, "UTF-8"); if (getTabid('Emails') && vtlib_isModuleActive('Emails')) { require_once 'modules/Emails/Emails.php'; $focus = new Emails(); $focus->column_fields["assigned_user_id"] = \Workflow\VTEntity::getUser()->id; $focus->column_fields["activitytype"] = "Emails"; $focus->column_fields["date_start"] = date("Y-m-d"); $focus->column_fields["parent_id"] = $storeid; $focus->column_fields["email_flag"] = "SAVED"; $focus->column_fields["subject"] = $subject; $focus->column_fields["description"] = $content; $focus->column_fields["from_email"] = $from_email; $focus->column_fields["saved_toid"] = '["' . str_replace(',', '","', trim($to_email, ",")) . '"]'; $focus->column_fields["ccmail"] = $cc; $focus->column_fields["bccmail"] = $bcc; $focus->save("Emails"); $this->_mailRecord = $focus; #error_log("eMail:".$emailID); $emailID = $focus->id; } else { $emailID = ""; } $attachments = json_decode($this->get("attachments"), true); if (is_array($attachments) && count($attachments) > 0) { // Module greifen auf Datenbank zurück. Daher vorher speichern! $context->save(); foreach ($attachments as $key => $value) { if ($value == false) { continue; } if (is_string($value)) { $value = array($value, false, array()); } // legacy check if (strpos($key, 'document#') === 0) { $key = 's#' . $key; } if (strpos($key, 's#') === 0) { $tmpParts = explode('#', $key, 2); $specialAttachments = \Workflow\Attachment::getAttachments($tmpParts[1], $value, $context, \Workflow\Attachment::MODE_NOT_ADD_NEW_ATTACHMENTS); foreach ($specialAttachments as $attachment) { if ($attachment[0] === 'ID') { $this->attachByAttachmentId($attachment[1]); } elseif ($attachment[0] === 'PATH') { $this->attachFile($attachment[1], $attachment[2], $attachment[3]); } } } else { $file = \Workflow\InterfaceFiles::getFile($key, $this->getModuleName(), $context->getId()); $this->attachFile($file['path'], $value[1] != false ? $value[1] : $file['name'], $file['type']); } } } $receiver = explode(",", $to_email); foreach ($receiver as $to_email) { $to_email = trim($to_email); if (empty($to_email)) { continue; } if (DEMO_MODE == false) { // Self using $mail = new Workflow_PHPMailer(); $mail->CharSet = 'utf-8'; $mail->IsSMTP(); foreach ($embeddedImages as $cid => $cdata) { $mail->AddEmbeddedImage($cdata["path"], $cid, $cdata["name"]); } setMailServerProperties($mail); $to_email = trim($to_email, ","); #setMailerProperties($mail,$subject, $content, $from_email, $from_name, trim($to_email,","), "all", $emailID); $mail->Timeout = 60; $mail->FromName = $from_name; $mail->From = $from_email; $this->addStat("From: " . $from_name . " <" . $from_email . ">"); if ($this->get('trackAccess') == '1') { //Including email tracking details global $site_URL, $application_unique_key; $counterUrl = $site_URL . '/modules/Emails/actions/TrackAccess.php?parentId=' . $storeid . '&record=' . $focus->id . '&applicationKey=' . $application_unique_key; $counterHeight = 1; $counterWidth = 1; if (defined('TRACKING_IMG_HEIGHT')) { $counterHeight = TRACKING_IMG_HEIGHT; } if (defined('TRACKING_IMG_WIDTH')) { $counterWidth = TRACKING_IMG_WIDTH; } $content = "<img src='" . $counterUrl . "' alt='' width='" . $counterWidth . "' height='" . $counterHeight . "'>" . $content; } $mail->Subject = $subject; $this->addStat("Subject: " . $subject); $mail->MsgHTML($content); $mail->SMTPDebug = 2; $mail->addAddress($to_email); $this->addStat("To: " . $to_email); setCCAddress($mail, 'cc', $cc); setCCAddress($mail, 'bcc', $bcc); #$mail->IsHTML(true); addAllAttachments($mail, $emailID); try { ob_start(); $mail_return = MailSend($mail); $debug = ob_get_clean(); $this->addStat($debug); } catch (Workflow_phpmailerException $exp) { Workflow2::error_handler($exp->getCode(), $exp->getMessage(), $exp->getFile(), $exp->getLine()); } #$mail_return = send_mail($module, $to_email,$from_name,$from_email,$subject,$content, $cc, $bcc,'all',$emailID); } else { $mail_return = 1; } $this->addStat("Send eMail with following Result:"); $this->addStat($mail_return); if ($mail_return != 1) { if (empty($mail->ErrorInfo) && empty($mail_return)) { $mail_return = 1; } } $context->setEnvironment("sendmail_result", $mail_return, $this); if ($mail_return != 1) { if ($this->isContinued()) { $delay = 180; } else { $delay = 60; } Workflow2::send_error("Sendmail Task couldn't send an email to " . $to_email . "<br>Error: " . var_export($mail->ErrorInfo, true) . "<br><br>The Task will be rerun after " . $delay . " minutes.", __FILE__, __LINE__); Workflow2::error_handler(E_NONBREAK_ERROR, "Sendmail Task couldn't send an email to " . $to_email . "<br>Error: " . var_export($mail->ErrorInfo, true) . "<br><br>The Task will be rerun after " . $delay . " minutes.", __FILE__, __LINE__); return array("delay" => time() + $delay * 60, "checkmode" => "static"); } } // Set Mails as Send $sql = "UPDATE vtiger_emaildetails SET email_flag = 'SENT' WHERE emailid = '" . $emailID . "'"; $adb->query($sql); return "yes"; }
$from_array = array("*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**"); $body_array = array("This release has close to 500 fixes in it and has gone through almost 7 rounds of validation. We think it is a stable product that you can directly use in deployment! ", "Nice to have you visit us, very nice of you. Stay for sometime and have a look at our product. I am sure you will like it", "This will take some time to fix. Can you provide me more details please?", "What a cool tool! I wish I had found it earlier. Oh it has a lot of my friends name in it too! I too can contribute. But how?", "Urgent. I need this done last week! Guys, you are the ones I am depending on. Do something!"); for ($i = 0; $i < 5; $i++) { $email = new Emails(); $email->column_fields["assigned_user_id"] = $assigned_user_id; $rand = array_rand($num_array); $email->column_fields["subject"] = $esubj_array[$i]; $email->column_fields["filename"] = $filename_array[$i]; $email->column_fields["date_start"] = $startdate_array[$i]; $email->column_fields["semodule"] = 'Tasks'; $email->column_fields["activitytype"] = 'Emails'; $email->column_fields["description"] = $body_array[$i]; $email->column_fields["saved_toid"] = $to_array[$i]; $focus->column_fields['ccmail'] = $cc_array[$i]; $focus->column_fields['bccmail'] = $bcc_array[$i]; $email->save("Emails"); $email_ids[] = $email->id; } //Populate PriceBook data $PB_array = array("Cd-R PB", "Vtiger PB", "Gator PB", "Kyple PB", "Pastor PB", "Zoho PB", "PB_100", "Per_PB", "CST_PB", "GATE_PB", "Chevron_PB", "Pizza_PB"); $Active_array = array("0", "1", "1", "0", "1", "0", "1", "1", "0", "1", "0", "1"); //$num_array = array(0,1,2,3,4); for ($i = 0; $i < 12; $i++) { $pricebook = new PriceBooks(); $rand = array_rand($num_array); $pricebook->column_fields["bookname"] = $PB_array[$i]; $pricebook->column_fields["active"] = $Active_array[$i]; $pricebook->column_fields["currency_id"] = '1'; $pricebook->save("PriceBooks"); $pricebook_ids[] = $pricebook->id; }
$focus->column_fields["date_start"] = $ddate; $focus->column_fields["time_start"] = $dtime; //Set the flag as 'Webmails' to show up the sent date $focus->column_fields["email_flag"] = "WEBMAIL"; //Save the To field information in vtiger_emaildetails $all_to_ids = $email->to; $focus->column_fields["saved_toid"] = implode(',', $all_to_ids); //store the sent date in 'yyyy-mm-dd' format $user_old_date_format = $current_user->date_format; $current_user->date_format = 'yyyy-mm-dd'; $focus->column_fields["description"] = $msgData; //to save the email details in vtiger_emaildetails vtiger_tables $fieldid = $adb->query_result($adb->pquery('select fieldid from vtiger_field where tablename="vtiger_contactdetails" and fieldname="email" and columnname="email" and vtiger_field.presence in (0,2)', array()), 0, 'fieldid'); if (count($email->relationship) != 0) { $focus->column_fields['parent_id'] = $email->relationship["id"] . '@' . $fieldid . '|'; $focus->save("Emails"); if ($email->relationship["type"] == "Contacts") { add_attachment_to_contact($email->relationship["id"], $email, $focus->id); } } else { //if relationship is not available create a contact and relate the email to the contact require_once 'modules/Contacts/Contacts.php'; $contact_focus = new Contacts(); //Populate the lastname as emailid if email doesn't have from name if ($email->fromname) { $contact_focus->column_fields['lastname'] = $email->fromname; } else { $contact_focus->column_fields['lastname'] = $email->from; } $contact_focus->column_fields['email'] = $email->from; $contact_focus->column_fields["assigned_user_id"] = $current_user->id;
/** * Create new Email record (and link to given record) including attachements */ function __CreateNewEmail($mailrecord, $module, $linkfocus) { global $current_user, $adb; if (!$current_user) { $current_user = Users::getActiveAdminUser(); } $focus = new Emails(); $focus->column_fields['parent_type'] = $module; $focus->column_fields['activitytype'] = 'Emails'; $focus->column_fields['parent_id'] = "{$linkfocus->id}@-1|"; $focus->column_fields['subject'] = $mailrecord->_subject; $focus->column_fields['description'] = $mailrecord->getBodyHTML(); $focus->column_fields['assigned_user_id'] = $linkfocus->column_fields['assigned_user_id']; $focus->column_fields["date_start"] = date('Y-m-d', $mailrecord->_date); $focus->column_fields["email_flag"] = 'MAILSCANNER'; $from = $mailrecord->_from[0]; $to = $mailrecord->_to[0]; $cc = !empty($mailrecord->_cc) ? implode(',', $mailrecord->_cc) : ''; $bcc = !empty($mailrecord->_bcc) ? implode(',', $mailrecord->_bcc) : ''; $flag = ''; // 'SENT'/'SAVED' //emails field were restructured and to,bcc and cc field are JSON arrays $focus->column_fields['from_email'] = $from; $focus->column_fields['saved_toid'] = $to; $focus->column_fields['ccmail'] = $cc; $focus->column_fields['bccmail'] = $bcc; $focus->save('Emails'); $emailid = $focus->id; $this->log("Created [{$focus->id}]: {$mailrecord->_subject} linked it to " . $linkfocus->id); // TODO: Handle attachments of the mail (inline/file) $this->__SaveAttachements($mailrecord, 'Emails', $focus); return $emailid; }
/** * Muestra la formulario para redactar un email junto con una lista de usuarios * * @ruta jugadorNum12/emails/redactar * @redirige juagdorNum12/emails */ public function actionRedactar($destinatario, $tema) { $trans = Yii::app()->db->beginTransaction(); $yo = Usuarios::model()->findByAttributes(array('id_usuario' => Yii::app()->user->usIdent)); $nombre_usuario = $yo->nick; $email = new Emails(); $email->scenario = 'redactar'; $this->performAjaxValidation($email); if (isset($_POST['Emails'])) { $co = $_POST['Emails']['contenido']; $as = $_POST['Emails']['asunto']; $no = $_POST['Emails']['nombre']; $dests = Emails::model()->sacarUsuarios($no); foreach ($dests as $dest) { $usr_dest = Usuarios::model()->findByAttributes(array('nick' => $dest)); if ($usr_dest != null) { $mail = new Emails(); $mail->fecha = time(); $mail->asunto = $as; $mail->contenido = $co; $mail->id_usuario_to = $usr_dest->id_usuario; $mail->id_usuario_from = $yo->id_usuario; if (!$mail->save()) { $this->render('redactar', array('email' => $email, 'mi_aficion' => $mi_aficion, 'destinatario' => $destinatario, 'tema' => $tema)); } } $email = new Emails(); } $trans->commit(); $this->redirect(array('index')); } $this->render('redactar', array('email' => $email, 'destinatario' => $destinatario, 'tema' => $tema, 'nombre_usuario' => $nombre_usuario)); }
/** * Make a combat with initial status. */ public function actionSendChallenge() { //Check session is enable if (!Yii::app()->user->isGuest) { //Check if user is a cheater if ($this->user_data['knights']->name != $this->knight->name) { //Check if user has not a previous challenger enable $conditionParams = array(':status1' => Combats::STATUS_PENDING, ':status2' => Combats::STATUS_ENABLE, ':me1' => Yii::app()->user->users_id, ':me2' => Yii::app()->user->users_id, ':rival1' => $this->knight->id, ':rival2' => $this->knight->id); //Check if knights have a pending or enable combat if (!Combats::model()->exists('status != :status AND (from_knight = :knight1 AND to_knight = :rival1) OR (from_knight = :rival2 AND from_knight = :knight2)', array(':knight1' => Yii::app()->user->knights_id, ':rival1' => $this->knight->id, ':knight2' => Yii::app()->user->knights_id, ':rival2' => $this->knight->id, ':status' => Combats::STATUS_FINISHED))) { //Insert a new combat $combat = new Combats(); $combat->attributes = array('from_knight' => Yii::app()->user->knights_id, 'to_knight' => $this->knight->id, 'date' => date("Y-m-d H:i:s"), 'type' => Combats::TYPE_FRIENDLY, 'status' => Combats::STATUS_PENDING); if ($combat->save()) { //Insert a new combat knight event of both knights $knightEventMe = new KnightsEvents(); $knightEventMe->attributes = array('knights_id' => Yii::app()->user->knights_id, 'type' => KnightsEvents::TYPE_COMBAT, 'identificator' => $combat->id); if ($knightEventMe->save()) { $knightEventRival = new KnightsEvents(); $knightEventRival->attributes = array('knights_id' => $this->knight->id, 'type' => KnightsEvents::TYPE_COMBAT, 'identificator' => $combat->id); if ($knightEventRival->save()) { //Update rows from knight events last $sql = "UPDATE\n\t\t\t\t\t\t\t\t\t\tknights_events_last as k\n\t\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\tk.type = " . KnightsEvents::TYPE_COMBAT . ",\n\t\t\t\t\t\t\t\t\t\t\t\tk.identificator = " . $combat->id . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tk.date = '" . date('Y-m-d H:i:s') . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tk.id IN (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT id FROM (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tknights_events_last\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tknights_id = " . Yii::app()->user->knights_id . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY date ASC\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t) as trick\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t)"; //echo $sql; die(); $command = Yii::app()->db->createCommand($sql); //$command->bindValue( ':user_knights_id', Yii::app()->user->knights_id ); if ($command->query()) { $sql = "UPDATE\n\t\t\t\t\t\t\t\t\t\t\tknights_events_last\n\t\t\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\t\ttype = " . KnightsEvents::TYPE_COMBAT . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\tidentificator = " . $combat->id . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype = " . KnightsEvents::TYPE_COMBAT . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdate = '" . date('Y-m-d H:i:s') . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tid IN (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT id FROM (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tknights_events_last\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tknights_id = " . $this->knight->id . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY date ASC\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t) as trick\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t)"; $command = Yii::app()->db->createCommand($sql); //$command->bindValue( ':knight_id', $this->knight->id ); if ($command->execute()) { Yii::trace('[CHARACTER][sendChallenge] CHECK email'); //Check email of challenge if ($knight_setting = KnightsSettings::model()->findByPk($this->knight->id)) { if ($knight_setting->emailToSendChallenge) { Yii::trace('[CHARACTER][sendChallenge] Send email'); if ($knight_user = Users::model()->findByPk($this->knight->users_id)) { Yii::trace('[CHARACTER][sendChallenge] Rival email' . $knight_user->email); //cargamos la plantilla $message = Yii::app()->controller->renderFile(Yii::app()->basePath . Yii::app()->params['email_templates_path'] . 'sendNewChallenge.tpl', array(), true); // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; // Additional headers $headers .= 'To: ' . $knight_user->email . "\r\n"; $headers .= 'From: <noreply@' . Yii::app()->params->url_domain . '>' . "\r\n"; $email = new Emails(); $email->attributes = array('destination' => $knight_user->email, 'headers' => $headers, 'title' => Yii::app()->name . ': tienes un reto pendiente.', 'body' => $message, 'status' => Emails::STATUS_PENDING, 'date' => date('Y-m-d H:i:s')); if (!$email->save()) { Yii::trace('[CHARACTER][actionSendChallenge] No se ha podido guardar el email'); } } else { Yii::trace('[CHARACTER][actionSendChallenge] No se ha encontrado usuario del caballero ' . $this->knight->id, 'error'); } } } else { Yii::trace('[CHARACTER][actionSendChallenge] No se ha encontrado setting del caballero ' . $this->knight->id, 'error'); } echo '<p>El guantazo resuena por toda la sala.</p><p>Una multitud mirando y una mejilla con 5 dedos marcados no dejan lugar a dudas. El desafio ha sido lanzado</p> <p>La reacción del adversario no debería hacerse esperar...</p>'; } else { echo '<p>Se ha producido un error al guardar el evento rival del combate en la cache.</p>'; } } else { echo '<p>Se ha producido un error al guardar el evento del combate en la cache.</p>'; } //Update events /* $knightEventLastMe = new KnightsEventsLast(); $knightEventLastMe->attributes = array( 'knights_id' => Yii::app()->user->knights_id, 'type' => KnightsEvents::TYPE_COMBAT, 'identificator' => $combat->id, 'date' => $combat->date ); $criteria = new CDbCriteria(); $criteria->condition = 'knights_id = :knights_id'; $criteria->condition = 'knights_id = :knights_id'; $knightEventMe = KnightsEvents::model()->find( ); if( $knightEventLastMe->save() ){ $knightEventLastMe = new KnightsEventsLast(); $knightEventLastMe->attributes = array( 'knights_id' => $this->knight->id, 'type' => KnightsEvents::TYPE_COMBAT, 'identificator' => $combat->id, 'date' => $combat->date ); if( $knightEventLastMe->save() ){ echo '<p>El guantazo resuena por toda la sala.</p><p>Una multitud mirando y una mejilla con 5 dedos marcados no dejan lugar a dudas. El desafio ha sido lanzado</p> <p>La reacción del adversario no debería hacerse esperar...</p>'; }else{ echo '<p>Se ha producido un error al guardar el evento rival en la caché .</p>' ; } }else{ echo '<p>Se ha producido un error al guardar el evento en la caché .</p>' ; } //Update table caché knights events las $knightEventLastMe = KnightsEventsLast::model()->find( 'knights_id :knights_id' ); */ } else { echo '<p>Se ha producido un error al guardar el evento rival del combate .</p>'; } } else { echo '<p>Se ha producido un error al guardar el evento del combate.</p>'; } } else { echo '<p>Se ha producido un error al guardar el desafio.</p>'; } } else { //There is a combat pending or enable echo '<p>No se puede desafiar a alguien con el que tienes un desafio pendiente o en curso.</p>'; } } else { echo '<p>¿Cómo has llegado a retarte a ti mismo? En este momento no te parece tan buena idea.</p>'; } } else { echo '<p>Tu sesión ha expirado. Tienes que volver a hacer login.</p>'; } }
public function save() { $record_id = $this -> input -> post('record_id'); //Check if we are in editing mode first; if so, retrieve the edited record. if not, create a new one! if (strlen($record_id) > 0) { $email = Emails::getEmail($record_id); } else { $email = new Emails(); } $div = $this -> session -> userdata('user_group'); //getting the session user group $div2 = $this -> session -> userdata('district_province_id'); if ($div == 1) { $national = "1"; $district = "0"; $provincial = "0"; } if ($div == 2) { $national = "1"; $district = "0"; $provincial = "0"; } if ($div == 3) { $national = "0"; $district = "0"; $provincial = $div2; } if ($div == 4) { $provincial = "0"; $national = "0"; $district = $div2; } $email -> email = $this -> input -> post("email"); $email -> provincial = $provincial; $email -> district = $district; $email -> national = $national; $email -> valid = "1"; $email -> stockout = $this -> input -> post("combo1"); $email -> consumption = $this -> input -> post("combo2"); $email -> coldchain = $this -> input -> post("combo3"); $email -> recepient = $this -> input -> post("rep"); $email -> number = $this -> input -> post("number"); $kenya=$country->country_code=trim($this->input->post("country_code")); $email->number=$kenya.$this->input->post("number"); $email -> save(); redirect("email_management"); }
public static function logEmailSending($client_id,$user_id,$project_id,$address) { $email = new Emails(); $email->Client_ID = $client_id; $email->User_ID = $user_id; if (!is_int($project_id)) $project_id = 0; $email->Project_ID = $project_id; $email->Email_Address = $address; $email->save(); }