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 ********************************************************************************/
45 require_once('include/formbase.php');
50 require_once('include/utils/db_utils.php');
55 global $app_list_strings, $app_strings,$mod_strings;
57 $site_url = $sugar_config['site_url'];
58 $web_form_header = $mod_strings['LBL_LEAD_DEFAULT_HEADER'];
59 $web_form_description = $mod_strings['LBL_DESCRIPTION_TEXT_LEAD_FORM'];
60 $web_form_submit_label = $mod_strings['LBL_DEFAULT_LEAD_SUBMIT'];
61 $web_form_required_fileds_msg = $mod_strings['LBL_PROVIDE_WEB_TO_LEAD_FORM_FIELDS'];
62 $web_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
63 $web_not_valid_email_address = $mod_strings['LBL_NOT_VALID_EMAIL_ADDRESS'];
64 $web_post_url = $site_url.'/index.php?entryPoint=WebToLeadCapture';
65 $web_redirect_url = '';
66 $web_notify_campaign = '';
67 $web_assigned_user = '';
69 $web_form_footer = '';
70 $regex = "/^\w+(['\.\-\+]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+\$/";
71 //_ppd($web_required_symbol);
72 if(!empty($_REQUEST['web_header'])){
73 $web_form_header= $_REQUEST['web_header'];
75 if(!empty($_REQUEST['web_description'])){
76 $web_form_description= $_REQUEST['web_description'];
78 if(!empty($_REQUEST['web_submit'])){
79 $web_form_submit_label=to_html($_REQUEST['web_submit']);
81 if(!empty($_REQUEST['post_url'])){
82 $web_post_url= $_REQUEST['post_url'];
84 if(!empty($_REQUEST['redirect_url']) && $_REQUEST['redirect_url'] !="http://"){
85 $web_redirect_url= $_REQUEST['redirect_url'];
87 if(!empty($_REQUEST['notify_campaign'])){
88 $web_notify_campaign = $_REQUEST['notify_campaign'];
90 if(!empty($_REQUEST['web_footer'])){
91 $web_form_footer= $_REQUEST['web_footer'];
93 if(!empty($_REQUEST['campaign_id'])){
94 $web_form_campaign= $_REQUEST['campaign_id'];
96 if(!empty($_REQUEST['assigned_user_id'])){
97 $web_assigned_user = $_REQUEST['assigned_user_id'];
102 $fieldsMetaData = new FieldsMetaData();
103 $xtpl=new XTemplate ('modules/Campaigns/WebToLeadForm.html');
104 $xtpl->assign("MOD", $mod_strings);
105 $xtpl->assign("APP", $app_strings);
106 $Web_To_Lead_Form_html = '';
107 $Web_To_Lead_Form_html .='<link rel="stylesheet" type="text/css" media="all" href="' . getJSPath(SugarThemeRegistry::current()->getCSSURL('calendar-win2k-cold-1.css')) . '">';
109 $Web_To_Lead_Form_html .= "<script type=\"text/javascript\" src='" . getJSPath($site_url.'/cache/include/javascript/sugar_grp1.js') . "'></script>";
110 $Web_To_Lead_Form_html .= '<script type="text/javascript" src="' . getJSPath($site_url.'/cache/include/javascript/calendar.js') . '"></script>';
112 $Web_To_Lead_Form_html .="<form action='$web_post_url' name='WebToLeadForm' method='POST' id='WebToLeadForm'>";
113 $Web_To_Lead_Form_html .= "<table width='100%' style='border-top: 1px solid;
114 border-bottom: 1px solid;
115 padding: 10px 6px 12px 10px;
116 background-color: rgb(233, 243, 255);
118 background-repeat: repeat-x;
119 background-position: center top;'>";
121 $Web_To_Lead_Form_html .= "<tr align='center' style='color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 18px; font-weight: bold; margin-bottom: 0px; margin-top: 0px;'><TD COLSPAN='4'><b><h2>$web_form_header</h2></b></TD></tr>";
122 $Web_To_Lead_Form_html .= "<tr align='center' style='color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 2px; font-weight: normal; margin-bottom: 0px; margin-top: 0px;'><TD COLSPAN='4'> </TD></tr>";
123 $Web_To_Lead_Form_html .= "<tr align='left' style='color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 12px; font-weight: normal; margin-bottom: 0px; margin-top: 0px;'><TD COLSPAN='4'>$web_form_description</TD></tr>";
124 $Web_To_Lead_Form_html .= "<tr align='center' style='color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 8px; font-weight: normal; margin-bottom: 0px; margin-top: 0px;'><TD COLSPAN='4'> </TD></tr>";
126 //$Web_To_Lead_Form_html .= "\n<p>\n";
128 if(!empty($_REQUEST['colsFirst']) && !empty($_REQUEST['colsSecond'])){
129 if(count($_REQUEST['colsFirst']) < count($_REQUEST['colsSecond'])){
130 $columns= count($_REQUEST['colsSecond']);
132 if(count($_REQUEST['colsFirst']) > count($_REQUEST['colsSecond']) || count($_REQUEST['colsFirst']) == count($_REQUEST['colsSecond'])){
133 $columns= count($_REQUEST['colsFirst']);
136 else if(!empty($_REQUEST['colsFirst'])){
137 $columns= count($_REQUEST['colsFirst']);
139 else if(!empty($_REQUEST['colsSecond'])){
140 $columns= count($_REQUEST['colsSecond']);
144 $required_fields = array();
145 $bool_fields = array();
146 for($i= 0; $i<$columns;$i++){
147 $colsFirstField = '';
148 $colsSecondField = '';
150 if(!empty($_REQUEST['colsFirst'][$i])){
151 $colsFirstField = $_REQUEST['colsFirst'][$i];
152 //_pp($_REQUEST['colsFirst']);
154 if(!empty($_REQUEST['colsSecond'][$i])){
155 $colsSecondField = $_REQUEST['colsSecond'][$i];
156 //_pp($_REQUEST['colsSecond']);
159 if(isset($lead->field_defs[$colsFirstField]) && $lead->field_defs[$colsFirstField] != null)
161 $field_vname = preg_replace('/:$/','',translate($lead->field_defs[$colsFirstField]['vname'],'Leads'));
162 $field_name = $colsFirstField;
163 $field_label = $field_vname .": ";
164 if(isset($lead->field_defs[$colsFirstField]['custom_type']) && $lead->field_defs[$colsFirstField]['custom_type'] != null){
165 $field_type= $lead->field_defs[$colsFirstField]['custom_type'];
168 $field_type= $lead->field_defs[$colsFirstField]['type'];
171 //bug: 47574 - make sure, that webtolead_email1 field has same required attribute as email1 field
172 if($colsFirstField == 'webtolead_email1' && isset($lead->field_defs['email1']) && isset($lead->field_defs['email1']['required'])){
173 $lead->field_defs['webtolead_email1']['required'] = $lead->field_defs['email1']['required'];
176 $field_required = '';
177 if(isset($lead->field_defs[$colsFirstField]['required']) && $lead->field_defs[$colsFirstField]['required'] != null
178 && $lead->field_defs[$colsFirstField]['required'] != 0)
180 $field_required = $lead->field_defs[$colsFirstField]['required'];
181 if (! in_array($lead->field_defs[$colsFirstField]['name'], $required_fields)){
182 array_push($required_fields,$lead->field_defs[$colsFirstField]['name']);
185 if($lead->field_defs[$colsFirstField]['name']=='last_name'){
186 if (! in_array($lead->field_defs[$colsFirstField]['name'], $required_fields)){
187 array_push($required_fields,$lead->field_defs[$colsFirstField]['name']);
190 if($field_type=='multienum' || $field_type=='enum' || $field_type=='radioenum') $field_options= $lead->field_defs[$colsFirstField]['options'];
192 //preg_replace('/:$/','',translate($field_def['vname'],'Leads')
193 if(isset($lead->field_defs[$colsSecondField]) && $lead->field_defs[$colsSecondField] != null)
195 $field1_vname= preg_replace('/:$/','',translate($lead->field_defs[$colsSecondField]['vname'],'Leads'));
196 $field1_name= $colsSecondField;
197 $field1_label = $field1_vname .": ";
198 if(isset($lead->field_defs[$colsSecondField]['custom_type']) && $lead->field_defs[$colsSecondField]['custom_type'] != null){
199 $field1_type= $lead->field_defs[$colsSecondField]['custom_type'];
202 $field1_type= $lead->field_defs[$colsSecondField]['type'];
205 //bug: 47574 - make sure, that webtolead_email1 field has same required attribute as email1 field
206 if($colsSecondField == 'webtolead_email1' && isset($lead->field_defs['email1']) && isset($lead->field_defs['email1']['required'])){
207 $lead->field_defs['webtolead_email1']['required'] = $lead->field_defs['email1']['required'];
210 $field1_required = '';
211 if(isset($lead->field_defs[$colsSecondField]['required']) && $lead->field_defs[$colsSecondField]['required'] != null
212 && $lead->field_defs[$colsSecondField]['required'] != 0){
213 $field1_required = $lead->field_defs[$colsSecondField]['required'];
214 if (! in_array($lead->field_defs[$colsSecondField]['name'], $required_fields)){
215 array_push($required_fields,$lead->field_defs[$colsSecondField]['name']);
218 if($lead->field_defs[$colsSecondField]['name']=='last_name'){
219 if (! in_array($lead->field_defs[$colsSecondField]['name'], $required_fields)){
220 array_push($required_fields,$lead->field_defs[$colsSecondField]['name']);
223 if($field1_type=='multienum' || $field1_type=='enum' || $field1_type=='radioenum') $field1_options= $lead->field_defs[$colsSecondField]['options'];
226 $Web_To_Lead_Form_html .= "<tr>";
228 if(isset($lead->field_defs[$colsFirstField]) && $lead->field_defs[$colsFirstField] != null){
229 if($field_type=='multienum' || $field_type=='enum' || $field_type=='radioenum'){
231 if(!empty($lead->$field_name)){
232 $lead_options= get_select_options_with_id($app_list_strings[$field_options], unencodeMultienum($lead->$field_name));
235 $lead_options= get_select_options_with_id($app_list_strings[$field_options], '');
238 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'><span class='required' style='color: rgb(255, 0, 0);'>$web_required_symbol</span></td>";
241 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'></td>";
243 if(isset($lead->field_defs[$colsFirstField]['isMultiSelect']) && $lead->field_defs[$colsFirstField]['isMultiSelect'] ==1){
244 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><select id='{$field_name}' multiple='true' name='{$field_name}[]' tabindex='1'>$lead_options</select></span sugar='slot'></td>";
245 }elseif(ifRadioButton($lead->field_defs[$colsFirstField]['name'])){
246 $Web_To_Lead_Form_html .="<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'>";
247 foreach($app_list_strings[$field_options] as $field_option_key => $field_option){
248 if($field_option != null){
249 if(!empty($lead->$field_name) && in_array($field_option_key,unencodeMultienum($lead->$field_name))){
250 $Web_To_Lead_Form_html .="<input id='$colsFirstField"."_$field_option_key' checked name='$colsFirstField' value='$field_option_key' type='radio'>";
252 $Web_To_Lead_Form_html .="<input id='$colsFirstField"."_$field_option_key' name='$colsFirstField' value='$field_option_key' type='radio'>";
254 $Web_To_Lead_Form_html .="<span ='document.getElementById('".$lead->field_defs[$colsFirstField]."_$field_option_key').checked =true style='cursor:default'; onmousedown='return false;'>$field_option</span><br>";
257 $Web_To_Lead_Form_html .="</span sugar='slot'></td>";
259 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><select id=$field_name name=$field_name tabindex='1'>$lead_options</select></span sugar='slot'></td>";
262 if($field_type=='bool'){
264 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'><span class='required' style='color: rgb(255, 0, 0);'>$web_required_symbol</span></td>";
267 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'></td>";
269 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><input type='checkbox' id=$field_name name=$field_name></span sugar='slot'></td>";
270 if (! in_array($lead->field_defs[$colsFirstField]['name'], $bool_fields)){
271 array_push($bool_fields,$lead->field_defs[$colsFirstField]['name']);
274 if($field_type=='date') {
277 $cal_dateformat = $timedate->get_cal_date_format();
278 $LBL_ENTER_DATE = translate('LBL_ENTER_DATE', 'Charts');
280 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'><span class='required' style='color: rgb(255, 0, 0);'>$web_required_symbol</span></td>";
283 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'></td>";
286 $Web_To_Lead_Form_html .= "
287 <td width='35%' style='font-size: 12px; font-weight: normal;'>
288 <script type='text/javascript'>
289 update{$field_name}Value = function() {
290 var format = '{$cal_dateformat}';
291 var month = document.getElementById('{$field_name}_month').value;
292 var day = document.getElementById('{$field_name}_day').value;
293 var year = document.getElementById('{$field_name}_year').value;
294 var val = format.replace('%m', month).replace('%d', day).replace('%Y', year);
295 if (!parseInt(month) > 0 || !parseInt(year) > 0 || !parseInt(year) > 0)
297 document.getElementById('{$field_name}').value = val;
300 <span sugar='slot'><input type='hidden' id='{$field_name}' name='{$field_name}'/>";
301 $order = explode("%", $cal_dateformat);
302 foreach($order as $part)
304 if (!isset($part[0]))
306 if (strToUpper($part[0]) == "M" )
307 $Web_To_Lead_Form_html .= translate("LBL_MONTH") . ":<input class=\"text\"
308 name=\"{$field_name}_month\" size='2' maxlength='2' id='{$field_name}_month' value=''
309 onblur=\"update{$field_name}Value()\">";
310 else if (strToUpper($part[0]) == "D" )
311 $Web_To_Lead_Form_html .= translate("LBL_DAY") . ":<input class=\"text\"
312 name=\"{$field_name}_day\" size='2' maxlength='2' id='{$field_name}_day' value=''
313 onblur=\"update{$field_name}Value()\">";
314 else if (strToUpper($part[0]) == "Y" )
315 $Web_To_Lead_Form_html .= translate("LBL_YEAR") . ":<input class=\"text\"
316 name=\"{$field_name}_year\" size='4' maxlength='4' id='{$field_name}_year' value=''
317 onblur=\"update{$field_name}Value()\">";
319 $Web_To_Lead_Form_html .= "</span></td>";
322 if( $field_type=='varchar' || $field_type=='name'
323 || $field_type=='phone' || $field_type=='currency' || $field_type=='url' || $field_type=='int'){
324 if($field_name=='last_name' || $field_required){
325 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'><span class='required' style='color: rgb(255, 0, 0);'>$web_required_symbol</span></td>";
328 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'></td>";
330 if ( $field_name=='email1'||$field_name=='email2' ){
331 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><input id=$field_name name=$field_name type='text' onchange='validateEmailAdd();'></span sugar='slot'></td>";
333 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><input id=$field_name name=$field_name type='text'></span sugar='slot'></td>";
336 if ( $field_type == 'text' ) {
337 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'></td>";
338 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span id='ta_replace' sugar='slot'><input id=$field_name name=$field_name type='text'></span sugar='slot'></td>";
340 if($field_type=='relate' && $field_name=='account_name'){
341 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'></td>";
342 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><input id=$field_name name=$field_name type='text'></span sugar='slot'></td>";
344 if($field_type=='email'){
346 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'><span class='required' style='color: rgb(255, 0, 0);'>$web_required_symbol</span></td>";
349 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field_label</span sugar='slot'></td>";
351 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><input id=$field_name name=$field_name type='text' onchange='validateEmailAdd();'></span sugar='slot'></td>";
355 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'> </span sugar='slot'></td>";
356 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'> </span sugar='slot'></td>";
359 if(isset($lead->field_defs[$colsSecondField]) && $lead->field_defs[$colsSecondField] != null){
360 if($field1_type=='multienum' || $field1_type=='enum' || $field1_type=='radioenum'){
362 if(!empty($lead->$field1_name)){
363 $lead1_options= get_select_options_with_id($app_list_strings[$field1_options], unencodeMultienum($lead->$field1_name));
366 $lead1_options= get_select_options_with_id($app_list_strings[$field1_options], '');
368 if($field1_required){
369 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'><span class='required' style='color: rgb(255, 0, 0);'>$web_required_symbol</span></td>";
372 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'></td>";
374 if(isset($lead->field_defs[$colsSecondField]['isMultiSelect']) && $lead->field_defs[$colsSecondField]['isMultiSelect'] ==1){
375 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><select id='{$field1_name}' name='{$field1_name}[]' multiple='true' tabindex='1'>$lead1_options</select></span sugar='slot'></td>";
376 }elseif(ifRadioButton($lead->field_defs[$colsSecondField]['name'])){
377 $Web_To_Lead_Form_html .="<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'>";
378 foreach($app_list_strings[$field1_options] as $field_option_key => $field_option){
379 if($field_option != null){
380 if(!empty($lead->$field1_name) && in_array($field_option_key,unencodeMultienum($lead->$field1_name))){
381 $Web_To_Lead_Form_html .="<input id='$colsSecondField"."_$field_option_key' checked name='$colsSecondField' value='$field_option_key' type='radio'>";
383 $Web_To_Lead_Form_html .="<input id='$colsSecondField"."_$field_option_key' name='$colsSecondField' value='$field_option_key' type='radio'>";
385 $Web_To_Lead_Form_html .="<span ='document.getElementById('".$lead->field_defs[$colsSecondField]."_$field_option_key').checked =true style='cursor:default'; onmousedown='return false;'>$field_option</span><br>";
388 $Web_To_Lead_Form_html .="</span sugar='slot'></td>";
390 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><select id=$field1_name name=$field1_name tabindex='1'>$lead1_options</select></span sugar='slot'></td>";
393 if($field1_type=='bool'){
394 if($field1_required){
395 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'><span class='required' style='color: rgb(255, 0, 0);'>$web_required_symbol</span></td>";
398 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'></td>";
400 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><input id=$field1_name name=$field1_name type='checkbox'></span sugar='slot'></td>";
401 if (! in_array($lead->field_defs[$colsSecondField]['name'], $bool_fields)){
402 array_push($bool_fields,$lead->field_defs[$colsSecondField]['name']);
405 if($field1_type=='date') {
407 $cal_dateformat = $timedate->get_cal_date_format();
408 $LBL_ENTER_DATE = translate('LBL_ENTER_DATE', 'Charts');
409 if($field1_required){
410 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'><span class='required' style='color: rgb(255, 0, 0);'>$web_required_symbol</span></td>";
413 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'></td>";
415 $Web_To_Lead_Form_html .= "
416 <td width='35%' style='font-size: 12px; font-weight: normal;'>
417 <script type='text/javascript'>
418 update{$field1_name}Value = function() {
419 var format = '{$cal_dateformat}';
420 var month = document.getElementById('{$field1_name}_month').value;
421 var day = document.getElementById('{$field1_name}_day').value;
422 var year = document.getElementById('{$field1_name}_year').value;
423 var val = format.replace('%m', month).replace('%d', day).replace('%Y', year);
424 if (!parseInt(month) > 0 || !parseInt(year) > 0 || !parseInt(year) > 0)
426 document.getElementById('{$field1_name}').value = val;
429 <span sugar='slot'><input type='hidden' id='{$field1_name}' name='{$field1_name}'/>";
430 $order = explode("%", $cal_dateformat);
431 foreach($order as $part)
433 if (!isset($part[0]))
435 if (strToUpper($part[0]) == "M" )
436 $Web_To_Lead_Form_html .= translate("LBL_MONTH") . ":<input class=\"text\"
437 name=\"{$field1_name}_month\" size='2' maxlength='2' id='{$field1_name}_month' value=''
438 onblur=\"update{$field1_name}Value()\">";
439 else if (strToUpper($part[0]) == "D" )
440 $Web_To_Lead_Form_html .= translate("LBL_DAY") . ":<input class=\"text\"
441 name=\"{$field1_name}_day\" size='2' maxlength='2' id='{$field1_name}_day' value=''
442 onblur=\"update{$field1_name}Value()\">";
443 else if (strToUpper($part[0]) == "Y" )
444 $Web_To_Lead_Form_html .= translate("LBL_YEAR") . ":<input class=\"text\"
445 name=\"{$field1_name}_year\" size='4' maxlength='4' id='{$field1_name}_year' value=''
446 onblur=\"update{$field1_name}Value()\">";
448 $Web_To_Lead_Form_html .= "</span></td>";
450 if( $field1_type=='varchar' || $field1_type=='name'
451 || $field1_type=='phone' || $field1_type=='currency' || $field1_type=='url' || $field1_type=='int'){
452 if($field1_name=='last_name' || $field1_required){
453 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'><span class='required' style='color: rgb(255, 0, 0);'>$web_required_symbol</span></td>";
456 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'></td>";
458 if ( $field1_name=='email1'||$field1_name=='email2' ){
459 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><input id=$field1_name name=$field1_name type='text' onchange='validateEmailAdd();'></span sugar='slot'></td>";
461 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><input id=$field1_name name=$field1_name type='text'></span sugar='slot'></td>";
465 if ( $field1_type == 'text' ) {
466 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'></td>";
467 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span id='ta_replace' sugar='slot'><input id=$field1_name name=$field1_name type='text'></span sugar='slot'></td>";
469 if($field1_type=='relate' && $field1_name=='account_name'){
470 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'></td>";
471 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><input id=$field1_name name=$field1_name type='text'></span sugar='slot'></td>";
473 if($field1_type=='email'){
474 if($field1_required){
475 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'><span class='required' style='color: rgb(255, 0, 0);'>$web_required_symbol</span></td>";
478 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>$field1_label</span sugar='slot'></td>";
480 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'><input id=$field1_name name=$field1_name type='text' onchange='validateEmailAdd();'></span sugar='slot'></td>";
484 $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'> </span sugar='slot'></td>";
485 $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'> </span sugar='slot'></td>";
487 $Web_To_Lead_Form_html .= "</tr>";
490 $Web_To_Lead_Form_html .= "<tr align='center' style='color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 18px; font-weight: bold; margin-bottom: 0px; margin-top: 0px;'><TD COLSPAN='4'> </TD></tr>";
492 if(!empty($web_form_footer)){
493 $Web_To_Lead_Form_html .= "<tr align='center' style='color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 18px; font-weight: bold; margin-bottom: 0px; margin-top: 0px;'><TD COLSPAN='4'> </TD></tr>";
494 $Web_To_Lead_Form_html .= "<tr align='left' style='color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 12px; font-weight: normal; margin-bottom: 0px; margin-top: 0px;'><TD COLSPAN='4'>$web_form_footer</TD></tr>";
497 $Web_To_Lead_Form_html .= "<tr align='center'><td colspan='10'><input type='button' onclick='submit_form();' class='button' name='Submit' value='$web_form_submit_label'/></td></tr>";
499 if(!empty($web_form_campaign)){
500 $Web_To_Lead_Form_html .= "<tr><td style='display: none'><input type='hidden' id='campaign_id' name='campaign_id' value='$web_form_campaign'></td></tr>";
502 if(!empty($web_redirect_url)){
503 $Web_To_Lead_Form_html .= "<tr><td style='display: none'><input type='hidden' id='redirect_url' name='redirect_url' value='$web_redirect_url'></td></tr>";
505 if(!empty($web_assigned_user)){
506 $Web_To_Lead_Form_html .= "<tr><td style='display: none'><input type='hidden' id='assigned_user_id' name='assigned_user_id' value='$web_assigned_user'></td></tr>";
509 if(isset($required_fields) && $required_fields != null ){
510 foreach($required_fields as $req){
511 $req_fields=$req_fields.$req.';';
515 if(isset($bool_fields) && $bool_fields != null ){
516 foreach($bool_fields as $boo){
517 $boolean_fields=$boolean_fields.$boo.';';
520 if(!empty($req_fields)){
521 $Web_To_Lead_Form_html .= "<tr><td style='display: none'><input type='hidden' id='req_id' name='req_id' value='$req_fields'></td></tr>";
523 if(!empty($boolean_fields)){
524 $Web_To_Lead_Form_html .= "<tr><td style='display: none'><input type='hidden' id='bool_id' name='bool_id' value='$boolean_fields'></td></tr>";
528 $Web_To_Lead_Form_html .= "</table >";
529 $Web_To_Lead_Form_html .="</form>";
531 $Web_To_Lead_Form_html .="<script type='text/javascript'>
532 function submit_form(){
533 if(typeof(validateCaptchaAndSubmit)!='undefined'){
534 validateCaptchaAndSubmit();
536 check_webtolead_fields();
539 function check_webtolead_fields(){
540 if(document.getElementById('bool_id') != null){
541 var reqs=document.getElementById('bool_id').value;
542 bools = reqs.substring(0,reqs.lastIndexOf(';'));
543 var bool_fields = new Array();
544 var bool_fields = bools.split(';');
545 nbr_fields = bool_fields.length;
546 for(var i=0;i<nbr_fields;i++){
547 if(document.getElementById(bool_fields[i]).value == 'on'){
548 document.getElementById(bool_fields[i]).value = 1;
551 document.getElementById(bool_fields[i]).value = 0;
555 if(document.getElementById('req_id') != null){
556 var reqs=document.getElementById('req_id').value;
557 reqs = reqs.substring(0,reqs.lastIndexOf(';'));
558 var req_fields = new Array();
559 var req_fields = reqs.split(';');
560 nbr_fields = req_fields.length;
562 for(var i=0;i<nbr_fields;i++){
563 if(document.getElementById(req_fields[i]).value.length <=0 || document.getElementById(req_fields[i]).value==0){
569 document.WebToLeadForm.submit();
573 alert('$web_form_required_fileds_msg');
579 document.WebToLeadForm.submit();
582 function validateEmailAdd(){
583 if(document.getElementById('email1') && document.getElementById('email1').value.length >0) {
584 if(document.getElementById('email1').value.match($regex) == null){
585 alert('$web_not_valid_email_address');
588 if(document.getElementById('email2') && document.getElementById('email2').value.length >0) {
589 if(document.getElementById('email2').value.match($regex) == null){
590 alert('$web_not_valid_email_address');
596 if(isset($Web_To_Lead_Form_html)) $xtpl->assign("BODY", $Web_To_Lead_Form_html); else $xtpl->assign("BODY", "");
597 if(isset($Web_To_Lead_Form_html)) $xtpl->assign("BODY_HTML", $Web_To_Lead_Form_html); else $xtpl->assign("BODY_HTML", "");
600 require_once('include/SugarTinyMCE.php');
601 $tiny = new SugarTinyMCE();
602 $tiny->defaultConfig['height']=400;
603 $tiny->defaultConfig['apply_source_formatting']=true;
604 $tiny->defaultConfig['cleanup']=false;
605 $ed = $tiny->getInstance('body_html');
606 $xtpl->assign("tiny", $ed);
608 $xtpl->parse("main.textarea");
610 $xtpl->assign("INSERT_VARIABLE_ONCLICK", "insert_variable_html(document.EditView.variable_text.value)");
611 $xtpl->parse("main.variable_button");
616 $xtpl->parse("main");
619 function ifRadioButton($customFieldName){
621 $query="select id,type from fields_meta_data where deleted = 0 and name = '$customFieldName'";
622 $result=$GLOBALS['db']->query($query);
623 $row = $GLOBALS['db']->fetchByAssoc($result);
624 if($row != null && $row['type'] == 'radioenum'){
625 return $custRow = $row;