|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
App::uses('AppController', 'Controller'); |
|
4
|
|
|
|
|
5
|
|
|
class AviseMeController extends AppController |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
public function listar_cadastros() |
|
9
|
|
|
{ |
|
10
|
|
|
$this->loadModel('AviseMe'); |
|
11
|
|
|
|
|
12
|
|
|
$query = array ( |
|
13
|
|
|
'joins' => array( |
|
14
|
|
|
array( |
|
15
|
|
|
'table' => 'produtos', |
|
16
|
|
|
'alias' => 'Produto', |
|
17
|
|
|
'type' => 'LEFT', |
|
18
|
|
|
'conditions' => array( |
|
19
|
|
|
'AviseMe.produto_id = Produto.id', |
|
20
|
|
|
), |
|
21
|
|
|
) |
|
22
|
|
|
), |
|
23
|
|
|
'conditions' => array('AviseMe.ativo' => 1, 'AviseMe.usuario_id' => $this->instancia), |
|
24
|
|
|
'fields' => array('Produto.nome, AviseMe.email, AviseMe.id, Produto.id'), |
|
25
|
|
|
); |
|
26
|
|
|
|
|
27
|
|
|
$cadastros = $this->AviseMe->find('all', $query); |
|
28
|
|
|
$this->set('cadastros', $cadastros); |
|
29
|
|
|
|
|
30
|
|
|
$this->layout = 'wadmin'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
View Code Duplication |
public function excluir_cadastro($id) |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
$this->loadModel('AviseMe'); |
|
36
|
|
|
$this->layout = 'ajax'; |
|
37
|
|
|
|
|
38
|
|
|
$id = $this->request->data('id'); |
|
39
|
|
|
|
|
40
|
|
|
$dados = array ('ativo' => '0'); |
|
41
|
|
|
$parametros = array ('id' => $id); |
|
42
|
|
|
|
|
43
|
|
|
if ($this->AviseMe->updateAll($dados, $parametros)) { |
|
44
|
|
|
echo json_encode(true); |
|
45
|
|
|
} else { |
|
46
|
|
|
echo json_encode(false); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return boolean |
|
52
|
|
|
* Cadastra as informações |
|
53
|
|
|
**/ |
|
54
|
|
|
public function cadastrar_avise_me() |
|
55
|
|
|
{ |
|
56
|
|
|
try |
|
57
|
|
|
{ |
|
58
|
|
|
$this->loadModel('AviseMe'); |
|
59
|
|
|
|
|
60
|
|
|
$this->AviseMe->set($this->request->data); |
|
61
|
|
|
|
|
62
|
|
|
if (!$this->AviseMe->validates()) |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->AviseMe->validationErrors; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if (!$this->AviseMe->save($this->request->data)) |
|
68
|
|
|
{ |
|
69
|
|
|
return false; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return true; |
|
73
|
|
|
} |
|
74
|
|
|
catch (Exception $e) |
|
75
|
|
|
{ |
|
76
|
|
|
throw new Exception("Error Processing Request", 1); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return false; |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function enviar_email_aviseme($produto_id, $email) |
|
|
|
|
|
|
83
|
|
|
{ |
|
84
|
|
|
try { |
|
85
|
|
|
$this->loadModel('Produto'); |
|
86
|
|
|
|
|
87
|
|
|
$produto = $this->Produto->find('all', |
|
88
|
|
|
array('conditions' => |
|
89
|
|
|
array('Produto.id' => $produto_id |
|
90
|
|
|
) |
|
91
|
|
|
) |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
App::uses('CakeEmail', 'Network/Email'); |
|
95
|
|
|
|
|
96
|
|
|
$email = new CakeEmail('default'); |
|
97
|
|
|
$email->from('[email protected]', 'reginaldo') |
|
98
|
|
|
->to('[email protected]') |
|
99
|
|
|
->subject('Produto Aviso'); |
|
100
|
|
|
|
|
101
|
|
|
$mensagem = ' |
|
102
|
|
|
<p><strong>Nome</strong>: '. $produto[0]['Produto']['nome'] .'</p> |
|
103
|
|
|
'; |
|
104
|
|
|
|
|
105
|
|
|
if ($email->send($mensagem)) { |
|
106
|
|
|
return true; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return false; |
|
110
|
|
|
} catch (Exception $e) { |
|
111
|
|
|
throw new Exception($e->getMessage(), 1); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.