| Conditions | 22 |
| Paths | > 20000 |
| Total Lines | 150 |
| Code Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 | |||
| 203 |