{$app_strings['LBL_EMAIL_CC']}:
|
{$ccs}
|
eoq;
}
echo $json->encode($out);
}
} else {
echo "error: no UID";
}
break;
case "getMultipleMessages":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: getMultipleMessages");
if(isset($_REQUEST['uid']) && !empty($_REQUEST['uid']) && isset($_REQUEST['ieId']) && !empty($_REQUEST['ieId'])) {
$exUids = explode(",", $_REQUEST['uid']);
$out = array();
foreach($exUids as $k => $uid) {
if($email->et->validCacheFileExists($_REQUEST['ieId'], 'messages', $_REQUEST['mbox'].$uid.".php")) {
$msg = $email->et->getCacheValue($_REQUEST['ieId'], 'messages', $_REQUEST['mbox'].$uid.".php", 'out');
} else {
$ie->retrieve($_REQUEST['ieId']);
$ie->mailbox = $_REQUEST['mbox'];
$ie->setEmailForDisplay($uid, false, true);
$msg = $ie->displayOneEmail($uid, $_REQUEST['mbox']);
$email->et->writeCacheFile('out', $msg, $_REQUEST['ieId'], 'messages', "{$_REQUEST['mbox']}{$uid}.php");
}
$out[] = $msg;
}
echo $json->encode($out);
} else {
echo "error: no UID";
}
break;
case "getMultipleMessagesFromSugar":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: getMultipleMessagesFromSugar");
if(isset($_REQUEST['uid']) && !empty($_REQUEST['uid'])) {
$exIds = explode(",", $_REQUEST['uid']);
$out = array();
foreach($exIds as $id) {
$e = new Email();
$e->retrieve($id);
$e->description_html = from_html($e->description_html);
$ie->email = $e;
$out[] = $ie->displayOneEmail($id, $_REQUEST['mbox']);
}
echo $json->encode($out);
}
break;
//// END MESSAGE HANDLING
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//// LIST VIEW
case "getMessageCount":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: getMessageCount");
$out = $ie->getCacheCount($_REQUEST['mbox']);
echo $json->encode($out);
break;
case "getMessageList":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: getMessageListJSON");
if(isset($_REQUEST['ieId']) && !empty($_REQUEST['ieId'])) {
// user view preferences
$email->et->saveListView($_REQUEST['ieId'], $_REQUEST['mbox']);
// list output
$ie->retrieve($_REQUEST['ieId']);
if(isset($_REQUEST['start']) && isset($_REQUEST['limit'])) {
$page = ceil($_REQUEST['start'] / $_REQUEST['limit']) + 1;
} else {
$page = 1;
}
$list = $ie->displayFolderContents($_REQUEST['mbox'], $_REQUEST['forceRefresh'], $page);
$count = $ie->getCacheCount($_REQUEST['mbox']);
$unread = $ie->getCacheUnread($_REQUEST['mbox']);
$out = $email->et->jsonOuput($list, 'Email', $count, true, $unread);
@ob_end_clean();
ob_start();
echo $out;
ob_end_flush();
//die();
} else {
echo "error: no ieID";
}
break;
case "getMessageListSugarFolders":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: getMessageListSugarFoldersJSON");
if(isset($_REQUEST['ieId']) && !empty($_REQUEST['ieId'])) {
// user view preferences
$email->et->saveListView($_REQUEST['ieId'], "SUGAR.{$_REQUEST['mbox']}");
if(isset($_REQUEST['start']) && isset($_REQUEST['limit'])) {
$page = ceil($_REQUEST['start'] / $_REQUEST['limit']) + 1;
} else {
$page = 1;
}
if(!isset($_REQUEST['sort']) || !isset($_REQUEST['dir'])) {
$_REQUEST['sort'] = '';
$_REQUEST['dir'] = '';
}
$emailSettings = $current_user->getPreference('emailSettings', 'Emails');
// cn: default to a low number until user specifies otherwise
if(empty($emailSettings['showNumInList'])) {
$emailSettings['showNumInList'] = 20;
}
// jchi #9424, get sort and direction from user preference
$sort = 'date';
$direction = 'desc';
$sortSerial = $current_user->getPreference('folderSortOrder', 'Emails');
if(!empty($sortSerial) && !empty($_REQUEST['ieId']) && !empty($_REQUEST['mbox'])) {
$sortArray = unserialize($sortSerial);
$GLOBALS['log']->debug("********** EMAIL 2.0********** ary=".print_r($sortArray,true).' id='.$_REQUEST['ieId'].'; box='.$_REQUEST['mbox']);
$sort = $sortArray[$_REQUEST['ieId']][$_REQUEST['mbox']]['current']['sort'];
$direction = $sortArray[$_REQUEST['ieId']][$_REQUEST['mbox']]['current']['direction'];
}
//set sort and direction to user predference
if(!empty($_REQUEST['sort']) && !empty($_REQUEST['dir'])) {
$email->et->saveListViewSortOrder($_REQUEST['ieId'], $_REQUEST['mbox'], $_REQUEST['sort'], $_REQUEST['dir']);
$sort = $_REQUEST['sort'];
$direction = $_REQUEST['dir'];
} else {
$_REQUEST['sort'] = '';
$_REQUEST['dir'] = '';
}
//end
$metalist = $email->et->folder->getListItemsForEmailXML($_REQUEST['ieId'], $page,
$emailSettings['showNumInList'], $sort, $direction);
$count = $email->et->folder->getCountItems($_REQUEST['ieId']);
$unread = $email->et->folder->getCountUnread($_REQUEST['ieId']);
$out = $email->et->jsonOuput($metalist, 'Email', $count, false, $unread);
@ob_end_clean();
ob_start();
echo $out;
ob_end_flush();
} else {
echo "error: no ieID";
}
break;
//// END LIST VIEW
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//// FOLDER ACTIONS
case "emptyTrash":
$email->et->emptyTrash($ie);
break;
case "clearInboundAccountCache":
$email->et->clearInboundAccountCache($_REQUEST['ieId']);
break;
case "updateSubscriptions":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: updateSubscriptions");
if(isset($_REQUEST['subscriptions']) && !empty($_REQUEST['subscriptions']))
{
$subs = explode("::", $_REQUEST['subscriptions']);
$childrenSubs = array();
//Find all children of the group folder subscribed to and add
//them to the list of folders to show.
foreach ($subs as $singleSub)
$email->et->folder->findAllChildren($singleSub, $childrenSubs);
$subs = array_merge($subs, $childrenSubs);
$email->et->folder->setSubscriptions($subs);
}
elseif(empty($_REQUEST['subscriptions'])) {
$email->et->folder->clearSubscriptions();
}
break;
case "refreshSugarFolders":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: refreshSugarFolders");
$rootNode = new ExtNode('','');
$folderOpenState = $current_user->getPreference('folderOpenState', 'Emails');
$folderOpenState = (empty($folderOpenState)) ? "" : $folderOpenState;
$ret = $email->et->folder->getUserFolders($rootNode, unserialize($folderOpenState), $current_user, true);
$out = $json->encode($ret);
echo $out;
break;
case "getFoldersForSettings":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: getFoldersForSettings");
$ret = $email->et->folder->getFoldersForSettings($current_user);
$out = $json->encode($ret);
echo $out;
break;
case "moveEmails":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: moveEmails");
$ie->moveEmails($_REQUEST['sourceIeId'], $_REQUEST['sourceFolder'], $_REQUEST['destinationIeId'], $_REQUEST['destinationFolder'], $_REQUEST['emailUids']);
break;
case "saveNewFolder":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: saveNewFolder");
if(isset($_REQUEST['folderType']) && !empty($_REQUEST['folderType'])) {
switch($_REQUEST['folderType']) {
case "sugar":
$ret = $email->et->saveNewFolder($_REQUEST['nodeLabel'], $_REQUEST['parentId']);
$out = $json->encode($ret);
echo $out;
break;
case "imap":
$ie->retrieve($_REQUEST['ieId']);
$ie->connectMailserver();
$ie->saveNewFolder($_REQUEST['newFolderName'], $_REQUEST['mbox']);
break;
}
} else {
echo "NOOP: no folderType defined";
}
break;
case "setFolderViewSelection": // flows into next case statement
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: setFolderViewSelection");
$viewFolders = $_REQUEST['ieIdShow'];
$current_user->setPreference('showFolders', base64_encode(serialize($viewFolders)), '', 'Emails');
$tree = $email->et->getMailboxNodes(false);
$return = $tree->generateNodesRaw();
$out = $json->encode($return);
echo $out;
break;
case "deleteFolder":
$v = $app_strings['LBL_NONE'];
$return = array();
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: deleteFolder");
if(isset($_REQUEST['folderType']) && !empty($_REQUEST['folderType'])) {
switch($_REQUEST['folderType']) {
case "sugar":
$status = $email->et->folder->deleteChildrenCascade($_REQUEST['folder_id']);
if ($status == true) {
$return['status'] = true;
$return['folder_id'] = $_REQUEST['folder_id'];
} else {
$return['status'] = false;
$return['errorMessage'] = $app_strings['LBL_EMAIL_ERROR_DELETE_GROUP_FOLDER'];
}
break;
case "imap":
$ie->retrieve($_REQUEST['ieId']);
$ie->connectMailserver();
$returnArray = $ie->deleteFolder($_REQUEST['mbox']);
$status = $returnArray['status'];
$errorMessage = $returnArray['errorMessage'];
if ($status == true) {
$return['status'] = true;
$return['mbox'] = $_REQUEST['mbox'];
$return['ieId'] = $_REQUEST['ieId'];
} else {
$return['status'] = false;
$return['errorMessage'] = $errorMessage;
}
break;
}
} else {
$return['status'] = false;
$return['errorMessage'] = "NOOP: no folderType defined";
}
$out = $json->encode($return);
echo $out;
break;
case "renameFolder":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: renameFolder");
if(isset($_REQUEST['ieId']) && isset($_REQUEST['oldFolderName']) && !empty($_REQUEST['oldFolderName'])
&& isset($_REQUEST['newFolderName']) && !empty($_REQUEST['newFolderName'])) {
$ie->retrieve($_REQUEST['ieId']);
$ie->renameFolder($_REQUEST['oldFolderName'], $_REQUEST['newFolderName']);
} elseif(isset($_REQUEST['folderId']) && !empty($_REQUEST['folderId']) && isset($_REQUEST['newFolderName']) && !empty($_REQUEST['newFolderName'])) {
if(is_guid($_REQUEST['folderId'])) {
$email->et->folder->retrieve($_REQUEST['folderId']);
$email->et->folder->name = $_REQUEST['newFolderName'];
$email->et->folder->save();
} else {
echo "NOOP - not a Sugar Folder";
}
}
case "moveFolder":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: moveFolder");
if(isset($_REQUEST['folderId']) && !empty($_REQUEST['folderId']) && isset($_REQUEST['newParentId']) && !empty($_REQUEST['newParentId']) && $_REQUEST['newParentId'] != $_REQUEST['folderId']) {
if(is_guid($_REQUEST['folderId']) && is_guid($_REQUEST['newParentId'])) {
$email->et->folder->retrieve($_REQUEST['folderId']);
$email->et->folder->updateFolder(array(
"record" => $_REQUEST['folderId'],
"name" => $email->et->folder->name,
"parent_folder" => $_REQUEST['newParentId'],
"team_id" => $email->et->folder->team_id,
"team_set_id" => $email->et->folder->team_set_id,
));
} else {
echo "NOOP - not a Sugar Folder";
}
}
break;
case "getGroupFolder":
$email->et->folder->retrieve($_REQUEST['folderId']);
$_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;
$out = $json->encode($ret);
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;
case "saveListViewSortOrder":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: saveListViewSortOrder");
$email->et->saveListViewSortOrder($_REQUEST['ieId'], $_REQUEST['focusFolder'], $_REQUEST['sortBy'], $_REQUEST['reverse']);
break;
//// END FOLDER ACTIONS
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//// INBOUND EMAIL ACCOUNTS
case "retrieveAllOutbound":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: retrieveAllOutbound");
global $current_user;
$oe = new OutboundEmail();
$outbounds = $oe->getUserMailers($current_user);
$results = array('outbound_account_list' => $outbounds, 'count' => count($outbounds));
$out = $json->encode($results, false);
echo $out;
break;
case "editOutbound":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: editOutbound");
if(isset($_REQUEST['outbound_email']) && !empty($_REQUEST['outbound_email'])) {
$oe = new OutboundEmail();
$oe->retrieve($_REQUEST['outbound_email']);
$ret = array();
foreach($oe->field_defs as $def) {
$ret[$def] = $oe->$def;
}
$ret['mail_smtppass']=''; // don't send back the password
$ret['has_password'] = isset($oe->mail_smtppass);
$out = $json->encode($ret, true);
echo $out;
} else {
echo "NOOP";
}
break;
case "deleteOutbound":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: deleteOutbound");
if(isset($_REQUEST['outbound_email']) && !empty($_REQUEST['outbound_email']))
{
$oe = new OutboundEmail();
global $current_user;
$oe->retrieve($_REQUEST['outbound_email']);
$affectedInboundAccounts = $oe->getAssociatedInboundAccounts($current_user);
//Check if the user has confirmed he wants to delete the email account even if associated to an inbound accnt.
$confirmedDelete = ( isset($_REQUEST['confirm']) && $_REQUEST['confirm'] ) ? TRUE : FALSE;
if( count($affectedInboundAccounts) > 0 && !$confirmedDelete)
{
$results = array('is_error' => true, 'error_message' => $app_strings['LBL_EMAIL_REMOVE_SMTP_WARNING'] , 'outbound_email' => $_REQUEST['outbound_email']);
}
else
{
$oe->delete();
$results = array('is_error' => false, 'error_message' => '');
}
$out = $json->encode($results);
@ob_end_clean();
ob_start();
echo $out;
ob_end_flush();
die();
}
else
{
echo "NOOP";
}
break;
case "saveOutbound":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: saveOutbound");
$oe = new OutboundEmail();
$oe->id = $_REQUEST['mail_id'];
$oe->retrieve($oe->id);
$oe->name = $_REQUEST['mail_name'];
$type = empty($_REQUEST['type']) ? 'user' : $_REQUEST['type'];
$oe->type = $type;
$oe->user_id = $current_user->id;
$oe->mail_sendtype = "SMTP";
$oe->mail_smtptype = $_REQUEST['mail_smtptype'];
$oe->mail_smtpserver = $_REQUEST['mail_smtpserver'];
$oe->mail_smtpport = $_REQUEST['mail_smtpport'];
$oe->mail_smtpssl = $_REQUEST['mail_smtpssl'];
$oe->mail_smtpauth_req = isset($_REQUEST['mail_smtpauth_req']) ? 1 : 0;
$oe->mail_smtpuser = $_REQUEST['mail_smtpuser'];
if(!empty($_REQUEST['mail_smtppass'])) {
$oe->mail_smtppass = $_REQUEST['mail_smtppass'];
}
$oe = $oe->save();
echo $oe->id;
break;
case "saveDefaultOutbound":
global $current_user;
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: saveDefaultOutbound");
$outbound_id = empty($_REQUEST['id']) ? "" : $_REQUEST['id'];
$ie = new InboundEmail();
$ie->setUsersDefaultOutboundServerId($current_user, $outbound_id);
break;
case "testOutbound":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: testOutbound");
$pass = '';
if(!empty($_REQUEST['mail_smtppass'])) {
$pass = $_REQUEST['mail_smtppass'];
} elseif(isset($_REQUEST['mail_name'])) {
$oe = new OutboundEmail();
$oe = $oe->getMailerByName($current_user, $_REQUEST['mail_name']);
if(!empty($oe)) {
$pass = $oe->mail_smtppass;
}
}
$out = $email->sendEmailTest($_REQUEST['mail_smtpserver'], $_REQUEST['mail_smtpport'], $_REQUEST['mail_smtpssl'],
(isset($_REQUEST['mail_smtpauth_req']) ? 1 : 0), $_REQUEST['mail_smtpuser'],
$pass, $_REQUEST['outboundtest_from_address'], $_REQUEST['outboundtest_from_address']);
$out = $json->encode($out);
echo $out;
break;
case "rebuildShowAccount":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: rebuildShowAccount");
$ret = $email->et->getShowAccountsOptions($ie);
$results = array('account_list' => $ret, 'count' => count($ret));
$out = $json->encode($results);
echo $out;
break;
case "rebuildShowAccountForSearch":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: rebuildShowAccount");
$ret = $email->et->getShowAccountsOptionsForSearch($ie);
$out = $json->encode($ret);
echo $out;
break;
case "deleteIeAccount":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: deleteIeAccount");
if(isset($_REQUEST['group_id']) && $_REQUEST['group_id'] == $current_user->id) {
$ret = array();
$updateFolders = array();
$ret['id'] = $_REQUEST['ie_id'];
$out = $json->encode($ret);
$ie->hardDelete($_REQUEST['ie_id']);
$out = $json->encode(array('id' => $_REQUEST['ie_id']));
echo $out;
foreach ($showFolders as $id) {
if ($id != $_REQUEST['ie_id']) {
$updateFolders[] = $id;
}
}
$showStore = base64_encode(serialize($updateFolders));
$current_user->setPreference('showFolders', $showStore, 0, 'Emails');
}
break;
case "saveIeAccount":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: saveIeAccount");
if(isset($_REQUEST['server_url']) && !empty($_REQUEST['server_url'])) {
if(false === $ie->savePersonalEmailAccount($current_user->id, $current_user->user_name, false)) {
$ret = array('error' => 'error');
$out = $json->encode($ret);
echo $out;
} else {
$ie->retrieve($_REQUEST['ie_id']);
if (!isset($ie->created_by_link)) {
$ie->created_by_link = null;
}
if (!isset($ie->modified_user_id_link)) {
$ie->modified_user_id_link = null;
}
if (!is_array($showFolders)) {
$showFolders = array();
}
if(!in_array($ie->id, $showFolders)) {
$showFolders[] = $ie->id;
$showStore = base64_encode(serialize($showFolders));
$current_user->setPreference('showFolders', $showStore, 0, 'Emails');
}
foreach($ie->field_defs as $k => $v) {
if (isset($v['type']) && ($v['type'] == 'link')) {
continue;
}
if($k == 'stored_options') {
$ie->$k = unserialize(base64_decode($ie->$k));
if (isset($ie->stored_options['from_name'])) {
$ie->stored_options['from_name'] = from_html($ie->stored_options['from_name']);
}
} elseif($k == 'service') {
$service = explode("::", $ie->$k);
$retService = array();
foreach($service as $serviceK => $serviceV) {
if(!empty($serviceV)) {
$retService[$serviceK] = $serviceV;
}
}
$ie->$k = $retService;
}
if (isset($ie->$k))
$ret[$k] = $ie->$k;
}
$out = $json->encode($ret);
echo $out;
}
//If the user is saving the username/password then we need to update the outbound account.
$outboundMailUser = (isset($_REQUEST['mail_smtpuser'])) ? $_REQUEST['mail_smtpuser'] : "";
$outboundMailPass = (isset($_REQUEST['mail_smtppass'])) ? $_REQUEST['mail_smtppass'] : "";
$outboundMailId = (isset($_REQUEST['outbound_email'])) ? $_REQUEST['outbound_email'] : "";
if( !empty($outboundMailUser) && !empty($outboundMailPass) && !empty($outboundMailId) )
{
$oe = new OutboundEmail();
$oe->retrieve($outboundMailId);
$oe->mail_smtpuser = $outboundMailUser;
$oe->mail_smtppass = $outboundMailPass;
$oe->save();
}
} else {
echo "NOOP";
}
break;
case "getIeAccount":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: getIeAccount");
$ie->retrieve($_REQUEST['ieId']);
if($ie->group_id == $current_user->id) {
$ret = array();
foreach($ie->field_defs as $k => $v) {
if($k == 'stored_options') {
$ie->$k = unserialize(base64_decode($ie->$k));
if (isset($ie->stored_options['from_name'])) {
$ie->stored_options['from_name'] = from_html($ie->stored_options['from_name']);
}
} elseif($k == 'service') {
$service = explode("::", $ie->$k);
$retService = array();
foreach($service as $serviceK => $serviceV) {
if(!empty($serviceV)) {
$retService[$serviceK] = $serviceV;
}
}
$ie->$k = $retService;
}
$ret[$k] = $ie->$k;
}
unset($ret['email_password']); // no need to send the password out
$out = $json->encode($ret);
} else {
$out = "NOOP: ID mismatch";
}
echo $out;
break;
//// END INBOUND EMAIL ACCOUNTS
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//// SEARCH
case "search":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: search");
if(isset($_REQUEST['subject']) && !empty($_REQUEST['subject']) && isset($_REQUEST['ieId']) && !empty($_REQUEST['ieId'])) {
$metalist = $ie->search($_REQUEST['ieId'], $_REQUEST['subject']);
if (!isset($_REQUEST['page'])) {
$_REQUEST['page'] = 1;
}
$_REQUEST['pageSize'] = count($metalist['out']);
$out = $email->et->xmlOutput($metalist, 'Email', false);
@ob_end_clean();
ob_start();
header("Content-type: text/xml");
echo $out;
ob_end_flush();
die();
} else {
echo "NOOP: no search criteria found";
}
break;
case "searchAdvanced":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: searchAdvanced");
$metalist = $email->searchImportedEmails();
$out = $email->et->jsonOuput($metalist, 'Email', $metalist['totalCount']);
@ob_end_clean();
ob_start();
echo $out;
ob_end_flush();
die();
break;
//// END SEARCH
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//// SETTINGS
case "loadPreferences":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: loadPreferences");
$prefs = $email->et->getUserPrefsJS();
$out = $json->encode($prefs);
echo $out;
break;
case "saveSettingsGeneral":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: saveSettingsGeneral");
$emailSettings = array();
$emailSettings['emailCheckInterval'] = $_REQUEST['emailCheckInterval'];
//$emailSettings['autoImport'] = isset($_REQUEST['autoImport']) ? '1' : '0';
$emailSettings['alwaysSaveOutbound'] = '1';
$emailSettings['sendPlainText'] = isset($_REQUEST['sendPlainText']) ? '1' : '0';
$emailSettings['showNumInList'] = $_REQUEST['showNumInList'];
$emailSettings['defaultOutboundCharset'] = $_REQUEST['default_charset'];
$current_user->setPreference('emailSettings', $emailSettings, '', 'Emails');
// signature
$current_user->setPreference('signature_default', $_REQUEST['signature_id']);
$current_user->setPreference('signature_prepend', (isset($_REQUEST['signature_prepend'])) ? true : false);
$out = $json->encode($email->et->getUserPrefsJS());
echo $out;
break;
case "setPreference":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: setPreference");
if(isset($_REQUEST['prefName']) && isset($_REQUEST['prefValue'])) {
// handle potential JSON encoding
if(isset($_REQUEST['decode'])) {
$_REQUEST['prefValue'] = $json->decode(from_html($_REQUEST['prefValue']));
}
$current_user->setPreference($_REQUEST['prefName'], $_REQUEST['prefValue'], '', 'Emails');
}
break;
//// END SETTINGS
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//// ADDRESS BOOK
case "editContact":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: editContact");
if(isset($_REQUEST['id']) && !empty($_REQUEST['id'])) {
$module = "Contacts";
$ret = $email->et->getEditContact($_REQUEST['id'], $module);
}
$out = $json->encode($ret);
echo $out;
break;
/* The four calls below all have the same return signature */
case "removeContact":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: removeContacts");
if(strpos($_REQUEST['ids'], "::") !== false) {
$removeIds = explode("::", $_REQUEST['ids']);
} else {
$removeIds[] = $_REQUEST['ids'];
}
$email->et->removeContacts($removeIds);
case "saveContactEdit":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: saveContactEdit");
if(isset($_REQUEST['args']) && !empty($_REQUEST['args'])) {
$email->et->saveContactEdit($_REQUEST['args']);
}
// flow into getUserContacts();
case "addContact":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: addContacts");
$contacts = array();
if(isset($_REQUEST['bean_module']) && !empty($_REQUEST['bean_module']) && isset($_REQUEST['bean_id']) && !empty($_REQUEST['bean_id'])) {
$contacts[$_REQUEST['bean_id']] = array(
'id' => $_REQUEST['bean_id'],
'module' => $_REQUEST['bean_module']
);
$email->et->setContacts($contacts);
}
case "addContactsMultiple":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: addContacts");
if (isset($_REQUEST['contactData'])) {
$contacts = $json->decode(from_HTML($_REQUEST['contactData']));
if ($contacts) {
//_ppd($contacts);
$email->et->setContacts($contacts);
}
}
case "getUserContacts":
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: getUserContacts");
$contacts = $email->et->getContacts();
if(is_array($contacts) && !empty($contacts)) {
$ret = $email->et->getUserContacts($contacts, $current_user);
$out = $json->encode($ret);
echo $out;
} else {
echo "{}";
}
break;
// address book search
case "getUnionData":
$wheres = array();
$person;
if(isset($_REQUEST['first_name']) && !empty($_REQUEST['first_name'])) {
$wheres['first_name'] = $_REQUEST['first_name'];
}
if(isset($_REQUEST['last_name']) && !empty($_REQUEST['last_name'])) {
$wheres['last_name'] = $_REQUEST['last_name'];
}
if(isset($_REQUEST['email_address']) && !empty($_REQUEST['email_address'])) {
$wheres['email_address'] = $_REQUEST['email_address'];
}
if(isset($_REQUEST['person']) && !empty($_REQUEST['person'])) {
$person = $_REQUEST['person'];
}
$q = $email->et->_getPeopleUnionQuery($wheres , $person);
$r = $ie->db->limitQuery($q, 0, 25, true);
$out = array();
while($a = $ie->db->fetchByAssoc($r)) {
$person = array();
$person['id'] = $a['id'];
$person['module'] = $a['module'];
$person['full_name'] = $locale->getLocaleFormattedName($a['first_name'], $a['last_name'],'');
$person['email_address'] = $a['email_address'];
$out[] = $person;
}
$ret = $json->encode($out, true);
echo $ret;
break;
case "getAddressSearchResults":
$wheres = array();
$person = 'contacts';
$relatedBeanInfo = '';
if(isset($_REQUEST['related_bean_id']) && !empty($_REQUEST['related_bean_id'])) {
$isRelatedSearch = true;
$relatedBeanInfo['related_bean_id'] = $_REQUEST['related_bean_id'];
$relatedBeanInfo['related_bean_type'] = ucfirst($_REQUEST['related_bean_type']);
}
if (isset($_REQUEST['search_field'])) {
$wheres['first_name'] = $_REQUEST['search_field'];
$wheres['last_name'] = $_REQUEST['search_field'];
$wheres['email_address'] = $_REQUEST['search_field'];
}
if(isset($_REQUEST['person']) && !empty($_REQUEST['person'])) {
$person = $_REQUEST['person'];
}
if(!empty($_REQUEST['start'])) {
$start = intval($_REQUEST['start']);
} else {
$start = 0;
}
$qArray = $email->et->getRelatedEmail($person, $wheres, $relatedBeanInfo);
$out = array();
$count = 0;
if (!empty($qArray['query'])) {
$countq = $qArray['countQuery'];
$time = microtime(true);
$r = $ie->db->query($countq);
$GLOBALS['log']->debug("***QUERY counted in " . (microtime(true) - $time) . " milisec\n");
if($row = $GLOBALS['db']->fetchByAssoc($r)){
$count = $row['c'];
}
$time = microtime(true);
//Handle sort and order requests
$sort = !empty($_REQUEST['sort']) ? $ie->db->getValidDBName($_REQUEST['sort']) : "id";
$sort = ($sort == 'bean_id') ? 'id' : $sort;
$sort = ($sort == 'email') ? 'email_address' : $sort;
$sort = ($sort == 'name') ? 'last_name' : $sort;
$direction = !empty($_REQUEST['dir']) && in_array(strtolower($_REQUEST['dir']), array("asc", "desc")) ? $_REQUEST['dir'] : "asc";
$order = ( !empty($sort) && !empty($direction) ) ? " ORDER BY {$sort} {$direction}" : "";
$r = $ie->db->limitQuery($qArray['query'] . " $order ", $start, 25, true);
$GLOBALS['log']->debug("***QUERY Got results in " . (microtime(true) - $time) . " milisec\n");
while($a = $ie->db->fetchByAssoc($r)) {
$person = array();
$person['bean_id'] = $a['id'];
$person['bean_module'] = $a['module'];
$person['name'] = $locale->getLocaleFormattedName($a['first_name'], $a['last_name'],'');
$person['email'] = $a['email_address'];
$out[] = $person;
}
}
$ret = $email->et->jsonOuput(array('out' => $out), 'Person', $count);
@ob_end_clean();
ob_start();
echo $ret;
ob_end_flush();
break;
//// END ADDRESS BOOK
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//// MISC
default:
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: default");
echo "NOOP";
break;
} // switch
} // if