示例#1
0
文件: Record.php 项目: Wasage/werpa
 /**
  * Function sends mail
  */
 public function send()
 {
     $currentUserModel = Users_Record_Model::getCurrentUserModel();
     $rootDirectory = vglobal('root_directory');
     $mailer = Emails_Mailer_Model::getInstance();
     $mailer->IsHTML(true);
     $fromEmail = $this->getFromEmailAddress();
     $replyTo = $currentUserModel->get('email1');
     $userName = $currentUserModel->getName();
     // To eliminate the empty value of an array
     $toEmailInfo = array_filter($this->get('toemailinfo'));
     $toMailNamesList = array_filter($this->get('toMailNamesList'));
     foreach ($toMailNamesList as $id => $emailData) {
         foreach ($emailData as $key => $email) {
             if ($toEmailInfo[$id]) {
                 array_push($toEmailInfo[$id], $email['value']);
             }
         }
     }
     $emailsInfo = array();
     foreach ($toEmailInfo as $id => $emails) {
         foreach ($emails as $key => $value) {
             array_push($emailsInfo, $value);
         }
     }
     $toFieldData = array_diff(explode(',', $this->get('saved_toid')), $emailsInfo);
     $toEmailsData = array();
     $i = 1;
     foreach ($toFieldData as $value) {
         $toEmailInfo['to' . $i++] = array($value);
     }
     $attachments = $this->getAttachmentDetails();
     $status = false;
     // Merge Users module merge tags based on current user.
     $mergedDescription = getMergedDescription($this->get('description'), $currentUserModel->getId(), 'Users');
     $mergedSubject = getMergedDescription($this->get('subject'), $currentUserModel->getId(), 'Users');
     foreach ($toEmailInfo as $id => $emails) {
         $mailer->reinitialize();
         $mailer->ConfigSenderInfo($fromEmail, $userName, $replyTo);
         $old_mod_strings = vglobal('mod_strings');
         $description = $this->get('description');
         $subject = $this->get('subject');
         $parentModule = $this->getEntityType($id);
         if ($parentModule) {
             $currentLanguage = Vtiger_Language_Handler::getLanguage();
             $moduleLanguageStrings = Vtiger_Language_Handler::getModuleStringsFromFile($currentLanguage, $parentModule);
             vglobal('mod_strings', $moduleLanguageStrings['languageStrings']);
             if ($parentModule != 'Users') {
                 // Apply merge for non-Users module merge tags.
                 $description = getMergedDescription($mergedDescription, $id, $parentModule);
                 $subject = getMergedDescription($mergedSubject, $id, $parentModule);
             } else {
                 // Re-merge the description for user tags based on actual user.
                 $description = getMergedDescription($description, $id, 'Users');
                 $subject = getMergedDescription($mergedSubject, $id, 'Users');
                 vglobal('mod_strings', $old_mod_strings);
             }
         }
         if (strpos($description, '$logo$')) {
             $description = str_replace('$logo$', "<img src='cid:logo' />", $description);
             $logo = true;
         }
         foreach ($emails as $email) {
             $mailer->Body = '';
             if ($parentModule) {
                 $mailer->Body = $this->getTrackImageDetails($id, $this->isEmailTrackEnabled());
             }
             $mailer->Body .= $description;
             $mailer->Signature = str_replace(array('\\r\\n', '\\n'), '<br>', $currentUserModel->get('signature'));
             if ($mailer->Signature != '') {
                 $mailer->Body .= '<br><br>' . decode_html($mailer->Signature);
             }
             $mailer->Subject = $subject;
             $mailer->AddAddress($email);
             //Adding attachments to mail
             if (is_array($attachments)) {
                 foreach ($attachments as $attachment) {
                     $fileNameWithPath = $rootDirectory . $attachment['path'] . $attachment['fileid'] . "_" . $attachment['attachment'];
                     if (is_file($fileNameWithPath)) {
                         $mailer->AddAttachment($fileNameWithPath, $attachment['attachment']);
                     }
                 }
             }
             if ($logo) {
                 //While sending email template and which has '$logo$' then it should replace with company logo
                 $mailer->AddEmbeddedImage(dirname(__FILE__) . '/../../../layouts/vlayout/skins/images/logo_mail.jpg', 'logo', 'logo.jpg', 'base64', 'image/jpg');
             }
             $ccs = array_filter(explode(',', $this->get('ccmail')));
             $bccs = array_filter(explode(',', $this->get('bccmail')));
             if (!empty($ccs)) {
                 // SalesPlatform.ru begin
                 foreach ($ccs as $cc) {
                     $mailer->AddCC($idn->encode($cc));
                 }
                 //$mailer->AddCC($cc);
                 // SalesPlatform.ru end
             }
             if (!empty($bccs)) {
                 // SalesPlatform.ru begin
                 foreach ($bccs as $bcc) {
                     $mailer->AddBCC($idn->encode($bcc));
                 }
                 //$mailer->AddBCC($bcc);
                 // SalesPlatform.ru end
             }
         }
         // SalesPlatform.ru begin
         $idn = new idna_convert();
         $query = "select * from vtiger_systems where server_type=?";
         $params = array('email');
         //SalesPlatform begin fix bug
         $adb = PearDatabase::getInstance();
         //SalesPaltform.ru end
         $result = $adb->pquery($query, $params);
         $server_username = $adb->query_result($result, 0, 'server_username');
         $from_name_db = $adb->query_result($result, 0, 'from_name');
         $server_port = $adb->query_result($result, 0, 'server_port');
         $server_tls = $adb->query_result($result, 0, 'server_tls');
         if ($server_username != '') {
             $server_username = $idn->encode($server_username);
             $mailer->Username = $server_username;
         }
         if (isset($from_name_db) && $from_name_db != '') {
             $mailer->FromName = decode_html($from_name_db);
         }
         $from_email = $adb->query_result($result, 0, 'from_email_field');
         if ($from_email != '') {
             $mailer->From = $idn->encode($from_email);
         }
         if (!empty($server_port) && $server_port != 0) {
             $mailer->Port = $server_port;
         }
         if (!empty($server_tls) && $server_tls != 'no') {
             $mailer->SMTPSecure = $server_tls;
         }
         $use_sendmail = $adb->query_result($result, 0, 'use_sendmail');
         if ($use_sendmail == "on") {
             $mailer->IsSendmail();
         } else {
             $mailer->IsSMTP();
         }
         // SalesPlatform.ru end
         $status = $mailer->Send(true);
         if (!$status) {
             $status = $mailer->getError();
         } else {
             $mailString = $mailer->getMailString();
             $mailBoxModel = MailManager_Mailbox_Model::activeInstance();
             $folderName = $mailBoxModel->folder();
             if (!empty($folderName) && !empty($mailString)) {
                 $connector = MailManager_Connector_Connector::connectorWithModel($mailBoxModel, '');
                 imap_append($connector->mBox, $connector->mBoxUrl . $folderName, $mailString, "\\Seen");
             }
         }
     }
     return $status;
 }
