Beispiel #1
0
 /**
  * @param string $emailAddress
  * @return mixed if true integer otherwise null
  */
 public static function saveEmailAddress($emailAddress)
 {
     $emailID = null;
     $parseEmail = explode('@', strtolower(trim($emailAddress)));
     if (count($parseEmail) == 2) {
         $domain = Domain::model()->findByAttributes(array('name' => $parseEmail[1]));
         if (!$domain) {
             $domain = new Domain();
             $domain->name = $parseEmail[1];
         }
         if ($domain->save()) {
             $email = new Email();
             $email->username = $parseEmail[0];
             $email->domainID = $domain->ID;
             if ($email->save()) {
                 $emailID = $email->ID;
             } else {
                 if ($domain->isNewRecord) {
                     Domain::model()->deleteByPk($domain->ID);
                 }
             }
         }
     }
     return $emailID;
 }
 public static function createEmail($id = '', $override = array())
 {
     global $timedate;
     $time = mt_rand();
     $name = 'SugarEmail';
     $email = new Email();
     $email->name = $name . $time;
     $email->type = 'out';
     $email->status = 'sent';
     $email->date_sent = $timedate->to_display_date_time(gmdate("Y-m-d H:i:s", gmmktime() - 3600 * 24 * 2));
     // Two days ago
     if (!empty($id)) {
         $email->new_with_id = true;
         $email->id = $id;
     }
     foreach ($override as $key => $value) {
         $email->{$key} = $value;
     }
     $email->save();
     if (!empty($override['parent_id']) && !empty($override['parent_type'])) {
         self::createEmailsBeansRelationship($email->id, $override['parent_type'], $override['parent_id']);
     }
     self::$_createdEmails[] = $email;
     return $email;
 }
Beispiel #3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Usuario();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['Usuario'])) {
         $model->attributes = $_POST['Usuario'];
         $model->estatus_did = 1;
         $model->tipoUsuario_did = 4;
         $model->fechaCreacion_f = date("Y-d-m H:i:s");
         $model->contrasena = md5($model->contrasena);
         if (isset($_POST["noticias"])) {
             $email = new Email();
             $email->nombre = $model->nombre . " " . $model->apPaterno . " " . $model->apMaterno;
             $email->direccion = $model->domCalle . " " . $model->domNo . " " . $model->domColonia;
             $email->telefono = $model->telefono;
             $email->correo = $model->correo;
             $email->estatus_did = 1;
             $email->fecha_f = date("Y-d-m");
             $email->save();
         }
         if ($model->save()) {
             $this->redirect(array('site/index'));
         }
     }
     $this->render('create', array('model' => $model));
 }
Beispiel #4
0
 public function actionSend()
 {
     if (Input::get('to') && Input::get('subject') && Input::get('message')) {
         $to = Input::get('to');
         $subject = Input::get('subject');
         $message = Input::get('message');
         if (empty($to) || empty($subject) || empty($message)) {
             $data = array('success' => false, 'message' => 'Please fill out the form completely.');
             echo json_encode($data);
             exit;
         }
         $email = new Email();
         $email->to = $to;
         if ($email->save()) {
             Mail::send('emails.main', ['text' => $message, 'host' => $_SERVER['HTTP_HOST'], 'id' => $email->id], function ($message) use($to, $subject) {
                 $message->to($to)->subject($subject);
             });
             if (count(Mail::failures())) {
                 $data = array('success' => false, 'message' => 'Message could not be sent.');
                 $email->delete();
                 echo json_encode($data);
                 exit;
             }
             $data = array('success' => true, 'message' => 'Thanks! We have received your message.');
             echo json_encode($data);
         } else {
             $data = array('success' => false, 'message' => 'Message could not be sent.');
             echo json_encode($data);
         }
     } else {
         $data = array('success' => false, 'message' => 'Please fill out the form completely.');
         echo json_encode($data);
     }
     exit;
 }
 function send_email($module, $module_type, $printable, $file_name, $attach)
 {
     require_once 'modules/Emails/Email.php';
     global $current_user, $mod_strings, $sugar_config;
     //First Create e-mail draft
     $email = new Email();
     // set the id for relationships
     $email->id = create_guid();
     $email->new_with_id = true;
     //subject
     $email->name = $mod_strings['LBL_EMAIL_NAME'] . ' ' . $module->name;
     //body
     $email->description_html = $printable;
     //type is draft
     $email->type = "draft";
     $email->status = "draft";
     if (!empty($module->billing_contact_id) && $module->billing_contact_id != "") {
         require_once 'modules/Contacts/Contact.php';
         $contact = new Contact();
         $contact->retrieve($module->billing_contact_id);
         $email->parent_type = 'Contacts';
         $email->parent_id = $contact->id;
         if (!empty($contact->email1)) {
             $email->to_addrs_emails = $contact->email1 . ";";
             $email->to_addrs = $module->billing_contact_name . " <" . $contact->email1 . ">";
         }
     }
     //team id
     $email->team_id = $current_user->default_team;
     //assigned_user_id
     $email->assigned_user_id = $current_user->id;
     //Save the email object
     global $timedate;
     $email->date_start = $timedate->to_display_date_time(gmdate($GLOBALS['timedate']->get_db_date_time_format()));
     $email->save(FALSE);
     $email_id = $email->id;
     if ($attach) {
         $note = new Note();
         $note->modified_user_id = $current_user->id;
         $note->created_by = $current_user->id;
         $note->name = $file_name;
         $note->parent_type = 'Emails';
         $note->parent_id = $email_id;
         $note->file_mime_type = 'application/pdf';
         $note->filename = $file_name;
         $note->save();
         rename($sugar_config['upload_dir'] . 'attachfile.pdf', $sugar_config['upload_dir'] . $note->id);
     }
     //redirect
     if ($email_id == "") {
         echo "Unable to initiate Email Client";
         exit;
     } else {
         header("Location: index.php?action=Compose&module=Emails&return_module=" . $module_type . "&return_action=DetailView&return_id=" . $_REQUEST['record'] . "&recordId=" . $email_id);
     }
 }
Beispiel #6
0
 public function setUp()
 {
     SugarTestHelper::setUp('beanFiles');
     SugarTestHelper::setUp('beanList');
     SugarTestHelper::setUp('current_user');
     $this->account = SugarTestAccountUtilities::createAccount();
     $this->contact = SugarTestContactUtilities::createContact();
     $this->email = SugarTestEmailUtilities::createEmail();
     $this->opportunity = SugarTestOpportunityUtilities::createOpportunity('', $this->account);
     $this->contact->account_id = $this->account->id;
     $this->contact->save();
     $this->opportunity->load_relationship('contacts');
     $this->opportunity->contacts->add($this->contact);
     $this->email->parent_id = $this->contact->id;
     $this->email->parent_type = $this->contact->module_name;
     $this->email->save();
     if (isset($GLOBALS['app'])) {
         $this->application = $GLOBALS['app'];
     }
     $GLOBALS['app'] = new SugarApplication();
     $GLOBALS['app']->controller = new SugarController();
 }
