]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Contacts/ShowDuplicates.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Contacts / 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 if (!isset($_SESSION['SHOW_DUPLICATES']))
39     sugar_die("Unauthorized access to this area.");
40 // retrieve $_POST values out of the $_SESSION variable - placed in there by ContactFormBase to avoid the length limitations on URLs implicit with GETS
41 //$GLOBALS['log']->debug('ShowDuplicates.php: _POST = '.print_r($_SESSION['SHOW_DUPLICATES'],true));
42 parse_str($_SESSION['SHOW_DUPLICATES'],$_POST);
43 unset($_SESSION['SHOW_DUPLICATES']);
44 //$GLOBALS['log']->debug('ShowDuplicates.php: _POST = '.print_r($_POST,true));
45
46 global $app_strings;
47 global $app_list_strings;
48 global $theme;
49
50 $error_msg = '';
51 global $current_language;
52 $mod_strings = return_module_language($current_language, 'Contacts');
53 $moduleName = $GLOBALS['app_list_strings']['moduleList']['Contacts'];
54 echo getClassicModuleTitle('Contacts', array($moduleName,$mod_strings['LBL_SAVE_CONTACT']), true);
55 $xtpl=new XTemplate ('modules/Contacts/ShowDuplicates.html');
56 $xtpl->assign("MOD", $mod_strings);
57 $xtpl->assign("APP", $app_strings);
58 $xtpl->assign("PRINT_URL", "index.php?".$GLOBALS['request_string']);
59 $xtpl->assign("MODULE", $_REQUEST['module']);
60 if ($error_msg != '')
61 {
62         $xtpl->assign("ERROR", $error_msg);
63         $xtpl->parse("main.error");
64 }
65
66 if((isset($_REQUEST['popup']) && $_REQUEST['popup'] == 'true') ||(isset($_POST['popup']) && $_POST['popup']==true)) insert_popup_header($theme);
67
68
69 $contact = new Contact();
70 require_once('modules/Contacts/ContactFormBase.php');
71 $contactForm = new ContactFormBase();
72 $GLOBALS['check_notify'] = FALSE;
73
74
75 $query = 'select id, first_name, last_name, title from contacts where deleted=0 ';
76 $duplicates = $_POST['duplicate']; 
77 $count = count($duplicates);
78 if ($count > 0)
79 {
80         $query .= "and (";
81         $first = true; 
82         foreach ($duplicates as $duplicate_id) 
83         {
84                 if (!$first) $query .= ' OR ';
85                 $first = false;
86                 $query .= "id='$duplicate_id' ";
87         }
88         $query .= ')';
89 }
90
91 $duplicateContacts = array();
92
93 $db = DBManagerFactory::getInstance();
94 $result = $db->query($query);
95 $i=0;
96 while (($row=$db->fetchByAssoc($result)) != null) {
97         $duplicateContacts[$i] = $row;
98         $i++;
99 }
100
101 $xtpl->assign('FORMBODY', $contactForm->buildTableForm($duplicateContacts));
102
103 $input = '';
104 foreach ($contact->column_fields as $field)
105 {       
106         if (!empty($_POST['Contacts'.$field])) {
107                 $input .= "<input type='hidden' name='$field' value='${_POST['Contacts'.$field]}'>\n";
108         }
109 }
110
111 foreach ($contact->additional_column_fields as $field)
112 {       
113         if (!empty($_POST['Contacts'.$field])) {
114                 $input .= "<input type='hidden' name='$field' value='${_POST['Contacts'.$field]}'>\n";
115         }
116 }
117
118 // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
119 if(!empty($_POST['Contactsrelate_to'])) {
120     $input .= "<input type='hidden' name='relate_to' value='{$_POST['Contactsrelate_to']}'>\n";
121 }
122 if(!empty($_POST['Contactsrelate_id'])) {
123     $input .= "<input type='hidden' name='relate_id' value='{$_POST['Contactsrelate_id']}'>\n";
124 }
125
126
127 $emailAddress = new SugarEmailAddress();
128 $input .= $emailAddress->getEmailAddressWidgetDuplicatesView($contact);
129
130 $get = '';
131 if(!empty($_POST['return_module'])) $xtpl->assign('RETURN_MODULE', $_POST['return_module']);
132 else $get .= "Contacts";
133 $get .= "&return_action=";
134 if(!empty($_POST['return_action'])) $xtpl->assign('RETURN_ACTION', $_POST['return_action']);
135 else $get .= "DetailView";
136
137 ///////////////////////////////////////////////////////////////////////////////
138 ////    INBOUND EMAIL WORKFLOW
139 if(isset($_REQUEST['inbound_email_id'])) {
140         $xtpl->assign('INBOUND_EMAIL_ID', $_REQUEST['inbound_email_id']);
141         $xtpl->assign('RETURN_MODULE', 'Emails');       
142         $xtpl->assign('RETURN_ACTION', 'EditView');
143         if(isset($_REQUEST['start'])) {
144                 $xtpl->assign('START', $_REQUEST['start']);
145         }
146                 
147 }
148 ////    END INBOUND EMAIL WORKFLOW
149 ///////////////////////////////////////////////////////////////////////////////
150
151
152
153 if(!empty($_POST['popup'])) 
154         $input .= '<input type="hidden" name="popup" value="'.$_POST['popup'].'">';
155 else 
156         $input .= '<input type="hidden" name="popup" value="false">';
157
158 if(!empty($_POST['to_pdf'])) 
159         $input .= '<input type="hidden" name="to_pdf" value="'.$_POST['to_pdf'].'">';
160 else 
161         $input .= '<input type="hidden" name="to_pdf" value="false">';
162         
163 if(!empty($_POST['create'])) 
164         $input .= '<input type="hidden" name="create" value="'.$_POST['create'].'">';
165 else 
166         $input .= '<input type="hidden" name="create" value="false">';
167
168 if(!empty($_POST['return_id'])) $xtpl->assign('RETURN_ID', $_POST['return_id']);
169
170 $xtpl->assign('INPUT_FIELDS',$input);
171 $xtpl->parse('main');
172 $xtpl->out('main');
173
174 ?>