コード例 #1
0
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'modules/Leads/Lead.php';
     require_once 'include/formbase.php';
     $focus = new Lead();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (!isset($_POST[$prefix . 'email_opt_out'])) {
         $focus->email_opt_out = 'off';
     }
     if (!isset($_POST[$prefix . 'do_not_call'])) {
         $focus->do_not_call = 'off';
     }
     if (!empty($GLOBALS['check_notify'])) {
         $focus->save($GLOBALS['check_notify']);
     } else {
         $focus->save(FALSE);
     }
     $return_id = $focus->id;
     if (isset($_POST[$prefix . 'prospect_id']) && !empty($_POST[$prefix . 'prospect_id'])) {
         if (!class_exists('Prospect')) {
             require_once 'modules/Prospects/Prospect.php';
         }
         $prospect = new Prospect();
         $prospect->retrieve($_POST[$prefix . 'prospect_id']);
         $prospect->lead_id = $focus->id;
         $prospect->save();
         $linked_beans = $prospect->get_linked_beans('campaigns', 'CampaignLog');
         if (empty($linked_beans)) {
             $linked_beans = array();
         }
         foreach ($linked_beans as $thebean) {
             $thebean->id = null;
             $thebean->target_id = $focus->id;
             $thebean->target_type = 'Leads';
             $thebean->archived = 1;
             $thebean->save();
         }
     }
     ///////////////////////////////////////////////////////////////////////////////
     ////	INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
         if (!isset($current_user)) {
             global $current_user;
         }
         // fake this case like it's already saved.
         require_once 'modules/Emails/Email.php';
         $email = new Email();
         $email->retrieve($_REQUEST['inbound_email_id']);
         $email->parent_type = 'Leads';
         $email->parent_id = $focus->id;
         $email->assigned_user_id = $current_user->id;
         $email->status = 'read';
         $email->save();
         $email->load_relationship('leads');
         $email->leads->add($focus->id);
         header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start']);
         exit;
     }
     ////	END INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if ($redirect) {
         handleRedirect($return_id, 'Leads');
     } else {
         return $focus;
     }
 }