video.class.php
4.65 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
<?php
class Video{
var $db = null;
var $tpl = null;
var $error = null;
var $photo_id = null;
function Video(&$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($upload['video']['tmp_name']) && $upload['video']['tmp_name']){
$type = substr(strrchr($upload['video']['name'],"."),1);
if( !preg_match("/^(flv|rar|doc|pdf|txt|pps)$/i",$type) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Âèäåî, òîëüêî flv|rar|doc|pdf|txt|pps.";
}
return ( count($this->error) ) ? true : false;
}
function deletePicsVideo($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/gallery/{$row['pic']}");
@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/gallery/big/{$row['pic_big']}");
}
function deleteVideo($id){
$this->deleteFile($id);
$sql = "delete from video where id=?";
$this->db->query($sql,array($id));
}
function viewVideoOne($id){
$sql = "select * from video where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('video',$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 SaveVideo($data,$upload){
$table_name = "video";
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_video');$where = null;}
$fields_values = array('id'=>$id,'product_id' => $data['product_id'],'name' => $data['name'],'code' => $data['code'],'type' => $data['type']);
if(isset($data['delete_video']) && $data['delete_video']==1){
$this->deleteFile($id);
$fields_values['video'] = null;
}
if($upload['video']['tmp_name']){
$this->deleteFile($id);
$name_video = mktime() . "." . substr(strrchr($_FILES['video']['name'],"."),1);
$file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/video/$name_video";
move_uploaded_file($_FILES["video"]["tmp_name"], $file_name);
chmod($file_name,"0777");
$fields_values['video'] = $name_video;
}
$this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,$where);
return $id;
}
function deleteFile($id){
$sql = "select video from video where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
$file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/video/{$row['video']}";
@unlink($file_name);
}
function viewVideo($params = array()){
$search = array();
if(isset($params['productID']) && $params['productID']>0)$product_id = $params['productID'];else $product_id = 0;
$sql = "select * from video 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 viewVideoProduct($id){
$sql = "select * from video where product_id=? order by id asc";
$row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('video', $row);
}
function displayServiceGallery(){
$this->tpl->assign("service_tpl",'gallery.tpl');
}
function displayVideo(){
$this->tpl->assign("tpl",'video.tpl');
}
function displayGalleryParent(){
$this->tpl->assign("tpl",'gallery_parent.tpl');
}
function displayGallery3(){
$this->tpl->assign("tpl",'gallery3.tpl');
}
function displayVideoSave(){
$this->tpl->assign("tpl",'video_save.tpl');
}
}
?>