Page 1 of 1

[RELEASED] - Admin IP Ignore

Posted: Wed Aug 20, 2008 2:31 am
by Qphoria
This contrib adds a new menu controller to allow ignoring a particular IP address from affecting statistics.
Useful for testing your site without being picked up as a customer. Currently, the only place this exists is
the “Products Viewed” report, but it is easily modified to include future statistics.

DOWNLOAD
DEMO (user:demo/pass:demo)
To test the demo:
1.  Enter your IP in the Admin IP.
2.  View the Reports->Products Viewed report and take count of a product.
3.  Visit that product on the front end.
4.  Verify the Product Viewed count did NOT increase.
5.  Change the Admin IP to something else.
6.  Visit the product again.
7.  Verify it the viewed count DID increase.

Enjoy
Q!

Re: Admin IP Ignore: 100% Complete - RELEASED

Posted: Wed Aug 20, 2008 4:04 am
by ogun
nice one, downloading :)

Re: Admin IP Ignore: 100% Complete - RELEASED

Posted: Sat Aug 23, 2008 4:40 am
by Geek
Nice job!

I had it working for a little while and then I ended up having to wipe the whole cart system out and restart from scratch. When I
tried to re-install it, my menu on the top goes away. Can't figure out why. I think it has something to do with the
'./admin/template/default/module/menu.tpl' file.

This is what my code looks like after I add the change from the original. And this is where my error ends up at.

Code: Select all

        ['', '', '', null, null],
 // Ignore Admin IP - Edited: geek@simplygeek.net
        ['', 'Admin IP', '../admin/index.php?controller=admin_ip’, null, null],
// End of Edit
    ['', '', '', null, null],
        ['', '', '', null, null]
This is what I have to do in order to have my menu come back after it disappears.

Code: Select all

        ['', '', '', null, null],
 // Ignore Admin IP - Edited: geek@simplygeek.net
        //['', 'Admin IP', '../admin/index.php?controller=admin_ip’, null, null],
// End of Edit
    ['', '', '', null, null],
        ['', '', '', null, null]
Any suggestions of what I may be doing wrong?

Re: Admin IP Ignore: 100% Complete - RELEASED

Posted: Sat Aug 23, 2008 4:46 am
by Qphoria
Honestly, we can't get rid of this file-based menu fast enough!

The string looks ok, but I wonder if it doesn't like you adding the //comments before and after it.

Soon we will have an db-based admin menu (like this) to replace the file-based one and never have these problems again!

Re: Admin IP Ignore: 100% Complete - RELEASED

Posted: Sat Aug 23, 2008 5:49 am
by Geek
Qphoria wrote: Honestly, we can't get rid of this file-based menu fast enough!

The string looks ok, but I wonder if it doesn't like you adding the //comments before and after it.

Soon we will have an db-based admin menu (like this) to replace the file-based one and never have these problems again!
I tried removing the //comments out before I posted and still nothing. I can still make it work by adding '../admin/index.php?controller=admin_ip' on to
the end of my URL and it seems to work fine. I just don't have a direct menu access to it. Oh well, I am sure that we will get it all fixed and straightened
out.

Edit:
I figured out what my problem was now.

Just a note for everyone that wants to use this mod at all, my mistake was that there must have been an extra carriage return (CR) somewhere in the code. The extra CR came from me just "copy, cut, and paste" from the PDF instruction file. I went and I manually edited the '../admin/template/default/module/menu.tpl' file instead of copy and paste and then my problem was fixed. I suggest you edit that file manually and not with your mouse.

Re: Admin IP Ignore: 100% Complete - RELEASED

Posted: Sat Aug 23, 2008 1:06 pm
by Qphoria
good catch!

Re: Admin IP Ignore: 100% Complete - RELEASED

Posted: Sat Aug 23, 2008 1:10 pm
by Geek
Qphoria wrote: good catch!
Haha! I am learning and picking up PHP and the OpenCart system, slowly but surely.

Actually, I have never been so proud of myself before tonight. Ha!
And I almost got a store up and fully functional just the way I need it to be setup as well.

Sorry, just had to gloat for a second there. :) Okay, now back on track...

Re: Admin IP Ignore: 100% Complete - RELEASED

Posted: Sat Aug 23, 2008 1:11 pm
by Qphoria
Good. can't wait to see the finished product

Re: Admin IP Ignore: 100% Complete - RELEASED

Posted: Sat Aug 23, 2008 1:30 pm
by fido-x
I've found similar sorts of problems with "cut & paste" of coding, with extra lines of space being added. This is primarily due to Windows using a carriage return AND a line feed, while Linux and Mac just use a carriage return. Text editors in Windows still behave like typewriters!

Re: Admin IP Ignore: 100% Complete - RELEASED

Posted: Mon Aug 25, 2008 5:34 pm
by frame
I would like to suggest (for the next release, hopefully it will be) to add the possibility to set more IP addresses.

Re: Admin IP Ignore: 100% Complete - RELEASED

Posted: Mon Aug 25, 2008 5:58 pm
by Qphoria
Yea, I was originally going to do a range. Then I thought it might make more sense to do other IPs .... maybe both.

Re: [RELEASED] - Admin IP Ignore

