Exemplo n.º 1
1
 /**
  * @see ViewQuickcreate::display()
  */
 public function display()
 {
     $userPref = $GLOBALS['current_user']->getPreference('email_link_type');
     $defaultPref = $GLOBALS['sugar_config']['email_default_client'];
     if ($userPref != '') {
         $client = $userPref;
     } else {
         $client = $defaultPref;
     }
     if ($client == 'sugar') {
         $eUi = new EmailUI();
         if (!empty($this->bean->id) && !in_array($this->bean->object_name, array('EmailMan'))) {
             $fullComposeUrl = "index.php?module=Emails&action=Compose&parent_id={$this->bean->id}&parent_type={$this->bean->module_dir}";
             $composeData = array('parent_id' => $this->bean->id, 'parent_type' => $this->bean->module_dir);
         } else {
             $fullComposeUrl = "index.php?module=Emails&action=Compose";
             $composeData = array('parent_id' => '', 'parent_type' => '');
         }
         $j_quickComposeOptions = $eUi->generateComposePackageForQuickCreate($composeData, $fullComposeUrl);
         $json_obj = getJSONobj();
         $opts = $json_obj->decode($j_quickComposeOptions);
         $opts['menu_id'] = 'dccontent';
         $ss = new Sugar_Smarty();
         $ss->assign('json_output', $json_obj->encode($opts));
         $ss->display('modules/Emails/templates/dceMenuQuickCreate.tpl');
     } else {
         $emailAddress = '';
         if (!empty($this->bean->id) && !in_array($this->bean->object_name, array('EmailMan')) && !is_null($this->bean->emailAddress)) {
             $emailAddress = $this->bean->emailAddress->getPrimaryAddress($this->bean);
         }
         echo "<script>document.location.href='mailto:{$emailAddress}';lastLoadedMenu=undefined;DCMenu.closeOverlay();</script>";
         die;
     }
 }
 function display($defines)
 {
     global $app_strings, $current_user, $sugar_config, $beanList, $beanFiles;
     $title = $app_strings['LBL_COMPOSE_EMAIL_BUTTON_TITLE'];
     //$accesskey = $app_strings['LBL_COMPOSE_EMAIL_BUTTON_KEY'];
     $value = $app_strings['LBL_COMPOSE_EMAIL_BUTTON_LABEL'];
     $parent_type = $defines['focus']->module_dir;
     $parent_id = $defines['focus']->id;
     //martin Bug 19660
     $userPref = $current_user->getPreference('email_link_type');
     $defaultPref = $sugar_config['email_default_client'];
     if ($userPref != '') {
         $client = $userPref;
     } else {
         $client = $defaultPref;
     }
     if ($client != 'sugar') {
         $bean = $defines['focus'];
         // awu: Not all beans have emailAddress property, we must account for this
         if (isset($bean->emailAddress)) {
             $to_addrs = $bean->emailAddress->getPrimaryAddress($bean);
             $button = "<input class='button' type='button'  value='{$value}'  id='" . $this->getWidgetId() . "'  name='" . preg_replace('[ ]', '', $value) . "'   title='{$title}' onclick=\"location.href='mailto:{$to_addrs}';return false;\" />";
         } else {
             $button = "<input class='button' type='button'  value='{$value}'  id='" . $this->getWidgetId() . "'  name='" . preg_replace('[ ]', '', $value) . "'  title='{$title}' onclick=\"location.href='mailto:';return false;\" />";
         }
     } else {
         //Generate the compose package for the quick create options.
         $composeData = array("parent_id" => $parent_id, "parent_type" => $parent_type);
         require_once 'modules/Emails/EmailUI.php';
         $eUi = new EmailUI();
         $j_quickComposeOptions = $eUi->generateComposePackageForQuickCreate($composeData, http_build_query($composeData), false, $defines['focus']);
         $button = "<input title='{$title}'  id='" . $this->getWidgetId() . "'  onclick='SUGAR.quickCompose.init({$j_quickComposeOptions});' class='button' type='submit' name='" . preg_replace('[ ]', '', $value) . "_button' value='{$value}' />";
     }
     return $button;
 }
 function display($defines)
 {
     global $app_strings, $current_user, $sugar_config, $beanList, $beanFiles;
     $title = $app_strings['LBL_COMPOSE_EMAIL_BUTTON_TITLE'];
     $accesskey = $app_strings['LBL_COMPOSE_EMAIL_BUTTON_KEY'];
     $value = $app_strings['LBL_COMPOSE_EMAIL_BUTTON_LABEL'];
     $parent_type = $defines['focus']->module_dir;
     $parent_id = $defines['focus']->id;
     //martin Bug 19660
     $userPref = $current_user->getPreference('email_link_type');
     $defaultPref = $sugar_config['email_default_client'];
     if ($userPref != '') {
         $client = $userPref;
     } else {
         $client = $defaultPref;
     }
     if ($client != 'sugar') {
         $class = $beanList[$parent_type];
         require_once $beanFiles[$class];
         $bean = new $class();
         $bean->retrieve($parent_id);
         // awu: Not all beans have emailAddress property, we must account for this
         if (isset($bean->emailAddress)) {
             $to_addrs = $bean->emailAddress->getPrimaryAddress($bean);
             $button = "<input class='button' type='button'  value='{$value}'  name='{$title}'  accesskey='{$accesskey}' title='{$title}' onclick=\"location.href='mailto:{$to_addrs}';return false;\" />";
         } else {
             $button = "<input class='button' type='button'  value='{$value}'  name='{$title}'  accesskey='{$accesskey}' title='{$title}' onclick=\"location.href='mailto:';return false;\" />";
         }
     } else {
         //Generate the compose package for the quick create options.
         $composeData = "parent_id={$parent_id}&parent_type={$parent_type}";
         require_once 'modules/Emails/EmailUI.php';
         $eUi = new EmailUI();
         $j_quickComposeOptions = $eUi->generateComposePackageForQuickCreateFromComposeUrl($composeData);
         $button = "<input title='{$title}' accesskey='{$accesskey}' onclick='SUGAR.quickCompose.init({$j_quickComposeOptions});' class='button' type='submit' name='button' value='{$value}'";
     }
     return $button;
 }
