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-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 /*********************************************************************************
40 * Description: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
47 require_once('include/EditView/EditView2.php');
49 require_once('modules/Campaigns/utils.php');
52 require_once('modules/Campaigns/utils.php');
54 global $mod_strings, $app_list_strings, $app_strings, $current_user, $import_bean_map;
55 global $import_file_name, $theme;$app_list_strings;
59 $xtpl=new XTemplate ('modules/Campaigns/WebToLeadCreation.html');
60 $xtpl->assign("MOD", $mod_strings);
61 $xtpl->assign("APP", $app_strings);
62 if(isset($_REQUEST['module']))
64 $xtpl->assign("MODULE", $_REQUEST['module']);
66 if(isset($_REQUEST['return_module']))
68 $xtpl->assign("RETURN_MODULE", $_REQUEST['return_module']);
70 if(isset($_REQUEST['return_id']))
72 $xtpl->assign("RETURN_ID", $_REQUEST['return_id']);
74 if(isset($_REQUEST['return_id']))
76 $xtpl->assign("RETURN_ACTION", $_REQUEST['return_action']);
78 if(isset($_REQUEST['record']))
80 $xtpl->assign("RECORD", $_REQUEST['record']);
84 global $currentModule;
88 $xtpl->assign("TITLE1",
89 $this->getModuleTitle(
92 $this->_getModuleTitleListParam(),
93 $mod_strings['LBL_WEB_TO_LEAD_FORM_TITLE1']
98 $xtpl->assign("TITLE2",
99 $this->getModuleTitle(
102 $this->_getModuleTitleListParam(),
103 $mod_strings['LBL_WEB_TO_LEAD_FORM_TITLE2']
108 $site_url = $sugar_config['site_url'];
109 $web_post_url = $site_url.'/index.php?entryPoint=WebToLeadCapture';
110 $json = getJSONobj();
112 $popup_request_data = array(
113 'call_back_function' => 'set_return',
114 'form_name' => 'WebToLeadCreation',
115 'field_to_name_array' => array(
116 'id' => 'assigned_user_id',
117 'user_name' => 'assigned_user_name',
120 $xtpl->assign('encoded_users_popup_request_data', $json->encode($popup_request_data));
123 $popup_request_data = array(
124 'call_back_function' => 'set_return',
125 'form_name' => 'WebToLeadCreation',
126 'field_to_name_array' => array(
127 'id' => 'campaign_id',
128 'name' => 'campaign_name',
131 $encoded_users_popup_request_data = $json->encode($popup_request_data);
132 $xtpl->assign('encoded_campaigns_popup_request_data' , $json->encode($popup_request_data));
134 //create the cancel button
135 $cancel_buttons_html = "<input class='button' onclick=\"this.form.action.value='".$_REQUEST['return_action']."'; this.form.module.value='".$_REQUEST['return_module']."';\" type='submit' name='cancel' value='".$app_strings['LBL_BACK']."'/>";
136 $xtpl->assign("CANCEL_BUTTON", $cancel_buttons_html );
138 $field_defs_js = "var field_defs = {'Contacts':[";
140 //bug: 47574 - make sure, that webtolead_email1 field has same required attribute as email1 field
141 if(isset($lead->field_defs['webtolead_email1']) && isset($lead->field_defs['email1']) && isset($lead->field_defs['email1']['required'])){
142 $lead->field_defs['webtolead_email1']['required'] = $lead->field_defs['email1']['required'];
146 foreach($lead->field_defs as $field_def)
148 $email_fields = false;
149 if($field_def['name']== 'email1' || $field_def['name']== 'email2')
151 $email_fields = true;
153 if($field_def['name']!= 'account_name'){
154 if( ( $field_def['type'] == 'relate' && empty($field_def['custom_type']) )
155 || $field_def['type'] == 'assigned_user_name' || $field_def['type'] =='link'
156 || (isset($field_def['source']) && $field_def['source']=='non-db' && !$email_fields) || $field_def['type'] == 'id')
161 if($field_def['name']== 'deleted' || $field_def['name']=='converted' || $field_def['name']=='date_entered'
162 || $field_def['name']== 'date_modified' || $field_def['name']=='modified_user_id'
163 || $field_def['name']=='assigned_user_id' || $field_def['name']=='created_by'
164 || $field_def['name']=='team_id')
170 $field_def['vname'] = preg_replace('/:$/','',translate($field_def['vname'],'Leads'));
172 //$cols_name = "{'".$field_def['vname']."'}";
174 if((isset($field_def['required']) && $field_def['required'] != null && $field_def['required'] != 0)
175 || $field_def['name']=='last_name'
177 $cols_name=$field_def['vname'].' '.$app_strings['LBL_REQUIRED_SYMBOL'];
178 $col_arr[0]=$cols_name;
179 $col_arr[1]=$field_def['name'];
183 $cols_name=$field_def['vname'];
184 $col_arr[0]=$cols_name;
185 $col_arr[1]=$field_def['name'];
187 if (! in_array($cols_name, $fields))
189 array_push($fields,$col_arr);
194 $xtpl->assign("WEB_POST_URL",$web_post_url);
195 //$xtpl->assign("LEAD_SELECT_FIELDS",'MOD.LBL_SELECT_LEAD_FIELDS');
197 require_once('include/QuickSearchDefaults.php');
198 $qsd = QuickSearchDefaults::getQuickSearchDefaults();
199 $sqs_objects = array('account_name' => $qsd->getQSParent(),
200 'assigned_user_name' => $qsd->getQSUser(),
201 'campaign_name' => $qsd->getQSCampaigns(),
204 $quicksearch_js = '<script type="text/javascript" language="javascript">sqs_objects = ' . $json->encode($sqs_objects) . '</script>';
205 $xtpl->assign("JAVASCRIPT", $quicksearch_js);
209 if (empty($focus->assigned_user_id) && empty($focus->id)) $focus->assigned_user_id = $current_user->id;
210 if (empty($focus->assigned_name) && empty($focus->id)) $focus->assigned_user_name = $current_user->user_name;
211 $xtpl->assign("ASSIGNED_USER_OPTIONS", get_select_options_with_id(get_user_array(TRUE, "Active", $focus->assigned_user_id), $focus->assigned_user_id));
212 $xtpl->assign("ASSIGNED_USER_NAME", $focus->assigned_user_name);
213 $xtpl->assign("ASSIGNED_USER_ID", $focus->assigned_user_id );
215 $xtpl->assign("REDIRECT_URL_DEFAULT",'http://');
217 //required fields on Webtolead form
218 $campaign= new Campaign();
220 $javascript = new javascript();
221 $javascript->setFormName('WebToLeadCreation');
222 $javascript->setSugarBean($lead);
223 $javascript->addAllFields('');
224 //$javascript->addFieldGeneric('redirect_url', '', 'LBL_REDIRECT_URL' ,'true');
225 $javascript->addFieldGeneric('campaign_name', '', 'LBL_RELATED_CAMPAIGN' ,'true');
226 $javascript->addFieldGeneric('assigned_user_name', '', 'LBL_ASSIGNED_TO' ,'true');
227 $javascript->addToValidateBinaryDependency('campaign_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $mod_strings['LBL_LEAD_NOTIFY_CAMPAIGN'], 'false', '', 'campaign_id');
228 $javascript->addToValidateBinaryDependency('assigned_user_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ASSIGNED_TO'], 'false', '', 'assigned_user_id');
229 echo $javascript->getScript();
231 $json = getJSONobj();
232 $lead_fields = $json->encode($fields);
233 $xtpl->assign("LEAD_FIELDS",$lead_fields);
234 $classname = "SUGAR_GRID";
235 $xtpl->assign("CLASSNAME",$classname);
236 $xtpl->assign("DRAG_DROP_CHOOSER_WEB_TO_LEAD",constructDDWebToLeadFields($fields,$classname));
238 $xtpl->parse("main");
242 WebToLeadForm.lead_fields = {$lead_fields};
247 *This function constructs Drag and Drop multiselect box of subscriptions for display in manage subscription form
249 function constructDDWebToLeadFields($fields,$classname){
250 require_once("include/templates/TemplateDragDropChooser.php");
253 //now call function that creates javascript for invoking DDChooser object
254 $dd_chooser = new TemplateDragDropChooser();
255 $dd_chooser->args['classname'] = $classname;
256 $dd_chooser->args['left_header'] = $mod_strings['LBL_AVALAIBLE_FIELDS_HEADER'];
257 $dd_chooser->args['mid_header'] = $mod_strings['LBL_LEAD_FORM_FIRST_HEADER'];
258 $dd_chooser->args['right_header'] = $mod_strings['LBL_LEAD_FORM_SECOND_HEADER'];
259 $dd_chooser->args['left_data'] = $fields;
260 $dd_chooser->args['mid_data'] = $d2;
261 $dd_chooser->args['right_data'] = $d2;
262 $dd_chooser->args['title'] = ' ';
263 $dd_chooser->args['left_div_name'] = 'ddgrid2';
264 $dd_chooser->args['mid_div_name'] = 'ddgrid3';
265 $dd_chooser->args['right_div_name'] = 'ddgrid4';
266 $dd_chooser->args['gridcount'] = 'three';
267 $str = $dd_chooser->displayScriptTags();
268 $str .= $dd_chooser->displayDefinitionScript();
269 $str .= $dd_chooser->display();
272 function postMoveRows(){
273 //Call other function when this is called
277 function displayAddRemoveDragButtons(Add_All_Fields,Remove_All_Fields){
278 var addRemove = document.getElementById('lead_add_remove_button');
279 if(" . $dd_chooser->args['classname'] . "_grid0.getDataModel().getTotalRowCount() ==0) {
280 addRemove.setAttribute('value',Remove_All_Fields);
281 addRemove.setAttribute('title',Remove_All_Fields);
283 else if(" . $dd_chooser->args['classname'] . "_grid1.getDataModel().getTotalRowCount() ==0 && " . $dd_chooser->args['classname'] . "_grid2.getDataModel().getTotalRowCount() ==0){
284 addRemove.setAttribute('value',Add_All_Fields);
285 addRemove.setAttribute('title',Add_All_Fields);
294 * function to retrieve webtolead image and title. path to help file
295 * refactored to use SugarView::getModuleTitle()
297 * @deprecated use SugarView::getModuleTitle() instead
299 * @param $module string not used, only for backward compatibility
300 * @param $image_name string image name
301 * @param $module_title string to display as the module title
302 * @param $show_help boolean which determines if the print and help links are shown.
303 * @return string HTML
305 function get_webtolead_title(
312 return $GLOBALS['current_view']->getModuleTitle($show_help);