| Conditions | 46 |
| Paths | > 20000 |
| Total Lines | 185 |
| Code Lines | 98 |
| Lines | 0 |
| Ratio | 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 |
||
| 211 | function handleSave($prefix,$redirect=true, $useRequired=false, $do_save=true, $exist_lead=null){ |
||
| 212 | |||
| 213 | require_once('modules/Campaigns/utils.php'); |
||
| 214 | require_once('include/formbase.php'); |
||
| 215 | |||
| 216 | if(empty($exist_lead)) { |
||
| 217 | $focus = new Lead(); |
||
| 218 | } |
||
| 219 | else { |
||
| 220 | $focus = $exist_lead; |
||
| 221 | } |
||
| 222 | |||
| 223 | if($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))){ |
||
| 224 | return null; |
||
| 225 | } |
||
| 226 | $focus = populateFromPost($prefix, $focus); |
||
| 227 | if(!$focus->ACLAccess('Save')){ |
||
| 228 | ACLController::displayNoAccess(true); |
||
| 229 | sugar_cleanup(true); |
||
| 230 | } |
||
| 231 | |||
| 232 | //Check for duplicate Leads |
||
| 233 | if (empty($_POST['record']) && empty($_POST['dup_checked'])) |
||
| 234 | { |
||
| 235 | $duplicateLeads = $this->checkForDuplicates($prefix); |
||
| 236 | |||
| 237 | if(isset($duplicateLeads)) |
||
| 238 | { |
||
| 239 | //Set the redirect location to call the ShowDuplicates action. This will map to view.showduplicates.php |
||
| 240 | $location='module=Leads&action=ShowDuplicates'; |
||
| 241 | |||
| 242 | $get = ''; |
||
| 243 | |||
| 244 | if(isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) { |
||
| 245 | $get .= '&inbound_email_id='.$_POST['inbound_email_id']; |
||
| 246 | } |
||
| 247 | |||
| 248 | if(isset($_POST['relate_to']) && !empty($_POST['relate_to'])) { |
||
| 249 | $get .= '&Leadsrelate_to='.$_POST['relate_to']; |
||
| 250 | } |
||
| 251 | if(isset($_POST['relate_id']) && !empty($_POST['relate_id'])) { |
||
| 252 | $get .= '&Leadsrelate_id='.$_POST['relate_id']; |
||
| 253 | } |
||
| 254 | |||
| 255 | //add all of the post fields to redirect get string |
||
| 256 | foreach ($focus->column_fields as $field) |
||
| 257 | { |
||
| 258 | if (!empty($focus->$field) && !is_object($focus->$field)) |
||
| 259 | { |
||
| 260 | $get .= "&Leads$field=".urlencode($focus->$field); |
||
| 261 | } |
||
| 262 | } |
||
| 263 | |||
| 264 | foreach ($focus->additional_column_fields as $field) |
||
| 265 | { |
||
| 266 | if (!empty($focus->$field)) |
||
| 267 | { |
||
| 268 | $get .= "&Leads$field=".urlencode($focus->$field); |
||
| 269 | } |
||
| 270 | } |
||
| 271 | |||
| 272 | if($focus->hasCustomFields()) { |
||
| 273 | foreach($focus->field_defs as $name=>$field) { |
||
| 274 | if (!empty($field['source']) && $field['source'] == 'custom_fields') |
||
| 275 | { |
||
| 276 | $get .= "&Leads$name=". (!empty($focus->$name) ? urlencode($focus->$name) : ''); |
||
| 277 | } |
||
| 278 | } |
||
| 279 | } |
||
| 280 | |||
| 281 | |||
| 282 | $emailAddress = new SugarEmailAddress(); |
||
| 283 | $get .= $emailAddress->getFormBaseURL($focus); |
||
| 284 | |||
| 285 | |||
| 286 | //create list of suspected duplicate lead ids in redirect get string |
||
| 287 | $i=0; |
||
| 288 | foreach ($duplicateLeads as $lead) |
||
| 289 | { |
||
| 290 | $get .= "&duplicate[$i]=".$lead['id']; |
||
| 291 | $i++; |
||
| 292 | } |
||
| 293 | |||
| 294 | //add return_module, return_action, and return_id to redirect get string |
||
| 295 | $get .= "&return_module="; |
||
| 296 | if(!empty($_POST['return_module'])) |
||
| 297 | { |
||
| 298 | $get .= $_POST['return_module']; |
||
| 299 | } else { |
||
| 300 | $get .= "Leads"; |
||
| 301 | } |
||
| 302 | |||
| 303 | //add return_module, return_action, and return_id to redirect get string |
||
| 304 | $urlData = array('return_module' => 'Leads', 'return_action' => ''); |
||
| 305 | foreach (array('return_module', 'return_action', 'return_id', 'popup', 'create', 'start') as $var) { |
||
| 306 | if (!empty($_POST[$var])) { |
||
| 307 | $urlData[$var] = $_POST[$var]; |
||
| 308 | } |
||
| 309 | } |
||
| 310 | $get .= "&".http_build_query($urlData); |
||
| 311 | $_SESSION['SHOW_DUPLICATES'] = $get; |
||
| 312 | |||
| 313 | if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') |
||
| 314 | { |
||
| 315 | ob_clean(); |
||
| 316 | $json = getJSONobj(); |
||
| 317 | echo $json->encode(array('status' => 'dupe', 'get' => $location)); |
||
| 318 | } else if(!empty($_REQUEST['ajax_load'])) { |
||
| 319 | echo "<script>SUGAR.ajaxUI.loadContent('index.php?$location');</script>"; |
||
| 320 | } else { |
||
| 321 | if(!empty($_POST['to_pdf'])) |
||
| 322 | { |
||
| 323 | $location .= '&to_pdf='.urlencode($_POST['to_pdf']); |
||
| 324 | } |
||
| 325 | header("Location: index.php?$location"); |
||
| 326 | } |
||
| 327 | return null; |
||
| 328 | } |
||
| 329 | } |
||
| 330 | |||
| 331 | if (!isset($_POST[$prefix.'email_opt_out'])) $focus->email_opt_out = 0; |
||
| 332 | if (!isset($_POST[$prefix.'do_not_call'])) $focus->do_not_call = 0; |
||
| 333 | |||
| 334 | if($do_save) { |
||
| 335 | if(!empty($GLOBALS['check_notify'])) { |
||
| 336 | $focus->save($GLOBALS['check_notify']); |
||
| 337 | } |
||
| 338 | else { |
||
| 339 | $focus->save(FALSE); |
||
| 340 | } |
||
| 341 | } |
||
| 342 | |||
| 343 | $return_id = $focus->id; |
||
| 344 | |||
| 345 | if (isset($_POST[$prefix.'prospect_id']) && !empty($_POST[$prefix.'prospect_id'])) { |
||
| 346 | $prospect=new Prospect(); |
||
| 347 | $prospect->retrieve($_POST[$prefix.'prospect_id']); |
||
| 348 | $prospect->lead_id=$focus->id; |
||
| 349 | // Set to keep email in target |
||
| 350 | $prospect->in_workflow = true; |
||
| 351 | $prospect->save(); |
||
| 352 | |||
| 353 | //if prospect id exists, make sure we are coming from prospect detail |
||
| 354 | if(strtolower($_POST['return_module']) =='prospects' && strtolower($_POST['return_action']) == 'detailview'){ |
||
| 355 | //create campaing_log entry |
||
| 356 | |||
| 357 | if(isset($focus->campaign_id) && $focus->campaign_id != null){ |
||
| 358 | campaign_log_lead_entry($focus->campaign_id,$prospect, $focus,'lead'); |
||
|
|
|||
| 359 | } |
||
| 360 | } |
||
| 361 | } |
||
| 362 | |||
| 363 | /////////////////////////////////////////////////////////////////////////////// |
||
| 364 | //// INBOUND EMAIL HANDLING |
||
| 365 | /////////////////////////////////////////////////////////////////////////////// |
||
| 366 | if(isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) { |
||
| 367 | if(!isset($current_user)) { |
||
| 368 | global $current_user; |
||
| 369 | } |
||
| 370 | |||
| 371 | // fake this case like it's already saved. |
||
| 372 | |||
| 373 | $email = new Email(); |
||
| 374 | $email->retrieve($_REQUEST['inbound_email_id']); |
||
| 375 | $email->parent_type = 'Leads'; |
||
| 376 | $email->parent_id = $focus->id; |
||
| 377 | $email->assigned_user_id = $current_user->id; |
||
| 378 | $email->status = 'read'; |
||
| 379 | $email->save(); |
||
| 380 | $email->load_relationship('leads'); |
||
| 381 | $email->leads->add($focus->id); |
||
| 382 | |||
| 383 | header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=".urlencode($_REQUEST['inbound_email_id'])."&parent_id=".$email->parent_id."&parent_type=".$email->parent_type.'&start='.urlencode($_REQUEST['start'])); |
||
| 384 | exit(); |
||
| 385 | } |
||
| 386 | //// END INBOUND EMAIL HANDLING |
||
| 387 | /////////////////////////////////////////////////////////////////////////////// |
||
| 388 | |||
| 389 | $GLOBALS['log']->debug("Saved record with id of ".$return_id); |
||
| 390 | if($redirect){ |
||
| 391 | handleRedirect($return_id, 'Leads'); |
||
| 392 | }else{ |
||
| 393 | return $focus; |
||
| 394 | } |
||
| 395 | } |
||
| 396 | |||
| 403 |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.