production.class.php
3.56 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
<?php
Class Production{
private $db;
private $lang;
private $path_pic = array('pic'=>"./pics/production/",
'pic_big'=>"./pics/production/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(!preg_match("/.{1,200}/i",$data['title']))$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 = "production";
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'],
"title_".$this->lang=>$data['title'],
"text_".$this->lang=>$data['text'],
"about_".$this->lang=>$data['about'],
"meta_title_".$this->lang=>$data['meta_title'],
"meta_description_".$this->lang=>$data['meta_description'],
"meta_keywords_".$this->lang=>$data['meta_keywords'],
"meta_about_".$this->lang=>$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; $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('width'=>"204",'height'=>"204",'upload_path'=>$this->path_pic['pic']));
$fields_values['pic_big'] = upload_ImageResize($upload['pic'],array('width'=>"600",'height'=>"600",'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 production 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 production where id=?",array($id));
}
public function getProduction($param = array()){
$search = array();
$sql = "select *,title_{$this->lang} as title,text_{$this->lang} as text,about_{$this->lang} as about from production 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,title_{$this->lang} as title,meta_title_{$this->lang} as meta_title,meta_description_{$this->lang} as meta_description,meta_keywords_{$this->lang} as meta_keywords,meta_about_{$this->lang} as meta_about,text_{$this->lang} as text,about_{$this->lang} as about from production where id=? limit 1";
return $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
}
}
?>