示例#2
0
 /**
  * Function which processes request for Mail Operations
  * @global Integer $list_max_entries_per_page - Number of entries per page
  * @global PearDataBase Instance $adb
  * @global Users Instance $current_user
  * @global String $root_directory
  * @param Vtiger_Request $request
  * @return MailManager_Response
  */
 function process(Vtiger_Request $request)
 {
     global $list_max_entries_per_page, $adb, $current_user;
     $moduleName = $request->getModule();
     $response = new Vtiger_Response();
     if ('open' == $this->getOperationArg($request)) {
         $foldername = $request->get('_folder');
         $connector = $this->getConnector($foldername);
         $folder = $connector->folderInstance($foldername);
         $connector->markMailRead($request->get('_msgno'));
         $mail = $connector->openMail($request->get('_msgno'));
         // Get updated count after opening the email
         $connector->updateFolder($folder, SA_MESSAGES | SA_UNSEEN);
         $viewer = $this->getViewer($request);
         $viewer->assign('FOLDER', $folder);
         $viewer->assign('MAIL', $mail);
         $viewer->assign('MODULE', $moduleName);
         $uicontent = $viewer->view('MailOpen.tpl', 'MailManager', true);
         $metainfo = array('from' => $mail->from(), 'subject' => $mail->subject(), 'msgno' => $mail->msgNo(), 'msguid' => $mail->uniqueid(), 'folder' => $foldername);
         $response->isJson(true);
         $response->setResult(array('folder' => $foldername, 'unread' => $folder->unreadCount(), 'ui' => $uicontent, 'meta' => $metainfo));
     } else {
         if ('mark' == $this->getOperationArg($request)) {
             $foldername = $request->get('_folder');
             $connector = $this->getConnector($foldername);
             $folder = $connector->folderInstance($foldername);
             $connector->updateFolder($folder, SA_UNSEEN);
             if ('unread' == $request->get('_markas')) {
                 $connector->markMailUnread($request->get('_msgno'));
             }
             $response->isJson(true);
             $response->setResult(array('folder' => $foldername, 'unread' => $folder->unreadCount() + 1, 'status' => true, 'msgno' => $request->get('_msgno')));
         } else {
             if ('delete' == $this->getOperationArg($request)) {
                 $msg_no = $request->get('_msgno');
                 $foldername = $request->get('_folder');
                 $connector = $this->getConnector($foldername);
                 $connector->deleteMail($msg_no);
                 $response->isJson(true);
                 $response->setResult(array('folder' => $foldername, 'status' => true));
             } else {
                 if ('move' == $this->getOperationArg($request)) {
                     $msg_no = $request->get('_msgno');
                     $foldername = $request->get('_folder');
                     $moveToFolder = $request->get('_moveFolder');
                     $connector = $this->getConnector($foldername);
                     $connector->moveMail($msg_no, $moveToFolder);
                     $response->isJson(true);
                     $response->setResult(array('folder' => $foldername, 'status' => true));
                 } else {
                     if ('send' == $this->getOperationArg($request)) {
                         require_once 'modules/MailManager/Config.php';
                         // This is to handle larger uploads
                         $memory_limit = MailManager_Config::get('MEMORY_LIMIT');
                         ini_set('memory_limit', $memory_limit);
                         $to_string = rtrim($request->get('to'), ',');
                         $connector = $this->getConnector('__vt_drafts');
                         if (!empty($to_string)) {
                             $toArray = explode(',', $to_string);
                             foreach ($toArray as $to) {
                                 $relatedtos = MailManager::lookupMailInVtiger($to, $current_user);
                                 $referenceArray = array('Contacts', 'Accounts', 'Leads');
                                 for ($j = 0; $j < count($referenceArray); $j++) {
                                     $val = $referenceArray[$j];
                                     if (!empty($relatedtos) && is_array($relatedtos)) {
                                         for ($i = 0; $i < count($relatedtos); $i++) {
                                             if ($i == count($relatedtos) - 1) {
                                                 $relateto = vtws_getIdComponents($relatedtos[$i]['record']);
                                                 $parentIds = $relateto[1] . "@1";
                                             } elseif ($relatedtos[$i]['module'] == $val) {
                                                 $relateto = vtws_getIdComponents($relatedtos[$i]['record']);
                                                 $parentIds = $relateto[1] . "@1";
                                                 break;
                                             }
                                         }
                                     }
                                     if (isset($parentIds)) {
                                         break;
                                     }
                                 }
                                 if ($parentIds == '') {
                                     if (count($relatedtos) > 0) {
                                         $relateto = vtws_getIdComponents($relatedtos[0]['record']);
                                         $parentIds = $relateto[1] . "@1";
                                         break;
                                     }
                                 }
                                 $cc_string = rtrim($request->get('cc'), ',');
                                 $bcc_string = rtrim($request->get('bcc'), ',');
                                 $subject = $request->get('subject');
                                 $body = $request->get('body');
                                 //Restrict this for users module
                                 if ($relateto[1] != NULL && $relateto[0] != '19') {
                                     $entityId = $relateto[1];
                                     $parent_module = getSalesEntityType($entityId);
                                     $description = getMergedDescription($body, $entityId, $parent_module);
                                 } else {
                                     if ($relateto[0] == '19') {
                                         $parentIds = $relateto[1] . '@-1';
                                     }
                                     $description = $body;
                                 }
                                 $fromEmail = $connector->getFromEmailAddress();
                                 $userFullName = getFullNameFromArray('Users', $current_user->column_fields);
                                 $userId = $current_user->id;
                                 $mailer = new Vtiger_Mailer();
                                 $mailer->IsHTML(true);
                                 $mailer->ConfigSenderInfo($fromEmail, $userFullName, $current_user->email1);
                                 $mailer->Subject = $subject;
                                 $mailer->Body = $description;
                                 $mailer->addSignature($userId);
                                 if ($mailer->Signature != '') {
                                     $mailer->Body .= $mailer->Signature;
                                 }
                                 $ccs = empty($cc_string) ? array() : explode(',', $cc_string);
                                 $bccs = empty($bcc_string) ? array() : explode(',', $bcc_string);
                                 $emailId = $request->get('emailid');
                                 $attachments = $connector->getAttachmentDetails($emailId);
                                 $mailer->AddAddress($to);
                                 foreach ($ccs as $cc) {
                                     $mailer->AddCC($cc);
                                 }
                                 foreach ($bccs as $bcc) {
                                     $mailer->AddBCC($bcc);
                                 }
                                 global $root_directory;
                                 if (is_array($attachments)) {
                                     foreach ($attachments as $attachment) {
                                         $fileNameWithPath = $root_directory . $attachment['path'] . $attachment['fileid'] . "_" . $attachment['attachment'];
                                         if (is_file($fileNameWithPath)) {
                                             $mailer->AddAttachment($fileNameWithPath, $attachment['attachment']);
                                         }
                                     }
                                 }
                                 $status = $mailer->Send(true);
                                 if ($status === true) {
                                     $email = CRMEntity::getInstance('Emails');
                                     $email->column_fields['assigned_user_id'] = $current_user->id;
                                     $email->column_fields['date_start'] = date('Y-m-d');
                                     $email->column_fields['time_start'] = date('H:i');
                                     $email->column_fields['parent_id'] = $parentIds;
                                     $email->column_fields['subject'] = $mailer->Subject;
                                     $email->column_fields['description'] = $mailer->Body;
                                     $email->column_fields['activitytype'] = 'Emails';
                                     $email->column_fields['from_email'] = $mailer->From;
                                     $email->column_fields['saved_toid'] = $to;
                                     $email->column_fields['ccmail'] = $cc_string;
                                     $email->column_fields['bccmail'] = $bcc_string;
                                     $email->column_fields['email_flag'] = 'SENT';
                                     if (empty($emailId)) {
                                         $email->save('Emails');
                                     } else {
                                         $email->id = $emailId;
                                         $email->mode = 'edit';
                                         $email->save('Emails');
                                     }
                                     // This is added since the Emails save_module is not handling this
                                     global $adb;
                                     $realid = explode("@", $parentIds);
                                     $mycrmid = $realid[0];
                                     $params = array($mycrmid, $email->id);
                                     if ($realid[1] == -1) {
                                         $adb->pquery('DELETE FROM vtiger_salesmanactivityrel WHERE smid=? AND activityid=?', $params);
                                         $adb->pquery('INSERT INTO vtiger_salesmanactivityrel VALUES (?,?)', $params);
                                     } else {
                                         $adb->pquery('DELETE FROM vtiger_seactivityrel WHERE crmid=? AND activityid=?', $params);
                                         $adb->pquery('INSERT INTO vtiger_seactivityrel VALUES (?,?)', $params);
                                     }
                                 }
                             }
                         }
                         if ($status === true) {
                             $response->isJson(true);
                             $response->setResult(array('sent' => true));
                         } else {
                             $response->isJson(true);
                             $response->setError(112, 'please verify outgoing server.');
                         }
                     } else {
                         if ('attachment_dld' == $this->getOperationArg($request)) {
                             $attachmentName = $request->get('_atname');
                             $attachmentName = str_replace(' ', '_', $attachmentName);
                             if (MailManager_Utils::allowedFileExtension($attachmentName)) {
                                 // This is to handle larger uploads
                                 $memory_limit = MailManager_Config::get('MEMORY_LIMIT');
                                 ini_set('memory_limit', $memory_limit);
                                 $mail = new MailManager_Message_Model(false, false);
                                 $mail->readFromDB($request->get('_muid'));
                                 $attachment = $mail->attachments(true, $attachmentName);
                                 if ($attachment[$attachmentName]) {
                                     // Send as downloadable
                                     header("Content-type: application/octet-stream");
                                     header("Pragma: public");
                                     header("Cache-Control: private");
                                     header("Content-Disposition: attachment; filename={$attachmentName}");
                                     echo $attachment[$attachmentName];
                                 } else {
                                     header("Content-Disposition: attachment; filename=INVALIDFILE");
                                     echo "";
                                 }
                             } else {
                                 header("Content-Disposition: attachment; filename=INVALIDFILE");
                                 echo "";
                             }
                             flush();
                             exit;
                         } elseif ('getdraftmail' == $this->getOperationArg($request)) {
                             $connector = $this->getConnector('__vt_drafts');
                             $draftMail = $connector->getDraftMail($request);
                             $response->isJson(true);
                             $response->setResult(array($draftMail));
                         } elseif ('save' == $this->getOperationArg($request)) {
                             $connector = $this->getConnector('__vt_drafts');
                             $draftId = $connector->saveDraft($request);
                             $response->isJson(true);
                             if (!empty($draftId)) {
                                 $response->setResult(array('success' => true, 'emailid' => $draftId));
                             } else {
                                 $response->setResult(array('success' => false, 'error' => "Draft was not saved"));
                             }
                         } elseif ('deleteAttachment' == $this->getOperationArg($request)) {
                             $connector = $this->getConnector('__vt_drafts');
                             $deleteResponse = $connector->deleteAttachment($request);
                             $response->isJson(true);
                             $response->setResult(array('success' => $deleteResponse));
                         } elseif ('forward' == $this->getOperationArg($request)) {
                             $messageId = $request->get('messageid');
                             $folderName = $request->get('folder');
                             $connector = $this->getConnector($folderName);
                             $mail = $connector->openMail($messageId);
                             $attachments = $mail->attachments(true);
                             $draftConnector = $this->getConnector('__vt_drafts');
                             $draftId = $draftConnector->saveDraft($request);
                             if (!empty($attachments)) {
                                 foreach ($attachments as $aName => $aValue) {
                                     $attachInfo = $mail->__SaveAttachmentFile($aName, $aValue);
                                     if (is_array($attachInfo) && !empty($attachInfo) && $attachInfo['size'] > 0) {
                                         if (!MailManager::checkModuleWriteAccessForCurrentUser('Documents')) {
                                             return;
                                         }
                                         $document = CRMEntity::getInstance('Documents');
                                         $document->column_fields['notes_title'] = $attachInfo['name'];
                                         $document->column_fields['filename'] = $attachInfo['name'];
                                         $document->column_fields['filestatus'] = 1;
                                         $document->column_fields['filelocationtype'] = 'I';
                                         $document->column_fields['folderid'] = 1;
                                         // Default Folder
                                         $document->column_fields['filesize'] = $attachInfo['size'];
                                         $document->column_fields['assigned_user_id'] = $current_user->id;
                                         $document->save('Documents');
                                         //save doc-attachment relation
                                         $draftConnector->saveAttachmentRel($document->id, $attachInfo['attachid']);
                                         //save email-doc relation
                                         $draftConnector->saveEmailDocumentRel($draftId, $document->id);
                                         //save email-attachment relation
                                         $draftConnector->saveAttachmentRel($draftId, $attachInfo['attachid']);
                                         $attachmentInfo[] = array('name' => $attachInfo['name'], 'size' => $attachInfo['size'], 'emailid' => $draftId, 'docid' => $document->id);
                                     }
                                     unset($aValue);
                                 }
                             }
                             $response->isJson(true);
                             $response->setResult(array('attachments' => $attachmentInfo, 'emailid' => $draftId));
                         }
                     }
                 }
             }
         }
     }
     return $response;
 }
