Completed
Push — console-installer ( e2b50d...6ce748 )
by Adam
22:30
created

ViewShowDuplicates::display()   F

Complexity

Conditions 22
Paths > 20000

Size

Total Lines 150
Code Lines 87

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 22
eloc 87
nc 221184
nop 0
dl 0
loc 150
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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