]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/WebToLeadCreation.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Campaigns / WebToLeadCreation.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
46
47 require_once('include/EditView/EditView2.php');
48
49 require_once('modules/Campaigns/utils.php');
50
51
52 require_once('modules/Campaigns/utils.php');
53
54 global $mod_strings, $app_list_strings, $app_strings, $current_user, $import_bean_map;
55 global $import_file_name, $theme;$app_list_strings;
56 $lead = new Lead();
57 $fields = array();
58
59 $xtpl=new XTemplate ('modules/Campaigns/WebToLeadCreation.html');
60 $xtpl->assign("MOD", $mod_strings);
61 $xtpl->assign("APP", $app_strings);
62 if(isset($_REQUEST['module']))
63 {
64     $xtpl->assign("MODULE", $_REQUEST['module']);
65 }
66 if(isset($_REQUEST['return_module']))
67 {
68     $xtpl->assign("RETURN_MODULE", $_REQUEST['return_module']);
69 }
70 if(isset($_REQUEST['return_id']))
71 {
72     $xtpl->assign("RETURN_ID", $_REQUEST['return_id']);
73 }
74 if(isset($_REQUEST['return_id']))
75 {
76     $xtpl->assign("RETURN_ACTION", $_REQUEST['return_action']);
77 }
78 if(isset($_REQUEST['record']))
79 {
80     $xtpl->assign("RECORD", $_REQUEST['record']);
81 }
82
83 global $theme;
84 global $currentModule;
85
86 $ev = new EditView;
87
88 $xtpl->assign("TITLE1",
89     $this->getModuleTitle(
90         true,
91         array(
92             $this->_getModuleTitleListParam(),
93             $mod_strings['LBL_WEB_TO_LEAD_FORM_TITLE1']
94             )
95         )
96     );
97
98 $xtpl->assign("TITLE2",
99     $this->getModuleTitle(
100         true,
101         array(
102             $this->_getModuleTitleListParam(),
103             $mod_strings['LBL_WEB_TO_LEAD_FORM_TITLE2']
104             )
105         )
106     );
107
108 $site_url = $sugar_config['site_url'];
109 $web_post_url = $site_url.'/index.php?entryPoint=WebToLeadCapture';
110 $json = getJSONobj();
111 // Users Popup
112 $popup_request_data = array(
113         'call_back_function' => 'set_return',
114         'form_name' => 'WebToLeadCreation',
115         'field_to_name_array' => array(
116                 'id' => 'assigned_user_id',
117                 'user_name' => 'assigned_user_name',
118                 ),
119         );
120 $xtpl->assign('encoded_users_popup_request_data', $json->encode($popup_request_data));
121
122 //Campaigns popup
123 $popup_request_data = array(
124                 'call_back_function' => 'set_return',
125                 'form_name' => 'WebToLeadCreation',
126                 'field_to_name_array' => array(
127                         'id' => 'campaign_id',
128                         'name' => 'campaign_name',
129                 ),
130 );
131 $encoded_users_popup_request_data = $json->encode($popup_request_data);
132 $xtpl->assign('encoded_campaigns_popup_request_data' , $json->encode($popup_request_data));
133
134 //create the cancel button
135 $cancel_buttons_html = "<input class='button' onclick=\"this.form.action.value='".$_REQUEST['return_action']."'; this.form.module.value='".$_REQUEST['return_module']."';\" type='submit' name='cancel' value='".$app_strings['LBL_BACK']."'/>";
136 $xtpl->assign("CANCEL_BUTTON", $cancel_buttons_html );
137
138 $field_defs_js = "var field_defs = {'Contacts':[";
139
140 //bug: 47574 - make sure, that webtolead_email1 field has same required attribute as email1 field
141 if(isset($lead->field_defs['webtolead_email1']) && isset($lead->field_defs['email1']) && isset($lead->field_defs['email1']['required'])){
142     $lead->field_defs['webtolead_email1']['required'] = $lead->field_defs['email1']['required'];
143 }
144
145 $count= 0;
146 foreach($lead->field_defs as $field_def)
147 {
148         $email_fields = false;
149     if($field_def['name']== 'email1' || $field_def['name']== 'email2')
150     {
151         $email_fields = true;
152     }
153           if($field_def['name']!= 'account_name'){
154             if( ( $field_def['type'] == 'relate' && empty($field_def['custom_type']) )
155                 || $field_def['type'] == 'assigned_user_name' || $field_def['type'] =='link'
156                 || (isset($field_def['source'])  && $field_def['source']=='non-db' && !$email_fields) || $field_def['type'] == 'id')
157             {
158                 continue;
159             }
160            }
161             if($field_def['name']== 'deleted' || $field_def['name']=='converted' || $field_def['name']=='date_entered'
162                 || $field_def['name']== 'date_modified' || $field_def['name']=='modified_user_id'
163                 || $field_def['name']=='assigned_user_id' || $field_def['name']=='created_by'
164                 || $field_def['name']=='team_id')
165             {
166                 continue;
167             }
168
169
170     $field_def['vname'] = preg_replace('/:$/','',translate($field_def['vname'],'Leads'));
171
172      //$cols_name = "{'".$field_def['vname']."'}";
173      $col_arr = array();
174      if((isset($field_def['required']) && $field_def['required'] != null && $field_def['required'] != 0)
175         || $field_def['name']=='last_name'
176         ){
177         $cols_name=$field_def['vname'].' '.$app_strings['LBL_REQUIRED_SYMBOL'];
178         $col_arr[0]=$cols_name;
179         $col_arr[1]=$field_def['name'];
180         $col_arr[2]=true;
181      }
182      else{
183              $cols_name=$field_def['vname'];
184              $col_arr[0]=$cols_name;
185              $col_arr[1]=$field_def['name'];
186      }
187      if (! in_array($cols_name, $fields))
188      {
189          array_push($fields,$col_arr);
190      }
191      $count++;
192 }
193
194 $xtpl->assign("WEB_POST_URL",$web_post_url);
195 //$xtpl->assign("LEAD_SELECT_FIELDS",'MOD.LBL_SELECT_LEAD_FIELDS');
196
197 require_once('include/QuickSearchDefaults.php');
198 $qsd = QuickSearchDefaults::getQuickSearchDefaults();
199 $sqs_objects = array('account_name' => $qsd->getQSParent(),
200                                         'assigned_user_name' => $qsd->getQSUser(),
201                                         'campaign_name' => $qsd->getQSCampaigns(),
202
203                                         );
204 $quicksearch_js = '<script type="text/javascript" language="javascript">sqs_objects = ' . $json->encode($sqs_objects) . '</script>';
205 $xtpl->assign("JAVASCRIPT", $quicksearch_js);
206
207
208
209 if (empty($focus->assigned_user_id) && empty($focus->id))  $focus->assigned_user_id = $current_user->id;
210 if (empty($focus->assigned_name) && empty($focus->id))  $focus->assigned_user_name = $current_user->user_name;
211 $xtpl->assign("ASSIGNED_USER_OPTIONS", get_select_options_with_id(get_user_array(TRUE, "Active", $focus->assigned_user_id), $focus->assigned_user_id));
212 $xtpl->assign("ASSIGNED_USER_NAME", $focus->assigned_user_name);
213 $xtpl->assign("ASSIGNED_USER_ID", $focus->assigned_user_id );
214
215 $xtpl->assign("REDIRECT_URL_DEFAULT",'http://');
216
217 //required fields on Webtolead form
218 $campaign= new Campaign();
219
220 $javascript = new javascript();
221 $javascript->setFormName('WebToLeadCreation');
222 $javascript->setSugarBean($lead);
223 $javascript->addAllFields('');
224 //$javascript->addFieldGeneric('redirect_url', '', 'LBL_REDIRECT_URL' ,'true');
225 $javascript->addFieldGeneric('campaign_name', '', 'LBL_RELATED_CAMPAIGN' ,'true');
226 $javascript->addFieldGeneric('assigned_user_name', '', 'LBL_ASSIGNED_TO' ,'true');
227 $javascript->addToValidateBinaryDependency('campaign_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $mod_strings['LBL_LEAD_NOTIFY_CAMPAIGN'], 'false', '', 'campaign_id');
228 $javascript->addToValidateBinaryDependency('assigned_user_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ASSIGNED_TO'], 'false', '', 'assigned_user_id');
229 echo $javascript->getScript();
230
231 $json = getJSONobj();
232 $lead_fields = $json->encode($fields);
233 $xtpl->assign("LEAD_FIELDS",$lead_fields);
234 $classname = "SUGAR_GRID";
235 $xtpl->assign("CLASSNAME",$classname);
236 $xtpl->assign("DRAG_DROP_CHOOSER_WEB_TO_LEAD",constructDDWebToLeadFields($fields,$classname));
237
238 $xtpl->parse("main");
239 $xtpl->out("main");
240 /*
241 $str = "<script>
242 WebToLeadForm.lead_fields = {$lead_fields};
243 </script>";
244 echo $str;
245 */
246 /*
247  *This function constructs Drag and Drop multiselect box of subscriptions for display in manage subscription form
248 */
249 function constructDDWebToLeadFields($fields,$classname){
250 require_once("include/templates/TemplateDragDropChooser.php");
251 global $mod_strings;
252 $d2 = array();
253     //now call function that creates javascript for invoking DDChooser object
254     $dd_chooser = new TemplateDragDropChooser();
255     $dd_chooser->args['classname']  = $classname;
256     $dd_chooser->args['left_header']  = $mod_strings['LBL_AVALAIBLE_FIELDS_HEADER'];
257     $dd_chooser->args['mid_header']   = $mod_strings['LBL_LEAD_FORM_FIRST_HEADER'];
258     $dd_chooser->args['right_header'] = $mod_strings['LBL_LEAD_FORM_SECOND_HEADER'];
259     $dd_chooser->args['left_data']    = $fields;
260     $dd_chooser->args['mid_data']     = $d2;
261     $dd_chooser->args['right_data']   = $d2;
262     $dd_chooser->args['title']        =  ' ';
263     $dd_chooser->args['left_div_name']      = 'ddgrid2';
264     $dd_chooser->args['mid_div_name']       = 'ddgrid3';
265     $dd_chooser->args['right_div_name']     = 'ddgrid4';
266     $dd_chooser->args['gridcount'] = 'three';
267     $str = $dd_chooser->displayScriptTags();
268     $str .= $dd_chooser->displayDefinitionScript();
269     $str .= $dd_chooser->display();
270     $str .= "<script>
271                    //function post rows
272                    function postMoveRows(){
273                                 //Call other function when this is called
274                    }
275                 </script>";
276         $str .= "<script>
277                        function displayAddRemoveDragButtons(Add_All_Fields,Remove_All_Fields){
278                                     var addRemove = document.getElementById('lead_add_remove_button');
279                                     if(" . $dd_chooser->args['classname'] . "_grid0.getDataModel().getTotalRowCount() ==0) {
280                                      addRemove.setAttribute('value',Remove_All_Fields);
281                                      addRemove.setAttribute('title',Remove_All_Fields);
282                                     }
283                                     else if(" . $dd_chooser->args['classname'] . "_grid1.getDataModel().getTotalRowCount() ==0 && " . $dd_chooser->args['classname'] . "_grid2.getDataModel().getTotalRowCount() ==0){
284                                      addRemove.setAttribute('value',Add_All_Fields);
285                                      addRemove.setAttribute('title',Add_All_Fields);
286                                     }
287               }
288             </script>";
289
290     return $str;
291 }
292
293 /**
294  * function to retrieve webtolead image and title. path to help file
295  * refactored to use SugarView::getModuleTitle()
296  *
297  * @deprecated use SugarView::getModuleTitle() instead
298  *
299  * @param  $module       string  not used, only for backward compatibility
300  * @param  $image_name   string  image name
301  * @param  $module_title string  to display as the module title
302  * @param  $show_help    boolean which determines if the print and help links are shown.
303  * @return string HTML
304  */
305 function get_webtolead_title(
306     $module,
307     $image_name, 
308     $module_title, 
309     $show_help
310     )
311 {
312     return $GLOBALS['current_view']->getModuleTitle($show_help);
313 }