Exemplo n.º 4
0
function getQuotesRelatedData($bean)
{
    $return = array();
    $emailId = $_REQUEST['recordId'];
    require_once "modules/Emails/EmailUI.php";
    $email = new Email();
    $email->retrieve($emailId);
    $return['subject'] = $email->name;
    $return['body'] = from_html($email->description_html);
    $return['toAddress'] = $email->to_addrs;
    $ret = array();
    $ret['uid'] = $emailId;
    $ret = EmailUI::getDraftAttachments($ret);
    $return['attachments'] = $ret['attachments'];
    $return['email_id'] = $emailId;
    return $return;
}
Exemplo n.º 5
0
function getQuotesRelatedData($data)
{
    $return = array();
    $emailId = $data['recordId'];
    require_once "modules/Emails/EmailUI.php";
    $email = new Email();
    $email->retrieve($emailId);
    $return['subject'] = $email->name;
    $return['body'] = from_html($email->description_html);
    $return['toAddress'] = $email->to_addrs;
    $ret = array();
    $ret['uid'] = $emailId;
    $ret = EmailUI::getDraftAttachments($ret);
    $return['attachments'] = $ret['attachments'];
    $return['email_id'] = $emailId;
    $return['parent_type'] = $email->parent_type;
    $return['parent_id'] = $email->parent_id;
    $return['parent_name'] = '';
    if (isset($return['parent_type']) && !empty($return['parent_type']) && isset($return['parent_id']) && !empty($return['parent_id'])) {
        global $beanList;
        global $beanFiles;
        $class = $beanList[$return['parent_type']];
        require_once $beanFiles[$class];
        $bean = new $class();
        $bean->retrieve($return['parent_id']);
        if (isset($bean->full_name)) {
            $parentName = $bean->full_name;
        } elseif (isset($bean->name)) {
            $parentName = $bean->name;
        } else {
            $parentName = '';
        }
        $parentName = from_html($parentName);
        $return['parent_name'] = $parentName;
        $return['toAddress'] = from_html($bean->full_name) . " <" . from_html($bean->emailAddress->getPrimaryAddress($bean)) . ">";
    }
    return $return;
}
 function displayList(&$layout_def)
 {
     global $current_user;
     global $beanList;
     global $focus;
     global $sugar_config;
     global $locale;
     if (isset($layout_def['varname'])) {
         $key = strtoupper($layout_def['varname']);
     } else {
         $key = $this->_get_column_alias($layout_def);
         $key = strtoupper($key);
     }
     $value = $layout_def['fields'][$key];
     if (isset($_REQUEST['action'])) {
         $action = $_REQUEST['action'];
     } else {
         $action = '';
     }
     if (isset($_REQUEST['module'])) {
         $module = $_REQUEST['module'];
     } else {
         $module = '';
     }
     if (isset($_REQUEST['record'])) {
         $record = $_REQUEST['record'];
     } else {
         $record = '';
     }
     if (!empty($focus->name)) {
         $name = $focus->name;
     } else {
         if (!empty($focus->first_name) && !empty($focus->last_name)) {
             $name = $locale->getLocaleFormattedName($focus->first_name, $focus->last_name);
         }
         if (empty($name)) {
             $name = '*';
         }
     }
     $userPref = $current_user->getPreference('email_link_type');
     $defaultPref = $sugar_config['email_default_client'];
     if ($userPref != '') {
         $client = $userPref;
     } else {
         $client = $defaultPref;
     }
     if ($client == 'sugar') {
         $fullComposeUrl = 'load_id=' . $layout_def['fields']['ID'] . '&load_module=' . $this->layout_manager->defs['module_name'] . '&parent_type=' . $this->layout_manager->defs['module_name'] . '&parent_id=' . $layout_def['fields']['ID'];
         if (isset($layout_def['fields']['FULL_NAME'])) {
             $fullComposeUrl .= '&parent_name=' . urlencode($layout_def['fields']['FULL_NAME']);
         }
         $fullComposeUrl .= '&return_module=' . $module . '&return_action=' . $action . '&return_id=' . $record;
         require_once 'modules/Emails/EmailUI.php';
         $eUi = new EmailUI();
         $j_quickComposeOptions = $eUi->generateComposePackageForQuickCreateFromComposeUrl($fullComposeUrl);
         $link = "<a href='javascript:void(0);' onclick='SUGAR.quickCompose.init({$j_quickComposeOptions});'>";
     } else {
         $link = '<a href="mailto:' . $value . '" >';
     }
     return $link . $value . '</a>';
 }
