]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Leads/views/view.showduplicates.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Leads / views / view.showduplicates.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 /**
40  * view.showduplicates.php
41  *
42  * This is the SugarView subclass to handle displaying the list of duplicate Leads found when attempting to create
43  * a new Lead.  This class is called from the LeadFormBase class handleSave function.
44  */
45 class ViewShowDuplicates extends SugarView
46 {
47
48     function display()
49     {
50         global $app_strings;
51         global $app_list_strings;
52         global $theme;
53         global $current_language;
54         global $mod_strings;
55
56         if(!isset($_SESSION['SHOW_DUPLICATES']))
57         {
58             $GLOBALS['log']->error("Unauthorized access to this area.");
59             sugar_die("Unauthorized access to this area.");
60         }
61
62         parse_str($_SESSION['SHOW_DUPLICATES'],$_POST);
63         unset($_SESSION['SHOW_DUPLICATES']);
64
65
66         $lead = new Lead();
67         require_once('modules/Leads/LeadFormBase.php');
68         $leadForm = new LeadFormBase();
69         $GLOBALS['check_notify'] = FALSE;
70
71         $query = 'SELECT id, first_name, last_name, title FROM leads WHERE deleted=0 ';
72
73         $duplicates = $_POST['duplicate'];
74         $count = count($duplicates);
75         if ($count > 0)
76         {
77             $query .= "and (";
78             $first = true;
79             foreach ($duplicates as $duplicate_id)
80             {
81                 if (!$first) $query .= ' OR ';
82                 $first = false;
83                 $query .= "id='$duplicate_id' ";
84             }
85             $query .= ')';
86         }
87
88         $duplicateLeads = array();
89         $db = DBManagerFactory::getInstance();
90         $result = $db->query($query);
91         $i=0;
92         while (($row=$db->fetchByAssoc($result)) != null) {
93             $duplicateLeads[$i] = $row;
94             $i++;
95         }
96
97         $this->ss->assign('FORMBODY', $leadForm->buildTableForm($duplicateLeads));
98
99         $input = '';
100         foreach ($lead->column_fields as $field)
101         {
102             if (!empty($_POST['Leads'.$field])) {
103                 $input .= "<input type='hidden' name='$field' value='${_POST['Leads'.$field]}'>\n";
104             }
105         }
106
107         foreach ($lead->additional_column_fields as $field)
108         {
109             if (!empty($_POST['Leads'.$field])) {
110                 $input .= "<input type='hidden' name='$field' value='${_POST['Leads'.$field]}'>\n";
111             }
112         }
113
114         // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
115         if(!empty($_POST['Leadsrelate_to'])) {
116             $input .= "<input type='hidden' name='relate_to' value='{$_POST['Leadsrelate_to']}'>\n";
117         }
118
119         if(!empty($_POST['Leadsrelate_id'])) {
120             $input .= "<input type='hidden' name='relate_id' value='{$_POST['Leadsrelate_id']}'>\n";
121         }
122
123
124         $emailAddress = new SugarEmailAddress();
125         $input .= $emailAddress->getEmailAddressWidgetDuplicatesView($lead);
126
127         $get = '';
128         if(!empty($_POST['return_module']))
129         {
130             $this->ss->assign('RETURN_MODULE', $_POST['return_module']);
131         } else {
132             $get .= "Leads";
133         }
134
135         $get .= "&return_action=";
136         if(!empty($_POST['return_action']))
137         {
138             $this->ss->assign('RETURN_ACTION', $_POST['return_action']);
139         } else {
140             $get .= "DetailView";
141         }
142
143         ///////////////////////////////////////////////////////////////////////////////
144         ////    INBOUND EMAIL WORKFLOW
145         if(isset($_REQUEST['inbound_email_id'])) {
146             $this->ss->assign('INBOUND_EMAIL_ID', $_REQUEST['inbound_email_id']);
147             $this->ss->assign('RETURN_MODULE', 'Emails');
148             $this->ss->assign('RETURN_ACTION', 'EditView');
149             if(isset($_REQUEST['start'])) {
150                $this->ss->assign('START', $_REQUEST['start']);
151             }
152         }
153         ////    END INBOUND EMAIL WORKFLOW
154         ///////////////////////////////////////////////////////////////////////////////
155         if(!empty($_POST['popup']))
156         {
157             $input .= '<input type="hidden" name="popup" value="'.$_POST['popup'].'">';
158         } else {
159             $input .= '<input type="hidden" name="popup" value="false">';
160         }
161
162         if(!empty($_POST['to_pdf']))
163         {
164             $input .= '<input type="hidden" name="to_pdf" value="'.$_POST['to_pdf'].'">';
165         } else {
166             $input .= '<input type="hidden" name="to_pdf" value="false">';
167         }
168
169         if(!empty($_POST['create']))
170         {
171             $input .= '<input type="hidden" name="create" value="'.$_POST['create'].'">';
172         } else {
173             $input .= '<input type="hidden" name="create" value="false">';
174         }
175
176         if(!empty($_POST['return_id']))
177         {
178             $this->ss->assign('RETURN_ID', $_POST['return_id']);
179         }
180
181         $this->ss->assign('INPUT_FIELDS', $input);
182
183         //Load the appropriate template
184         $template = 'modules/Leads/tpls/ShowDuplicates.tpl';
185         if(file_exists('custom/' . $template))
186         {
187            $template = 'custom/' . $template;
188         }
189
190         $saveLabel = string_format($app_strings['LBL_SAVE_OBJECT'], array($this->module));
191         $this->ss->assign('TITLE', getClassicModuleTitle('Leads', array($this->module, $saveLabel), true));
192         $this->ss->display($template);
193     }
194
195 }