Page 1 of 2

Help needed updating last part of old Inactive customers addon

Posted: Sat Jul 24, 2021 11:56 am
by 14Steve14
I have been updating an old osc addon to work with 1.0.7.11. It is an admin page and it deletes inactive customers/users. I have the page layout as I want it, and all seems to show correctly apart from the actual deleting of the customers. Here is the whole code for the page that I have so far.

Code: Select all

<?php
/*
  $Id: stats_inactive_user.php,v 1.2 2004/05/02 15:00:00
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2004 osCommerce

  Released under the GNU General Public License
  Created by John Wood - www.z-is.net
*/

 require('includes/application_top.php');
 
 require('includes/template_top.php');
?>

	<h1 class="display-4 mb-2"><?php echo HEADING_TITLE; ?></h1>

<?php
$cust_query = tep_db_query("select customers_firstname, customers_lastname from " . 'customers' . " where customers_id = '" . $_GET['id'] . "'");
$cust = tep_db_fetch_array($cust_query);

if ($_GET['go'] == ''){
?>
  <div class="table-responsive">
    <table class="table table-striped table-hover">
      <thead class="thead-dark">
        <tr>
                      <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_ID; ?></td>
                      <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CUSTOMERS; ?></td>
                      <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_EMAIL; ?></td>
                      <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_NEWS; ?></td>
                      <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_ACCOUNT_CREATED; ?></td>
                      <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_LAST_LOGON; ?></td>
                      <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_DELETE; ?></td>
                    </tr>
                       </thead>
<?php
  $siu_query_raw = "select ci.customers_info_date_of_last_logon, ci.customers_info_date_account_created, c.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address, c.customers_newsletter from " . 'customers_info' . " ci, " . 'customers' . " c left join " . 'orders' . " o on c.customers_id = o.customers_id where o.customers_id is NULL and c.customers_id = ci.customers_info_id order by c.customers_id";
  $siu_split = new splitPageResults($_GET['page'], MAX_DISPLAY_SEARCH_RESULTS, $siu_query_raw, $siu_query_numrows );
  $siu_query = tep_db_query($siu_query_raw);
  while ($customers = tep_db_fetch_array($siu_query)) {

    if ($customers['customers_newsletter'] == '1') {
        $customers['customers_newsletter'] = NEWSLETTER_YES;
      } else {
        $customers['customers_newsletter'] = NEWSLETTER_NO ;
      }
?>
    <tbody>
      <tr class="dataTableRow"> 
        <td class="dataTableContent"><?php echo $customers['customers_id'];?></td>
        <td class="dataTableContent"><?php echo $customers['customers_firstname'] . ' ' . $customers['customers_lastname'];?></td>
        <td class="dataTableContent"><?php echo '<a href="mailto:' . $customers['customers_email_address'] . '"><u>' . $customers['customers_email_address'] . '</u></a>' ; ?></td>
        <td class="dataTableContent"><?php echo $customers['customers_newsletter']; ?></td>
        <td class="dataTableContent"><?php echo tep_date_short($customers['customers_info_date_account_created']); ?></td>
        <td class="dataTableContent"><?php echo tep_date_short($customers['customers_info_date_of_last_logon']); ?></td>
        <td class="dataTableContent"><?php echo '<a href="' . tep_href_link('stats_inactive_user.php', 'go=delete&id=' . $customers['customers_id'] . '&page=' . $_GET['page']) .'">' . SIU_DELETE . '</a>'; ?></td>
      </tr>
<?php
  }
?>
      </tbody>
    </table>
  </div>
  
	<div class="row">
            <div class="col-sm-6"><?php echo $siu_split->display_count($siu_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_CUSTOMERS); ?></div>
            <div class="col-sm-6 text-sm-right"><?php echo $siu_split->display_links($siu_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $_GET['page'], tep_get_all_get_params(array('page', 'info', 'x', 'y', 'cID'))); ?></div>
          </tr>
  </div>
<?php
            } elseif ($_GET['go'] == 'delete'){
            echo '<br />' . sprintf(SURE_TO_DELETE, $cust['customers_firstname'] . ' ' . $cust['customers_lastname']) . '<br /><br />' . tep_draw_button(IMAGE_DELETE, 'trash', tep_href_link('stats_inactive_user.php',  'page=' . $page . '&go=deleteyes&id=' . $cid)) . '&nbsp;&nbsp;' . tep_draw_button(IMAGE_CANCEL, 'cancel', tep_href_link('stats_inactive_user.php',  'page=' . $page), 'primary') . '<br /><br />';
            } elseif ($_GET['go'] == 'deleteyes'){
		  tep_db_query("DELETE FROM " . 'customers' . " where customers_id = '" . $_GET['id'] . "'");
		  tep_db_query("DELETE FROM " . 'customers_basket' . " where customers_id = '" . $_GET['id'] . "'");
		  tep_db_query("DELETE FROM " . 'customers_basket_attributes' . " where customers_id = '" . $_GET['id'] . "'");
		  tep_db_query("DELETE FROM " . 'customers_info' . " where customers_info_id = '" . $_GET['id'] . "'");
		  tep_db_query("DELETE FROM " . 'address_book' . " where customers_id = '" . $_GET['id'] . "'");
		  tep_db_query("DELETE FROM " . 'products_notifications' . " where customers_id = '" . $_GET['id'] . "'");
		  echo '<br />' . sprintf(SIU_CUSTOMER_DELETED, $cust['customers_firstname'] . ' ' . $cust['customers_lastname']) . '<br /><br /><br />' . tep_draw_button(IMAGE_BACK, 'arrowrefresh-1-n', tep_href_link('stats_inactive_user.php',  'page=' . $page), 'primary') . '<br /><br /></p>'; 
		}
				
