Post by newcode » Sat Jan 28, 2012 8:52 am

new to opencart v 1.5.1.3.1
and I have my first question
how can I see the names of user who are login as admin user in the Dashboard
I have 2 persons the help me and I what to see if they are login in the Admin Dashboard
but Me only I am the Top Administrator so I need to see the names in the are of ( You are logged in as: My User name )
and to be able to see my staff names also ( when they login )
they have different privileges as admin user so they can not modify the setting in the site
I only have two User Groups
can this be possible in opencart?
if so can any one help
thanks in advance
OC

Image
http://www.ifixmaccomputers.com


User avatar
Newbie

Posts

Joined
Sat Jan 28, 2012 8:33 am


Post by JAY6390 » Sun Jan 29, 2012 1:57 am

There's no way of doing this "live" as such, but you could update your admin's table entries each time they refresh the page, and have a small control panel that shows you which admins are logged in

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by straightlight » Sun Jan 29, 2012 4:20 am

JAY6390 wrote:There's no way of doing this "live" as such
Incorrect. My theory regarding $GLOBALS on other topics says otherwise as I wouldn't be able to publish the Cart Sessions contribution if there wouldn't be a way nor this object would exist from PHP developers and is there for this purpose most specifically.

@newcode:

In admin/controller/home.php file,

find:

Code: Select all

if ($this->config->get('config_currency_auto')) {
			$this->load->model('localisation/currency');
		
			$this->model_localisation_currency->updateCurrencies();
		}
add after:

Code: Select all

$user_ids = array();
		$routes = array();
		$post_keys = array();
		$post_values = array();
		if (isset($GLOBALS['_SESSION']) && isset($GLOBALS['_GET']) && isset($GLOBALS['_POST'])) {
			foreach ($GLOBALS['_SESSION'] as $user_key => $user_id) {
				if ($user_key == 'user_id') {
					$user_ids[] = (int)$user_id;
					
					foreach($GLOBALS['_GET'] as $route_key => $route_name) {						
						if ($route_key == 'route') {
							$routes[] = $route_name;
						}
					}
					
					if (!empty($GLOBALS['_POST'])) {
						foreach ($GLOBALS['_POST'] as $post_key => $post_value) {
							$post_keys[] 		= $post_key;
							$post_values[] 		= $post_value;
						}							
					}
				}
			}
		}
		
		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
			
		} else {
			$page = 1;
		}
		
		$this->load->model('user/user');
		$this->load->model('user/user_group');
		
		$this->data['user_info'] = '';
		
		$this->data['text_user_monitor']		= $this->language->get('text_user_monitor');
		$this->data['text_username']			= $this->language->get('text_username');
		$this->data['text_user_group']			= $this->language->get('text_user_group');
		$this->data['text_route']				= $this->language->get('text_route');
		$this->data['text_action_modified']		= $this->language->get('text_action_modified');
		$this->data['text_ip']					= $this->language->get('text_ip');		
		
		if (!empty($user_ids) && !empty($routes)) {			
			$user_info = $this->model_user_user->getUsersByIds($user_ids);
				
			if (!empty($user_info)) {			
				if (isset($post_keys) && !empty($post_keys) && isset($post_values) && !empty($post_values)) {
					$file = DIR_LOGS . 'access.txt';		
					$handle = fopen($file, 'a+'); 				
				}
			
				$user_total = 0;
				foreach ($user_info as $user) {					
					foreach ($routes as $route) {
						$user_group_info = $this->model_user_user_group->getUserGroup($user['user_group_id']);
						
						$this->data['user_info'][] = array('username'				=> htmlentities($user['username'], ENT_QUOTES, 'UTF-8', true),
														   'href'					=> $this->url->link('user/user/update', 'token=' . $this->session->data['token'] . '&user_id=' . (int)$user['user_id'], 'SSL'),
														   'group_name'				=> htmlentities($user_group_info['name'], ENT_QUOTES, 'UTF-8', true),
														   'href_group'				=> $this->url->link('user/user_permission/update', 'token=' . $this->session->data['token'] . '&user_group_id=' . (int)$user['user_group_id'], 'SSL'),
													       'route'					=> htmlentities($route, ENT_QUOTES, 'UTF-8', true),
														   'href_route'				=> $this->url->link($route, 'token=' . $this->session->data['token'], 'SSL'),
													       'ip'						=> htmlentities($user['ip'], ENT_QUOTES, 'UTF-8', true),
													       'date_added'				=> date('Y-m-d H:i:s', strtotime($user['date_added'])),
														   'post_keys'				=> (isset($post_keys) && !empty($post_keys)) ? $post_keys : '',
														   'post_values'			=> (isset($post_values) && !empty($post_values) && isset($post_keys) && !empty($post_keys)) ? $post_values : '',
													      );
														  
						if (!empty($post_keys) && !empty($post_values)) {
							foreach ($post_keys as $key => $post_key) {
								foreach ($post_values as $key1 => $post_value) {
									if ($key == $key1) {
										fwrite($handle, 'Date ' . date('Y-m-d H:i:s', strtotime(time())) . ' => User (' . $user['username'] . ') path (' . str_replace('token=' . $this->session->data['token'], '', stripslashes($this->request->server['REQUEST_URI'])) . ' action (update: ' . $post_value . ')');
									}
								}
							}
						}
														  
						$user_total++;
					}					
				}
				
				$pagination = new Pagination();
				$pagination->total = (isset($user_total) && (int)$user_total > 0) ? (int)$user_total : 0;
				$pagination->page = $page;
				$pagination->limit = $this->config->get('config_admin_limit');
				$pagination->text = $this->language->get('text_pagination');
				$pagination->url = $this->url->link('common/home', 'token=' . $this->session->data['token'] . '&page={page}', 'SSL');
			
				$this->data['pagination'] = $pagination->render();
								
				if (isset($post_keys) && !empty($post_keys) && isset($post_values) && !empty($post_values)) {
					fclose($handle);
				}
			}			
		}