Beispiel #7
0
 /**
  * Link the Lead to the Email from which the lead was created
  * Also set the assigned user to current user and mark email as read.
  * TODO: This logic is brought over from LeadFormBase->handleSave() - need refactoring to use Link2?
  *
  * @param $emailId
  * @param $leadId
  */
 protected function linkLeadToEmail($emailId, $leadId)
 {
     global $current_user;
     $email = new Email();
     $email->retrieve($emailId);
     $email->parent_type = 'Leads';
     $email->parent_id = $leadId;
     $email->assigned_user_id = $current_user->id;
     $email->status = 'read';
     $email->save();
     $email->load_relationship('leads');
     $email->leads->add($leadId);
 }
 public function send_email($dummy)
 {
     $rules = array('from_name' => 'required|max:128', 'from_email' => 'required|email|max:255', 'subject' => 'required|max:128', 'emailbody' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Response::json(array('validation' => $validator->messages()->toArray()));
     } else {
         $from_name = Input::get('from_name');
         $from_email = Input::get('from_email');
         $selected = Input::get('to');
         $subject = Input::get('subject');
         $emailbody = Input::get('emailbody');
         $from = $from_name . ' (' . $from_email . ')';
         $recipients = Subscriber::whereIn('email', $selected)->where('active', '=', 1)->get();
         $email = new Email();
         $email->from = $from;
         $email->subject = $subject;
         $email->message = $emailbody;
         $email->save();
         $email_id = $email->id;
         $numrecipients = $recipients->count();
         $numsent = 0;
         foreach ($recipients as $key => $recipient) {
             $tracker = new Tracker();
             $tracker->subscriber_id = $recipient->id;
             $tracker->email_id = $email_id;
             $tracker->save();
             $tracker_id = $tracker->id;
             $tracker_url = URL::to('tracker/' . $tracker_id);
             $unsubscriber_url = URL::to('unsubscribe/' . $tracker_id);
             $subscriber = $recipient;
             $data = array('emailbody' => $emailbody, 'tracker' => $tracker_url, 'unsubscribe' => $unsubscriber_url, 'subscriber' => $subscriber);
             $to_email = $subscriber->email;
             $to_name = $subscriber->first_name . ' ' . $subscriber->last_name;
             $issent = Mail::send('emails.sub-emails', $data, function ($message) use($from_email, $from_name, $to_email, $to_name, $subject) {
                 $message->from($from_email, $from_name)->to($to_email, $to_name)->subject($subject);
             });
             if ($issent) {
                 $numsent += 1;
             } else {
                 $tracker->bounced = 1;
                 $tracker->save();
             }
         }
         if ($numsent == $numrecipients) {
             return Response::json(array('success' => 'Your email was successfully sent to <b>' . $numsent . '</b> subscribers out of the ' . $numrecipients . ' subscribers you selected. <b>Rejoice!</b>'));
         } else {
             return Response::json(array('success' => 'Your email was successfully sent to <b>' . $numsent . '</b> subscribers out of the ' . $numrecipients . 'All bounces have been logged.'));
         }
     }
 }
Beispiel #9
0
 public static function queue_to_email($to_email, $to_name, $subject, $text, $html)
 {
     $email = new Email();
     $email->set('user_id', $user->id);
     $email->set('subject', $subject);
     $email->set('text_body', $text);
     $email->set('html_body', $html);
     $email->set('to_email', $to_email);
     $email->set('to_name', $to_name);
     $email->set('queue_date', date("Y-m-d H:i:s"));
     $email->set('status', 'queued');
     $email->save();
     //send it right away.
     //$email->send();
 }
Beispiel #10
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Email();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Email'])) {
         $model->attributes = $_POST['Email'];
         $model->estatus_did = 1;
         $model->fecha_f = date("Y-d-m");
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Beispiel #11
0
 public static function queue_to_email($to_email, $to_name, $subject, $text, $html, $user_id = 0)
 {
     $email = new Email();
     $email->set('user_id', $user_id);
     $email->set('subject', $subject);
     $email->set('text_body', $text);
     $email->set('html_body', $html);
     $email->set('to_email', $to_email);
     $email->set('to_name', $to_name);
     $email->set('queue_date', date("Y-m-d H:i:s"));
     $email->set('status', 'queued');
     $email->save();
     //send it right away, or queue it.
     if (!(defined("QUEUE_EMAIL") && QUEUE_EMAIL)) {
         $email->send();
     }
     return $email;
 }
Beispiel #12
0
 public function announce()
 {
     $content = Input::get('content');
     $content = nl2br($content);
     $users = User::all();
     foreach ($users as $user) {
         $input = array('content' => $content, 'user' => $user);
         Mail::send('emails.announce', $input, function ($message) use($user) {
             $message->to("{$user->email}")->subject('hackGFS - Announcement from ' . Sentry::getUser()->first_name . ' ' . Sentry::getUser()->last_name);
         });
     }
     $user = Sentry::getUser();
     $email = new Email();
     $email->email = '*****@*****.**';
     $email->company = 'hackGFS';
     $email->user_id = $user->id;
     $email->content = $content;
     $email->save();
     return Redirect::back();
 }
Beispiel #13
0
 public function testSaveNewEmailWithParent()
 {
     $email = new Email();
     $email->type = 'out';
     $email->status = 'sent';
     $email->from_addr_name = $email->cleanEmails("*****@*****.**");
     $email->to_addrs_names = $email->cleanEmails("*****@*****.**");
     $email->cc_addrs_names = $email->cleanEmails("*****@*****.**");
     // set a few parent info to test the scenario
     $email->parent_type = 'Accounts';
     $email->parent_id = $this->_account->id;
     $email->fetched_row['parent_type'] = 'Accounts';
     $email->fetched_row['parent_id'] = $this->_account->id;
     $email->save();
     $this->assertNotNull($email->id, 'Null email id');
     $this->email_id = $email->id;
     // ensure record is inserted into emails_beans table
     $query = "select count(*) as cnt from emails_beans eb WHERE eb.bean_id = '{$this->_account->id}' AND eb.bean_module = 'Accounts' AND eb.email_id = '{$email->id}' AND eb.deleted=0";
     $result = $GLOBALS['db']->query($query);
     $count = $GLOBALS['db']->fetchByAssoc($result);
     $this->assertEquals(1, $count['cnt'], 'Incorrect emails_beans count');
 }
Beispiel #14
0
 public function setUp()
 {
     global $current_user, $currentModule, $timedate;
     $mod_strings = return_module_language($GLOBALS['current_language'], "Contacts");
     $current_user = SugarTestUserUtilities::createAnonymousUser();
     $this->outbound_id = uniqid();
     $time = date('Y-m-d H:i:s');
     $em = new Email();
     $em->name = 'tst_' . uniqid();
     $em->type = 'inbound';
     $em->intent = 'pick';
     $em->date_sent = $timedate->to_display_date_time(gmdate("Y-m-d H:i:s", gmmktime() + 3600 * 24 * 2));
     //Two days from today
     $em->save();
     $this->em1 = $em;
     $n = new Note();
     $n->name = 'tst_' . uniqid();
     $n->filename = 'file_' . uniqid();
     $n->parent_type = 'Emails';
     $n->parent_id = $this->em1->id;
     $n->save();
     $this->note1 = $n;
 }