Exemplo n.º 7
0
 /**
  * Test to ensure that whenever the inboud folder is deleted, it will be created for a user
  * and the parent_id for the other folders will be updated accordingly.
  *
  */
 public function testCreationOnDeletedInboundFolder()
 {
     $this->createNewSugarFolder();
     // Call preflightUser() to re-create all folders
     $emailUI = new EmailUI();
     $emailUI->preflightUser($GLOBALS['current_user']);
     $error_message = "Unable to get user folders";
     $rootNode = new ExtNode('', '');
     // Delete one folder type
     $GLOBALS['db']->query("DELETE FROM folders WHERE folder_type = 'inbound' AND created_by='{$GLOBALS['current_user']->id}'");
     // Retrieve folders
     $ret = $this->folder->getUserFolders($rootNode, "", $GLOBALS['current_user'], true);
     $this->assertEquals(0, count($ret), $error_message);
     // Call preflightUser() to re-create missing folder
     $emailUI->preflightUser($GLOBALS['current_user']);
     // Retrieve folders
     $ret = $this->folder->getUserFolders($rootNode, "", $GLOBALS['current_user'], true);
     $this->assertEquals(1, count($ret));
     // Should contain all folders after preflightUser
     $folderTypes = array();
     foreach ($ret[0]['children'] as $p) {
         $folderTypes[] = $p['folder_type'];
     }
     $this->assertContains("draft", $folderTypes);
 }
 function displayList(&$layout_def)
 {
     global $current_user;
     global $beanList;
     global $focus;
     global $sugar_config;
     global $locale;
     if (isset($layout_def['varname'])) {
         $key = strtoupper($layout_def['varname']);
     } else {
         $key = $this->_get_column_alias($layout_def);
         $key = strtoupper($key);
     }
     $value = $layout_def['fields'][$key];
     if (isset($_REQUEST['action'])) {
         $action = $_REQUEST['action'];
     } else {
         $action = '';
     }
     if (isset($_REQUEST['module'])) {
         $module = $_REQUEST['module'];
     } else {
         $module = '';
     }
     if (isset($_REQUEST['record'])) {
         $record = $_REQUEST['record'];
     } else {
         $record = '';
     }
     if (!empty($focus->name)) {
         $name = $focus->name;
     } else {
         if (!empty($focus->first_name) && !empty($focus->last_name)) {
             $name = $locale->formatName($focus);
         }
         if (empty($name)) {
             $name = '*';
         }
     }
     $userPref = $current_user->getPreference('email_link_type');
     $defaultPref = $sugar_config['email_default_client'];
     if ($userPref != '') {
         $client = $userPref;
     } else {
         $client = $defaultPref;
     }
     if ($client == 'sugar') {
         $composeData = array('load_id' => $layout_def['fields']['ID'], 'load_module' => $this->layout_manager->defs['module_name'], 'parent_type' => $this->layout_manager->defs['module_name'], 'parent_id' => $layout_def['fields']['ID'], 'return_module' => $module, 'return_action' => $action, 'return_id' => $record);
         if (isset($layout_def['fields']['FULL_NAME'])) {
             $composeData['parent_name'] = $layout_def['fields']['FULL_NAME'];
             $composeData['to_email_addrs'] = sprintf("%s <%s>", $layout_def['fields']['FULL_NAME'], $layout_def['fields']['EMAIL1']);
         } else {
             $composeData['to_email_addrs'] = $layout_def['fields']['EMAIL1'];
         }
         require_once 'modules/Emails/EmailUI.php';
         $eUi = new EmailUI();
         $j_quickComposeOptions = $eUi->generateComposePackageForQuickCreate($composeData, http_build_query($composeData), true);
         $link = "<a href='javascript:void(0);' onclick='SUGAR.quickCompose.init({$j_quickComposeOptions});'>";
     } else {
         $link = '<a href="mailto:' . $value . '" >';
     }
     return $link . $value . '</a>';
 }
Exemplo n.º 9
0
     $_REQUEST['record'] = $_REQUEST['folderId'];
     $ret = array();
     $ret['folderId'] = $email->et->folder->id;
     $ret['folderName'] = $email->et->folder->name;
     $ret['parentFolderId'] = $email->et->folder->parent_folder;
     require_once 'include/SugarFields/Fields/Teamset/EmailSugarFieldTeamsetCollection.php';
     $teamSetField = new EmailSugarFieldTeamsetCollection($email->et->folder, $ie->field_defs, "get_non_private_teams_array", 'EditViewGroupFolder');
     $sqs_objects = $teamSetField->createQuickSearchCode(true);
     //$quicksearch_js = '<script type="text/javascript" language="javascript">sqs_objects = ' . $json->encode($sqs_objects) . '</script>';
     $code = $teamSetField->get_code();
     $ret['team_id'] = $code . $sqs_objects;
     $out = $json->encode($ret);
     echo $out;
     break;
 case "retrieveTeamsInfoForSettings":
     $emailUI = new EmailUI();
     $returnArray = $emailUI->retrieveTeamInfoForSettingsUI();
     $out = $json->encode($returnArray);
     echo $out;
     break;
 case "rebuildFolders":
     $GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: rebuildFolders");
     $tree = $email->et->getMailboxNodes(false);
     $return = $tree->generateNodesRaw();
     $out = $json->encode($return);
     echo $out;
     break;
 case "setFolderOpenState":
     $GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: setFolderOpenState");
     $email->et->saveFolderOpenState($_REQUEST['focusFolder'], $_REQUEST['focusFolderOpen']);
     break;
