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