gallery.class.php
2.96 KB
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
<?php
Class Gallery{
private $db;
private $lang;
private $path_pic = array('pic'=>"./pics/catalogs_gallery/",
'pic_big'=>"./pics/catalogs_gallery/big/");
function __construct($lang){
$this->db = sdb::getInstance();
$this->lang = $lang;
}
public function valid($data,$upload = null){
$error = array();
if(!preg_match("/.{1,200}/i",$data['name']))$error[] = "Îøèáêà ââîäà Íàçâàíèå!";
if(isset($upload['pic']['name']) && $upload['pic']['name']!=null){
$type = substr(strrchr($upload['pic']['name'],"."),1);
if( !preg_match("/^(jpeg|jpg|gif|png)$/i",$type) ) $error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif.";
}
return $error;
}
public function save($data,$upload = null){
$table_name = "catalogs_gallery";
if($data['update_id']>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "id={$data['update_id']}";}else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = null;}
$fields_values = array("name_".$this->lang=>$data['name'],
"product_id"=>$data['product_id'],
"type"=>$data['type'],
"code"=>$data['code']
);
if(isset($data['delete_pic']) && $data['delete_pic']==1){
if($data['update_id']>0)$this->deletePic($data['update_id']);
$fields_values['pic'] = null; $fields_values['pic_big'] = null;
}
if($upload['pic']['tmp_name']){
if($data['update_id']>0)$this->deletePic($data['update_id']);
$fields_values['pic'] = upload_ImageResize($upload['pic'],array('crop'=>true,'width'=>"64",'height'=>"42",'upload_path'=>$this->path_pic['pic']));
$fields_values['pic_big'] = upload_ImageResize($upload['pic'],array('width'=>"800",'height'=>"800",'upload_path'=>$this->path_pic['pic_big']));
}
$this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where);
return $id;
}
private function deletePic($id){
$sql = "select pic,pic_big from catalogs_gallery where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink($this->path_pic['pic'] . $row['pic']);
@unlink($this->path_pic['pic_big'] . $row['pic_big']);
}
public function delete($id){
$this->deletePic($id);
$this->db->query("delete from catalogs_gallery where id=?",array($id));
}
public function getGallery($params = array()){
$search = array();
if(isset($params['product_id']) && $params['product_id']>0)$search[] = sprintf("product_id='%d'",$params['product_id']);
$sql = "select *,name_{$this->lang} as name from catalogs_gallery where 1=1 ";
if(count($search))$sql .= "AND " . implode(" AND ",$search)." ";
$sql .= "order by id desc";
$pagerOptions = Array(
'mode' => 'Sliding',
'delta' => 6,
'perPage' => 10,
'spacesBeforeSeparator' => 1,
'spacesAfterSeparator' => 1
);
return Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array());
}
function view($id){
$sql = "select *,name_{$this->lang} as name from catalogs_gallery where id=? limit 1";
return $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
}
}
?>