Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added user group permission check to product viewed report reset #1675

Merged
merged 7 commits into from
Aug 3, 2014
430 changes: 254 additions & 176 deletions upload/admin/controller/catalog/profile.php

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions upload/admin/controller/report/product_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ public function index() {

$data['reset'] = $this->url->link('report/product_viewed/reset', 'token=' . $this->session->data['token'] . $url, 'SSL');

if (isset($this->session->data['error'])) {
$data['error_warning'] = $this->session->data['error'];

unset($this->session->data['error']);
} elseif (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}

if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];

Expand Down Expand Up @@ -107,11 +117,15 @@ public function index() {
public function reset() {
$this->load->language('report/product_viewed');

$this->load->model('report/product');
if (!$this->user->hasPermission('modify', 'report/product_viewed')) {
$this->session->data['error'] = $this->language->get('error_permission');
} else {
$this->load->model('report/product');

$this->model_report_product->reset();
$this->model_report_product->reset();

$this->session->data['success'] = $this->language->get('text_success');
$this->session->data['success'] = $this->language->get('text_success');
}

$this->response->redirect($this->url->link('report/product_viewed', 'token=' . $this->session->data['token'], 'SSL'));
}
Expand Down
2 changes: 2 additions & 0 deletions upload/admin/controller/tool/error_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public function index() {

$data['heading_title'] = $this->language->get('heading_title');

$data['text_confirm'] = $this->language->get('text_confirm');

$data['button_clear'] = $this->language->get('button_clear');

if (isset($this->session->data['error'])) {
Expand Down
61 changes: 31 additions & 30 deletions upload/admin/language/english/catalog/profile.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
<?php
// Heading
$_['heading_title'] = 'Profiles';
$_['heading_title'] = 'Profiles';

// Text
$_['text_remove'] = 'Remove';
$_['text_edit'] = 'Edit';
$_['text_success'] = 'Profile was successfully added';
$_['text_removed'] = 'Profile(s) were removed';
$_['text_copied'] = 'Profile was copied';
$_['text_day'] = 'Day';
$_['text_week'] = 'Week';
$_['text_semi_month'] = 'Semi Month';
$_['text_month'] = 'Month';
$_['text_year'] = 'Year';
$_['text_recurring_help'] = 'Recurring amounts are calculated by the frequency and cycles. <br />For example if you use a frequency of "week" and a cycle of "2", then the user will be billed every 2 weeks. <br />The duration is the number of times the user will make a payment, set this to 0 if you want payments until they are cancelled.';
$_['text_remove'] = 'Remove';
$_['text_edit'] = 'Edit';
$_['text_success'] = 'Profile was successfully added';
$_['text_removed'] = 'Profile(s) were removed';
$_['text_copied'] = 'Profile was copied';
$_['text_day'] = 'Day';
$_['text_week'] = 'Week';
$_['text_semi_month'] = 'Semi Month';
$_['text_month'] = 'Month';
$_['text_year'] = 'Year';
$_['text_recurring_help'] = 'Recurring amounts are calculated by the frequency and cycles. <br />For example if you use a frequency of "week" and a cycle of "2", then the user will be billed every 2 weeks. <br />The duration is the number of times the user will make a payment, set this to 0 if you want payments until they are cancelled.';

// Entry
$_['entry_name'] = 'Name';
$_['entry_sort_order'] = 'Sort Order';
$_['entry_price'] = 'Price';
$_['entry_duration'] = 'Duration';
$_['entry_status'] = 'Status';
$_['entry_cycle'] = 'Cycle';
$_['entry_frequency'] = 'Frequency';
$_['entry_trial_price'] = 'Trial price';
$_['entry_trial_duration'] = 'Trial duration';
$_['entry_trial_status'] = 'Trial status';
$_['entry_trial_cycle'] = 'Trial cycle';
$_['entry_trial_frequency'] = 'Trial frequency';
$_['entry_name'] = 'Name';
$_['entry_sort_order'] = 'Sort Order';
$_['entry_price'] = 'Price';
$_['entry_duration'] = 'Duration';
$_['entry_status'] = 'Status';
$_['entry_cycle'] = 'Cycle';
$_['entry_frequency'] = 'Frequency';
$_['entry_trial_price'] = 'Trial price';
$_['entry_trial_duration'] = 'Trial duration';
$_['entry_trial_status'] = 'Trial status';
$_['entry_trial_cycle'] = 'Trial cycle';
$_['entry_trial_frequency'] = 'Trial frequency';

// Column
$_['column_name'] = 'Name';
$_['column_sort_order'] = 'Sort Order';
$_['column_action'] = 'Action';
$_['column_name'] = 'Name';
$_['column_sort_order'] = 'Sort Order';
$_['column_action'] = 'Action';

// Error
$_['error_warning'] = 'Warning: Please check the form carefully for errors!';
$_['error_permission'] = 'Warning: You do not have permission to modify profiles!';
$_['error_name'] = 'Profile Name must be greater than 3 and less than 255 characters!';
$_['error_warning'] = 'Warning: Please check the form carefully for errors!';
$_['error_permission'] = 'Warning: You do not have permission to modify profiles!';
$_['error_name'] = 'Profile Name must be greater than 3 and less than 255 characters!';
$_['error_product'] = 'Warning: This profile cannot be deleted as it is currently assigned to %s products!';
15 changes: 9 additions & 6 deletions upload/admin/language/english/report/product_viewed.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php
// Heading
$_['heading_title'] = 'Products Viewed Report';
$_['heading_title'] = 'Products Viewed Report';

// Text
$_['text_success'] = 'Success: You have reset the product viewed report!';
$_['text_success'] = 'Success: You have reset the product viewed report!';

// Column
$_['column_name'] = 'Product Name';
$_['column_model'] = 'Model';
$_['column_viewed'] = 'Viewed';
$_['column_percent'] = 'Percent';
$_['column_name'] = 'Product Name';
$_['column_model'] = 'Model';
$_['column_viewed'] = 'Viewed';
$_['column_percent'] = 'Percent';

// Error
$_['error_permission'] = 'Warning: You do not have permission to reset product viewed report!';
6 changes: 3 additions & 3 deletions upload/admin/language/english/tool/error_log.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
// Heading
$_['heading_title'] = 'Error Log';
$_['heading_title'] = 'Error Log';

// Text
$_['text_success'] = 'Success: You have successfully cleared your error log!';
$_['text_success'] = 'Success: You have successfully cleared your error log!';

// Error
$_['error_warning'] = 'Warning: Your error log file %s is %s!';
$_['error_warning'] = 'Warning: Your error log file %s is %s!';
$_['error_permission'] = 'Warning: You do not have permission to clear error log!';
2 changes: 1 addition & 1 deletion upload/admin/model/catalog/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function getOptionValueDescriptions($option_id) {
}

public function getTotalOptions() {
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "option`");
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "option`");

return $query->row['total'];
}
Expand Down
6 changes: 6 additions & 0 deletions upload/admin/model/catalog/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,12 @@ public function getTotalProductsByOptionId($option_id) {
return $query->row['total'];
}

public function getTotalProductsByProfileId($profile_id) {
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_profile WHERE profile_id = '" . (int)$profile_id . "'");

return $query->row['total'];
}

public function getTotalProductsByLayoutId($layout_id) {
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_layout WHERE layout_id = '" . (int)$layout_id . "'");

Expand Down
47 changes: 41 additions & 6 deletions upload/admin/model/catalog/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,51 @@ public function getProfileDescription($profile_id) {
return $profile_descriptions;
}

public function getProfiles() {
return $this->db->query("SELECT `p`.`profile_id`, `p`.`sort_order`, `pd`.`name` FROM `" . DB_PREFIX . "profile` AS `p` JOIN `" . DB_PREFIX . "profile_description` AS `pd` ON `pd`.`profile_id` = `p`.`profile_id` AND `pd`.`language_id` = " . (int)$this->config->get('config_language_id') . " ORDER BY p.sort_order ASC
")->rows;
}
public function getProfiles($data = array()) {

public function getTotalProfiles() {
$sql = "SELECT COUNT(DISTINCT p.profile_id) AS total FROM " . DB_PREFIX . "profile p";
$sql = "SELECT * FROM `" . DB_PREFIX . "profile` p LEFT JOIN " . DB_PREFIX . "profile_description pd ON (p.profile_id = pd.profile_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";

if (isset($data['filter_name']) && $data['filter_name'] !== null) {
$sql .= " AND pd.name LIKE '" . $this->db->escape($data['filter_name']) . "%'";
}

$sort_data = array(
'pd.name',
'p.sort_order'
);

if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY " . $data['sort'];
} else {
$sql .= " ORDER BY pd.name";
}

if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}

if (isset($data['start']) || isset($data['limit'])) {
if ($data['start'] < 0) {
$data['start'] = 0;
}

if ($data['limit'] < 1) {
$data['limit'] = 20;
}

$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
}

$query = $this->db->query($sql);

return $query->rows;
}

public function getTotalProfiles() {
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "profile`");

return $query->row['total'];
}
}
26 changes: 18 additions & 8 deletions upload/admin/view/template/catalog/profile_list.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,32 @@
<table class="table table-striped table-hover">
<thead>
<tr>
<td class="text-center" width="1"><input type="checkbox" onclick="$('input[name*=\'profile_ids\']').attr('checked', this.checked)"/></td>
<td class="text-left"><?php echo $column_name ?></td>
<td class="text-left"><?php echo $column_sort_order ?></td>
<td class="text-center" width="1"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
<td class="text-left"><?php if ($sort == 'pd.name') { ?>
<a href="<?php echo $sort_name; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_name; ?></a>
<?php } else { ?>
<a href="<?php echo $sort_name; ?>"><?php echo $column_name; ?></a>
<?php } ?></td>
<td class="text-right"><?php if ($sort == 'p.sort_order') { ?>
<a href="<?php echo $sort_sort_order; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_sort_order; ?></a>
<?php } else { ?>
<a href="<?php echo $sort_sort_order; ?>"><?php echo $column_sort_order; ?></a>
<?php } ?></td>
<td class="text-right"><?php echo $column_action ?></td>
</tr>
</thead>
<tbody>
<?php if ($profiles) { ?>
<?php foreach ($profiles as $profile) { ?>
<tr>
<td class="text-center"><input type="checkbox" name="profile_ids[]" value="<?php echo $profile['profile_id'] ?>"/></td>
<td class="text-center"><?php if (in_array($profile['profile_id'], $selected)) { ?>
<input type="checkbox" name="selected[]" value="<?php echo $profile['profile_id']; ?>" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="selected[]" value="<?php echo $profile['profile_id']; ?>" />
<?php } ?></td>
<td class="text-left"><?php echo $profile['name'] ?></td>
<td class="text-left"><?php echo $profile['sort_order'] ?></td>
<td class="text-right"><?php foreach ($profile['action'] as $action): ?>
[<a href="<?php echo $action['href'] ?>"><?php echo $action['name'] ?></a>]
<?php endforeach;?></td>
<td class="text-right"><?php echo $profile['sort_order'] ?></td>
<td class="text-right"><a href="<?php echo $profile['edit']; ?>" data-toggle="tooltip" title="<?php echo $button_edit; ?>" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td>
</tr>
<?php } ?>
<?php } else { ?>
Expand Down
7 changes: 6 additions & 1 deletion upload/admin/view/template/report/product_viewed.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right"><a href="<?php echo $reset; ?>" data-toggle="tooltip" title="<?php echo $button_reset; ?>" class="btn btn-danger"><i class="fa fa-refresh"></i></a></div>
<div class="pull-right"><a onclick="confirm('<?php echo $text_confirm; ?>') ? location.href='<?php echo $reset; ?>' : false;" data-toggle="tooltip" title="<?php echo $button_reset; ?>" class="btn btn-danger"><i class="fa fa-refresh"></i></a></div>
<h1><i class="fa fa-bar-chart-o"></i> <?php echo $heading_title; ?></h1>
</div>
</div>
<div class="container-fluid">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">&times;</button>
</div>
<?php } ?>
<?php if ($success) { ?>
<div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $success; ?>
<button type="button" class="close" data-dismiss="alert">&times;</button>
Expand Down
2 changes: 1 addition & 1 deletion upload/admin/view/template/tool/error_log.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right"><a href="<?php echo $clear; ?>" data-toggle="tooltip" title="<?php echo $button_clear; ?>" class="btn btn-danger"><i class="fa fa-eraser"></i></a></div>
<div class="pull-right"><a onclick="confirm('<?php echo $text_confirm; ?>') ? location.href='<?php echo $clear; ?>' : false;" data-toggle="tooltip" title="<?php echo $button_clear; ?>" class="btn btn-danger"><i class="fa fa-eraser"></i></a></div>
<h1><i class="fa fa-exclamation-circle"></i> <?php echo $heading_title; ?></h1>
</div>
</div>
Expand Down