In admin/language/english/common/home.php file,

find:

Code: Select all

$_['text_customer']                 = 'Total Customers';
add after:

Code: Select all

$_['text_user_monitor']				= 'User Monitor';
$_['text_username']					= 'User Name';
$_['text_user_group']				= 'User Group';
$_['text_route']					= 'Current Route';
$_['text_ip']						= 'IP Address';
$_['text_action_modified'] 			= 'Modified Actions';
$_['text_modified_action']			= 'Action: ({post_key} -> {post_val})';
$_['text_no_actions']				= 'No modified actions';
In admin/model/user/user.php file,

find:

Code: Select all

public function getTotalUsersByEmail($email) {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "user` WHERE email = '" . $this->db->escape($email) . "'");
		
		return $query->row['total'];
	}	
add after:

Code: Select all

public function getUsersByIds($data) {
		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "user` WHERE user_id IN ('" . implode(", ", $data) . "')");
	
		return $query->rows;
	}
(Note to OC Developers: This step specifically should really be amongst the core on the next release so to help others to gather all required users by IDs next time).

In admin/view/template/common/home.tpl file,

find:

Code: Select all

<div class="latest">
        <div class="dashboard-heading"><?php echo $text_latest_10_orders; ?></div>
        <div class="dashboard-content">
          <table class="list">
            <thead>
              <tr>
                <td class="right"><?php echo $column_order; ?></td>
                <td class="left"><?php echo $column_customer; ?></td>
                <td class="left"><?php echo $column_status; ?></td>
                <td class="left"><?php echo $column_date_added; ?></td>
                <td class="right"><?php echo $column_total; ?></td>
                <td class="right"><?php echo $column_action; ?></td>
              </tr>
            </thead>
            <tbody>
              <?php if ($orders) { ?>
              <?php foreach ($orders as $order) { ?>
              <tr>
                <td class="right"><?php echo $order['order_id']; ?></td>
                <td class="left"><?php echo $order['customer']; ?></td>
                <td class="left"><?php echo $order['status']; ?></td>
                <td class="left"><?php echo $order['date_added']; ?></td>
                <td class="right"><?php echo $order['total']; ?></td>
                <td class="right"><?php foreach ($order['action'] as $action) { ?>
                  [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
                  <?php } ?></td>
              </tr>
              <?php } ?>
              <?php } else { ?>
              <tr>
                <td class="center" colspan="6"><?php echo $text_no_results; ?></td>
              </tr>
              <?php } ?>
            </tbody>
          </table>
        </div>
      </div>
add after:

Code: Select all

<div class="latest">
        <div class="dashboard-heading"><?php echo $text_user_monitor; ?></div>
        <div class="dashboard-content">
          <table class="list">
            <thead>
              <tr>
                <td class="right"><?php echo $text_username; ?></td>
				<td class="left"><?php echo $text_user_group; ?></td>
                <td class="left"><?php echo $text_route; ?></td>
				<td class="left"><?php echo $text_action_modified; ?></td>
                <td class="left"><?php echo $text_ip; ?></td>
				<td class="left"><?php echo $column_date_added; ?></td>
              </tr>
            </thead>
            <tbody>
              <?php if (isset($user_info) && !empty($user_info) && (int)$this->user->getId() == 1) { ?>
              <?php foreach ($user_info as $user) { ?>
              <tr>
                <td class="right"><a href="<?php echo $user['href']; ?>"><?php echo $user['username']; ?></a></td>
				<td class="left"><a href="<?php echo $user['href_group']; ?>"><?php echo $user['group_name']; ?></a></td>                
                <td class="left">
				<?php if (!empty($user['route'])) { ?>
					<a href="<?php echo $user['href_route']; ?>"><?php echo $user['route']; ?></a>
				<?php } ?>
				</td>
				<td class="left">
				<?php if (isset($user['post_keys']) && !empty($user['post_keys']) && isset($user['post_values']) && !empty($user['post_values'])) { ?>
					<?php foreach ($user['post_keys'] as $key => $post_key) { ?>
						<?php foreach ($user['post_values'] as $key1 => $post_value) { ?>
							<?php if ($key == $key1) { ?>
								<?php echo str_replace(array("{post_key}", "{post_val}"), array(htmlspecialentities($post_key, ENT_QUOTES, 'UTF-8', true), htmlspecialentities($post_value, ENT_QUOTES, 'UTF-8', true)), $this->language->get('text_modified_action')); ?>
							<?php } ?>
						<?php } ?>
					<?php } ?>
					
				<?php } else { ?>
					<?php echo $this->language->get('text_no_actions'); ?>
				<?php } ?>
				</td>
                <td class="left"><?php echo $user['ip']; ?></td>                
				<td class="left"><?php echo $user['date_added']; ?></td>                
              </tr>
              <?php } ?>
              <?php } else { ?>
              <tr>
                <td class="center" colspan="6"><?php echo $text_no_results; ?></td>
              </tr>
              <?php } ?>
            </tbody>
          </table>
		  <div class="pagination"><?php echo $pagination; ?></div>
        </div>
      </div>
This should give you what you wanted. The pagination has also been included in the code. If you need to change the user ID value 1 to another value in your case, simply edit this line:

Code: Select all

<?php if (isset($user_info) && !empty($user_info) && (int)$this->user->getId() == 1) { ?>
from the template file mentioned above.

Then, from admin/controller/common/header.php file,

find:

Code: Select all

$this->data['text_error_log'] = $this->language->get('text_error_log');
add after:

Code: Select all

$this->data['text_access_log'] = $this->language->get('text_access_log');
Then, find:

Code: Select all

$this->data['error_log'] = $this->url->link('tool/error_log', 'token=' . $this->session->data['token'], 'SSL');
add after:

Code: Select all

$this->data['access_log'] = $this->url->link('tool/access_log', 'token=' . $this->session->data['token'], 'SSL');
Then, in admin/language/english/common/header.php file,

find:

Code: Select all

$_['text_error_log']                   = 'Error Logs';
add after:

Code: Select all

$_['text_access_log']                  = 'Access Logs';
Then, in admin/view/template/common/header.tpl file,

find:

Code: Select all

<li><a href="<?php echo $error_log; ?>"><?php echo $text_error_log; ?></a></li>
add after:

Code: Select all

<li><a href="<?php echo $access_log; ?>"><?php echo $text_access_log; ?></a></li>
Then, go to your system - > users - > user groups and unlock the access log page.
Last edited by straightlight on Sun Jan 29, 2012 6:31 am, edited 2 times in total.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by adi_555 » Sun Jan 29, 2012 4:59 am

Thats a great mod!

Is it possible to log all actions by users? for investigation purpose?

Active Member

Posts

Joined
Mon Nov 08, 2010 6:21 pm

Post by straightlight » Sun Jan 29, 2012 5:06 am

The 'all actions' term must have a purpose for specific aspects. Monitoring activities must be done by subjects which, otherwise, it wouldn't be useful to build a monitoring system. Which type of actions are you referring to specifically ?

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by adi_555 » Sun Jan 29, 2012 5:09 am

I mean like

Date 29/01/2012 12:00 => User(Userxyz) path (/index.php?route=sale/order/edit) action(update order 1234)

Active Member

Posts

Joined
Mon Nov 08, 2010 6:21 pm

Post by JAY6390 » Sun Jan 29, 2012 5:46 am

@straightlight - you seem to have misunderstood what I meant by doing it live. You aren't tracking every live connection with your code. I never said it was impossible to track users completely

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by straightlight » Sun Jan 29, 2012 5:57 am

adi_555 wrote:I mean like

Date 29/01/2012 12:00 => User(Userxyz) path (/index.php?route=sale/order/edit) action(update order 1234)
Instructions modified above.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by adi_555 » Sun Jan 29, 2012 6:00 am

Where does it save the log? and what do i copy? cause I see all code remains same???

Active Member

Posts

Joined
Mon Nov 08, 2010 6:21 pm

Post by adi_555 » Sun Jan 29, 2012 6:03 am

Also it would be nice if OC had option for users to change their own password, sometimes people forget the password given by top admin :)

Active Member

Posts

Joined
Mon Nov 08, 2010 6:21 pm

Post by straightlight » Sun Jan 29, 2012 6:04 am

Incorrect. The code is NOT the same as before, I expanded it. As for the logs, there was no where it was said previously that you needed log files stored into FTP but I did used the $this->log->write method from OC to store the lines into the error logs.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Sun Jan 29, 2012 6:05 am

Also it would be nice if OC had option for users to change their own password, sometimes people forget the password given by top admin
This is an unrelated request. A new created topic would be more ideal in this case.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Sun Jan 29, 2012 6:08 am

JAY6390 wrote:@straightlight - you seem to have misunderstood what I meant by doing it live. You aren't tracking every live connection with your code. I never said it was impossible to track users completely
The methodology is clearly explained here: http://php.net/manual/en/reserved.variables.globals.php

You can see both versions between local and global variables.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by adi_555 » Sun Jan 29, 2012 6:10 am

straightlight wrote:Incorrect. The code is NOT the same as before, I expanded it. As for the logs, there was no where it was said previously that you needed log files stored into FTP but I did used the $this->log->write method from OC to store the lines into the error logs.
Isnt it possible to save the log in a another txt file and then give a link in admin just like error log?? errorlog file seems unreliable considering most users clear it after a while or so.

I think this would be great!

Active Member

Posts

Joined
Mon Nov 08, 2010 6:21 pm

Post by victorj » Sun Jan 29, 2012 6:15 am

Logging admin users is far more easy

download trace watch.
install and give it its own database

apply the logging code into de admin/index.php
now every pageload very detailed, ip, browser, date time spent on page total time and a lot more is logged.
even where they came from.

it is a very powerfull logger witch i use for the main website and tels far more than any other stats program

Koeltechnische deurrubbers eenvoudig online op maat bestellen.
Alle niet stekplichtige onderdelen zoals scharnieren, sloten, randverwarming en verlichting voor alle typen koelingen en vriezers.
https://koelcel-onderdelen.com


User avatar
Expert Member

Posts

Joined
Sat Jun 25, 2011 4:09 am
Location - Alkmaar Holland

Post by JAY6390 » Sun Jan 29, 2012 6:20 am

straightlight wrote:
JAY6390 wrote:@straightlight - you seem to have misunderstood what I meant by doing it live. You aren't tracking every live connection with your code. I never said it was impossible to track users completely
The methodology is clearly explained here: http://php.net/manual/en/reserved.variables.globals.php

You can see both versions between local and global variables.
What the hell are you on about? I've not said anything about super globals or $GLOBALS. I'm well aware of variable scope. You clearly have no idea what I was saying, and its not worth even trying to explain it to you

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by straightlight » Sun Jan 29, 2012 6:25 am

No offense intended Jay. I was simply stating the facts regarding the possibility of this variable which you state on the first reply that it wasn't possible doing this live. If I really misunderstood the term, then perhaps you could elaborate what it really meant while, right now, I do read this sentence as a not possible solution ?

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by JAY6390 » Sun Jan 29, 2012 6:29 am

It's possible to track user interaction. What I was saying was it's not possible to tell if a user is currently viewing the page in real time. it's done by checking if a user has done something in the last X minutes. This has nothing to do with globals, or anything like that, it's merely because PHP doesn't have any information as to any connections other than the current user executing a script at that time, plus Apache closes connections unless keep-alive is enabled

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by straightlight » Sun Jan 29, 2012 6:32 am

@adi_555:

Steps updated above. You can now use the 'Access Log' page within the system menu tree in the admin. The file will be written in system/logs/access.txt file.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Sun Jan 29, 2012 6:34 am

JAY6390 wrote:It's possible to track user interaction. What I was saying was it's not possible to tell if a user is currently viewing the page in real time. it's done by checking if a user has done something in the last X minutes. This has nothing to do with globals, or anything like that, it's merely because PHP doesn't have any information as to any connections other than the current user executing a script at that time, plus Apache closes connections unless keep-alive is enabled
Yes, that is correct regarding Apache and the keep-alive connection. There are no ways yet to track momentarily when a user will access a page until some time and if not expired during session already.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 49 guests