]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/GenerateWebToLeadForm.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Campaigns / GenerateWebToLeadForm.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 require_once('include/formbase.php');
46
47
48
49
50 require_once('include/utils/db_utils.php');
51
52
53
54
55 global $app_list_strings, $app_strings,$mod_strings;
56
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 = '';
68 $web_team_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'];
74 }
75 if(!empty($_REQUEST['web_description'])){
76     $web_form_description= $_REQUEST['web_description'];
77 }
78 if(!empty($_REQUEST['web_submit'])){
79     $web_form_submit_label=to_html($_REQUEST['web_submit']);
80 }
81 if(!empty($_REQUEST['post_url'])){
82     $web_post_url= $_REQUEST['post_url'];
83 }
84 if(!empty($_REQUEST['redirect_url']) && $_REQUEST['redirect_url'] !="http://"){
85     $web_redirect_url= $_REQUEST['redirect_url'];
86 }
87 if(!empty($_REQUEST['notify_campaign'])){
88     $web_notify_campaign = $_REQUEST['notify_campaign'];
89 }
90 if(!empty($_REQUEST['web_footer'])){
91     $web_form_footer= $_REQUEST['web_footer'];
92 }
93 if(!empty($_REQUEST['campaign_id'])){
94     $web_form_campaign= $_REQUEST['campaign_id'];
95 }
96 if(!empty($_REQUEST['assigned_user_id'])){
97     $web_assigned_user = $_REQUEST['assigned_user_id'];
98 }
99
100
101  $lead = new Lead();
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')) . '">';
108
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>';
111
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);
117 font-size: 12px;
118 background-repeat: repeat-x;
119 background-position: center top;'>";
120
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'>&nbsp</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'>&nbsp</TD></tr>";
125
126  //$Web_To_Lead_Form_html .= "\n<p>\n";
127
128 if(!empty($_REQUEST['colsFirst']) && !empty($_REQUEST['colsSecond'])){
129  if(count($_REQUEST['colsFirst']) < count($_REQUEST['colsSecond'])){
130    $columns= count($_REQUEST['colsSecond']);
131  }
132  if(count($_REQUEST['colsFirst']) > count($_REQUEST['colsSecond']) || count($_REQUEST['colsFirst']) == count($_REQUEST['colsSecond'])){
133    $columns= count($_REQUEST['colsFirst']);
134  }
135 }
136 else if(!empty($_REQUEST['colsFirst'])){
137  $columns= count($_REQUEST['colsFirst']);
138 }
139 else if(!empty($_REQUEST['colsSecond'])){
140  $columns= count($_REQUEST['colsSecond']);
141 }
142
143
144 $required_fields = array();
145 $bool_fields = array();
146 for($i= 0; $i<$columns;$i++){
147     $colsFirstField = '';
148     $colsSecondField = '';
149
150     if(!empty($_REQUEST['colsFirst'][$i])){
151         $colsFirstField = $_REQUEST['colsFirst'][$i];
152         //_pp($_REQUEST['colsFirst']);
153      }
154     if(!empty($_REQUEST['colsSecond'][$i])){
155         $colsSecondField = $_REQUEST['colsSecond'][$i];
156         //_pp($_REQUEST['colsSecond']);
157      }
158
159     if(isset($lead->field_defs[$colsFirstField]) && $lead->field_defs[$colsFirstField] != null)
160     {
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'];
166          }
167          else{
168             $field_type= $lead->field_defs[$colsFirstField]['type'];
169          }
170          $field_required = '';
171          if(isset($lead->field_defs[$colsFirstField]['required']) && $lead->field_defs[$colsFirstField]['required'] != null
172              && $lead->field_defs[$colsFirstField]['required'] != 0)
173           {
174             $field_required = $lead->field_defs[$colsFirstField]['required'];
175             if (! in_array($lead->field_defs[$colsFirstField]['name'], $required_fields)){
176               array_push($required_fields,$lead->field_defs[$colsFirstField]['name']);
177              }
178           }
179           if($lead->field_defs[$colsFirstField]['name']=='last_name'){
180             if (! in_array($lead->field_defs[$colsFirstField]['name'], $required_fields)){
181               array_push($required_fields,$lead->field_defs[$colsFirstField]['name']);
182             }
183           }
184          if($field_type=='multienum' || $field_type=='enum' || $field_type=='radioenum')  $field_options= $lead->field_defs[$colsFirstField]['options'];
185     }
186     //preg_replace('/:$/','',translate($field_def['vname'],'Leads')
187     if(isset($lead->field_defs[$colsSecondField]) && $lead->field_defs[$colsSecondField] != null)
188     {
189          $field1_vname= preg_replace('/:$/','',translate($lead->field_defs[$colsSecondField]['vname'],'Leads'));
190          $field1_name= $colsSecondField;
191          $field1_label = $field1_vname .": ";
192          if(isset($lead->field_defs[$colsSecondField]['custom_type']) && $lead->field_defs[$colsSecondField]['custom_type'] != null){
193             $field1_type= $lead->field_defs[$colsSecondField]['custom_type'];
194          }
195          else{
196             $field1_type= $lead->field_defs[$colsSecondField]['type'];
197          }
198          $field1_required = '';
199          if(isset($lead->field_defs[$colsSecondField]['required']) && $lead->field_defs[$colsSecondField]['required'] != null
200              && $lead->field_defs[$colsSecondField]['required'] != 0){
201           $field1_required = $lead->field_defs[$colsSecondField]['required'];
202            if (! in_array($lead->field_defs[$colsSecondField]['name'], $required_fields)){
203               array_push($required_fields,$lead->field_defs[$colsSecondField]['name']);
204             }
205          }
206          if($lead->field_defs[$colsSecondField]['name']=='last_name'){
207             if (! in_array($lead->field_defs[$colsSecondField]['name'], $required_fields)){
208               array_push($required_fields,$lead->field_defs[$colsSecondField]['name']);
209             }
210          }
211          if($field1_type=='multienum' || $field1_type=='enum' || $field1_type=='radioenum')  $field1_options= $lead->field_defs[$colsSecondField]['options'];
212     }
213
214      $Web_To_Lead_Form_html .= "<tr>";
215
216     if(isset($lead->field_defs[$colsFirstField]) && $lead->field_defs[$colsFirstField] != null){
217         if($field_type=='multienum' || $field_type=='enum' || $field_type=='radioenum'){
218           $lead_options = '';
219           if(!empty($lead->$field_name)){
220             $lead_options= get_select_options_with_id($app_list_strings[$field_options], unencodeMultienum($lead->$field_name));
221           }
222           else{
223             $lead_options= get_select_options_with_id($app_list_strings[$field_options], '');
224           }
225           if($field_required){
226                 $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>";
227             }
228          else{
229                 $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>";
230              }
231           if(isset($lead->field_defs[$colsFirstField]['isMultiSelect']) && $lead->field_defs[$colsFirstField]['isMultiSelect'] ==1){
232             $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>";
233           }elseif(ifRadioButton($lead->field_defs[$colsFirstField]['name'])){
234             $Web_To_Lead_Form_html .="<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'>";
235             foreach($app_list_strings[$field_options] as $field_option_key => $field_option){
236                 if($field_option != null){
237                         if(!empty($lead->$field_name) && in_array($field_option_key,unencodeMultienum($lead->$field_name))){
238                                 $Web_To_Lead_Form_html .="<input id='$colsFirstField"."_$field_option_key' checked name='$colsFirstField' value='$field_option_key' type='radio'>";
239                         } else{
240                                 $Web_To_Lead_Form_html .="<input id='$colsFirstField"."_$field_option_key' name='$colsFirstField' value='$field_option_key' type='radio'>";
241                         }
242                         $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>";
243                 }
244             }
245             $Web_To_Lead_Form_html .="</span sugar='slot'></td>";
246           }else{
247             $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>";
248           }
249          }
250          if($field_type=='bool'){
251           if($field_required){
252                 $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>";
253           }
254           else{
255                 $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>";
256           }
257           $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>";
258           if (! in_array($lead->field_defs[$colsFirstField]['name'], $bool_fields)){
259               array_push($bool_fields,$lead->field_defs[$colsFirstField]['name']);
260              }
261          }
262          if($field_type=='date') {
263
264           global $timedate;
265           $cal_dateformat = $timedate->get_cal_date_format();
266               $LBL_ENTER_DATE = translate('LBL_ENTER_DATE', 'Charts');
267           if($field_required){
268                 $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>";
269           }
270           else{
271                 $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>";
272           }
273
274                         $Web_To_Lead_Form_html .= "
275                                 <td width='35%' style='font-size: 12px; font-weight: normal;'>
276                                 <script type='text/javascript'>
277                                         update{$field_name}Value = function() {
278                                                 var format = '{$cal_dateformat}';
279                                                 var month = document.getElementById('{$field_name}_month').value;
280                                                 var day = document.getElementById('{$field_name}_day').value;
281                                                 var year = document.getElementById('{$field_name}_year').value;
282                                                 var val = format.replace('%m', month).replace('%d', day).replace('%Y', year);
283                                                 if (!parseInt(month) > 0 || !parseInt(year) > 0 || !parseInt(year) > 0)
284                                                         val = '';
285                                                 document.getElementById('{$field_name}').value = val;
286                                         }
287                                 </script>
288                                 <span sugar='slot'><input type='hidden' id='{$field_name}' name='{$field_name}'/>";
289                 $order = explode("%", $cal_dateformat);
290                 foreach($order as $part)
291                 {
292                         if (!isset($part[0]))
293                                 continue;
294                         if (strToUpper($part[0]) == "M" )
295                                 $Web_To_Lead_Form_html .= translate("LBL_MONTH") . ":<input class=\"text\"
296                                         name=\"{$field_name}_month\" size='2' maxlength='2' id='{$field_name}_month' value=''
297                                         onblur=\"update{$field_name}Value()\">";
298                                 else if (strToUpper($part[0]) == "D" )
299                                         $Web_To_Lead_Form_html .=  translate("LBL_DAY") . ":<input class=\"text\"
300                                         name=\"{$field_name}_day\" size='2' maxlength='2' id='{$field_name}_day' value=''
301                                         onblur=\"update{$field_name}Value()\">";
302                                 else if (strToUpper($part[0]) == "Y" )
303                                         $Web_To_Lead_Form_html .= translate("LBL_YEAR") . ":<input class=\"text\"
304                                         name=\"{$field_name}_year\" size='4' maxlength='4' id='{$field_name}_year' value=''
305                                         onblur=\"update{$field_name}Value()\">";
306                 }
307                 $Web_To_Lead_Form_html .= "</span></td>";
308              } // if
309
310          if( $field_type=='varchar' ||  $field_type=='name'
311           ||  $field_type=='phone' || $field_type=='currency' || $field_type=='url' || $field_type=='int'){
312            if($field_name=='last_name' ||   $field_required){
313                 $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>";
314               }
315             else{
316                 $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>";
317              }
318            $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>";
319             }
320           if ( $field_type == 'text' ) {
321                $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>";
322                            $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>";
323            }
324            if($field_type=='relate' &&  $field_name=='account_name'){
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'></td>";
326                     $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>";
327            }
328           if($field_type=='email'){
329             if($field_required){
330                 $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>";
331               }
332            else{
333                 $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>";
334              }
335             $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>";
336            }
337        }
338       else{
339             $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>&nbsp</span sugar='slot'></td>";
340             $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'>&nbsp</span sugar='slot'></td>";
341         }
342
343      if(isset($lead->field_defs[$colsSecondField]) && $lead->field_defs[$colsSecondField] != null){
344          if($field1_type=='multienum' || $field1_type=='enum' || $field1_type=='radioenum'){
345           $lead1_options = '';
346           if(!empty($lead->$field1_name)){
347             $lead1_options= get_select_options_with_id($app_list_strings[$field1_options], unencodeMultienum($lead->$field1_name));
348           }
349           else{
350             $lead1_options= get_select_options_with_id($app_list_strings[$field1_options], '');
351           }
352             if($field1_required){
353                 $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>";
354             }
355             else{
356                 $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>";
357              }
358             if(isset($lead->field_defs[$colsSecondField]['isMultiSelect']) && $lead->field_defs[$colsSecondField]['isMultiSelect'] ==1){
359                 $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>";
360             }elseif(ifRadioButton($lead->field_defs[$colsSecondField]['name'])){
361                 $Web_To_Lead_Form_html .="<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'>";
362                 foreach($app_list_strings[$field1_options] as $field_option_key => $field_option){
363                     if($field_option != null){
364                         if(!empty($lead->$field1_name) && in_array($field_option_key,unencodeMultienum($lead->$field1_name))){
365                                 $Web_To_Lead_Form_html .="<input id='$colsSecondField"."_$field_option_key' checked name='$colsSecondField' value='$field_option_key' type='radio'>";
366                         }else{
367                                 $Web_To_Lead_Form_html .="<input id='$colsSecondField"."_$field_option_key' name='$colsSecondField' value='$field_option_key' type='radio'>";
368                             }
369                             $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>";
370                     }
371                 }
372                 $Web_To_Lead_Form_html .="</span sugar='slot'></td>";
373             }else{
374                 $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>";
375             }
376          }
377          if($field1_type=='bool'){
378           if($field1_required){
379             $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>";
380           }
381           else{
382             $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>";
383           }
384             $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>";
385             if (! in_array($lead->field_defs[$colsSecondField]['name'], $bool_fields)){
386               array_push($bool_fields,$lead->field_defs[$colsSecondField]['name']);
387              }
388          }
389          if($field1_type=='date') {
390                 global $timedate;
391                         $cal_dateformat = $timedate->get_cal_date_format();
392                 $LBL_ENTER_DATE = translate('LBL_ENTER_DATE', 'Charts');
393           if($field1_required){
394                 $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>";
395           }
396           else{
397                 $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>";
398           }
399                         $Web_To_Lead_Form_html .= " 
400                                 <td width='35%' style='font-size: 12px; font-weight: normal;'>
401                                 <script type='text/javascript'>
402                                         update{$field1_name}Value = function() {
403                                                 var format = '{$cal_dateformat}';
404                                                 var month = document.getElementById('{$field1_name}_month').value;
405                                                 var day = document.getElementById('{$field1_name}_day').value;
406                                                 var year = document.getElementById('{$field1_name}_year').value;
407                                                 var val = format.replace('%m', month).replace('%d', day).replace('%Y', year);
408                                                 if (!parseInt(month) > 0 || !parseInt(year) > 0 || !parseInt(year) > 0)
409                                                         val = '';
410                                                 document.getElementById('{$field1_name}').value = val;
411                                         }
412                                 </script>
413                                 <span sugar='slot'><input type='hidden' id='{$field1_name}' name='{$field1_name}'/>";
414                 $order = explode("%", $cal_dateformat);
415                 foreach($order as $part)
416                 {
417                         if (!isset($part[0]))
418                                 continue;
419                         if (strToUpper($part[0]) == "M" )
420                                 $Web_To_Lead_Form_html .= translate("LBL_MONTH") . ":<input class=\"text\"
421                                         name=\"{$field1_name}_month\" size='2' maxlength='2' id='{$field1_name}_month' value='' 
422                                         onblur=\"update{$field1_name}Value()\">";
423                                 else if (strToUpper($part[0]) == "D" ) 
424                                         $Web_To_Lead_Form_html .=  translate("LBL_DAY") . ":<input class=\"text\"
425                                         name=\"{$field1_name}_day\" size='2' maxlength='2' id='{$field1_name}_day' value='' 
426                                         onblur=\"update{$field1_name}Value()\">";
427                                 else if (strToUpper($part[0]) == "Y" ) 
428                                         $Web_To_Lead_Form_html .= translate("LBL_YEAR") . ":<input class=\"text\"
429                                         name=\"{$field1_name}_year\" size='4' maxlength='4' id='{$field1_name}_year' value='' 
430                                         onblur=\"update{$field1_name}Value()\">";
431                 }
432                 $Web_To_Lead_Form_html .= "</span></td>";
433          } // if
434          if( $field1_type=='varchar' ||  $field1_type=='name'
435           ||  $field1_type=='phone' || $field1_type=='currency' || $field1_type=='url' || $field1_type=='int'){
436             if($field1_name=='last_name' ||  $field1_required){
437                 $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>";
438               }
439             else{
440                 $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>";
441              }
442             $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>";
443            }
444            if ( $field1_type == 'text' ) {
445                $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>";
446                                 $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>";
447            }
448            if($field1_type=='relate' &&  $field1_name=='account_name'){
449                     $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>";
450                     $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>";
451            }
452            if($field1_type=='email'){
453                 if($field1_required){
454                 $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>";
455               }
456             else{
457                 $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              }
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>";
460            }
461       }
462       else{
463             $Web_To_Lead_Form_html .= "<td width='15%' style='text-align: left; font-size: 12px; font-weight: normal;'><span sugar='slot'>&nbsp</span sugar='slot'></td>";
464             $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'>&nbsp</span sugar='slot'></td>";
465        }
466        $Web_To_Lead_Form_html .= "</tr>";
467 }
468
469 $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'>&nbsp</TD></tr>";
470
471 if(!empty($web_form_footer)){
472     $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'>&nbsp</TD></tr>";
473     $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>";
474 }
475
476 $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>";
477
478 if(!empty($web_form_campaign)){
479    $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>";
480 }
481 if(!empty($web_redirect_url)){
482     $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>";
483 }
484 if(!empty($web_assigned_user)){
485     $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>";
486 }
487 $req_fields='';
488 if(isset($required_fields) && $required_fields != null ){
489     foreach($required_fields as $req){
490         $req_fields=$req_fields.$req.';';
491     }
492 }
493 $boolean_fields='';
494 if(isset($bool_fields) && $bool_fields != null ){
495     foreach($bool_fields as $boo){
496         $boolean_fields=$boolean_fields.$boo.';';
497     }
498 }
499 if(!empty($req_fields)){
500     $Web_To_Lead_Form_html .= "<tr><td style='display: none'><input type='hidden' id='req_id' name='req_id' value='$req_fields'></td></tr>";
501 }
502 if(!empty($boolean_fields)){
503     $Web_To_Lead_Form_html .= "<tr><td style='display: none'><input type='hidden' id='bool_id' name='bool_id' value='$boolean_fields'></td></tr>";
504 }
505
506
507 $Web_To_Lead_Form_html .= "</table >";
508 $Web_To_Lead_Form_html .="</form>";
509
510 $Web_To_Lead_Form_html .="<script type='text/javascript'>
511  function submit_form(){
512         if(typeof(validateCaptchaAndSubmit)!='undefined'){
513                 validateCaptchaAndSubmit();
514         }else{
515                 check_webtolead_fields();
516         }
517  }
518  function check_webtolead_fields(){
519      if(document.getElementById('bool_id') != null){
520         var reqs=document.getElementById('bool_id').value;
521         bools = reqs.substring(0,reqs.lastIndexOf(';'));
522         var bool_fields = new Array();
523         var bool_fields = bools.split(';');
524         nbr_fields = bool_fields.length;
525         for(var i=0;i<nbr_fields;i++){
526           if(document.getElementById(bool_fields[i]).value == 'on'){
527              document.getElementById(bool_fields[i]).value = 1;
528           }
529           else{
530              document.getElementById(bool_fields[i]).value = 0;
531           }
532         }
533       }
534     if(document.getElementById('req_id') != null){
535         var reqs=document.getElementById('req_id').value;
536         reqs = reqs.substring(0,reqs.lastIndexOf(';'));
537         var req_fields = new Array();
538         var req_fields = reqs.split(';');
539         nbr_fields = req_fields.length;
540         var req = true;
541         for(var i=0;i<nbr_fields;i++){
542           if(document.getElementById(req_fields[i]).value.length <=0 || document.getElementById(req_fields[i]).value==0){
543            req = false;
544            break;
545           }
546         }
547         if(req){
548             document.WebToLeadForm.submit();
549             return true;
550         }
551         else{
552           alert('$web_form_required_fileds_msg');
553           return false;
554          }
555         return false
556    }
557    else{
558     document.WebToLeadForm.submit();
559    }
560 }
561 function validateEmailAdd(){
562         if(document.getElementById('webtolead_email1').value.length >0) {
563                 if(document.getElementById('webtolead_email1').value.match($regex) == null){
564                   alert('$web_not_valid_email_address');
565                 }
566         }
567         if(document.getElementById('webtolead_email2').value.length >0) {
568                 if(document.getElementById('webtolead_email2').value.match($regex) == null){
569                   alert('$web_not_valid_email_address');
570                 }
571         }
572 }
573 </script>";
574
575 if(isset($Web_To_Lead_Form_html)) $xtpl->assign("BODY", $Web_To_Lead_Form_html); else $xtpl->assign("BODY", "");
576 if(isset($Web_To_Lead_Form_html)) $xtpl->assign("BODY_HTML", $Web_To_Lead_Form_html); else $xtpl->assign("BODY_HTML", "");
577
578
579 require_once('include/SugarTinyMCE.php');
580 $tiny = new SugarTinyMCE();
581 $tiny->defaultConfig['height']=400;
582 $tiny->defaultConfig['apply_source_formatting']=true;
583 $tiny->defaultConfig['cleanup']=false;
584 $ed = $tiny->getInstance('body_html');
585 $xtpl->assign("tiny", $ed);
586
587 $xtpl->parse("main.textarea");
588
589 $xtpl->assign("INSERT_VARIABLE_ONCLICK", "insert_variable_html(document.EditView.variable_text.value)");
590 $xtpl->parse("main.variable_button");
591
592
593
594
595 $xtpl->parse("main");
596 $xtpl->out("main");
597
598 function ifRadioButton($customFieldName){
599     $custRow = null;
600     $query="select id,type from fields_meta_data where deleted = 0 and name = '$customFieldName'";
601     $result=$GLOBALS['db']->query($query);
602     $row = $GLOBALS['db']->fetchByAssoc($result);
603     if($row != null && $row['type'] == 'radioenum'){
604         return $custRow = $row;
605     }
606     return $custRow;
607 }
608
609 ?>