Beispiel #15
0
 /**
  * Save a SugarFolder 
  */
 public function testSaveNewFolder()
 {
     $this->markTestIncomplete('This test takes to long to run');
     return;
     global $current_user, $app_strings;
     $email = new Email();
     $email->type = 'out';
     $email->status = 'sent';
     $email->from_addr_name = $email->cleanEmails("*****@*****.**");
     $email->to_addrs_names = $email->cleanEmails("*****@*****.**");
     $email->cc_addrs_names = $email->cleanEmails("*****@*****.**");
     $email->save();
     $_REQUEST["emailUIAction"] = "getSingleMessageFromSugar";
     $_REQUEST["uid"] = $email->id;
     $_REQUEST["mbox"] = "";
     $_REQUEST['ieId'] = "";
     ob_start();
     require "modules/Emails/EmailUIAjax.php";
     $jsonOutput = ob_get_contents();
     ob_end_clean();
     $meta = json_decode($jsonOutput);
     $this->assertRegExp("/.*cc@domain.eu.*/", $meta->meta->email->cc);
 }
 function sendEmail($emailTo, $emailSubject, $emailBody, $altemailBody, SugarBean $relatedBean = null)
 {
     require_once 'modules/Emails/Email.php';
     require_once 'include/SugarPHPMailer.php';
     $emailObj = new Email();
     $emailSettings = getPortalEmailSettings();
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     $mail->From = $emailSettings['from_address'];
     $mail->FromName = $emailSettings['from_name'];
     $mail->ClearAllRecipients();
     $mail->ClearReplyTos();
     $mail->Subject = from_html($emailSubject);
     $mail->Body = $emailBody;
     $mail->AltBody = $altemailBody;
     $mail->prepForOutbound();
     $mail->AddAddress($emailTo);
     //now create email
     if (@$mail->Send()) {
         $emailObj->to_addrs = '';
         $emailObj->type = 'archived';
         $emailObj->deleted = '0';
         $emailObj->name = $mail->Subject;
         $emailObj->description = $mail->AltBody;
         $emailObj->description_html = $mail->Body;
         $emailObj->from_addr = $mail->From;
         if ($relatedBean instanceof SugarBean && !empty($relatedBean->id)) {
             $emailObj->parent_type = $relatedBean->module_dir;
             $emailObj->parent_id = $relatedBean->id;
         }
         $emailObj->date_sent = TimeDate::getInstance()->nowDb();
         $emailObj->modified_user_id = '1';
         $emailObj->created_by = '1';
         $emailObj->status = 'sent';
         $emailObj->save();
     }
 }
Beispiel #17
0
 /**
  * Send new password or link to user
  *
  * @param string $templateId Id of email template
  * @param array $additionalData additional params: link, url, password
  * @return array status: true|false, message: error message, if status = false and message = '' it means that send method has returned false
  */
 public function sendEmailForPassword($templateId, array $additionalData = array())
 {
     global $sugar_config, $current_user;
     $mod_strings = return_module_language('', 'Users');
     $result = array('status' => false, 'message' => '');
     $emailTemp = new EmailTemplate();
     $emailTemp->disable_row_level_security = true;
     if ($emailTemp->retrieve($templateId) == '') {
         $result['message'] = $mod_strings['LBL_EMAIL_TEMPLATE_MISSING'];
         return $result;
     }
     //replace instance variables in email templates
     $htmlBody = $emailTemp->body_html;
     $body = $emailTemp->body;
     if (isset($additionalData['link']) && $additionalData['link'] == true) {
         $htmlBody = str_replace('$contact_user_link_guid', $additionalData['url'], $htmlBody);
         $body = str_replace('$contact_user_link_guid', $additionalData['url'], $body);
     } else {
         $htmlBody = str_replace('$contact_user_user_hash', $additionalData['password'], $htmlBody);
         $body = str_replace('$contact_user_user_hash', $additionalData['password'], $body);
     }
     // Bug 36833 - Add replacing of special value $instance_url
     $htmlBody = str_replace('$config_site_url', $sugar_config['site_url'], $htmlBody);
     $body = str_replace('$config_site_url', $sugar_config['site_url'], $body);
     $htmlBody = str_replace('$contact_user_user_name', $this->user_name, $htmlBody);
     $htmlBody = str_replace('$contact_user_pwd_last_changed', TimeDate::getInstance()->nowDb(), $htmlBody);
     $body = str_replace('$contact_user_user_name', $this->user_name, $body);
     $body = str_replace('$contact_user_pwd_last_changed', TimeDate::getInstance()->nowDb(), $body);
     $emailTemp->body_html = $htmlBody;
     $emailTemp->body = $body;
     $itemail = $this->emailAddress->getPrimaryAddress($this);
     //retrieve IT Admin Email
     //_ppd( $emailTemp->body_html);
     //retrieve email defaults
     $emailObj = new Email();
     $defaults = $emailObj->getSystemDefaultEmail();
     require_once 'include/SugarPHPMailer.php';
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     //$mail->IsHTML(true);
     $mail->From = $defaults['email'];
     $mail->FromName = $defaults['name'];
     $mail->ClearAllRecipients();
     $mail->ClearReplyTos();
     $mail->Subject = from_html($emailTemp->subject);
     if ($emailTemp->text_only != 1) {
         $mail->IsHTML(true);
         $mail->Body = from_html($emailTemp->body_html);
         $mail->AltBody = from_html($emailTemp->body);
     } else {
         $mail->Body_html = from_html($emailTemp->body_html);
         $mail->Body = from_html($emailTemp->body);
     }
     if ($mail->Body == '' && $current_user->is_admin) {
         global $app_strings;
         $result['message'] = $app_strings['LBL_EMAIL_TEMPLATE_EDIT_PLAIN_TEXT'];
         return $result;
     }
     if ($mail->Mailer == 'smtp' && $mail->Host == '' && $current_user->is_admin) {
         $result['message'] = $mod_strings['ERR_SERVER_SMTP_EMPTY'];
         return $result;
     }
     $mail->prepForOutbound();
     $hasRecipients = false;
     if (!empty($itemail)) {
         if ($hasRecipients) {
             $mail->AddBCC($itemail);
         } else {
             $mail->AddAddress($itemail);
         }
         $hasRecipients = true;
     }
     if ($hasRecipients) {
         $result['status'] = @$mail->Send();
     }
     if ($result['status'] == true) {
         $emailObj->team_id = 1;
         $emailObj->to_addrs = '';
         $emailObj->type = 'archived';
         $emailObj->deleted = '0';
         $emailObj->name = $mail->Subject;
         $emailObj->description = $mail->Body;
         $emailObj->description_html = null;
         $emailObj->from_addr = $mail->From;
         $emailObj->parent_type = 'User';
         $emailObj->date_sent = TimeDate::getInstance()->nowDb();
         $emailObj->modified_user_id = '1';
         $emailObj->created_by = '1';
         $emailObj->status = 'sent';
         $emailObj->save();
         if (!isset($additionalData['link']) || $additionalData['link'] == false) {
             $user_hash = strtolower(md5($additionalData['password']));
             $this->setPreference('loginexpiration', '0');
             $this->setPreference('lockout', '');
             $this->setPreference('loginfailed', '0');
             $this->savePreferencesToDB();
             //set new password
             $now = TimeDate::getInstance()->nowDb();
             $query = "UPDATE {$this->table_name} SET user_hash='{$user_hash}', system_generated_password='******', pwd_last_changed='{$now}' where id='{$this->id}'";
             $this->db->query($query, true, "Error setting new password for {$this->user_name}: ");
         }
     }
     return $result;
 }
