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