reviews2.class.php
1.4 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
<?php
Class Reviews2{
private $db;
private $lang;
function __construct(&$db,&$tpl,&$error,$lang){
$this->db = $db;
$this->tpl = &$tpl;
$this->error = &$error;
$this->lang = $lang;
}
public function valid($data){
$error = array();
if(isset($data['name'])){
if( !preg_match("/.{1,100}/i",$data['name']) ) $error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ (Ìàêñèìóì 100 ñèìâîëîâ).";
}
if(isset($data['title'])){
if( !preg_match("/.{1,200}/i",$data['title']) ) $error[] = "Îøèáêà ââîäà ïîëÿ Çàãëàâèå (Ìàêñèìóì 200 ñèìâîëîâ).";
}
if(isset($data['comment'])){
if( !preg_match("/.+/i",$data['comment']) ) $error[] = "Îøèáêà ââîäà ïîëÿ Êîììåíòàðèé";
}
if(isset($data['order_email'])){
if( !preg_match("/^([^@]+)+@([^@]+)\.([^@]+)$/i",$data['order_email']) || strlen($data['order_email'])>80 ) $error[] = "Îøèáêà ââîäà ïîëÿ E-mail, äî 80 ñèìâîëîâ.";
}
return $error;
}
public function save($data,$type,$type_id){
$fields_values = array(
'type'=>$type,
'type_id'=>$type_id,
'name'=>$data['name'],
'title'=>$data['title'],
'comment'=>$data['comment'],
'mktime'=>mktime()
);
$this->db->autoExecute("reviews", $fields_values, DB_AUTOQUERY_INSERT);
}
public function getAll($type,$type_id){
$sql = "select * from reviews where active=? and type=? and type_id=? order by mktime desc";
return $this->db->getAll($sql,array(1,$type,$type_id),DB_FETCHMODE_ASSOC);
}
}
?>