book.class.php
5.86 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
<?php
class Book{
var $db = null;
var $tpl = null;
var $error = null;
var $mail = null;
function Book(&$db,&$tpl,&$error){
$this->db = &$db;
$this->tpl = &$tpl;
$this->error = &$error;
$this->mail = new PHPMailer();
}
function trim(&$data){
foreach($data as $key=>$value){
if(is_array($data[$key]))$this->trim($data[$key]);
else $data[$key] = trim($value);
}
}
function valid($data,$upload = null){
if(!preg_match("/.{1,250}/i",$data['title']))$this->error[] = "Îøèáêà ââîäà ïîëÿ Çàãëàâèå!";
if(!preg_match("/.+/is",$data['question']))$this->error[] = "Îøèáêà ââîäà ïîëÿ Âîïðîñ!";
if(!preg_match("/.{1,50}/is",$data['name']))$this->error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ!";
if(isset($data['email'])){
if(!preg_match("/([^@]+)@([^@]+)\.([^@]+)/i",$data['email']) || strlen($data['email'])>80)$this->error[] = "Îøèáêà ââîäà ïîëÿ Email!";
}
if(!isset($_SESSION['spam']))$this->error[] = "Âû ñïàìåð!";
if($_SESSION['spam']!=$data['no_spam'])$this->error[] = "Îøèáêà ââîäà ïîëÿ Ñèìâîëû íà êàðòèíêå!";
return ( count($this->error) ) ? true : false;
}
function saveListQuestion($data){
$table_name = "book";
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('mySequenceBook');$where = null;}
$fields_values = array("id"=>$id,"title"=>$data['title'],"question"=>$data['question'],"name"=>$data['name'],"email"=>$data['email'],"mktime"=>mktime());
$this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where);
return $id;
}
function saveList($data,$lang = "rus"){
$table_name = "book";
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('mySequenceBook');$where = null;}
$fields_values = array("id"=>$id,"question"=>$data['question'],"question_ukr"=>$data['question_ukr'],
"answer"=>$data['answer'],"answer_ukr"=>$data['answer_ukr'],"mktime"=>mktime(),"active"=>$data['active'],"type"=>$data['type']);
$this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where);
return $id;
}
function viewBookLast($limit = 1){
$sql = "select * from book where active=0 order by id desc limit $limit";
$row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
$this->tpl->assign("book_list",$row);
}
function viewBooks($params,$active = "all"){
$search = array();
if($active!="all"){
$search[] = sprintf("active='%d'",$active);
}
if(isset($params['type']) && $params['type']>0)$search[] = sprintf("type='%d'",$params['type']);
$sql = "select book.* from book where 1=1 ";
if(count($search))$sql .= "AND " . implode(" AND " , $search) . " ";
$sql .= "order by mktime desc";
$pagerOptions = Array(
'mode' => 'Sliding',
'delta' => 6,
'perPage' => 10,
'linkClass'=>"link_class",
'curPageLinkClassName'=>"link_class_active",
'spacesBeforeSeparator' => 1,
'spacesAfterSeparator' => 1
);
$this->tpl->assign('bookData', Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()));
}
function viewBooksAll($lang){
$sql = "select book.*";
if($lang=='ukr')$sql .= ", question_ukr as question,answer_ukr as answer";
$sql .= " from book where 1=1 ";
$sql .= "order by mktime desc";
$res = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
$arr = array();
foreach($res as $row){
$arr[$row['type']][] = $row;
}
$this->tpl->assign('books',$arr);
}
function sendMSG($data){ // print_r($data);
$this->mail->CharSet = "windows-1251";
$this->mail->From = "info@extremstyle.ua";
$this->mail->FromName = "ExtremStyle";
$this->mail->AddAddress($data['email'], $data['name']);
//$this->mail->AddAddress('pavel_1986@bigmir.net', 'Pavel');
$this->mail->Subject = 'Îòâåò íà Âàø âîïðîñ';
$msg = sprintf("Çäðàâñòâóéòå %s\n",$data['name']);
$msg .= "\n";
$msg .= "Âàñ ïðèâåòñòâóåò êîìïàíèÿ ExtremStyle!";
$msg .= "\n";
$msg .= "Âû îòñòàâëÿëè âîïðîñ íà ñàéòå: www.extremstyle.ua";
$msg .= "\n";
$msg .= "Ñïåöèàëèñòû êîìïàíèè îòâåòèëè íà íåãî, äëÿ ïðîñìîòðà ïðîéäèòå ïî ññûëêè: ".URL."question/".$data['update_id']."/";
$msg .= "\n";
$msg .= "--";
$msg .= "\n";
$msg .= "Ñ óâàæåíèåì, êîìïàíèÿ \"ExtremStyle.\"";
$msg .= "\n";
$msg .= URL;
$this->mail->Body = $msg;
if(!$this->mail->Send()){echo "There has been a mail error sending to <br>";return false;}
$this->mail->ClearAddresses();
$this->mail->ClearAttachments();
return true;
}
function sendClient($data){ // print_r($data);
$this->mail->CharSet = "windows-1251";
$this->mail->From = $data['email'];
$this->mail->FromName = $data['name'];
$this->mail->AddAddress("info@extremstyle.ua", "info");
//$this->mail->AddAddress('pavel_1986@bigmir.net', 'Pavel');
$this->mail->Subject = 'Êîíñóëüòàöèÿ Online';
$msg = sprintf("Âàøå èìÿ: %s\n",$data['name']);
$msg .= sprintf("Âàø e-mail: %s\n",$data['email']);
$msg .= sprintf("Çàãëàâèå âîïðîñà: %s\n",$data['title']);
$msg .= sprintf("Âîïðîñ: %s\n",$data['question']);
$msg .= "\n";
$msg .= URL;
$this->mail->Body = $msg;
if(!$this->mail->Send()){echo "There has been a mail error sending to <br>";return false;}
$this->mail->ClearAddresses();
$this->mail->ClearAttachments();
return true;
}
function viewBookOne($id){
$sql = "select * from book where id=?";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign("book",$row);
return $row;
}
function deleteBook($id){
$sql = "delete from book where id=?";
$this->db->query($sql,array($id));
}
function displayBookOne(){
$this->tpl->assign("tpl","book_one.tpl");
}
function displayBook(){
$this->tpl->assign("tpl","book.tpl");
}
function displaySaveBook(){
$this->tpl->assign("tpl","book_add.tpl");
}
}
?>