示例#3
0
    public static function getPortalEmailContents($entityData, $password, $type = '')
    {
        require_once 'config.inc.php';
        global $PORTAL_URL, $default_charset;
        $adb = PearDatabase::getInstance();
        $moduleName = $entityData->getModuleName();
        $portalURL = '<a href="' . $PORTAL_URL . '" style="font-family:Arial, Helvetica, sans-serif;font-size:12px; font-weight:bolder;text-decoration:none;color: #4242FD;">' . getTranslatedString('Please Login Here', $moduleName) . '</a>';
        //here id is hardcoded with 5. it is for support start notification in vtiger_notificationscheduler
        $query = 'SELECT vtiger_emailtemplates.subject,vtiger_emailtemplates.body
				FROM vtiger_notificationscheduler
				INNER JOIN vtiger_emailtemplates ON vtiger_emailtemplates.templateid=vtiger_notificationscheduler.notificationbody
				WHERE schedulednotificationid=5';
        $result = $adb->pquery($query, array());
        $body = $adb->query_result($result, 0, 'body');
        $contents = html_entity_decode($body, ENT_QUOTES, $default_charset);
        $contents = str_replace('$contact_name$', $entityData->get('firstname') . " " . $entityData->get('lastname'), $contents);
        $contents = str_replace('$login_name$', $entityData->get('email'), $contents);
        $contents = str_replace('$password$', $password, $contents);
        $contents = str_replace('$URL$', $portalURL, $contents);
        $contents = str_replace('$support_team$', getTranslatedString('Support Team', $moduleName), $contents);
        $contents = str_replace('$logo$', '<img src="cid:logo" />', $contents);
        $contents = getMergedDescription($contents, $entityData->getId(), 'Contacts');
        if ($type == "LoginDetails") {
            $temp = $contents;
            $value["subject"] = $adb->query_result($result, 0, 'subject');
            $value["body"] = $temp;
            return $value;
        }
        return $contents;
    }
