PageRenderTime 51ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/InboundEmail/DetailView.php

https://github.com/asakusuma/sugarcrm_dev
PHP | 303 lines | 212 code | 34 blank | 57 comment | 65 complexity | 83323c4e3516f55322d710e296fd518d MD5 | raw file
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. /*********************************************************************************
  4. * SugarCRM is a customer relationship management program developed by
  5. * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU Affero General Public License version 3 as published by the
  9. * Free Software Foundation with the addition of the following permission added
  10. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  11. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  12. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License along with
  20. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  21. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301 USA.
  23. *
  24. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  25. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  26. *
  27. * The interactive user interfaces in modified source and object code versions
  28. * of this program must display Appropriate Legal Notices, as required under
  29. * Section 5 of the GNU Affero General Public License version 3.
  30. *
  31. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  32. * these Appropriate Legal Notices must retain the display of the "Powered by
  33. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  34. * technical reasons, the Appropriate Legal Notices must display the words
  35. * "Powered by SugarCRM".
  36. ********************************************************************************/
  37. require_once('include/DetailView/DetailView.php');
  38. require_once('include/SugarFolders/SugarFolders.php');
  39. global $mod_strings;
  40. global $app_strings;
  41. global $sugar_config;
  42. global $timedate;
  43. global $theme;
  44. /* start standard DetailView layout process */
  45. $GLOBALS['log']->info("InboundEmails DetailView");
  46. $focus = new InboundEmail();
  47. $focus->retrieve($_REQUEST['record']);
  48. if (empty($focus->id)) {
  49. sugar_die($app_strings['ERROR_NO_RECORD']);
  50. } // if
  51. $focus->checkImap();
  52. $detailView = new DetailView();
  53. $offset=0;
  54. /* end standard DetailView layout process */
  55. $exServ = explode('::',$focus->service);
  56. if($focus->delete_seen == 1) {
  57. $delete_seen = $mod_strings['LBL_MARK_READ_NO'];
  58. } else {
  59. $delete_seen = $mod_strings['LBL_MARK_READ_YES'];
  60. }
  61. // deferred
  62. //$r = $focus->db->query("SELECT id, name FROM queues WHERE owner_id = '".$focus->id."'");
  63. //$a = $focus->db->fetchByAssoc($r);
  64. //$queue = '<a href="index.php?module=Queues&action=EditView&record='.$a['id'].'">'.$a['name'].'</a>';
  65. $groupName = '';
  66. if($focus->group_id) {
  67. //$group = new Group();
  68. //$group->retrieve($focus->group_id);
  69. //$groupName = $group->user_name;
  70. }
  71. if($focus->template_id) {
  72. $et = new EmailTemplate();
  73. $et->retrieve($focus->template_id);
  74. $emailTemplate = $et->name;
  75. } else {
  76. $emailTemplate = $mod_strings['LBL_NONE'];
  77. }
  78. $ssl = $app_list_strings['dom_email_bool']['bool_false'];
  79. $allow_outbound_group_usage = $app_list_strings['dom_email_bool']['bool_false'];
  80. $tls = $app_list_strings['dom_email_bool']['bool_false'];
  81. $ca = $app_list_strings['dom_email_bool']['bool_false'];
  82. if(!empty($focus->service)) {
  83. // will always have 2 values: /tls || /notls and /validate-cert || /novalidate-cert
  84. $exServ = explode('::', $focus->service);
  85. if($exServ[0] == 'tls') {
  86. $tls = $app_list_strings['dom_email_bool']['bool_true'];
  87. }
  88. if($exServ[1] == 'validate-cert') {
  89. $cert = $app_list_strings['dom_email_bool']['bool_true'];
  90. }
  91. if(isset($exServ[2]) && !empty($exServ[2]) && $exServ[2] == 'ssl') {
  92. $ssl = $app_list_strings['dom_email_bool']['bool_true'];
  93. }
  94. }
  95. // FROM NAME FROM ADDRESS STRINGS
  96. $email = new Email();
  97. $from = $email->getSystemDefaultEmail();
  98. $default_from_name = $from['name'];
  99. $default_from_addr = $from['email'];
  100. $from_name = '';
  101. $from_addr = '';
  102. $reply_to_name = '';
  103. $reply_to_addr = '';
  104. $distrib_method ='';
  105. $filterDomain = '';
  106. $trashFolder = '';
  107. $sentFolder = '';
  108. $distributionMethod = '';
  109. $create_case_email_template='';
  110. $create_case_email_template_name = $mod_strings['LBL_NONE'];
  111. $leaveMessagesOnMailServer = $app_strings['LBL_EMAIL_NO'];
  112. //$fromNameAddr = $fromName.' &lt;'.$from['email'].'&gt; <br><em>('.$mod_strings['LBL_SYSTEM_DEFAULT'].')</em>';
  113. //$replyNameAddr = $mod_strings['LBL_SAME_AS_ABOVE'];
  114. $onlySince = $mod_strings['LBL_ONLY_SINCE_NO'];
  115. if(!empty($focus->stored_options)) {
  116. // FROM NAME and Address
  117. $storedOptions = unserialize(base64_decode($focus->stored_options));
  118. $from_name = (isset($storedOptions['from_name']) ? $storedOptions['from_name'] : "");
  119. $from_addr = (isset($storedOptions['from_addr']) ? $storedOptions['from_addr'] : "");
  120. $reply_to_name = (isset($storedOptions['reply_to_name'])) ? $storedOptions['reply_to_name'] : "";
  121. $reply_to_addr = (isset($storedOptions['reply_to_addr'])) ? $storedOptions['reply_to_addr'] : "";
  122. // only-since option
  123. if($storedOptions['only_since']) {
  124. $onlySince = $mod_strings['LBL_ONLY_SINCE_YES'];
  125. } else {
  126. $onlySince = $mod_strings['LBL_ONLY_SINCE_NO'];
  127. }
  128. // filter-domain
  129. if(isset($storedOptions['filter_domain']) && !empty($storedOptions['filter_domain'])) {
  130. $filterDomain = $storedOptions['filter_domain'];
  131. } else {
  132. $filterDomain = $app_strings['NTC_NO_ITEMS_DISPLAY'];
  133. }
  134. // Trash Folder
  135. if(isset($storedOptions['trashFolder']) && !empty($storedOptions['trashFolder'])) {
  136. $trashFolder = $storedOptions['trashFolder'];
  137. } else {
  138. $trashFolder = $mod_strings['LBL_NONE'];
  139. }
  140. // Sent Folder
  141. if(isset($storedOptions['sentFolder']) && !empty($storedOptions['sentFolder'])) {
  142. $sentFolder = $storedOptions['sentFolder'];
  143. } else {
  144. $sentFolder = $mod_strings['LBL_NONE'];
  145. }
  146. if(!isset($storedOptions['leaveMessagesOnMailServer']) || $storedOptions['leaveMessagesOnMailServer'] == 1) {
  147. $leaveMessagesOnMailServer = $app_strings['LBL_EMAIL_YES'];
  148. } else {
  149. $leaveMessagesOnMailServer = $app_strings['LBL_EMAIL_NO'];
  150. } // else
  151. if(!isset($storedOptions['leaveMessagesOnMailServer']) || $storedOptions['leaveMessagesOnMailServer'] == 1) {
  152. $leaveMessagesOnMailServer = $app_strings['LBL_EMAIL_YES'];
  153. } else {
  154. $leaveMessagesOnMailServer = $app_strings['LBL_EMAIL_NO'];
  155. } // else
  156. $distrib_method = (isset($storedOptions['distrib_method'])) ? $storedOptions['distrib_method'] : "";
  157. $create_case_email_template = (isset($storedOptions['create_case_email_template'])) ? $storedOptions['create_case_email_template'] : "";
  158. $email_num_autoreplies_24_hours = (isset($storedOptions['email_num_autoreplies_24_hours'])) ? $storedOptions['email_num_autoreplies_24_hours'] : $focus->defaultEmailNumAutoreplies24Hours;
  159. if( isset($storedOptions['allow_outbound_group_usage']) && $storedOptions['allow_outbound_group_usage'] == 1)
  160. $allow_outbound_group_usage = $app_list_strings['dom_email_bool']['bool_true'];
  161. }
  162. if(!empty($create_case_email_template)) {
  163. $et = new EmailTemplate();
  164. $et->retrieve($create_case_email_template);
  165. $create_case_email_template_name = $et->name;
  166. }
  167. if (!empty($distrib_method)) {
  168. $distributionMethod = $app_list_strings['dom_email_distribution_for_auto_create'][$distrib_method];
  169. } // if
  170. $xtpl = new XTemplate('modules/InboundEmail/DetailView.html');
  171. //// ERRORS from Save
  172. if(isset($_REQUEST['error'])) {
  173. $xtpl->assign('ERROR', "<div class='error'>".$mod_strings['ERR_NO_OPTS_SAVED']."</div>");
  174. }
  175. //cma, June 24,2008 - Fix bug 21670. User status and group/personal statements are not localized.
  176. $userStatus = $mod_strings['LBL_STATUS_ACTIVE'];
  177. if('Inactive' == $focus->status) {
  178. $userStatus = $mod_strings['LBL_STATUS_INACTIVE'];
  179. }
  180. $xtpl->assign('MODULE_TITLE', get_module_title($mod_strings['LBL_MODULE_TITLE'], $mod_strings['LBL_MODULE_NAME'].": ".$focus->name, true));
  181. $xtpl->assign('MOD', $mod_strings);
  182. $xtpl->assign('APP', $app_strings);
  183. $xtpl->assign('CREATED_BY', $focus->created_by_name);
  184. $xtpl->assign('MODIFIED_BY', $focus->modified_by_name);
  185. $xtpl->assign('GRIDLINE', $gridline);
  186. $xtpl->assign('PRINT_URL', 'index.php?'.$GLOBALS['request_string']);
  187. $xtpl->assign('ID', $focus->id);
  188. $xtpl->assign('STATUS', $userStatus);
  189. $xtpl->assign('SERVER_URL', $focus->server_url);
  190. $xtpl->assign('USER', $focus->email_user);
  191. $xtpl->assign('NAME', $focus->name);
  192. $xtpl->assign('MAILBOX', $focus->mailbox);
  193. $xtpl->assign('TRASHFOLDER', $trashFolder);
  194. $xtpl->assign('SENTFOLDER', $sentFolder);
  195. $protocol = filterInboundEmailPopSelection($app_list_strings['dom_email_server_type']);
  196. $xtpl->assign('SERVER_TYPE', $protocol[$focus->protocol]);
  197. $xtpl->assign('SSL', $ssl);
  198. $xtpl->assign('TLS', $tls);
  199. $xtpl->assign('CERT', $ca);
  200. $xtpl->assign('MARK_READ', $delete_seen);
  201. $xtpl->assign('ALLOW_OUTBOUND_GROUP_USAGE', $allow_outbound_group_usage);
  202. // deferred
  203. //$xtpl->assign('QUEUE', $queue);
  204. $createCaseRowStyle = "display:none";
  205. $leaveMessagesOnMailServerStyle = "display:none";
  206. if ($focus->is_personal) {
  207. $xtpl->assign('EDIT_GROUP_FOLDER_STYLE', "display:none");
  208. } else {
  209. $is_auto_import = $app_list_strings['checkbox_dom']['2'];
  210. if (!empty($focus->groupfolder_id)) {
  211. $is_auto_import = $app_list_strings['checkbox_dom']['1'];
  212. $leaveMessagesOnMailServerStyle = "display:''";
  213. } // if
  214. $xtpl->assign('IS_AUTO_IMPORT_ENABLED', $is_auto_import);
  215. $xtpl->assign('EDIT_GROUP_FOLDER_STYLE', "display:''");
  216. if ($focus->isMailBoxTypeCreateCase()) {
  217. $createCaseRowStyle = "display:''";
  218. }
  219. }
  220. $xtpl->assign('LEAVEMESSAGESONMAILSERVER_STYLE', $leaveMessagesOnMailServerStyle);
  221. $xtpl->assign('LEAVEMESSAGESONMAILSERVER', $leaveMessagesOnMailServer);
  222. $xtpl->assign('CREATE_CASE_ROW_STYLE', $createCaseRowStyle);
  223. $xtpl->assign('DISTRIBUTION_METHOD', $distributionMethod);
  224. $xtpl->assign('CREATE_CASE_EMAIL_TEMPLATE', $create_case_email_template_name);
  225. if ($focus->isPop3Protocol()) {
  226. $xtpl->assign('TRASH_SENT_FOLDER_STYLE', "display:none");
  227. } else {
  228. $xtpl->assign('TRASH_SENT_FOLDER_STYLE', "display:''");
  229. } // else
  230. $possibleAction = "pick";
  231. if (!isset($app_list_strings['dom_mailbox_type'][$focus->mailbox_type])) {
  232. $possibleAction = $app_list_strings['dom_mailbox_type']['pick'];
  233. } else {
  234. $possibleAction = $app_list_strings['dom_mailbox_type'][$focus->mailbox_type];
  235. }
  236. if($focus->mailbox_type == 'createcase')
  237. $is_create_case = $app_list_strings['checkbox_dom']['1'];
  238. else
  239. $is_create_case = $app_list_strings['checkbox_dom']['2'];
  240. $xtpl->assign('GROUP_NAME', $groupName);
  241. $xtpl->assign('IS_CREATE_CASE', $is_create_case);
  242. $xtpl->assign('EMAIL_TEMPLATE', $emailTemplate);
  243. $xtpl->assign('FROM_NAME', $from_name);
  244. $xtpl->assign('FROM_ADDR', $from_addr);
  245. $xtpl->assign('DEFAULT_FROM_NAME', $default_from_name);
  246. $xtpl->assign('DEFAULT_FROM_ADDR', $default_from_addr);
  247. $xtpl->assign('REPLY_TO_NAME', $reply_to_name);
  248. $xtpl->assign('REPLY_TO_ADDR', $reply_to_addr);
  249. $xtpl->assign('ONLY_SINCE', $onlySince);
  250. $xtpl->assign('FILTER_DOMAIN', $filterDomain);
  251. $xtpl->assign('EMAIL_NUM_AUTOREPLIES_24_HOURS', $email_num_autoreplies_24_hours);
  252. if(!empty($focus->port)) {
  253. $xtpl->assign('PORT', $focus->port);
  254. }
  255. if($focus->handleIsPersonal()) {
  256. $xtpl->assign('LBL_GROUP_QUEUE', $mod_strings['LBL_ASSIGN_TO_USER']);
  257. } else {
  258. $xtpl->assign('LBL_GROUP_QUEUE', $mod_strings['LBL_GROUP_QUEUE']);
  259. }
  260. //Overrides for bounce mailbox accounts
  261. if ($focus->mailbox_type == 'bounce')
  262. {
  263. $xtpl->assign('MODULE_TITLE', get_module_title($mod_strings['LBL_MODULE_TITLE'], $mod_strings['LBL_BOUNCE_MODULE_NAME'].": ".$focus->name, true));
  264. }
  265. else if( $focus->is_personal == '1')
  266. $xtpl->assign('MODULE_TITLE', get_module_title($mod_strings['LBL_MODULE_TITLE'], $mod_strings['LBL_PERSONAL_MODULE_NAME'].": ".$focus->name, true));
  267. $xtpl->parse('main');
  268. $xtpl->out('main');
  269. ?>