Skip to content

Commit 6a77273

Browse files
committedNov 4, 2012
Add "AutoBanner" module.
1 parent df88bbf commit 6a77273

File tree

8 files changed

+852
-0
lines changed

8 files changed

+852
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,328 @@
1+
<?php
2+
class ControllerModuleAutoBanner extends Controller {
3+
private $error = array();
4+
public $MODULENAME = 'autobanner';
5+
6+
function _make_static_data() {
7+
$this->load->language("module/{$this->MODULENAME}");
8+
$this->document->setTitle($this->language->get('heading_title'));
9+
$this->data['heading_title'] = $this->language->get('heading_title');
10+
11+
/* Breadcrumbs */
12+
$this->data['breadcrumbs'] = array();
13+
14+
$this->data['breadcrumbs'][] = array(
15+
'text' => $this->language->get('text_home'),
16+
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
17+
'separator' => FALSE
18+
);
19+
20+
$this->data['breadcrumbs'][] = array(
21+
'text' => $this->language->get('text_module'),
22+
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
23+
'separator' => ' :: '
24+
);
25+
26+
$this->data['breadcrumbs'][] = array(
27+
'text' => $this->language->get('heading_title'),
28+
'href' => $this->url->link("module/{$this->MODULENAME}", 'token=' . $this->session->data['token'], 'SSL'),
29+
'separator' => ' :: '
30+
);
31+
32+
/* Error messages */
33+
$error_msgs = array();
34+
if (isset($this->session->data['error'])) {
35+
$error_msgs[] = $this->session->data['error'];
36+
}
37+
if (isset($this->error['warning'])) {
38+
$error_msgs[] = $this->error['warning'];
39+
}
40+
$this->data['error_warning'] = join('<br />', $error_msgs);
41+
42+
if (isset($this->session->data['success'])) {
43+
$this->data['success'] = $this->session->data['success'];
44+
}
45+
else {
46+
$this->data['success'] = '';
47+
}
48+
$this->session->data['error'] = '';
49+
$this->session->data['success'] = '';
50+
51+
$this->children = array(
52+
'common/header',
53+
'common/footer'
54+
);
55+
}
56+
57+
function _get_banner_info($banner_id) {
58+
$banner_info = $this->model_design_banner->getBanner($banner_id);
59+
60+
$token = $this->session->data['token'];
61+
$banner_info['edit_link'] = $this->url->link(
62+
"module/{$this->MODULENAME}/update",
63+
"token=$token&banner_id=$banner_id", 'SSL');
64+
65+
return $banner_info;
66+
}
67+
68+
public function index() {
69+
$this->load->model('module/autobanner');
70+
$this->load->model('design/banner');
71+
72+
$this->_make_static_data();
73+
74+
/* Button */
75+
$this->data['button_insert'] = $this->language->get('button_insert');
76+
$this->data['button_delete'] = $this->language->get('button_delete');
77+
$this->data['insert'] = $this->url->link("module/{$this->MODULENAME}/insert", 'token=' . $this->session->data['token'], 'SSL');
78+
$this->data['delete'] = $this->url->link("module/{$this->MODULENAME}/delete", 'token=' . $this->session->data['token'], 'SSL');
79+
80+
/* Get banners which were created by this module */
81+
$own_banners = $this->model_module_autobanner->getBannerIds();
82+
$this->data['own_banners'] = array_map(array($this, '_get_banner_info'),
83+
$own_banners);
84+
85+
$this->template = "module/{$this->MODULENAME}.tpl";
86+
$this->response->setOutput($this->render());
87+
}
88+
89+
function _make_form_data($banner_id=0) {
90+
$this->data['text_enabled'] = $this->language->get('text_enabled');
91+
$this->data['text_disabled'] = $this->language->get('text_disabled');
92+
$this->data['text_default'] = $this->language->get('text_default');
93+
$this->data['text_image_manager'] = $this->language->get('text_image_manager');
94+
$this->data['text_browse'] = $this->language->get('text_browse');
95+
$this->data['text_clear'] = $this->language->get('text_clear');
96+
97+
$this->data['entry_name'] = $this->language->get('entry_name');
98+
$this->data['entry_title'] = $this->language->get('entry_title');
99+
$this->data['entry_link'] = $this->language->get('entry_link');
100+
$this->data['entry_image'] = $this->language->get('entry_image');
101+
$this->data['entry_status'] = $this->language->get('entry_status');
102+
103+
104+
if (isset($this->error['name'])) {
105+
$this->data['error_name'] = $this->error['name'];
106+
} else {
107+
$this->data['error_name'] = '';
108+
}
109+
110+
if ($banner_id) {
111+
$this->load->model('design/banner');
112+
$banner_info = $this->model_design_banner->getBanner($banner_id);
113+
$this->data['banner_id'] = $banner_id;
114+
}
115+
116+
if (isset($this->request->post['name'])) {
117+
$this->data['name'] = $this->request->post['name'];
118+
} elseif (!empty($banner_info)) {
119+
$this->data['name'] = $banner_info['name'];
120+
} else {
121+
$this->data['name'] = '';
122+
}
123+
124+
if (isset($this->request->post['status'])) {
125+
$this->data['status'] = $this->request->post['status'];
126+
} elseif (!empty($banner_info)) {
127+
$this->data['status'] = $banner_info['status'];
128+
} else {
129+
$this->data['status'] = true;
130+
}
131+
}
132+
133+
function _show_form($banner_id=0) {
134+
/* Button */
135+
$this->data['button_save'] = $this->language->get('button_save');
136+
$this->data['button_cancel'] = $this->language->get('button_cancel');
137+
138+
/* Target for form */
139+
$token = $this->session->data['token'];
140+
if ($banner_id) {
141+
$this->data['action'] = $this->url->link(
142+
"module/{$this->MODULENAME}/update",
143+
"token=$token&banner_id=$banner_id", 'SSL');
144+
}
145+
else {
146+
$this->data['action'] = $this->url->link(
147+
"module/{$this->MODULENAME}/insert",
148+
"token=$token", 'SSL');
149+
}
150+
151+
/* Cancel button's link target */
152+
$this->data['cancel'] = $this->url->link("module/{$this->MODULENAME}",
153+
"token=$token", 'SSL');
154+
155+
$this->_make_form_data($banner_id);
156+
157+
$this->document->addScript('view/javascript/jquery/ui/jquery.dataTables.min.js');
158+
$this->document->addStyle('view/stylesheet/autobanner.css');
159+
160+
$this->load->model('catalog/product');
161+
$this->load->model('tool/image');
162+
163+
if (!$banner_id) {
164+
$criteria = array('filter_status' => TRUE);
165+
$allproducts = $this->model_catalog_product->getProducts($criteria);
166+
$ownproducts = array();
167+
}
168+
else {
169+
$prd_ids = $this->model_module_autobanner->getProductIds($banner_id);
170+
$allproducts = $this->model_module_autobanner->getProductsByIds($prd_ids,
171+
FALSE);
172+
$ownproducts = $this->model_module_autobanner->getProductsByIds($prd_ids,
173+
TRUE);
174+
}
175+
176+
$allproducts = array_map(array($this, '_reduce_product'), $allproducts);
177+
$ownproducts = array_map(array($this, '_reduce_product'), $ownproducts);
178+
$this->data['allproducts'] = $allproducts;
179+
$this->data['ownproducts'] = $ownproducts;
180+
181+
$this->template = "module/{$this->MODULENAME}_form.tpl";
182+
$this->response->setOutput($this->render());
183+
}
184+
185+
public function insert() {
186+
$this->load->model('module/autobanner');
187+
$this->_make_static_data();
188+
189+
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
190+
$this->_process_submitted_data();
191+
}
192+
193+
$this->_show_form();
194+
}
195+
196+
public function update() {
197+
$this->load->model('module/autobanner');
198+
$this->_make_static_data();
199+
200+
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
201+
$this->_process_submitted_data();
202+
}
203+
204+
$id = (int)$this->request->get['banner_id'];
205+
$this->_show_form($id);
206+
}
207+
208+
function _reduce_product($prd) {
209+
$img = $prd['image'];
210+
if ($img && file_exists(DIR_IMAGE . $img)) {
211+
$image = $this->model_tool_image->resize($img, 40, 40);
212+
}
213+
else {
214+
$image = $this->model_tool_image->resize('no_image.jpg', 40, 40);
215+
}
216+
return array(
217+
'product_id' => $prd['product_id'],
218+
'name' => $prd['name'],
219+
'model' => $prd['model'],
220+
'image' => $image
221+
);
222+
}
223+
224+
function _desc_in_langs($desc, $languages) {
225+
$d = array();
226+
foreach ($languages as $l) {
227+
$lid = $l['language_id'];
228+
$d[$lid] = array('title' => $desc);
229+
}
230+
return $d;
231+
}
232+
function _process_submitted_data() {
233+
if (!$this->_validate()) {
234+
return;
235+
}
236+
237+
/* Data OK */
238+
$banner = array(
239+
'name' => $this->request->post['name'],
240+
'status' => $this->request->post['status']
241+
);
242+
if (isset($this->request->get['banner_id'])) {
243+
$banner_id = (int)$this->request->get['banner_id'];
244+
}
245+
$this->load->model('catalog/product');
246+
$this->load->model('localisation/language');
247+
$languages = $this->model_localisation_language->getLanguages();
248+
$products = $this->request->post['selected'];
249+
$banner_image = array();
250+
foreach ($products as $id) {
251+
$product_info = $this->model_catalog_product->getProduct($id);
252+
$banner_image_description = $this->_desc_in_langs($product_info['name'],
253+
$languages);
254+
$image = $product_info['image'];
255+
$cat = $this->model_catalog_product->getProductCategories($id)[0];
256+
$link = $this->url->link('product/product', "path=$cat&product_id=$id");
257+
$banner_image[] = compact('banner_image_description', 'image', 'link');
258+
}
259+
$banner['banner_image'] = $banner_image;
260+
261+
/* Save to database */
262+
$this->load->model('design/banner');
263+
if (isset($banner_id)) {
264+
$this->model_design_banner->editBanner($banner_id, $banner);
265+
/* Update the list of banners created by this module */
266+
$this->model_module_autobanner->editBanner($banner_id, $products);
267+
}
268+
else {
269+
$banner_id = $this->model_design_banner->addBanner($banner);
270+
/* Update the list of banners created by this module */
271+
$this->model_module_autobanner->addBanner($banner_id, $products);
272+
}
273+
$this->session->data['success'] = $this->language->get('text_success');
274+
275+
/* Redirect to parent page */
276+
$this->redirect($this->url->link('module/autobanner', 'token=' . $this->session->data['token'], 'SSL'));
277+
}
278+
279+
function _validate() {
280+
$this->request->post['name'] = trim($this->request->post['name']);
281+
if (!$this->user->hasPermission('modify', 'design/banner')) {
282+
$this->error['warning'] = $this->language->get('error_permission');
283+
}
284+
285+
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) {
286+
$this->error['name'] = $this->language->get('error_name');
287+
}
288+
289+
if (!$this->error) {
290+
return true;
291+
} else {
292+
return false;
293+
}
294+
}
295+
296+
public function install() {
297+
$this->load->language('extension/module');
298+
299+
/* Though permission checking has been done in extesion/module already,
300+
* we still have to check again because this function is public,
301+
* one may call it via URL. */
302+
if (!$this->user->hasPermission('modify', 'extension/module')) {
303+
$this->session->data['error'] = $this->language->get('error_permission');
304+
}
305+
else {
306+
/*Permisson is OK */
307+
$this->load->model('module/autobanner');
308+
$this->model_module_autobanner->install();
309+
}
310+
}
311+
312+
public function uninstall() {
313+
$this->load->language('extension/module');
314+
315+
/* Though permission checking has been done in extesion/module already,
316+
* we still have to check again because this function is public,
317+
* one may call it via URL. */
318+
if (!$this->user->hasPermission('modify', 'extension/module')) {
319+
$this->session->data['error'] = $this->language->get('error_permission');
320+
}
321+
else {
322+
/*Permisson is OK */
323+
$this->load->model('module/autobanner');
324+
$this->model_module_autobanner->uninstall();
325+
}
326+
}
327+
}
328+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
// Heading
3+
$_['heading_title'] = 'Auto Banner';
4+
5+
// Text
6+
$_['text_module'] = 'Modules';
7+
$_['text_success'] = 'Success: You have added/modified one Auto Banner!';
8+
9+
// Entry
10+
$_['entry_name'] = 'Banner Name:';
11+
$_['entry_title'] = 'Title:';
12+
$_['entry_link'] = 'Link:';
13+
$_['entry_image'] = 'Image:';
14+
$_['entry_status'] = 'Status:';
15+
16+
// Error
17+
$_['error_permission'] = 'Warning: You do not have permission to modify banners!';
18+
$_['error_name'] = 'Banner Name must be between 3 and 64 characters!';
19+
$_['error_title'] = 'Banner Title must be between 2 and 64 characters!';
20+
$_['error_default'] = 'Warning: This layout cannot be deleted as it is currently assigned as the default store layout!';
21+
$_['error_product'] = 'Warning: This layout cannot be deleted as it is currently assigned to %s products!';
22+
$_['error_category'] = 'Warning: This layout cannot be deleted as it is currently assigned to %s categories!';
23+
$_['error_information'] = 'Warning: This layout cannot be deleted as it is currently assigned to %s information pages!';
24+
?>
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
class ModelModuleAutoBanner extends Model {
3+
const TABLE_NAME = 'banner_to_products';
4+
public function install() {
5+
$this->uninstall();
6+
7+
$sql = "CREATE TABLE `".DB_PREFIX.self::TABLE_NAME."`
8+
(`banner_id` INT NOT NULL UNIQUE, `product_ids` TEXT NOT NULL,
9+
FOREIGN KEY (`banner_id`) REFERENCES `".DB_PREFIX.self::TABLE_NAME.
10+
"`(`banner_id`))
11+
ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin";
12+
$this->db->query($sql);
13+
}
14+
15+
public function uninstall() {
16+
$this->db->query("DROP TABLE IF EXISTS `".DB_PREFIX.self::TABLE_NAME."`");
17+
}
18+
19+
public function getBannerIds() {
20+
$sql = "SELECT `banner_id` FROM `".DB_PREFIX.self::TABLE_NAME."`";
21+
$query = $this->db->query($sql);
22+
return array_map(array($this, '_row_to_id'), $query->rows);
23+
}
24+
25+
public function getProductIds($banner_id) {
26+
if (empty($banner_id)) return FALSE;
27+
$sql = "SELECT `product_ids` FROM `".DB_PREFIX.self::TABLE_NAME."`
28+
WHERE `banner_id` = ".(int)$banner_id;
29+
$query = $this->db->query($sql);
30+
$row = $query->row;
31+
return unserialize($row['product_ids']);
32+
}
33+
34+
public function getProductsByIds($product_ids, $include = TRUE) {
35+
if (!is_array($product_ids)) {
36+
return FALSE;
37+
}
38+
39+
$prdlist = join(', ', $product_ids);
40+
41+
$sql = "SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)";
42+
$sql .= " WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
43+
44+
if ($include) {
45+
$sql .= " AND p.product_id IN ($prdlist)";
46+
}
47+
else {
48+
$sql .= " AND p.product_id NOT IN ($prdlist)";
49+
}
50+
51+
$sql .= " AND p.status = '1'";
52+
$sql .= " GROUP BY p.product_id";
53+
54+
$query = $this->db->query($sql);
55+
return $query->rows;
56+
}
57+
58+
public function addBanner($banner_id, $product_ids) {
59+
if (!is_array($product_ids)) {
60+
return FALSE;
61+
}
62+
$products = serialize($product_ids);
63+
$banner_id = (int)$banner_id;
64+
$sql = "INSERT INTO `".DB_PREFIX.self::TABLE_NAME."`
65+
SET `banner_id` = $banner_id, `product_ids` = '$products'";
66+
return $this->db->query($sql);
67+
}
68+
69+
public function editBanner($banner_id, $product_ids) {
70+
if (!is_array($product_ids)) {
71+
return FALSE;
72+
}
73+
$products = serialize($product_ids);
74+
$banner_id = (int)$banner_id;
75+
$sql = "UPDATE `".DB_PREFIX.self::TABLE_NAME."`
76+
SET `product_ids` = '$products'
77+
WHERE `banner_id` = $banner_id";
78+
return $this->db->query($sql);
79+
}
80+
81+
function _row_to_id($row) {
82+
return $row['banner_id'];
83+
}
84+
}
85+
?>
898 Bytes
Loading