Exemplo n.º 10
0
 /**
  * Special handler for POP3 boxes.  Standard IMAP commands are useless.
  * This will fetch only partial emails for POP3 and hence needs to be call again and again based on status it returns
  */
 function pop3_checkPartialEmail($synch = false)
 {
     require_once 'include/utils/array_utils.php';
     global $current_user;
     global $sugar_config;
     $cacheDataExists = false;
     $diff = array();
     $results = array();
     $cacheFilePath = clean_path("{$this->EmailCachePath}/{$this->id}/folders/MsgNOToUIDLData.php");
     if (file_exists($cacheFilePath)) {
         $cacheDataExists = true;
         if ($fh = @fopen($cacheFilePath, "rb")) {
             $data = "";
             $chunksize = 1 * (1024 * 1024);
             // how many bytes per chunk
             while (!feof($fh)) {
                 $buf = fgets($fh, $chunksize);
                 // 8kb max buffer - shouldn't be more than 80 chars via pop3...
                 $data = $data . $buf;
                 flush();
             }
             // while
             fclose($fh);
             $diff = unserialize($data);
             if (!empty($diff)) {
                 if (count($diff) > 50) {
                     $newDiff = array_slice($diff, 50, count($diff), true);
                 } else {
                     $newDiff = array();
                 }
                 $results = array_slice(array_keys($diff), 0, 50);
                 $data = serialize($newDiff);
                 if ($fh = @fopen($cacheFilePath, "w")) {
                     fputs($fh, $data);
                     fclose($fh);
                 }
                 // if
             }
         }
         // if
     }
     // if
     if (!$cacheDataExists) {
         if ($synch) {
             $this->deletePop3Cache();
         }
         $UIDLs = $this->pop3_getUIDL();
         if (count($UIDLs) > 0) {
             // get cached UIDLs
             $cacheUIDLs = $this->pop3_getCacheUidls();
             // new email cache values we should deal with
             $diff = array_diff_assoc($UIDLs, $cacheUIDLs);
             $diff = $this->pop3_shiftCache($diff, $cacheUIDLs);
             require_once 'modules/Emails/EmailUI.php';
             EmailUI::preflightEmailCache("{$this->EmailCachePath}/{$this->id}");
             if (count($diff) > 50) {
                 $newDiff = array_slice($diff, 50, count($diff), true);
             } else {
                 $newDiff = array();
             }
             $results = array_slice(array_keys($diff), 0, 50);
             $data = serialize($newDiff);
             if ($fh = @fopen($cacheFilePath, "w")) {
                 fputs($fh, $data);
                 fclose($fh);
             }
             // if
         } else {
             $GLOBALS['log']->debug("*** INBOUNDEMAIL: could not open socket connection to POP3 server");
             return "could not open socket connection to POP3 server";
         }
         // else
     }
     // if
     // build up msgNo request
     if (count($diff) > 0) {
         // remove dirty cache entries
         $startingNo = 0;
         if (isset($_REQUEST['currentCount']) && $_REQUEST['currentCount'] > -1) {
             $startingNo = $_REQUEST['currentCount'];
         }
         $this->mailbox = 'INBOX';
         $this->connectMailserver();
         //$searchResults = array_keys($diff);
         //$fetchedOverviews = array();
         //$chunkArraySerachResults = array_chunk($searchResults, 50);
         $concatResults = implode(",", $results);
         $GLOBALS['log']->info('$$$$ ' . $concatResults);
         $GLOBALS['log']->info("[EMAIL] Start POP3 fetch overview on mailbox [{$this->mailbox}] for user [{$current_user->user_name}] on 50 data");
         $fetchedOverviews = imap_fetch_overview($this->conn, $concatResults);
         $GLOBALS['log']->info("[EMAIL] End POP3 fetch overview on mailbox [{$this->mailbox}] for user [{$current_user->user_name}] on " . sizeof($fetchedOverviews) . " data");
         // clean up cache entry
         foreach ($fetchedOverviews as $k => $overview) {
             $overview->message_id = trim($diff[$overview->msgno]);
             $fetchedOverviews[$k] = $overview;
         }
         $GLOBALS['log']->info("[EMAIL] Start updating overview cache for pop3 mailbox [{$this->mailbox}] for user [{$current_user->user_name}]");
         $this->updateOverviewCacheFile($fetchedOverviews);
         $GLOBALS['log']->info("[EMAIL] Start updating overview cache for pop3 mailbox [{$this->mailbox}] for user [{$current_user->user_name}]");
         return array('status' => "In Progress", 'mbox' => $this->mailbox, 'count' => count($results) + $startingNo, 'totalcount' => count($diff), 'ieid' => $this->id);
     }
     // if
     unlink($cacheFilePath);
     return array('status' => "done");
 }