Beispiel #18
0
    $focus->date_start_flag = 1;
    $focus->date_start = '';
}
///////////////////////////////////////////////////////////////////////////////
////	INBOUND EMAIL HANDLING
///////////////////////////////////////////////////////////////////////////////
if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
    // fake this case like it's already saved.
    $focus->save();
    $email = new Email();
    $email->retrieve($_REQUEST['inbound_email_id']);
    $email->parent_type = 'Tasks';
    $email->parent_id = $focus->id;
    $email->assigned_user_id = $current_user->id;
    $email->status = 'read';
    $email->save();
    $email->load_relationship('tasks');
    $email->tasks->add($focus->id);
    header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start'] . '&assigned_user_id=' . $current_user->id);
    exit;
}
////	END INBOUND EMAIL HANDLING
///////////////////////////////////////////////////////////////////////////////
// CCL - Bugs 41103 and 43751.  41103 address the issue where the parent_id is set, but
// the relate_id field overrides the relationship.  43751 fixes the problem where the relate_id and
// parent_id are the same value (in which case it should just use relate_id) by adding the != check
if (!empty($_REQUEST['relate_id']) && !empty($_REQUEST['parent_id']) && $_REQUEST['relate_id'] != $_REQUEST['parent_id']) {
    $_REQUEST['relate_id'] = false;
}
// avoid undefined index
if (!isset($GLOBALS['check_notify'])) {
Beispiel #19
0
 public function sendEmail($emailTo, $emailSubject, $emailToname, $emailBody, $altemailBody, SugarBean $relatedBean = null, $attachments = array())
 {
     $emailObj = new Email();
     $defaults = $emailObj->getSystemDefaultEmail();
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     $mail->From = $defaults['email'];
     $mail->FromName = $defaults['name'];
     $mail->ClearAllRecipients();
     $mail->ClearReplyTos();
     $mail->Subject = from_html($emailSubject);
     $mail->Body = $emailBody;
     $mail->AltBody = $altemailBody;
     $mail->handleAttachments($attachments);
     $mail->prepForOutbound();
     $mail->AddAddress($emailTo);
     //now create email
     if (@$mail->Send()) {
         $emailObj->to_addrs = '';
         $emailObj->type = 'out';
         $emailObj->deleted = '0';
         $emailObj->name = $mail->Subject;
         $emailObj->description = $mail->AltBody;
         $emailObj->description_html = $mail->Body;
         $emailObj->from_addr = $mail->From;
         if ($relatedBean instanceof SugarBean && !empty($relatedBean->id)) {
             $emailObj->parent_type = $relatedBean->module_dir;
             $emailObj->parent_id = $relatedBean->id;
         }
         $emailObj->date_sent = TimeDate::getInstance()->nowDb();
         $emailObj->modified_user_id = '1';
         $emailObj->created_by = '1';
         $emailObj->status = 'sent';
         $emailObj->save();
         return true;
     } else {
         return false;
     }
 }
Beispiel #20
0
/**
 * does post-post-install stuff
 * @param array persistence
 * @return array persistence
 */
function commitAjaxFinalTouches($persistence)
{
    global $current_user;
    global $timedate;
    global $mod_strings;
    global $sugar_version;
    if (empty($sugar_version)) {
        require 'sugar_version.php';
    }
    // convert to UTF8 if needed
    if (!empty($persistence['allTables'])) {
        executeConvertTablesSql($persistence['allTables']);
    }
    // rebuild
    logThis('Performing UWrebuild()...');
    UWrebuild();
    logThis('UWrebuild() done.');
    // upgrade history
    registerUpgrade($persistence);
    // flag to say upgrade has completed
    $persistence['upgrade_complete'] = true;
    // reminders if needed
    ///////////////////////////////////////////////////////////////////////////////
    ////	HANDLE REMINDERS
    if (count($persistence['skipped_files']) > 0) {
        $desc = $mod_strings['LBL_UW_COMMIT_ADD_TASK_OVERVIEW'] . "\n\n";
        $desc .= $mod_strings['LBL_UW_COMMIT_ADD_TASK_DESC_1'];
        $desc .= $persistence['uw_restore_dir'] . "\n\n";
        $desc .= $mod_strings['LBL_UW_COMMIT_ADD_TASK_DESC_2'] . "\n\n";
        foreach ($persistence['skipped_files'] as $file) {
            $desc .= $file . "\n";
        }
        //MFH #13468
        $nowDate = $timedate->nowDbDate();
        $nowTime = $timedate->asDbTime($timedate->getNow());
        $nowDateTime = $nowDate . ' ' . $nowTime;
        if ($_REQUEST['addTaskReminder'] == 'remind') {
            logThis('Adding Task for admin for manual merge.');
            $task = new Task();
            $task->name = $mod_strings['LBL_UW_COMMIT_ADD_TASK_NAME'];
            $task->description = $desc;
            $task->date_due = $nowDate;
            $task->time_due = $nowTime;
            $task->priority = 'High';
            $task->status = 'Not Started';
            $task->assigned_user_id = $current_user->id;
            $task->created_by = $current_user->id;
            $task->date_entered = $nowDateTime;
            $task->date_modified = $nowDateTime;
            $task->save();
        }
        if ($_REQUEST['addEmailReminder'] == 'remind') {
            logThis('Sending Reminder for admin for manual merge.');
            $email = new Email();
            $email->assigned_user_id = $current_user->id;
            $email->name = $mod_strings['LBL_UW_COMMIT_ADD_TASK_NAME'];
            $email->description = $desc;
            $email->description_html = nl2br($desc);
            $email->from_name = $current_user->full_name;
            $email->from_addr = $current_user->email1;
            $email->to_addrs_arr = $email->parse_addrs($current_user->email1, '', '', '');
            $email->cc_addrs_arr = array();
            $email->bcc_addrs_arr = array();
            $email->date_entered = $nowDateTime;
            $email->date_modified = $nowDateTime;
            $email->send();
            $email->save();
        }
    }
    ////	HANDLE REMINDERS
    ///////////////////////////////////////////////////////////////////////////////
    // clean up
    unlinkUWTempFiles();
    ob_start();
    echo 'done';
    ob_flush();
    return $persistence;
}
 /**
  * moves emails from folder to folder
  * @param string $fromIe I-E id
  * @param string $fromFolder IMAP path to folder in which the email lives
  * @param string $toIe I-E id
  * @param string $toFolder
  * @param string $uids UIDs of emails to move, either Sugar GUIDS or IMAP
  * UIDs
  * @param bool $copy Default false
  * @return bool True on successful execution
  */
 function moveEmails($fromIe, $fromFolder, $toIe, $toFolder, $uids, $copy = false)
 {
     global $app_strings;
     global $current_user;
     // same I-E server
     if ($fromIe == $toIe) {
         $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() moving email from I-E to I-E");
         //$exDestFolder = explode("::", $toFolder);
         //preserve $this->mailbox
         if (isset($this->mailbox)) {
             $oldMailbox = $this->mailbox;
         }
         $this->retrieve($fromIe);
         $this->mailbox = $fromFolder;
         $this->connectMailserver();
         $exUids = explode('::;::', $uids);
         $uids = implode(",", $exUids);
         // imap_mail_move accepts comma-delimited lists of UIDs
         if ($copy) {
             if (imap_mail_copy($this->conn, $uids, $toFolder, CP_UID)) {
                 $this->mailbox = $toFolder;
                 $this->connectMailserver();
                 $newOverviews = imap_fetch_overview($this->conn, $uids, FT_UID);
                 $this->updateOverviewCacheFile($newOverviews, 'append');
                 if (isset($oldMailbox)) {
                     $this->mailbox = $oldMailbox;
                 }
                 return true;
             } else {
                 $GLOBALS['log']->debug("INBOUNDEMAIL: could not imap_mail_copy() [ {$uids} ] to folder [ {$toFolder} ] from folder [ {$fromFolder} ]");
             }
         } else {
             if (imap_mail_move($this->conn, $uids, $toFolder, CP_UID)) {
                 $GLOBALS['log']->info("INBOUNDEMAIL: imap_mail_move() [ {$uids} ] to folder [ {$toFolder} ] from folder [ {$fromFolder} ]");
                 imap_expunge($this->conn);
                 // hard deletes moved messages
                 // update cache on fromFolder
                 $newOverviews = $this->getOverviewsFromCacheFile($uids, $fromFolder, true);
                 $this->deleteCachedMessages($uids, $fromFolder);
                 // update cache on toFolder
                 $this->checkEmailOneMailbox($toFolder, true, true);
                 if (isset($oldMailbox)) {
                     $this->mailbox = $oldMailbox;
                 }
                 return true;
             } else {
                 $GLOBALS['log']->debug("INBOUNDEMAIL: could not imap_mail_move() [ {$uids} ] to folder [ {$toFolder} ] from folder [ {$fromFolder} ]");
             }
         }
     } elseif ($toIe == 'folder' && $fromFolder == 'sugar::Emails') {
         $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() moving email from SugarFolder to SugarFolder");
         // move from sugar folder to sugar folder
         require_once "include/SugarFolders/SugarFolders.php";
         $sugarFolder = new SugarFolder();
         $exUids = explode($app_strings['LBL_EMAIL_DELIMITER'], $uids);
         foreach ($exUids as $id) {
             if ($copy) {
                 $sugarFolder->copyBean($fromIe, $toFolder, $id, "Emails");
             } else {
                 $fromSugarFolder = new SugarFolder();
                 $fromSugarFolder->retrieve($fromIe);
                 $toSugarFolder = new SugarFolder();
                 $toSugarFolder->retrieve($toFolder);
                 $email = new Email();
                 $email->retrieve($id);
                 $email->status = 'unread';
                 // when you move from My Emails to Group Folder, Assign To field for the Email should become null
                 if ($fromSugarFolder->is_dynamic && $toSugarFolder->is_group) {
                     $email->assigned_user_id = "";
                     $email->save();
                     if (!$toSugarFolder->checkEmailExistForFolder($id)) {
                         $fromSugarFolder->deleteEmailFromAllFolder($id);
                         $toSugarFolder->addBean($email);
                     }
                 } elseif ($fromSugarFolder->is_group && $toSugarFolder->is_dynamic) {
                     $fromSugarFolder->deleteEmailFromAllFolder($id);
                     $email->assigned_user_id = $current_user->id;
                     $email->save();
                 } else {
                     // If you are moving something from personal folder then delete an entry from all folder
                     if (!$fromSugarFolder->is_dynamic && !$fromSugarFolder->is_group) {
                         $fromSugarFolder->deleteEmailFromAllFolder($id);
                     }
                     // if
                     if ($fromSugarFolder->is_dynamic && !$toSugarFolder->is_dynamic && !$toSugarFolder->is_group) {
                         $email->assigned_user_id = "";
                         $toSugarFolder->addBean($email);
                     }
                     // if
                     if (!$toSugarFolder->checkEmailExistForFolder($id)) {
                         if (!$toSugarFolder->is_dynamic) {
                             $fromSugarFolder->deleteEmailFromAllFolder($id);
                             $toSugarFolder->addBean($email);
                         } else {
                             $fromSugarFolder->deleteEmailFromAllFolder($id);
                             $email->assigned_user_id = $current_user->id;
                         }
                     } else {
                         $sugarFolder->move($fromIe, $toFolder, $id);
                     }
                     // else
                     $email->save();
                 }
                 // else
             }
         }
         return true;
     } elseif ($toIe == 'folder') {
         $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() moving email from I-E to SugarFolder");
         // move to Sugar folder
         require_once "include/SugarFolders/SugarFolders.php";
         $sugarFolder = new SugarFolder();
         $sugarFolder->retrieve($toFolder);
         //Show the import form if we don't have the required info
         if (!isset($_REQUEST['delete'])) {
             $json = getJSONobj();
             if ($sugarFolder->is_group) {
                 $_REQUEST['showTeam'] = false;
                 $_REQUEST['showAssignTo'] = false;
             }
             $ret = $this->email->et->getImportForm($_REQUEST, $this->email);
             $ret['move'] = true;
             $ret['srcFolder'] = $fromFolder;
             $ret['srcIeId'] = $fromIe;
             $ret['dstFolder'] = $toFolder;
             $ret['dstIeId'] = $toIe;
             $out = trim($json->encode($ret, false));
             echo $out;
             return true;
         }
         // import to Sugar
         $this->retrieve($fromIe);
         $this->mailbox = $fromFolder;
         $this->connectMailserver();
         // If its a group folder the team should be of the folder team
         if ($sugarFolder->is_group) {
             $_REQUEST['team_id'] = $sugarFolder->team_id;
             $_REQUEST['team_set_id'] = $sugarFolder->team_set_id;
         } else {
             // TODO - set team_id, team_set for new UI
         }
         // else
         $exUids = explode($app_strings['LBL_EMAIL_DELIMITER'], $uids);
         if (!empty($sugarFolder->id)) {
             $count = 1;
             $return = array();
             $json = getJSONobj();
             foreach ($exUids as $k => $uid) {
                 $msgNo = $uid;
                 if ($this->isPop3Protocol()) {
                     $msgNo = $this->getCorrectMessageNoForPop3($uid);
                 } else {
                     $msgNo = imap_msgno($this->conn, $uid);
                 }
                 if (!empty($msgNo)) {
                     $importStatus = $this->importOneEmail($msgNo, $uid);
                     // add to folder
                     if ($importStatus) {
                         $sugarFolder->addBean($this->email);
                         if (!$copy && isset($_REQUEST['delete']) && $_REQUEST['delete'] == "true" && $importStatus) {
                             $GLOBALS['log']->error("********* delete from mailserver [ {explode(", ", {$uids})} ]");
                             // delete from mailserver
                             $this->deleteMessageOnMailServer($uid);
                             $this->deleteMessageFromCache($uid);
                         }
                         // if
                     }
                     $return[] = $app_strings['LBL_EMAIL_MESSAGE_NO'] . " " . $count . ", " . $app_strings['LBL_STATUS'] . " " . ($importStatus ? $app_strings['LBL_EMAIL_IMPORT_SUCCESS'] : $app_strings['LBL_EMAIL_IMPORT_FAIL']);
                     $count++;
                 }
                 // if
             }
             // foreach
             echo $json->encode($return);
             return true;
         } else {
             $GLOBALS['log']->error("********* SUGARFOLDER - failed to retrieve folder ID [ {$toFolder} ]");
         }
     } else {
         $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() called with no passing criteria");
     }
     return false;
 }
        foreach ($ids as $k => $id) {
            $in .= '"' . $id . '", ';
        }
        $in = substr($in, 0, strlen($in) - 2);
        $in .= ') ';
        $team = '';
        $qE = 'SELECT count(id) AS c FROM emails WHERE deleted = 0 AND assigned_user_id' . $in . $team . 'LIMIT 1';
        $rE = $next->db->query($qE);
        $aE = $next->db->fetchByAssoc($rE);
        if ($aE['c'] > 0) {
            $qE = 'SELECT id FROM emails WHERE deleted = 0 AND assigned_user_id' . $in . $team . 'LIMIT 1';
            $rE = $next->db->query($qE);
            $aE = $next->db->fetchByAssoc($rE);
            $next->retrieve($aE['id']);
            $next->assigned_user_id = $current_user->id;
            $next->save();
            header('Location: index.php?module=Emails&action=DetailView&record=' . $next->id);
        } else {
            // no free items
            header('Location: index.php?module=Emails&action=ListView&type=inbound&group=true');
        }
    } else {
        // no groups
        header('Location: index.php?module=Emails&action=ListView&type=inbound&group=true');
    }
}
?>
<table width="100%" cellpadding="12" cellspacing="0" border="0">
	<tr>
		<td valign="middle" align="center" colspan="2">
			<?php 