示例#4
0
文件: mailsend.php 项目: hardikk/HNH
 } elseif ($pmodule == 'Vendors') {
     require_once 'modules/Vendors/Vendors.php';
     $myfocus = new Vendors();
     $myfocus->retrieve_entity_info($mycrmid, "Vendors");
 } else {
     // vtlib customization: Enabling mail send from other modules
     $myfocus = CRMEntity::getInstance($pmodule);
     $myfocus->retrieve_entity_info($mycrmid, $pmodule);
     // END
 }
 $fldname = $adb->query_result($fresult, 0, "columnname");
 $emailadd = br2nl($myfocus->column_fields[$fldname]);
 //This is to convert the html encoded string to original html entities so that in mail description contents will be displayed correctly
 //$focus->column_fields['description'] = from_html($focus->column_fields['description']);
 if ($emailadd != '') {
     $description = getMergedDescription($_REQUEST['description'], $mycrmid, $pmodule);
     //Email Open Tracking
     global $site_URL, $application_unique_key;
     $emailid = $focus->id;
     $track_URL = "{$site_URL}/modules/Emails/TrackAccess.php?record={$mycrmid}&mailid={$emailid}&app_key={$application_unique_key}";
     $description = "<img src='{$track_URL}' alt='' width='1' height='1'>{$description}";
     // END
     $pos = strpos($description, '$logo$');
     if ($pos !== false) {
         $description = str_replace('$logo$', '<img src="cid:logo" />', $description);
         $logo = 1;
     }
     if (isPermitted($pmodule, 'DetailView', $mycrmid) == 'yes') {
         $mail_status = send_mail('Emails', $emailadd, $from_name, $from_address, $_REQUEST['subject'], $description, '', '', 'all', $focus->id, $logo);
     }
     $all_to_emailids[] = $emailadd;
示例#5
0
function Contacts_sendCustomerPortalLoginDetails($entityData)
{
    $adb = PearDatabase::getInstance();
    $moduleName = $entityData->getModuleName();
    $wsId = $entityData->getId();
    $parts = explode('x', $wsId);
    $entityId = $parts[1];
    $entityDelta = new VTEntityDelta();
    $portalChanged = $entityDelta->hasChanged($moduleName, $entityId, 'portal');
    $email = $entityData->get('email');
    if ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') {
        $sql = "SELECT id, user_name, user_password, isactive FROM vtiger_portalinfo WHERE id=?";
        $result = $adb->pquery($sql, array($entityId));
        $insert = false;
        if ($adb->num_rows($result) == 0) {
            $insert = true;
        } else {
            $dbusername = $adb->query_result($result, 0, 'user_name');
            $isactive = $adb->query_result($result, 0, 'isactive');
            if ($email == $dbusername && $isactive == 1 && !$entityData->isNew()) {
                $update = false;
            } else {
                if ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') {
                    $sql = "UPDATE vtiger_portalinfo SET user_name=?, isactive=? WHERE id=?";
                    $adb->pquery($sql, array($email, 1, $entityId));
                    $update = true;
                } else {
                    $sql = "UPDATE vtiger_portalinfo SET user_name=?, isactive=? WHERE id=?";
                    $adb->pquery($sql, array($email, 0, $entityId));
                    $update = false;
                }
            }
        }
        $password = makeRandomPassword();
        $md5_password = md5($password);
        if ($insert == true) {
            $sql = "INSERT INTO vtiger_portalinfo(id,user_name,user_password,type,isactive) VALUES(?,?,?,?,?)";
            $params = array($entityId, $email, $md5_password, 'C', 1);
            $adb->pquery($sql, $params);
        }
        if ($update == true && $portalChanged == true) {
            $sql = "UPDATE vtiger_portalinfo SET user_password=? WHERE id=?";
            $params = array($md5_password, $entityId);
            $adb->pquery($sql, $params);
        }
        if (($insert == true || ($update = true && $portalChanged == true)) && $entityData->get('emailoptout') == 0) {
            global $current_user, $HELPDESK_SUPPORT_EMAIL_ID, $HELPDESK_SUPPORT_NAME;
            require_once "modules/Emails/mail.php";
            $emailData = Contacts::getPortalEmailContents($entityData, $password, 'LoginDetails');
            $subject = $emailData['subject'];
            if (empty($subject)) {
                $subject = 'Customer Portal Login Details';
            }
            $contents = $emailData['body'];
            $contents = decode_html(getMergedDescription($contents, $entityId, 'Contacts'));
            if (empty($contents)) {
                require_once 'config.inc.php';
                global $PORTAL_URL;
                $contents = 'LoginDetails';
                $contents .= "<br><br> User ID : " . $entityData->get('email');
                $contents .= "<br> Password: "******"' . $PORTAL_URL . '" style="font-family:Arial, Helvetica, sans-serif;font-size:13px;">' . vtranslate('click here', $moduleName) . '</a>';
                $contents .= "<br>" . $portalURL;
            }
            $subject = decode_html(getMergedDescription($subject, $entityId, 'Contacts'));
            send_mail('Contacts', $entityData->get('email'), $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $contents, '', '', '', '', '', true);
        }
    } else {
        $sql = "UPDATE vtiger_portalinfo SET user_name=?,isactive=0 WHERE id=?";
        $adb->pquery($sql, array($email, $entityId));
    }
}
示例#6
0
 /**
  * Function sends mail
  */
 public function send()
 {
     $currentUserModel = Users_Record_Model::getCurrentUserModel();
     $rootDirectory = vglobal('root_directory');
     $mailer = Emails_Mailer_Model::getInstance();
     $mailer->IsHTML(true);
     $fromEmail = $this->getFromEmailAddress();
     $replyTo = $currentUserModel->get('email1');
     $userName = $currentUserModel->getName();
     // To eliminate the empty value of an array
     $toEmailInfo = array_filter($this->get('toemailinfo'));
     $toMailNamesList = array_filter($this->get('toMailNamesList'));
     foreach ($toMailNamesList as $id => $emailData) {
         foreach ($emailData as $key => $email) {
             if ($toEmailInfo[$id]) {
                 array_push($toEmailInfo[$id], $email['value']);
             }
         }
     }
     $emailsInfo = array();
     foreach ($toEmailInfo as $id => $emails) {
         foreach ($emails as $key => $value) {
             array_push($emailsInfo, $value);
         }
     }
     $toFieldData = array_diff(explode(',', $this->get('saved_toid')), $emailsInfo);
     $toEmailsData = array();
     $i = 1;
     foreach ($toFieldData as $value) {
         $toEmailInfo['to' . $i++] = array($value);
     }
     $attachments = $this->getAttachmentDetails();
     $status = false;
     // Merge Users module merge tags based on current user.
     $mergedDescription = getMergedDescription($this->get('description'), $currentUserModel->getId(), 'Users');
     foreach ($toEmailInfo as $id => $emails) {
         $mailer->reinitialize();
         $mailer->ConfigSenderInfo($fromEmail, $userName, $replyTo);
         $old_mod_strings = vglobal('mod_strings');
         $description = $this->get('description');
         $parentModule = $this->getEntityType($id);
         if ($parentModule) {
             $currentLanguage = Vtiger_Language_Handler::getLanguage();
             $moduleLanguageStrings = Vtiger_Language_Handler::getModuleStringsFromFile($currentLanguage, $parentModule);
             vglobal('mod_strings', $moduleLanguageStrings['languageStrings']);
             if ($parentModule != 'Users') {
                 // Apply merge for non-Users module merge tags.
                 $description = getMergedDescription($mergedDescription, $id, $parentModule);
             } else {
                 // Re-merge the description for user tags based on actual user.
                 $description = getMergedDescription($description, $id, 'Users');
                 vglobal('mod_strings', $old_mod_strings);
             }
         }
         if (strpos($description, '$logo$')) {
             $description = str_replace('$logo$', "<img src='cid:logo' />", $description);
             $logo = true;
         }
         foreach ($emails as $email) {
             $mailer->Body = $description;
             $mailer->Signature = str_replace(array('\\r\\n', '\\n'), '<br>', $currentUserModel->get('signature'));
             if ($mailer->Signature != '') {
                 $mailer->Body .= '<br><br>' . decode_html($mailer->Signature);
             }
             $mailer->Subject = $this->get('subject');
             $mailer->AddAddress($email);
             //Adding attachments to mail
             if (is_array($attachments)) {
                 foreach ($attachments as $attachment) {
                     $fileNameWithPath = $rootDirectory . $attachment['path'] . $attachment['fileid'] . "_" . $attachment['attachment'];
                     if (is_file($fileNameWithPath)) {
                         $mailer->AddAttachment($fileNameWithPath, $attachment['attachment']);
                     }
                 }
             }
             if ($logo) {
                 //While sending email template and which has '$logo$' then it should replace with company logo
                 $company = Settings_Vtiger_CompanyDetails_Model::getInstance();
                 $logo = $company->getLogoPath('logoname');
                 $mailer->AddEmbeddedImage(dirname(__FILE__) . '/../../../' . $logo, 'logo', 'logo.jpg', 'base64', 'image/jpg');
             }
             $ccs = array_filter(explode(',', $this->get('ccmail')));
             $bccs = array_filter(explode(',', $this->get('bccmail')));
             if (!empty($ccs)) {
                 foreach ($ccs as $cc) {
                     $mailer->AddCC($cc);
                 }
             }
             if (!empty($bccs)) {
                 foreach ($bccs as $bcc) {
                     $mailer->AddBCC($bcc);
                 }
             }
         }
         $status = $mailer->Send(true);
         if (!$status) {
             $status = $mailer->getError();
         } else {
             $mailString = $mailer->getMailString();
             $mailBoxModel = MailManager_Mailbox_Model::activeInstance();
             $folderName = $mailBoxModel->folder();
             if (!empty($folderName) && !empty($mailString)) {
                 $connector = MailManager_Connector_Connector::connectorWithModel($mailBoxModel, '');
                 imap_append($connector->mBox, $connector->mBoxUrl . $folderName, $mailString, "\\Seen");
             }
         }
     }
     return $status;
 }