Exemplo n.º 11
0
 function display()
 {
     global $mod_strings, $app_strings, $app_list_strings, $sugar_config, $current_user;
     $this->ss->assign("MOD", $mod_strings);
     $this->ss->assign("APP_LIST", $app_list_strings);
     // Sync info from tilkee server
     $this->bean->sync_from_API('update_connexions');
     $button_array = $this->dv->defs['templateMeta']['form']['buttons'];
     $new_button_array = array();
     if ($this->bean->archived === 'true') {
         $new_button_array[] = $button_array[0];
         // DELETED
     }
     $new_button_array[] = $button_array[1];
     // SEND EMAIL
     $new_button_array[] = $button_array[2];
     // COPY URL
     $new_button_array[] = $button_array[3];
     // ARCHIVED/WON
     $new_button_array[] = $button_array[4];
     // ARCHIVED/LOST
     $new_button_array[] = $button_array[5];
     // ARCHIVED
     $this->dv->defs['templateMeta']['form']['buttons'] = $new_button_array;
     // BUILD SEND MAIL BUTTON
     $userPref = $current_user->getPreference('email_link_type');
     $defaultPref = $sugar_config['email_default_client'];
     if ($userPref != '') {
         $client = $userPref;
     } else {
         $client = $defaultPref;
     }
     $title_button = $mod_strings['LBL_SEND_MAIL_TITLE'];
     $value_button = $mod_strings['LBL_SEND_MAIL_VALUE'];
     $parent_id = '';
     $parent_type = '';
     $parent_name = '';
     $button = '';
     // Links to a Contact
     if ($this->bean->contacts_id != '') {
         $parent_id = $this->bean->contacts_id;
         $parent_name = $this->bean->contacts_name;
         $parent_type = 'Contacts';
     }
     // Links to a Lead
     if ($this->bean->leads_id != '') {
         $parent_id = $this->bean->leads_id;
         $parent_name = $this->bean->leads_name;
         $parent_type = 'Leads';
     }
     // Build Send mail action depends on user prefs
     if ($parent_type != '') {
         if ($client != 'sugar') {
             if (isset($this->bean->contact_email)) {
                 $to_addrs = $this->bean->contact_email;
                 $button = "<input class='button' type='button'  value='{$value_button}'  id=''  name=''   title='{$title_button}' onclick=\"location.href='mailto:{$to_addrs}';return false;\" />";
             } else {
                 $button = "<input class='button' type='button'  value='{$value_button}'  id=''  name=''  title='{$title_button}' onclick=\"location.href='mailto:';return false;\" />";
             }
         } else {
             //Generate the compose package for the quick create options.
             $composeData = array("to_email_addrs" => $this->bean->contact_email, "parent_id" => $parent_id, "parent_type" => $parent_type, "parent_name" => $parent_name);
             if (!empty($this->bean->tilk_url)) {
                 $composeData['body'] = "<a href='" . $this->bean->tilk_url . "'>" . $this->bean->tilk_url . "</a>";
             }
             require_once 'modules/Emails/EmailUI.php';
             $eUi = new EmailUI();
             $j_quickComposeOptions = $eUi->generateComposePackageForQuickCreate($composeData, http_build_query($composeData), false);
             $button = "<input title='{$title_button}'  id=''  onclick='SUGAR.quickCompose.init({$j_quickComposeOptions});' class='button' type='submit' name='_button' value='{$value_button}' />";
         }
     }
     $this->ss->assign("SEND_EMAIL_BUTTON", $button);
     // BUILD COPY TO CLIPBOARD BUTTON
     $button_copy = "<button id='copy-button' data-clipboard-text='" . $this->bean->tilk_url . "' title='Click to copy me.'>" . $mod_strings['LBL_COPY_VALUE'] . "</button>";
     $this->ss->assign("COPY_TILK_URL", $button_copy);
     parent::display();
 }
Exemplo n.º 12
0
 /**
  * Clears the user's attachment cache directory
  *
  * @param ServiceBase $api The service base
  * @param array $args The request args
  * @return bool
  * @throws SugarApiExceptionRequestMethodFailure
  */
 public function clearUserCache($api, $args)
 {
     $em = new EmailUI();
     $em->preflightUserCache();
     return true;
 }
