<?php
/**
 * @version $Id: guest.php 333 2008-04-03 02:07:00Z bigmouse-nfox $
 */

  function zen_delete_guest_account() {
    global $db;
    $guest_flag = $db->Execute("select customer_id from " . TABLE_GUEST_EXTRA . "");
    while (!$guest_flag->EOF) {
       $online_check_sql = "select count(customer_id) as count
                                from " . TABLE_WHOS_ONLINE . "
                                where customer_id = '" . $guest_flag->fields['customer_id'] ."'";
       $online_check = $db->Execute($online_check_sql);
          if ($online_check->fields['count'] < 1) {
            $customers_id = $guest_flag->fields['customer_id'];
              $db->Execute("delete from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customers_id . "' limit 1");
              $db->Execute("delete from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customers_id . "' limit 1");
              $db->Execute("delete from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . (int)$customers_id . "' limit 1");
              $db->Execute("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customers_id . "' limit 1");
              $db->Execute("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customers_id . "' limit 1");
              $db->Execute("delete from " . TABLE_GUEST_EXTRA . " where customer_id = '" . (int)$customers_id . "' limit 1");
          }
      $guest_flag->MoveNext();
    }
  }


  function zen_delete_guest_account_now() {
    global $db;
    $customers_id  = intval($_SESSION['customer_id']);
          $db->Execute("delete from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customers_id . "' limit 1");
          $db->Execute("delete from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customers_id . "' limit 1");
          $db->Execute("delete from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . (int)$customers_id . "' limit 1");
          $db->Execute("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customers_id . "' limit 1");
          $db->Execute("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customers_id . "' limit 1");
          $db->Execute("delete from " . TABLE_GUEST_EXTRA . " where customer_id = '" . (int)$customers_id . "' limit 1");
          unset($_SESSION['guest_shopping']);
          zen_session_destroy();
  }
?>