‎upload/admin/view/javascript/jquery/ui/jquery.dataTables.min.js

+157
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#allproducts_wrapper {
2+
width: 46%;
3+
overflow: hidden;
4+
float: left
5+
}
6+
#ownproducts_wrapper {
7+
width: 46%;
8+
overflow: hidden;
9+
float: right
10+
}
11+
.dataTables_length {
12+
width: 200px;
13+
float: left
14+
}
15+
.dataTables_filter {
16+
width: 300px;
17+
float: right;
18+
text-align: right
19+
}
20+
.dataTables_info {
21+
width: 300px;
22+
float: left
23+
}
24+
.dataTables_paginate {
25+
width: 120px;
26+
float: right;
27+
text-align: right
28+
}
29+
.dataTables_paginate a {
30+
margin-left: 15px;
31+
}
32+
33+
img.addproduct:hover, img.remproduct:hover {
34+
cursor: pointer
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php echo $header ?>
2+
<div id="content">
3+
<div class="breadcrumb">
4+
<?php
5+
foreach ($breadcrumbs as $breadcrumb) {
6+
echo $breadcrumb['separator']; ?>
7+
<a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
8+
<?php
9+
}
10+
?>
11+
</div>
12+
<?php if ($error_warning) { ?>
13+
<div class="warning"><?php echo $error_warning; ?></div>
14+
<?php } ?>
15+
<?php if ($success) { ?>
16+
<div class="success"><?php echo $success; ?></div>
17+
<?php } ?>
18+
<div class="box">
19+
<div class="heading">
20+
<h1><img src="view/image/module.png" alt="" /> <?php echo $heading_title; ?></h1>
21+
<div class="buttons">
22+
<a onclick="location = '<?php echo $insert; ?>'" class="button"><?php echo $button_insert; ?></a>
23+
<a onclick="$('form').submit();" class="button"><?php echo $button_delete; ?></a>
24+
</div>
25+
</div>
26+
<div class="content">
27+
<table class='list'>
28+
<thead>
29+
<tr>
30+
<td><input type='checkbox' /></td>
31+
<td class='left'>Name</td>
32+
<td></td>
33+
</tr>
34+
</thead>
35+
<tbody>
36+
<?php
37+
foreach ($own_banners as $b) { ?>
38+
<tr>
39+
<td><input type='checkbox' name='selected[]' /></td>
40+
<td class='left'><?php echo $b['name']?></td>
41+
<td>
42+
<a href='<?php echo $b['edit_link']?>'>Edit</a>
43+
</td>
44+
</tr>
45+
<?php
46+
} ?>
47+
</tbody>
48+
</table>
49+
</div>
50+
</div>
51+
</div>
52+
<?php echo $footer ?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?php echo $header ?>
2+
<div id="content">
3+
<div class="breadcrumb">
4+
<?php
5+
foreach ($breadcrumbs as $breadcrumb) {
6+
echo $breadcrumb['separator']; ?>
7+
<a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
8+
<?php
9+
}
10+
?>
11+
</div>
12+
<?php if ($error_warning) { ?>
13+
<div class="warning"><?php echo $error_warning; ?></div>
14+
<?php } ?>
15+
16+
<div class="box">
17+
<div class="heading">
18+
<h1><img src="view/image/module.png" alt="" /> <?php echo $heading_title; ?></h1>
19+
<div class="buttons">
20+
<a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a>
21+
<a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a>
22+
</div>
23+
</div>
24+
<div class="content">
25+
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
26+
<?php
27+
if (isset($banner_id)) {
28+
echo "<input type='hidden' name='banner_id' value='$banner_id' />";
29+
}
30+
?>
31+
<table class="form">
32+
<tr>
33+
<td><span class="required">*</span> <?php echo $entry_name; ?></td>
34+
<td><input type="text" name="name" value="<?php echo $name; ?>" size="100" />
35+
<?php if ($error_name) { ?>
36+
<span class="error"><?php echo $error_name; ?></span>
37+
<?php } ?></td>
38+
</tr>
39+
<tr>
40+
<td><?php echo $entry_status; ?></td>
41+
<td><select name="status">
42+
<?php if ($status) { ?>
43+
<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
44+
<option value="0"><?php echo $text_disabled; ?></option>
45+
<?php } else { ?>
46+
<option value="1"><?php echo $text_enabled; ?></option>
47+
<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
48+
<?php } ?>
49+
</select></td>
50+
</tr>
51+
</table>
52+
53+
<div with='100%' style='overflow: hidden'>
54+
<table id='allproducts' class='list'>
55+
<thead>
56+
<tr>
57+
<td class='left'>Image</td>
58+
<td><?php echo $entry_name; ?></td>
59+
<td>Model</td>
60+
<td></td>
61+
</tr>
62+
</thead>
63+
<tbody>
64+
<?php
65+
foreach ($allproducts as $p) {
66+
$id = $p['product_id']; ?>
67+
<tr>
68+
<td><img src='<?php echo $p['image']?>' /></td>
69+
<td><?php echo $p['name']?></td>
70+
<td><?php echo $p['model']?></td>
71+
<td class='center'>
72+
<img class='addproduct' src='view/image/package_go.png'
73+
alt='<?php echo $id ?>'/></td>
74+
</tr>
75+
<?php
76+
}
77+
?>
78+
</tbody>
79+
</table>
80+
<table id='ownproducts' class='list'>
81+
<thead>
82+
<tr>
83+
<td class='left'>Image</td>
84+
<td><?php echo $entry_name; ?></td>
85+
<td>Model</td>
86+
<td></td>
87+
</tr>
88+
</thead>
89+
<tbody>
90+
<?php
91+
foreach ($ownproducts as $p) {
92+
$id = $p['product_id']; ?>
93+
<tr>
94+
<td><img src='<?php echo $p['image']?>' /></td>
95+
<td><?php echo $p['name']?></td>
96+
<td><?php echo $p['model']?></td>
97+
<td class='center'>
98+
<img class='remproduct' src='view/image/delete.png'
99+
alt='<?php echo $id ?>'/>
100+
<input type='hidden' name='selected[]' value='<?php echo $id ?>' />
101+
</td>
102+
</tr>
103+
<?php
104+
}
105+
?>
106+
</tbody>
107+
</table>
108+
</div>
109+
</form>
110+
</div>
111+
</div>
112+
</div>
113+
<script type='text/javascript'>
114+
var remove_empty = true;
115+
var table_allproducts = null;
116+
var table_ownproducts = null;
117+
/* Remove the row saying that there is no data */
118+
function remove_empty_row() {
119+
var tbody = $('#ownproducts > tbody:last');
120+
var td = tbody.find('td.dataTables_empty');
121+
if (td.length) {
122+
tbody.empty();
123+
}
124+
remove_empty = false;
125+
}
126+
127+
function init_tables() {
128+
$('#allproducts').removeAttr('style');
129+
table_allproducts = $('#allproducts').dataTable();
130+
$('#ownproducts').removeAttr('style');
131+
table_ownproducts = $('#ownproducts').dataTable({"bLengthChange": false, "bInfo": false})
132+
}
133+
134+
function restore_tables() {
135+
table_allproducts.fnDestroy();
136+
table_ownproducts.fnDestroy();
137+
}
138+
139+
$(document).ready(function() {
140+
init_tables();
141+
});
142+
143+
function select_product(event) {
144+
//if (remove_empty) remove_empty_row();
145+
restore_tables();
146+
var row = $(this).closest('tr');
147+
this.src = 'view/image/delete.png';
148+
var select_indicator = document.createElement('input')
149+
select_indicator.type = 'hidden'
150+
select_indicator.name = 'selected[]'
151+
select_indicator.value = this.alt
152+
$(this).closest('td').append(select_indicator)
153+
$(this).one('click', unselect_product);
154+
$('#ownproducts > tbody:last').append(row);
155+
init_tables();
156+
}
157+
158+
function unselect_product(event) {
159+
restore_tables();
160+
$(this).next('input[type=hidden]').remove()
161+
this.src = 'view/image/package_go.png';
162+
$(this).one('click', select_product);
163+
var row = $(this).closest('tr');
164+
$('#allproducts > tbody:last').append(row);
165+
init_tables();
166+
}
167+
168+
$('img.addproduct').one('click', select_product);
169+
$('img.remproduct').one('click', unselect_product);
170+
</script>
171+
<?php echo $footer ?>

0 commit comments

Comments
 (0)
Please sign in to comment.