Exemplo n.º 13
0
function getQuotesRelatedData($bean, $data)
{
    $return = array();
    $emailId = $data['recordId'];
    require_once "modules/Emails/EmailUI.php";
    $email = BeanFactory::getBean('Emails', $emailId);
    $return['subject'] = $email->name;
    $return['body'] = from_html($email->description_html);
    $return['toAddress'] = $email->to_addrs;
    $ret = array();
    $ret['uid'] = $emailId;
    $ret = EmailUI::getDraftAttachments($ret);
    $return['attachments'] = $ret['attachments'];
    $return['email_id'] = $emailId;
    return $return;
}
 function displayList(&$layout_def)
 {
     global $current_user;
     global $beanList;
     global $focus;
     global $sugar_config;
     global $locale;
     global $mod_strings;
     if (isset($layout_def['varname'])) {
         $key = strtoupper($layout_def['varname']);
     } else {
         $key = $this->_get_column_alias($layout_def);
         $key = strtoupper($key);
     }
     $value = $layout_def['fields'][$key];
     if (isset($_REQUEST['action'])) {
         $action = $_REQUEST['action'];
     } else {
         $action = '';
     }
     if (isset($_REQUEST['module'])) {
         $module = $_REQUEST['module'];
     } else {
         $module = '';
     }
     if (isset($_REQUEST['record'])) {
         $record = $_REQUEST['record'];
     } else {
         $record = '';
     }
     if (!empty($focus->name)) {
         $name = $focus->name;
     }
     $userPref = $current_user->getPreference('email_link_type');
     $defaultPref = $sugar_config['email_default_client'];
     if ($userPref != '') {
         $client = $userPref;
     } else {
         $client = $defaultPref;
     }
     if ($client == 'sugar') {
         $composeData = array('load_id' => $layout_def['fields']['ID'], 'load_module' => $this->layout_manager->defs['module_name'], 'return_module' => $module, 'return_action' => $action, 'return_id' => $record);
         if (!empty($layout_def['fields']['CONTACTS_NAME'])) {
             $composeData['parent_name'] = $layout_def['fields']['CONTACTS_NAME'];
             $composeData['parent_id'] = $layout_def['fields']['CONTACTS_ID'];
             $composeData['parent_type'] = 'Contacts';
         }
         if (!empty($layout_def['fields']['LEADS_NAME'])) {
             $composeData['parent_name'] = $layout_def['fields']['LEADS_NAME'];
             $composeData['parent_id'] = $layout_def['fields']['LEADS_ID'];
             $composeData['parent_type'] = 'Leads';
         }
         $composeData['to_email_addrs'] = $layout_def['fields']['CONTACT_EMAIL'];
         if (!empty($layout_def['fields']['TILK_URL'])) {
             $composeData['body'] = "<a href='" . $layout_def['fields']['TILK_URL'] . "'>" . $layout_def['fields']['TILK_URL'] . "</a>";
         }
         require_once 'modules/Emails/EmailUI.php';
         $eUi = new EmailUI();
         $j_quickComposeOptions = $eUi->generateComposePackageForQuickCreate($composeData, http_build_query($composeData), true);
         $link = "<a onclick='SUGAR.quickCompose.init({$j_quickComposeOptions});'>";
     } else {
         $link = '<a href="mailto:' . $value . '" >';
     }
     return $link . $mod_strings['LBL_SEND_MAIL_TITLE'] . '</a>';
 }
Exemplo n.º 15
0
/**
 * Job 1
 */
