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.
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':[";
141 foreach($lead->field_defs as $field_def)
143 $email_fields = false;
144 if($field_def['name']== 'webtolead_email1' || $field_def['name']== 'webtolead_email2')
146 $email_fields = true;
148 if($field_def['name']!= 'account_name'){
149 if( ( $field_def['type'] == 'relate' && empty($field_def['custom_type']) )
150 || $field_def['type'] == 'assigned_user_name' || $field_def['type'] =='link'
151 || (isset($field_def['source']) && $field_def['source']=='non-db' && !$email_fields) || $field_def['type'] == 'id')
156 if($field_def['name']== 'deleted' || $field_def['name']=='converted' || $field_def['name']=='date_entered'
157 || $field_def['name']== 'date_modified' || $field_def['name']=='modified_user_id'
158 || $field_def['name']=='assigned_user_id' || $field_def['name']=='created_by'
159 || $field_def['name']=='team_id')
165 $field_def['vname'] = preg_replace('/:$/','',translate($field_def['vname'],'Leads'));
167 //$cols_name = "{'".$field_def['vname']."'}";
169 if((isset($field_def['required']) && $field_def['required'] != null && $field_def['required'] != 0)
170 || $field_def['name']=='last_name'
172 $cols_name=$field_def['vname'].' '.$app_strings['LBL_REQUIRED_SYMBOL'];
173 $col_arr[0]=$cols_name;
174 $col_arr[1]=$field_def['name'];
178 $cols_name=$field_def['vname'];
179 $col_arr[0]=$cols_name;
180 $col_arr[1]=$field_def['name'];
182 if (! in_array($cols_name, $fields))
184 array_push($fields,$col_arr);
189 $xtpl->assign("WEB_POST_URL",$web_post_url);
190 //$xtpl->assign("LEAD_SELECT_FIELDS",'MOD.LBL_SELECT_LEAD_FIELDS');
192 require_once('include/QuickSearchDefaults.php');
193 $qsd = new QuickSearchDefaults();
194 $sqs_objects = array('account_name' => $qsd->getQSParent(),
195 'assigned_user_name' => $qsd->getQSUser(),
196 'campaign_name' => $qsd->getQSCampaigns(),
199 $quicksearch_js = '<script type="text/javascript" language="javascript">sqs_objects = ' . $json->encode($sqs_objects) . '</script>';
200 $xtpl->assign("JAVASCRIPT", $quicksearch_js);
204 if (empty($focus->assigned_user_id) && empty($focus->id)) $focus->assigned_user_id = $current_user->id;
205 if (empty($focus->assigned_name) && empty($focus->id)) $focus->assigned_user_name = $current_user->user_name;
206 $xtpl->assign("ASSIGNED_USER_OPTIONS", get_select_options_with_id(get_user_array(TRUE, "Active", $focus->assigned_user_id), $focus->assigned_user_id));
207 $xtpl->assign("ASSIGNED_USER_NAME", $focus->assigned_user_name);
208 $xtpl->assign("ASSIGNED_USER_ID", $focus->assigned_user_id );
210 $xtpl->assign("REDIRECT_URL_DEFAULT",'http://');
212 //required fields on Webtolead form
213 $campaign= new Campaign();
215 $javascript = new javascript();
216 $javascript->setFormName('WebToLeadCreation');
217 $javascript->setSugarBean($lead);
218 $javascript->addAllFields('');
219 //$javascript->addFieldGeneric('redirect_url', '', 'LBL_REDIRECT_URL' ,'true');
220 $javascript->addFieldGeneric('campaign_name', '', 'LBL_RELATED_CAMPAIGN' ,'true');
221 $javascript->addFieldGeneric('assigned_user_name', '', 'LBL_ASSIGNED_TO' ,'true');
222 $javascript->addToValidateBinaryDependency('campaign_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $mod_strings['LBL_LEAD_NOTIFY_CAMPAIGN'], 'false', '', 'campaign_id');
223 $javascript->addToValidateBinaryDependency('assigned_user_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ASSIGNED_TO'], 'false', '', 'assigned_user_id');
224 echo $javascript->getScript();
226 $json = getJSONobj();
227 $lead_fields = $json->encode($fields);
228 $xtpl->assign("LEAD_FIELDS",$lead_fields);
229 $classname = "SUGAR_GRID";
230 $xtpl->assign("CLASSNAME",$classname);
231 $xtpl->assign("DRAG_DROP_CHOOSER_WEB_TO_LEAD",constructDDWebToLeadFields($fields,$classname));
233 $xtpl->parse("main");
237 WebToLeadForm.lead_fields = {$lead_fields};
242 *This function constructs Drag and Drop multiselect box of subscriptions for display in manage subscription form
244 function constructDDWebToLeadFields($fields,$classname){
245 require_once("include/templates/TemplateDragDropChooser.php");
248 //now call function that creates javascript for invoking DDChooser object
249 $dd_chooser = new TemplateDragDropChooser();
250 $dd_chooser->args['classname'] = $classname;
251 $dd_chooser->args['left_header'] = $mod_strings['LBL_AVALAIBLE_FIELDS_HEADER'];
252 $dd_chooser->args['mid_header'] = $mod_strings['LBL_LEAD_FORM_FIRST_HEADER'];
253 $dd_chooser->args['right_header'] = $mod_strings['LBL_LEAD_FORM_SECOND_HEADER'];
254 $dd_chooser->args['left_data'] = $fields;
255 $dd_chooser->args['mid_data'] = $d2;
256 $dd_chooser->args['right_data'] = $d2;
257 $dd_chooser->args['title'] = ' ';
258 $dd_chooser->args['left_div_name'] = 'ddgrid2';
259 $dd_chooser->args['mid_div_name'] = 'ddgrid3';
260 $dd_chooser->args['right_div_name'] = 'ddgrid4';
261 $dd_chooser->args['gridcount'] = 'three';
262 $str = $dd_chooser->displayScriptTags();
263 $str .= $dd_chooser->displayDefinitionScript();
264 $str .= $dd_chooser->display();
267 function postMoveRows(){
268 //Call other function when this is called
272 function displayAddRemoveDragButtons(Add_All_Fields,Remove_All_Fields){
273 var addRemove = document.getElementById('lead_add_remove_button');
274 if(" . $dd_chooser->args['classname'] . "_grid0.getDataModel().getTotalRowCount() ==0) {
275 addRemove.setAttribute('value',Remove_All_Fields);
276 addRemove.setAttribute('title',Remove_All_Fields);
278 else if(" . $dd_chooser->args['classname'] . "_grid1.getDataModel().getTotalRowCount() ==0 && " . $dd_chooser->args['classname'] . "_grid2.getDataModel().getTotalRowCount() ==0){
279 addRemove.setAttribute('value',Add_All_Fields);
280 addRemove.setAttribute('title',Add_All_Fields);
289 * function to retrieve webtolead image and title. path to help file
290 * refactored to use SugarView::getModuleTitle()
292 * @deprecated use SugarView::getModuleTitle() instead
294 * @param $module string not used, only for backward compatibility
295 * @param $image_name string image name
296 * @param $module_title string to display as the module title
297 * @param $show_help boolean which determines if the print and help links are shown.
298 * @return string HTML
300 function get_webtolead_title(
307 return $GLOBALS['current_view']->getModuleTitle($show_help);