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