PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/vtigerCRM/modules/Emails/EditView.php

https://github.com/hitchby/PLEXUS
PHP | 356 lines | 276 code | 33 blank | 47 comment | 90 complexity | 865939a3c1e782282da243511f1030cc MD5 | raw file
  1. <?php
  2. /*********************************************************************************
  3. * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
  4. * ("License"); You may not use this file except in compliance with the
  5. * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
  6. * Software distributed under the License is distributed on an "AS IS" basis,
  7. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  8. * the specific language governing rights and limitations under the License.
  9. * The Original Code is: SugarCRM Open Source
  10. * The Initial Developer of the Original Code is SugarCRM, Inc.
  11. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12. * All Rights Reserved.
  13. * Contributor(s): ______________________________________.
  14. ********************************************************************************/
  15. /*********************************************************************************
  16. * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Emails/EditView.php,v 1.25 2005/04/18 10:37:49 samk Exp $
  17. * Description: TODO: To be written.
  18. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  19. * All Rights Reserved.
  20. * Contributor(s): ______________________________________..
  21. ********************************************************************************/
  22. require_once('Smarty_setup.php');
  23. require_once('data/Tracker.php');
  24. require_once('include/utils/utils.php');
  25. require_once('include/utils/UserInfoUtil.php');
  26. require_once("include/Zend/Json.php");
  27. global $log;
  28. global $app_strings;
  29. global $app_list_strings;
  30. global $mod_strings;
  31. global $current_user;
  32. global $currentModule;
  33. global $default_charset;
  34. $focus = CRMEntity::getInstance($currentModule);
  35. $smarty = new vtigerCRM_Smarty();
  36. $json = new Zend_Json();
  37. if($_REQUEST['upload_error'] == true)
  38. {
  39. echo '<br><b><font color="red"> The selected file has no data or a invalid file.</font></b><br>';
  40. }
  41. //Email Error handling
  42. if($_REQUEST['mail_error'] != '')
  43. {
  44. require_once("modules/Emails/mail.php");
  45. echo parseEmailErrorString($_REQUEST['mail_error']);
  46. }
  47. //added to select the module in combobox of compose-popup
  48. if(isset($_REQUEST['par_module']) && $_REQUEST['par_module']!=''){
  49. $smarty->assign('select_module',vtlib_purify($_REQUEST['par_module']));
  50. }
  51. elseif(isset($_REQUEST['pmodule']) && $_REQUEST['pmodule']!='') {
  52. $smarty->assign('select_module',vtlib_purify($_REQUEST['pmodule']));
  53. }
  54. if(isset($_REQUEST['record']) && $_REQUEST['record'] !='')
  55. {
  56. $focus->id = $_REQUEST['record'];
  57. $focus->mode = 'edit';
  58. $focus->retrieve_entity_info($_REQUEST['record'],"Emails");
  59. $query = 'select idlists,from_email,to_email,cc_email,bcc_email from vtiger_emaildetails where emailid =?';
  60. $result = $adb->pquery($query, array($focus->id));
  61. $from_email = $adb->query_result($result,0,'from_email');
  62. $smarty->assign('FROM_MAIL',$from_email);
  63. $to_email = implode(',',$json->decode($adb->query_result($result,0,'to_email')));
  64. $smarty->assign('TO_MAIL',$to_email);
  65. $cc_add = implode(',',$json->decode($adb->query_result($result,0,'cc_email')));
  66. $smarty->assign('CC_MAIL',$cc_add);
  67. $bcc_add = implode(',',$json->decode($adb->query_result($result,0,'bcc_email')));
  68. $smarty->assign('BCC_MAIL',$bcc_add);
  69. $idlist = $adb->query_result($result,0,'idlists');
  70. $smarty->assign('IDLISTS',$idlist);
  71. $log->info("Entity info successfully retrieved for EditView.");
  72. $focus->name=$focus->column_fields['name'];
  73. }
  74. elseif(isset($_REQUEST['sendmail']) && $_REQUEST['sendmail'] !='')
  75. {
  76. $mailids = get_to_emailids($_REQUEST['pmodule']);
  77. if($mailids['mailds'] != '')
  78. $to_add = trim($mailids['mailds'],",").",";
  79. $smarty->assign('TO_MAIL',$to_add);
  80. $smarty->assign('IDLISTS',$mailids['idlists']);
  81. $focus->mode = '';
  82. }
  83. // INTERNAL MAILER
  84. if($_REQUEST["internal_mailer"] == "true") {
  85. $smarty->assign('INT_MAILER',"true");
  86. $rec_type = $_REQUEST["type"];
  87. $rec_id = $_REQUEST["rec_id"];
  88. $fieldname = $_REQUEST["fieldname"];
  89. //added for getting list-ids to compose email popup from list view(Accounts,Contacts,Leads)
  90. if(isset($_REQUEST['field_id']) && strlen($_REQUEST['field_id']) != 0) {
  91. if($_REQUEST['par_module'] == "Users")
  92. $id_list = $_REQUEST['rec_id'].'@'.'-1|';
  93. else
  94. $id_list = $_REQUEST['rec_id'].'@'.$_REQUEST['field_id'].'|';
  95. $smarty->assign("IDLISTS", $id_list);
  96. }
  97. if($rec_type == "record_id") {
  98. $type = $_REQUEST['par_module'];
  99. //check added for email link in user detail view
  100. $normal_tabs = Array('Users'=>'vtiger_users', 'Leads'=>'vtiger_leaddetails', 'Contacts'=>'vtiger_contactdetails', 'Accounts'=>'vtiger_account', 'Vendors'=>'vtiger_vendor');
  101. $cf_tabs = Array('Accounts'=>'vtiger_accountscf', 'Campaigns'=>'vtiger_campaignscf', 'Contacts'=>'vtiger_contactscf', 'Invoice'=>'vtiger_invoicecf', 'Leads'=>'vtiger_leadscf', 'Potentials'=>'vtiger_potentialscf', 'Products'=>'vtiger_productcf', 'PurchaseOrder'=>'vtiger_purchaseordercf', 'Quotes'=>'vtiger_quotescf', 'SalesOrder'=>'vtiger_salesordercf', 'HelpDesk'=>'vtiger_ticketcf', 'Vendors'=>'vtiger_vendorcf');
  102. if(substr($fieldname,0,2)=="cf")
  103. $tablename = $cf_tabs[$type];
  104. else
  105. $tablename = $normal_tabs[$type];
  106. if($type == "Users")
  107. $q = "select $fieldname from $tablename where id=?";
  108. elseif($type == "Leads")
  109. $q = "select $fieldname from $tablename where leadid=?";
  110. elseif ($type == "Contacts")
  111. $q = "select $fieldname from $tablename where contactid=?";
  112. elseif ($type == "Accounts")
  113. $q = "select $fieldname from $tablename where accountid=?";
  114. elseif ($type == "Vendors")
  115. $q = "select $fieldname from $tablename where vendorid=?";
  116. else {
  117. // vtlib customization: Support for email-type custom field for other modules.
  118. $module_focus = CRMEntity::getInstance($type);
  119. vtlib_setup_modulevars($type, $module_focus);
  120. if(!empty($module_focus->customFieldTable)) {
  121. $q = "select $fieldname from " . $module_focus->customFieldTable[0] . " where " . $module_focus->customFieldTable[1]. "= ?";
  122. }
  123. // END
  124. }
  125. $email1 = $adb->query_result($adb->pquery($q, array($rec_id)),0,$fieldname);
  126. } elseif ($rec_type == "email_addy") {
  127. $email1 = $_REQUEST["email_addy"];
  128. }
  129. $smarty->assign('TO_MAIL',trim($email1,",").",");
  130. }
  131. //handled for replying emails
  132. if($_REQUEST['reply'] == "true")
  133. {
  134. $fromadd = $_REQUEST['record'];
  135. $query = "select from_email,idlists,cc_email,bcc_email from vtiger_emaildetails where emailid =?";
  136. $result = $adb->pquery($query, array($fromadd));
  137. $from_mail = $adb->query_result($result,0,'from_email');
  138. $smarty->assign('TO_MAIL',trim($from_mail,",").',');
  139. $cc_add = implode(',',$json->decode($adb->query_result($result,0,'cc_email')));
  140. $smarty->assign('CC_MAIL',$cc_add);
  141. $bcc_add = implode(',',$json->decode($adb->query_result($result,0,'bcc_email')));
  142. $smarty->assign('BCC_MAIL',$bcc_add);
  143. $smarty->assign('IDLISTS',preg_replace('/###/',',',$adb->query_result($result,0,'idlists')));
  144. }
  145. // Webmails
  146. if(isset($_REQUEST["mailid"]) && $_REQUEST["mailid"] != "") {
  147. $mailid = $_REQUEST["mailid"];
  148. $mailbox = $_REQUEST["mailbox"];
  149. require_once('include/utils/UserInfoUtil.php');
  150. require_once("modules/Webmails/Webmails.php");
  151. require_once("modules/Webmails/MailParse.php");
  152. require_once('modules/Webmails/MailBox.php');
  153. $mailInfo = getMailServerInfo($current_user);
  154. $temprow = $adb->fetch_array($mailInfo);
  155. $MailBox = new MailBox($mailbox);
  156. $mbox = $MailBox->mbox;
  157. $webmail = new Webmails($mbox,$mailid);
  158. $array_tab = Array();
  159. $webmail->loadMail($array_tab);
  160. $hdr = @imap_headerinfo($mbox, $mailid);
  161. $smarty->assign('WEBMAIL',"true");
  162. $smarty->assign('mailid',$mailid);
  163. $smarty->assign('mailbox',$mailbox);
  164. $temp_id = $MailBox->boxinfo['mail_id'];
  165. $smarty->assign('from_add',$temp_id);
  166. $webmail->subject = utf8_decode(utf8_encode(imap_utf8($webmail->subject)));
  167. if($_REQUEST["reply"] == "all") {
  168. $smarty->assign('TO_MAIL',$webmail->from.",");
  169. //added to remove the emailid of webmail client from cc list....to fix the issue #3818
  170. $cc_address = '';
  171. $use_to_header = htmlentities($webmail->to_header, ENT_QUOTES, $default_charset);
  172. $use_cc_address= htmlentities($hdr->ccaddress, ENT_QUOTES, $default_charset);
  173. $cc_array = explode(',',$use_to_header.','.$use_cc_address);
  174. for($i=0;$i<count($cc_array);$i++) {
  175. if(trim($cc_array[$i]) != trim($temp_id)) {
  176. $cc_address .= $cc_array[$i];
  177. $cc_address = ($i != (count($cc_array)-1))?($cc_address.','):$cc_address;
  178. }
  179. }
  180. if(trim($cc_address) != '')
  181. $cc_address = trim($cc_address,",").",";
  182. $smarty->assign('CC_MAIL',$cc_address);
  183. // fix #3818 ends
  184. /*if(is_array($webmail->cc_list))
  185. {
  186. $smarty->assign('CC_MAIL',implode(",",$webmail->cc_list).",".implode(",",$webmail->to));
  187. }
  188. else
  189. {
  190. //Commenting this to fix #3231
  191. // $smarty->assign('CC_MAIL',implode(",",$webmail->to));
  192. }*/
  193. if(preg_match("/RE:/i", $webmail->subject))
  194. $smarty->assign('SUBJECT',$webmail->subject);
  195. else
  196. $smarty->assign('SUBJECT',"RE: ".$webmail->subject);
  197. } elseif($_REQUEST["reply"] == "single"){
  198. $smarty->assign('TO_MAIL',$webmail->reply_to[0].",");
  199. //$smarty->assign('BCC_MAIL',$webmail->to[0]);
  200. if(preg_match("/RE:/i", $webmail->subject))
  201. $smarty->assign('SUBJECT',$webmail->subject);
  202. else
  203. $smarty->assign('SUBJECT',"RE: ".$webmail->subject);
  204. } elseif($_REQUEST["forward"] == "true" ) {
  205. //added for attachment handling
  206. $attachment_links = Array();
  207. for($i=0;$i<count($webmail->attname);$i++){
  208. $attachment_links[$i] = $webmail->anchor_arr[$i].decode_header($webmail->attname[$i])."</a></br>";
  209. }
  210. $smarty->assign('webmail_attachments',$attachment_links);
  211. if(preg_match("/FW:/i", $webmail->subject))
  212. $smarty->assign('SUBJECT',$webmail->subject);
  213. else
  214. $smarty->assign('SUBJECT',"FW: ".$webmail->subject);
  215. }
  216. $smarty->assign('DESCRIPTION',$webmail->replyBody());
  217. $focus->mode='';
  218. }
  219. global $theme;
  220. $theme_path="themes/".$theme."/";
  221. $image_path=$theme_path."images/";
  222. $disp_view = getView($focus->mode);
  223. $details = getBlocks($currentModule,$disp_view,$mode,$focus->column_fields);
  224. //changed this below line to view description in all language - bharath
  225. $smarty->assign("BLOCKS",$details[$mod_strings['LBL_EMAIL_INFORMATION']]);
  226. $smarty->assign("MODULE",$currentModule);
  227. $smarty->assign("SINGLE_MOD",$app_strings['Email']);
  228. //id list of attachments while forwarding
  229. $smarty->assign("ATT_ID_LIST",$att_id_list);
  230. //needed when creating a new email with default values passed in
  231. if (isset($_REQUEST['contact_name']) && is_null($focus->contact_name))
  232. {
  233. $focus->contact_name = $_REQUEST['contact_name'];
  234. }
  235. if (isset($_REQUEST['contact_id']) && is_null($focus->contact_id))
  236. {
  237. $focus->contact_id = $_REQUEST['contact_id'];
  238. }
  239. if (isset($_REQUEST['parent_name']) && is_null($focus->parent_name))
  240. {
  241. $focus->parent_name = $_REQUEST['parent_name'];
  242. }
  243. if (isset($_REQUEST['parent_id']) && is_null($focus->parent_id))
  244. {
  245. $focus->parent_id = $_REQUEST['parent_id'];
  246. }
  247. if (isset($_REQUEST['parent_type']))
  248. {
  249. $focus->parent_type = $_REQUEST['parent_type'];
  250. }
  251. if (isset($_REQUEST['filename']) && $_REQUEST['isDuplicate'] != 'true')
  252. {
  253. $focus->filename = $_REQUEST['filename'];
  254. }
  255. elseif (is_null($focus->parent_type))
  256. {
  257. $focus->parent_type = $app_list_strings['record_type_default_key'];
  258. }
  259. $log->info("Email detail view");
  260. $smarty->assign("MOD", $mod_strings);
  261. $smarty->assign("APP", $app_strings);
  262. if (isset($focus->name)) $smarty->assign("NAME", $focus->name);
  263. else $smarty->assign("NAME", "");
  264. if($focus->mode == 'edit')
  265. {
  266. $smarty->assign("UPDATEINFO",updateInfo($focus->id));
  267. $smarty->assign("MODE", $focus->mode);
  268. }
  269. // Unimplemented until jscalendar language vtiger_files are fixed
  270. $smarty->assign("CALENDAR_LANG", $app_strings['LBL_JSCALENDAR_LANG']);
  271. $smarty->assign("CALENDAR_DATEFORMAT", parse_calendardate($app_strings['NTC_DATE_FORMAT']));
  272. if(isset($_REQUEST['return_module'])) $smarty->assign("RETURN_MODULE", vtlib_purify($_REQUEST['return_module']));
  273. else $smarty->assign("RETURN_MODULE",'Emails');
  274. if(isset($_REQUEST['return_action'])) $smarty->assign("RETURN_ACTION", vtlib_purify($_REQUEST['return_action']));
  275. else $smarty->assign("RETURN_ACTION",'index');
  276. if(isset($_REQUEST['return_id'])) $smarty->assign("RETURN_ID", vtlib_purify($_REQUEST['return_id']));
  277. if (isset($_REQUEST['return_viewname'])) $smarty->assign("RETURN_VIEWNAME", vtlib_purify($_REQUEST['return_viewname']));
  278. $smarty->assign("THEME", $theme);
  279. $smarty->assign("IMAGE_PATH", $image_path);
  280. $smarty->assign("PRINT_URL", "phprint.php?jt=".session_id().$GLOBALS['request_string']);
  281. $smarty->assign("ID", $focus->id);
  282. $smarty->assign("ENTITY_ID", vtlib_purify($_REQUEST["record"]));
  283. $smarty->assign("ENTITY_TYPE",vtlib_purify($_REQUEST["email_directing_module"]));
  284. $smarty->assign("OLD_ID", $old_id );
  285. //Display the RTE or not? -- configure $USE_RTE in config.php
  286. $USE_RTE = vt_hasRTE();
  287. $smarty->assign("USE_RTE",$USE_RTE);
  288. if(empty($focus->filename))
  289. {
  290. $smarty->assign("FILENAME_TEXT", "");
  291. $smarty->assign("FILENAME", "");
  292. }
  293. else
  294. {
  295. $smarty->assign("FILENAME_TEXT", "(".$focus->filename.")");
  296. $smarty->assign("FILENAME", $focus->filename);
  297. }
  298. if($ret_error == 1) {
  299. require_once('modules/Webmails/MailBox.php');
  300. $smarty->assign("RET_ERROR",$ret_error);
  301. if($ret_parentid != ''){
  302. $smarty->assign("IDLISTS",$ret_parentid);
  303. }
  304. if($ret_toadd != '')
  305. $smarty->assign("TO_MAIL",$ret_toadd);
  306. $ret_toadd = '';
  307. if($ret_subject != '')
  308. $smarty->assign("SUBJECT",$ret_subject);
  309. if($ret_ccaddress != '')
  310. $smarty->assign("CC_MAIL",$ret_ccaddress);
  311. if($ret_bccaddress != '')
  312. $smarty->assign("BCC_MAIL",$ret_bccaddress);
  313. if($ret_description != '')
  314. $smarty->assign("DESCRIPTION", $ret_description);
  315. $temp_obj = new MailBox($mailbox);
  316. $temp_id = $temp_obj->boxinfo['mail_id'];
  317. if($temp_id != '')
  318. $smarty->assign('from_add',$temp_id);
  319. }
  320. $check_button = Button_Check($module);
  321. $smarty->assign("CHECK", $check_button);
  322. $smarty->display("ComposeEmail.tpl");
  323. ?>