Beispiel #23
0
 /**
  * Sends Email
  * @return bool True on success
  */
 function send()
 {
     global $mod_strings, $app_strings;
     global $current_user;
     global $sugar_config;
     global $locale;
     $OBCharset = $locale->getPrecedentPreference('default_email_charset');
     $mail = new SugarPHPMailer();
     foreach ($this->to_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddAddress($addr_arr['email'], "");
         } else {
             $mail->AddAddress($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset));
         }
     }
     foreach ($this->cc_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddCC($addr_arr['email'], "");
         } else {
             $mail->AddCC($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset));
         }
     }
     foreach ($this->bcc_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddBCC($addr_arr['email'], "");
         } else {
             $mail->AddBCC($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset));
         }
     }
     $mail = $this->setMailer($mail);
     // FROM ADDRESS
     if (!empty($this->from_addr)) {
         $mail->From = $this->from_addr;
     } else {
         $mail->From = $current_user->getPreference('mail_fromaddress');
         $this->from_addr = $mail->From;
     }
     // FROM NAME
     if (!empty($this->from_name)) {
         $mail->FromName = $this->from_name;
     } else {
         $mail->FromName = $current_user->getPreference('mail_fromname');
         $this->from_name = $mail->FromName;
     }
     //Reply to information for case create and autoreply.
     if (!empty($this->reply_to_name)) {
         $ReplyToName = $this->reply_to_name;
     } else {
         $ReplyToName = $mail->FromName;
     }
     if (!empty($this->reply_to_addr)) {
         $ReplyToAddr = $this->reply_to_addr;
     } else {
         $ReplyToAddr = $mail->From;
     }
     $mail->Sender = $mail->From;
     /* set Return-Path field in header to reduce spam score in emails sent via Sugar's Email module */
     $mail->AddReplyTo($ReplyToAddr, $locale->translateCharsetMIME(trim($ReplyToName), 'UTF-8', $OBCharset));
     //$mail->Subject = html_entity_decode($this->name, ENT_QUOTES, 'UTF-8');
     $mail->Subject = $this->name;
     ///////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS
     foreach ($this->saved_attachments as $note) {
         $mime_type = 'text/plain';
         if ($note->object_name == 'Note') {
             if (!empty($note->file->temp_file_location) && is_file($note->file->temp_file_location)) {
                 // brandy-new file upload/attachment
                 $file_location = $sugar_config['upload_dir'] . $note->id;
                 $filename = $note->file->original_file_name;
                 $mime_type = $note->file->mime_type;
             } else {
                 // attachment coming from template/forward
                 $file_location = rawurldecode(UploadFile::get_file_path($note->filename, $note->id));
                 // cn: bug 9723 - documents from EmailTemplates sent with Doc Name, not file name.
                 $filename = !empty($note->filename) ? $note->filename : $note->name;
                 $mime_type = $note->file_mime_type;
             }
         } elseif ($note->object_name == 'DocumentRevision') {
             // from Documents
             $filePathName = $note->id;
             // cn: bug 9723 - Emails with documents send GUID instead of Doc name
             $filename = $note->getDocumentRevisionNameForDisplay();
             $file_location = getcwd() . '/' . $GLOBALS['sugar_config']['upload_dir'] . $filePathName;
             $mime_type = $note->file_mime_type;
         }
         // strip out the "Email attachment label if exists
         $filename = str_replace($mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ', '', $filename);
         //is attachment in our list of bad files extensions?  If so, append .txt to file location
         //get position of last "." in file name
         $file_ext_beg = strrpos($file_location, ".");
         $file_ext = "";
         //get file extension
         if ($file_ext_beg > 0) {
             $file_ext = substr($file_location, $file_ext_beg + 1);
         }
         //check to see if this is a file with extension located in "badext"
         foreach ($sugar_config['upload_badext'] as $badExt) {
             if (strtolower($file_ext) == strtolower($badExt)) {
                 //if found, then append with .txt to filename and break out of lookup
                 //this will make sure that the file goes out with right extension, but is stored
                 //as a text in db.
                 $file_location = $file_location . ".txt";
                 break;
                 // no need to look for more
             }
         }
         $mail->AddAttachment($file_location, $locale->translateCharsetMIME(trim($filename), 'UTF-8', $OBCharset), 'base64', $mime_type);
         // embedded Images
         if ($note->embed_flag == true) {
             $cid = $filename;
             $mail->AddEmbeddedImage($file_location, $cid, $filename, 'base64', $mime_type);
         }
     }
     ////	END ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////
     $mail = $this->handleBody($mail);
     $GLOBALS['log']->debug('Email sending --------------------- ');
     ///////////////////////////////////////////////////////////////////////
     ////	I18N TRANSLATION
     $mail->prepForOutbound();
     ////	END I18N TRANSLATION
     ///////////////////////////////////////////////////////////////////////
     if ($mail->Send()) {
         ///////////////////////////////////////////////////////////////////
         ////	INBOUND EMAIL HANDLING
         // mark replied
         if (!empty($_REQUEST['inbound_email_id'])) {
             $ieMail = new Email();
             $ieMail->retrieve($_REQUEST['inbound_email_id']);
             $ieMail->status = 'replied';
             $ieMail->save();
         }
         $GLOBALS['log']->debug(' --------------------- buh bye -- sent successful');
         ////	END INBOUND EMAIL HANDLING
         ///////////////////////////////////////////////////////////////////
         return true;
     }
     $GLOBALS['log']->debug($app_strings['LBL_EMAIL_ERROR_PREPEND'] . $mail->ErrorInfo);
     return false;
 }
