]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/GenerateWebToLeadForm.php
Release 6.5.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-2012 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          
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'];
174          }
175          
176          $field_required = '';
177          if(isset($lead->field_defs[$colsFirstField]['required']) && $lead->field_defs[$colsFirstField]['required'] != null
178              && $lead->field_defs[$colsFirstField]['required'] != 0)
179           {
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']);
183              }
184           }
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']);
188             }
189           }
190          if($field_type=='multienum' || $field_type=='enum' || $field_type=='radioenum')  $field_options= $lead->field_defs[$colsFirstField]['options'];
191     }
192     //preg_replace('/:$/','',translate($field_def['vname'],'Leads')
193     if(isset($lead->field_defs[$colsSecondField]) && $lead->field_defs[$colsSecondField] != null)
194     {
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'];
200          }
201          else{
202             $field1_type= $lead->field_defs[$colsSecondField]['type'];
203          }
204          
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'];
208          }
209          
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']);
216             }
217          }
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']);
221             }
222          }
223          if($field1_type=='multienum' || $field1_type=='enum' || $field1_type=='radioenum')  $field1_options= $lead->field_defs[$colsSecondField]['options'];
224     }
225
226      $Web_To_Lead_Form_html .= "<tr>";
227
228     if(isset($lead->field_defs[$colsFirstField]) && $lead->field_defs[$colsFirstField] != null){
229         if($field_type=='multienum' || $field_type=='enum' || $field_type=='radioenum'){
230           $lead_options = '';
231           if(!empty($lead->$field_name)){
232             $lead_options= get_select_options_with_id($app_list_strings[$field_options], unencodeMultienum($lead->$field_name));
233           }
234           else{
235             $lead_options= get_select_options_with_id($app_list_strings[$field_options], '');
236           }
237           if($field_required){
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>";
239             }
240          else{
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>";
242              }
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'>";
251                         } else{
252                                 $Web_To_Lead_Form_html .="<input id='$colsFirstField"."_$field_option_key' name='$colsFirstField' value='$field_option_key' type='radio'>";
253                         }
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>";
255                 }
256             }
257             $Web_To_Lead_Form_html .="</span sugar='slot'></td>";
258           }else{
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>";
260           }
261          }
262          if($field_type=='bool'){
263           if($field_required){
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>";
265           }
266           else{
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>";
268           }
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']);
272              }
273          }
274          if($field_type=='date') {
275
276           global $timedate;
277           $cal_dateformat = $timedate->get_cal_date_format();
278               $LBL_ENTER_DATE = translate('LBL_ENTER_DATE', 'Charts');
279           if($field_required){
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>";
281           }
282           else{
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>";
284           }
285
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)
296                                                         val = '';
297                                                 document.getElementById('{$field_name}').value = val;
298                                         }
299                                 </script>
300                                 <span sugar='slot'><input type='hidden' id='{$field_name}' name='{$field_name}'/>";
301                 $order = explode("%", $cal_dateformat);
302                 foreach($order as $part)
303                 {
304                         if (!isset($part[0]))
305                                 continue;
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()\">";
318                 }
319                 $Web_To_Lead_Form_html .= "</span></td>";
320              } // if
321
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>";
326               }
327             else{
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>";
329              }
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>";
332              } else {
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>";
334              }
335             }
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>";
339            }
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>";
343            }
344           if($field_type=='email'){
345             if($field_required){
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>";
347               }
348            else{
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>";
350              }
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>";
352            }
353        }
354       else{
355             $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>";
356             $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'>&nbsp</span sugar='slot'></td>";
357         }
358
359      if(isset($lead->field_defs[$colsSecondField]) && $lead->field_defs[$colsSecondField] != null){
360          if($field1_type=='multienum' || $field1_type=='enum' || $field1_type=='radioenum'){
361           $lead1_options = '';
362           if(!empty($lead->$field1_name)){
363             $lead1_options= get_select_options_with_id($app_list_strings[$field1_options], unencodeMultienum($lead->$field1_name));
364           }
365           else{
366             $lead1_options= get_select_options_with_id($app_list_strings[$field1_options], '');
367           }
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>";
370             }
371             else{
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>";
373              }
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'>";
382                         }else{
383                                 $Web_To_Lead_Form_html .="<input id='$colsSecondField"."_$field_option_key' name='$colsSecondField' value='$field_option_key' type='radio'>";
384                             }
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>";
386                     }
387                 }
388                 $Web_To_Lead_Form_html .="</span sugar='slot'></td>";
389             }else{
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>";
391             }
392          }
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>";
396           }
397           else{
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>";
399           }
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']);
403              }
404          }
405          if($field1_type=='date') {
406                 global $timedate;
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>";
411           }
412           else{
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>";
414           }
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)
425                                                         val = '';
426                                                 document.getElementById('{$field1_name}').value = val;
427                                         }
428                                 </script>
429                                 <span sugar='slot'><input type='hidden' id='{$field1_name}' name='{$field1_name}'/>";
430                 $order = explode("%", $cal_dateformat);
431                 foreach($order as $part)
432                 {
433                         if (!isset($part[0]))
434                                 continue;
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()\">";
447                 }
448                 $Web_To_Lead_Form_html .= "</span></td>";
449          } // if
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>";
454               }
455             else{
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>";
457              }
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>";
460              } else {
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>";
462              }
463
464            }
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>";
468            }
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>";
472            }
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>";
476               }
477             else{
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>";
479              }
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>";
481            }
482       }
483       else{
484             $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>";
485             $Web_To_Lead_Form_html .= "<td width='35%' style='font-size: 12px; font-weight: normal;'><span sugar='slot'>&nbsp</span sugar='slot'></td>";
486        }
487        $Web_To_Lead_Form_html .= "</tr>";
488 }
489
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'>&nbsp</TD></tr>";
491
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'>&nbsp</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>";
495 }
496
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>";
498
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>";
501 }
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>";
504 }
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>";
507 }
508 $req_fields='';
509 if(isset($required_fields) && $required_fields != null ){
510     foreach($required_fields as $req){
511         $req_fields=$req_fields.$req.';';
512     }
513 }
514 $boolean_fields='';
515 if(isset($bool_fields) && $bool_fields != null ){
516     foreach($bool_fields as $boo){
517         $boolean_fields=$boolean_fields.$boo.';';
518     }
519 }
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>";
522 }
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>";
525 }
526
527
528 $Web_To_Lead_Form_html .= "</table >";
529 $Web_To_Lead_Form_html .="</form>";
530
531 $Web_To_Lead_Form_html .="<script type='text/javascript'>
532  function submit_form(){
533         if(typeof(validateCaptchaAndSubmit)!='undefined'){
534                 validateCaptchaAndSubmit();
535         }else{
536                 check_webtolead_fields();
537         }
538  }
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;
549           }
550           else{
551              document.getElementById(bool_fields[i]).value = 0;
552           }
553         }
554       }
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;
561         var req = true;
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){
564            req = false;
565            break;
566           }
567         }
568         if(req){
569             document.WebToLeadForm.submit();
570             return true;
571         }
572         else{
573           alert('$web_form_required_fileds_msg');
574           return false;
575          }
576         return false
577    }
578    else{
579     document.WebToLeadForm.submit();
580    }
581 }
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');
586                 }
587         }
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');
591                 }
592         }
593 }
594 </script>";
595
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", "");
598
599
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);
607
608 $xtpl->parse("main.textarea");
609
610 $xtpl->assign("INSERT_VARIABLE_ONCLICK", "insert_variable_html(document.EditView.variable_text.value)");
611 $xtpl->parse("main.variable_button");
612
613
614
615
616 $xtpl->parse("main");
617 $xtpl->out("main");
618
619 function ifRadioButton($customFieldName){
620     $custRow = null;
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;
626     }
627     return $custRow;
628 }
629
630 ?>