?>
<?php
  require 'includes/template_bottom.php';
  require 'includes/application_bottom.php';
?>
Using the delete customer button on the admin customers page I have changed the main bit of the page as follows but the customer is still not deleted.

Code: Select all

<?php
            } elseif ($_GET['go'] == 'delete'){
            echo '<br />' . sprintf(SURE_TO_DELETE, $cust['customers_firstname'] . ' ' . $cust['customers_lastname']) . '<br /><br />' . tep_draw_button(IMAGE_DELETE, 'trash', tep_href_link('stats_inactive_user.php',  'page=' . $page . '&go=deleteyes&id=' . $cid)) . '&nbsp;&nbsp;' . tep_draw_button(IMAGE_CANCEL, 'cancel', tep_href_link('stats_inactive_user.php',  'page=' . $page), 'primary') . '<br /><br />';
            } elseif ($_GET['go'] == 'deleteyes'){
		  tep_db_query("DELETE FROM customers WHERE customers_id = " . (int)$customers_id);
		  tep_db_query("DELETE FROM customers_basket WHERE customers_id = " . (int)$customers_id);
          tep_db_query("DELETE FROM customers_basket_attributes WHERE customers_id = " . (int)$customers_id);
		  tep_db_query("DELETE FROM customers_info WHERE customers_info_id = " . (int)$customers_id);
		  tep_db_query("DELETE FROM address_book WHERE customers_id = " . (int)$customers_id);
		  tep_db_query("DELETE FROM products_notifications WHERE customers_id = " . (int)$customers_id);
		  
		  echo '<br />' . sprintf(SIU_CUSTOMER_DELETED, $cust['customers_firstname'] . ' ' . $cust['customers_lastname']) . '<br /><br /><br />' . tep_draw_button(IMAGE_BACK, 'arrowrefresh-1-n', tep_href_link('stats_inactive_user.php',  'page=' . $page), 'primary') . '<br /><br /></p>'; 
		}
				
?>
<?php
I am obviously missing something but have no idea on what. Is anyone able to give advice?

Re: Help needed updating last part of old Inactive customers addon

Posted: Sat Jul 24, 2021 12:09 pm
by raiwa
Do you have $customers_id defined before using it in the queries?
In the original code $_GET['id’] is used in the queries.

Re: Help needed updating last part of old Inactive customers addon

Posted: Sat Jul 24, 2021 2:09 pm
by 14Steve14
raiwa wrote: Sat Jul 24, 2021 12:09 pm Do you have $customers_id defined before using it in the queries?
In the original code $_GET['id’] is used in the queries.
In the first lot of code I posted all I have changed is the way the page looks and it does not delete the customers. I copied the 2nd bit of code from the customers page as it looks like that bit of code had changed from the really old version of this addon.

The page displays all the required information as it did in the older version.

Re: Help needed updating last part of old Inactive customers addon

Posted: Sat Jul 24, 2021 5:31 pm
by raiwa
14Steve14 wrote: Sat Jul 24, 2021 2:09 pm ... and it does not delete the customers..
Exact this happens if you are using $customers_id in the delete queries and it has not been defined.
In customers.php from where you copied the code it is defined before the queries like this:

Code: Select all

        $customers_id = tep_db_prepare_input($_GET['cID']);
So looking at the original code of stats_inactive_user.php it should be in that file:

Code: Select all

$customers_id = tep_db_prepare_input($_GET['id']);
I do not see this line in your code. Or add it before the delete queries or use $_GET['id'] instead of $customers_id in the delete queries like in the old version.

Re: Help needed updating last part of old Inactive customers addon

Posted: Sun Aug 01, 2021 9:50 pm
by lambro28
Would be interested in something like this if you get it working @14Steve14 in exchange for beer tokens................ :-)

Re: Help needed updating last part of old Inactive customers addon

Posted: Mon Aug 02, 2021 7:01 am
by heatherbell
lambro28 wrote: Sun Aug 01, 2021 9:50 pm Would be interested in something like this
This addon by @zipurman does similar and a lot else besides app.php/addons/paid_addon/zipur_reporting_tool/

Re: Help needed updating last part of old Inactive customers addon

Posted: Mon Aug 02, 2021 7:59 am
by 14Steve14
lambro28 wrote: Sun Aug 01, 2021 9:50 pm Would be interested in something like this if you get it working @14Steve14 in exchange for beer tokens................ :-)
I would be very interested.

Re: Help needed updating last part of old Inactive customers addon

Posted: Wed Aug 04, 2021 4:55 pm
by lambro28
heatherbell wrote: Mon Aug 02, 2021 7:01 am
lambro28 wrote: Sun Aug 01, 2021 9:50 pm Would be interested in something like this
This addon by @zipurman does similar and a lot else besides app.php/addons/paid_addon/zipur_reporting_tool/
Thanks Heather, have that one already. You have to look at customers one by one rather then a list with a check and press a button in one go, which I think Steve's one will do, well fingers crossed!

Re: Help needed updating last part of old Inactive customers addon

Posted: Thu Aug 05, 2021 6:07 am
by heatherbell
lambro28 wrote: Wed Aug 04, 2021 4:55 pmwhich I think Steve's one will do, well fingers crossed!
I'm sure the community will look forward to seeing it in the Addons Library.

Re: Help needed updating last part of old Inactive customers addon

Posted: Thu Aug 05, 2021 8:14 am
by 14Steve14
lambro28 wrote: Wed Aug 04, 2021 4:55 pm
Thanks Heather, have that one already. You have to look at customers one by one rather then a list with a check and press a button in one go, which I think Steve's one will do, well fingers crossed!
I think it could be made to delete more than one at a time, but currently its a one at a time job, but also currently it does not delete anything, hence the request for help.