function pollMonitoredInboxes()
{
    $_bck_up = array('team_id' => $GLOBALS['current_user']->team_id, 'team_set_id' => $GLOBALS['current_user']->team_set_id);
    Log::info('----->Scheduler fired job of type pollMonitoredInboxes()');
    global $dictionary;
    global $app_strings;
    require_once 'modules/Emails/EmailUI.php';
    $ie = new InboundEmail();
    $emailUI = new EmailUI();
    $r = $ie->db->query('SELECT id, name FROM inbound_email WHERE is_personal = 0 AND deleted=0 AND status=\'Active\' AND mailbox_type != \'bounce\'');
    Log::debug('Just got Result from get all Inbounds of Inbound Emails');
    while ($a = $ie->db->fetchByAssoc($r)) {
        Log::debug('In while loop of Inbound Emails');
        $ieX = new InboundEmail();
        $ieX->retrieve($a['id']);
        $GLOBALS['current_user']->team_id = $ieX->team_id;
        $GLOBALS['current_user']->team_set_id = $ieX->team_set_id;
        $mailboxes = $ieX->mailboxarray;
        foreach ($mailboxes as $mbox) {
            $ieX->mailbox = $mbox;
            $newMsgs = array();
            $msgNoToUIDL = array();
            $connectToMailServer = false;
            if ($ieX->isPop3Protocol()) {
                $msgNoToUIDL = $ieX->getPop3NewMessagesToDownloadForCron();
                // get all the keys which are msgnos;
                $newMsgs = array_keys($msgNoToUIDL);
            }
            if ($ieX->connectMailserver() == 'true') {
                $connectToMailServer = true;
            }
            // if
            Log::debug('Trying to connect to mailserver for [ ' . $a['name'] . ' ]');
            if ($connectToMailServer) {
                Log::debug('Connected to mailserver');
                if (!$ieX->isPop3Protocol()) {
                    $newMsgs = $ieX->getNewMessageIds();
                }
                if (is_array($newMsgs)) {
                    $current = 1;
                    $total = count($newMsgs);
                    require_once "include/SugarFolders/SugarFolders.php";
                    $sugarFolder = new SugarFolder();
                    $groupFolderId = $ieX->groupfolder_id;
                    $isGroupFolderExists = false;
                    $users = array();
                    if ($groupFolderId != null && $groupFolderId != "") {
                        $sugarFolder->retrieve($groupFolderId);
                        $isGroupFolderExists = true;
                    }
                    // if
                    $messagesToDelete = array();
                    if ($ieX->isMailBoxTypeCreateCase()) {
                        $users[] = $sugarFolder->assign_to_id;
                        $distributionMethod = $ieX->get_stored_options("distrib_method", "");
                        if ($distributionMethod != 'roundRobin') {
                            $counts = $emailUI->getAssignedEmailsCountForUsers($users);
                        } else {
                            $lastRobin = $emailUI->getLastRobin($ieX);
                        }
                        Log::debug('distribution method id [ ' . $distributionMethod . ' ]');
                    }
                    foreach ($newMsgs as $k => $msgNo) {
                        $uid = $msgNo;
                        if ($ieX->isPop3Protocol()) {
                            $uid = $msgNoToUIDL[$msgNo];
                        } else {
                            $uid = imap_uid($ieX->conn, $msgNo);
                        }
                        // else
                        if ($isGroupFolderExists) {
                            if ($ieX->importOneEmail($msgNo, $uid)) {
                                // add to folder
                                $sugarFolder->addBean($ieX->email);
                                if ($ieX->isPop3Protocol()) {
                                    $messagesToDelete[] = $msgNo;
                                } else {
                                    $messagesToDelete[] = $uid;
                                }
                                if ($ieX->isMailBoxTypeCreateCase()) {
                                    $userId = "";
                                    if ($distributionMethod == 'roundRobin') {
                                        if (sizeof($users) == 1) {
                                            $userId = $users[0];
                                            $lastRobin = $users[0];
                                        } else {
                                            $userIdsKeys = array_flip($users);
                                            // now keys are values
                                            $thisRobinKey = $userIdsKeys[$lastRobin] + 1;
                                            if (!empty($users[$thisRobinKey])) {
                                                $userId = $users[$thisRobinKey];
                                                $lastRobin = $users[$thisRobinKey];
                                            } else {
                                                $userId = $users[0];
                                                $lastRobin = $users[0];
                                            }
                                        }
                                        // else
                                    } else {
                                        if (sizeof($users) == 1) {
                                            foreach ($users as $k => $value) {
                                                $userId = $value;
                                            }
                                            // foreach
                                        } else {
                                            asort($counts);
                                            // lowest to highest
                                            $countsKeys = array_flip($counts);
                                            // keys now the 'count of items'
                                            $leastBusy = array_shift($countsKeys);
                                            // user id of lowest item count
                                            $userId = $leastBusy;
                                            $counts[$leastBusy] = $counts[$leastBusy] + 1;
                                        }
                                    }
                                    // else
                                    Log::debug('userId [ ' . $userId . ' ]');
                                    $ieX->handleCreateCase($ieX->email, $userId);
                                }
                                // if
                            }
                            // if
                        } else {
                            if ($ieX->isAutoImport()) {
                                $ieX->importOneEmail($msgNo, $uid);
                            } else {
                                /*If the group folder doesn't exist then download only those messages
                                	 which has caseid in message*/
                                $ieX->getMessagesInEmailCache($msgNo, $uid);
                                $email = new Email();
                                $header = imap_headerinfo($ieX->conn, $msgNo);
                                $email->name = $ieX->handleMimeHeaderDecode($header->subject);
                                $email->from_addr = $ieX->convertImapToSugarEmailAddress($header->from);
                                $email->reply_to_email = $ieX->convertImapToSugarEmailAddress($header->reply_to);
                                if (!empty($email->reply_to_email)) {
                                    $contactAddr = $email->reply_to_email;
                                } else {
                                    $contactAddr = $email->from_addr;
                                }
                                $mailBoxType = $ieX->mailbox_type;
                                $ieX->handleAutoresponse($email, $contactAddr);
                            }
                            // else
                        }
                        // else
                        Log::debug('***** On message [ ' . $current . ' of ' . $total . ' ] *****');
                        $current++;
                    }
                    // foreach
                    // update Inbound Account with last robin
                    if ($ieX->isMailBoxTypeCreateCase() && $distributionMethod == 'roundRobin') {
                        $emailUI->setLastRobin($ieX, $lastRobin);
                    }
                    // if
                }
                // if
                if ($isGroupFolderExists) {
                    $leaveMessagesOnMailServer = $ieX->get_stored_options("leaveMessagesOnMailServer", 0);
                    if (!$leaveMessagesOnMailServer) {
                        if ($ieX->isPop3Protocol()) {
                            $ieX->deleteMessageOnMailServerForPop3(implode(",", $messagesToDelete));
                        } else {
                            $ieX->deleteMessageOnMailServer(implode($app_strings['LBL_EMAIL_DELIMITER'], $messagesToDelete));
                        }
                    }
                }
            } else {
                Log::fatal("SCHEDULERS: could not get an IMAP connection resource for ID [ {$a['id']} ]. Skipping mailbox [ {$a['name']} ].");
                // cn: bug 9171 - continue while
            }
            // else
        }
        // foreach
        imap_expunge($ieX->conn);
        imap_close($ieX->conn, CL_EXPUNGE);
    }
    // while
    $GLOBALS['current_user']->team_id = $_bck_up['team_id'];
    $GLOBALS['current_user']->team_set_id = $_bck_up['team_set_id'];
    return true;
}
Exemplo n.º 16
0
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 *
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
 ********************************************************************************/
