fotovideo.class.php
4.85 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
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
<?php
Class FotoVideo{
private $db;
private $lang;
private $path_pic = array('pic'=>"./pics/fotovideo/rubrics/",'gallery_pic'=>"./pics/fotovideo/",'gallery_pic_big'=>"./pics/fotovideo/big/");
function __construct($lang){
$this->db = sdb::getInstance();
$this->lang = $lang;
}
public function valid($data){
$error = array();
if(!preg_match("/.{1,50}/i",$data['name']))$error[] = "error name";
return $error;
}
public function viewRubric($id){
return $this->db->getRow("select * from fotovideo_rubrics where id=?",array($id),DB_FETCHMODE_ASSOC);
}
public function getRubrics_begin(){
$sql = "select id,parent_id,name_{$this->lang} as name from fotovideo_rubrics where parent_id=? order by sort";
return $this->db->getAll($sql,array(0),DB_FETCHMODE_ASSOC);
}
public function getRubrics(){
$sql = "select * from fotovideo_rubrics where 1=1";
$sql .= " order by sort";
return $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
}
public function saveRubric($data,$upload){
$table_name = "fotovideo_rubrics";
$DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
$fields_values = array(
'sort' => $data['sort'],
'name' => $data['name'],
'meta_title' => $data['meta_title'],
'meta_description' => $data['meta_description'],
'meta_keywords' => $data['meta_keywords'],
'meta_about' => $data['meta_about']
);
if(isset($data['delete_pic']) && $data['delete_pic']==1){
if($data['update_id']>0)$this->deletePic($data['update_id']);
$fields_values['pic'] = 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'=>"147",'height'=>"147",'upload_path'=>$this->path_pic['pic']));
}
print_r($fields_values);
$res = $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}");
if (PEAR::isError($res)) die($res->getMessage());
}
private function deletePic($id){
$sql = "select pic from fotovideo_rubrics where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink($this->path_pic['pic'] . $row['pic']);
}
public function deleteRubric($id){
$this->deletePic($id);
$this->db->query("delete from fotovideo_rubrics where id=?",array($id));
$this->deleteGalleryRubric($id);
}
public function getGallery($rubric_id = 0){
$search = array();
if($rubric_id>0)$search[] = sprintf("rubric_id='%d'",$rubric_id);
$sql = "select * from fotovideo_gallery where 1=1 ";
if(count($search))$sql .= "AND " . implode(" AND ",$search)." ";
$sql .= "order by id desc";
//print $sql;
$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());
}
public function saveGallery($data,$upload = null){
$table_name = "fotovideo_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"=>$data['name'],
"rubric_id"=>$data['rubric_id'],
"type"=>$data['type'],
"code"=>$data['code']
);
if(isset($data['delete_pic']) && $data['delete_pic']==1){
if($data['update_id']>0)$this->deletePic_gallery($data['update_id']);
$fields_values['pic'] = null; $fields_values['pic_big'] = null;
}
if($upload['pic']['tmp_name']){
if($data['update_id']>0)$this->deletePic_gallery($data['update_id']);
$fields_values['pic'] = upload_ImageResize($upload['pic'],array('crop'=>true,'width'=>"147",'height'=>"147",'upload_path'=>$this->path_pic['gallery_pic']));
$fields_values['pic_big'] = upload_ImageResize($upload['pic'],array('width'=>"700",'height'=>"700",'upload_path'=>$this->path_pic['gallery_pic_big']));
}
$this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where);
}
private function deletePic_gallery($id){
$sql = "select pic,pic_big from fotovideo_gallery where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink($this->path_pic['gallery_pic'] . $row['pic']);
@unlink($this->path_pic['gallery_pic_big'] . $row['pic_big']);
}
public function getGalleryOne($id){
return $this->db->getRow("select * from fotovideo_gallery where id=?",array($id),DB_FETCHMODE_ASSOC);
}
public function deleteGallery($id){
$this->deletePic_gallery($id);
$this->db->query("delete from fotovideo_gallery where id=?",array($id));
}
private function deleteGalleryRubric($rubric_id){
$sql = "select * from fotovideo_gallery where rubric_id=?";
$res = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC);
foreach($res as $row){
$this->deleteGallery($row['id']);
}
}
}
?>