function getcontent_week($id)
{
    global $adb;
    $query = 'select vtiger_emailtemplates.subject,vtiger_emailtemplates.body from vtiger_notificationscheduler inner join vtiger_emailtemplates on vtiger_emailtemplates.templateid=vtiger_notificationscheduler.notificationbody where schedulednotificationid=6';
    $result = $adb->pquery($query, array());
    $body = $adb->query_result($result, 0, 'body');
    $body = getMergedDescription($body, $id, "Contacts");
    $body = getMergedDescription($body, $id, "Users");
    $res_array["subject"] = $adb->query_result($result, 0, 'subject');
    $res_array["body"] = $body;
    return $res_array;
}
示例#8
0
 /**
  * Function sends mail
  */
 public function send()
 {
     $currentUserModel = Users_Record_Model::getCurrentUserModel();
     $rootDirectory = vglobal('root_directory');
     $mailer = Emails_Mailer_Model::getInstance();
     $mailer->IsHTML(true);
     $fromEmail = $this->getFromEmailAddress();
     $replyTo = $currentUserModel->get('email1');
     $userName = $currentUserModel->getName();
     // To eliminate the empty value of an array
     $toEmailInfo = array_filter($this->get('toemailinfo'));
     $attachments = $this->getAttachmentDetails();
     $status = false;
     // Merge Users module merge tags based on current user.
     $mergedDescription = getMergedDescription($this->get('description'), $currentUserModel->getId(), 'Users');
     foreach ($toEmailInfo as $id => $emails) {
         $parentModule = $this->getEntityType($id);
         $mailer->reinitialize();
         $mailer->ConfigSenderInfo($fromEmail, $userName, $replyTo);
         $old_mod_strings = vglobal('mod_strings');
         $currentLanguage = Vtiger_Language_Handler::getLanguage();
         $moduleLanguageStrings = Vtiger_Language_Handler::getModuleStringsFromFile($currentLanguage, $parentModule);
         vglobal('mod_strings', $moduleLanguageStrings['languageStrings']);
         if ($parentModule != 'Users') {
             // Apply merge for non-Users module merge tags.
             $description = getMergedDescription($mergedDescription, $id, $parentModule);
         } else {
             // Re-merge the description for user tags based on actual user.
             $description = getMergedDescription($this->get('description'), $id, 'Users');
         }
         vglobal('mod_strings', $old_mod_strings);
         if (strpos($description, '$logo$')) {
             $description = str_replace('$logo$', "<img src='cid:logo' />", $description);
             $logo = true;
         }
         foreach ($emails as $email) {
             $mailer->Body = $this->getTrackImageDetails($id, $this->isEmailTrackEnabled());
             $mailer->Body .= $description;
             $mailer->Signature = str_replace(array('\\r\\n', '\\n'), '<br>', $currentUserModel->get('signature'));
             if ($mailer->Signature != '') {
                 $mailer->Body .= decode_html($mailer->Signature);
             }
             $mailer->Subject = $this->get('subject');
             $mailer->AddAddress($email);
             //Adding attachments to mail
             if (is_array($attachments)) {
                 foreach ($attachments as $attachment) {
                     $fileNameWithPath = $rootDirectory . $attachment['path'] . $attachment['fileid'] . "_" . $attachment['attachment'];
                     if (is_file($fileNameWithPath)) {
                         $mailer->AddAttachment($fileNameWithPath, $attachment['attachment']);
                     }
                 }
             }
             if ($logo) {
                 //While sending email template and which has '$logo$' then it should replace with company logo
                 $mailer->AddEmbeddedImage(vimage_path('logo_mail.jpg'), 'logo', 'logo.jpg', 'base64', 'image/jpg');
             }
             $ccs = array_filter(explode(',', $this->get('ccmail')));
             $bccs = array_filter(explode(',', $this->get('bccmail')));
             if (!empty($ccs)) {
                 foreach ($ccs as $cc) {
                     $mailer->AddCC($cc);
                 }
             }
             if (!empty($bccs)) {
                 foreach ($bccs as $bcc) {
                     $mailer->AddBCC($bcc);
                 }
             }
         }
         $status = $mailer->Send(true);
         if (!$status) {
             $status = $mailer->getError();
         }
     }
     return $status;
 }