*    (i) the "Powered by SugarCRM" logo and
 *    (ii) the SugarCRM copyright notice
 * in the same form as they appear in the distribution.  See full license for
 * requirements.
 *
 * The Original Code is: SugarCRM Open Source
 * The Initial Developer of the Original Code is SugarCRM, Inc.
 * Portions created by SugarCRM are Copyright (C) 2004-2006 SugarCRM, Inc.;
 * All Rights Reserved.
 * Contributor(s): ______________________________________.
 ********************************************************************************/
/*********************************************************************************
 * Description:  Deletes an Account record and then redirects the browser to the 
 * defined return URL.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
require_once 'modules/Accounts/Account.php';
global $mod_strings;
$focus = new Account();
if (!isset($_REQUEST['record'])) {
    sugar_die($mod_strings['ERR_DELETE_RECORD']);
}
$focus->retrieve($_REQUEST['record']);
if (!$focus->ACLAccess('Delete')) {
    ACLController::displayNoAccess(true);
    sugar_cleanup(true);
}
$focus->mark_deleted($_REQUEST['record']);
header("Location: index.php?module=" . $_REQUEST['return_module'] . "&action=" . $_REQUEST['return_action'] . "&record=" . $_REQUEST['return_id']);
Beispiel #2
0
function create_account($user_name, $password, $name, $phone, $website)
{
    if (!validate_user($user_name, $password)) {
        return 0;
    }
    //todo make the activity body not be html encoded
    $seed_user = new User();
    $user_id = $seed_user->retrieve_user_id($user_name);
    $account = new Account();
    if (!$account->ACLAccess('Save')) {
        return -1;
    }
    $account->name = $name;
    $account->phone_office = $phone;
    $account->website = $website;
    $account->assigned_user_id = $user_id;
    $account->assigned_user_name = $user_name;
    $account->save();
    return $account->id;
}
function add_create_account($seed)
{
    global $current_user;
    $account_name = $seed->account_name;
    $account_id = $seed->account_id;
    $assigned_user_id = $current_user->id;
    // check if it already exists
    $focus = new Account();
    if ($focus->ACLAccess('Save')) {
        $class = get_class($seed);
        $temp = new $class();
        $temp->retrieve($seed->id);
        if (!isset($account_name) || $account_name == '') {
            return;
        }
        if (!isset($seed->accounts)) {
            $seed->load_relationship('accounts');
        }
        if ($seed->account_name == '' && isset($temp->account_id)) {
            $seed->accounts->delete($seed->id, $temp->account_id);
            return;
        }
        // attempt to find by id first
        $ret = $focus->retrieve($account_id, true, false);
        // if it doesn't exist by id, attempt to find by name (non-deleted)
        if (empty($ret)) {
            $query = "select {$focus->table_name}.id, {$focus->table_name}.deleted from {$focus->table_name} ";
            $query .= " WHERE name='" . $seed->db->quote($account_name) . "'";
            $query .= " ORDER BY deleted ASC";
            $result = $seed->db->query($query, true);
            $row = $seed->db->fetchByAssoc($result, false);
            if (!empty($row['id'])) {
                $focus->retrieve($row['id']);
            }
        } else {
            if ($focus->deleted) {
                $query2 = "delete from {$focus->table_name} WHERE id='" . $seed->db->quote($focus->id) . "'";
                $seed->db->query($query2, true);
                // it was deleted, create new
                $focus = BeanFactory::newBean('Accounts');
            }
        }
        // if we didnt find the account, so create it
        if (empty($focus->id)) {
            $focus->name = $account_name;
            if (isset($assigned_user_id)) {
                $focus->assigned_user_id = $assigned_user_id;
                $focus->modified_user_id = $assigned_user_id;
            }
            $focus->save();
        }
        if ($seed->accounts != null && $temp->account_id != null && $temp->account_id != $focus->id) {
            $seed->accounts->delete($seed->id, $temp->account_id);
        }
        if (isset($focus->id) && $focus->id != '') {
            $seed->account_id = $focus->id;
        }
    }
}
 function add_create_account($seed)
 {
     $GLOBALS['log']->info('Begin: SoapHelperWebServices->add_create_account');
     global $current_user;
     $account_name = $seed->account_name;
     $account_id = $seed->account_id;
     $assigned_user_id = $current_user->id;
     // check if it already exists
     $focus = new Account();
     if ($focus->ACLAccess('Save')) {
         $class = get_class($seed);
         $temp = new $class();
         $temp->retrieve($seed->id);
         if (!isset($account_name) || $account_name == '') {
             return;
         }
         // if
         if (!isset($seed->accounts)) {
             $seed->load_relationship('accounts');
         }
         // if
         if ($seed->account_name = '' && isset($temp->account_id)) {
             $seed->accounts->delete($seed->id, $temp->account_id);
             $GLOBALS['log']->info('End: SoapHelperWebServices->add_create_account');
             return;
         }
         $arr = array();
         $query = "select id, deleted from {$focus->table_name} WHERE name='" . $seed->db->quote($account_name) . "'";
         $result = $seed->db->query($query) or sugar_die("Error selecting sugarbean: " . mysql_error());
         $row = $seed->db->fetchByAssoc($result, -1, false);
         // we found a row with that id
         if (isset($row['id']) && $row['id'] != -1) {
             // if it exists but was deleted, just remove it entirely
             if (isset($row['deleted']) && $row['deleted'] == 1) {
                 $query2 = "delete from {$focus->table_name} WHERE id='" . $seed->db->quote($row['id']) . "'";
                 $result2 = $seed->db->query($query2) or sugar_die("Error deleting existing sugarbean: " . mysql_error());
             } else {
                 $focus->id = $row['id'];
             }
         }
         // if we didnt find the account, so create it
         if (!isset($focus->id) || $focus->id == '') {
             $focus->name = $account_name;
             if (isset($assigned_user_id)) {
                 $focus->assigned_user_id = $assigned_user_id;
                 $focus->modified_user_id = $assigned_user_id;
             }
             $focus->save();
         }
         if ($seed->accounts != null && $temp->account_id != null && $temp->account_id != $focus->id) {
             $seed->accounts->delete($seed->id, $temp->account_id);
         }
         if (isset($focus->id) && $focus->id != '') {
             $seed->account_id = $focus->id;
         }
         // if
         $GLOBALS['log']->info('End: SoapHelperWebServices->add_create_account');
     } else {
         $GLOBALS['log']->info('End: SoapHelperWebServices->add_create_account - Insufficient ACLAccess');
     }
     // else
 }
function add_create_account($seed)
{
    global $current_user;
    $account_name = $seed->account_name;
    $account_id = $seed->account_id;
    $assigned_user_id = $current_user->id;
    // check if it already exists
    $focus = new Account();
    if ($focus->ACLAccess('Save')) {
        $class = get_class($seed);
        $temp = new $class();
        $temp->retrieve($seed->id);
        if (!isset($account_name) || $account_name == '') {
            return;
        }
        if (!isset($seed->accounts)) {
            $seed->load_relationship('accounts');
        }
        if ($seed->account_name == '' && isset($temp->account_id)) {
            $seed->accounts->delete($seed->id, $temp->account_id);
            return;
        }
        $arr = array();
        $query = "select id, deleted from {$focus->table_name} ";
        $query .= " WHERE name='" . $seed->db->quote($account_name) . "'";
        $query .= " ORDER BY deleted ASC";
        $result = $seed->db->query($query, true);
        $row = $seed->db->fetchByAssoc($result, false);
        // we found a row with that id
        if (!empty($row['id'])) {
            // if it exists but was deleted, just remove it entirely
            if (!empty($row['deleted'])) {
                $query2 = "delete from {$focus->table_name} WHERE id='" . $seed->db->quote($row['id']) . "'";
                $result2 = $seed->db->query($query2, true);
            } else {
                $focus->id = $row['id'];
            }
        }
        // if we didnt find the account, so create it
        if (empty($focus->id)) {
            $focus->name = $account_name;
            if (isset($assigned_user_id)) {
                $focus->assigned_user_id = $assigned_user_id;
                $focus->modified_user_id = $assigned_user_id;
            }
            $focus->save();
        }
        if ($seed->accounts != null && $temp->account_id != null && $temp->account_id != $focus->id) {
            $seed->accounts->delete($seed->id, $temp->account_id);
        }
        if (isset($focus->id) && $focus->id != '') {
            $seed->account_id = $focus->id;
        }
    }
}