gallery_list.class.php
7.54 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
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
<?php
class GalleryList{
var $db = null;
var $tpl = null;
var $error = null;
var $photo_id = null;
function GalleryList(&$db,&$tpl,&$error){
$this->db = &$db;
$this->tpl = &$tpl;
$this->error = &$error;
}
function trim(&$data){
foreach($data as $key=>$value){
$data[$key] = trim($value);
}
}
function valid($data,$upload = null){
if(isset($data['name'])){
if( !preg_match("/.{1,150}/i",$data['name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Íàçâàíèÿ èçîáðàæåíèÿ.";
}
if(isset($data['rubric'])){
if( !preg_match("/.{1,100}/i",$data['rubric']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Íàçâàíèÿ ðóáðèêè, 100 ñèìâ..";
}
if(isset($upload['pic']['name']) && !$data['update_id']){
$type = substr(strrchr($upload['pic']['name'],"."),1);
if( !preg_match("/^(jpeg|jpg|gif|png)$/i",$type) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif.";
}
return ( count($this->error) ) ? true : false;
}
function deletePicsGallery($id){
$sql = "select pic,pic_big from catalogs_gallery where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/gallery/{$row['pic']}");
//@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/big/{$row['pic_big']}");
}
function deleteGallery($id){
$this->deletePicsGallery($id);
$sql = "delete from catalogs_gallery where id=?";
$this->db->query($sql,array($id));
}
function deleteGalleryProduct($id){
$sql = "select * from catalogs_gallery where product_id=?";
$res = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
foreach($res as $row){
$this->deleteGallery($row['id']);
}
}
function deleteRoom($id){
$sql = "select pic from rooms where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/gallery/rooms/{$row['pic']}");
$sql = "delete from rooms where id=?";
$this->db->query($sql,array($id));
}
function viewGalleryOne($id){
$sql = "select * from catalogs_gallery where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('pic',$row);
}
function PhotosCheck($id_s,$check_s = array()){
$sql = "UPDATE gallery SET active = ? WHERE id =?";
foreach($id_s as $id){
$this->db->query($sql,array(0,$id));
}
if(count($check_s)){
foreach($check_s as $id){
$this->db->query($sql,array(1,$id));
}
}
}
function viewCheckPhotos(){
$sql = "select gallery.*,topic.id as topic_id,topic.comments as topic_comments, firms.name as firm_name from gallery left join topic on topic.parent_table='gallery' Left join firms on firms.id=gallery.firm_id where gallery.active=? and topic.parent_table_id=gallery.id order by gallery.mktime desc";
$row = $this->db->getAll($sql,array(1),DB_FETCHMODE_ASSOC);
$this->tpl->assign('photosCheck',$row);
}
function SaveGallery($data,$upload){
$table_name = "catalogs_gallery";
if(isset($data['update_id']) && $data['update_id']>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$id = $data['update_id'];$where = "id=$id";}
else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$id = $this->db->nextId('mySequence_catalogs_gallery');$where = null;}
$fields_values = array('id'=>$id,'name' => $data['name'],'product_id' => $data['product_id']);
if($upload['pic']['tmp_name']){
$this->deletePicsGallery($id);
$fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"100",'height'=>"100",'upload_path'=>"./uploaded/pic/catalogs/products/gallery/"));
$fields_values['pic_big'] = upload_ImageResize($upload['pic'],array('width'=>"600",'height'=>"600",'upload_path'=>"./uploaded/pic/catalogs/products/big/"));
}
$this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,$where);
return $id;
}
function SaveRubric($data,$num){
$table_name = "gallery_rubrics";
$DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
$where = ($data['update_id']>0) ? "id=".$data['update_id'] : null;
$fields_values = array('name' => $data['rubric'],'num' => $num);
$this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,$where);
}
function viewRubrics($num){
$sql = "select * from gallery_rubrics where num=?";
$row = $this->db->getAll($sql,array($num),DB_FETCHMODE_ASSOC);
$this->tpl->assign('rubrics'.$num,$row);
}
function getRubrics($num){
$sql = "select * from gallery_rubrics where num=?";
return $this->db->getAll($sql,array($num),DB_FETCHMODE_ASSOC);
}
function viewRubric($id){
$sql = "select * from gallery_rubrics where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('rubric',$row);
}
function deleteRubric($id){
$sql = "delete from gallery_rubrics where id=?";
$this->db->query($sql,array($id));
}
function countPhotosFirm($firm_id){
$data = array();
$sql = "select count(id) from gallery where 1=1";
if($firm_id!='All'){$sql .= " and firm_id=?";$data[] = $firm_id;}
$count = $this->db->getOne($sql,$data);
$this->tpl->assign('count_photos',$count);
}
function viewGallery($params = array()){
$search = array();
if(isset($params['productID']) && $params['productID']>0)$product_id = $params['productID'];else $product_id = 0;
$sql = "select * from catalogs_gallery where product_id=? ";
if(count($search))$sql .= " and " . implode(" and ",$search)." ";
$sql .= "order by id asc";
$pagerOptions = Array(
'mode' => 'Sliding',
'delta' => 6,
'perPage' => 15,
'spacesBeforeSeparator' => 1,
'spacesAfterSeparator' => 1
);
$this->tpl->assign('galleryAllData', Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array($product_id)));
}
function viewGalleryProduct($id){
$sql = "select * from catalogs_gallery where product_id=? order by id asc";
$row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('gallery', $row);
}
function viewGalleryRubrics($params = array(),$what = 1){
$search = array();
//if(isset($params['rubID']) && $params['rubID']>0)$search[] = sprintf("gallery.group_id=%d",$params['rubID']);
if(isset($params['parentID']) && $params['parentID']>0)$parentID = $params['parentID'];else $parentID = 0;
$sql = "select gallery.*,gallery_rubrics.name as rubric,topic.id as topic_id,topic.comments as topic_comments from gallery Left Join gallery_rubrics On gallery_rubrics.id=rubric_id Left Join topic On topic.parent_table='gallery' And topic.parent_table_id=gallery.id where parent_id=? and what=? and rubric_id=? ";
// if(count($search))$sql .= " and " . implode(" and ",$search)." ";
if($parentID>0)$sql .= "order by rubric_id asc";
else $sql .= "order by sort asc";
$row = array();
foreach($this->getRubrics($what) as $key=>$rub){
$row[$key]['rubric'] = $rub['name'];
$row[$key]['gallery'] = $this->db->getAll($sql,array($parentID,$what,$rub['id']),DB_FETCHMODE_ASSOC);
}
//print_r($row);
$this->tpl->assign('gallery', $row);
}
function displayServiceGallery(){
$this->tpl->assign("service_tpl",'gallery.tpl');
}
function displayGallery(){
$this->tpl->assign("tpl",'gallery_list.tpl');
}
function displayGalleryParent(){
$this->tpl->assign("tpl",'gallery_parent.tpl');
}
function displayGallery3(){
$this->tpl->assign("tpl",'gallery3.tpl');
}
function displayGallerySave(){
$this->tpl->assign("tpl",'gallery_list_save.tpl');
}
function displayGallerySave2(){
$this->tpl->assign("tpl",'gallery_save2.tpl');
}
function displayRooms(){
$this->tpl->assign("tpl",'rooms_gallery.tpl');
}
function displayGalleryBar(){
$this->tpl->display('gallery_bar.tpl');
}
}
?>