gallery.class.php
8.89 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
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
<?php
class Gallery{
var $db = null;
var $tpl = null;
var $error = null;
var $photo_id = null;
function Gallery(&$db,&$tpl,&$error){
$this->db = &$db;
$this->tpl = &$tpl;
$this->error = &$error;
}
function trim(&$data){
foreach($data as $key=>$value){
$data[$key] = strip_tags(trim($value));
}
}
function valid($data,$upload = null){
if(isset($data['name'])){
if( !preg_match("/.{1,50}/i",$data['name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Íàçâàíèÿ èçîáðàæåíèÿ.";
}
if(isset($upload['upload']['name']) && $upload['upload']['name']){
$type = substr(strrchr($upload['upload']['name'],"."),1);
if( !preg_match("/^(jpeg|jpg|gif|png)$/i",$type) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif.";
}
return ( count($this->error) ) ? true : false;
}
function deletePhoto($id){
$sql = "select pic,pic_big from gallery where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/gallery/{$row['pic']}");
@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/gallery/big/{$row['pic_big']}");
$sql = "delete from gallery where id=?";
$this->db->query($sql,array($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 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 SavePhoto($data,$upload){
$table_name = "gallery";
$id = ($data['update_id']>0) ? $data['update_id'] : $this->db->nextId('mySequenceGallery');
$DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
$fields_values = array('id'=>$id,'name_rus' => $data['name_rus'],'rub_id'=>$data['rub_id']);
if(!$data['update_id'])$fields_values['mktime'] = mktime();
if($upload['upload']['tmp_name']){
$fields_values['pic'] = upload_ImageResize($upload['upload'],array('width'=>"180",'height'=>"180",'upload_path'=>"./uploaded/pic/gallery/"));
$fields_values['pic_big'] = upload_ImageResize($upload['upload'],array('width'=>"600",'height'=>"600",'upload_path'=>"./uploaded/pic/gallery/big/"));
}
$res = $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id='$id'");
if (PEAR::isError($res)) die($res->getMessage());
return $id;
}
function SaveRoom($data,$upload){
$table_name = "rooms";
$id = ($data['update_id']>0) ? $data['update_id'] : $this->db->nextId('mySequenceRooms');
$DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
$fields_values = array('id'=>$id,'title' => $data['title'],'about' => $data['about'], 'mktime' => mktime());
if($upload['pic']['tmp_name']){
$fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"180",'height'=>"180",'upload_path'=>"./uploaded/pic/gallery/rooms/"));
}
$this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id='$id'");
return $id;
}
function saveSortRooms($sorts){
$sql = "update rooms set sort=? where id=?";
foreach($sorts as $key=>$value){
$this->db->query($sql,array($value,$key));
}
}
function viewRoomOne($id){
$sql = "select * from rooms where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('room',$row);
}
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 viewRooms(){
$sql = "select * from rooms order by sort";
$pagerOptions = Array(
'mode' => 'Sliding',
'delta' => 6,
'perPage' => 10,
'spacesBeforeSeparator' => 1,
'spacesAfterSeparator' => 1
);
$this->tpl->assign('roomsData', Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()));
}
function viewAllPhotos($param = array(),$isview = "all"){
$search = array();
if(isset($param['rubID']) && $param['rubID']>0)$search[] = sprintf("rub_id=%d",$param['rubID']);
if(isset($param['trainingID']) && $param['trainingID']>0)$search[] = sprintf("training_id=%d",$param['trainingID']);
if($isview != "all"){$search[] = sprintf("isview='%d'",0);}
$sql = "select id,rub_id,pic,pic_big,name_rus as name from gallery where 1=1 ";
if(count($search))$sql .= " and " . implode(" and ",$search)." ";
$sql .= "order by mktime desc";
$pagerOptions = Array(
'mode' => 'Sliding',
'delta' => 6,
'perPage' => 21,
'spacesBeforeSeparator' => 1,
'spacesAfterSeparator' => 1
);
$this->tpl->assign('galleryAllData', Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()));
}
function viewAllPhotosTrainings($param = array()){
$search = array();
/*
if(isset($param['rubID']) && $param['rubID']>0)$search[] = sprintf("rub_id=%d",$param['rubID']);
if(isset($param['trainingID']) && $param['trainingID']>0)$search[] = sprintf("training_id=%d",$param['trainingID']);
$sql = "select * from gallery where 1=1 ";
if(count($search))$sql .= " and " . implode(" and ",$search)." ";
$sql .= "order by mktime asc";
*/
$sql = "select trainings.id,trainings.title from trainings,gallery WHERE gallery.training_id=trainings.id and trainings.active='1' GROUP BY gallery.training_id order by trainings.sort";
$pagerOptions = Array(
'mode' => 'Sliding',
'delta' => 6,
'perPage' => 21,
'spacesBeforeSeparator' => 1,
'spacesAfterSeparator' => 1
);
$data = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array());
foreach($data['data'] as $key=>$value){
$pics_row = $this->db->getAll("select pic from gallery where training_id=? ORDER BY mktime DESC limit 3",array($value['id']), DB_FETCHMODE_ASSOC);
if(isset($pics_row[0]))$data['data'][$key]['pic1'] = $pics_row[0]['pic'];
if(isset($pics_row[1]))$data['data'][$key]['pic2'] = $pics_row[1]['pic'];
if(isset($pics_row[1]))$data['data'][$key]['pic3'] = $pics_row[2]['pic'];
}
$this->tpl->assign('galleryAllData',$data);
}
function viewPhotosRubric($id,$lang = "rus"){
$sql = "select pic,pic_big,name_$lang as name from gallery where rub_id=? order by mktime desc";
$row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('gallery', $row);
}
function viewPhotosRubAll($id_s){
foreach($id_s as $id){
$sql = "select * from gallery where rub_id=? order by mktime desc";
$row[$id] = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('gallery_'.$id, $row[$id]);
}
}
function viewPhoto($id){
$sql = "select * from gallery where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('photo',$row);
}
function nextPhotoID($firm_id){
$data = array($this->photo_id);
$sql = "select id from gallery where id<?";
if($firm_id!='All'){$sql .= " and firm_id=?";$data[] = $firm_id;}
$sql .= " order by id desc limit 1";
$id = $this->db->getOne($sql,$data);
$this->tpl->assign('next_id',$id);
}
function prevPhotoID($firm_id){
$data = array($this->photo_id);
$sql = "select id from gallery where id>?";
if($firm_id!='All'){$sql .= " and firm_id=?";$data[] = $firm_id;}
$sql .= " order by id asc limit 1";
$id = $this->db->getOne($sql,$data);
$this->tpl->assign('prev_id',$id);
}
function numberPhoto($firm_id){
$data = array($this->photo_id);
$sql = "select count(id) from gallery where id>=?";
if($firm_id!='All'){$sql .= " and firm_id=?";$data[] = $firm_id;}
$count = $this->db->getOne($sql,$data);
$this->tpl->assign('number_id',$count);
}
function displayServiceGallery(){
$this->tpl->assign("service_tpl",'gallery.tpl');
}
function displayGallery(){
$this->tpl->assign("tpl",'gallery.tpl');
}
function displayGalleryTrainings(){
$this->tpl->assign("tpl",'gallery_trainings.tpl');
}
function displayGallerySave(){
$this->tpl->assign("tpl",'gallery_save.tpl');
}
function displayRoomGallerySave(){
$this->tpl->assign("tpl",'rooms_gallery_save.tpl');
}
function displayRooms(){
$this->tpl->assign("tpl",'rooms_gallery.tpl');
}
function displayGalleryBar(){
$this->tpl->display('gallery_bar.tpl');
}
}
?>