1 | <?php |
---|
2 | defined('MPS_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | |
---|
5 | if(isset($_POST['check'])){ |
---|
6 | foreach($_POST['check'] AS $delete_id){ |
---|
7 | |
---|
8 | $query='DELETE FROM '.MPS_PRODUCT_TABLE.' |
---|
9 | WHERE id = '.$delete_id.';'; |
---|
10 | pwg_query($query); |
---|
11 | $page['infos']=l10n('deleted'); |
---|
12 | |
---|
13 | $query='DELETE FROM '.MPS_PROD_OPT_TABLE.' |
---|
14 | WHERE product_id = '.$delete_id.';'; |
---|
15 | pwg_query($query); |
---|
16 | |
---|
17 | |
---|
18 | } |
---|
19 | } |
---|
20 | |
---|
21 | if(isset($_POST['product_add'])) |
---|
22 | { |
---|
23 | if(!empty($_POST['id'])) |
---|
24 | { |
---|
25 | $id = $_POST['id']; |
---|
26 | $product = $_POST['product']; |
---|
27 | $noteAdmin = $_POST['noteAdmin']; |
---|
28 | $price = $_POST['price']; |
---|
29 | |
---|
30 | $query='UPDATE '.MPS_PRODUCT_TABLE.' |
---|
31 | SET product = \''.$product.'\',noteAdmin = \''.$noteAdmin.'\',price=\''.$price.'\' |
---|
32 | WHERE id = '.$id.';'; |
---|
33 | pwg_query($query); |
---|
34 | |
---|
35 | $query = 'DELETE FROM '.MPS_PROD_OPT_TABLE.' WHERE product_id IN ('.$id.');'; |
---|
36 | pwg_query($query); |
---|
37 | |
---|
38 | if(isset($_POST['opt'])) |
---|
39 | { |
---|
40 | $opt = $_POST['opt']; |
---|
41 | $inserts = array(); |
---|
42 | foreach ($opt as $opt_id) |
---|
43 | { |
---|
44 | $inserts[] = array( |
---|
45 | 'opt_id' => $opt_id, |
---|
46 | 'product_id' => $id, |
---|
47 | ); |
---|
48 | } |
---|
49 | mass_inserts( |
---|
50 | MPS_PROD_OPT_TABLE, |
---|
51 | array_keys($inserts[0]), |
---|
52 | $inserts |
---|
53 | ); |
---|
54 | } |
---|
55 | |
---|
56 | $page['infos']=l10n('Edit'); |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | if (empty($_POST['id'])and isset($_POST['product'])and isset($_POST['price'])and is_numeric($_POST['price'])) |
---|
61 | { |
---|
62 | $order = array(); |
---|
63 | $query ='SELECT * FROM '.MPS_PRODUCT_TABLE.';'; |
---|
64 | $result = pwg_query($query); |
---|
65 | while($row = pwg_db_fetch_assoc($result)){ |
---|
66 | $order[] = $row['order']; |
---|
67 | } |
---|
68 | if (count($order) == 0) { |
---|
69 | $order = 1; |
---|
70 | }else{ |
---|
71 | $order = max($order)+1; |
---|
72 | } |
---|
73 | |
---|
74 | $product = $_POST['product']; |
---|
75 | $noteAdmin = $_POST['noteAdmin']; |
---|
76 | $price = $_POST['price']; |
---|
77 | |
---|
78 | |
---|
79 | $query='INSERT into '.MPS_PRODUCT_TABLE.' (`order`,`product`,`noteAdmin`,`price`) |
---|
80 | values (\''.$order.'\',\''.$product.'\',\''.$noteAdmin.'\',\''.$price.'\');'; |
---|
81 | $result=pwg_query($query); |
---|
82 | $prod = pwg_db_insert_id(); |
---|
83 | |
---|
84 | if(isset($_POST['opt'])) |
---|
85 | { |
---|
86 | $opt = $_POST['opt']; |
---|
87 | $inserts = array(); |
---|
88 | foreach ($opt as $opt_id) |
---|
89 | { |
---|
90 | $inserts[] = array( |
---|
91 | 'opt_id' => $opt_id, |
---|
92 | 'product_id' => $prod, |
---|
93 | ); |
---|
94 | } |
---|
95 | mass_inserts( |
---|
96 | MPS_PROD_OPT_TABLE, |
---|
97 | array_keys($inserts[0]), |
---|
98 | $inserts |
---|
99 | ); |
---|
100 | } |
---|
101 | $page['infos']=l10n('Product registered'); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | if(isset($_POST['newOrder'])) |
---|
106 | { |
---|
107 | $newOrder = explode(",", $_POST['newOrder']); |
---|
108 | $ex = array_pop($newOrder); |
---|
109 | |
---|
110 | foreach( $newOrder as $order => $id ) |
---|
111 | { |
---|
112 | $order = $order +1; |
---|
113 | |
---|
114 | $query='UPDATE '.MPS_PRODUCT_TABLE.' SET `order` = \''.$order.'\' WHERE id = '.$id.';'; |
---|
115 | $result = pwg_query($query); |
---|
116 | |
---|
117 | $page['infos']=l10n('the order is changed'); |
---|
118 | |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | $select_type_opt=array( |
---|
123 | 'select' =>'select', |
---|
124 | 'radio' =>'radio', |
---|
125 | 'text' =>'text', |
---|
126 | 'textarea' =>'textarea', |
---|
127 | 'checkbox' =>'checkbox', |
---|
128 | ); |
---|
129 | |
---|
130 | if (isset($_POST['option_add'])) |
---|
131 | { |
---|
132 | $order = array(); |
---|
133 | $query ='SELECT * FROM '.MPS_OPTION_TABLE.';'; |
---|
134 | $result = pwg_query($query); |
---|
135 | while($row = pwg_db_fetch_assoc($result)){ |
---|
136 | $order[] = $row['order']; |
---|
137 | } |
---|
138 | |
---|
139 | if (count($order) == 0) { |
---|
140 | $order = 1; |
---|
141 | }else{ |
---|
142 | $order = max($order)+1; |
---|
143 | } |
---|
144 | |
---|
145 | $name = $_POST['name']; |
---|
146 | $type = $_POST['type']; |
---|
147 | $title = $_POST['title']; |
---|
148 | |
---|
149 | if(isset($_POST['requi'])){ |
---|
150 | $requi = $_POST['requi']; |
---|
151 | }else{ |
---|
152 | $requi = 0; |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | $query='INSERT into '.MPS_OPTION_TABLE.' (`name`,`type`,`titre`,`requi`,`order`) |
---|
157 | values (\''.$name.'\',\''.$type.'\',\''.$title.'\',\''.$requi.'\',\''.$order.'\');'; |
---|
158 | |
---|
159 | pwg_query($query); |
---|
160 | $select_id = pwg_db_insert_id(); |
---|
161 | |
---|
162 | if(isset($_POST['val'])){ |
---|
163 | $val = $_POST['val']; |
---|
164 | foreach($val as $val_ele) |
---|
165 | { |
---|
166 | $query='INSERT into '.MPS_OPT_VAL_TABLE.' (val,select_id) |
---|
167 | values (\''.$val_ele.'\',\''.$select_id.'\');'; |
---|
168 | pwg_query($query); |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | echo('<div><div id="idlastopt" data-idlo="'.$select_id.'"></div></div>'); |
---|
173 | |
---|
174 | } |
---|
175 | |
---|
176 | $query='SELECT * FROM '.MPS_PRODUCT_TABLE.' ORDER BY `order`;'; |
---|
177 | $result = pwg_query($query); |
---|
178 | $products = array(); |
---|
179 | while($row = pwg_db_fetch_assoc($result)){ |
---|
180 | $query=' |
---|
181 | SELECT * |
---|
182 | FROM '.MPS_PROD_OPT_TABLE.' AS op |
---|
183 | JOIN '.MPS_OPTION_TABLE.' AS p ON p.id = op.opt_id |
---|
184 | WHERE product_id = '.$row['id'].' |
---|
185 | ;'; |
---|
186 | $res = pwg_query($query); |
---|
187 | $opt = array(); |
---|
188 | while($row1 = pwg_db_fetch_assoc($res)){ |
---|
189 | $opt[] = $row1['name']; |
---|
190 | } |
---|
191 | $row['option'] = $opt ; |
---|
192 | $products[$row['id']]=$row; |
---|
193 | } |
---|
194 | |
---|
195 | |
---|
196 | $query='SELECT * FROM '.MPS_OPTION_TABLE.' ;'; |
---|
197 | $result = pwg_query($query); |
---|
198 | $option = array(); |
---|
199 | while($row = pwg_db_fetch_assoc($result)){ |
---|
200 | $option[$row['id']] = $row['name']; |
---|
201 | } |
---|
202 | |
---|
203 | $template->assign(array( |
---|
204 | 'mps_product' => $products, |
---|
205 | 'mps_option' => $option, |
---|
206 | 'mps_type_opt' => $select_type_opt, |
---|
207 | )); |
---|
208 | $template->set_filename('mps_content', realpath(MPS_PATH . 'admin/template/product.tpl')); |
---|