/**
 * Render the quick compose frame needed by the UI.  The data is returned as a JSOn
 * object and consumed by the client in an ajax call.
 */
require_once 'modules/Emails/EmailUI.php';
$em = new EmailUI();
$out = $em->displayQuickComposeEmailFrame();
@ob_end_clean();
ob_start();
echo $out;
ob_end_flush();
Exemplo n.º 17
0
 /**
  * Test retreiving a list of emails for a particular folder.
  *
  */
 function testGetListItemsForEmailXML()
 {
     //Create the my Emails Folder
     $GLOBALS['mod_strings'] = return_module_language($GLOBALS['current_language'], "Emails");
     require_once 'modules/Emails/EmailUI.php';
     $emailUI = new EmailUI();
     $emailUI->preflightUser($GLOBALS['current_user']);
     $error_message = "Unable to get list items for email.";
     $rootNode = new ExtNode('', '');
     $folderOpenState = "";
     $ret = $this->folder->getUserFolders($rootNode, $folderOpenState, $GLOBALS['current_user'], true);
     $this->assertEquals(1, count($ret), $error_message);
     $folderID = $ret[0]['id'];
     //Create the Email Object
     $emailParams = array('status' => 'unread', 'assigned_user_id' => $GLOBALS['current_user']->id);
     $email = $this->_createEmailObject($emailParams);
     $this->emails[] = $email->id;
     //Add Email Object to My Email Folder
     $my_email = new SugarFolder();
     $my_email->retrieve($folderID);
     $my_email->addBean($email, $GLOBALS['current_user']);
     //Make sure the email was added to the folder.
     $emailExists = $my_email->checkEmailExistForFolder($email->id);
     $this->assertTrue($emailExists, $error_message);
     //Get the list of emails.
     $emailList = $my_email->getListItemsForEmailXML($folderID);
     $this->assertEquals($email->id, $emailList['out'][0]['uid'], $error_message);
 }
Exemplo n.º 18
0
 /**
  * returns opening <a href=xxxx for a contact, account, etc
  * cascades from User set preference to System-wide default
  * @return string	link
  * @param attribute the email addy
  * @param focus the parent bean
  * @param contact_id
  * @param return_module
  * @param return_action
  * @param return_id
  * @param class
  */
 function getEmailLink($attribute, &$focus, $contact_id = '', $ret_module = '', $ret_action = 'DetailView', $ret_id = '', $class = '')
 {
     $emailLink = '';
     global $sugar_config;
     if (!isset($sugar_config['email_default_client'])) {
         $this->setDefaultsInConfig();
     }
     $userPref = $this->getPreference('email_link_type');
     $defaultPref = $sugar_config['email_default_client'];
     if ($userPref != '') {
         $client = $userPref;
     } else {
         $client = $defaultPref;
     }
     if ($client == 'sugar') {
         $email = '';
         $to_addrs_ids = '';
         $to_addrs_names = '';
         $to_addrs_emails = '';
         $fullName = !empty($focus->name) ? $focus->name : '';
         if (!empty($focus->{$attribute})) {
             $email = $focus->{$attribute};
         }
         if (empty($ret_module)) {
             $ret_module = $focus->module_dir;
         }
         if (empty($ret_id)) {
             $ret_id = $focus->id;
         }
         if ($focus->object_name == 'Contact') {
             // Bug #48555 Not User Name Format of User's locale.
             $focus->_create_proper_name_field();
             $fullName = $focus->name;
             $contact_id = $focus->id;
             $to_addrs_ids = $focus->id;
             $to_addrs_names = $fullName;
             $to_addrs_emails = $focus->email1;
         }
         $emailLinkUrl = 'contact_id=' . $contact_id . '&parent_type=' . $focus->module_dir . '&parent_id=' . $focus->id . '&parent_name=' . urlencode($fullName) . '&to_addrs_ids=' . $to_addrs_ids . '&to_addrs_names=' . urlencode($to_addrs_names) . '&to_addrs_emails=' . urlencode($to_addrs_emails) . '&to_email_addrs=' . urlencode($fullName . '&nbsp;&lt;' . $email . '&gt;') . '&return_module=' . $ret_module . '&return_action=' . $ret_action . '&return_id=' . $ret_id;
         //Generate the compose package for the quick create options.
         require_once 'modules/Emails/EmailUI.php';
         $eUi = new EmailUI();
         $j_quickComposeOptions = $eUi->generateComposePackageForQuickCreateFromComposeUrl($emailLinkUrl, true);
         $emailLink = "<a href='javascript:void(0);' onclick='SUGAR.quickCompose.init({$j_quickComposeOptions});' class='{$class}'>";
     } else {
         // straight mailto:
         $emailLink = '<a href="mailto:' . $focus->{$attribute} . '" class="' . $class . '">';
     }
     return $emailLink;
 }
Exemplo n.º 19
0
 public function _loadQuickCreateModules()
 {
     return parent::_loadQuickCreateModules();
 }