Posted: Mon Oct 06, 2008 10:25 pm
by frame
I have created a little mod as an extension to Qphoria's Ignore Admin IP @ Products Viewed Report.
So, this mod ignores admin IP @ People Online Report (as I know when I am online) and is based on the previous mod.
Only 2 extra files have to be modified (please backup them before make changes):

/admin/controller/home.php:

Code: Select all

.
.
function index() {
		$response =& $this->locator->get('response');
		$database =& $this->locator->get('database');
		$url      =& $this->locator->get('url');
		//Added by Frame
		$config   =& $this->locator->get('config');
		//EOF
		$language =& $this->locator->get('language');
		$template =& $this->locator->get('template');
		$customer =& $this->locator->get('customer');
		$currency =& $this->locator->get('currency');
		$module   =& $this->locator->get('module');
.
.
.
.
$view->set('online', $url->ssl('report_online'));
	//Added by Frame
            if ($_SERVER['REMOTE_ADDR'] == $config->get('config_admin_ip')) {
      		    if ($config->get('config_admin_ip_status') == "0") {
			$user_info = $database->getRow("select count(*) as total from session");
									} else {
    	$user_info = $database->getRow("select count(*) as total from session where ip <> '".$config->get('config_admin_ip')."'");}
		} else {
	$user_info = $database->getRow("select count(*) as total from session");
			}
	//EOF
    	$view->set('users', $user_info['total']);
and /admin/controller/report_online.php:

Code: Select all

.
.
function index() { 
		$database =& $this->locator->get('database');
		$language =& $this->locator->get('language');
		//Added by Frame
		$config   =& $this->locator->get('config');
		//EOF
		$response =& $this->locator->get('response');
		$template =& $this->locator->get('template');
		$module   =& $this->locator->get('module');
.
.
foreach ($results as $result) {
			$value = array();
 
			$a = preg_split("/(\w+)\|/", $result['value'], - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

			for ($i = 0; $i < count($a); $i = $i + 2) {
				$value[$a[$i]] = unserialize($a[$i + 1]);
			}
 		//Added by Frame
            if ($_SERVER['REMOTE_ADDR'] == $config->get('config_admin_ip')) {
      		    if ($config->get('config_admin_ip_status') == "0") {

			if (isset($value['user_id'])) {
				$user_info = $database->getRow("select username from user where user_id = '" . (int)$value['user_id'] . "'");

				$name = $language->get('text_admin', $user_info['username']);
			} elseif (isset($value['customer_id'])) {
				$customer_info = $database->getRow("select concat(firstname,' ',lastname) as name from customer where customer_id = '" . (int)$value['customer_id'] . "'");

				$name = $customer_info['name'];
			} else {
				$name = $language->get('text_guest');
			}
				$rows[] = array(
				'name'  => $name,
				'time'  => date('dS F Y h:i:s A', strtotime($result['time'])),
				'ip'    => $result['ip'],
				'url'   => $result['url'],
				'total' => (isset($value['products']) ? count($value['products']) : 0)
			);
									} else {
			if (isset($value['user_id'])) {
				$user_info = $database->getRow("select username from user where user_id = '" . (int)$value['user_id'] . "'");

				$name = $language->get('text_admin', $user_info['username']);
			}elseif (isset($value['customer_id'])) {
				$customer_info = $database->getRow("select concat(firstname,' ',lastname) as name from customer where customer_id = '" . (int)$value['customer_id'] . "'");

				$name = $customer_info['name'];
			} else {
				$name = $language->get('text_guest');
			}

			if ($_SERVER['REMOTE_ADDR'] <> $result['ip']) {
				$rows[] = array(
				'name'  => $name,
				'time'  => date('dS F Y h:i:s A', strtotime($result['time'])),
				'ip'    => $result['ip'],
				'url'   => $result['url'],
				'total' => (isset($value['products']) ? count($value['products']) : 0)
			);}
										}

		} else {
			if (isset($value['user_id'])) {
				$user_info = $database->getRow("select username from user where user_id = '" . (int)$value['user_id'] . "'");

				$name = $language->get('text_admin', $user_info['username']);
			} elseif (isset($value['customer_id'])) {
				$customer_info = $database->getRow("select concat(firstname,' ',lastname) as name from customer where customer_id = '" . (int)$value['customer_id'] . "'");

				$name = $customer_info['name'];
			} else {
				$name = $language->get('text_guest');
			}
				$rows[] = array(
				'name'  => $name,
				'time'  => date('dS F Y h:i:s A', strtotime($result['time'])),
				'ip'    => $result['ip'],
				'url'   => $result['url'],
				'total' => (isset($value['products']) ? count($value['products']) : 0)
			);
}
//EOF
			
		}

		$view = $this->locator->create('template');

This is not the most beautiful solution but it works (hopefully).
Bye
Frame

Re: [RELEASED] - Admin IP Ignore

Posted: Mon Oct 06, 2008 10:28 pm
by frame
I have just noticed a little bug, so I modified above the report_online.php

Re: [RELEASED] - Admin IP Ignore

Posted: Mon Oct 06, 2008 10:31 pm
by Qphoria
Nice. It looks like you added the check on the homepage and added the customer name on the report. Good additions :)