hpdl
|
1219
|
1
|
<?php
|
|
2
|
/*
|
|
3
|
$Id: $
|
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
|
8
|
Copyright (c) 2007 osCommerce
|
|
9
|
|
hpdl
|
1498
|
10
|
This program is free software; you can redistribute it and/or modify
|
|
11
|
it under the terms of the GNU General Public License v2 (1991)
|
|
12
|
as published by the Free Software Foundation.
|
hpdl
|
1219
|
13
|
*/
|
|
14
|
|
|
15
|
class osC_Manufacturers_Admin {
|
|
16
|
function getData($id, $language_id = null) {
|
|
17
|
global $osC_Database, $osC_Language;
|
|
18
|
|
|
19
|
if ( empty($language_id) ) {
|
|
20
|
$language_id = $osC_Language->getID();
|
|
21
|
}
|
|
22
|
|
|
23
|
$Qmanufacturers = $osC_Database->query('select m.*, mi.* from :table_manufacturers m, :table_manufacturers_info mi where m.manufacturers_id = :manufacturers_id and m.manufacturers_id = mi.manufacturers_id and mi.languages_id = :languages_id');
|
|
24
|
$Qmanufacturers->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
|
|
25
|
$Qmanufacturers->bindTable(':table_manufacturers_info', TABLE_MANUFACTURERS_INFO);
|
|
26
|
$Qmanufacturers->bindInt(':manufacturers_id', $id);
|
|
27
|
$Qmanufacturers->bindInt(':languages_id', $language_id);
|
|
28
|
$Qmanufacturers->execute();
|
|
29
|
|
|
30
|
$data = $Qmanufacturers->toArray();
|
|
31
|
|
|
32
|
$Qclicks = $osC_Database->query('select sum(url_clicked) as total from :table_manufacturers_info where manufacturers_id = :manufacturers_id');
|
|
33
|
$Qclicks->bindTable(':table_manufacturers_info', TABLE_MANUFACTURERS_INFO);
|
|
34
|
$Qclicks->bindInt(':manufacturers_id', $id);
|
|
35
|
$Qclicks->execute();
|
|
36
|
|
|
37
|
$data['url_clicks'] = $Qclicks->valueInt('total');
|
|
38
|
|
|
39
|
$Qproducts = $osC_Database->query('select count(*) as products_count from :table_products where manufacturers_id = :manufacturers_id');
|
|
40
|
$Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
|
|
41
|
$Qproducts->bindInt(':manufacturers_id', $id);
|
|
42
|
$Qproducts->execute();
|
|
43
|
|
|
44
|
$data['products_count'] = $Qproducts->valueInt('products_count');
|
|
45
|
|
|
46
|
$Qclicks->freeResult();
|
|
47
|
$Qproducts->freeResult();
|
|
48
|
$Qmanufacturers->freeResult();
|
|
49
|
|
|
50
|
return $data;
|
|
51
|
}
|
|
52
|
|
|
53
|
function save($id = null, $data) {
|
|
54
|
global $osC_Database, $osC_Language;
|
|
55
|
|
|
56
|
$error = false;
|
|
57
|
|
|
58
|
$osC_Database->startTransaction();
|
|
59
|
|
|
60
|
if ( is_numeric($id) ) {
|
|
61
|
$Qmanufacturer = $osC_Database->query('update :table_manufacturers set manufacturers_name = :manufacturers_name, last_modified = now() where manufacturers_id = :manufacturers_id');
|
|
62
|
$Qmanufacturer->bindInt(':manufacturers_id', $id);
|
|
63
|
} else {
|
|
64
|
$Qmanufacturer = $osC_Database->query('insert into :table_manufacturers (manufacturers_name, date_added) values (:manufacturers_name, now())');
|
|
65
|
}
|
|
66
|
|
|
67
|
$Qmanufacturer->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
|
|
68
|
$Qmanufacturer->bindValue(':manufacturers_name', $data['name']);
|
hpdl
|
1374
|
69
|
$Qmanufacturer->setLogging($_SESSION['module'], $id);
|
hpdl
|
1219
|
70
|
$Qmanufacturer->execute();
|
|
71
|
|
|
72
|
if ( !$osC_Database->isError() ) {
|
|
73
|
if ( is_numeric($id) ) {
|
|
74
|
$manufacturers_id = $id;
|
|
75
|
} else {
|
|
76
|
$manufacturers_id = $osC_Database->nextID();
|
|
77
|
}
|
|
78
|
|
|
79
|
$image = new upload('manufacturers_image', realpath('../' . DIR_WS_IMAGES . 'manufacturers'));
|
|
80
|
|
|
81
|
if ( $image->exists() ) {
|
|
82
|
if ( $image->parse() && $image->save() ) {
|
|
83
|
$Qimage = $osC_Database->query('update :table_manufacturers set manufacturers_image = :manufacturers_image where manufacturers_id = :manufacturers_id');
|
|
84
|
$Qimage->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
|
|
85
|
$Qimage->bindValue(':manufacturers_image', $image->filename);
|
|
86
|
$Qimage->bindInt(':manufacturers_id', $manufacturers_id);
|
hpdl
|
1554
|
87
|
$Qimage->setLogging($_SESSION['module'], $manufacturers_id);
|
hpdl
|
1219
|
88
|
$Qimage->execute();
|
|
89
|
|
|
90
|
if ( $osC_Database->isError() ) {
|
|
91
|
$error = true;
|
|
92
|
}
|
|
93
|
}
|
|
94
|
}
|
|
95
|
} else {
|
|
96
|
$error = true;
|
|
97
|
}
|
|
98
|
|
|
99
|
if ( $error === false ) {
|
|
100
|
foreach ( $osC_Language->getAll() as $l ) {
|
|
101
|
if ( is_numeric($id) ) {
|
|
102
|
$Qurl = $osC_Database->query('update :table_manufacturers_info set manufacturers_url = :manufacturers_url where manufacturers_id = :manufacturers_id and languages_id = :languages_id');
|
|
103
|
} else {
|
|
104
|
$Qurl = $osC_Database->query('insert into :table_manufacturers_info (manufacturers_id, languages_id, manufacturers_url) values (:manufacturers_id, :languages_id, :manufacturers_url)');
|
|
105
|
}
|
|
106
|
|
|
107
|
$Qurl->bindTable(':table_manufacturers_info', TABLE_MANUFACTURERS_INFO);
|
|
108
|
$Qurl->bindInt(':manufacturers_id', $manufacturers_id);
|
|
109
|
$Qurl->bindInt(':languages_id', $l['id']);
|
|
110
|
$Qurl->bindValue(':manufacturers_url', $data['url'][$l['id']]);
|
hpdl
|
1374
|
111
|
$Qurl->setLogging($_SESSION['module'], $manufacturers_id);
|
hpdl
|
1219
|
112
|
$Qurl->execute();
|
|
113
|
|
|
114
|
if ( $osC_Database->isError() ) {
|
|
115
|
$error = true;
|
|
116
|
break;
|
|
117
|
}
|
|
118
|
}
|
|
119
|
}
|
|
120
|
|
|
121
|
if ( $error === false ) {
|
|
122
|
$osC_Database->commitTransaction();
|
|
123
|
|
|
124
|
osC_Cache::clear('manufacturers');
|
|
125
|
|
|
126
|
return true;
|
|
127
|
}
|
|
128
|
|
|
129
|
$osC_Database->rollbackTransaction();
|
|
130
|
|
|
131
|
return false;
|
|
132
|
}
|
|
133
|
|
|
134
|
function delete($id, $delete_image = false, $delete_products = false) {
|
|
135
|
global $osC_Database;
|
|
136
|
|
|
137
|
if ( $delete_image === true ) {
|
|
138
|
$Qimage = $osC_Database->query('select manufacturers_image from :table_manufacturers where manufacturers_id = :manufacturers_id');
|
|
139
|
$Qimage->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
|
|
140
|
$Qimage->bindInt(':manufacturers_id', $id);
|
|
141
|
$Qimage->execute();
|
|
142
|
|
|
143
|
if ( $Qimage->numberOfRows() && !osc_empty($Qimage->value('manufacturers_image')) ) {
|
|
144
|
if ( file_exists(realpath('../' . DIR_WS_IMAGES . 'manufacturers/' . $Qimage->value('manufacturers_image'))) ) {
|
|
145
|
@unlink(realpath('../' . DIR_WS_IMAGES . 'manufacturers/' . $Qimage->value('manufacturers_image')));
|
|
146
|
}
|
|
147
|
}
|
|
148
|
}
|
|
149
|
|
|
150
|
$Qm = $osC_Database->query('delete from :table_manufacturers where manufacturers_id = :manufacturers_id');
|
|
151
|
$Qm->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
|
|
152
|
$Qm->bindInt(':manufacturers_id', $id);
|
hpdl
|
1374
|
153
|
$Qm->setLogging($_SESSION['module'], $id);
|
hpdl
|
1219
|
154
|
$Qm->execute();
|
|
155
|
|
|
156
|
$Qmi = $osC_Database->query('delete from :table_manufacturers_info where manufacturers_id = :manufacturers_id');
|
|
157
|
$Qmi->bindTable(':table_manufacturers_info', TABLE_MANUFACTURERS_INFO);
|
|
158
|
$Qmi->bindInt(':manufacturers_id', $id);
|
hpdl
|
1374
|
159
|
$Qmi->setLogging($_SESSION['module'], $id);
|
hpdl
|
1219
|
160
|
$Qmi->execute();
|
|
161
|
|
|
162
|
if ( $delete_products === true ) {
|
|
163
|
$Qproducts = $osC_Database->query('select products_id from :table_products where manufacturers_id = :manufacturers_id');
|
|
164
|
$Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
|
|
165
|
$Qproducts->bindInt(':manufacturers_id', $id);
|
|
166
|
$Qproducts->execute();
|
|
167
|
|
|
168
|
while ( $Qproducts->next() ) {
|
|
169
|
osC_Products_Admin::delete($Qproducts->valueInt('products_id'));
|
|
170
|
}
|
|
171
|
} else {
|
|
172
|
$Qupdate = $osC_Database->query('update :table_products set manufacturers_id = null where manufacturers_id = :manufacturers_id');
|
|
173
|
$Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
|
|
174
|
$Qupdate->bindInt(':manufacturers_id', $id);
|
hpdl
|
1374
|
175
|
$Qupdate->setLogging($_SESSION['module'], $id);
|
hpdl
|
1219
|
176
|
$Qupdate->execute();
|
|
177
|
}
|
|
178
|
|
|
179
|
osC_Cache::clear('manufacturers');
|
|
180
|
|
|
181
|
return true;
|
|
182
|
}
|
|
183
|
}
|
|
184
|
?>
|