shops.class.php
2.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
<?php
Class Shops{
private $db;
private $lang;
private $path_pic = array('pic'=>"./pics/shops/");
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['adress']))$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 = "shops";
$DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
$fields_values = array("adress"=>$data['adress'],
"city"=>$data['city'],
"rayon"=>$data['rayon'],
"name"=>$data['name'],
"contacts"=>$data['contacts'],
'url' => $data['url']);
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('width'=>"126",'height'=>"35",'upload_path'=>$this->path_pic['pic']));
}
$this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,"id={$data['update_id']}");
if (PEAR::isError($res)) die($res->getMessage());
$id = ($data['update_id']>0) ? $data['update_id'] : mysql_insert_id();
$brends = new Brends($this->lang);
$brends->saveKeys($id,$data['brends']);
return $id;
}
function deletePic($id){
$sql = "select pic from shops where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink($this->path_pic['pic'] . $row['pic']);
}
function delete($id){
$this->deletePic($id);
$this->db->query("delete from shops where id=?",array($id));
$brends = new Brends($this->lang);
$brends->deleteKeysShop($id);
}
public function getShops($param = array()){
$search = array();
$sql = "select * from shops 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 * from shops where id=? limit 1";
return $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
}
}
?>