示例#1
0
function fn_delete_company($company_id)
{
    if (empty($company_id)) {
        return false;
    }
    //TODO log_event
    // Log user deletion
    /*fn_log_event('companies', 'delete', array (
    		'company_id' => $company_id
    	));*/
    $condition = fn_get_company_condition('company_id');
    $company_id = db_get_field("SELECT company_id FROM ?:companies WHERE 1 {$condition} AND company_id = ?i", $company_id);
    if (empty($company_id)) {
        return false;
    }
    db_query("DELETE FROM ?:companies WHERE company_id = ?i", $company_id);
    // deleting products
    $product_ids = db_get_fields("SELECT product_id FROM ?:products WHERE company_id = ?i", $company_id);
    foreach ($product_ids as $product_id) {
        fn_delete_product($product_id);
    }
    // deleting shipping
    $shipping_ids = db_get_fields("SELECT shipping_id FROM ?:shippings WHERE company_id = ?i", $company_id);
    foreach ($shipping_ids as $shipping_id) {
        fn_delete_shipping($shipping_id);
    }
    if (PRODUCT_TYPE == 'MULTIVENDOR') {
        db_query("DELETE FROM ?:company_descriptions WHERE company_id = ?i", $company_id);
        // deleting product_options
        $option_ids = db_get_fields("SELECT option_id FROM ?:product_options WHERE company_id = ?i", $company_id);
        foreach ($option_ids as $option_id) {
            fn_delete_product_option($option_id);
        }
        // deleting orders
        $order_ids = db_get_fields("SELECT order_id FROM ?:orders WHERE company_id = ?i", $company_id);
        foreach ($order_ids as $order_id) {
            fn_delete_order($order_id);
        }
        // deleting users
        $user_ids = db_get_fields("SELECT user_id FROM ?:users WHERE company_id = ?i", $company_id);
        foreach ($user_ids as $user_id) {
            fn_delete_user($user_id);
        }
        // deleting pages
        $page_ids = db_get_fields("SELECT page_id FROM ?:pages WHERE company_id = ?i", $company_id);
        foreach ($page_ids as $page_id) {
            fn_delete_page($page_id);
        }
        // deleting promotions
        $promotion_ids = db_get_fields("SELECT promotion_id FROM ?:promotions WHERE company_id = ?i", $company_id);
        fn_delete_promotions($promotion_ids);
    }
    //db_query("UPDATE ?:orders SET user_id = 0 WHERE company_id = ?i", $company_id);
    fn_set_hook('delete_company', $company_id);
    return true;
}
function fn_delete_company($company_id)
{
    if (empty($company_id)) {
        return false;
    }
    if (fn_allowed_for('MULTIVENDOR')) {
        // Do not delete vendor if there're any orders associated with this company
        if (db_get_field("SELECT COUNT(*) FROM ?:orders WHERE company_id = ?i", $company_id)) {
            fn_set_notification('W', __('warning'), __('unable_delete_vendor_orders_exists'), '', 'company_has_orders');
            return false;
        }
    }
    fn_set_hook('delete_company_pre', $company_id);
    $result = db_query("DELETE FROM ?:companies WHERE company_id = ?i", $company_id);
    // deleting categories
    $cat_ids = db_get_fields("SELECT category_id FROM ?:categories WHERE company_id = ?i", $company_id);
    foreach ($cat_ids as $cat_id) {
        fn_delete_category($cat_id, false);
    }
    // deleting products
    $product_ids = db_get_fields("SELECT product_id FROM ?:products WHERE company_id = ?i", $company_id);
    foreach ($product_ids as $product_id) {
        fn_delete_product($product_id);
    }
    // deleting shipping
    $shipping_ids = db_get_fields("SELECT shipping_id FROM ?:shippings WHERE company_id = ?i", $company_id);
    foreach ($shipping_ids as $shipping_id) {
        fn_delete_shipping($shipping_id);
    }
    if (fn_allowed_for('ULTIMATE')) {
        // deleting layouts
        $layouts = Layout::instance($company_id)->getList();
        foreach ($layouts as $layout_id => $layout) {
            Layout::instance($company_id)->delete($layout_id);
        }
    }
    $blocks = Block::instance($company_id)->getAllUnique();
    foreach ($blocks as $block) {
        Block::instance($company_id)->remove($block['block_id']);
    }
    $product_tabs = ProductTabs::instance($company_id)->getList();
    foreach ($product_tabs as $product_tab) {
        ProductTabs::instance($company_id)->delete($product_tab['tab_id'], true);
    }
    $_menus = Menu::getList(db_quote(" AND company_id = ?i", $company_id));
    foreach ($_menus as $menu) {
        Menu::delete($menu['menu_id']);
    }
    db_query("DELETE FROM ?:company_descriptions WHERE company_id = ?i", $company_id);
    // deleting product_options
    $option_ids = db_get_fields("SELECT option_id FROM ?:product_options WHERE company_id = ?i", $company_id);
    foreach ($option_ids as $option_id) {
        fn_delete_product_option($option_id);
    }
    // deleting company admins and users
    if (Registry::get('settings.Stores.share_users') != 'Y') {
        $users_condition = db_quote(' OR company_id = ?i', $company_id);
    } else {
        $users_condition = '';
        // Unassign users from deleted company
        db_query('UPDATE ?:users SET company_id = 0 WHERE company_id = ?i', $company_id);
    }
    $user_ids = db_get_fields("SELECT user_id FROM ?:users WHERE company_id = ?i AND user_type = ?s ?p", $company_id, 'V', $users_condition);
    foreach ($user_ids as $user_id) {
        fn_delete_user($user_id);
    }
    // deleting pages
    $page_ids = db_get_fields("SELECT page_id FROM ?:pages WHERE company_id = ?i", $company_id);
    foreach ($page_ids as $page_id) {
        fn_delete_page($page_id);
    }
    // deleting promotions
    $promotion_ids = db_get_fields("SELECT promotion_id FROM ?:promotions WHERE company_id = ?i", $company_id);
    fn_delete_promotions($promotion_ids);
    // deleting features
    $feature_ids = db_get_fields("SELECT feature_id FROM ?:product_features WHERE company_id = ?i", $company_id);
    foreach ($feature_ids as $feature_id) {
        fn_delete_feature($feature_id);
    }
    // deleting logos
    $types = fn_get_logo_types();
    foreach ($types as $type => $data) {
        fn_delete_logo($type, $company_id);
    }
    $payment_ids = db_get_fields('SELECT payment_id FROM ?:payments WHERE company_id = ?i', $company_id);
    foreach ($payment_ids as $payment_id) {
        fn_delete_payment($payment_id);
    }
    // Delete sitemap sections and links
    $params = array('company_id' => $company_id);
    $section_ids = fn_get_sitemap_sections($params);
    fn_delete_sitemap_sections(array_keys($section_ids));
    fn_set_hook('delete_company', $company_id, $result);
    return $result;
}
示例#3
0
                 $notify_user = !empty($user['notify_updated_user']) && $user['notify_updated_user'] == 'Y' ? true : false;
                 if (!empty($user['status']) && !$user['is_complete_data']) {
                     $result = db_query("UPDATE ?:users SET status = ?s WHERE user_id = ?i", $user['status'], $user['user_id']);
                     $force_notification = fn_get_notification_rules(array('notify_user' => $noify_user));
                     if (!empty($force_notification['C']) && $user['status'] == 'A' && $user_data['status'] == 'D') {
                         Mailer::sendMail(array('to' => $user_data['email'], 'from' => 'company_users_department', 'data' => array('user_data' => $user_data), 'tpl' => 'profiles/profile_activated.tpl', 'company_id' => $user_data['company_id']), fn_check_user_type_admin_area($user_data['user_type']) ? 'A' : 'C', $user_data['lang_code']);
                     }
                 }
                 $temp_auth = null;
                 $result = fn_twg_api_update_user($user, $temp_auth, $notify_user);
                 if (!$result) {
                     $msg = str_replace('[object_id]', $user['user_id'], __('twgadmin_wrong_api_object_data'));
                     $response->addError('ERROR_OBJECT_UPDATE', str_replace('[object]', 'users', __('twgadmin_wrong_api_object_data')));
                 }
             } elseif ($_REQUEST['action'] == 'delete') {
                 if (!fn_delete_user($user['user_id'])) {
                     $msg = str_replace('[object_id]', $user['user_id'], __('twgadmin_wrong_api_object_data'));
                     $response->addError('ERROR_OBJECT_DELETE', str_replace('[object]', 'users', __('twgadmin_wrong_api_object_data')));
                 }
             }
         } else {
             $response->addError('ERROR_WRONG_OBJECT_DATA', str_replace('[object]', 'users', __('twgadmin_wrong_api_object_data')));
         }
     }
 }
 if ($object == 'shipments') {
     if ($_REQUEST['action'] == 'update') {
         $shipments = fn_check_shipment_data($data);
         if ($shipments) {
             foreach ($shipments as $shipment) {
                 if (empty($shipment['shipment_id'])) {
示例#4
0
 public function delete($id)
 {
     $data = array();
     $status = Response::STATUS_BAD_REQUEST;
     if (fn_delete_user($id)) {
         $status = Response::STATUS_OK;
         $data['message'] = 'Ok';
     } elseif (!fn_notification_exists('extra', 'user_delete_no_permissions')) {
         $status = Response::STATUS_NOT_FOUND;
     }
     return array('status' => $status, 'data' => $data);
 }
示例#5
0
function fn_specific_development_before_login($request, $redirect_url)
{
    if (!empty($request['token'])) {
        $auth =& $auth;
        $_request = array();
        $_request[] = 'apiKey=' . Registry::get('addons.specific_development.apikey');
        $_request[] = 'token=' . $request['token'];
        list($header, $_result) = fn_https_request('POST', 'https://rpxnow.com/api/v2/auth_info', $_request);
        $data = fn_from_json($_result, true);
        if (isset($data['stat']) && $data['stat'] == 'ok') {
            $user_data = array();
            $user_data = db_get_row('SELECT user_id, password FROM ?:users WHERE janrain_identifier = ?s', md5($data['profile']['identifier']));
            if (empty($user_data['user_id'])) {
                Registry::get('settings.General.address_position') == 'billing_first' ? $address_zone = 'b' : ($address_zone = 's');
                $user_data = array();
                $user_data['janrain_identifier'] = md5($data['profile']['identifier']);
                $user_data['email'] = !empty($data['profile']['verifiedEmail']) ? $data['profile']['verifiedEmail'] : (!empty($data['profile']['email']) ? $data['profile']['email'] : $data['profile']['displayName'] . '@' . $data['profile']['preferredUsername'] . '.com');
                $user_data['user_login'] = !empty($data['profile']['verifiedEmail']) ? $data['profile']['verifiedEmail'] : (!empty($data['profile']['email']) ? $data['profile']['email'] : $data['profile']['displayName'] . '@' . $data['profile']['preferredUsername'] . '.com');
                $user_data['user_type'] = 'C';
                $user_data['is_root'] = 'N';
                $user_data['password1'] = $user_data['password2'] = '';
                $user_data['title'] = 'mr';
                $user_data[$address_zone . '_firstname'] = !empty($data['profile']['name']['givenName']) ? $data['profile']['name']['givenName'] : $data['profile']['displayName'];
                $user_data[$address_zone . '_lastname'] = !empty($data['profile']['name']['familyName']) ? $data['profile']['name']['familyName'] : '';
                list($user_data['user_id'], $profile_id) = fn_update_user('', $user_data, $auth, true, false, false);
            }
            $user_status = empty($user_data['user_id']) ? LOGIN_STATUS_USER_NOT_FOUND : fn_login_user($user_data['user_id']);
            if ($user_status == LOGIN_STATUS_OK) {
                if (empty($user_data['password'])) {
                    $subscriber = db_get_row("SELECT * FROM ?:subscribers WHERE email = ?s", $user_data['email']);
                    if (empty($subscriber)) {
                        $c_data = array('email' => $user_data['email'], 'timestamp' => TIME);
                        $subscriber_id = db_query("INSERT INTO ?:subscribers ?e", $c_data);
                        $_data['subscriber_id'] = $subscriber_id;
                        $_data['list_id'] = "1";
                        $_data['timestamp'] = TIME;
                        $_data['activation_key'] = md5(uniqid(rand()));
                        $_data['unsubscribe_key'] = md5(uniqid(rand()));
                        db_query("INSERT INTO ?:user_mailing_lists ?e", $_data);
                    } else {
                        $subscriber_id = $subscriber['subscriber_id'];
                    }
                    $redirect_url = 'checkout.checkout&edit_step=step_two&from_step=step_one';
                } else {
                    $redirect_url = !empty($_REQUEST['return_url']) ? $_REQUEST['return_url'] : $index_script;
                }
            } elseif ($user_status == LOGIN_STATUS_USER_DISABLED) {
                fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('error_account_disabled'));
                fn_save_post_data();
                $redirect_url = !empty($_REQUEST['return_url']) ? $_REQUEST['return_url'] : $index_script;
            } elseif ($user_status == LOGIN_STATUS_USER_NOT_FOUND) {
                fn_delete_notification('user_exist');
                fn_set_notification('W', fn_get_lang_var('warning'), fn_get_lang_var('janrain_cant_create_profile'));
                $redirect_url = !empty($_REQUEST['return_url']) ? $_REQUEST['return_url'] : $index_script;
            }
            fn_delete_user($user_data['user_id']);
        }
        unset($request['token']);
    } elseif (empty($_REQUEST['user_login']) || empty($_REQUEST['password'])) {
        $redirect_url = !empty($_REQUEST['return_url']) ? $_REQUEST['return_url'] : $index_script;
    }
}
示例#6
0
     }
     $redirect_params = array('user_id' => $user_id);
     if (Registry::get('settings.General.user_multiple_profiles') == 'Y') {
         $redirect_params['profile_id'] = $profile_id;
     }
     if (!empty($_REQUEST['user_type'])) {
         $redirect_params['user_type'] = $_REQUEST['user_type'];
     }
     if (!empty($_REQUEST['return_url'])) {
         $redirect_params['return_url'] = urlencode($_REQUEST['return_url']);
     }
     return array(CONTROLLER_STATUS_OK, 'profiles' . (!empty($user_id) ? '.update' : '.add') . '?' . http_build_query($redirect_params));
 }
 if ($mode == 'delete') {
     $user_type = fn_get_request_user_type($_REQUEST);
     fn_delete_user($_REQUEST['user_id']);
     return array(CONTROLLER_STATUS_REDIRECT, 'profiles.manage?user_type=' . $user_type);
 }
 if ($mode == 'delete_profile') {
     if (fn_is_restricted_admin($_REQUEST)) {
         return array(CONTROLLER_STATUS_DENIED);
     }
     $user_id = empty($_REQUEST['user_id']) ? $auth['user_id'] : $_REQUEST['user_id'];
     fn_delete_user_profile($user_id, $_REQUEST['profile_id']);
     return array(CONTROLLER_STATUS_OK, 'profiles.update?user_id=' . $user_id);
 }
 if ($mode == 'update_status') {
     $condition = fn_get_company_condition('?:users.company_id');
     $user_data = db_get_row("SELECT * FROM ?:users WHERE user_id = ?i {$condition}", $_REQUEST['id']);
     if (!empty($user_data)) {
         $result = db_query("UPDATE ?:users SET status = ?s WHERE user_id = ?i", $_REQUEST['status'], $_REQUEST['id']);
示例#7
0
 function deleteAllUsers($deleteAdmins = false)
 {
     $this->useDatabase($this->destinationDB);
     $query = "SELECT * FROM cscart_users";
     if (!$deleteAdmins) {
         $query = $query . " WHERE user_type != 'A'";
     }
     $result = mysqli_query($this->link, $query) or die("Failed select from: cscart_users" . mysqli_error($this->link));
     while ($user = mysqli_fetch_array($result, MYSQL_ASSOC)) {
         if (fn_delete_user($user['user_id'])) {
             echo "User {$user['user_id']} deleted<br>";
         }
     }
 }