Beispiel #24
0
 function create($vars, &$errors)
 {
     return Email::save(0, $vars, $errors);
 }
Beispiel #25
0
/**
 * Record and email message and associated it with the specified parent bean and contact ids.
 *
 * This function does not require a session be created first.
 *
 * @param string $user_name -- Name of the user to authenticate
 * @param string $password -- MD5 hash of the user password for authentication
 * @param id $parent_id -- [optional] The parent record to link the email to.
 * @param unknown_type $contact_ids
 * @param string $date_sent -- Date/time the email was sent in Visual Basic Date format. (e.g. '7/22/2004 9:36:31 AM')
 * @param string $email_subject -- The subject of the email
 * @param string $email_body -- The body of the email
 * @return "Invalid username and/or password"
 * @return -1 If the authenticated user does not have ACL access to save Email.
 */
function track_email($user_name, $password, $parent_id, $contact_ids, $date_sent, $email_subject, $email_body)
{
    if (!validate_user($user_name, $password)) {
        return "Invalid username and/or password";
    }
    global $current_user;
    $GLOBALS['log']->info("In track email: username: {$user_name} contacts: {$contact_ids} date_sent: {$date_sent}");
    // translate date sent from VB format 7/22/2004 9:36:31 AM
    // to yyyy-mm-dd 9:36:31 AM
    $date_sent = preg_replace("@([0-9]*)/([0-9]*)/([0-9]*)( .*\$)@", "\\3-\\1-\\2\\4", $date_sent);
    $seed_user = new User();
    $user_id = $seed_user->retrieve_user_id($user_name);
    $seed_user->retrieve($user_id);
    $current_user = $seed_user;
    $email = new Email();
    if (!$email->ACLAccess('Save')) {
        return -1;
    }
    $email->description = $email_body;
    $email->name = $email_subject;
    $email->user_id = $user_id;
    $email->assigned_user_id = $user_id;
    $email->assigned_user_name = $user_name;
    $email->date_start = $date_sent;
    // Save one copy of the email message
    $parent_id_list = explode(";", $parent_id);
    $parent_id = explode(':', $parent_id_list[0]);
    // Having a parent object is optional.  If it is set, then associate it.
    if (isset($parent_id[0]) && isset($parent_id[1])) {
        $email->parent_type = $parent_id[0];
        $email->parent_id = $parent_id[1];
    }
    $email->save();
    // for each contact, add a link between the contact and the email message
    $id_list = explode(";", $contact_ids);
    foreach ($id_list as $id) {
        if (!empty($id)) {
            $email->set_emails_contact_invitee_relationship($email->id, $GLOBALS['db']->quote($id));
        }
    }
    return "Succeeded";
}
 private function logEmail($email, $mailer, $caseId = null)
 {
     require_once 'modules/Emails/Email.php';
     $emailObj = new Email();
     $emailObj->to_addrs = $email;
     $emailObj->type = 'out';
     $emailObj->deleted = '0';
     $emailObj->name = $mailer->Subject;
     $emailObj->description = $mailer->AltBody;
     $emailObj->description_html = $mailer->Body;
     $emailObj->from_addr = $mailer->From;
     if ($caseId) {
         $emailObj->parent_type = "Cases";
         $emailObj->parent_id = $caseId;
     }
     $emailObj->date_sent = TimeDate::getInstance()->nowDb();
     $emailObj->modified_user_id = '1';
     $emailObj->created_by = '1';
     $emailObj->status = 'sent';
     $emailObj->save();
 }
