]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/WebToLeadCapture.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Campaigns / WebToLeadCapture.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 require_once('include/formbase.php');
39 require_once('modules/Leads/LeadFormBase.php');
40
41
42
43 global $app_strings, $app_list_strings, $sugar_config, $timedate, $current_user;
44
45 $mod_strings = return_module_language($sugar_config['default_language'], 'Leads');
46
47 $app_list_strings['record_type_module'] = array('Contact'=>'Contacts', 'Account'=>'Accounts', 'Opportunity'=>'Opportunities', 'Case'=>'Cases', 'Note'=>'Notes', 'Call'=>'Calls', 'Email'=>'Emails', 'Meeting'=>'Meetings', 'Task'=>'Tasks', 'Lead'=>'Leads','Bug'=>'Bugs',
48
49 );
50
51 /**
52  * To make your changes upgrade safe create a file called leadCapture_override.php and place the changes there
53  */
54 $users = array(
55         'PUT A RANDOM KEY FROM THE WEBSITE HERE' => array('name'=>'PUT THE USER_NAME HERE', 'pass'=>'PUT THE USER_HASH FOR THE RESPECTIVE USER HERE'),
56 );
57
58 if (isset($_POST['campaign_id']) && !empty($_POST['campaign_id'])) {
59             //adding the client ip address
60             $_POST['client_id_address'] = query_client_ip();
61                 $campaign_id=$_POST['campaign_id'];
62                 $campaign = new Campaign();
63                 $camp_query  = "select name,id from campaigns where id='$campaign_id'";
64                 $camp_query .= " and deleted=0";
65         $camp_result=$campaign->db->query($camp_query);
66         $camp_data=$campaign->db->fetchByAssoc($camp_result);
67                 
68                 if (isset($_REQUEST['assigned_user_id']) && !empty($_REQUEST['assigned_user_id'])) {
69                         $current_user = new User();
70                         $current_user->retrieve($_REQUEST['assigned_user_id']);
71                 } 
72
73             if(isset($camp_data) && $camp_data != null ){
74                         $leadForm = new LeadFormBase();
75             $lead = new Lead();
76                         $prefix = '';
77                         if(!empty($_POST['prefix'])){
78                                 $prefix = $_POST['prefix'];
79                         }
80
81                         if(empty($lead->id)) {
82                 $lead->id = create_guid();
83                 $lead->new_with_id = true;
84             }
85             $GLOBALS['check_notify'] = true;
86             $lead = $leadForm->handleSave($prefix, false, true, false, $lead);
87             
88                         if(!empty($lead)){
89                                 
90                     //create campaign log
91                     $camplog = new CampaignLog();
92                     $camplog->campaign_id  = $_POST['campaign_id'];
93                     $camplog->related_id   = $lead->id;
94                     $camplog->related_type = $lead->module_dir;
95                     $camplog->activity_type = "lead";
96                     $camplog->target_type = $lead->module_dir;
97                     $campaign_log->activity_date=$timedate->to_display_date_time(gmdate($GLOBALS['timedate']->get_db_date_time_format()));
98                     $camplog->target_id    = $lead->id;
99                     $camplog->save();
100
101                         //link campaignlog and lead
102
103                         if(isset($_POST['webtolead_email1']) && $_POST['webtolead_email1'] != null){
104                     $lead->email1 = $_POST['webtolead_email1'];
105                         }
106                         if(isset($_POST['webtolead_email2']) && $_POST['webtolead_email2'] != null){
107                     $lead->email2 = $_POST['webtolead_email2'];
108                         }
109                         $lead->load_relationship('campaigns');
110                         $lead->campaigns->add($camplog->id);
111                 if(!empty($GLOBALS['check_notify'])) {
112                     $lead->save($GLOBALS['check_notify']);
113                 }
114                 else {
115                     $lead->save(FALSE);
116                 }
117             }
118
119             //in case there are forms out there still using email_opt_out
120             if(isset($_POST['webtolead_email_opt_out']) || isset($_POST['email_opt_out'])){
121                     
122                 if(isset ($lead->email1) && !empty($lead->email1)){
123                     $sea = new SugarEmailAddress();
124                     $sea->AddUpdateEmailAddress($lead->email1,0,1);
125                 }   
126                 if(isset ($lead->email2) && !empty($lead->email2)){
127                     $sea = new SugarEmailAddress();
128                     $sea->AddUpdateEmailAddress($lead->email2,0,1);
129                     
130                 }
131             }              
132                         if(isset($_POST['redirect_url']) && !empty($_POST['redirect_url'])){
133                             // Get the redirect url, and make sure the query string is not too long
134                         $redirect_url = $_POST['redirect_url'];
135                         $query_string = '';
136                                 $first_char = '&';
137                                 if(strpos($redirect_url, '?') === FALSE){
138                                         $first_char = '?';
139                                 }
140                                 $first_iteration = true;
141                                 $get_and_post = array_merge($_GET, $_POST);
142                                 foreach($get_and_post as $param => $value) {
143
144                                         if($param == 'redirect_url' || $param == 'submit')
145                                                 continue;
146                                         
147                                         if($first_iteration){
148                                                 $first_iteration = false;
149                                                 $query_string .= $first_char;
150                                         }
151                                         else{
152                                                 $query_string .= "&";
153                                         }
154                                         $query_string .= "{$param}=".urlencode($value);
155                                 }
156                                 if(empty($lead)) {
157                                         if($first_iteration){
158                                                 $query_string .= $first_char;
159                                         }
160                                         else{
161                                                 $query_string .= "&";
162                                         }
163                                         $query_string .= "error=1";
164                                 }
165                                 
166                                 $redirect_url = $redirect_url.$query_string;
167                                 
168                                 // Check if the headers have been sent, or if the redirect url is greater than 2083 characters (IE max URL length)
169                                 //   and use a javascript form submission if that is the case.
170                             if(headers_sent() || strlen($redirect_url) > 2083){
171                                 echo '<html><head><title>SugarCRM</title></head><body>';
172                                 echo '<form name="redirect" action="' .$_POST['redirect_url']. '" method="GET">';
173     
174                                 foreach($_POST as $param => $value) {
175                                         if($param != 'redirect_url' ||$param != 'submit') {
176                                                 echo '<input type="hidden" name="'.$param.'" value="'.$value.'">';
177                                         }
178                                 }
179                                 if(empty($lead)) {
180                                         echo '<input type="hidden" name="error" value="1">';
181                                 }
182                                 echo '</form><script language="javascript" type="text/javascript">document.redirect.submit();</script>';
183                                 echo '</body></html>';
184                         }
185                                 else{
186                                 header("Location: {$redirect_url}");
187                                 die();
188                             }
189                         }
190                         else{
191                                 echo $mod_strings['LBL_THANKS_FOR_SUBMITTING_LEAD'];
192                         }
193                         sugar_cleanup();
194                         // die to keep code from running into redirect case below
195                         die();
196             }
197            else{
198                   echo $mod_strings['LBL_SERVER_IS_CURRENTLY_UNAVAILABLE'];
199           }
200 }
201
202 if (!empty($_POST['redirect'])) {
203     if(headers_sent()){
204         echo '<html><head><title>SugarCRM</title></head><body>';
205         echo '<form name="redirect" action="' .$_POST['redirect']. '" method="GET">';
206         echo '</form><script language="javascript" type="text/javascript">document.redirect.submit();</script>';
207         echo '</body></html>';
208     }
209     else{
210         header("Location: {$_POST['redirect']}");
211         die();
212     }
213 }
214 echo $mod_strings['LBL_SERVER_IS_CURRENTLY_UNAVAILABLE'];
215 ?>