php switch function_name case show_goods VARS CALL TEMPLATE call_templ

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<?php
switch ($function_name) {
case 'show_goods';
/*VARS*/
/*CALL TEMPLATE*/call_template('goods/main.html',$CONTEXT=Array(
));
break;
case 'show_cat_goods';
/*VARS*/
$db = open_datebase_connection('DATEBASE#1');
$cat=mysql_fetch_array(mysql_query("SELECT * FROM project_categories WHERE id='".addslashes($request['1'])."'",$db));
/*CSETS begin*/
$paginate=16;//Only Integer
/*CSETS end*/
$goods_co=mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM project_goods WHERE cat='".addslashes($request['1'])."' AND (`sellscount`='0' OR `sales`<`sellscount`)",$db));
if(isSet($request['2']) AND preg_match("/^\d+$/iu",$request['2'])) {
$pag_nums=pag_nums($paginate,$request['2'],$goods_co['0']);
//$current_page=(($pag_nums['from']+$pag_nums['to'])/$paginate);
//exit('FROM: '.$pag_nums['from'].'<br />Take: '.$pag_nums['to'].'<br />ALL GOODS:'.$goods_co['0'].'<br />Current Page:'.$current_page);
$goods=mysql_query("SELECT * FROM project_goods WHERE cat='".addslashes($request['1'])."' AND (`sellscount`='0' OR `sales`<`sellscount`) LIMIT $pag_nums[from],$pag_nums[to]",$db);
}
else {
$pag_nums=pag_nums($paginate,1,$goods_co['0']);
$goods=mysql_query("SELECT * FROM project_goods WHERE cat='".addslashes($request['1'])."' AND (`sellscount`='0' OR `sales`<`sellscount`) LIMIT 0,$paginate",$db);
}
//GOODS LIST
$gds='';
while($g=mysql_fetch_array($goods)) {
$pic=explode('|',$g['pictures']);
$decoded_pic_path = decode_str($pic[0],True);
$anons=(mb_strlen($g['description'],'UTF-8')>15) ? trim(mb_substr($g['description'],0,15,'UTF-8')).'...':mb_substr($g['description'],0,15,'UTF-8');
$gds.='
<div id="tvr_ITEM">
<a href="/goods/'.$cat['id'].'/'.$g['id'].'">
<img id="tvr_image" src="/'.$pic[0].'"/>
</a>
<div id="tvr_tile">'.mb_substr($g['tile'],0,22,'UTF-8').'</div>
<div id="tvr_author"><a href="/users/'.$g['owner'].'" target="_blank">'.$g['owner_login'].'</a></div>
<div id="tvr_price">RUR '.$g['price'].'</div>
</div>';
}
//PAGINATOR
$last_page=(ceil($goods_co['0']/$paginate));
if(!empty($gds) AND $last_page>1) {
$current_page=(($pag_nums['from']+$pag_nums['to'])/$paginate);
$next_page=$current_page+1;
$prev_page=$current_page-1;
if(($prev_page-1)>1) {
$lpag.="<a href='/goods/1/page1'>&laquo;</a>";
}
if($prev_page>1) {
$lpag.="<a href='/goods/1/page".($prev_page-1)."'>&lsaquo;</a>";
}
if($current_page>1) {
$lpag.="<a href='/goods/1/page$prev_page'>$prev_page</a>";
}
if($current_page<$last_page) {
$rpag.="<a href='/goods/1/page$next_page'>$next_page</a>";
}
if($next_page<$last_page) {
$rpag.="<a href='/goods/1/page".($next_page+1)."'>&rsaquo;</a>";
}
if(($next_page+1)<$last_page) {
$rpag.="<a href='/goods/1/page$last_page'>&raquo;</a>";
}
}
$cat['tile'] = iconv('windows-1251', 'utf-8', $cat['tile']);
/*CALL TEMPLATE*/call_template('goods/cat_inside.html',$CONTEXT=Array(
'cat_tile'=>(mb_strlen($cat['tile'],'UTF-8')>15) ? trim(mb_substr($cat['tile'],0,15,'UTF-8')).'...':mb_substr($cat['tile'],0,15,'UTF-8'),
'cat_des'=>iconv('windows-1251','utf-8',$cat['des']),
'cat_id'=>$cat['id'],
'current_page'=>$current_page,
'paginator_l'=>$lpag,
'paginator_r'=>$rpag,
'cat_goods_list'=>(!empty($gds)) ? $gds:'В данной категории товаров не найдено!',
));
break;
case 'show_good';
/*VARS*/
$db = open_datebase_connection('DATEBASE#1');
$cat=mysql_fetch_array(mysql_query("SELECT * FROM project_categories WHERE id='".addslashes($request['1'])."'",$db));
$good=mysql_fetch_array(mysql_query("SELECT * FROM project_goods WHERE cat='".addslashes($request['1'])."' AND (`sellscount`='0' OR `sales`<`sellscount`) AND id='".addslashes($request['2'])."'",$db));
$owner=mysql_fetch_array(mysql_query("SELECT * FROM project_members WHERE id='".addslashes($good['owner'])."'",$db));
if(!$good) {$go_back='<meta http-equiv="refresh" content="0; url=/"> Товар не найден, возвращаемся.';} else {$go_back='';}
$pics=explode('|',$good['pictures']);
foreach($pics as $key=>$path) {
if(!empty($path)) {
$slides.='
<li class="pic">
<a href="/'.$pics[$key].'" rel="prettyPhoto[portfolio]" title="'.$good['tile'].'">
<img height="500" src="/'.$pics[$key].'" /><span class="img_overlay_zoom"></span>
</a>
</li>
';
}
}
$comments=mysql_query("SELECT * FROM project_comments WHERE good='".$good['id']."'",$db);
$cmz='';
while($comment=mysql_fetch_array($comments)) {
$cmz.='
<div id="comment">
<div id="info">
<span id="author" title="Ответить" onclick="jQuery(\'#comment_box\').val(jQuery(\'#comment_box\').val()+jQuery(this).text()+\',\').focus();">'.$comment['author'].'</span><span id="comment_date">'.$comment['comment_date'].'</span>
</div>
'.$comment['text'].'
</div>
';
}
@session_start();
if(isset($_SESSION['id']) AND isset($_SESSION['hash']) AND $user=mysql_fetch_array(mysql_query("SELECT * FROM `project_members` WHERE id='".$_SESSION['id']."' AND hash='".$_SESSION['hash']."'",$db)) OR $user['ip']==$_SERVER['REMOTE_ADDR'] AND $user['ip']==0) {
$comment_form='
<form id="comment_form" action="/controllers/users/users.php?action=add_comment" method="POST">
<div id="tile">Добавить комментарий</div>
<textarea required="" name="comment" id="comment_box" placeholder="Текст комментария (Макс. 5.000 символов)"></textarea>
<input type="submit" value="Отправить" id="send_comment" />
<input type="hidden" name="good" value="'.$good['id'].'" />
<input type="hidden" name="cat" value="'.$good['cat'].'" />
</form>
';
$send_mesBTN='href="/messages/write_to/{{owner_login}}"';
}
else {
$comment_form='
<form id="comment_form" action="#" method="POST">
<div id="tile">Добавить комментарий</div>
<textarea name="comment" disabled="disabled" placeholder="Добавлять комментарии могут только авторизованные пользователи"></textarea>
<input type="submit" style="background-color:#7D7D7D;" disabled="disabled" value="Отправить" id="send_comment" />
</form>
';
$send_mesBTN='onclick="alert(\'Авторизуйтесь, что бы отправлять личные сообщения!\');"';
}
$zipINFO='
Информация о архиве:<br />
Размер: '.filesize_get($good['zip']);
$cat['tile'] = iconv('windows-1251', 'utf-8', $cat['tile']);
/*CALL TEMPLATE*/call_template('goods/good_inside.html',$CONTEXT=Array(
'good_tile'=>(mb_strlen($good['tile'],'UTF-8')>15) ? trim(mb_substr($good['tile'],0,15,'UTF-8')).'...':mb_substr($good['tile'],0,15,'UTF-8'),
'good_id'=>$good['id'],
'cat_tile'=>(mb_strlen($cat['tile'],'UTF-8')>15) ? trim(mb_substr($cat['tile'],0,15,'UTF-8')).'...':mb_substr($cat['tile'],0,15,'UTF-8'),
'cat_id'=>$cat['id'],
'slides'=>$slides,
'send_mes_ONCLICK'=>$send_mesBTN,
'good_full_tile'=>$good['tile'],
'owner_login'=>$good['owner_login'],
'good_price'=>$good['price'],
'good_des'=>wordwrap($good['description'], 79, '<br />'),
'good_zip_info'=>$zipINFO,
'good_sales'=>$good['sales'],
'pos_rews'=>$good['pos_rews'],
'neg_rews'=>$good['neg_rews'],
'owner_pos_rews'=>$owner['positive_reviews'],
'owner_neg_rews'=>$owner['negative_reviews'],
'owner_id'=>$owner['id'],
'comments'=>$cmz,
'comment_form'=>$comment_form,
'go_back'=>$go_back,
));
break;
case 'filter_goods';
$input=$_POST['data'];
if(is_integer((int) $input['price']['from']) AND (is_integer((int) $input['price']['to']) OR $input['price']['to']=='') AND
is_integer((int) $input['pos_rews']['from']) AND (is_integer((int) $input['pos_rews']['to']) OR $input['pos_rews']['to']=='') AND
is_integer((int) $input['neg_rews']['from']) AND (is_integer((int) $input['neg_rews']['to']) OR $input['neg_rews']['to']=='') AND
is_integer((int) $input['sales']['from']) AND (is_integer((int) $input['sales']['to']) OR $input['sales']['to']=='') AND
(is_integer((int) $input['cat']) OR $input['cat']=='all')) {
//All NICE, LETS GO
//Составляем фильтр BEGIN
$filter['price_from']=($input['price']['from']<0) ? 0:$input['price']['from'];
$filter['price_to']=($input['price']['to']<=0) ? 9999999999:$input['price']['to'];
$filter['pos_rews_from']=($input['pos_rews']['from']<0) ? 0:$input['pos_rews']['from'];
$filter['pos_rews_to']=($input['pos_rews']['to']<=0) ? 9999999999:$input['pos_rews']['to'];
$filter['pos_neg_from']=($input['neg_rews']['from']<0) ? 0:$input['neg_rews']['from'];
$filter['pos_neg_to']=($input['neg_rews']['to']<=0) ? 9999999999:$input['neg_rews']['to'];
$filter['sales_from']=($input['sales']['from']<0) ? 0:$input['sales']['from'];
$filter['sales_to']=($input['sales']['to']<=0) ? 9999999999:$input['sales']['to'];
$filter['cat']=( ($input['cat']=='all' OR $input['cat'] == '') ? '':"AND cat='$input[cat]'" );
//Составляем фильтр END
$SFilter_query=sprintf("SELECT * FROM project_goods WHERE price>=%d AND price<=%d AND pos_rews>=%d AND pos_rews<=%d AND neg_rews>=%d AND neg_rews<=%d AND sales>=%d AND sales<=%d AND (`sellscount`='0' OR `sales`<`sellscount`) %s",
$filter['price_from'],$filter['price_to'],$filter['pos_rews_from'],$filter['pos_rews_to'],$filter['pos_neg_from'],$filter['pos_neg_to'],$filter['sales_from'],$filter['sales_to'],$filter['cat']);
$db = open_datebase_connection('DATEBASE#1');
$GG_by_filter=mysql_query($SFilter_query,$db);
if($GG_by_filter) {
//GetGoodsByFilter Ready
$gds='';
while($g=mysql_fetch_array($GG_by_filter)) {
$pic=explode('|',$g['pictures']);
$decoded_pic_path = decode_str($pic[0],True);
$anons=(mb_strlen($g['description'],'UTF-8')>15) ? trim(mb_substr($g['description'],0,15,'UTF-8')).'...':mb_substr($g['description'],0,15,'UTF-8');
$gds.='
<div id="tvr_ITEM">
<a href="/goods/'.$g['cat'].'/'.$g['id'].'">
<img id="tvr_image" src="/'.$pic[0].'"/>
</a>
<div id="tvr_tile">'.$g['tile'].'</div>
<div id="tvr_author"><a href="/users/'.$g['owner'].'" target="_blank">'.$g['owner_login'].'</a></div>
<div id="tvr_price">RUR '.$g['price'].'</div>
</div>';
}
/*CALL TEMPLATE*/call_template('goods/filter.html',$CONTEXT=Array(
'ShowGoodsByFilter'=>(empty($gds)) ? 'Ничего не найдено!':$gds,
));
}
else exit('<meta http-equiv="refresh" content="5; url=/">'.iconv('utf-8','windows-1251','Произошла ошибка, пожалуйста, повторите попытку!'));
}
else {
//Voodoo, break;
exit('<meta http-equiv="refresh" content="5; url=/">'.iconv('utf-8','windows-1251','Неправильно переданы параметры поиска, пожалуйста, повторите попытку!'));
}
break;
default;
echo 'Error!<br />Function '.$function_name.' does not exist!';
break;
}