PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/EmailTemplates/EditView.php

https://github.com/lukio/sugarcrm_dev
PHP | 349 lines | 245 code | 40 blank | 64 comment | 79 complexity | 1a1bea636cfd2d0d60db24f4cbcde8b2 MD5 | raw file
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. /*********************************************************************************
  4. * SugarCRM Community Edition 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. /*********************************************************************************
  38. * Description: TODO: To be written.
  39. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  40. * All Rights Reserved.
  41. * Contributor(s): ______________________________________..
  42. ********************************************************************************/
  43. require_once('modules/Campaigns/utils.php');
  44. //if campaign_id is passed then we assume this is being invoked from the campaign module and in a popup.
  45. $has_campaign=true;
  46. $inboundEmail=true;
  47. if (!isset($_REQUEST['campaign_id']) || empty($_REQUEST['campaign_id'])) {
  48. $has_campaign=false;
  49. }
  50. if (!isset($_REQUEST['inboundEmail']) || empty($_REQUEST['inboundEmail'])) {
  51. $inboundEmail=false;
  52. }
  53. $focus = new EmailTemplate();
  54. if(isset($_REQUEST['record'])) {
  55. $focus->retrieve($_REQUEST['record']);
  56. }
  57. $old_id = '';
  58. if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
  59. $old_id = $focus->id; // for attachments down below
  60. $focus->id = "";
  61. }
  62. //setting default flag value so due date and time not required
  63. if(!isset($focus->id)) $focus->date_due_flag = 1;
  64. //needed when creating a new case with default values passed in
  65. if(isset($_REQUEST['contact_name']) && is_null($focus->contact_name)) {
  66. $focus->contact_name = $_REQUEST['contact_name'];
  67. }
  68. if(isset($_REQUEST['contact_id']) && is_null($focus->contact_id)) {
  69. $focus->contact_id = $_REQUEST['contact_id'];
  70. }
  71. if(isset($_REQUEST['parent_name']) && is_null($focus->parent_name)) {
  72. $focus->parent_name = $_REQUEST['parent_name'];
  73. }
  74. if(isset($_REQUEST['parent_id']) && is_null($focus->parent_id)) {
  75. $focus->parent_id = $_REQUEST['parent_id'];
  76. }
  77. if(isset($_REQUEST['parent_type'])) {
  78. $focus->parent_type = $_REQUEST['parent_type'];
  79. }
  80. elseif(!isset($focus->parent_type)) {
  81. $focus->parent_type = $app_list_strings['record_type_default_key'];
  82. }
  83. if(isset($_REQUEST['filename']) && $_REQUEST['isDuplicate'] != 'true') {
  84. $focus->filename = $_REQUEST['filename'];
  85. }
  86. if($has_campaign || $inboundEmail) {
  87. insert_popup_header($theme);
  88. }
  89. $params = array();
  90. if(empty($focus->id)){
  91. $params[] = $GLOBALS['app_strings']['LBL_CREATE_BUTTON_LABEL'];
  92. }else{
  93. $params[] = "<a href='index.php?module={$focus->module_dir}&action=DetailView&record={$focus->id}'>{$focus->name}</a>";
  94. $params[] = $GLOBALS['app_strings']['LBL_EDIT_BUTTON_LABEL'];
  95. }
  96. echo getClassicModuleTitle($focus->module_dir, $params, true);
  97. $GLOBALS['log']->info("EmailTemplate detail view");
  98. if($has_campaign || $inboundEmail) {
  99. $xtpl=new XTemplate ('modules/EmailTemplates/EditView.html');
  100. } else {
  101. $xtpl=new XTemplate ('modules/EmailTemplates/EditViewMain.html');
  102. } // else
  103. $xtpl->assign("MOD", $mod_strings);
  104. $xtpl->assign("APP", $app_strings);
  105. $xtpl->assign("LBL_ACCOUNT",$app_list_strings['moduleList']['Accounts']);
  106. $xtpl->parse("main.variable_option");
  107. $returnAction = 'index';
  108. if(isset($_REQUEST['return_module'])) $xtpl->assign("RETURN_MODULE", $_REQUEST['return_module']);
  109. if(isset($_REQUEST['return_action'])){
  110. $xtpl->assign("RETURN_ACTION", $_REQUEST['return_action']);
  111. $returnAction = $_REQUEST['return_action'];
  112. }
  113. if(isset($_REQUEST['return_id'])) $xtpl->assign("RETURN_ID", $_REQUEST['return_id']);
  114. // handle Create $module then Cancel
  115. if(empty($_REQUEST['return_id'])) {
  116. $xtpl->assign("RETURN_ACTION", 'index');
  117. }
  118. if ($has_campaign || $inboundEmail ) {
  119. $cancel_script="window.close();";
  120. }else {
  121. $cancel_script="this.form.action.value='{$returnAction}'; this.form.module.value='{$_REQUEST['return_module']}';
  122. this.form.record.value=";
  123. if(empty($_REQUEST['return_id'])) {
  124. $cancel_script="this.form.action.value='index'; this.form.module.value='{$_REQUEST['return_module']}';this.form.name.value='';this.form.description.value=''";
  125. } else {
  126. $cancel_script.="'{$_REQUEST['return_id']}'";
  127. }
  128. }
  129. //Setup assigned user name
  130. $popup_request_data = array(
  131. 'call_back_function' => 'set_return',
  132. 'form_name' => 'EditView',
  133. 'field_to_name_array' => array(
  134. 'id' => 'assigned_user_id',
  135. 'user_name' => 'assigned_user_name',
  136. ),
  137. );
  138. $json = getJSONobj();
  139. $xtpl->assign('encoded_assigned_users_popup_request_data', $json->encode($popup_request_data));
  140. if(!empty($focus->assigned_user_name))
  141. $xtpl->assign("ASSIGNED_USER_NAME", $focus->assigned_user_name);
  142. $xtpl->assign("assign_user_select", SugarThemeRegistry::current()->getImage('id-ff-select'));
  143. $xtpl->assign("assign_user_clear", SugarThemeRegistry::current()->getImage('id-ff-clear'));
  144. //Assign qsd script
  145. require_once('include/QuickSearchDefaults.php');
  146. $qsd = new QuickSearchDefaults();
  147. $sqs_objects = array( 'EditView_assigned_user_name' => $qsd->getQSUser());
  148. $quicksearch_js = '<script type="text/javascript" language="javascript">sqs_objects = ' . $json->encode($sqs_objects) . '; enableQS();</script>';
  149. $xtpl->assign("CANCEL_SCRIPT", $cancel_script);
  150. $xtpl->assign("PRINT_URL", "index.php?".$GLOBALS['request_string']);
  151. $xtpl->assign("JAVASCRIPT", get_set_focus_js() . $quicksearch_js);
  152. if(!is_file($GLOBALS['sugar_config']['cache_dir'] . 'jsLanguage/' . $GLOBALS['current_language'] . '.js')) {
  153. require_once('include/language/jsLanguage.php');
  154. jsLanguage::createAppStringsCache($GLOBALS['current_language']);
  155. }
  156. $jsLang = '<script type="text/javascript" src="' . $GLOBALS['sugar_config']['cache_dir'] . 'jsLanguage/' . $GLOBALS['current_language'] . '.js?s=' . $GLOBALS['sugar_version'] . '&c=' . $GLOBALS['sugar_config']['js_custom_version'] . '&j=' . $GLOBALS['sugar_config']['js_lang_version'] . '"></script>';
  157. $xtpl->assign("JSLANG", $jsLang);
  158. $xtpl->assign("ID", $focus->id);
  159. if(isset($focus->name)) $xtpl->assign("NAME", $focus->name); else $xtpl->assign("NAME", "");
  160. if(isset($focus->description)) $xtpl->assign("DESCRIPTION", $focus->description); else $xtpl->assign("DESCRIPTION", "");
  161. if(isset($focus->subject)) $xtpl->assign("SUBJECT", $focus->subject); else $xtpl->assign("SUBJECT", "");
  162. if( $focus->published == 'on')
  163. {
  164. $xtpl->assign("PUBLISHED","CHECKED");
  165. }
  166. //if text only is set to true, then make sure input is checked and value set to 1
  167. if(isset($focus->text_only) && $focus->text_only){
  168. $xtpl->assign("TEXTONLY_CHECKED","CHECKED");
  169. $xtpl->assign("TEXTONLY_VALUE","1");
  170. }else{//set value to 0
  171. $xtpl->assign("TEXTONLY_VALUE","0");
  172. }
  173. $xtpl->assign("FIELD_DEFS_JS", $focus->generateFieldDefsJS());
  174. $xtpl->assign("LBL_CONTACT",$app_list_strings['moduleList']['Contacts']);
  175. global $current_user;
  176. if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])) {
  177. $record = '';
  178. if(!empty($_REQUEST['record'])) {
  179. $record = $_REQUEST['record'];
  180. }
  181. $xtpl->assign("ADMIN_EDIT","<a href='index.php?action=index&module=DynamicLayout&from_action=" . $_REQUEST['action']
  182. ."&from_module=".$_REQUEST['module'] ."&record=".$record. "'>".SugarThemeRegistry::current()->getImage("EditLayout","border='0' alt='Edit Layout' align='bottom'")."</a>");
  183. }
  184. if(isset($focus->parent_type) && $focus->parent_type != "") {
  185. $change_parent_button = "<input title='".$app_strings['LBL_SELECT_BUTTON_TITLE']."' accessKey='".$app_strings['LBL_SELECT_BUTTON_KEY']."'
  186. tabindex='3' type='button' class='button' value='".$app_strings['LBL_SELECT_BUTTON_LABEL']."' name='button' LANGUAGE=javascript onclick='return
  187. window.open(\"index.php?module=\"+ document.EditView.parent_type.value +
  188. \"&action=Popup&html=Popup_picker&form=TasksEditView\",\"test\",\"width=600,height=400,resizable=1,scrollbars=1\");'>";
  189. $xtpl->assign("CHANGE_PARENT_BUTTON", $change_parent_button);
  190. }
  191. if($focus->parent_type == "Account") {
  192. $xtpl->assign("DEFAULT_SEARCH","&query=true&account_id=$focus->parent_id&account_name=".urlencode($focus->parent_name));
  193. }
  194. $xtpl->assign("DESCRIPTION", $focus->description);
  195. $xtpl->assign("TYPE_OPTIONS", get_select_options_with_id($app_list_strings['record_type_display'], $focus->parent_type));
  196. //$xtpl->assign("DEFAULT_MODULE","Accounts");
  197. if(isset($focus->body)) $xtpl->assign("BODY", $focus->body); else $xtpl->assign("BODY", "");
  198. if(isset($focus->body_html)) $xtpl->assign("BODY_HTML", $focus->body_html); else $xtpl->assign("BODY_HTML", "");
  199. if(true) {
  200. if ( !isTouchScreen() ) {
  201. require_once("include/SugarTinyMCE.php");
  202. $tiny = new SugarTinyMCE();
  203. $tiny->defaultConfig['cleanup_on_startup']=true;
  204. $tiny->defaultConfig['height']=600;
  205. $tinyHtml = $tiny->getInstance();
  206. $xtpl->assign("tiny", $tinyHtml);
  207. }
  208. ///////////////////////////////////////
  209. //// MACRO VARS
  210. $xtpl->assign("INSERT_VARIABLE_ONCLICK", "insert_variable(document.EditView.variable_text.value)");
  211. if(!$inboundEmail){
  212. $xtpl->parse("main.NoInbound.variable_button");
  213. }
  214. ///////////////////////////////////////
  215. //// CAMPAIGNS
  216. if($has_campaign || $inboundEmail) {
  217. $xtpl->assign("INPOPUPWINDOW",'true');
  218. $xtpl->assign("INSERT_URL_ONCLICK", "insert_variable_html_link(document.EditView.tracker_url.value)");
  219. if($has_campaign){
  220. $campaign_urls=get_campaign_urls($_REQUEST['campaign_id']);
  221. }
  222. if(!empty($campaign_urls)) {
  223. $xtpl->assign("DEFAULT_URL_TEXT",key($campaign_urls));
  224. }
  225. if($has_campaign){
  226. $xtpl->assign("TRACKER_KEY_OPTIONS", get_select_options_with_id($campaign_urls, null));
  227. $xtpl->parse("main.NoInbound.tracker_url");
  228. }
  229. }
  230. // The insert variable drodown should be conditionally displayed.
  231. // If it's campaign then hide the Account.
  232. if($has_campaign) {
  233. $dropdown="<option value='Contacts'>
  234. ".$mod_strings['LBL_CONTACT_AND_OTHERS']."
  235. </option>";
  236. $xtpl->assign("DROPDOWN",$dropdown);
  237. $xtpl->assign("DEFAULT_MODULE",'Contacts');
  238. //$xtpl->assign("CAMPAIGN_POPUP_JS", '<script type="text/javascript" src="include/javascript/sugar_3.js"></script>');
  239. } else {
  240. $dropdown="<option value='Accounts'>
  241. ".$mod_strings['LBL_ACCOUNT']."
  242. </option>
  243. <option value='Contacts'>
  244. ".$mod_strings['LBL_CONTACT_AND_OTHERS']."
  245. </option>
  246. <option value='Users'>
  247. ".$mod_strings['LBL_USERS']."
  248. </option>";
  249. $xtpl->assign("DROPDOWN",$dropdown);
  250. $xtpl->assign("DEFAULT_MODULE",'Accounts');
  251. }
  252. //// END CAMPAIGNS
  253. ///////////////////////////////////////
  254. ///////////////////////////////////////
  255. //// ATTACHMENTS
  256. $attachments = '';
  257. if(!empty($focus->id)) {
  258. $etid = $focus->id;
  259. } elseif(!empty($old_id)) {
  260. $xtpl->assign('OLD_ID', $old_id);
  261. $etid = $old_id;
  262. }
  263. if(!empty($etid)) {
  264. $note = new Note();
  265. $where = "notes.parent_id='{$etid}' AND notes.filename IS NOT NULL";
  266. $notes_list = $note->get_full_list("", $where,true);
  267. if(!isset($notes_list)) {
  268. $notes_list = array();
  269. }
  270. for($i = 0;$i < count($notes_list);$i++) {
  271. $the_note = $notes_list[$i];
  272. if( empty($the_note->filename)) {
  273. continue;
  274. }
  275. $secureLink = 'index.php?entryPoint=download&id='.$the_note->id.'&type=Notes';
  276. $attachments .= '<input type="checkbox" name="remove_attachment[]" value="'.$the_note->id.'"> '.$app_strings['LNK_REMOVE'].'&nbsp;&nbsp;';
  277. $attachments .= '<a href="'.$secureLink.'" target="_blank">'. $the_note->filename .'</a><br>';
  278. }
  279. }
  280. $attJs = '<script type="text/javascript">';
  281. $attJs .= 'var file_path = "'.$sugar_config['site_url'].'/'.$sugar_config['upload_dir'].'";';
  282. $attJs .= 'var lnk_remove = "'.$app_strings['LNK_REMOVE'].'";';
  283. $attJs .= '</script>';
  284. $xtpl->assign('ATTACHMENTS', $attachments);
  285. $xtpl->assign('ATTACHMENTS_JAVASCRIPT', $attJs);
  286. //// END ATTACHMENTS
  287. ///////////////////////////////////////
  288. // done and parse
  289. $xtpl->parse("main.textarea");
  290. }
  291. //Add Custom Fields
  292. require_once('modules/DynamicFields/templates/Files/EditView.php');
  293. if(!$inboundEmail){
  294. $xtpl->parse("main.NoInbound");
  295. $xtpl->parse("main.NoInbound1");
  296. $xtpl->parse("main.NoInbound2");
  297. $xtpl->parse("main.NoInbound3");
  298. $xtpl->parse("main.NoInbound4");
  299. $xtpl->parse("main.NoInbound5");
  300. }
  301. $xtpl->parse("main");
  302. $xtpl->out("main");
  303. $javascript = new javascript();
  304. $javascript->setFormName('EditView');
  305. $javascript->setSugarBean($focus);
  306. $javascript->addAllFields('');
  307. echo $javascript->getScript();
  308. ?>