Example #1
0
function handle_user_deactivate($user_id, $HTTP_VARS, &$errors)
{
    if ($user_id == get_opendb_session_var('user_id')) {
        $errors[] = array('error' => get_opendb_lang_var('cannot_deactivate_yourself'), 'detail' => '');
        return FALSE;
    } else {
        if (fetch_my_borrowed_item_cnt($user_id) > 0) {
            $errors[] = array('error' => get_opendb_lang_var('user_with_borrows_not_deactivated'), 'detail' => '');
            return FALSE;
        } else {
            if (fetch_owner_borrowed_item_cnt($user_id) > 0) {
                $errors[] = array('error' => get_opendb_lang_var('user_with_owner_borrows_not_deactivated'), 'detail' => '');
                return FALSE;
            } else {
                if ($HTTP_VARS['confirmed'] == 'true') {
                    // Cancel all reservations.
                    $results = fetch_owner_reserved_item_rs($user_id);
                    if ($results) {
                        while ($borrowed_item_r = db_fetch_assoc($results)) {
                            cancel_reserve_item($borrowed_item_r['sequence_number']);
                        }
                        db_free_result($results);
                    }
                    $results = fetch_my_reserved_item_rs($user_id);
                    if ($results) {
                        while ($borrowed_item_r = db_fetch_assoc($results)) {
                            cancel_reserve_item($borrowed_item_r['sequence_number']);
                        }
                        db_free_result($results);
                    }
                    // deactivate user.
                    if (deactivate_user($user_id)) {
                        return TRUE;
                    } else {
                        return FALSE;
                    }
                } else {
                    if ($HTTP_VARS['confirmed'] != 'false') {
                        // confirmation required.
                        return "__CONFIRM__";
                    } else {
                        return "__ABORTED__";
                    }
                }
            }
        }
    }
}
Example #2
0
/**
*/
function handle_cancelreserve($sequence_number, $more_information, &$errors)
{
    $borrowed_item_r = fetch_borrowed_item_r($sequence_number);
    if ($borrowed_item_r['borrower_id'] !== get_opendb_session_var('user_id') && !is_user_owner_of_item($borrowed_item_r['item_id'], $borrowed_item_r['instance_no']) && !is_user_granted_permission(PERM_ADMIN_BORROWER)) {
        $errors = get_opendb_lang_var('not_allowed_cancel_reserve');
        return FALSE;
    } else {
        if ($borrowed_item_r['status'] == 'X') {
            $errors = get_opendb_lang_var('already_cancelled');
            return FALSE;
        } else {
            if ($borrowed_item_r['status'] != 'R') {
                $errors = get_opendb_lang_var('borrowed_item_not_found');
                return FALSE;
            } else {
                if (cancel_reserve_item($sequence_number, $more_information)) {
                    return TRUE;
                } else {
                    return FALSE;
                }
            }
        }
    }
}