ef60cd4d
Administrator
first commit
|
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
|
<?php
namespace controllers;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class MessageController extends \Phalcon\Mvc\Controller
{
function indexAction($type)
{
$data = \message::find(array("type='$type'","order" => 'id'));
$this->view->setVars([
'data' => $data,
'type' => $type
]);
}
function setAction()
{
if($this->request->getPost()){
$model = new \message();
$model->email = $this->request->getPost('email', 'email');
$model->comments = $this->request->getPost('text', 'string');
$model->type = $this->request->getPost('type', 'string');
$model->phone = $this->request->getPost('phone', 'string');
$model->status = 0;
$model->save();
} else {
echo "doesn't have any messages ";
}
die();
}
function addAction()
{
$model = array();
if( $this->request->isPost() )
{
$model = new \message();
$data['request'] = $this->request->getPost('request', 'string', NULL );
$data['email'] = $this->request->getPost('email', 'email', NULL );
if( $model->save($data) )
{
$this->flash->success( 'Сохранение прошло успешно' );
return $this->response->redirect([ 'for' => 'index_message' ]);
}
else
{
$this->flash->error( 'Произошла ошибка во время сохранения.' );
}
}
$this->view->pick( 'message/addEdit' );
$this->view->setVars([
'item' => $model,
]);
}
function deleteAction($id,$type)
{
$model = \message::findFirst("id = '$id'");
if($model instanceof \message) {
if($model->delete()){
$this->flash->error( 'Данные успешно удалены' );
return $this->response->redirect([ 'for' => 'index_message', 'type'=>$type ]);
} else {
$this->flash->error( 'Произошла ошибка при попытке удаления' );
return $this->response->redirect([ 'for' => 'index_message', 'type'=>$type ]);
}
}
}
function updateAction($id)
{
$model = \message::findFirst("id = '$id'");
$model->status = '1';
$model->save();
if( $this->request->isPost() )
{
$model->email = $this->request->getPost('email', 'email');
$model->comments = $this->request->getPost('text', 'string');
$model->type = $this->request->getPost('type', 'string');
$model->phone = $this->request->getPost('phone', 'string');
if( $model->save() )
{
$this->flash->success( 'Сохранение прошло успешно' );
return $this->response->redirect([ 'for' => 'index_request' ]);
}
else
{
$this->flash->error( 'Произошла ошибка во время сохранения.' );
}
}
$this->view->pick( 'message/addEdit' );
$this->view->setVars([
'data' => $model,
]);
}
}
|