Beispiel #27
0
/**
 * Handles requirements for creating reminder Tasks and Emails
 * @param array skippedFiles Array of files that were not overwriten and must be manually mereged.
 * @param string path Optional full path to alternate upgradeWizard log.
 */
function commitHandleReminders($skippedFiles, $path = '')
{
    global $mod_strings;
    global $current_user;
    if (empty($mod_strings)) {
        $mod_strings = return_module_language('en_us', 'UpgradeWizard');
    }
    if (empty($current_user->id)) {
        $current_user->getSystemUser();
    }
    if (count($skippedFiles) > 0) {
        $desc = $mod_strings['LBL_UW_COMMIT_ADD_TASK_OVERVIEW'] . "\n\n";
        $desc .= $mod_strings['LBL_UW_COMMIT_ADD_TASK_DESC_1'];
        $desc .= $_SESSION['uw_restore_dir'] . "\n\n";
        $desc .= $mod_strings['LBL_UW_COMMIT_ADD_TASK_DESC_2'] . "\n\n";
        foreach ($skippedFiles as $file) {
            $desc .= $file . "\n";
        }
        //MFH #13468
        /// Not using new TimeDate stuff here because it needs to be compatible with 6.0
        $nowDate = gmdate('Y-m-d');
        $nowTime = gmdate('H:i:s');
        $nowDateTime = $nowDate . ' ' . $nowTime;
        if ($_REQUEST['addTaskReminder'] == 'remind') {
            logThis('Adding Task for admin for manual merge.', $path);
            $task = new Task();
            $task->name = $mod_strings['LBL_UW_COMMIT_ADD_TASK_NAME'];
            $task->description = $desc;
            $task->date_due = $nowDate;
            $task->time_due = $nowTime;
            $task->priority = 'High';
            $task->status = 'Not Started';
            $task->assigned_user_id = $current_user->id;
            $task->created_by = $current_user->id;
            $task->date_entered = $nowDateTime;
            $task->date_modified = $nowDateTime;
            $task->save();
        }
        if ($_REQUEST['addEmailReminder'] == 'remind') {
            logThis('Sending Reminder for admin for manual merge.', $path);
            $email = new Email();
            $email->assigned_user_id = $current_user->id;
            $email->name = $mod_strings['LBL_UW_COMMIT_ADD_TASK_NAME'];
            $email->description = $desc;
            $email->description_html = nl2br($desc);
            $email->from_name = $current_user->full_name;
            $email->from_addr = $current_user->email1;
            $email->to_addrs_arr = $email->parse_addrs($current_user->email1, '', '', '');
            $email->cc_addrs_arr = array();
            $email->bcc_addrs_arr = array();
            $email->date_entered = $nowDateTime;
            $email->date_modified = $nowDateTime;
            $email->send();
            $email->save();
        }
    }
}
Beispiel #28
0
 /**
  * distributes emails to 1 user
  * @param	$user		users to dist to
  * @param	$mailIds	array of email ids to push
  * @return  boolean		true on success
  */
 function distDirect($user, $mailIds)
 {
     foreach ($mailIds as $k => $mailId) {
         $email = new Email();
         $email->retrieve($mailId);
         $email->assigned_user_id = $user;
         $email->status = 'unread';
         $email->save();
     }
     return true;
 }
Beispiel #29
0
 /**
  * The function creates a copy of email send to each target.
  */
 function create_indiv_email($module, $mail)
 {
     global $locale, $timedate;
     $email = new Email();
     $email->to_addrs = $module->name . '&lt;' . $module->email1 . '&gt;';
     $email->to_addrs_ids = $module->id . ';';
     $email->to_addrs_names = $module->name . ';';
     $email->to_addrs_emails = $module->email1 . ';';
     $email->type = 'archived';
     $email->deleted = '0';
     $email->name = $this->current_campaign->name . ': ' . $mail->Subject;
     if ($mail->ContentType == "text/plain") {
         $email->description = $mail->Body;
         $email->description_html = null;
     } else {
         $email->description_html = $mail->Body;
         $email->description = $mail->AltBody;
     }
     $email->from_addr = $mail->From;
     $email->assigned_user_id = $this->user_id;
     $email->parent_type = $this->related_type;
     $email->parent_id = $this->related_id;
     $email->date_start = $timedate->nowDbDate();
     $email->time_start = $timedate->asDbTime($timedate->getNow());
     $email->status = 'sent';
     $retId = $email->save();
     foreach ($this->notes_array as $note) {
         if (!class_exists('Note')) {
         }
         // create "audit" email without duping off the file to save on disk space
         $noteAudit = new Note();
         $noteAudit->parent_id = $retId;
         $noteAudit->parent_type = $email->module_dir;
         $noteAudit->description = "[" . $note->filename . "] " . $mod_strings['LBL_ATTACHMENT_AUDIT'];
         $noteAudit->save();
     }
     if (!empty($this->related_id) && !empty($this->related_type)) {
         //save relationships.
         switch ($this->related_type) {
             case 'Users':
                 $rel_name = "users";
                 break;
             case 'Prospects':
                 $rel_name = "prospects";
                 break;
             case 'Contacts':
                 $rel_name = "contacts";
                 break;
             case 'Leads':
                 $rel_name = "leads";
                 break;
             case 'Accounts':
                 $rel_name = "accounts";
                 break;
         }
         if (!empty($rel_name)) {
             $email->load_relationship($rel_name);
             $email->{$rel_name}->add($this->related_id);
         }
     }
     return $email->id;
 }
Beispiel #30
0
 function handleSave($prefix, $redirect = true, $useRequired = false, $do_save = true, $exist_lead = null)
 {
     require_once 'modules/Campaigns/utils.php';
     require_once 'include/formbase.php';
     if (empty($exist_lead)) {
         $focus = new Lead();
     } else {
         $focus = $exist_lead;
     }
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     //Check for duplicate Leads
     if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
         $duplicateLeads = $this->checkForDuplicates($prefix);
         if (isset($duplicateLeads)) {
             //Set the redirect location to call the ShowDuplicates action.  This will map to view.showduplicates.php
             $location = 'module=Leads&action=ShowDuplicates';
             $get = '';
             if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
                 $get .= '&inbound_email_id=' . $_POST['inbound_email_id'];
             }
             if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
                 $get .= '&Leadsrelate_to=' . $_POST['relate_to'];
             }
             if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
                 $get .= '&Leadsrelate_id=' . $_POST['relate_id'];
             }
             //add all of the post fields to redirect get string
             foreach ($focus->column_fields as $field) {
                 if (!empty($focus->{$field}) && !is_object($focus->{$field})) {
                     $get .= "&Leads{$field}=" . urlencode($focus->{$field});
                 }
             }
             foreach ($focus->additional_column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&Leads{$field}=" . urlencode($focus->{$field});
                 }
             }
             if ($focus->hasCustomFields()) {
                 foreach ($focus->field_defs as $name => $field) {
                     if (!empty($field['source']) && $field['source'] == 'custom_fields') {
                         $get .= "&Leads{$name}=" . urlencode($focus->{$name});
                     }
                 }
             }
             $emailAddress = new SugarEmailAddress();
             $get .= $emailAddress->getFormBaseURL($focus);
             //create list of suspected duplicate lead ids in redirect get string
             $i = 0;
             foreach ($duplicateLeads as $lead) {
                 $get .= "&duplicate[{$i}]=" . $lead['id'];
                 $i++;
             }
             //add return_module, return_action, and return_id to redirect get string
             $get .= "&return_module=";
             if (!empty($_POST['return_module'])) {
                 $get .= $_POST['return_module'];
             } else {
                 $get .= "Leads";
             }
             $get .= "&return_action=";
             if (!empty($_POST['return_action'])) {
                 $get .= $_POST['return_action'];
             }
             if (!empty($_POST['return_id'])) {
                 $get .= "&return_id=" . $_POST['return_id'];
             }
             if (!empty($_POST['popup'])) {
                 $get .= '&popup=' . $_POST['popup'];
             }
             if (!empty($_POST['create'])) {
                 $get .= '&create=' . $_POST['create'];
             }
             // for InboundEmail flow
             if (!empty($_POST['start'])) {
                 $get .= '&start=' . $_POST['start'];
             }
             $_SESSION['SHOW_DUPLICATES'] = $get;
             if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
                 ob_clean();
                 $json = getJSONobj();
                 echo $json->encode(array('status' => 'dupe', 'get' => $location));
             } else {
                 if (!empty($_REQUEST['ajax_load'])) {
                     echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>";
                 } else {
                     if (!empty($_POST['to_pdf'])) {
                         $location .= '&to_pdf=' . $_POST['to_pdf'];
                     }
                     header("Location: index.php?{$location}");
                 }
             }
             return null;
         }
     }
     if (!isset($_POST[$prefix . 'email_opt_out'])) {
         $focus->email_opt_out = 0;
     }
     if (!isset($_POST[$prefix . 'do_not_call'])) {
         $focus->do_not_call = 0;
     }
     if ($do_save) {
         if (!empty($GLOBALS['check_notify'])) {
             $focus->save($GLOBALS['check_notify']);
         } else {
             $focus->save(FALSE);
         }
     }
     $return_id = $focus->id;
     if (isset($_POST[$prefix . 'prospect_id']) && !empty($_POST[$prefix . 'prospect_id'])) {
         $prospect = new Prospect();
         $prospect->retrieve($_POST[$prefix . 'prospect_id']);
         $prospect->lead_id = $focus->id;
         // Set to keep email in target
         $prospect->in_workflow = true;
         $prospect->save();
         //if prospect id exists, make sure we are coming from prospect detail
         if (strtolower($_POST['return_module']) == 'prospects' && strtolower($_POST['return_action']) == 'detailview') {
             //create campaing_log entry
             if (isset($focus->campaign_id) && $focus->campaign_id != null) {
                 campaign_log_lead_entry($focus->campaign_id, $prospect, $focus, 'lead');
             }
         }
     }
     ///////////////////////////////////////////////////////////////////////////////
     ////	INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
         if (!isset($current_user)) {
             global $current_user;
         }
         // fake this case like it's already saved.
         $email = new Email();
         $email->retrieve($_REQUEST['inbound_email_id']);
         $email->parent_type = 'Leads';
         $email->parent_id = $focus->id;
         $email->assigned_user_id = $current_user->id;
         $email->status = 'read';
         $email->save();
         $email->load_relationship('leads');
         $email->leads->add($focus->id);
         header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start']);
         exit;
     }
     ////	END INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if ($redirect) {
         handleRedirect($return_id, 'Leads');
     } else {
         return $focus;
     }
 }