Version Notes
First beta release.
Download this release
Release Info
Developer | Koiber |
Extension | Koiber_TransactionalMessages |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos.php +10 -0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos/Edit.php +29 -0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos/Edit/Form.php +214 -0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos/Grid.php +58 -0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos/Renderer/Status.php +9 -0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos/Renderer/Template.php +19 -0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Historico.php +11 -0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Historico/Grid.php +85 -0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Historico/Renderer/Template.php +62 -0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Mensagem/Edit.php +28 -0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Mensagem/Edit/Form.php +166 -0
- app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/System/Config/Info.php +11 -0
- app/code/community/Koiber/TransactionalMessages/Helper/Data.php +5 -0
- app/code/community/Koiber/TransactionalMessages/Model/Eventos.php +7 -0
- app/code/community/Koiber/TransactionalMessages/Model/Historico.php +7 -0
- app/code/community/Koiber/TransactionalMessages/Model/Mensagem.php +7 -0
- app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Eventos.php +6 -0
- app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Eventos/Collection.php +6 -0
- app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Historico.php +6 -0
- app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Historico/Collection.php +6 -0
- app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Mensagem.php +6 -0
- app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Mensagem/Collection.php +6 -0
- app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Padrao.php +6 -0
- app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Padrao/Collection.php +6 -0
- app/code/community/Koiber/TransactionalMessages/Model/Padrao.php +7 -0
- app/code/community/Koiber/TransactionalMessages/controllers/IndexController.php +167 -0
- app/code/community/Koiber/TransactionalMessages/controllers/KoiberController.php +196 -0
- app/code/community/Koiber/TransactionalMessages/etc/adminhtml.xml +20 -0
- app/code/community/Koiber/TransactionalMessages/etc/config.xml +117 -0
- app/code/community/Koiber/TransactionalMessages/etc/system.xml +58 -0
- app/code/community/Koiber/TransactionalMessages/sql/koiber_transactionalmessages_setup/mysql4-install-1.0.0.php +176 -0
- app/code/community/Mage/Core/Model/Email/Template.php +812 -0
- app/design/adminhtml/default/default/layout/koiber.xml +13 -0
- app/etc/modules/Koiber_TransactionalMessages.xml +8 -0
- app/locale/en_US/Koiber_Koiber.csv +47 -0
- lib/koiberPHP/.gitignore +1 -0
- lib/koiberPHP/README.md +124 -0
- lib/koiberPHP/sample/canal_busca.php +37 -0
- lib/koiberPHP/sample/canal_cria.php +36 -0
- lib/koiberPHP/sample/canal_lista.php +24 -0
- lib/koiberPHP/sample/canal_remove.php +35 -0
- lib/koiberPHP/sample/canal_update.php +43 -0
- lib/koiberPHP/sample/config.php +5 -0
- lib/koiberPHP/sample/departamento_busca.php +37 -0
- lib/koiberPHP/sample/departamento_cria.php +35 -0
- lib/koiberPHP/sample/departamento_lista.php +24 -0
- lib/koiberPHP/sample/departamento_remove.php +35 -0
- lib/koiberPHP/sample/departamento_update.php +41 -0
- lib/koiberPHP/sample/index.php +44 -0
- lib/koiberPHP/sample/msg_add_msg.php +59 -0
- lib/koiberPHP/sample/msg_busca.php +70 -0
- lib/koiberPHP/sample/msg_cria.php +66 -0
- lib/koiberPHP/sample/msg_encerra.php +44 -0
- lib/koiberPHP/sample/msg_foi_encerra.php +44 -0
- lib/koiberPHP/sample/msg_lista.php +40 -0
- lib/koiberPHP/sample/user_autorizou.php +45 -0
- lib/koiberPHP/sample/user_busca.php +41 -0
- lib/koiberPHP/sample/user_lista.php +40 -0
- lib/koiberPHP/src/Koiber/Address.php +44 -0
- lib/koiberPHP/src/Koiber/Autoload.php +20 -0
- lib/koiberPHP/src/Koiber/Channel.php +79 -0
- lib/koiberPHP/src/Koiber/Form/Element.php +58 -0
- lib/koiberPHP/src/Koiber/Form/Form.php +25 -0
- lib/koiberPHP/src/Koiber/Form/IElement.php +7 -0
- lib/koiberPHP/src/Koiber/Form/Paragraph.php +16 -0
- lib/koiberPHP/src/Koiber/Form/Textarea.php +19 -0
- lib/koiberPHP/src/Koiber/Koiber.php +137 -0
- lib/koiberPHP/src/Koiber/Message/Message.php +111 -0
- lib/koiberPHP/src/Koiber/Message/Talk.php +143 -0
- lib/koiberPHP/src/Koiber/Message/Type.php +7 -0
- lib/koiberPHP/src/Koiber/Response.php +49 -0
- lib/koiberPHP/src/Koiber/User.php +73 -0
- package.xml +18 -0
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_Eventos extends Mage_Adminhtml_Block_Widget_Grid_Container {
|
3 |
+
public function __construct() {
|
4 |
+
$this->_blockGroup = 'koiber_transactionalmessages';
|
5 |
+
$this->_controller = 'adminhtml_eventos';
|
6 |
+
$this->_headerText = $this->__('Mensagens');
|
7 |
+
|
8 |
+
parent::__construct();
|
9 |
+
}
|
10 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos/Edit.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_Eventos_Edit extends Mage_Adminhtml_Block_Widget_Form_Container {
|
3 |
+
public function __construct() {
|
4 |
+
$this->_objectId = 'evento_id';
|
5 |
+
$this->_blockGroup = 'koiber_transactionalmessages';
|
6 |
+
$this->_controller = 'adminhtml_eventos';
|
7 |
+
|
8 |
+
parent::__construct();
|
9 |
+
|
10 |
+
$this->_updateButton('save', 'label', $this->__('Salvar Mensagem'));
|
11 |
+
$this->_updateButton('delete', 'label', $this->__('Excluir Mensagem'));
|
12 |
+
}
|
13 |
+
|
14 |
+
public function getHeaderText() {
|
15 |
+
if(Mage::registry('koiber_transactionalmessages')->getId()) {
|
16 |
+
return $this->__('Editar Mensagem');
|
17 |
+
} else {
|
18 |
+
return $this->__('Nova Mensagem');
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
protected function _prepareLayout() {
|
23 |
+
parent::_prepareLayout();
|
24 |
+
|
25 |
+
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
|
26 |
+
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
|
27 |
+
}
|
28 |
+
}
|
29 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos/Edit/Form.php
ADDED
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_Eventos_Edit_Form extends Mage_Adminhtml_Block_Widget_Form {
|
3 |
+
public function __construct() {
|
4 |
+
parent::__construct();
|
5 |
+
|
6 |
+
$this->setId('koiber_transactionalmessages_eventos_form');
|
7 |
+
$this->setTitle($this->__('Informações da Mensagem'));
|
8 |
+
}
|
9 |
+
|
10 |
+
protected function _prepareLayout() {
|
11 |
+
if ($head = $this->getLayout()->getBlock('head')) {
|
12 |
+
$head->addItem('js', 'prototype/window.js')
|
13 |
+
->addItem('js_css', 'prototype/windows/themes/default.css')
|
14 |
+
->addCss('lib/prototype/windows/themes/magento.css')
|
15 |
+
->addItem('js', 'mage/adminhtml/variables.js');
|
16 |
+
}
|
17 |
+
|
18 |
+
return parent::_prepareLayout();
|
19 |
+
}
|
20 |
+
|
21 |
+
protected function _prepareForm() {
|
22 |
+
$model = Mage::registry('koiber_transactionalmessages');
|
23 |
+
|
24 |
+
$form = new Varien_Data_Form(array(
|
25 |
+
'id' => 'edit_form',
|
26 |
+
'action' => $this->getUrl('*/*/save', array('evento_id' => $this->getRequest()->getParam('evento_id'))),
|
27 |
+
'method' => 'post'
|
28 |
+
));
|
29 |
+
|
30 |
+
$fieldset = $form->addFieldset('base_fieldset', array(
|
31 |
+
'legend' => Mage::helper('checkout')->__('Dados da Mensagem'),
|
32 |
+
'class' => 'fieldset-wide'
|
33 |
+
));
|
34 |
+
|
35 |
+
if ($model->getId()) {
|
36 |
+
$fieldset->addFieldset('evento_id', 'hidden', array(
|
37 |
+
'name' => 'evento_id'
|
38 |
+
));
|
39 |
+
}
|
40 |
+
|
41 |
+
$defaultTemplates = Mage::getModel('core/email_template')->getDefaultTemplatesAsOptionsArray();
|
42 |
+
|
43 |
+
$eventoOptions = array(
|
44 |
+
1 => array(
|
45 |
+
'value' => 0,
|
46 |
+
'label' => '-- Selecione uma template --'
|
47 |
+
)
|
48 |
+
);
|
49 |
+
|
50 |
+
foreach ($defaultTemplates as $defaultTemplate) {
|
51 |
+
if ((strpos($defaultTemplate['value'], 'design') !== false) || !$defaultTemplate['value']) {
|
52 |
+
continue;
|
53 |
+
}
|
54 |
+
|
55 |
+
$eventoOptions[] = array(
|
56 |
+
'value' => $defaultTemplate['value'],
|
57 |
+
'label' => $defaultTemplate['label']
|
58 |
+
);
|
59 |
+
}
|
60 |
+
|
61 |
+
$insertVariableButton = $this->getLayout()
|
62 |
+
->createBlock('adminhtml/widget_button', '', array(
|
63 |
+
'type' => 'button',
|
64 |
+
'label' => Mage::helper('adminhtml')->__('Inserir Variável...'),
|
65 |
+
'onclick' => 'MagentovariablePlugin.loadChooser(\'' . $this->getUrl('*/*/variaveisPlugin', array('template_code' => $model->getEvento())) . '\', \'email\');'
|
66 |
+
));
|
67 |
+
|
68 |
+
$fieldset->addField('evento', 'select', array(
|
69 |
+
'name' => 'evento',
|
70 |
+
'class' => 'required-entry',
|
71 |
+
'label' => $this->__('Template da Mensagem'),
|
72 |
+
'title' => $this->__('Template da Mensagem'),
|
73 |
+
'required' => true,
|
74 |
+
'values' => $eventoOptions,
|
75 |
+
'after_element_html' => (Mage::getSingleton('adminhtml/session')->getEventoErro() ? '<br><span style="color:red">' . Mage::getSingleton('adminhtml/session')->getEventoErro() . '</span>' : '') . $this->resetarJanelaVariaveis($insertVariableButton->getId()) . $this->obterAjaxTemplatePadraoKoiber(),
|
76 |
+
'onchange' => 'trocarVariaveisCustom(this.value);'
|
77 |
+
));
|
78 |
+
|
79 |
+
require_once(Mage::getBaseDir('lib') . '/koiberPHP/src/Koiber/Autoload.php');
|
80 |
+
|
81 |
+
$koiberConfig = Mage::getStoreConfig('koiber_options/koiber_configs');
|
82 |
+
|
83 |
+
$koiberApi = new Koiber($koiberConfig['koiber_api']);
|
84 |
+
$response = $koiberApi->getCannels();
|
85 |
+
|
86 |
+
$canaisKoiber = $response->getBody(true);
|
87 |
+
|
88 |
+
$canalOptions = array(
|
89 |
+
1 => array(
|
90 |
+
'value' => 0,
|
91 |
+
'label' => '-- Selecione um canal --'
|
92 |
+
)
|
93 |
+
);
|
94 |
+
|
95 |
+
foreach ($canaisKoiber as $canalKoiber) {
|
96 |
+
$canalOptions[] = array(
|
97 |
+
'value' => $canalKoiber['id'],
|
98 |
+
'label' => $canalKoiber['name']
|
99 |
+
);
|
100 |
+
}
|
101 |
+
|
102 |
+
$fieldset->addField('canal', 'select', array(
|
103 |
+
'name' => 'canal',
|
104 |
+
'class' => 'required-entry',
|
105 |
+
'label' => $this->__('Selecione o Canal'),
|
106 |
+
'title' => $this->__('Selecione o Canal'),
|
107 |
+
'required' => true,
|
108 |
+
'values' => $canalOptions,
|
109 |
+
'after_element_html' => Mage::getSingleton('adminhtml/session')->getCanalErro() ? '<br><span style="color:red">' . Mage::getSingleton('adminhtml/session')->getCanalErro() . '</span>' : ''
|
110 |
+
));
|
111 |
+
|
112 |
+
$fieldset->addField('status', 'select', array(
|
113 |
+
'name' => 'status',
|
114 |
+
'class' => 'required-entry',
|
115 |
+
'label' => $this->__('Status da Mensagem'),
|
116 |
+
'title' => $this->__('Status da Mensagem'),
|
117 |
+
'required' => true,
|
118 |
+
'tabindex' => 1,
|
119 |
+
'values' => array(1 => __('Ativo'), 0 => __('Inativo')),
|
120 |
+
'after_element_html' => '<br><small>' . __('Ativado, na template selecionada, será enviado esta menssagem para o koiber ao invez do e-mail (apenas se o usuário tiver cadastro no koiber).') . '</small>'
|
121 |
+
));
|
122 |
+
|
123 |
+
$fieldset->addField('tipo', 'select', array(
|
124 |
+
'name' => 'tipo',
|
125 |
+
'class' => 'required-entry',
|
126 |
+
'label' => $this->__('Tipo de Mensagem'),
|
127 |
+
'title' => $this->__('Tipo de Mensagem'),
|
128 |
+
'required' => true,
|
129 |
+
'tabindex' => 1,
|
130 |
+
'values' => array('text' => 'Texto', 'form' => 'Formulário'),
|
131 |
+
'after_element_html' => '<br><small>' . __('Caso seja formulário, observar os nomes do campos para que tenham os mesmo nomes no magento para atualização no callback.') . '</small>'
|
132 |
+
));
|
133 |
+
|
134 |
+
$fieldset->addField('assunto', 'text', array(
|
135 |
+
'name' => 'assunto',
|
136 |
+
'label' => $this->__('Assunto da Mensagem'),
|
137 |
+
'title' => $this->__('Assunto da Mensagem'),
|
138 |
+
'after_element_html' => '<br><small>' . __('Pode-se usar as variáveis normalmente.') . '</small>'
|
139 |
+
));
|
140 |
+
|
141 |
+
$fieldset->addField('insert_variable', 'note', array(
|
142 |
+
'text' => $insertVariableButton->toHtml()
|
143 |
+
));
|
144 |
+
|
145 |
+
$fieldset->addField('email', 'textarea', array(
|
146 |
+
'name' => 'email',
|
147 |
+
'label' => $this->__('Template do E-mail'),
|
148 |
+
'title' => $this->__('Template do E-mail'),
|
149 |
+
'after_element_html' => '<br><small>' . __('Caso preenchido, irá trocar a template padrão do e-mail para o conteudo deste campo.') . '</small>'
|
150 |
+
));
|
151 |
+
|
152 |
+
Mage::getSingleton('adminhtml/session')->unsEventoErro();
|
153 |
+
Mage::getSingleton('adminhtml/session')->unsCanalErro();
|
154 |
+
|
155 |
+
$form->setValues($model->getData());
|
156 |
+
$form->setUseContainer(true);
|
157 |
+
$this->setForm($form);
|
158 |
+
|
159 |
+
return parent::_prepareForm();
|
160 |
+
}
|
161 |
+
|
162 |
+
protected function resetarJanelaVariaveis($id) {
|
163 |
+
$js_function = "<script type=\"text/javascript\"><!--
|
164 |
+
function trocarVariaveisCustom(template_code) {
|
165 |
+
Variables.variablesContent = null;
|
166 |
+
MagentovariablePlugin.variables = null;
|
167 |
+
|
168 |
+
|
169 |
+
document.getElementById('" . $id . "').setAttribute('onclick', 'MagentovariablePlugin.loadChooser(\'" . $this->getUrl('koiber/index/variaveisPlugin') . "template_code/' + template_code + '\', \'email\');');
|
170 |
+
|
171 |
+
obterAjaxTemplatePadraoKoiber(template_code);
|
172 |
+
}
|
173 |
+
//--></script>";
|
174 |
+
|
175 |
+
return $js_function;
|
176 |
+
}
|
177 |
+
|
178 |
+
protected function obterAjaxTemplatePadraoKoiber() {
|
179 |
+
$js_function = "<script type=\"text/javascript\"><!--
|
180 |
+
var obterJSON = function(url, successHandler, errorHandler) {
|
181 |
+
var xhr = typeof XMLHttpRequest != 'undefined' ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
|
182 |
+
xhr.open('get', url, true);
|
183 |
+
xhr.responseType = 'json';
|
184 |
+
xhr.onreadystatechange = function() {
|
185 |
+
var status;
|
186 |
+
var data;
|
187 |
+
|
188 |
+
if (xhr.readyState == 4) { // `DONE`
|
189 |
+
status = xhr.status;
|
190 |
+
|
191 |
+
if (status == 200) {
|
192 |
+
successHandler && successHandler(xhr.response);
|
193 |
+
} else {
|
194 |
+
errorHandler && errorHandler(status);
|
195 |
+
}
|
196 |
+
}
|
197 |
+
};
|
198 |
+
|
199 |
+
xhr.send();
|
200 |
+
};
|
201 |
+
|
202 |
+
function obterAjaxTemplatePadraoKoiber(template_code) {
|
203 |
+
obterJSON('" . $this->getUrl('koiber/index/obterTemplatePadrao') . "template_code/' + template_code, function(dados) {
|
204 |
+
document.getElementById('email').value = dados.text;
|
205 |
+
document.getElementById('assunto').value = dados.subject;
|
206 |
+
}, function(status) {
|
207 |
+
alert('Erro com status ' + status);
|
208 |
+
});
|
209 |
+
}
|
210 |
+
//--></script>";
|
211 |
+
|
212 |
+
return $js_function;
|
213 |
+
}
|
214 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos/Grid.php
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_Eventos_Grid extends Mage_Adminhtml_Block_Widget_Grid {
|
3 |
+
public function __construct() {
|
4 |
+
parent::__construct();
|
5 |
+
|
6 |
+
$this->setDefaultSort('evento_id');
|
7 |
+
$this->setId('koiber_transactionalmessages_eventos_grid');
|
8 |
+
$this->setDefaultDir('asc');
|
9 |
+
$this->setSaveParametersInSession(true);
|
10 |
+
}
|
11 |
+
|
12 |
+
protected function _getCollectionClass() {
|
13 |
+
return 'koiber_transactionalmessages/eventos_collection';
|
14 |
+
}
|
15 |
+
|
16 |
+
protected function _prepareCollection() {
|
17 |
+
$collection = Mage::getResourceModel($this->_getCollectionClass());
|
18 |
+
|
19 |
+
$this->setCollection($collection);
|
20 |
+
|
21 |
+
return parent::_prepareCollection();
|
22 |
+
}
|
23 |
+
|
24 |
+
protected function _prepareColumns() {
|
25 |
+
$this->addColumn('evento_id',
|
26 |
+
array(
|
27 |
+
'header'=> $this->__('ID'),
|
28 |
+
'align' =>'right',
|
29 |
+
'width' => '50px',
|
30 |
+
'index' => 'evento_id'
|
31 |
+
)
|
32 |
+
);
|
33 |
+
|
34 |
+
$this->addColumn('evento',
|
35 |
+
array(
|
36 |
+
'header' => $this->__('Mensagem'),
|
37 |
+
'align' => 'left',
|
38 |
+
'index' => 'evento',
|
39 |
+
'renderer' => 'Koiber_TransactionalMessages_Block_Adminhtml_Eventos_Renderer_Template'
|
40 |
+
)
|
41 |
+
);
|
42 |
+
|
43 |
+
$this->addColumn('status',
|
44 |
+
array(
|
45 |
+
'header' => $this->__('Status'),
|
46 |
+
'align' => 'center',
|
47 |
+
'index' => 'status',
|
48 |
+
'renderer' => 'Koiber_TransactionalMessages_Block_Adminhtml_Eventos_Renderer_Status'
|
49 |
+
)
|
50 |
+
);
|
51 |
+
|
52 |
+
return parent::_prepareColumns();
|
53 |
+
}
|
54 |
+
|
55 |
+
public function getRowUrl($row) {
|
56 |
+
return $this->getUrl('*/*/edit', array('evento_id' => $row->getId()));
|
57 |
+
}
|
58 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos/Renderer/Status.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_Eventos_Renderer_Status extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
|
3 |
+
public function render(Varien_Object $row) {
|
4 |
+
$value = $row->getData($this->getColumn()->getIndex());
|
5 |
+
|
6 |
+
return $value ? __('Ativo') : __('Inativo');
|
7 |
+
}
|
8 |
+
}
|
9 |
+
?>
|
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Eventos/Renderer/Template.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_Eventos_Renderer_Template extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
|
3 |
+
public function render(Varien_Object $row) {
|
4 |
+
$value = $row->getData($this->getColumn()->getIndex());
|
5 |
+
|
6 |
+
$defaultTemplates = Mage::getModel('core/email_template')->getDefaultTemplatesAsOptionsArray();
|
7 |
+
|
8 |
+
foreach ($defaultTemplates as $defaultTemplate) {
|
9 |
+
if ($defaultTemplate['value'] == $value) {
|
10 |
+
$value = $defaultTemplate['label'];
|
11 |
+
|
12 |
+
break;
|
13 |
+
}
|
14 |
+
}
|
15 |
+
|
16 |
+
return $value;
|
17 |
+
}
|
18 |
+
}
|
19 |
+
?>
|
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Historico.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_Historico extends Mage_Adminhtml_Block_Widget_Grid_Container {
|
3 |
+
public function __construct() {
|
4 |
+
$this->_blockGroup = 'koiber_transactionalmessages';
|
5 |
+
$this->_controller = 'adminhtml_historico';
|
6 |
+
$this->_headerText = __('Histórico de Mensagens');
|
7 |
+
$this->_removeButton('add');
|
8 |
+
|
9 |
+
parent::__construct();
|
10 |
+
}
|
11 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Historico/Grid.php
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_Historico_Grid extends Mage_Adminhtml_Block_Widget_Grid {
|
3 |
+
public function __construct() {
|
4 |
+
parent::__construct();
|
5 |
+
|
6 |
+
$this->setDefaultSort('historico_id');
|
7 |
+
$this->setId('koiber_transactionalmessages_historico_grid');
|
8 |
+
$this->setDefaultDir('desc');
|
9 |
+
$this->setSaveParametersInSession(true);
|
10 |
+
}
|
11 |
+
|
12 |
+
protected function _getCollectionClass() {
|
13 |
+
return 'koiber_transactionalmessages/historico_collection';
|
14 |
+
}
|
15 |
+
|
16 |
+
protected function _prepareCollection() {
|
17 |
+
$collection = Mage::getResourceModel($this->_getCollectionClass());
|
18 |
+
|
19 |
+
$this->setCollection($collection);
|
20 |
+
|
21 |
+
return parent::_prepareCollection();
|
22 |
+
}
|
23 |
+
|
24 |
+
protected function _prepareColumns() {
|
25 |
+
$this->addColumn('historico_id',
|
26 |
+
array(
|
27 |
+
'header'=> $this->__('ID'),
|
28 |
+
'align' =>'right',
|
29 |
+
'width' => '50px',
|
30 |
+
'index' => 'historico_id'
|
31 |
+
)
|
32 |
+
);
|
33 |
+
|
34 |
+
$this->addColumn('titulo',
|
35 |
+
array(
|
36 |
+
'header' => $this->__('Título'),
|
37 |
+
'align' => 'left',
|
38 |
+
'index' => 'koiber_parent_talk_id',
|
39 |
+
'renderer' => 'Koiber_TransactionalMessages_Block_Adminhtml_Historico_Renderer_Template'
|
40 |
+
)
|
41 |
+
);
|
42 |
+
|
43 |
+
$this->addColumn('cliente',
|
44 |
+
array(
|
45 |
+
'header' => $this->__('Cliente'),
|
46 |
+
'align' => 'left',
|
47 |
+
'index' => 'email',
|
48 |
+
'renderer' => 'Koiber_TransactionalMessages_Block_Adminhtml_Historico_Renderer_Template'
|
49 |
+
)
|
50 |
+
);
|
51 |
+
|
52 |
+
$this->addColumn('status',
|
53 |
+
array(
|
54 |
+
'header' => $this->__('Nome do Evento'),
|
55 |
+
'align' => 'left',
|
56 |
+
'index' => 'koiber_last_message_id_status',
|
57 |
+
'renderer' => 'Koiber_TransactionalMessages_Block_Adminhtml_Historico_Renderer_Template'
|
58 |
+
)
|
59 |
+
);
|
60 |
+
|
61 |
+
$this->addColumn('canal',
|
62 |
+
array(
|
63 |
+
'header' => $this->__('Canal'),
|
64 |
+
'align' => 'left',
|
65 |
+
'index' => 'canal',
|
66 |
+
'renderer' => 'Koiber_TransactionalMessages_Block_Adminhtml_Historico_Renderer_Template'
|
67 |
+
)
|
68 |
+
);
|
69 |
+
|
70 |
+
$this->addColumn('data',
|
71 |
+
array(
|
72 |
+
'header' => $this->__('Data'),
|
73 |
+
'align' => 'left',
|
74 |
+
'index' => 'data_modificado',
|
75 |
+
'renderer' => 'Koiber_TransactionalMessages_Block_Adminhtml_Historico_Renderer_Template'
|
76 |
+
)
|
77 |
+
);
|
78 |
+
|
79 |
+
return parent::_prepareColumns();
|
80 |
+
}
|
81 |
+
|
82 |
+
public function getRowUrl($row) {
|
83 |
+
return $this->getUrl('*/*/mensagem', array('historico_id' => $row->getId()));
|
84 |
+
}
|
85 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Historico/Renderer/Template.php
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_Historico_Renderer_Template extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
|
3 |
+
public function render(Varien_Object $row) {
|
4 |
+
$value = $row->getData($this->getColumn()->getIndex());
|
5 |
+
|
6 |
+
switch ($this->getColumn()->getId()) {
|
7 |
+
case 'status':
|
8 |
+
$texto = array(
|
9 |
+
'talk.created' => __('Conversa Criada'),
|
10 |
+
'talk.msg.created' => __('Mensagem Adicionada'),
|
11 |
+
'talk.close' => __('Conversa Encerrada'),
|
12 |
+
'talk.rating' => __('Conversa Avaliada'),
|
13 |
+
);
|
14 |
+
|
15 |
+
$value = isset($texto[$value]) ? $texto[$value] : $value;
|
16 |
+
break;
|
17 |
+
case 'canal':
|
18 |
+
require_once(Mage::getBaseDir('lib') . '/koiberPHP/src/Koiber/Autoload.php');
|
19 |
+
|
20 |
+
$koiberConfig = Mage::getStoreConfig('koiber_options/koiber_configs');
|
21 |
+
|
22 |
+
$koiberApi = new Koiber($koiberConfig['koiber_api']);
|
23 |
+
$response = $koiberApi->getCannels();
|
24 |
+
|
25 |
+
$canaisKoiber = $response->getBody(true);
|
26 |
+
|
27 |
+
foreach ($canaisKoiber as $canalKoiber) {
|
28 |
+
if ($canalKoiber['id'] == $value) {
|
29 |
+
$value = $canalKoiber['name'];
|
30 |
+
|
31 |
+
break;
|
32 |
+
}
|
33 |
+
}
|
34 |
+
break;
|
35 |
+
case 'cliente':
|
36 |
+
$customer = Mage::getModel('customer/customer')->setWebsiteId(1)->loadByEmail($value)->getData();
|
37 |
+
|
38 |
+
$value = $customer ? $customer['firstname'] . ' ' . $customer['lastname'] : $value;
|
39 |
+
break;
|
40 |
+
case 'data':
|
41 |
+
$value = date('d/m/Y H:i:s', strtotime($value));
|
42 |
+
break;
|
43 |
+
case 'titulo':
|
44 |
+
require_once(Mage::getBaseDir('lib') . '/koiberPHP/src/Koiber/Autoload.php');
|
45 |
+
|
46 |
+
$koiberConfig = Mage::getStoreConfig('koiber_options/koiber_configs');
|
47 |
+
|
48 |
+
$koiberApi = new Koiber($koiberConfig['koiber_api']);
|
49 |
+
$response = $koiberApi->getTalk($value);
|
50 |
+
$response = $response->getBody(true);
|
51 |
+
|
52 |
+
$historico = Mage::getModel('koiber_transactionalmessages/historico')->load($response['id'], 'koiber_parent_talk_id');
|
53 |
+
$mensagem = Mage::getModel('koiber_transactionalmessages/mensagem')->getCollection()->addFieldToFilter('historico_id', array('eq' => $historico->getId()))->count();
|
54 |
+
|
55 |
+
$value = $response['title'] . ' (' . ($mensagem) . ')';
|
56 |
+
break;
|
57 |
+
}
|
58 |
+
|
59 |
+
return $value;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
?>
|
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Mensagem/Edit.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_Mensagem_Edit extends Mage_Adminhtml_Block_Widget_Form_Container {
|
3 |
+
public function __construct() {
|
4 |
+
$this->_objectId = 'historico_id';
|
5 |
+
$this->_blockGroup = 'koiber_transactionalmessages';
|
6 |
+
$this->_controller = 'adminhtml_mensagem';
|
7 |
+
|
8 |
+
parent::__construct();
|
9 |
+
|
10 |
+
$this->_removeButton('save');
|
11 |
+
$this->_removeButton('delete');
|
12 |
+
$this->_removeButton('reset');
|
13 |
+
}
|
14 |
+
|
15 |
+
public function getHeaderText() {
|
16 |
+
return $this->__('Visualizar a Mensagem');
|
17 |
+
}
|
18 |
+
|
19 |
+
protected function _prepareLayout() {
|
20 |
+
parent::_prepareLayout();
|
21 |
+
}
|
22 |
+
|
23 |
+
public function getBackUrl() {
|
24 |
+
parent::getBackUrl();
|
25 |
+
|
26 |
+
return $this->getUrl('*/*/historico');
|
27 |
+
}
|
28 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/Mensagem/Edit/Form.php
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_Mensagem_Edit_Form extends Mage_Adminhtml_Block_Widget_Form {
|
3 |
+
public function __construct() {
|
4 |
+
parent::__construct();
|
5 |
+
|
6 |
+
$this->setId('koiber_transactionalmessages_mensagem_form');
|
7 |
+
$this->setTitle($this->__('Informações da Mensagem'));
|
8 |
+
}
|
9 |
+
|
10 |
+
protected function _prepareLayout() {
|
11 |
+
return parent::_prepareLayout();
|
12 |
+
}
|
13 |
+
|
14 |
+
protected function _prepareForm() {
|
15 |
+
$model = Mage::registry('koiber_transactionalmessages_historico');
|
16 |
+
|
17 |
+
$form = new Varien_Data_Form(array('id' => 'view_form'));
|
18 |
+
|
19 |
+
$fieldset = $form->addFieldset('base_fieldset', array(
|
20 |
+
'legend' => Mage::helper('checkout')->__('Dados da Mensagem'),
|
21 |
+
'class' => 'fieldset-wide'
|
22 |
+
));
|
23 |
+
|
24 |
+
$defaultTemplates = Mage::getModel('core/email_template')->getDefaultTemplates();
|
25 |
+
|
26 |
+
foreach ($defaultTemplates as $code => $defaultTemplate) {
|
27 |
+
if ($code == $model->getTemplate()) {
|
28 |
+
$template = $defaultTemplate['label'];
|
29 |
+
|
30 |
+
break;
|
31 |
+
} else {
|
32 |
+
$template = "";
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
$fieldset->addField('template', 'note', array(
|
37 |
+
'label' => $this->__('Template da Mensagem'),
|
38 |
+
'text' => $template
|
39 |
+
));
|
40 |
+
|
41 |
+
require_once(Mage::getBaseDir('lib') . '/koiberPHP/src/Koiber/Autoload.php');
|
42 |
+
|
43 |
+
$koiberConfig = Mage::getStoreConfig('koiber_options/koiber_configs');
|
44 |
+
|
45 |
+
$koiberApi = new Koiber($koiberConfig['koiber_api']);
|
46 |
+
$response = $koiberApi->getCannels();
|
47 |
+
|
48 |
+
$canaisKoiber = $response->getBody(true);
|
49 |
+
|
50 |
+
foreach ($canaisKoiber as $canalKoiber) {
|
51 |
+
if ($canalKoiber['id'] == $model->getCanal()) {
|
52 |
+
$canal = $canalKoiber['name'];
|
53 |
+
|
54 |
+
break;
|
55 |
+
} else {
|
56 |
+
$canal = "";
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
$fieldset->addField('canal', 'note', array(
|
61 |
+
'label' => $this->__('Canal'),
|
62 |
+
'text' => $canal
|
63 |
+
));
|
64 |
+
|
65 |
+
/*$texto_tipo = array(
|
66 |
+
'text' => __('Texto'),
|
67 |
+
'form' => __('Formulário'),
|
68 |
+
'form_resp' => __('Resposta de Formulário')
|
69 |
+
);
|
70 |
+
|
71 |
+
$fieldset->addField('tipo', 'note', array(
|
72 |
+
'label' => $this->__('Tipo de Mensagem'),
|
73 |
+
'text' => isset($texto_tipo[$model->getTipo()]) ? $texto_tipo[$model->getTipo()] : $model->getTipo()
|
74 |
+
));*/
|
75 |
+
|
76 |
+
$texto_evento = array(
|
77 |
+
'talk.created' => __('Conversa Criada'),
|
78 |
+
'talk.msg.created' => __('Mensagem Adicionada'),
|
79 |
+
'talk.close' => __('Conversa Encerrada'),
|
80 |
+
'talk.rating' => __('Conversa Avaliada'),
|
81 |
+
);
|
82 |
+
|
83 |
+
$fieldset->addField('evento', 'note', array(
|
84 |
+
'label' => $this->__('Último Evento'),
|
85 |
+
'text' => isset($texto_evento[$model->getKoiberLastMessageIdStatus()]) ? $texto_evento[$model->getKoiberLastMessageIdStatus()] : $model->getTipo()
|
86 |
+
));
|
87 |
+
|
88 |
+
$fieldset->addField('data_inserido', 'note', array(
|
89 |
+
'label' => $this->__('Data de Criação da Conversa'),
|
90 |
+
'text' => date('d/m/Y H:i:s', strtotime($model->getDataInserido()))
|
91 |
+
));
|
92 |
+
|
93 |
+
$fieldset->addField('data_modificado', 'note', array(
|
94 |
+
'label' => $this->__('Data da Última Modificação'),
|
95 |
+
'text' => date('d/m/Y H:i:s', strtotime($model->getDataModificado()))
|
96 |
+
));
|
97 |
+
|
98 |
+
$mensagens = Mage::getModel('koiber_transactionalmessages/mensagem')->getCollection()->addFieldToFilter('historico_id', array('eq' => $model->getId()));
|
99 |
+
|
100 |
+
$i = 1;
|
101 |
+
|
102 |
+
foreach ($mensagens as $mensagem) {
|
103 |
+
$message = unserialize($mensagem->getMensagem());
|
104 |
+
|
105 |
+
if ($this->validate_json($message['content'])) {
|
106 |
+
$message['content'] = (array)json_decode($message['content']);
|
107 |
+
}
|
108 |
+
|
109 |
+
if ($message['type'] == 'form') {
|
110 |
+
$message_html = '';
|
111 |
+
|
112 |
+
foreach ($message['content']['elements'] as $element) {
|
113 |
+
$element = (object)$element;
|
114 |
+
|
115 |
+
switch ($element->element) {
|
116 |
+
case 'p': $message_html .= '<p>' . $element->content . '</p>'; break;
|
117 |
+
case 'input':
|
118 |
+
$message_html .= '<p>' . $element->label . ' <input type="' . $element->type . '" name="' . $element->id . '" value="' . $element->response . '" disabled="disabled"></p>';
|
119 |
+
break;
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
$message['content'] = $message_html;
|
124 |
+
} elseif ($message['type'] == 'form_resp') {
|
125 |
+
$message_html = '';
|
126 |
+
|
127 |
+
foreach ($message['content'] as $element) {
|
128 |
+
switch ($element['element']) {
|
129 |
+
case 'p': $message_html .= '<p>' . $element['content'] . '</p>'; break;
|
130 |
+
case 'input':
|
131 |
+
$message_html .= '<p>' . $element['label'] . ': ' . $element['response'] . '</p>';
|
132 |
+
break;
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
$message['content'] = $message_html;
|
137 |
+
} else {
|
138 |
+
$message['content'] = nl2br(strip_tags($message['content']));
|
139 |
+
}
|
140 |
+
|
141 |
+
$trajeto = (($i == 1) || ($message['author'] == 'company')) ? __('enviado') : __('recebido');
|
142 |
+
|
143 |
+
$fieldset->addField('mensagem' . $mensagem->getId(), 'note', array(
|
144 |
+
'label' => $this->__('Mensagem') . '# ' . $i . ' ' . $trajeto . ' ' . __('em') . ' ' . date('d/m/Y H:i:s', strtotime($mensagem->getDataInserido())),
|
145 |
+
'text' => $message['content']
|
146 |
+
));
|
147 |
+
|
148 |
+
$i++;
|
149 |
+
}
|
150 |
+
|
151 |
+
$form->setUseContainer(true);
|
152 |
+
$this->setForm($form);
|
153 |
+
|
154 |
+
return parent::_prepareForm();
|
155 |
+
}
|
156 |
+
|
157 |
+
protected function validate_json($str=NULL) {
|
158 |
+
if (is_string($str)) {
|
159 |
+
@json_decode($str);
|
160 |
+
|
161 |
+
return !json_last_error() ? true : false;
|
162 |
+
}
|
163 |
+
|
164 |
+
return false;
|
165 |
+
}
|
166 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Block/Adminhtml/System/Config/Info.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Block_Adminhtml_System_Config_Info extends Mage_Adminhtml_Block_Abstract {
|
3 |
+
public function render(Varien_Data_Form_Element_Abstract $element) {
|
4 |
+
$apiUrl = Mage::getBaseUrl() . 'koiber';
|
5 |
+
|
6 |
+
$html = '<big><b>' . __('INSTRUÇÕES') . '</b></big><br><br>' . __('O koiber é um aplicativo de envio de mensagens instantânea. Envie mensagens em tempo real para seu cliente com integração total com o magento.') . '<br>' . __('Para gerar o TOKEN você terá que ter cadastro no site www.koiber.com (cadastro gratuito) e acessar o Painel -> Integração -> API') . '<br><br>' . __('Para habilitar as notificações para fins de comunicação do Koiber com o Magento, cadastre a seguinte url no Koiber') . '<br> <a href="' . $apiUrl . '">' . $apiUrl . '</a><br><br>' . __('Para saber mais acesse o site www.koiber.com') . '<br><br>';
|
7 |
+
|
8 |
+
return $html;
|
9 |
+
}
|
10 |
+
}
|
11 |
+
?>
|
app/code/community/Koiber/TransactionalMessages/Helper/Data.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Helper_Data extends Mage_Core_Helper_Abstract {
|
3 |
+
|
4 |
+
}
|
5 |
+
?>
|
app/code/community/Koiber/TransactionalMessages/Model/Eventos.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Eventos extends Mage_Core_Model_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/eventos');
|
5 |
+
}
|
6 |
+
}
|
7 |
+
?>
|
app/code/community/Koiber/TransactionalMessages/Model/Historico.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Historico extends Mage_Core_Model_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/historico');
|
5 |
+
}
|
6 |
+
}
|
7 |
+
?>
|
app/code/community/Koiber/TransactionalMessages/Model/Mensagem.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Mensagem extends Mage_Core_Model_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/mensagem');
|
5 |
+
}
|
6 |
+
}
|
7 |
+
?>
|
app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Eventos.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Mysql4_Eventos extends Mage_Core_Model_Mysql4_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/eventos', 'evento_id');
|
5 |
+
}
|
6 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Eventos/Collection.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Mysql4_Eventos_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/eventos');
|
5 |
+
}
|
6 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Historico.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Mysql4_Historico extends Mage_Core_Model_Mysql4_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/historico', 'historico_id');
|
5 |
+
}
|
6 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Historico/Collection.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Mysql4_Historico_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/historico');
|
5 |
+
}
|
6 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Mensagem.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Mysql4_Mensagem extends Mage_Core_Model_Mysql4_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/mensagem', 'mensagem_historico_id');
|
5 |
+
}
|
6 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Mensagem/Collection.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Mysql4_Mensagem_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/mensagem');
|
5 |
+
}
|
6 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Padrao.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Mysql4_Padrao extends Mage_Core_Model_Mysql4_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/padrao', 'padrao_id');
|
5 |
+
}
|
6 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Model/Mysql4/Padrao/Collection.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Mysql4_Padrao_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/padrao');
|
5 |
+
}
|
6 |
+
}
|
app/code/community/Koiber/TransactionalMessages/Model/Padrao.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_Model_Padrao extends Mage_Core_Model_Abstract {
|
3 |
+
protected function _construct() {
|
4 |
+
$this->_init('koiber_transactionalmessages/padrao');
|
5 |
+
}
|
6 |
+
}
|
7 |
+
?>
|
app/code/community/Koiber/TransactionalMessages/controllers/IndexController.php
ADDED
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_IndexController extends Mage_Core_Controller_Front_Action {
|
3 |
+
public function indexAction() {
|
4 |
+
date_default_timezone_set(Mage::getStoreConfig('general/locale/timezone'));
|
5 |
+
//file_put_contents('teste_cell.txt', http_build_query($this->getRequest()->getPost()));
|
6 |
+
|
7 |
+
if (!$this->getRequest()->isPost() && !$this->getRequest()->getParam('debug')) {
|
8 |
+
$this->getResponse()->setBody("Por enquanto, apenas para mostrar que eu existo, estou mostrando esta mensagem. Porém muito breve eu irei desaparecer e qualquer acesso que não seja via POST até mim será enviado para a loja de quem eu pertenço =).");
|
9 |
+
} elseif ($this->getRequest()->getParam('debug') || $this->getRequest()->isPost()) {
|
10 |
+
$postData = !$this->getRequest()->getParam('debug') ? $this->getRequest()->getPost() : $this->getRequest()->getParams();
|
11 |
+
|
12 |
+
if (isset($postData['event']) && (isset($postData['data']['id']) || isset($postData['data']['talk_id']))) {
|
13 |
+
$talk_id = isset($postData['data']['talk_id']) ? $postData['data']['talk_id'] : $postData['data']['id'];
|
14 |
+
|
15 |
+
$msg_id = '';
|
16 |
+
$msg_data = array();
|
17 |
+
|
18 |
+
if (isset($postData['data']['msg_id'])) {
|
19 |
+
if (is_array($postData['data']['msg_id'])) {
|
20 |
+
foreach ($postData['data']['msg_id'] as $data_msg_id) {
|
21 |
+
$msg_id = $data_msg_id;
|
22 |
+
$msg_data = $this->obterMsgData($data_msg_id);
|
23 |
+
}
|
24 |
+
} else {
|
25 |
+
$msg_id = $postData['data']['msg_id'];
|
26 |
+
$msg_data = $this->obterMsgData($postData['data']['msg_id']);
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
$model = Mage::getSingleton('koiber_transactionalmessages/historico')->load($talk_id, 'koiber_parent_talk_id');
|
31 |
+
|
32 |
+
$id = $model->getId();
|
33 |
+
|
34 |
+
if ($id) {
|
35 |
+
$model->addData(array(
|
36 |
+
'koiber_last_message_id' => $msg_id ? $msg_id : $model->getKoiberLastMessageId(),
|
37 |
+
'koiber_last_message_id_status' => $postData['event'],
|
38 |
+
'data_modificado' => date('Y-m-d H:i:s'),
|
39 |
+
'tipo' => $msg_data ? $msg_data['type'] : 'text',
|
40 |
+
));
|
41 |
+
|
42 |
+
$model->setId($id)->save();
|
43 |
+
|
44 |
+
if ($msg_data && $msg_data['content']) {
|
45 |
+
$modelMensagem = Mage::getSingleton('koiber_transactionalmessages/mensagem')->load($msg_id, 'tipo');
|
46 |
+
|
47 |
+
if (!$modelMensagem->getId()) {
|
48 |
+
$modelMensagem->setData(array(
|
49 |
+
'historico_id' => $id,
|
50 |
+
'mensagem' => serialize($msg_data),
|
51 |
+
'tipo' => $msg_id,
|
52 |
+
'data_inserido' => date('Y-m-d H:i:s')
|
53 |
+
));
|
54 |
+
|
55 |
+
$modelMensagem->save();
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
if ($msg_data && ($msg_data['type'] == 'form_resp')) {
|
60 |
+
$data = array();
|
61 |
+
|
62 |
+
foreach ($msg_data['content'] as $content) {
|
63 |
+
switch ($content['element']) {
|
64 |
+
case 'input':
|
65 |
+
$data[$content['id']] = $content['response'];
|
66 |
+
break;
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
$order = Mage::getModel('sales/order')->load($model->getOrderId(), 'increment_id');
|
71 |
+
|
72 |
+
foreach ($data as $campo => $valor) {
|
73 |
+
if (strpos(strtolower($campo), 'order_shipping') !== false) {
|
74 |
+
$shippingAddress = Mage::getModel('sales/order_address')->load($order->getShippingAddress()->getId());
|
75 |
+
|
76 |
+
if ($campo_filtrado = $this->obterCampoFiltrado($campo)) {
|
77 |
+
$shippingAddress->addData(array($campo_filtrado => $valor))->save();
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
if (strpos(strtolower($campo), 'order_billing') !== false) {
|
82 |
+
$billingAddress = Mage::getModel('sales/order_address')->load($order->getBillingAddress()->getId());
|
83 |
+
|
84 |
+
if ($campo_filtrado = $this->obterCampoFiltrado($campo)) {
|
85 |
+
$billingAddress->addData(array($campo_filtrado => $valor))->save();
|
86 |
+
}
|
87 |
+
}
|
88 |
+
}
|
89 |
+
}
|
90 |
+
}
|
91 |
+
}
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
public function obterTemplatePadraoAction() {
|
96 |
+
if(!$this->getRequest()->getParam('template_code')) {
|
97 |
+
return array();
|
98 |
+
} else {
|
99 |
+
$template_code = $this->getRequest()->getParam('template_code');
|
100 |
+
}
|
101 |
+
|
102 |
+
$koiberDefault = Mage::getModel('koiber_transactionalmessages/padrao')->load($template_code, 'evento');
|
103 |
+
|
104 |
+
if ($koiberDefault->getId()) {
|
105 |
+
$templateData['text'] = trim($koiberDefault->getMensagem(), "\n");
|
106 |
+
$templateData['subject'] = trim($koiberDefault->getAssunto(), "\n");
|
107 |
+
} else {
|
108 |
+
$localeCode = Mage::getStoreConfig('general/locale/code', $storeId);
|
109 |
+
|
110 |
+
$templateData['text'] = trim(Mage::getModel('core/email_template')->loadDefault($template_code, $localeCode)->getTemplateText(), "\n");
|
111 |
+
$templateData['subject'] = trim(Mage::getModel('core/email_template')->loadDefault($template_code, $localeCode)->getTemplateSubject(), "\n");
|
112 |
+
}
|
113 |
+
|
114 |
+
$this->getResponse()->setBody(Zend_Json::encode($templateData));
|
115 |
+
}
|
116 |
+
|
117 |
+
public function variaveisPluginAction() {
|
118 |
+
$storeContactVariabls = Mage::getModel('core/source_email_variables')->toOptionArray(true);
|
119 |
+
|
120 |
+
if ($this->getRequest()->getParam('template_code')) {
|
121 |
+
$customVariables = Mage::getModel('core/email_template')->loadDefault($this->getRequest()->getParam('template_code'))->getVariablesOptionArray(true);
|
122 |
+
} else {
|
123 |
+
$customVariables = array();
|
124 |
+
}
|
125 |
+
|
126 |
+
$variables = array($storeContactVariabls, $customVariables);
|
127 |
+
|
128 |
+
$this->getResponse()->setBody(Zend_Json::encode($variables));
|
129 |
+
}
|
130 |
+
|
131 |
+
protected function obterCampoFiltrado($campo) {
|
132 |
+
$filtro = array(
|
133 |
+
'order_shipping_address_street1' => 'street',
|
134 |
+
'order_shipping_address_country' => 'country_id',
|
135 |
+
'order_shipping_address_city' => 'city',
|
136 |
+
'order_shipping_address_region' => 'region',
|
137 |
+
'order_shipping_address_postcode' => 'postcode',
|
138 |
+
'order_billing_address_street1' => 'street',
|
139 |
+
'order_billing_address_country' => 'country_id',
|
140 |
+
'order_billing_address_city' => 'city',
|
141 |
+
'order_billing_address_region' => 'region',
|
142 |
+
'order_billing_address_postcode' => 'postcode'
|
143 |
+
);
|
144 |
+
|
145 |
+
return isset($filtro[strtolower($campo)]) ? $filtro[strtolower($campo)] : '';
|
146 |
+
}
|
147 |
+
|
148 |
+
protected function obterMsgData($msg_id) {
|
149 |
+
require_once(Mage::getBaseDir('lib') . '/koiberPHP/src/Koiber/Autoload.php');
|
150 |
+
|
151 |
+
$koiberConfig = Mage::getStoreConfig('koiber_options/koiber_configs');
|
152 |
+
|
153 |
+
$koiberApi = new Koiber($koiberConfig['koiber_api']);
|
154 |
+
|
155 |
+
$response = $koiberApi->getMsg($msg_id);
|
156 |
+
$response = $response->isOk() ? $response->getBody(true) : '';
|
157 |
+
|
158 |
+
//if (($response['type']) && ($response['type'] == 'form_resp')) {
|
159 |
+
if ($response) {
|
160 |
+
$msg_data = $response;
|
161 |
+
} else {
|
162 |
+
$msg_data = array();
|
163 |
+
}
|
164 |
+
|
165 |
+
return $msg_data;
|
166 |
+
}
|
167 |
+
}
|
app/code/community/Koiber/TransactionalMessages/controllers/KoiberController.php
ADDED
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Koiber_TransactionalMessages_KoiberController extends Mage_Adminhtml_Controller_Action {
|
3 |
+
private $pageData = array(
|
4 |
+
'action' => 'koiber/index',
|
5 |
+
'title' => 'Mensagens'
|
6 |
+
);
|
7 |
+
|
8 |
+
private function verificaStatusKoiber($index = false) {
|
9 |
+
$koiberConfig = Mage::getStoreConfig('koiber_options/koiber_configs');
|
10 |
+
|
11 |
+
if (!$koiberConfig['koiber_api'] || !$koiberConfig['koiber_status']) {
|
12 |
+
Mage::getSingleton('adminhtml/session')->addError($this->__('Para o correto funcionamento é necessário o módulo está ativo nas configurações e com uma chave API válida.'));
|
13 |
+
|
14 |
+
if (!$index) {
|
15 |
+
$this->_redirect('*/*');
|
16 |
+
}
|
17 |
+
}
|
18 |
+
}
|
19 |
+
|
20 |
+
public function indexAction() {
|
21 |
+
$this->verificaStatusKoiber(true);
|
22 |
+
$this->_initAction()->renderLayout();
|
23 |
+
}
|
24 |
+
|
25 |
+
public function historicoAction() {
|
26 |
+
$this->verificaStatusKoiber();
|
27 |
+
$this->pageData = array(
|
28 |
+
'action' => 'koiber/historico',
|
29 |
+
'title' => 'Histórico de Mensagens'
|
30 |
+
);
|
31 |
+
|
32 |
+
$this->_initAction()->renderLayout();
|
33 |
+
}
|
34 |
+
|
35 |
+
public function mensagemAction() {
|
36 |
+
$this->verificaStatusKoiber();
|
37 |
+
$this->pageData = array(
|
38 |
+
'action' => 'koiber/mensagem',
|
39 |
+
'title' => 'Mensagem'
|
40 |
+
);
|
41 |
+
|
42 |
+
$historico_id = $this->getRequest()->getParam('historico_id');
|
43 |
+
$model = Mage::getModel('koiber_transactionalmessages/historico');
|
44 |
+
|
45 |
+
$model->load((int)$historico_id);
|
46 |
+
|
47 |
+
if (!$model->getId()) {
|
48 |
+
Mage::getSingleton('adminhtml/session')->addError($this->__('Esta mensagem não existe no histórico.'));
|
49 |
+
$this->_redirect('*/*/historico');
|
50 |
+
|
51 |
+
return;
|
52 |
+
}
|
53 |
+
|
54 |
+
Mage::register('koiber_transactionalmessages_historico', $model);
|
55 |
+
|
56 |
+
$this->_initAction()
|
57 |
+
->_addContent($this->getLayout()->createBlock('koiber_transactionalmessages/adminhtml_mensagem_edit'))
|
58 |
+
->renderLayout();
|
59 |
+
}
|
60 |
+
|
61 |
+
public function newAction() {
|
62 |
+
$this->verificaStatusKoiber();
|
63 |
+
$this->_forward('edit');
|
64 |
+
}
|
65 |
+
|
66 |
+
public function editAction() {
|
67 |
+
$this->verificaStatusKoiber();
|
68 |
+
$this->_initAction();
|
69 |
+
|
70 |
+
$evento_id = $this->getRequest()->getParam('evento_id');
|
71 |
+
$model = Mage::getModel('koiber_transactionalmessages/eventos');
|
72 |
+
|
73 |
+
if ($evento_id) {
|
74 |
+
$model->load($evento_id);
|
75 |
+
|
76 |
+
if (!$model->getId()) {
|
77 |
+
Mage::getSingleton('adminhtml/session')->addError($this->__('Esta mensagem não existe mais.'));
|
78 |
+
$this->_redirect('*/*/');
|
79 |
+
|
80 |
+
return;
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
$this->_title($model->getId() ? $model->getName() : $this->__('Nova Mensagem'));
|
85 |
+
|
86 |
+
$data = Mage::getSingleton('adminhtml/session')->getEventosData(true);
|
87 |
+
|
88 |
+
if (!empty($data)) {
|
89 |
+
$model->setData($data);
|
90 |
+
}
|
91 |
+
|
92 |
+
Mage::register('koiber_transactionalmessages', $model);
|
93 |
+
|
94 |
+
$this->_initAction()
|
95 |
+
->_addBreadcrumb($evento_id ? $this->__('Editar Mensagem') : $this->__('Nova Mensagem'), $evento_id ? $this->__('Editar Mensagem') : $this->__('Nova Mensagem'))
|
96 |
+
->_addContent($this->getLayout()->createBlock('koiber_transactionalmessages/adminhtml_eventos_edit')->setData('action', $this->getUrl('*/*/save')))
|
97 |
+
->renderLayout();
|
98 |
+
}
|
99 |
+
|
100 |
+
public function saveAction() {
|
101 |
+
$this->verificaStatusKoiber();
|
102 |
+
$postData = $this->getRequest()->getPost();
|
103 |
+
|
104 |
+
if ($postData && !$this->validateForm($postData)) {
|
105 |
+
$model = Mage::getSingleton('koiber_transactionalmessages/eventos');
|
106 |
+
$model->setData(array_merge(array('evento_id' => $this->getRequest()->getParam('evento_id')), $postData));
|
107 |
+
|
108 |
+
try {
|
109 |
+
$model->save();
|
110 |
+
|
111 |
+
Mage::getSingleton('adminhtml/session')->addSuccess($this->__('A mensagem foi salva com sucesso.'));
|
112 |
+
$this->_redirect('*/*/');
|
113 |
+
|
114 |
+
return;
|
115 |
+
} catch (Mage_Core_Exception $e) {
|
116 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
117 |
+
} catch (Exception $e) {
|
118 |
+
Mage::getSingleton('adminhtml/session')->addError($this->__('Um erro ocorreu ao salvar a mensagem.'));
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
Mage::getSingleton('adminhtml/session')->setEventosData($postData);
|
123 |
+
|
124 |
+
$this->_redirectReferer();
|
125 |
+
}
|
126 |
+
|
127 |
+
public function deleteAction() {
|
128 |
+
$this->verificaStatusKoiber();
|
129 |
+
if($this->getRequest()->getParam('evento_id')) {
|
130 |
+
try {
|
131 |
+
$model = Mage::getModel('koiber_transactionalmessages/eventos');
|
132 |
+
$model->setId($this->getRequest()->getParam('evento_id'))->delete();
|
133 |
+
|
134 |
+
Mage::getSingleton('adminhtml/session')->addSuccess('Mensagem excluido com sucesso.');
|
135 |
+
|
136 |
+
$this->_redirect('*/*/');
|
137 |
+
|
138 |
+
return;
|
139 |
+
} catch (Mage_Core_Exception $e) {
|
140 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
141 |
+
} catch (Exception $e) {
|
142 |
+
Mage::getSingleton('adminhtml/session')->addError($this->__('Um erro ocorreu ao excluir a mensagem.'));
|
143 |
+
}
|
144 |
+
|
145 |
+
$this->_redirectReferer();
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
public function variaveisPluginAction() {
|
150 |
+
$storeContactVariabls = Mage::getModel('core/source_email_variables')->toOptionArray(true);
|
151 |
+
|
152 |
+
if ($this->getRequest()->getParam('template_code')) {
|
153 |
+
$customVariables = Mage::getModel('core/email_template')->loadDefault($this->getRequest()->getParam('template_code'))->getVariablesOptionArray(true);
|
154 |
+
} else {
|
155 |
+
$customVariables = array();
|
156 |
+
}
|
157 |
+
|
158 |
+
$variables = array($storeContactVariabls, $customVariables);
|
159 |
+
|
160 |
+
$this->getResponse()->setBody(Zend_Json::encode($variables));
|
161 |
+
}
|
162 |
+
|
163 |
+
public function messageAction() {
|
164 |
+
$data = Mage::getModel('koiber_transactionalmessages/eventos')->load($this->getRequest()->getParam('evento_id'));
|
165 |
+
|
166 |
+
echo $data->getContent();
|
167 |
+
}
|
168 |
+
|
169 |
+
protected function _initAction() {
|
170 |
+
$this->loadLayout()
|
171 |
+
->_setActiveMenu($this->pageData['action'])
|
172 |
+
->_title($this->__('Koiber'))->_title($this->__($this->pageData['title']))
|
173 |
+
->_addBreadcrumb($this->__('Koiber'), $this->__('Koiber'))
|
174 |
+
->_addBreadcrumb($this->__($this->pageData['title']), $this->__($this->pageData['title']));
|
175 |
+
|
176 |
+
return $this;
|
177 |
+
}
|
178 |
+
|
179 |
+
protected function validateForm($data) {
|
180 |
+
$error = false;
|
181 |
+
|
182 |
+
if (!$data['evento']) {
|
183 |
+
$error = true;
|
184 |
+
|
185 |
+
Mage::getSingleton('adminhtml/session')->setEventoErro($this->__('A seleção da template da mensagem é obrigatória.'));
|
186 |
+
}
|
187 |
+
|
188 |
+
if (!$data['canal']) {
|
189 |
+
$error = true;
|
190 |
+
|
191 |
+
Mage::getSingleton('adminhtml/session')->setCanalErro($this->__('A seleção do canal é obrigatória.'));
|
192 |
+
}
|
193 |
+
|
194 |
+
return $error;
|
195 |
+
}
|
196 |
+
}
|
app/code/community/Koiber/TransactionalMessages/etc/adminhtml.xml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<config>
|
2 |
+
<menu>
|
3 |
+
<koiber translate="title" module="koiber_transactionalmessages">
|
4 |
+
<title>Koiber</title>
|
5 |
+
<sort_order>100</sort_order>
|
6 |
+
<children>
|
7 |
+
<menssgens>
|
8 |
+
<title>Mensagens</title>
|
9 |
+
<sort_order>1</sort_order>
|
10 |
+
<action>adminhtml/koiber/index</action>
|
11 |
+
</menssgens>
|
12 |
+
<historico>
|
13 |
+
<title>Histórico de Mensagens</title>
|
14 |
+
<sort_order>2</sort_order>
|
15 |
+
<action>adminhtml/koiber/historico</action>
|
16 |
+
</historico>
|
17 |
+
</children>
|
18 |
+
</koiber>
|
19 |
+
</menu>
|
20 |
+
</config>
|
app/code/community/Koiber/TransactionalMessages/etc/config.xml
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<config>
|
2 |
+
<modules>
|
3 |
+
<Koiber_TransactionalMessages>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
</Koiber_TransactionalMessages>
|
6 |
+
</modules>
|
7 |
+
<frontend>
|
8 |
+
<routers>
|
9 |
+
<koiber>
|
10 |
+
<use>standard</use>
|
11 |
+
<args>
|
12 |
+
<module>Koiber_TransactionalMessages</module>
|
13 |
+
<frontName>koiber</frontName>
|
14 |
+
</args>
|
15 |
+
</koiber>
|
16 |
+
</routers>
|
17 |
+
<translate>
|
18 |
+
<modules>
|
19 |
+
<Koiber_TransactionalMessages>
|
20 |
+
<files>
|
21 |
+
<default>Koiber_Koiber.csv</default>
|
22 |
+
</files>
|
23 |
+
</Koiber_TransactionalMessages>
|
24 |
+
</modules>
|
25 |
+
</translate>
|
26 |
+
</frontend>
|
27 |
+
<global>
|
28 |
+
<helpers>
|
29 |
+
<koiber_transactionalmessages>
|
30 |
+
<class>Koiber_TransactionalMessages_Helper</class>
|
31 |
+
</koiber_transactionalmessages>
|
32 |
+
</helpers>
|
33 |
+
<blocks>
|
34 |
+
<koiber_transactionalmessages>
|
35 |
+
<class>Koiber_TransactionalMessages_Block</class>
|
36 |
+
</koiber_transactionalmessages>
|
37 |
+
</blocks>
|
38 |
+
<models>
|
39 |
+
<koiber_transactionalmessages>
|
40 |
+
<class>Koiber_TransactionalMessages_Model</class>
|
41 |
+
<resourceModel>koiber_transactionalmessages_mysql4</resourceModel>
|
42 |
+
</koiber_transactionalmessages>
|
43 |
+
<koiber_transactionalmessages_mysql4>
|
44 |
+
<class>Koiber_TransactionalMessages_Model_Mysql4</class>
|
45 |
+
<entities>
|
46 |
+
<eventos>
|
47 |
+
<table>koiber_transactionalmessages_eventos</table>
|
48 |
+
</eventos>
|
49 |
+
<historico>
|
50 |
+
<table>koiber_transactionalmessages_historico</table>
|
51 |
+
</historico>
|
52 |
+
<mensagem>
|
53 |
+
<table>koiber_transactionalmessages_mensagem</table>
|
54 |
+
</mensagem>
|
55 |
+
<padrao>
|
56 |
+
<table>koiber_transactionalmessages_padrao</table>
|
57 |
+
</padrao>
|
58 |
+
</entities>
|
59 |
+
</koiber_transactionalmessages_mysql4>
|
60 |
+
</models>
|
61 |
+
<resources>
|
62 |
+
<koiber_transactionalmessages_setup>
|
63 |
+
<setup>
|
64 |
+
<module>Koiber_TransactionalMessages</module>
|
65 |
+
</setup>
|
66 |
+
</koiber_transactionalmessages_setup>
|
67 |
+
</resources>
|
68 |
+
</global>
|
69 |
+
<admin>
|
70 |
+
<routers>
|
71 |
+
<adminhtml>
|
72 |
+
<args>
|
73 |
+
<modules>
|
74 |
+
<Koiber_TransactionalMessages after="Mage_Adminhtml">Koiber_TransactionalMessages</Koiber_TransactionalMessages>
|
75 |
+
</modules>
|
76 |
+
</args>
|
77 |
+
</adminhtml>
|
78 |
+
</routers>
|
79 |
+
</admin>
|
80 |
+
<adminhtml>
|
81 |
+
<layout>
|
82 |
+
<updates>
|
83 |
+
<koiber_transactionalmessages>
|
84 |
+
<file>koiber.xml</file>
|
85 |
+
</koiber_transactionalmessages>
|
86 |
+
</updates>
|
87 |
+
</layout>
|
88 |
+
<translate>
|
89 |
+
<modules>
|
90 |
+
<Koiber_TransactionalMessages>
|
91 |
+
<files>
|
92 |
+
<default>Koiber_Koiber.csv</default>
|
93 |
+
</files>
|
94 |
+
</Koiber_TransactionalMessages>
|
95 |
+
</modules>
|
96 |
+
</translate>
|
97 |
+
<acl>
|
98 |
+
<resources>
|
99 |
+
<admin>
|
100 |
+
<children>
|
101 |
+
<system>
|
102 |
+
<children>
|
103 |
+
<config>
|
104 |
+
<children>
|
105 |
+
<koiber_options>
|
106 |
+
<title>Configurações do Koiber</title>
|
107 |
+
</koiber_options>
|
108 |
+
</children>
|
109 |
+
</config>
|
110 |
+
</children>
|
111 |
+
</system>
|
112 |
+
</children>
|
113 |
+
</admin>
|
114 |
+
</resources>
|
115 |
+
</acl>
|
116 |
+
</adminhtml>
|
117 |
+
</config>
|
app/code/community/Koiber/TransactionalMessages/etc/system.xml
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<tabs>
|
4 |
+
<koiberconfig translate="label" module="koiber_transactionalmessages">
|
5 |
+
<label>Koiber</label>
|
6 |
+
<sort_order>100</sort_order>
|
7 |
+
</koiberconfig>
|
8 |
+
</tabs>
|
9 |
+
<sections>
|
10 |
+
<koiber_options translate="label" module="koiber_transactionalmessages">
|
11 |
+
<label>Configurações do Koiber</label>
|
12 |
+
<tab>koiberconfig</tab>
|
13 |
+
<frontend_type>text</frontend_type>
|
14 |
+
<sort_order>1000</sort_order>
|
15 |
+
<show_in_default>1</show_in_default>
|
16 |
+
<show_in_website>1</show_in_website>
|
17 |
+
<show_in_store>1</show_in_store>
|
18 |
+
<groups>
|
19 |
+
<koiber_configs translate="label">
|
20 |
+
<label>Dados de Configurações do Koiber</label>
|
21 |
+
<frontend_type>text</frontend_type>
|
22 |
+
<sort_order>1</sort_order>
|
23 |
+
<show_in_default>1</show_in_default>
|
24 |
+
<show_in_website>1</show_in_website>
|
25 |
+
<show_in_store>1</show_in_store>
|
26 |
+
<fields>
|
27 |
+
<koiber_api>
|
28 |
+
<label>TOKEN da API:</label>
|
29 |
+
<comment>Insira aqui o token api gerado pelo koiber.</comment>
|
30 |
+
<frontend_type>text</frontend_type>
|
31 |
+
<sort_order>1</sort_order>
|
32 |
+
<show_in_default>1</show_in_default>
|
33 |
+
<show_in_website>1</show_in_website>
|
34 |
+
<show_in_store>1</show_in_store>
|
35 |
+
</koiber_api>
|
36 |
+
<koiber_status translate="label">
|
37 |
+
<label>Status:</label>
|
38 |
+
<frontend_type>select</frontend_type>
|
39 |
+
<comment>Status de funcionamento do módulo.</comment>
|
40 |
+
<sort_order>90</sort_order>
|
41 |
+
<show_in_default>1</show_in_default>
|
42 |
+
<show_in_website>1</show_in_website>
|
43 |
+
<show_in_store>1</show_in_store>
|
44 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
45 |
+
</koiber_status>
|
46 |
+
<koiber_label translate="label">
|
47 |
+
<frontend_model>koiber_transactionalmessages/adminhtml_system_config_info</frontend_model>
|
48 |
+
<sort_order>100</sort_order>
|
49 |
+
<show_in_default>1</show_in_default>
|
50 |
+
<show_in_website>1</show_in_website>
|
51 |
+
<show_in_store>1</show_in_store>
|
52 |
+
</koiber_label>
|
53 |
+
</fields>
|
54 |
+
</koiber_configs>
|
55 |
+
</groups>
|
56 |
+
</koiber_options>
|
57 |
+
</sections>
|
58 |
+
</config>
|
app/code/community/Koiber/TransactionalMessages/sql/koiber_transactionalmessages_setup/mysql4-install-1.0.0.php
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* @var $installer Mage_Core_Model_Resource_Setup */
|
3 |
+
$installer = $this;
|
4 |
+
$installer->startSetup();
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Create table 'koiber_transactionalmessages_eventos'
|
8 |
+
*/
|
9 |
+
$eventos = $installer->getTable('koiber_transactionalmessages/eventos');
|
10 |
+
|
11 |
+
if ($installer->getConnection()->isTableExists($eventos) != true) {
|
12 |
+
$table = $installer->getConnection()
|
13 |
+
->newTable($installer->getTable('koiber_transactionalmessages/eventos'))
|
14 |
+
->addColumn('evento_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
15 |
+
'identity' => true,
|
16 |
+
'unsigned' => true,
|
17 |
+
'nullable' => false,
|
18 |
+
'primary' => true,
|
19 |
+
), 'Evento_ID')
|
20 |
+
->addColumn('evento', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
21 |
+
'nullable' => false
|
22 |
+
), 'Evento')
|
23 |
+
->addColumn('status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
24 |
+
'default' => 1
|
25 |
+
), 'Status')
|
26 |
+
->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
|
27 |
+
'nullable' => false,
|
28 |
+
), 'E-mail')
|
29 |
+
->addColumn('canal', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
30 |
+
'nullable' => false,
|
31 |
+
), 'Canal')
|
32 |
+
->addColumn('tipo', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
33 |
+
'nullable' => false,
|
34 |
+
), 'Tipo')
|
35 |
+
->addColumn('assunto', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
36 |
+
'nullable' => false,
|
37 |
+
), 'Assunto');
|
38 |
+
$installer->getConnection()->createTable($table);
|
39 |
+
|
40 |
+
$installer->run("INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (2,'sales_email_order_template',1,'{\r\n \"elements\": [\r\n {\r\n \"element\": \"p\",\r\n \"id\": \"p1\",\r\n \"content\": \"Obrigado <b>{{htmlescape var=\$order.getCustomerName()}}</b> pela compra. Por favor confirme o endereço de entrega\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_city\",\r\n \"label\": \"Cidade\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getCity()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_region\",\r\n \"label\": \"Estado\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getRegion()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_street1\",\r\n \"label\": \"Endereço\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getStreet1()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_street2\",\r\n \"label\": \"Complemento\",\r\n \"required\": false,\r\n \"response\": \"{{var order.getShippingAddress().getStreet2()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"number\",\r\n \"id\": \"Order_shipping_address_postcode\",\r\n \"label\": \"CEP\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getPostcode()}}\"\r\n }\r\n ]\r\n}','5755822cf68af264192fc4df','form','Confirmação de pedido ({{var order.increment_id}})');
|
41 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (3,'customer_password_forgot_email_template',1,'Houve recentemente um pedido para alterar a senha da sua conta.\r\n\r\nSe você solicitou esta alteração de senha, por favor redefinir sua senha aqui:\r\n\r\n<a href=\"{{store url=\"customer/account/resetpassword/\" _query_id=\$customer.id _query_token=\$customer.rp_token}}\">Redefinir senha</a>\r\n\r\n\r\nSe você não fez esta solicitação, você pode ignorar esta mensagem e sua senha permanecerá a mesma.','56feaca54c4fe96d457124f7','text','Nova senha');
|
42 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (17,'sales_email_invoice_template',1,'Foi gerado uma nova fatura para o pedido {{var order.increment_id}}.\r\n\r\n{{if comment}}Nota:\r\n{{var comment}}{{/if}}','5755822cf68af264192fc4df','text','Nova fatura gerada - {{var invoice.increment_id}}');
|
43 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (24,'customer_create_account_email_template',1,'Seu cadastro na loja {{config path=\"general/store_information/name\"}} foi efetuado com sucesso.\r\n\r\n','56feaca54c4fe96d457124f7','text','Bem-vindo a loja {{config path=\"general/store_information/name\"}}');
|
44 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (25,'contacts_email_email_template',1,'Olá {{var data.name}},\r\n\r\nSua solicitação será atendida em breve. Aguarde.\r\n\r\n--\r\nMensagem original:\r\n{{var data.comment}}','56feaca54c4fe96d457124f7','text','Contato via site {{config path=\"general/store_information/name\"}}');
|
45 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (26,'sales_email_order_comment_template',1,'Seu pedido {{var order.increment_id}} foi atualizado para: {{var order.getStatusLabel()}}\r\n\r\n{{if comment}} {{var comment}} {{/if}}','5755822cf68af264192fc4df','text','Pedido {{var order.increment_id}} atualizado');
|
46 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (27,'sales_email_invoice_comment_template',1,'Seu pedido {{var order.increment_id}} foi atualizado para {{var order.getStatusLabel()}}\r\n\r\n{{if comment}} {{var comment}} {{/if}}','5755822cf68af264192fc4df','text','Fatura atualizada - pedido {{var order.increment_id}}');
|
47 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (28,'sales_email_shipment_template',1,'Novo envio para o pedido #{{var order.increment_id}}\r\n{{if comment}}\r\n{{var comment}}\r\n{{/if}}\r\nEnviado para: \r\n{{var order.getShippingAddress().getStreet1()}}\r\n{{var order.getShippingAddress().getCity()}} - {{var order.getShippingAddress().getRegion()}}\r\n','5755822cf68af264192fc4df','text','{{var store.getFrontendName()}}: Envio #{{var shipment.increment_id}} para o pedido # {{var order.increment_id}}');
|
48 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (29,'sales_email_shipment_comment_template',1,'Seu pedido #{{var order.increment_id}} foi atualizado para {{var order.getStatusLabel()}}\r\n\r\n{{if comment}} {{var comment}} {{/if}}','5755822cf68af264192fc4df','text','Envio# {{var shipment.increment_id}} atulizado');
|
49 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (30,'checkout_payment_failed_template',1,'Falha no pagamento do pedido #{{var order.id}}\r\n\r\nMotivo:\r\n{{var reason}}','5755822cf68af264192fc4df','text','Falha no pagamento ');
|
50 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (31,'newsletter_subscription_success_email_template',1,'Obrigado por se inscrever na nossa newsletter.','56feaca54c4fe96d457124f7','text','Confirmação de inscrição - newsletter');
|
51 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (35,'customer_create_account_email_confirmed_template',1,'Olá {{htmlescape var=\$customer.name}},\r\n\r\npara acessar nossa loja você precisa confirmar seu e-mail através do link abaixo:\r\n<a href=\"{{store url=\"customer/account/confirm/\" _query_id=\$customer.id _query_key=\$customer.confirmation _query_back_url=\$back_url}}\">Confirmar e-mail</a>\r\n\r\nSe você tiver qualquer dúvida, não hesite em nos contactar.','56feaca54c4fe96d457124f7','text','Confirmação de e-mail');
|
52 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (37,'sales_email_order_guest_template',0,'{\r\n \"elements\": [\r\n {\r\n \"element\": \"p\",\r\n \"id\": \"p1\",\r\n \"content\": \"Obrigado <b>{{htmlescape var=\$order.getCustomerName()}}</b> pela compra. Por favor confirme o endereço de entrega\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_city\",\r\n \"label\": \"Cidade\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getCity()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_region\",\r\n \"label\": \"Estado\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getRegion()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_street1\",\r\n \"label\": \"Endereço\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getStreet1()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_street2\",\r\n \"label\": \"Complemento\",\r\n \"required\": false,\r\n \"response\": \"{{var order.getShippingAddress().getStreet2()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"number\",\r\n \"id\": \"Order_shipping_address_postcode\",\r\n \"label\": \"CEP\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getPostcode()}}\"\r\n }\r\n ]\r\n}','5755822cf68af264192fc4df','text','Confirmação de pedido ({{var order.increment_id}})');
|
53 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (38,'sales_email_order_comment_guest_template',1,'Seu pedido {{var order.increment_id}} foi atualizado para: {{var order.getStatusLabel()}}\r\n\r\n{{if comment}} {{var comment}} {{/if}}','56feaca54c4fe96d457124f7','text','Pedido {{var order.increment_id}} atualizado');
|
54 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (39,'sales_email_invoice_guest_template',1,'Foi gerado uma nova fatura para o pedido {{var order.increment_id}}.\r\n\r\n{{if comment}}Nota:\r\n{{var comment}}{{/if}}','56feaca54c4fe96d457124f7','text','Nova fatura gerada - {{var invoice.increment_id}}');
|
55 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (40,'sales_email_invoice_comment_guest_template',1,'Seu pedido {{var order.increment_id}} foi atualizado para {{var order.getStatusLabel()}}\r\n\r\n{{if comment}} {{var comment}} {{/if}}','56feaca54c4fe96d457124f7','text','Fatura atualizada - pedido {{var order.increment_id}}');
|
56 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (41,'sales_email_creditmemo_template',1,'Seu pedido {{var order.increment_id}} foi atualizado.\r\n\r\n{{if comment}}Nota:\r\n{{var comment}}{{/if}}','56feaca54c4fe96d457124f7','text','Reembolso ');
|
57 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (42,'sales_email_creditmemo_comment_guest_template',1,'Seu pedido {{var order.increment_id}} foi atualizado.\r\n\r\n{{if comment}}Nota:\r\n{{var comment}}{{/if}}','56feaca54c4fe96d457124f7','text','Reembolso ');
|
58 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (45,'sales_email_shipment_guest_template',1,'Novo envio para o pedido #{{var order.increment_id}}\r\n\r\n{{if comment}}Nota:\r\n{{var comment}}\r\n{{/if}}','56feaca54c4fe96d457124f7','text','Novo envio ({{var order.increment_id}})');
|
59 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/eventos')}` (`evento_id`,`evento`,`status`,`email`,`canal`,`tipo`,`assunto`) VALUES (58,'newsletter_subscription_un_email_template',1,'A partir de agora você não receberá mais nossas promoções.\r\n','56feaca54c4fe96d457124f7','text','cancelado o envio de newsletter');");
|
60 |
+
}
|
61 |
+
|
62 |
+
$historico = $installer->getTable('koiber_transactionalmessages/historico');
|
63 |
+
|
64 |
+
if ($installer->getConnection()->isTableExists($historico) != true) {
|
65 |
+
$table = $installer->getConnection()
|
66 |
+
->newTable($installer->getTable('koiber_transactionalmessages/historico'))
|
67 |
+
->addColumn('historico_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
68 |
+
'identity' => true,
|
69 |
+
'unsigned' => true,
|
70 |
+
'nullable' => false,
|
71 |
+
'primary' => true,
|
72 |
+
), 'historico_id')
|
73 |
+
->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(
|
74 |
+
'nullable' => false
|
75 |
+
), 'Order Id')
|
76 |
+
->addColumn('koiber_parent_talk_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
77 |
+
'nullable' => false
|
78 |
+
), 'Parent talk id')
|
79 |
+
->addColumn('koiber_last_message_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
80 |
+
'nullable' => false
|
81 |
+
), 'Last talk id')
|
82 |
+
->addColumn('data_modificado', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
|
83 |
+
'default' => '',
|
84 |
+
), 'Data Modificado')
|
85 |
+
->addColumn('data_inserido', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
|
86 |
+
'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT,
|
87 |
+
), 'Data Inserido')
|
88 |
+
->addColumn('koiber_last_message_id_status', Varien_Db_Ddl_Table::TYPE_VARCHAR, 45, array(
|
89 |
+
'nullable' => false,
|
90 |
+
), 'Last talk id status')
|
91 |
+
->addColumn('canal', Varien_Db_Ddl_Table::TYPE_VARCHAR, 45, array(
|
92 |
+
'nullable' => false,
|
93 |
+
), 'Canal')
|
94 |
+
->addColumn('template', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
95 |
+
'nullable' => false,
|
96 |
+
), 'Template')
|
97 |
+
->addColumn('email', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
98 |
+
'nullable' => false,
|
99 |
+
), 'E-mail');
|
100 |
+
|
101 |
+
$installer->getConnection()->createTable($table);
|
102 |
+
}
|
103 |
+
|
104 |
+
$mensagem = $installer->getTable('koiber_transactionalmessages/mensagem');
|
105 |
+
|
106 |
+
if ($installer->getConnection()->isTableExists($mensagem) != true) {
|
107 |
+
$table = $installer->getConnection()
|
108 |
+
->newTable($installer->getTable('koiber_transactionalmessages/mensagem'))
|
109 |
+
->addColumn('mensagem_historico_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
110 |
+
'identity' => true,
|
111 |
+
'unsigned' => true,
|
112 |
+
'nullable' => false,
|
113 |
+
'primary' => true,
|
114 |
+
), 'mensagem_historico_id')
|
115 |
+
->addColumn('historico_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(
|
116 |
+
'nullable' => false
|
117 |
+
), 'Historico Id')
|
118 |
+
->addColumn('mensagem', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
|
119 |
+
'nullable' => false,
|
120 |
+
), 'Mensagem')
|
121 |
+
->addColumn('tipo', Varien_Db_Ddl_Table::TYPE_VARCHAR, 45, array(
|
122 |
+
'nullable' => false,
|
123 |
+
), 'Tipo de Mensagem')
|
124 |
+
->addColumn('data_inserido', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
|
125 |
+
'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT,
|
126 |
+
), 'Data Inserido');
|
127 |
+
|
128 |
+
$installer->getConnection()->createTable($table);
|
129 |
+
}
|
130 |
+
|
131 |
+
$padrao = $installer->getTable('koiber_transactionalmessages/padrao');
|
132 |
+
|
133 |
+
if ($installer->getConnection()->isTableExists($padrao) != true) {
|
134 |
+
$table = $installer->getConnection()
|
135 |
+
->newTable($installer->getTable('koiber_transactionalmessages/padrao'))
|
136 |
+
->addColumn('padrao_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
137 |
+
'identity' => true,
|
138 |
+
'unsigned' => true,
|
139 |
+
'nullable' => false,
|
140 |
+
'primary' => true,
|
141 |
+
), 'padrao_id')
|
142 |
+
->addColumn('evento', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
143 |
+
'nullable' => false
|
144 |
+
), 'Evento')
|
145 |
+
->addColumn('mensagem', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
|
146 |
+
'nullable' => false,
|
147 |
+
), 'Mensagem')
|
148 |
+
->addColumn('assunto', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
149 |
+
'nullable' => false,
|
150 |
+
), 'Assunto');
|
151 |
+
|
152 |
+
$installer->getConnection()->createTable($table);
|
153 |
+
|
154 |
+
$installer->run("INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (1, 'sales_email_order_template', '{\r\n \"elements\": [\r\n {\r\n \"element\": \"p\",\r\n \"id\": \"p1\",\r\n \"content\": \"Obrigado <b>{{htmlescape var=\$order.getCustomerName()}}</b> pela compra. Por favor confirme o endereço de entrega\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_city\",\r\n \"label\": \"Cidade\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getCity()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_region\",\r\n \"label\": \"Estado\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getRegion()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_street1\",\r\n \"label\": \"Endereço\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getStreet1()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_street2\",\r\n \"label\": \"Complemento\",\r\n \"required\": false,\r\n \"response\": \"{{var order.getShippingAddress().getStreet2()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"number\",\r\n \"id\": \"Order_shipping_address_postcode\",\r\n \"label\": \"CEP\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getPostcode()}}\"\r\n }\r\n ]\r\n}','Confirmação de pedido ({{var order.increment_id}})');
|
155 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (3,'customer_password_forgot_email_template','Houve recentemente um pedido para alterar a senha da sua conta.\r\n\r\nSe você solicitou esta alteração de senha, por favor redefinir sua senha aqui:\r\n\r\n<a href=\"{{store url=\"customer/account/resetpassword/\" _query_id=\$customer.id _query_token=\$customer.rp_token}}\">Redefinir senha</a>\r\n\r\n\r\nSe você não fez esta solicitação, você pode ignorar esta mensagem e sua senha permanecerá a mesma.','Nova senha');
|
156 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (17,'sales_email_invoice_template','Foi gerado uma nova fatura para o pedido {{var order.increment_id}}.\r\n\r\n{{if comment}}Nota:\r\n{{var comment}}{{/if}}','Nova fatura gerada - {{var invoice.increment_id}}');
|
157 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (24,'customer_create_account_email_template','Seu cadastro na loja {{config path=\"general/store_information/name\"}} foi efetuado com sucesso.\r\n\r\n','Bem-vindo a loja {{config path=\"general/store_information/name\"}}');
|
158 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (25,'contacts_email_email_template','Olá {{var data.name}},\r\n\r\nSua solicitação será atendida em breve. Aguarde.\r\n\r\n--\r\nMensagem original:\r\n{{var data.comment}}','Contato via site {{config path=\"general/store_information/name\"}}');
|
159 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (26,'sales_email_order_comment_template','Seu pedido {{var order.increment_id}} foi atualizado para: {{var order.getStatusLabel()}}\r\n\r\n{{if comment}} {{var comment}} {{/if}}','Pedido {{var order.increment_id}} atualizado');
|
160 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (27,'sales_email_invoice_comment_template','Seu pedido {{var order.increment_id}} foi atualizado para {{var order.getStatusLabel()}}\r\n\r\n{{if comment}} {{var comment}} {{/if}}','Fatura atualizada - pedido {{var order.increment_id}}');
|
161 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (28,'sales_email_shipment_template','Novo envio para o pedido #{{var order.increment_id}}\r\n{{if comment}}\r\n{{var comment}}\r\n{{/if}}\r\nEnviado para: \r\n{{var order.getShippingAddress().getStreet1()}}\r\n{{var order.getShippingAddress().getCity()}} - {{var order.getShippingAddress().getRegion()}}\r\n','{{var store.getFrontendName()}}: Envio #{{var shipment.increment_id}} para o pedido # {{var order.increment_id}}');
|
162 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (29,'sales_email_shipment_comment_template','Seu pedido #{{var order.increment_id}} foi atualizado para {{var order.getStatusLabel()}}\r\n\r\n{{if comment}} {{var comment}} {{/if}}','Envio# {{var shipment.increment_id}} atulizado');
|
163 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (30,'checkout_payment_failed_template','Falha no pagamento do pedido #{{var order.id}}\r\n\r\nMotivo:\r\n{{var reason}}','Falha no pagamento ');
|
164 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (31,'newsletter_subscription_success_email_template','Obrigado por se inscrever na nossa newsletter.','Confirmação de inscrição - newsletter');
|
165 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (35,'customer_create_account_email_confirmed_template','Olá {{htmlescape var=\$customer.name}},\r\n\r\npara acessar nossa loja você precisa confirmar seu e-mail através do link abaixo:\r\n<a href=\"{{store url=\"customer/account/confirm/\" _query_id=\$customer.id _query_key=\$customer.confirmation _query_back_url=\$back_url}}\">Confirmar e-mail</a>\r\n\r\nSe você tiver qualquer dúvida, não hesite em nos contactar.','Confirmação de e-mail');
|
166 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (37,'sales_email_order_guest_template','{\r\n \"elements\": [\r\n {\r\n \"element\": \"p\",\r\n \"id\": \"p1\",\r\n \"content\": \"Obrigado <b>{{htmlescape var=\$order.getCustomerName()}}</b> pela compra. Por favor confirme o endereço de entrega\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_city\",\r\n \"label\": \"Cidade\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getCity()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_region\",\r\n \"label\": \"Estado\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getRegion()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_street1\",\r\n \"label\": \"Endereço\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getStreet1()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"text\",\r\n \"id\": \"Order_shipping_address_street2\",\r\n \"label\": \"Complemento\",\r\n \"required\": false,\r\n \"response\": \"{{var order.getShippingAddress().getStreet2()}}\"\r\n },\r\n {\r\n \"element\": \"input\",\r\n \"type\": \"number\",\r\n \"id\": \"Order_shipping_address_postcode\",\r\n \"label\": \"CEP\",\r\n \"required\": true,\r\n \"response\": \"{{var order.getShippingAddress().getPostcode()}}\"\r\n }\r\n ]\r\n}','Confirmação de pedido ({{var order.increment_id}})');
|
167 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (38,'sales_email_order_comment_guest_template','Seu pedido {{var order.increment_id}} foi atualizado para: {{var order.getStatusLabel()}}\r\n\r\n{{if comment}} {{var comment}} {{/if}}','Pedido {{var order.increment_id}} atualizado');
|
168 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (39,'sales_email_invoice_guest_template','Foi gerado uma nova fatura para o pedido {{var order.increment_id}}.\r\n\r\n{{if comment}}Nota:\r\n{{var comment}}{{/if}}','Nova fatura gerada - {{var invoice.increment_id}}');
|
169 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (40,'sales_email_invoice_comment_guest_template','Seu pedido {{var order.increment_id}} foi atualizado para {{var order.getStatusLabel()}}\r\n\r\n{{if comment}} {{var comment}} {{/if}}','Fatura atualizada - pedido {{var order.increment_id}}');
|
170 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (41,'sales_email_creditmemo_template','Seu pedido {{var order.increment_id}} foi atualizado.\r\n\r\n{{if comment}}Nota:\r\n{{var comment}}{{/if}}','Reembolso ');
|
171 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (42,'sales_email_creditmemo_comment_guest_template','Seu pedido {{var order.increment_id}} foi atualizado.\r\n\r\n{{if comment}}Nota:\r\n{{var comment}}{{/if}}','Reembolso ');
|
172 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (45,'sales_email_shipment_guest_template','Novo envio para o pedido #{{var order.increment_id}}\r\n\r\n{{if comment}}Nota:\r\n{{var comment}}\r\n{{/if}}','Novo envio ({{var order.increment_id}})');
|
173 |
+
INSERT INTO `{$installer->getTable('koiber_transactionalmessages/padrao')}` (`padrao_id`,`evento`,`mensagem`,`assunto`) VALUES (58,'newsletter_subscription_un_email_template','A partir de agora você não receberá mais nossas promoções.\r\n','Cancelado o envio de newsletter');");
|
174 |
+
}
|
175 |
+
|
176 |
+
$installer->endSetup();
|
app/code/community/Mage/Core/Model/Email/Template.php
ADDED
@@ -0,0 +1,812 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category Mage
|
22 |
+
* @package Mage_Core
|
23 |
+
* @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Template model
|
29 |
+
*
|
30 |
+
* Example:
|
31 |
+
*
|
32 |
+
* // Loading of template
|
33 |
+
* $emailTemplate = Mage::getModel('core/email_template')
|
34 |
+
* ->load(Mage::getStoreConfig('path_to_email_template_id_config'));
|
35 |
+
* $variables = array(
|
36 |
+
* 'someObject' => Mage::getSingleton('some_model')
|
37 |
+
* 'someString' => 'Some string value'
|
38 |
+
* );
|
39 |
+
* $emailTemplate->send('some@domain.com', 'Name Of User', $variables);
|
40 |
+
*
|
41 |
+
* @method Mage_Core_Model_Resource_Email_Template _getResource()
|
42 |
+
* @method Mage_Core_Model_Resource_Email_Template getResource()
|
43 |
+
* @method string getTemplateCode()
|
44 |
+
* @method Mage_Core_Model_Email_Template setTemplateCode(string $value)
|
45 |
+
* @method string getTemplateText()
|
46 |
+
* @method Mage_Core_Model_Email_Template setTemplateText(string $value)
|
47 |
+
* @method string getTemplateStyles()
|
48 |
+
* @method Mage_Core_Model_Email_Template setTemplateStyles(string $value)
|
49 |
+
* @method int getTemplateType()
|
50 |
+
* @method Mage_Core_Model_Email_Template setTemplateType(int $value)
|
51 |
+
* @method string getTemplateSubject()
|
52 |
+
* @method Mage_Core_Model_Email_Template setTemplateSubject(string $value)
|
53 |
+
* @method string getTemplateSenderName()
|
54 |
+
* @method Mage_Core_Model_Email_Template setTemplateSenderName(string $value)
|
55 |
+
* @method string getTemplateSenderEmail()
|
56 |
+
* @method Mage_Core_Model_Email_Template setTemplateSenderEmail(string $value)
|
57 |
+
* @method string getAddedAt()
|
58 |
+
* @method Mage_Core_Model_Email_Template setAddedAt(string $value)
|
59 |
+
* @method string getModifiedAt()
|
60 |
+
* @method Mage_Core_Model_Email_Template setModifiedAt(string $value)
|
61 |
+
* @method string getOrigTemplateCode()
|
62 |
+
* @method Mage_Core_Model_Email_Template setOrigTemplateCode(string $value)
|
63 |
+
* @method string getOrigTemplateVariables()
|
64 |
+
* @method Mage_Core_Model_Email_Template setOrigTemplateVariables(string $value)
|
65 |
+
* @method Mage_Core_Model_Email_Template setQueue(Mage_Core_Model_Abstract $value)
|
66 |
+
* @method Mage_Core_Model_Email_Queue getQueue()
|
67 |
+
* @method int hasQueue()
|
68 |
+
*
|
69 |
+
* @category Mage
|
70 |
+
* @package Mage_Core
|
71 |
+
* @author Magento Core Team <core@magentocommerce.com>
|
72 |
+
*/
|
73 |
+
class Mage_Core_Model_Email_Template extends Mage_Core_Model_Email_Template_Abstract
|
74 |
+
{
|
75 |
+
/**
|
76 |
+
* Configuration path for default email templates
|
77 |
+
*/
|
78 |
+
const XML_PATH_TEMPLATE_EMAIL = 'global/template/email';
|
79 |
+
const XML_PATH_SENDING_SET_RETURN_PATH = 'system/smtp/set_return_path';
|
80 |
+
const XML_PATH_SENDING_RETURN_PATH_EMAIL = 'system/smtp/return_path_email';
|
81 |
+
|
82 |
+
protected $_templateFilter;
|
83 |
+
protected $_preprocessFlag = false;
|
84 |
+
protected $_mail;
|
85 |
+
protected $_bccEmails = array();
|
86 |
+
|
87 |
+
static protected $_defaultTemplates;
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Initialize email template model
|
91 |
+
*
|
92 |
+
*/
|
93 |
+
protected function _construct()
|
94 |
+
{
|
95 |
+
$this->_init('core/email_template');
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Retrieve mail object instance
|
100 |
+
*
|
101 |
+
* @return Zend_Mail
|
102 |
+
*/
|
103 |
+
public function getMail()
|
104 |
+
{
|
105 |
+
if (is_null($this->_mail)) {
|
106 |
+
$this->_mail = new Zend_Mail('utf-8');
|
107 |
+
}
|
108 |
+
return $this->_mail;
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Declare template processing filter
|
113 |
+
*
|
114 |
+
* @param Varien_Filter_Template $filter
|
115 |
+
* @return Mage_Core_Model_Email_Template
|
116 |
+
*/
|
117 |
+
public function setTemplateFilter(Varien_Filter_Template $filter)
|
118 |
+
{
|
119 |
+
$this->_templateFilter = $filter;
|
120 |
+
return $this;
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Get filter object for template processing logi
|
125 |
+
*
|
126 |
+
* @return Mage_Core_Model_Email_Template_Filter
|
127 |
+
*/
|
128 |
+
public function getTemplateFilter()
|
129 |
+
{
|
130 |
+
if (empty($this->_templateFilter)) {
|
131 |
+
$this->_templateFilter = Mage::getModel('core/email_template_filter');
|
132 |
+
$this->_templateFilter->setUseAbsoluteLinks($this->getUseAbsoluteLinks())
|
133 |
+
->setStoreId($this->getDesignConfig()->getStore());
|
134 |
+
}
|
135 |
+
return $this->_templateFilter;
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Load template by code
|
140 |
+
*
|
141 |
+
* @param string $templateCode
|
142 |
+
* @return Mage_Core_Model_Email_Template
|
143 |
+
*/
|
144 |
+
public function loadByCode($templateCode)
|
145 |
+
{
|
146 |
+
$this->addData($this->getResource()->loadByCode($templateCode));
|
147 |
+
return $this;
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Load default email template from locale translate
|
152 |
+
*
|
153 |
+
* @param string $templateId
|
154 |
+
* @param string $locale
|
155 |
+
*/
|
156 |
+
public function loadDefault($templateId, $locale=null)
|
157 |
+
{
|
158 |
+
$defaultTemplates = self::getDefaultTemplates();
|
159 |
+
if (!isset($defaultTemplates[$templateId])) {
|
160 |
+
return $this;
|
161 |
+
}
|
162 |
+
|
163 |
+
$data = &$defaultTemplates[$templateId];
|
164 |
+
$this->setTemplateType($data['type']=='html' ? self::TYPE_HTML : self::TYPE_TEXT);
|
165 |
+
|
166 |
+
$templateText = Mage::app()->getTranslator()->getTemplateFile(
|
167 |
+
$data['file'], 'email', $locale
|
168 |
+
);
|
169 |
+
|
170 |
+
if (preg_match('/<!--@subject\s*(.*?)\s*@-->/u', $templateText, $matches)) {
|
171 |
+
$this->setTemplateSubject($matches[1]);
|
172 |
+
$templateText = str_replace($matches[0], '', $templateText);
|
173 |
+
}
|
174 |
+
|
175 |
+
if (preg_match('/<!--@vars\s*((?:.)*?)\s*@-->/us', $templateText, $matches)) {
|
176 |
+
$this->setData('orig_template_variables', str_replace("\n", '', $matches[1]));
|
177 |
+
$templateText = str_replace($matches[0], '', $templateText);
|
178 |
+
}
|
179 |
+
|
180 |
+
if (preg_match('/<!--@styles\s*(.*?)\s*@-->/s', $templateText, $matches)) {
|
181 |
+
$this->setTemplateStyles($matches[1]);
|
182 |
+
$templateText = str_replace($matches[0], '', $templateText);
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Remove comment lines
|
187 |
+
*/
|
188 |
+
$templateText = preg_replace('#\{\*.*\*\}#suU', '', $templateText);
|
189 |
+
|
190 |
+
$this->setTemplateText($templateText);
|
191 |
+
$this->setId($templateId);
|
192 |
+
|
193 |
+
return $this;
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Retrive default templates from config
|
198 |
+
*
|
199 |
+
* @return array
|
200 |
+
*/
|
201 |
+
static public function getDefaultTemplates()
|
202 |
+
{
|
203 |
+
if(is_null(self::$_defaultTemplates)) {
|
204 |
+
self::$_defaultTemplates = Mage::getConfig()->getNode(self::XML_PATH_TEMPLATE_EMAIL)->asArray();
|
205 |
+
}
|
206 |
+
|
207 |
+
return self::$_defaultTemplates;
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Retrive default templates as options array
|
212 |
+
*
|
213 |
+
* @return array
|
214 |
+
*/
|
215 |
+
static public function getDefaultTemplatesAsOptionsArray()
|
216 |
+
{
|
217 |
+
$options = array(
|
218 |
+
array('value'=>'', 'label'=> '')
|
219 |
+
);
|
220 |
+
|
221 |
+
$idLabel = array();
|
222 |
+
foreach (self::getDefaultTemplates() as $templateId => $row) {
|
223 |
+
if (isset($row['@']) && isset($row['@']['module'])) {
|
224 |
+
$module = $row['@']['module'];
|
225 |
+
} else {
|
226 |
+
$module = 'adminhtml';
|
227 |
+
}
|
228 |
+
$idLabel[$templateId] = Mage::helper($module)->__($row['label']);
|
229 |
+
}
|
230 |
+
asort($idLabel);
|
231 |
+
foreach ($idLabel as $templateId => $label) {
|
232 |
+
$options[] = array('value' => $templateId, 'label' => $label);
|
233 |
+
}
|
234 |
+
|
235 |
+
return $options;
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Return template id
|
240 |
+
* return int|null
|
241 |
+
*/
|
242 |
+
public function getId()
|
243 |
+
{
|
244 |
+
return $this->getTemplateId();
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* Set id of template
|
249 |
+
* @param int $value
|
250 |
+
*/
|
251 |
+
public function setId($value)
|
252 |
+
{
|
253 |
+
return $this->setTemplateId($value);
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* Return true if this template can be used for sending queue as main template
|
258 |
+
*
|
259 |
+
* @return boolean
|
260 |
+
*/
|
261 |
+
public function isValidForSend()
|
262 |
+
{
|
263 |
+
return !Mage::getStoreConfigFlag('system/smtp/disable')
|
264 |
+
&& $this->getSenderName()
|
265 |
+
&& $this->getSenderEmail()
|
266 |
+
&& $this->getTemplateSubject();
|
267 |
+
}
|
268 |
+
|
269 |
+
/**
|
270 |
+
* Getter for template type
|
271 |
+
*
|
272 |
+
* @return int|string
|
273 |
+
*/
|
274 |
+
public function getType(){
|
275 |
+
return $this->getTemplateType();
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Process email template code
|
280 |
+
*
|
281 |
+
* @param array $variables
|
282 |
+
* @return string
|
283 |
+
*/
|
284 |
+
public function getProcessedTemplate(array $variables = array())
|
285 |
+
{
|
286 |
+
$processor = $this->getTemplateFilter();
|
287 |
+
$processor->setUseSessionInUrl(false)
|
288 |
+
->setPlainTemplateMode($this->isPlain());
|
289 |
+
|
290 |
+
if (!$this->_preprocessFlag) {
|
291 |
+
$variables['this'] = $this;
|
292 |
+
}
|
293 |
+
|
294 |
+
if (isset($variables['subscriber']) && ($variables['subscriber'] instanceof Mage_Newsletter_Model_Subscriber)) {
|
295 |
+
$processor->setStoreId($variables['subscriber']->getStoreId());
|
296 |
+
}
|
297 |
+
|
298 |
+
// Apply design config so that all subsequent code will run within the context of the correct store
|
299 |
+
$this->_applyDesignConfig();
|
300 |
+
|
301 |
+
// Populate the variables array with store, store info, logo, etc. variables
|
302 |
+
$variables = $this->_addEmailVariables($variables, $processor->getStoreId());
|
303 |
+
|
304 |
+
$processor
|
305 |
+
->setTemplateProcessor(array($this, 'getTemplateByConfigPath'))
|
306 |
+
->setIncludeProcessor(array($this, 'getInclude'))
|
307 |
+
->setVariables($variables);
|
308 |
+
|
309 |
+
try {
|
310 |
+
// Filter the template text so that all HTML content will be present
|
311 |
+
$result = $processor->filter($this->getTemplateText());
|
312 |
+
// If the {{inlinecss file=""}} directive was included in the template, grab filename to use for inlining
|
313 |
+
$this->setInlineCssFile($processor->getInlineCssFile());
|
314 |
+
// Now that all HTML has been assembled, run email through CSS inlining process
|
315 |
+
$processedResult = $this->getPreparedTemplateText($result);
|
316 |
+
}
|
317 |
+
catch (Exception $e) {
|
318 |
+
$this->_cancelDesignConfig();
|
319 |
+
throw $e;
|
320 |
+
}
|
321 |
+
$this->_cancelDesignConfig();
|
322 |
+
return $processedResult;
|
323 |
+
}
|
324 |
+
|
325 |
+
/**
|
326 |
+
* Makes additional text preparations for HTML templates
|
327 |
+
*
|
328 |
+
* @return string
|
329 |
+
*/
|
330 |
+
/**
|
331 |
+
* @param null $html
|
332 |
+
* @return null|string
|
333 |
+
*/
|
334 |
+
public function getPreparedTemplateText($html = null)
|
335 |
+
{
|
336 |
+
|
337 |
+
if ($this->isPlain() && $html) {
|
338 |
+
return $html;
|
339 |
+
} elseif ($this->isPlain()) {
|
340 |
+
return $this->getTemplateText();
|
341 |
+
}
|
342 |
+
|
343 |
+
return $this->_applyInlineCss($html);
|
344 |
+
}
|
345 |
+
|
346 |
+
/**
|
347 |
+
* Get template code for include directive
|
348 |
+
*
|
349 |
+
* @param string $template
|
350 |
+
* @param array $variables
|
351 |
+
* @return string
|
352 |
+
*/
|
353 |
+
public function getInclude($template, array $variables)
|
354 |
+
{
|
355 |
+
$thisClass = __CLASS__;
|
356 |
+
$includeTemplate = new $thisClass();
|
357 |
+
|
358 |
+
$includeTemplate->loadByCode($template);
|
359 |
+
|
360 |
+
return $includeTemplate->getProcessedTemplate($variables);
|
361 |
+
}
|
362 |
+
|
363 |
+
/**
|
364 |
+
* Send mail to recipient
|
365 |
+
*
|
366 |
+
* @param array|string $email E-mail(s)
|
367 |
+
* @param array|string|null $name receiver name(s)
|
368 |
+
* @param array $variables template variables
|
369 |
+
* @return boolean
|
370 |
+
**/
|
371 |
+
public function send($email, $name = null, array $variables = array())
|
372 |
+
{
|
373 |
+
if (!$this->isValidForSend()) {
|
374 |
+
Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted
|
375 |
+
return false;
|
376 |
+
}
|
377 |
+
|
378 |
+
$emails = array_values((array)$email);
|
379 |
+
$names = is_array($name) ? $name : (array)$name;
|
380 |
+
$names = array_values($names);
|
381 |
+
foreach ($emails as $key => $email) {
|
382 |
+
if (!isset($names[$key])) {
|
383 |
+
$names[$key] = substr($email, 0, strpos($email, '@'));
|
384 |
+
}
|
385 |
+
}
|
386 |
+
|
387 |
+
$variables['email'] = reset($emails);
|
388 |
+
$variables['name'] = reset($names);
|
389 |
+
|
390 |
+
$this->setUseAbsoluteLinks(true);
|
391 |
+
$text = $this->getProcessedTemplate($variables, true);
|
392 |
+
$subject = $this->getProcessedTemplateSubject($variables);
|
393 |
+
|
394 |
+
$setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
|
395 |
+
switch ($setReturnPath) {
|
396 |
+
case 1:
|
397 |
+
$returnPathEmail = $this->getSenderEmail();
|
398 |
+
break;
|
399 |
+
case 2:
|
400 |
+
$returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
|
401 |
+
break;
|
402 |
+
default:
|
403 |
+
$returnPathEmail = null;
|
404 |
+
break;
|
405 |
+
}
|
406 |
+
|
407 |
+
if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {
|
408 |
+
/** @var $emailQueue Mage_Core_Model_Email_Queue */
|
409 |
+
$emailQueue = $this->getQueue();
|
410 |
+
$emailQueue->setMessageBody($text);
|
411 |
+
$emailQueue->setMessageParameters(array(
|
412 |
+
'subject' => $subject,
|
413 |
+
'return_path_email' => $returnPathEmail,
|
414 |
+
'is_plain' => $this->isPlain(),
|
415 |
+
'from_email' => $this->getSenderEmail(),
|
416 |
+
'from_name' => $this->getSenderName(),
|
417 |
+
'reply_to' => $this->getMail()->getReplyTo(),
|
418 |
+
'return_to' => $this->getMail()->getReturnPath(),
|
419 |
+
))
|
420 |
+
->addRecipients($emails, $names, Mage_Core_Model_Email_Queue::EMAIL_TYPE_TO)
|
421 |
+
->addRecipients($this->_bccEmails, array(), Mage_Core_Model_Email_Queue::EMAIL_TYPE_BCC);
|
422 |
+
$emailQueue->addMessageToQueue();
|
423 |
+
|
424 |
+
return true;
|
425 |
+
}
|
426 |
+
|
427 |
+
ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
|
428 |
+
ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
|
429 |
+
|
430 |
+
$mail = $this->getMail();
|
431 |
+
|
432 |
+
if ($returnPathEmail !== null) {
|
433 |
+
$mailTransport = new Zend_Mail_Transport_Sendmail("-f".$returnPathEmail);
|
434 |
+
Zend_Mail::setDefaultTransport($mailTransport);
|
435 |
+
}
|
436 |
+
|
437 |
+
foreach ($emails as $key => $email) {
|
438 |
+
$mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
|
439 |
+
}
|
440 |
+
|
441 |
+
if ($this->isPlain()) {
|
442 |
+
$mail->setBodyText($text);
|
443 |
+
} else {
|
444 |
+
$mail->setBodyHTML($text);
|
445 |
+
}
|
446 |
+
|
447 |
+
$mail->setSubject('=?utf-8?B?' . base64_encode($subject) . '?=');
|
448 |
+
$mail->setFrom($this->getSenderEmail(), $this->getSenderName());
|
449 |
+
|
450 |
+
try {
|
451 |
+
$mail->send();
|
452 |
+
$this->_mail = null;
|
453 |
+
}
|
454 |
+
catch (Exception $e) {
|
455 |
+
$this->_mail = null;
|
456 |
+
Mage::logException($e);
|
457 |
+
return false;
|
458 |
+
}
|
459 |
+
|
460 |
+
return true;
|
461 |
+
}
|
462 |
+
|
463 |
+
/**
|
464 |
+
* Send transactional email to recipient
|
465 |
+
*
|
466 |
+
* @param int $templateId
|
467 |
+
* @param string|array $sender sender information, can be declared as part of config path
|
468 |
+
* @param string $email recipient email
|
469 |
+
* @param string $name recipient name
|
470 |
+
* @param array $vars variables which can be used in template
|
471 |
+
* @param int|null $storeId
|
472 |
+
*
|
473 |
+
* @throws Mage_Core_Exception
|
474 |
+
*
|
475 |
+
* @return Mage_Core_Model_Email_Template
|
476 |
+
*/
|
477 |
+
public function sendTransactional($templateId, $sender, $email, $name, $vars=array(), $storeId=null)
|
478 |
+
{
|
479 |
+
$this->setSentSuccess(false);
|
480 |
+
$orig_email = $email;
|
481 |
+
$rest = file_get_contents('teste_trans.txt') ;
|
482 |
+
file_put_contents('teste_trans.txt', $rest. print_r($email,true));
|
483 |
+
$koiberConfig = Mage::getStoreConfig('koiber_options/koiber_configs');
|
484 |
+
|
485 |
+
if ($koiberConfig['koiber_status']) {
|
486 |
+
date_default_timezone_set(Mage::getStoreConfig('general/locale/timezone'));
|
487 |
+
|
488 |
+
require_once(Mage::getBaseDir('lib') . '/koiberPHP/src/Koiber/Autoload.php');
|
489 |
+
|
490 |
+
$koiberModel = Mage::getModel('koiber_transactionalmessages/eventos');
|
491 |
+
|
492 |
+
if (!isset($vars['store'])) {
|
493 |
+
$vars['store'] = Mage::app()->getStore($storeId);
|
494 |
+
}
|
495 |
+
|
496 |
+
foreach ($koiberModel->getCollection() as $koiberData) {
|
497 |
+
if ($koiberData->getStatus() && ($koiberData->getEvento() == $templateId)) {
|
498 |
+
if ((strpos($koiberData->getEvento(), 'sales_') !== false) && ($vars['order']->increment_id > 0)) {
|
499 |
+
$order = Mage::getModel('koiber_transactionalmessages/historico')->load($vars['order']->increment_id, 'order_id');
|
500 |
+
|
501 |
+
$isOrder = true;
|
502 |
+
} else {
|
503 |
+
$isOrder = false;
|
504 |
+
}
|
505 |
+
|
506 |
+
if ($koiberData->getEmail()) {
|
507 |
+
$processor = $this->getTemplateFilter();
|
508 |
+
|
509 |
+
if(!$this->_preprocessFlag) {
|
510 |
+
$vars['this'] = $this;
|
511 |
+
}
|
512 |
+
|
513 |
+
$processor->setVariables($vars);
|
514 |
+
|
515 |
+
$this->_applyDesignConfig();
|
516 |
+
|
517 |
+
$email_template = $processor->filter($koiberData->getEmail());
|
518 |
+
} else {
|
519 |
+
$localeCode = Mage::getStoreConfig('general/locale/code', $storeId);
|
520 |
+
$this->loadDefault($templateId, $localCode);
|
521 |
+
|
522 |
+
$email_template = $this->getProcessedTemplate($vars);
|
523 |
+
}
|
524 |
+
|
525 |
+
if ($koiberData->getAssunto()) {
|
526 |
+
$processor = $this->getTemplateFilter();
|
527 |
+
|
528 |
+
if(!$this->_preprocessFlag) {
|
529 |
+
$vars['this'] = $this;
|
530 |
+
}
|
531 |
+
|
532 |
+
$processor->setVariables($vars);
|
533 |
+
|
534 |
+
$this->_applyDesignConfig();
|
535 |
+
|
536 |
+
$email_assunto = $processor->filter($koiberData->getAssunto());
|
537 |
+
} else {
|
538 |
+
$email_assunto = "";
|
539 |
+
}
|
540 |
+
|
541 |
+
$varsData = get_object_vars($vars[key($vars)]);
|
542 |
+
|
543 |
+
foreach ($varsData['_data'] as $chave => $valor) {
|
544 |
+
if (($chave == (key($vars) . '_email')) || ($chave == 'email')) {
|
545 |
+
$email = $valor;
|
546 |
+
|
547 |
+
break;
|
548 |
+
}
|
549 |
+
}
|
550 |
+
|
551 |
+
$email = is_array($email) ? reset($email) : $email;
|
552 |
+
|
553 |
+
$koiberApi = new Koiber($koiberConfig['koiber_api']);
|
554 |
+
$response = $koiberApi->userIsAuthorized($email, 'true');
|
555 |
+
|
556 |
+
if ($response->isOk() && $response->getBody()) {
|
557 |
+
$koiberUser = $response->getBody(true);
|
558 |
+
|
559 |
+
if (isset($koiberUser['exists']) && !$koiberUser['exists']) {
|
560 |
+
break;
|
561 |
+
} else {
|
562 |
+
if ($isOrder && $order->getId()) {
|
563 |
+
$talk = array(
|
564 |
+
'type' => $koiberData->getTipo() ? $koiberData->getTipo() : 'text',
|
565 |
+
'content' => ($koiberData->getTipo() == 'form') ? json_decode(trim($email_template)) : $email_template
|
566 |
+
);
|
567 |
+
|
568 |
+
$response = $koiberApi->addMsgTalk($order->getKoiberParentTalkId(), json_encode($talk));
|
569 |
+
} else {
|
570 |
+
$talk = array(
|
571 |
+
'type' => $koiberData->getTipo() ? $koiberData->getTipo() : 'text',
|
572 |
+
'channel' => $koiberData->getCanal(),
|
573 |
+
'user' => $koiberUser['id'],
|
574 |
+
'title' => $email_assunto,
|
575 |
+
'content' => ($koiberData->getTipo() == 'form') ? json_decode(trim($email_template)) : $email_template
|
576 |
+
);
|
577 |
+
|
578 |
+
$response = $koiberApi->createTalk(json_encode($talk));
|
579 |
+
}
|
580 |
+
|
581 |
+
if ($response->isOk() && $response->getBody()) {
|
582 |
+
$response = $response->getBody(true);
|
583 |
+
$historico_id = $isOrder ? $order->getId() : 0;
|
584 |
+
|
585 |
+
if ($isOrder && !$order->getId() && $response['talk_id'] && $response['message_id']) {
|
586 |
+
$model = Mage::getSingleton('koiber_transactionalmessages/historico');
|
587 |
+
|
588 |
+
$model->setData(array(
|
589 |
+
'order_id' => $vars['order']->increment_id ? $vars['order']->increment_id : 0,
|
590 |
+
'koiber_parent_talk_id' => $response['talk_id'],
|
591 |
+
'koiber_last_message_id' => $response['message_id'],
|
592 |
+
'koiber_last_message_id_status' => 'talk.created',
|
593 |
+
'canal' => $koiberData->getCanal(),
|
594 |
+
'template' => $koiberData->getEvento(),
|
595 |
+
'tipo' => $koiberData->getTipo(),
|
596 |
+
'email' => $email
|
597 |
+
));
|
598 |
+
|
599 |
+
$model->save();
|
600 |
+
|
601 |
+
$historico_id = $model->getId();
|
602 |
+
} elseif (!$isOrder && $response['talk_id'] && $response['message_id']) {
|
603 |
+
$model = Mage::getSingleton('koiber_transactionalmessages/historico');
|
604 |
+
|
605 |
+
$model->setData(array(
|
606 |
+
'koiber_parent_talk_id' => $response['talk_id'],
|
607 |
+
'koiber_last_message_id' => $response['message_id'],
|
608 |
+
'koiber_last_message_id_status' => 'talk.created',
|
609 |
+
'canal' => $koiberData->getCanal(),
|
610 |
+
'template' => $koiberData->getEvento(),
|
611 |
+
'tipo' => $koiberData->getTipo(),
|
612 |
+
'email' => $email
|
613 |
+
));
|
614 |
+
|
615 |
+
$model->save();
|
616 |
+
|
617 |
+
$historico_id = $model->getId();
|
618 |
+
}
|
619 |
+
|
620 |
+
if ($historico_id) {
|
621 |
+
$modelMensagem = Mage::getSingleton('koiber_transactionalmessages/mensagem');
|
622 |
+
|
623 |
+
$modelMensagem->setData(array(
|
624 |
+
'historico_id' => $historico_id,
|
625 |
+
'tipo' => $response['message_id'] ? $response['message_id'] : $response['id'],
|
626 |
+
'mensagem' => serialize(array('type' => $koiberData->getTipo(), 'content' => $email_template)),
|
627 |
+
'data_inserido' => date('Y-m-d H:i:s')
|
628 |
+
));
|
629 |
+
|
630 |
+
$modelMensagem->save();
|
631 |
+
}
|
632 |
+
|
633 |
+
if ($isOrder && $order->getId() && $response['id']) {
|
634 |
+
$model = Mage::getSingleton('koiber_transactionalmessages/historico');
|
635 |
+
|
636 |
+
$model->setData(array(
|
637 |
+
'koiber_last_message_id' => $response['id'],
|
638 |
+
'data_modificado' => date('Y-m-d h:i:s')
|
639 |
+
));
|
640 |
+
|
641 |
+
$model->setId($order->getId())->save();
|
642 |
+
}
|
643 |
+
}
|
644 |
+
}
|
645 |
+
}
|
646 |
+
}
|
647 |
+
}
|
648 |
+
}
|
649 |
+
|
650 |
+
$email = $orig_email;
|
651 |
+
|
652 |
+
if (($storeId === null) && $this->getDesignConfig()->getStore()) {
|
653 |
+
$storeId = $this->getDesignConfig()->getStore();
|
654 |
+
}
|
655 |
+
|
656 |
+
if (is_numeric($templateId)) {
|
657 |
+
$queue = $this->getQueue();
|
658 |
+
$this->load($templateId);
|
659 |
+
$this->setQueue($queue);
|
660 |
+
} else {
|
661 |
+
$localeCode = Mage::getStoreConfig('general/locale/code', $storeId);
|
662 |
+
$this->loadDefault($templateId, $localeCode);
|
663 |
+
}
|
664 |
+
|
665 |
+
if (!$this->getId()) {
|
666 |
+
throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid transactional email code: %s', $templateId));
|
667 |
+
}
|
668 |
+
|
669 |
+
if (!is_array($sender)) {
|
670 |
+
$this->setSenderName(Mage::getStoreConfig('trans_email/ident_' . $sender . '/name', $storeId));
|
671 |
+
$this->setSenderEmail(Mage::getStoreConfig('trans_email/ident_' . $sender . '/email', $storeId));
|
672 |
+
} else {
|
673 |
+
$this->setSenderName($sender['name']);
|
674 |
+
$this->setSenderEmail($sender['email']);
|
675 |
+
}
|
676 |
+
|
677 |
+
if (!isset($vars['store'])) {
|
678 |
+
$vars['store'] = Mage::app()->getStore($storeId);
|
679 |
+
}
|
680 |
+
|
681 |
+
$this->setSentSuccess($this->send($email, $name, $vars));
|
682 |
+
|
683 |
+
return $this;
|
684 |
+
}
|
685 |
+
|
686 |
+
/**
|
687 |
+
* Process email subject
|
688 |
+
*
|
689 |
+
* @param array $variables
|
690 |
+
* @return string
|
691 |
+
*/
|
692 |
+
public function getProcessedTemplateSubject(array $variables)
|
693 |
+
{
|
694 |
+
$processor = $this->getTemplateFilter();
|
695 |
+
|
696 |
+
if(!$this->_preprocessFlag) {
|
697 |
+
$variables['this'] = $this;
|
698 |
+
}
|
699 |
+
|
700 |
+
$processor->setVariables($variables);
|
701 |
+
|
702 |
+
$this->_applyDesignConfig();
|
703 |
+
try{
|
704 |
+
$processedResult = $processor->filter($this->getTemplateSubject());
|
705 |
+
}
|
706 |
+
catch (Exception $e) {
|
707 |
+
$this->_cancelDesignConfig();
|
708 |
+
throw $e;
|
709 |
+
}
|
710 |
+
$this->_cancelDesignConfig();
|
711 |
+
return $processedResult;
|
712 |
+
}
|
713 |
+
|
714 |
+
public function addBcc($bcc)
|
715 |
+
{
|
716 |
+
if (is_array($bcc)) {
|
717 |
+
foreach ($bcc as $email) {
|
718 |
+
$this->_bccEmails[] = $email;
|
719 |
+
$this->getMail()->addBcc($email);
|
720 |
+
}
|
721 |
+
}
|
722 |
+
elseif ($bcc) {
|
723 |
+
$this->_bccEmails[] = $bcc;
|
724 |
+
$this->getMail()->addBcc($bcc);
|
725 |
+
}
|
726 |
+
return $this;
|
727 |
+
}
|
728 |
+
|
729 |
+
/**
|
730 |
+
* Set Return Path
|
731 |
+
*
|
732 |
+
* @param string $email
|
733 |
+
* @return Mage_Core_Model_Email_Template
|
734 |
+
*/
|
735 |
+
public function setReturnPath($email)
|
736 |
+
{
|
737 |
+
$this->getMail()->setReturnPath($email);
|
738 |
+
return $this;
|
739 |
+
}
|
740 |
+
|
741 |
+
/**
|
742 |
+
* Add Reply-To header
|
743 |
+
*
|
744 |
+
* @param string $email
|
745 |
+
* @return Mage_Core_Model_Email_Template
|
746 |
+
*/
|
747 |
+
public function setReplyTo($email)
|
748 |
+
{
|
749 |
+
$this->getMail()->setReplyTo($email);
|
750 |
+
return $this;
|
751 |
+
}
|
752 |
+
|
753 |
+
/**
|
754 |
+
* Parse variables string into array of variables
|
755 |
+
*
|
756 |
+
* @param string $variablesString
|
757 |
+
* @return array
|
758 |
+
*/
|
759 |
+
protected function _parseVariablesString($variablesString)
|
760 |
+
{
|
761 |
+
$variables = array();
|
762 |
+
if ($variablesString && is_string($variablesString)) {
|
763 |
+
$variablesString = str_replace("\n", '', $variablesString);
|
764 |
+
$variables = Zend_Json::decode($variablesString);
|
765 |
+
}
|
766 |
+
return $variables;
|
767 |
+
}
|
768 |
+
|
769 |
+
/**
|
770 |
+
* Retrieve option array of variables
|
771 |
+
*
|
772 |
+
* @param boolean $withGroup if true wrap variable options in group
|
773 |
+
* @return array
|
774 |
+
*/
|
775 |
+
public function getVariablesOptionArray($withGroup = false)
|
776 |
+
{
|
777 |
+
$optionArray = array();
|
778 |
+
$variables = $this->_parseVariablesString($this->getData('orig_template_variables'));
|
779 |
+
if ($variables) {
|
780 |
+
foreach ($variables as $value => $label) {
|
781 |
+
$optionArray[] = array(
|
782 |
+
'value' => '{{' . $value . '}}',
|
783 |
+
'label' => Mage::helper('core')->__('%s', $label)
|
784 |
+
);
|
785 |
+
}
|
786 |
+
if ($withGroup) {
|
787 |
+
$optionArray = array(
|
788 |
+
'label' => Mage::helper('core')->__('Template Variables'),
|
789 |
+
'value' => $optionArray
|
790 |
+
);
|
791 |
+
}
|
792 |
+
}
|
793 |
+
return $optionArray;
|
794 |
+
}
|
795 |
+
|
796 |
+
/**
|
797 |
+
* Validate email template code
|
798 |
+
*
|
799 |
+
* @return Mage_Core_Model_Email_Template
|
800 |
+
*/
|
801 |
+
protected function _beforeSave()
|
802 |
+
{
|
803 |
+
$code = $this->getTemplateCode();
|
804 |
+
if (empty($code)) {
|
805 |
+
Mage::throwException(Mage::helper('core')->__('The template Name must not be empty.'));
|
806 |
+
}
|
807 |
+
if($this->_getResource()->checkCodeUsage($this)) {
|
808 |
+
Mage::throwException(Mage::helper('core')->__('Duplicate Of Template Name'));
|
809 |
+
}
|
810 |
+
return parent::_beforeSave();
|
811 |
+
}
|
812 |
+
}
|
app/design/adminhtml/default/default/layout/koiber.xml
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout>
|
3 |
+
<adminhtml_koiber_index>
|
4 |
+
<reference name="content">
|
5 |
+
<block type="koiber_transactionalmessages/adminhtml_eventos" name="koiber_transactionalmessages_eventos" />
|
6 |
+
</reference>
|
7 |
+
</adminhtml_koiber_index>
|
8 |
+
<adminhtml_koiber_historico>
|
9 |
+
<reference name="content">
|
10 |
+
<block type="koiber_transactionalmessages/adminhtml_historico" name="koiber_transactionalmessages_historico" />
|
11 |
+
</reference>
|
12 |
+
</adminhtml_koiber_historico>
|
13 |
+
</layout>
|
app/etc/modules/Koiber_TransactionalMessages.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<config>
|
2 |
+
<modules>
|
3 |
+
<Koiber_TransactionalMessages>
|
4 |
+
<active>true</active>
|
5 |
+
<codePool>community</codePool>
|
6 |
+
</Koiber_TransactionalMessages>
|
7 |
+
</modules>
|
8 |
+
</config>
|
app/locale/en_US/Koiber_Koiber.csv
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"Mensagem","Message"
|
2 |
+
"Status","Status"
|
3 |
+
"ID","ID"
|
4 |
+
"Salvar Mensagem","Save Message"
|
5 |
+
"Excluir Mensagem","Delete Message"
|
6 |
+
"Editar Mensagem","Edit Message"
|
7 |
+
"Nova Mensagem","New Message"
|
8 |
+
"Informações da Mensagem","Message Information"
|
9 |
+
"Dados da Mensagem","Message Parameters"
|
10 |
+
"Inserir Variável...","Insert Variable..."
|
11 |
+
"Template da Mensagem","Message Template"
|
12 |
+
"Selecione o Canal","Select the Channel"
|
13 |
+
"Status da Mensagem","Message Status"
|
14 |
+
"Tipo de Mensagem","Message Type"
|
15 |
+
"Caso seja formulário, observar os nomes do campos para que tenham os mesmo nomes no magento para atualização no callback.","In case it's a form, if the fields have the same naming pattern in Magento, it will update it on the callback."
|
16 |
+
"Pode-se usar as variáveis normalmente.","Variables can be used normally."
|
17 |
+
"Template do E-mail","E-Mail Template"
|
18 |
+
"Assunto da Mensagem","Message Subject"
|
19 |
+
"Ativo","Active"
|
20 |
+
"Inativo","Inactive"
|
21 |
+
"Ativado, na template selecionada, será enviado esta menssagem para o koiber ao invez do e-mail (apenas se o usuário tiver cadastro no koiber).","When activated on the selected template, the e-mail messages will be sent to koiber instead of the e-mail's inbox."
|
22 |
+
"Caso preenchido, irá trocar a template padrão do e-mail para o conteudo deste campo.","In case it's filled, the systems default message template will be replaced with whatever is in this text box."
|
23 |
+
"Título","Title"
|
24 |
+
"Histórico de Mensagens","Message History"
|
25 |
+
"Cliente","Customer"
|
26 |
+
"Nome do Evento","Event Name"
|
27 |
+
"Canal","Channel"
|
28 |
+
"Data","Date"
|
29 |
+
"Conversa Criada","Conversation Created"
|
30 |
+
"Mensagem Adicionada","Message Added"
|
31 |
+
"Conversa Encerrada","Conversation Closed"
|
32 |
+
"Conversa Avaliada","Conversation Rated"
|
33 |
+
"Visualizar a Mensagem","View Message"
|
34 |
+
"Último Evento","Last Event"
|
35 |
+
"Data de Criação da Conversa","Creation Date"
|
36 |
+
"Data da Última Modificação","Last Modified Date"
|
37 |
+
"enviado","sent"
|
38 |
+
"recebido","received"
|
39 |
+
"em","on"
|
40 |
+
"Texto","Text"
|
41 |
+
"Formulário","Form"
|
42 |
+
"Resposta de Formulário","Form Response"
|
43 |
+
"INSTRUÇÕES","INSTRUCTIONS"
|
44 |
+
"O koiber é um aplicativo de envio de mensagens instantânea. Envie mensagens em tempo real para seu cliente com integração total com o magento.","Koiber is an instant message software. Send messages in real time to your customers with total integration with magento."
|
45 |
+
"Para gerar o TOKEN você terá que ter cadastro no site www.koiber.com (cadastro gratuito) e acessar o Painel -> Integração -> API","To generate your TOKEN you will need to register at www.koiber.com (registration is free) and access Painel -> Integração -> API"
|
46 |
+
"Para habilitar as notificações para fins de comunicação do Koiber com o Magento, cadastre a seguinte url no Koiber","To activate notifications, for communication purposes from Koiber to Magento, register the following url"
|
47 |
+
"Para saber mais acesse o site www.koiber.com","To know more access www.koiber.com"
|
lib/koiberPHP/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
nbproject
|
lib/koiberPHP/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Biblioteca PHP da api do Koiber.com - 1.0
|
2 |
+
|
3 |
+
Biblioteca de integração com o [koiber.com](http://www.koiber.com). Acesse a [documentação](http://www.koiber.com/api) da api para saber mais.
|
4 |
+
|
5 |
+
|
6 |
+
## Sobre o koiber
|
7 |
+
O koiber é um aplicativo de atendimento ao consumidor (SAC) que usa as tecnologias atuais para conectar os clientes às empresas por meio de mensagens instantâneas.
|
8 |
+
|
9 |
+
## Instalação
|
10 |
+
Basta fazer [download da biblioteca ](https://github.com/natan88/koiberPHP/archive/master.zip) e fazer include do arquivo `src/Koiber/Autoload.php`
|
11 |
+
|
12 |
+
## Recursos desta versão
|
13 |
+
- Listar conversas
|
14 |
+
- Buscar uma conversa específica
|
15 |
+
- Criar conversa
|
16 |
+
- Adicionar mensagem a conversa
|
17 |
+
- Encerrar conversa
|
18 |
+
- Verificar se a conversa esta encerrada
|
19 |
+
- Listar usuários
|
20 |
+
- Buscar um usuário
|
21 |
+
- Verificar se um usuário portador de um telefone ou e-mail autorizou a empresa
|
22 |
+
|
23 |
+
## Credenciais de acesso
|
24 |
+
Para usar a API ter um TOKEN, o token é gerado no painel da empresa. Para mais informações acesse a [documentação](http://www.koiber.com/api) da api
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
## Uso básico
|
29 |
+
|
30 |
+
|
31 |
+
```php
|
32 |
+
<?php
|
33 |
+
require 'src/Koiber/Autoload.php';
|
34 |
+
$koiber = new Koiber("API TOKEN");
|
35 |
+
```
|
36 |
+
|
37 |
+
## Lista conversas
|
38 |
+
|
39 |
+
```php
|
40 |
+
<?php
|
41 |
+
require 'src/Koiber/Autoload.php';
|
42 |
+
$koiber = new Koiber("API KEY");
|
43 |
+
$response = $koiber->getTalks();
|
44 |
+
$talks = $response->getBody();
|
45 |
+
```
|
46 |
+
|
47 |
+
|
48 |
+
## Buscando uma conversa específica
|
49 |
+
``` php
|
50 |
+
<?php
|
51 |
+
require 'src/Koiber/Autoload.php';
|
52 |
+
$koiber = new Koiber("API KEY");
|
53 |
+
$response = $koiber->getTalk("TALK ID");
|
54 |
+
$talk = $response->getBody();
|
55 |
+
```
|
56 |
+
|
57 |
+
|
58 |
+
# Usuários
|
59 |
+
|
60 |
+
|
61 |
+
## Listar usuários
|
62 |
+
``` php
|
63 |
+
<?php
|
64 |
+
require 'src/Koiber/Autoload.php';
|
65 |
+
$koiber = new Koiber("API KEY");
|
66 |
+
$page = 1;
|
67 |
+
$per_page = 10;
|
68 |
+
$response = $koiber->getUsers($page, $per_page);
|
69 |
+
$talk = $response->getBody();
|
70 |
+
```
|
71 |
+
|
72 |
+
## Buscar um usuário
|
73 |
+
``` php
|
74 |
+
<?php
|
75 |
+
require 'src/Koiber/Autoload.php';
|
76 |
+
$koiber = new Koiber("API KEY");
|
77 |
+
$response = $koiber->getUser("USER ID");
|
78 |
+
$talk = $response->getBody();
|
79 |
+
```
|
80 |
+
|
81 |
+
|
82 |
+
## Verifica se um usuário autorizou a empresa
|
83 |
+
``` php
|
84 |
+
<?php
|
85 |
+
require 'src/Koiber/Autoload.php';
|
86 |
+
$koiber = new Koiber("API KEY");
|
87 |
+
$dado = "";
|
88 |
+
$retornaDados = true;
|
89 |
+
$response = $koiber->userIsAuthorized($dado, $retornaDados);
|
90 |
+
$talk = $response->getBody();
|
91 |
+
```
|
92 |
+
|
93 |
+
**$dado** é o telefone (sem o DDI) ou um e-mail. **$retornaDados** indica se deve retornar os dados do usuário
|
94 |
+
|
95 |
+
|
96 |
+
---
|
97 |
+
|
98 |
+
# Retorno
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
## Checando o status da requisição
|
103 |
+
|
104 |
+
Para verificar se a requisição teve sucesso ou falha, basta chamar `$response->isOk()`, se a resposta for **TRUE** a requisição foi válida.
|
105 |
+
|
106 |
+
Para verificar o status HTTP da requisição chame `$response->getResponseCode()`.
|
107 |
+
|
108 |
+
|
109 |
+
## Retornando o erro
|
110 |
+
|
111 |
+
Se obetem o erro chamando o método `$response->getError()`.
|
112 |
+
|
113 |
+
|
114 |
+
## Corpo da requisição
|
115 |
+
|
116 |
+
`$response->getBody()` retorna um json em formato string com a resposta da requisição que pode ser um erro em caso de falha ou a resposta do
|
117 |
+
|
118 |
+
A resposta pode ser convertido para array chamando `$array = json_decode($response->getBody(), true);`
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
# Licença
|
123 |
+
|
124 |
+
Esta biblioteca utiliza a licença [MIT](https://opensource.org/licenses/MIT)
|
lib/koiberPHP/sample/canal_busca.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
$id = null;
|
5 |
+
$post = filter_input_array(INPUT_POST);
|
6 |
+
if($post) {
|
7 |
+
$id = $post['id'];
|
8 |
+
}
|
9 |
+
|
10 |
+
$koiber = new Koiber(API_KEY);
|
11 |
+
$response = $koiber->getCannel($id);
|
12 |
+
?>
|
13 |
+
<html>
|
14 |
+
<head>
|
15 |
+
<meta charset="UTF-8">
|
16 |
+
<title>Buscar Canal</title>
|
17 |
+
</head>
|
18 |
+
<body>
|
19 |
+
<h1>Buscar Canal</h1>
|
20 |
+
<a href="./">Voltar</a><br><br>
|
21 |
+
|
22 |
+
<form method="POST" action="">
|
23 |
+
<label>ID canal</label>
|
24 |
+
<input type="text" name="id" value="<?php echo $id; ?>" size="30">
|
25 |
+
<input type="submit" value="buscar">
|
26 |
+
</form>
|
27 |
+
|
28 |
+
<?php if($post) { ?>
|
29 |
+
<h2>Resultado</h2>
|
30 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
31 |
+
|
32 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
33 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
34 |
+
</div>
|
35 |
+
<?php } ?>
|
36 |
+
</body>
|
37 |
+
</html>
|
lib/koiberPHP/sample/canal_cria.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$post = filter_input_array(INPUT_POST);
|
6 |
+
if($post && isset($post['content'])) {
|
7 |
+
$koiber = new Koiber(API_KEY);
|
8 |
+
$response = $koiber->createCannel(json_encode($post['content']));
|
9 |
+
}
|
10 |
+
?>
|
11 |
+
<html>
|
12 |
+
<head>
|
13 |
+
<meta charset="UTF-8">
|
14 |
+
<title>Criar Canal</title>
|
15 |
+
</head>
|
16 |
+
<body>
|
17 |
+
<h1>Criar Canal</h1>
|
18 |
+
<a href="./">Voltar</a><br><br>
|
19 |
+
|
20 |
+
<form method="POST" action="">
|
21 |
+
<label>Conteúdo (OBJETO JSON)</label><br>
|
22 |
+
<textarea name="content" cols="100" rows="15"></textarea><br>
|
23 |
+
|
24 |
+
<input type="submit" value="criar">
|
25 |
+
</form>
|
26 |
+
|
27 |
+
<?php if($post) { ?>
|
28 |
+
<h2>Resultado</h2>
|
29 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
30 |
+
|
31 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
32 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
33 |
+
</div>
|
34 |
+
<?php } ?>
|
35 |
+
</body>
|
36 |
+
</html>
|
lib/koiberPHP/sample/canal_lista.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$koiber = new Koiber(API_KEY);
|
6 |
+
$response = $koiber->getCannels();
|
7 |
+
?>
|
8 |
+
<html>
|
9 |
+
<head>
|
10 |
+
<meta charset="UTF-8">
|
11 |
+
<title>Listar Canais</title>
|
12 |
+
</head>
|
13 |
+
<body>
|
14 |
+
<h1>Canais Canais</h1>
|
15 |
+
<a href="./">Voltar</a><br><br>
|
16 |
+
|
17 |
+
<h2>Resultado</h2>
|
18 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
19 |
+
|
20 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
21 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
22 |
+
</div>
|
23 |
+
</body>
|
24 |
+
</html>
|
lib/koiberPHP/sample/canal_remove.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$post = filter_input_array(INPUT_POST);
|
6 |
+
if($post && isset($post['id'])) {
|
7 |
+
$koiber = new Koiber(API_KEY);
|
8 |
+
$response = $koiber->deleteCannel($post['id']);
|
9 |
+
}
|
10 |
+
?>
|
11 |
+
<html>
|
12 |
+
<head>
|
13 |
+
<meta charset="UTF-8">
|
14 |
+
<title>Excluir Canal</title>
|
15 |
+
</head>
|
16 |
+
<body>
|
17 |
+
<h1>Excluir Canal</h1>
|
18 |
+
<a href="./">Voltar</a><br><br>
|
19 |
+
|
20 |
+
<form method="POST" action="">
|
21 |
+
<label>ID do Canal</label>
|
22 |
+
<input type="text" name="id" size="30">
|
23 |
+
<input type="submit" value="excluir">
|
24 |
+
</form>
|
25 |
+
|
26 |
+
<?php if($post) { ?>
|
27 |
+
<h2>Resultado</h2>
|
28 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
29 |
+
|
30 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
31 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
32 |
+
</div>
|
33 |
+
<?php } ?>
|
34 |
+
</body>
|
35 |
+
</html>
|
lib/koiberPHP/sample/canal_update.php
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$post = filter_input_array(INPUT_POST);
|
6 |
+
$id = null;
|
7 |
+
$content = null;
|
8 |
+
if($post && isset($post['content'])) {
|
9 |
+
$koiber = new Koiber(API_KEY);
|
10 |
+
$id = $post['id'];
|
11 |
+
$content = $post['content'];
|
12 |
+
$response = $koiber->updateCannel($id, json_encode(json_decode($content)));
|
13 |
+
}
|
14 |
+
?>
|
15 |
+
<html>
|
16 |
+
<head>
|
17 |
+
<meta charset="UTF-8">
|
18 |
+
<title>Atualiza Canal</title>
|
19 |
+
</head>
|
20 |
+
<body>
|
21 |
+
<h1>Atualiza Canal</h1>
|
22 |
+
<a href="./">Voltar</a><br><br>
|
23 |
+
|
24 |
+
<form method="POST" action="">
|
25 |
+
<label>ID do departamento</label><br>
|
26 |
+
<input type="text" name="id" value="<?php echo $id; ?>" size="50"><br><br>
|
27 |
+
|
28 |
+
<label>Conteúdo (OBJETO JSON)</label><br>
|
29 |
+
<textarea name="content" cols="100" rows="15"><?php echo $content; ?></textarea><br>
|
30 |
+
|
31 |
+
<input type="submit" value="Atualizar">
|
32 |
+
</form>
|
33 |
+
|
34 |
+
<?php if($post) { ?>
|
35 |
+
<h2>Resultado</h2>
|
36 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
37 |
+
|
38 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
39 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
40 |
+
</div>
|
41 |
+
<?php } ?>
|
42 |
+
</body>
|
43 |
+
</html>
|
lib/koiberPHP/sample/config.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* TOKEN DA API gerada no painel do cliente (www.koiber.com/panel) no menu INTEGRAÇÃO -> API
|
4 |
+
*/
|
5 |
+
define( 'API_KEY', 'dcd196c0-01cf-11e6-991f-c3ce6ccb4cd2' );
|
lib/koiberPHP/sample/departamento_busca.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
$id = null;
|
5 |
+
$post = filter_input_array(INPUT_POST);
|
6 |
+
if($post) {
|
7 |
+
$id = $post['id'];
|
8 |
+
}
|
9 |
+
|
10 |
+
$koiber = new Koiber(API_KEY);
|
11 |
+
$response = $koiber->getDepartment($id);
|
12 |
+
?>
|
13 |
+
<html>
|
14 |
+
<head>
|
15 |
+
<meta charset="UTF-8">
|
16 |
+
<title>Buscar Departamento</title>
|
17 |
+
</head>
|
18 |
+
<body>
|
19 |
+
<h1>Buscar Departamento</h1>
|
20 |
+
<a href="./">Voltar</a><br><br>
|
21 |
+
|
22 |
+
<form method="POST" action="">
|
23 |
+
<label>ID departamento</label>
|
24 |
+
<input type="text" name="id" value="<?php echo $id; ?>" size="30">
|
25 |
+
<input type="submit" value="buscar">
|
26 |
+
</form>
|
27 |
+
|
28 |
+
<?php if($post) { ?>
|
29 |
+
<h2>Resultado</h2>
|
30 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
31 |
+
|
32 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
33 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
34 |
+
</div>
|
35 |
+
<?php } ?>
|
36 |
+
</body>
|
37 |
+
</html>
|
lib/koiberPHP/sample/departamento_cria.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$post = filter_input_array(INPUT_POST);
|
6 |
+
if($post && isset($post['name'])) {
|
7 |
+
$koiber = new Koiber(API_KEY);
|
8 |
+
$response = $koiber->createDepartment($post['name']);
|
9 |
+
}
|
10 |
+
?>
|
11 |
+
<html>
|
12 |
+
<head>
|
13 |
+
<meta charset="UTF-8">
|
14 |
+
<title>Criar Departamento</title>
|
15 |
+
</head>
|
16 |
+
<body>
|
17 |
+
<h1>Criar Departamento</h1>
|
18 |
+
<a href="./">Voltar</a><br><br>
|
19 |
+
|
20 |
+
<form method="POST" action="">
|
21 |
+
<label>Nome do departamento</label>
|
22 |
+
<input type="text" name="name" size="30">
|
23 |
+
<input type="submit" value="criar">
|
24 |
+
</form>
|
25 |
+
|
26 |
+
<?php if($post) { ?>
|
27 |
+
<h2>Resultado</h2>
|
28 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
29 |
+
|
30 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
31 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
32 |
+
</div>
|
33 |
+
<?php } ?>
|
34 |
+
</body>
|
35 |
+
</html>
|
lib/koiberPHP/sample/departamento_lista.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$koiber = new Koiber(API_KEY);
|
6 |
+
$response = $koiber->getDepartments();
|
7 |
+
?>
|
8 |
+
<html>
|
9 |
+
<head>
|
10 |
+
<meta charset="UTF-8">
|
11 |
+
<title>Listar Departamentos</title>
|
12 |
+
</head>
|
13 |
+
<body>
|
14 |
+
<h1>Listar Departamentos</h1>
|
15 |
+
<a href="./">Voltar</a><br><br>
|
16 |
+
|
17 |
+
<h2>Resultado</h2>
|
18 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
19 |
+
|
20 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
21 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
22 |
+
</div>
|
23 |
+
</body>
|
24 |
+
</html>
|
lib/koiberPHP/sample/departamento_remove.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$post = filter_input_array(INPUT_POST);
|
6 |
+
if($post && isset($post['id'])) {
|
7 |
+
$koiber = new Koiber(API_KEY);
|
8 |
+
$response = $koiber->deleteDepartment($post['id']);
|
9 |
+
}
|
10 |
+
?>
|
11 |
+
<html>
|
12 |
+
<head>
|
13 |
+
<meta charset="UTF-8">
|
14 |
+
<title>Excluir Departamento</title>
|
15 |
+
</head>
|
16 |
+
<body>
|
17 |
+
<h1>Excluir Departamento</h1>
|
18 |
+
<a href="./">Voltar</a><br><br>
|
19 |
+
|
20 |
+
<form method="POST" action="">
|
21 |
+
<label>ID do departamento</label>
|
22 |
+
<input type="text" name="id" size="30">
|
23 |
+
<input type="submit" value="excluir">
|
24 |
+
</form>
|
25 |
+
|
26 |
+
<?php if($post) { ?>
|
27 |
+
<h2>Resultado</h2>
|
28 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
29 |
+
|
30 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
31 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
32 |
+
</div>
|
33 |
+
<?php } ?>
|
34 |
+
</body>
|
35 |
+
</html>
|
lib/koiberPHP/sample/departamento_update.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$post = filter_input_array(INPUT_POST);
|
6 |
+
$id = null;
|
7 |
+
$name = null;
|
8 |
+
if($post && isset($post['name'])) {
|
9 |
+
$koiber = new Koiber(API_KEY);
|
10 |
+
$id = $post['id'];
|
11 |
+
$name = $post['name'];
|
12 |
+
$response = $koiber->updateDepartment($id, $name);
|
13 |
+
}
|
14 |
+
?>
|
15 |
+
<html>
|
16 |
+
<head>
|
17 |
+
<meta charset="UTF-8">
|
18 |
+
<title>Atualizar Departamento</title>
|
19 |
+
</head>
|
20 |
+
<body>
|
21 |
+
<h1>Atualizar Departamento</h1>
|
22 |
+
<a href="./">Voltar</a><br><br>
|
23 |
+
|
24 |
+
<form method="POST" action="">
|
25 |
+
<label>ID do departamento</label><br>
|
26 |
+
<input type="text" name="id" value="<?php echo $id; ?>" size="50"><br><br>
|
27 |
+
<label>Nome do departamento</label><br>
|
28 |
+
<input type="text" name="name" value="<?php echo $name; ?>" size="50"><br><br>
|
29 |
+
<input type="submit" value="atualizar">
|
30 |
+
</form>
|
31 |
+
|
32 |
+
<?php if($post) { ?>
|
33 |
+
<h2>Resultado</h2>
|
34 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
35 |
+
|
36 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
37 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
38 |
+
</div>
|
39 |
+
<?php } ?>
|
40 |
+
</body>
|
41 |
+
</html>
|
lib/koiberPHP/sample/index.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<meta charset="UTF-8">
|
4 |
+
<title>Teste da biblioteca do koiber</title>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h1>Teste da biblioteca</h1>
|
8 |
+
|
9 |
+
<h2>Conversas</h2>
|
10 |
+
<ol>
|
11 |
+
<li><a href="msg_lista.php">Listar conversas</a></li>
|
12 |
+
<li><a href="msg_busca.php">Buscar uma conversa</a></li>
|
13 |
+
<li><a href="msg_cria.php">Criar conversa</a></li>
|
14 |
+
<li><a href="msg_add_msg.php">Adiciona nova mensagem</a></li>
|
15 |
+
<li><a href="msg_encerra.php">Encerra conversa</a></li>
|
16 |
+
<li><a href="msg_foi_encerra.php">Verifica se conversa foi encerrada</a></li>
|
17 |
+
</ol>
|
18 |
+
|
19 |
+
<br><h2>Usuário</h2>
|
20 |
+
<ol>
|
21 |
+
<li><a href="user_lista.php">Listar usuários</a></li>
|
22 |
+
<li><a href="user_busca.php">Buscar um usuario</a></li>
|
23 |
+
<li><a href="user_autorizou.php">Verifica se um usuario autorizou a empresa</a></li>
|
24 |
+
</ol>
|
25 |
+
|
26 |
+
<br><h2>Departamentos</h2>
|
27 |
+
<ol>
|
28 |
+
<li><a href="departamento_lista.php">Listar departamentos</a></li>
|
29 |
+
<li><a href="departamento_busca.php">Buscar um departamento</a></li>
|
30 |
+
<li><a href="departamento_cria.php">Criar um departamento</a></li>
|
31 |
+
<li><a href="departamento_update.php">Atualizar um departamento</a></li>
|
32 |
+
<li><a href="departamento_remove.php">Excluir um departamento</a></li>
|
33 |
+
</ol>
|
34 |
+
|
35 |
+
<br><h2>Departamentos</h2>
|
36 |
+
<ol>
|
37 |
+
<li><a href="canal_lista.php">Listar canais</a></li>
|
38 |
+
<li><a href="canal_busca.php">Buscar um canal</a></li>
|
39 |
+
<li><a href="canal_cria.php">Criar um canal</a></li>
|
40 |
+
<li><a href="canal_update.php">Atualizar um canal</a></li>
|
41 |
+
<li><a href="canal_remove.php">Excluir um canal</a></li>
|
42 |
+
</ol>
|
43 |
+
</body>
|
44 |
+
</html>
|
lib/koiberPHP/sample/msg_add_msg.php
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$method = filter_input(INPUT_SERVER, "REQUEST_METHOD");
|
6 |
+
if($method == 'POST') {
|
7 |
+
$post = filter_input_array(INPUT_POST);
|
8 |
+
|
9 |
+
$talk = array(
|
10 |
+
'type' => $post['type'],
|
11 |
+
'content' => ($post['type'] == 'form' ? json_decode($post['content']) : $post['content'])
|
12 |
+
);
|
13 |
+
|
14 |
+
$koiber = new Koiber(API_KEY);
|
15 |
+
$response = $koiber->addMsgTalk($post['conversa'], json_encode($talk));
|
16 |
+
}
|
17 |
+
?>
|
18 |
+
<html>
|
19 |
+
<head>
|
20 |
+
<meta charset="UTF-8">
|
21 |
+
<title>Adicionar mensagem a conversa</title>
|
22 |
+
<style>
|
23 |
+
label{display: block; margin-top: 25px;}
|
24 |
+
input{width: 400px; height: 30px;}
|
25 |
+
textarea{width: 800px; height: 200px;}
|
26 |
+
input:last-child{margin-top: 20px;width: auto}
|
27 |
+
</style>
|
28 |
+
</head>
|
29 |
+
<body>
|
30 |
+
<h1>Adicionar mensagem a conversa</h1>
|
31 |
+
<a href="./" onclick="window.history.back()">Voltar</a><br><br>
|
32 |
+
|
33 |
+
<?php if($method === 'GET') {?>
|
34 |
+
<form method="POST" action="">
|
35 |
+
<label>Conversa</label>
|
36 |
+
<input type="text" name="conversa" value=""><br>
|
37 |
+
|
38 |
+
<label>Tipo da mensagem</label>
|
39 |
+
<select name="type">
|
40 |
+
<option value="">--</option>
|
41 |
+
<option value="text">Text</option>
|
42 |
+
<option value="form">Formulário</option>
|
43 |
+
</select><br>
|
44 |
+
|
45 |
+
<label>Conteúdo</label>
|
46 |
+
<textarea name="content"></textarea><br>
|
47 |
+
|
48 |
+
<input type="submit" value="Adicionar mensagem">
|
49 |
+
</form>
|
50 |
+
<?php } else { ?>
|
51 |
+
<h2>Resultado</h2>
|
52 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
53 |
+
|
54 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
55 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
56 |
+
</div>
|
57 |
+
<?php } ?>
|
58 |
+
</body>
|
59 |
+
</html>
|
lib/koiberPHP/sample/msg_busca.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
setlocale(LC_ALL, 'pt_BR.utf8', 'pt_br', 'pt_BR', 'ptb', 'ptb_ptb', 'brazilian', 'brazil', 'portuguese');
|
3 |
+
date_default_timezone_set('America/Sao_Paulo');
|
4 |
+
|
5 |
+
require '../src/Koiber/Autoload.php';
|
6 |
+
require 'config.php';
|
7 |
+
$id = null;
|
8 |
+
$post = filter_input_array(INPUT_POST);
|
9 |
+
if($post) {
|
10 |
+
$id = $post['id'];
|
11 |
+
}
|
12 |
+
|
13 |
+
|
14 |
+
$koiber = new Koiber(API_KEY);
|
15 |
+
$response = $koiber->getTalk($id);
|
16 |
+
?>
|
17 |
+
<html>
|
18 |
+
<head>
|
19 |
+
<meta charset="UTF-8">
|
20 |
+
<title>Buscar conversas</title>
|
21 |
+
</head>
|
22 |
+
<body>
|
23 |
+
<h1>Buscar conversa</h1>
|
24 |
+
<a href="./">Voltar</a><br><br>
|
25 |
+
|
26 |
+
<form method="POST" action="">
|
27 |
+
<label>ID conversa</label>
|
28 |
+
<input type="text" name="id" value="<?php echo $id; ?>" size="30">
|
29 |
+
<input type="submit" value="buscar">
|
30 |
+
</form>
|
31 |
+
|
32 |
+
<?php if($post) { ?>
|
33 |
+
<h2>Resultado</h2>
|
34 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
35 |
+
|
36 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
37 |
+
<?php $talk = $response->getTalk(); ?>
|
38 |
+
<p>
|
39 |
+
<strong>ID</strong>: <?php echo $talk->getId(); ?><br>
|
40 |
+
<strong>Data criação</strong>: <?php echo $talk->getCreatedAt()->format('d-m-Y H:i:s'); ?><br>
|
41 |
+
<strong>Title</strong>: <?php echo $talk->getTitle(); ?><br>
|
42 |
+
<strong>Autor </strong>: <?php echo $talk->getAuthor(); ?><br>
|
43 |
+
<strong>Uusuário id</strong>: <?php echo $talk->getUser()->getId(); ?><br>
|
44 |
+
<strong>Canal id</strong>: <?php echo $talk->getChannel()->getId(); ?><br>
|
45 |
+
<strong>Total de mensagens</strong>: <?php echo count($talk->getMsgs()); ?><br>
|
46 |
+
</p>
|
47 |
+
|
48 |
+
<h3>Mensagens</h3>
|
49 |
+
<?php foreach($talk->getMsgs() as $msg ) { ?>
|
50 |
+
<p>
|
51 |
+
------------------------<br>
|
52 |
+
<strong>ID</strong>: <?php echo $msg->getId(); ?><br>
|
53 |
+
<strong>Data criação</strong>: <?php echo $msg->getCreatedAt()->format('d-m-Y H:i:s'); ?><br>
|
54 |
+
<strong>Autor </strong>: <?php echo $msg->getAuthor(); ?><br>
|
55 |
+
<strong>Tipo </strong>: <?php echo $msg->getType(); ?><br>
|
56 |
+
<strong>Conteúdo </strong>:
|
57 |
+
<?php if($msg->getType() == Type::TEXT) echo $msg->getContent(); else {
|
58 |
+
$fields = $msg->getContent()->getElements();
|
59 |
+
foreach ($fields as $field) {
|
60 |
+
echo $field->getId().' - ' . $field->getElement().' - ' . $field->getLabel();
|
61 |
+
}
|
62 |
+
?>
|
63 |
+
<?php } // end field ?>
|
64 |
+
|
65 |
+
</p>
|
66 |
+
<?php }// end msg ?>
|
67 |
+
</div>
|
68 |
+
<?php } ?>
|
69 |
+
</body>
|
70 |
+
</html>
|
lib/koiberPHP/sample/msg_cria.php
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$method = filter_input(INPUT_SERVER, "REQUEST_METHOD");
|
6 |
+
if($method == 'POST') {
|
7 |
+
$post = filter_input_array(INPUT_POST);
|
8 |
+
|
9 |
+
$talk = array(
|
10 |
+
'type' => $post['type'],
|
11 |
+
'channel' => $post['channel'],
|
12 |
+
'user' => $post['user'],
|
13 |
+
'content' => ($post['type'] == 'form' ? json_decode($post['content']) : $post['content'])
|
14 |
+
);
|
15 |
+
if(isset($post['title'])) {$talk['title'] = $post['title'];}
|
16 |
+
if(isset($post['branch'])) {$talk['branch'] = $post['branch'];}
|
17 |
+
|
18 |
+
$koiber = new Koiber(API_KEY);
|
19 |
+
$response = $koiber->createTalk(json_encode($talk));
|
20 |
+
}
|
21 |
+
?>
|
22 |
+
<html>
|
23 |
+
<head>
|
24 |
+
<meta charset="UTF-8">
|
25 |
+
<title>Cria conversa</title>
|
26 |
+
<style>
|
27 |
+
label{display: block; margin-top: 25px;}
|
28 |
+
input{width: 400px; height: 30px;}
|
29 |
+
textarea{width: 800px; height: 200px;}
|
30 |
+
input:last-child{margin-top: 20px;width: auto}
|
31 |
+
</style>
|
32 |
+
</head>
|
33 |
+
<body>
|
34 |
+
<h1>Cria conversa</h1>
|
35 |
+
<a href="./" onclick="window.history.back()">Voltar</a><br><br>
|
36 |
+
|
37 |
+
<?php if($method === 'GET') {?>
|
38 |
+
<form method="POST" action="">
|
39 |
+
<label>Destinatário</label>
|
40 |
+
<input type="text" name="user" value=""><br>
|
41 |
+
|
42 |
+
<label>Canal</label>
|
43 |
+
<input type="text" name="channel" value=""><br>
|
44 |
+
|
45 |
+
<label>Tipo da mensagem</label>
|
46 |
+
<select name="type">
|
47 |
+
<option value="">--</option>
|
48 |
+
<option value="text">Text</option>
|
49 |
+
<option value="form">Formulário</option>
|
50 |
+
</select><br>
|
51 |
+
|
52 |
+
<label>Conteúdo</label>
|
53 |
+
<textarea name="content"></textarea><br>
|
54 |
+
|
55 |
+
<input type="submit" value="Criar conversa">
|
56 |
+
</form>
|
57 |
+
<?php } else { ?>
|
58 |
+
<h2>Resultado</h2>
|
59 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
60 |
+
|
61 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
62 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
63 |
+
</div>
|
64 |
+
<?php } ?>
|
65 |
+
</body>
|
66 |
+
</html>
|
lib/koiberPHP/sample/msg_encerra.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$method = filter_input(INPUT_SERVER, "REQUEST_METHOD");
|
6 |
+
if($method == 'POST') {
|
7 |
+
$post = filter_input_array(INPUT_POST);
|
8 |
+
|
9 |
+
$koiber = new Koiber(API_KEY);
|
10 |
+
$response = $koiber->closeTalk($post['conversa']);
|
11 |
+
}
|
12 |
+
?>
|
13 |
+
<html>
|
14 |
+
<head>
|
15 |
+
<meta charset="UTF-8">
|
16 |
+
<title>Encerra conversa</title>
|
17 |
+
<style>
|
18 |
+
label{display: block; margin-top: 25px;}
|
19 |
+
input{width: 400px; height: 30px;}
|
20 |
+
textarea{width: 800px; height: 200px;}
|
21 |
+
input:last-child{margin-top: 20px;width: auto}
|
22 |
+
</style>
|
23 |
+
</head>
|
24 |
+
<body>
|
25 |
+
<h1>Encerra conversa</h1>
|
26 |
+
<a href="./" onclick="window.history.back()">Voltar</a><br><br>
|
27 |
+
|
28 |
+
<?php if($method === 'GET') {?>
|
29 |
+
<form method="POST" action="">
|
30 |
+
<label>Conversa</label>
|
31 |
+
<input type="text" name="conversa" value="">
|
32 |
+
|
33 |
+
<input type="submit" value="Encerrar conversa">
|
34 |
+
</form>
|
35 |
+
<?php } else { ?>
|
36 |
+
<h2>Resultado</h2>
|
37 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
38 |
+
|
39 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
40 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
41 |
+
</div>
|
42 |
+
<?php } ?>
|
43 |
+
</body>
|
44 |
+
</html>
|
lib/koiberPHP/sample/msg_foi_encerra.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
|
5 |
+
$method = filter_input(INPUT_SERVER, "REQUEST_METHOD");
|
6 |
+
if($method == 'POST') {
|
7 |
+
$post = filter_input_array(INPUT_POST);
|
8 |
+
|
9 |
+
$koiber = new Koiber(API_KEY);
|
10 |
+
$response = $koiber->isCloseTalk($post['conversa']);
|
11 |
+
}
|
12 |
+
?>
|
13 |
+
<html>
|
14 |
+
<head>
|
15 |
+
<meta charset="UTF-8">
|
16 |
+
<title>Verifica se a conversa foi encerrada</title>
|
17 |
+
<style>
|
18 |
+
label{display: block; margin-top: 25px;}
|
19 |
+
input{width: 400px; height: 30px;}
|
20 |
+
textarea{width: 800px; height: 200px;}
|
21 |
+
input:last-child{margin-top: 20px;width: auto}
|
22 |
+
</style>
|
23 |
+
</head>
|
24 |
+
<body>
|
25 |
+
<h1>Verifica se a conversa foi encerrada</h1>
|
26 |
+
<a href="./" onclick="window.history.back()">Voltar</a><br><br>
|
27 |
+
|
28 |
+
<?php if($method === 'GET') {?>
|
29 |
+
<form method="POST" action="">
|
30 |
+
<label>Conversa</label>
|
31 |
+
<input type="text" name="conversa" value="">
|
32 |
+
|
33 |
+
<input type="submit" value="Verificar">
|
34 |
+
</form>
|
35 |
+
<?php } else { ?>
|
36 |
+
<h2>Resultado</h2>
|
37 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
38 |
+
|
39 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
40 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
41 |
+
</div>
|
42 |
+
<?php } ?>
|
43 |
+
</body>
|
44 |
+
</html>
|
lib/koiberPHP/sample/msg_lista.php
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
$per_page = 1;
|
5 |
+
$page = 1;
|
6 |
+
|
7 |
+
$post = filter_input_array(INPUT_POST);
|
8 |
+
if($post) {
|
9 |
+
$per_page = (int)$post['per_page'];
|
10 |
+
$page = (int)$post['page'];
|
11 |
+
}
|
12 |
+
|
13 |
+
$koiber = new Koiber(API_KEY);
|
14 |
+
$response = $koiber->getTalks($page, $per_page);
|
15 |
+
?>
|
16 |
+
<html>
|
17 |
+
<head>
|
18 |
+
<meta charset="UTF-8">
|
19 |
+
<title>Listar conversas</title>
|
20 |
+
</head>
|
21 |
+
<body>
|
22 |
+
<h1>Listar conversa</h1>
|
23 |
+
<a href="./">Voltar</a><br><br>
|
24 |
+
|
25 |
+
<form method="POST" action="">
|
26 |
+
<label>Resultados por página</label>
|
27 |
+
<input type="text" name="per_page" value="<?php echo $per_page; ?>" size="5">
|
28 |
+
<label>Página</label>
|
29 |
+
<input type="text" name="page" value="<?php echo $page; ?>" size="5">
|
30 |
+
<input type="submit" value="buscar">
|
31 |
+
</form>
|
32 |
+
|
33 |
+
<h2>Resultado</h2>
|
34 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
35 |
+
|
36 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
37 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
38 |
+
</div>
|
39 |
+
</body>
|
40 |
+
</html>
|
lib/koiberPHP/sample/user_autorizou.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
$dado = null;
|
5 |
+
$get = false;
|
6 |
+
$post = filter_input_array(INPUT_POST);
|
7 |
+
if($post) {
|
8 |
+
$dado = $post['dado'];
|
9 |
+
$get = $post['get'];
|
10 |
+
$koiber = new Koiber(API_KEY);
|
11 |
+
$response = $koiber->userIsAuthorized($dado, $get);
|
12 |
+
}
|
13 |
+
|
14 |
+
?>
|
15 |
+
<html>
|
16 |
+
<head>
|
17 |
+
<meta charset="UTF-8">
|
18 |
+
<title>Verifica se usuário autorizou a empresa</title>
|
19 |
+
</head>
|
20 |
+
<body>
|
21 |
+
<h1>Verifica se usuário autorizou a empresa</h1>
|
22 |
+
<a href="./">Voltar</a><br><br>
|
23 |
+
|
24 |
+
<form method="POST" action="">
|
25 |
+
<label>Trazer dados?</label><br>
|
26 |
+
<select name="get">
|
27 |
+
<option value="true">SIM</option>
|
28 |
+
<option value="false"<?php echo ($get == 'false' ? ' selected' : ''); ?>>Não</option>
|
29 |
+
</select><br><br>
|
30 |
+
|
31 |
+
<label>Telefone ou e-mail</label><br>
|
32 |
+
<input type="text" name="dado" value="<?php echo $dado; ?>" size="50"><br><br>
|
33 |
+
<input type="submit" value="Verificar">
|
34 |
+
</form>
|
35 |
+
|
36 |
+
<?php if($post) { ?>
|
37 |
+
<h2>Resultado</h2>
|
38 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
39 |
+
|
40 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
41 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
42 |
+
</div>
|
43 |
+
<?php } ?>
|
44 |
+
</body>
|
45 |
+
</html>
|
lib/koiberPHP/sample/user_busca.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
setlocale(LC_ALL, 'pt_BR.utf8', 'pt_br', 'pt_BR', 'ptb', 'ptb_ptb', 'brazilian', 'brazil', 'portuguese');
|
3 |
+
date_default_timezone_set('America/Sao_Paulo');
|
4 |
+
|
5 |
+
require '../src/Koiber/Autoload.php';
|
6 |
+
require 'config.php';
|
7 |
+
$id = null;
|
8 |
+
$post = filter_input_array(INPUT_POST);
|
9 |
+
if($post) {
|
10 |
+
$id = $post['id'];
|
11 |
+
}
|
12 |
+
|
13 |
+
|
14 |
+
$koiber = new Koiber(API_KEY);
|
15 |
+
$response = $koiber->getUser($id);
|
16 |
+
?>
|
17 |
+
<html>
|
18 |
+
<head>
|
19 |
+
<meta charset="UTF-8">
|
20 |
+
<title>Buscar usuário</title>
|
21 |
+
</head>
|
22 |
+
<body>
|
23 |
+
<h1>Buscar usuário</h1>
|
24 |
+
<a href="./">Voltar</a><br><br>
|
25 |
+
|
26 |
+
<form method="POST" action="">
|
27 |
+
<label>ID usuário</label>
|
28 |
+
<input type="text" name="id" value="<?php echo $id; ?>" size="30">
|
29 |
+
<input type="submit" value="buscar">
|
30 |
+
</form>
|
31 |
+
|
32 |
+
<?php if($post) { ?>
|
33 |
+
<h2>Resultado</h2>
|
34 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
35 |
+
|
36 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
37 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
38 |
+
</div>
|
39 |
+
<?php } ?>
|
40 |
+
</body>
|
41 |
+
</html>
|
lib/koiberPHP/sample/user_lista.php
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require '../src/Koiber/Autoload.php';
|
3 |
+
require 'config.php';
|
4 |
+
$per_page = 1;
|
5 |
+
$page = 1;
|
6 |
+
|
7 |
+
$post = filter_input_array(INPUT_POST);
|
8 |
+
if($post) {
|
9 |
+
$per_page = (int)$post['per_page'];
|
10 |
+
$page = (int)$post['page'];
|
11 |
+
}
|
12 |
+
|
13 |
+
$koiber = new Koiber(API_KEY);
|
14 |
+
$response = $koiber->getUsers($page, $per_page);
|
15 |
+
?>
|
16 |
+
<html>
|
17 |
+
<head>
|
18 |
+
<meta charset="UTF-8">
|
19 |
+
<title>Listar usuários</title>
|
20 |
+
</head>
|
21 |
+
<body>
|
22 |
+
<h1>Listar usuários</h1>
|
23 |
+
<a href="./">Voltar</a><br><br>
|
24 |
+
|
25 |
+
<form method="POST" action="">
|
26 |
+
<label>Resultados por página</label>
|
27 |
+
<input type="text" name="per_page" value="<?php echo $per_page; ?>" size="5">
|
28 |
+
<label>Página</label>
|
29 |
+
<input type="text" name="page" value="<?php echo $page; ?>" size="5">
|
30 |
+
<input type="submit" value="buscar">
|
31 |
+
</form>
|
32 |
+
|
33 |
+
<h2>Resultado</h2>
|
34 |
+
<p><strong>STATUS: </strong> <?php echo $response->getResponseCode(); ?> - <?php echo $response->isOk(); ?></p>
|
35 |
+
|
36 |
+
<div style="max-height: 630px; overflow: auto; padding: 10px; border: 1px solid #ddd;">
|
37 |
+
<pre><?php print_r(json_decode($response->getBody(), true));?></pre>
|
38 |
+
</div>
|
39 |
+
</body>
|
40 |
+
</html>
|
lib/koiberPHP/src/Koiber/Address.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Address {
|
4 |
+
private $country;
|
5 |
+
private $state;
|
6 |
+
private $city;
|
7 |
+
private $address;
|
8 |
+
|
9 |
+
public function getCountry() {
|
10 |
+
return $this->country;
|
11 |
+
}
|
12 |
+
|
13 |
+
public function getState() {
|
14 |
+
return $this->state;
|
15 |
+
}
|
16 |
+
|
17 |
+
public function getCity() {
|
18 |
+
return $this->city;
|
19 |
+
}
|
20 |
+
|
21 |
+
public function getAddress() {
|
22 |
+
return $this->address;
|
23 |
+
}
|
24 |
+
|
25 |
+
public function setCountry($country) {
|
26 |
+
$this->country = $country;
|
27 |
+
return $this;
|
28 |
+
}
|
29 |
+
|
30 |
+
public function setState($state) {
|
31 |
+
$this->state = $state;
|
32 |
+
return $this;
|
33 |
+
}
|
34 |
+
|
35 |
+
public function setCity($city) {
|
36 |
+
$this->city = $city;
|
37 |
+
return $this;
|
38 |
+
}
|
39 |
+
|
40 |
+
public function setAddress($address) {
|
41 |
+
$this->address = $address;
|
42 |
+
return $this;
|
43 |
+
}
|
44 |
+
}
|
lib/koiberPHP/src/Koiber/Autoload.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//function __autoload($classname) {
|
4 |
+
$paths = array(
|
5 |
+
"",
|
6 |
+
'Message/',
|
7 |
+
'Form/'
|
8 |
+
);
|
9 |
+
|
10 |
+
foreach ($paths as $path) {
|
11 |
+
foreach (glob(__DIR__ . '/' . $path . '*.php') as $file) {
|
12 |
+
include_once $file;
|
13 |
+
}
|
14 |
+
/*$file = sprintf('%s/%s%s.php', dirname(__FILE__), $path, $classname);
|
15 |
+
if(file_exists($file)) {
|
16 |
+
include_once $file;
|
17 |
+
return;
|
18 |
+
}*/
|
19 |
+
}
|
20 |
+
//}
|
lib/koiberPHP/src/Koiber/Channel.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Channel {
|
4 |
+
private $id;
|
5 |
+
private $name;
|
6 |
+
private $info;
|
7 |
+
private $conf;
|
8 |
+
|
9 |
+
/**
|
10 |
+
*
|
11 |
+
* @var Form
|
12 |
+
*/
|
13 |
+
private $form;
|
14 |
+
|
15 |
+
/**
|
16 |
+
*
|
17 |
+
* @var Branch
|
18 |
+
*/
|
19 |
+
private $branch;
|
20 |
+
|
21 |
+
public function __construct($id) {
|
22 |
+
$this->id = $id;
|
23 |
+
}
|
24 |
+
|
25 |
+
public function getId() {
|
26 |
+
return $this->id;
|
27 |
+
}
|
28 |
+
|
29 |
+
public function getName() {
|
30 |
+
return $this->name;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getInfo() {
|
34 |
+
return $this->info;
|
35 |
+
}
|
36 |
+
|
37 |
+
public function getConf() {
|
38 |
+
return $this->conf;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function getForm() {
|
42 |
+
return $this->form;
|
43 |
+
}
|
44 |
+
|
45 |
+
public function getBranch() {
|
46 |
+
return $this->branch;
|
47 |
+
}
|
48 |
+
|
49 |
+
public function setId($id) {
|
50 |
+
$this->id = $id;
|
51 |
+
return $this;
|
52 |
+
}
|
53 |
+
|
54 |
+
public function setName($name) {
|
55 |
+
$this->name = $name;
|
56 |
+
return $this;
|
57 |
+
}
|
58 |
+
|
59 |
+
public function setInfo($info) {
|
60 |
+
$this->info = $info;
|
61 |
+
return $this;
|
62 |
+
}
|
63 |
+
|
64 |
+
public function setConf($conf) {
|
65 |
+
$this->conf = $conf;
|
66 |
+
return $this;
|
67 |
+
}
|
68 |
+
|
69 |
+
public function setForm(Form $form) {
|
70 |
+
$this->form = $form;
|
71 |
+
return $this;
|
72 |
+
}
|
73 |
+
|
74 |
+
public function setBranch(Branch $branch) {
|
75 |
+
$this->branch = $branch;
|
76 |
+
return $this;
|
77 |
+
}
|
78 |
+
|
79 |
+
}
|
lib/koiberPHP/src/Koiber/Form/Element.php
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
abstract class Element {
|
4 |
+
private $id;
|
5 |
+
private $label;
|
6 |
+
private $element;
|
7 |
+
private $required = false;
|
8 |
+
|
9 |
+
private $elements = array('p', 'input', 'textarea');
|
10 |
+
|
11 |
+
public function __construct($id, $label, $element) {
|
12 |
+
$this->id = $id;
|
13 |
+
$this->label = $label;
|
14 |
+
|
15 |
+
if(in_array($element, $this->elements)) {
|
16 |
+
$this->element = $element;
|
17 |
+
}else {
|
18 |
+
throw new Exception('O elemento não é válido');
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
|
23 |
+
public function getId() {
|
24 |
+
return $this->id;
|
25 |
+
}
|
26 |
+
|
27 |
+
public function getLabel() {
|
28 |
+
return $this->label;
|
29 |
+
}
|
30 |
+
|
31 |
+
public function getElement() {
|
32 |
+
return $this->element;
|
33 |
+
}
|
34 |
+
|
35 |
+
public function setId($id) {
|
36 |
+
$this->id = $id;
|
37 |
+
return $this;
|
38 |
+
}
|
39 |
+
|
40 |
+
public function setLabel($label) {
|
41 |
+
$this->label = $label;
|
42 |
+
return $this;
|
43 |
+
}
|
44 |
+
|
45 |
+
public function setElement($element) {
|
46 |
+
$this->element = $element;
|
47 |
+
return $this;
|
48 |
+
}
|
49 |
+
|
50 |
+
public function setRequired(Boolean $required) {
|
51 |
+
if(!is_bool($required))
|
52 |
+
throw new Exception('boolean is expected');
|
53 |
+
$this->required = $required;
|
54 |
+
return $this;
|
55 |
+
}
|
56 |
+
|
57 |
+
abstract function getResponse();
|
58 |
+
}
|
lib/koiberPHP/src/Koiber/Form/Form.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Form {
|
4 |
+
private $elements = array();
|
5 |
+
private $title;
|
6 |
+
|
7 |
+
public function addElement(Element $element) {
|
8 |
+
array_push($this->elements, $element);
|
9 |
+
return $this;
|
10 |
+
}
|
11 |
+
|
12 |
+
public function getElements() {
|
13 |
+
return $this->elements;
|
14 |
+
}
|
15 |
+
|
16 |
+
public function getTitle() {
|
17 |
+
return $this->title;
|
18 |
+
}
|
19 |
+
|
20 |
+
public function setTitle($title) {
|
21 |
+
$this->title = $title;
|
22 |
+
return $this;
|
23 |
+
}
|
24 |
+
|
25 |
+
}
|
lib/koiberPHP/src/Koiber/Form/IElement.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
interface IElement {
|
4 |
+
public function setRequired($required);
|
5 |
+
public function isRequired();
|
6 |
+
public function getResponse();
|
7 |
+
}
|
lib/koiberPHP/src/Koiber/Form/Paragraph.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Paragraph extends Element {
|
4 |
+
|
5 |
+
/*
|
6 |
+
*
|
7 |
+
*/
|
8 |
+
public function __construct($id, $content) {
|
9 |
+
parent::__construct($id, $content, "p");
|
10 |
+
}
|
11 |
+
|
12 |
+
public function getResponse() {
|
13 |
+
|
14 |
+
}
|
15 |
+
|
16 |
+
}
|
lib/koiberPHP/src/Koiber/Form/Textarea.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Textarea extends Element {
|
4 |
+
|
5 |
+
public function __construct($id, $label) {
|
6 |
+
parent::__construct($id, $label, "textarea");
|
7 |
+
}
|
8 |
+
|
9 |
+
public function getElement() {
|
10 |
+
parent::getElement();
|
11 |
+
}
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
public function getResponse() {
|
16 |
+
|
17 |
+
}
|
18 |
+
|
19 |
+
}
|
lib/koiberPHP/src/Koiber/Koiber.php
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Koiber {
|
4 |
+
|
5 |
+
private $token;
|
6 |
+
const API_URL = "http://api.koiber.com/v1/";
|
7 |
+
const GET = "GET";
|
8 |
+
const POST = "POST";
|
9 |
+
const PUT = "PUT";
|
10 |
+
const DELETE = "DELETE";
|
11 |
+
|
12 |
+
public function __construct($token) {
|
13 |
+
$this->token = $token;
|
14 |
+
}
|
15 |
+
|
16 |
+
public function getToken() {
|
17 |
+
return $this->token;
|
18 |
+
}
|
19 |
+
|
20 |
+
private function get($url, $method, $data = NULL) {
|
21 |
+
$curl = curl_init();
|
22 |
+
$options = array(
|
23 |
+
CURLOPT_URL => self::API_URL . $url,
|
24 |
+
CURLOPT_RETURNTRANSFER => true,
|
25 |
+
CURLOPT_MAXREDIRS => 10,
|
26 |
+
CURLOPT_TIMEOUT => 30,
|
27 |
+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
28 |
+
CURLOPT_CUSTOMREQUEST => $method,
|
29 |
+
CURLOPT_HTTPHEADER => array(
|
30 |
+
"authorization: Basic " . base64_encode($this->token . ":x"),
|
31 |
+
"content-type: application/json"
|
32 |
+
),
|
33 |
+
);
|
34 |
+
if(!empty($data) || $data != NULL) {
|
35 |
+
$options[CURLOPT_POSTFIELDS] = $data;
|
36 |
+
}
|
37 |
+
curl_setopt_array($curl, $options);
|
38 |
+
$response = curl_exec($curl);
|
39 |
+
$err = curl_error($curl);
|
40 |
+
$status = curl_getinfo($curl);
|
41 |
+
curl_close($curl);
|
42 |
+
return new Response($response, $status['http_code'], $err);
|
43 |
+
}
|
44 |
+
|
45 |
+
/* ------------------------- TALKS -------------------- */
|
46 |
+
|
47 |
+
public function getTalks($page = 1, $perPage = 1) {
|
48 |
+
return $this->get("talks?page=$page&per_page=$perPage", Koiber::GET);
|
49 |
+
}
|
50 |
+
|
51 |
+
public function getTalk($id) {
|
52 |
+
return $this->get("talks/$id", Koiber::GET);
|
53 |
+
}
|
54 |
+
|
55 |
+
public function getMsg($id) {
|
56 |
+
return $this->get("talks/messages/$id", Koiber::GET);
|
57 |
+
}
|
58 |
+
|
59 |
+
|
60 |
+
public function createTalk($dados) {
|
61 |
+
return $this->get("talks", Koiber::POST, $dados);
|
62 |
+
}
|
63 |
+
|
64 |
+
public function addMsgTalk($talkID, $dados) {
|
65 |
+
return $this->get("talks/$talkID/messages", Koiber::POST, $dados);
|
66 |
+
}
|
67 |
+
|
68 |
+
public function closeTalk($talkID) {
|
69 |
+
return $this->get("talks/$talkID/close", Koiber::PUT);
|
70 |
+
}
|
71 |
+
|
72 |
+
public function isCloseTalk($talkID) {
|
73 |
+
return $this->get("talks/$talkID/is_closed", Koiber::GET);
|
74 |
+
}
|
75 |
+
|
76 |
+
|
77 |
+
/* ------------------------- USERS -------------------- */
|
78 |
+
|
79 |
+
public function getUsers($page = 1, $perPage = 1) {
|
80 |
+
return $this->get("users?page=$page&per_page=$perPage", Koiber::GET);
|
81 |
+
}
|
82 |
+
|
83 |
+
public function getUser($id) {
|
84 |
+
return $this->get("users/$id", Koiber::GET);
|
85 |
+
}
|
86 |
+
|
87 |
+
public function userIsAuthorized($dado, $getDados = false) {
|
88 |
+
return $this->get("users/exists/$dado?data=$getDados", Koiber::GET);
|
89 |
+
}
|
90 |
+
|
91 |
+
|
92 |
+
/* ------------------------- DEPARTMENTS -------------------- */
|
93 |
+
|
94 |
+
public function getDepartments() {
|
95 |
+
return $this->get("departments", Koiber::GET);
|
96 |
+
}
|
97 |
+
|
98 |
+
public function getDepartment($id) {
|
99 |
+
return $this->get("departments/$id", Koiber::GET);
|
100 |
+
}
|
101 |
+
|
102 |
+
public function createDepartment($name) {
|
103 |
+
$dados = json_encode(array("name" => $name));
|
104 |
+
return $this->get("departments", Koiber::POST, $dados);
|
105 |
+
}
|
106 |
+
|
107 |
+
public function updateDepartment($id, $name) {
|
108 |
+
$dados = json_encode(array("name" => $name));
|
109 |
+
return $this->get("departments/$id", Koiber::PUT, $dados);
|
110 |
+
}
|
111 |
+
|
112 |
+
public function deleteDepartment($id) {
|
113 |
+
return $this->get("departments/$id", Koiber::DELETE);
|
114 |
+
}
|
115 |
+
|
116 |
+
/* ------------------------- CHANNELS -------------------- */
|
117 |
+
|
118 |
+
public function getCannels() {
|
119 |
+
return $this->get("channels", Koiber::GET);
|
120 |
+
}
|
121 |
+
|
122 |
+
public function getCannel($id) {
|
123 |
+
return $this->get("channels/$id", Koiber::GET);
|
124 |
+
}
|
125 |
+
|
126 |
+
public function createCannel($dados) {
|
127 |
+
return $this->get("channels", Koiber::POST, $dados);
|
128 |
+
}
|
129 |
+
|
130 |
+
public function updateCannel($id, $dados) {
|
131 |
+
return $this->get("channels/$id", Koiber::PUT, $dados);
|
132 |
+
}
|
133 |
+
|
134 |
+
public function deleteCannel($id) {
|
135 |
+
return $this->get("channels/$id", Koiber::DELETE);
|
136 |
+
}
|
137 |
+
}
|
lib/koiberPHP/src/Koiber/Message/Message.php
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Message {
|
4 |
+
private $id;
|
5 |
+
/**
|
6 |
+
*
|
7 |
+
* @var DateTime
|
8 |
+
*/
|
9 |
+
private $createdAt;
|
10 |
+
private $author;
|
11 |
+
|
12 |
+
private $type;
|
13 |
+
private $content;
|
14 |
+
private $parent;
|
15 |
+
|
16 |
+
public function getId() {
|
17 |
+
return $this->id;
|
18 |
+
}
|
19 |
+
|
20 |
+
public function getCreatedAt() {
|
21 |
+
return $this->createdAt;
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getAuthor() {
|
25 |
+
return $this->author;
|
26 |
+
}
|
27 |
+
|
28 |
+
public function getType() {
|
29 |
+
return $this->type;
|
30 |
+
}
|
31 |
+
|
32 |
+
public function getContent() {
|
33 |
+
return $this->content;
|
34 |
+
}
|
35 |
+
|
36 |
+
public function getParent() {
|
37 |
+
return $this->parent;
|
38 |
+
}
|
39 |
+
|
40 |
+
public function setId($id) {
|
41 |
+
$this->id = $id;
|
42 |
+
return $this;
|
43 |
+
}
|
44 |
+
|
45 |
+
public function setCreatedAt(DateTime $createdAt) {
|
46 |
+
$this->createdAt = $createdAt;
|
47 |
+
return $this;
|
48 |
+
}
|
49 |
+
|
50 |
+
public function setAuthor($author) {
|
51 |
+
$this->author = $author;
|
52 |
+
return $this;
|
53 |
+
}
|
54 |
+
|
55 |
+
public function setType($type) {
|
56 |
+
$this->type = $type;
|
57 |
+
return $this;
|
58 |
+
}
|
59 |
+
|
60 |
+
public function setContent($content) {
|
61 |
+
$this->content = $content;
|
62 |
+
return $this;
|
63 |
+
}
|
64 |
+
|
65 |
+
public function setParent($parent) {
|
66 |
+
$this->parent = $parent;
|
67 |
+
return $this;
|
68 |
+
}
|
69 |
+
|
70 |
+
public function fromArray(array &$data) {
|
71 |
+
$this->id = $data['id'];
|
72 |
+
$this->author = $data['author'];
|
73 |
+
$this->setCreatedAt(new DateTime($data['created_at']));
|
74 |
+
$this->setType($data['type']);
|
75 |
+
|
76 |
+
if($this->type == Type::TEXT) {
|
77 |
+
$this->setContent($data['content']);
|
78 |
+
} else {
|
79 |
+
$form = new Form();
|
80 |
+
if(isset($data['content']['title'])) {
|
81 |
+
$form->setTitle($data['content']['title']);
|
82 |
+
}
|
83 |
+
$fields = $data['content'];
|
84 |
+
|
85 |
+
if($this->type == Type::FORM) {
|
86 |
+
$fields = $data['content']['elements'];
|
87 |
+
}
|
88 |
+
|
89 |
+
if($fields) {
|
90 |
+
foreach ($fields as $field) {
|
91 |
+
switch ($field['element']) {
|
92 |
+
case "p":
|
93 |
+
$form->addElement(new Paragraph($field['id'], $field['content']));
|
94 |
+
break;
|
95 |
+
case "textarea" :
|
96 |
+
$ta = new Textarea($field['id'], $field['label']);
|
97 |
+
if($field['required']) $ta->setRequired (false);
|
98 |
+
$form->addElement($ta);
|
99 |
+
break;
|
100 |
+
|
101 |
+
case "input":
|
102 |
+
|
103 |
+
break;
|
104 |
+
}
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
$this->setContent($form);
|
109 |
+
}
|
110 |
+
}
|
111 |
+
}
|
lib/koiberPHP/src/Koiber/Message/Talk.php
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Talk {
|
4 |
+
const AUTHOR_COMPANY = "company";
|
5 |
+
const AUTHOR_USER = "user";
|
6 |
+
|
7 |
+
private $id;
|
8 |
+
/**
|
9 |
+
*
|
10 |
+
* @var DateTime
|
11 |
+
*/
|
12 |
+
private $createdAt;
|
13 |
+
/**
|
14 |
+
*
|
15 |
+
* @var User
|
16 |
+
*/
|
17 |
+
private $user;
|
18 |
+
/**
|
19 |
+
*
|
20 |
+
* @var Channel
|
21 |
+
*/
|
22 |
+
private $channel;
|
23 |
+
/**
|
24 |
+
*
|
25 |
+
* @var Branch
|
26 |
+
*/
|
27 |
+
private $branch;
|
28 |
+
private $author;
|
29 |
+
private $title;
|
30 |
+
private $closed = null;
|
31 |
+
private $msgs = array();
|
32 |
+
|
33 |
+
public function Talk() {
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
public function getId() {
|
38 |
+
return $this->id;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function getCreatedAt() {
|
42 |
+
return $this->createdAt;
|
43 |
+
}
|
44 |
+
|
45 |
+
public function getUser() {
|
46 |
+
return $this->user;
|
47 |
+
}
|
48 |
+
|
49 |
+
public function getChannel() {
|
50 |
+
return $this->channel;
|
51 |
+
}
|
52 |
+
|
53 |
+
public function getBranch() {
|
54 |
+
return $this->branch;
|
55 |
+
}
|
56 |
+
|
57 |
+
public function getAuthor() {
|
58 |
+
return $this->author;
|
59 |
+
}
|
60 |
+
|
61 |
+
public function getTitle() {
|
62 |
+
return $this->title;
|
63 |
+
}
|
64 |
+
|
65 |
+
public function getClosed() {
|
66 |
+
return $this->closed;
|
67 |
+
}
|
68 |
+
|
69 |
+
public function getMsgs() {
|
70 |
+
return $this->msgs;
|
71 |
+
}
|
72 |
+
|
73 |
+
public function setId($id) {
|
74 |
+
$this->id = $id;
|
75 |
+
return $this;
|
76 |
+
}
|
77 |
+
|
78 |
+
public function setCreatedAt(DateTime $createdAt) {
|
79 |
+
$this->createdAt = $createdAt;
|
80 |
+
return $this;
|
81 |
+
}
|
82 |
+
|
83 |
+
public function setUser(User $user) {
|
84 |
+
$this->user = $user;
|
85 |
+
return $this;
|
86 |
+
}
|
87 |
+
|
88 |
+
public function setChannel(Channel $channel) {
|
89 |
+
$this->channel = $channel;
|
90 |
+
return $this;
|
91 |
+
}
|
92 |
+
|
93 |
+
public function setBranch(Branch $branch) {
|
94 |
+
$this->branch = $branch;
|
95 |
+
return $this;
|
96 |
+
}
|
97 |
+
|
98 |
+
public function setAuthor($author) {
|
99 |
+
$this->author = $author;
|
100 |
+
return $this;
|
101 |
+
}
|
102 |
+
|
103 |
+
public function setTitle($title) {
|
104 |
+
$this->title = $title;
|
105 |
+
return $this;
|
106 |
+
}
|
107 |
+
|
108 |
+
public function setClosed($closed) {
|
109 |
+
$this->closed = $closed;
|
110 |
+
return $this;
|
111 |
+
}
|
112 |
+
|
113 |
+
public function setMsgs(array $msg) {
|
114 |
+
$this->msgs = $msg;
|
115 |
+
return $this;
|
116 |
+
}
|
117 |
+
|
118 |
+
public function addMsg(Message $msg) {
|
119 |
+
array_push($this->msgs, $msg);
|
120 |
+
return $this;
|
121 |
+
}
|
122 |
+
|
123 |
+
public function fromArray(Array &$data) {
|
124 |
+
$this->id = $data['id'];
|
125 |
+
$this->setCreatedAt(new DateTime($data['created_at']));
|
126 |
+
$this->author = $data['author'];
|
127 |
+
if(isset($data['title'] )) {
|
128 |
+
$this->title = $data['title'];
|
129 |
+
}
|
130 |
+
|
131 |
+
$this->setUser(new User($data['user']));
|
132 |
+
$this->setChannel(new Channel($data['channel']));
|
133 |
+
|
134 |
+
if($data['msg']) {
|
135 |
+
foreach ($data['msg'] as $msg) {
|
136 |
+
$m = new Message();
|
137 |
+
$m->fromArray($msg);
|
138 |
+
$this->addMsg($m);
|
139 |
+
}
|
140 |
+
}
|
141 |
+
}
|
142 |
+
|
143 |
+
}
|
lib/koiberPHP/src/Koiber/Message/Type.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Type {
|
4 |
+
const TEXT = "text";
|
5 |
+
const FORM = "form";
|
6 |
+
const FORM_RESPONSE = "form_resp";
|
7 |
+
}
|
lib/koiberPHP/src/Koiber/Response.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Response {
|
4 |
+
private $response;
|
5 |
+
private $erroRequest;
|
6 |
+
private $status_code;
|
7 |
+
|
8 |
+
public function __construct($response, $status_code, $erro = null) {
|
9 |
+
$this->response = $response;
|
10 |
+
$this->status_code = $status_code;
|
11 |
+
$this->erroRequest = $erro;
|
12 |
+
}
|
13 |
+
|
14 |
+
public function setResponse($response) {
|
15 |
+
$this->response = $response;
|
16 |
+
}
|
17 |
+
|
18 |
+
public function isOk() {
|
19 |
+
if($this->status_code < 300 && $this->status_code >= 200) {
|
20 |
+
return true;
|
21 |
+
}
|
22 |
+
return false;
|
23 |
+
}
|
24 |
+
|
25 |
+
public function getResponseCode() {
|
26 |
+
return $this->status_code;
|
27 |
+
}
|
28 |
+
|
29 |
+
public function getError() {
|
30 |
+
return $this->erroRequest;
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* returns the request content
|
35 |
+
*/
|
36 |
+
public function getBody($json = FALSE) {
|
37 |
+
if($json === FALSE) {
|
38 |
+
return $this->response;
|
39 |
+
}
|
40 |
+
return json_decode($this->response, true);
|
41 |
+
}
|
42 |
+
|
43 |
+
public function getTalk() {
|
44 |
+
$d = json_decode($this->response, true);
|
45 |
+
$talk = new Talk();
|
46 |
+
$talk->fromArray($d);
|
47 |
+
return $talk;
|
48 |
+
}
|
49 |
+
}
|
lib/koiberPHP/src/Koiber/User.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class User {
|
4 |
+
private $id;
|
5 |
+
private $mail;
|
6 |
+
private $phoneDDI;
|
7 |
+
private $phoneNumber;
|
8 |
+
private $name;
|
9 |
+
|
10 |
+
/**
|
11 |
+
*
|
12 |
+
* @var Address
|
13 |
+
*/
|
14 |
+
private $address;
|
15 |
+
|
16 |
+
public function __construct($id) {
|
17 |
+
$this->id = $id;
|
18 |
+
}
|
19 |
+
|
20 |
+
public function getId() {
|
21 |
+
return $this->id;
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getMail() {
|
25 |
+
return $this->mail;
|
26 |
+
}
|
27 |
+
|
28 |
+
public function getPhoneDDI() {
|
29 |
+
return $this->phoneDDI;
|
30 |
+
}
|
31 |
+
|
32 |
+
public function getPhoneNumber() {
|
33 |
+
return $this->phoneNumber;
|
34 |
+
}
|
35 |
+
|
36 |
+
public function getName() {
|
37 |
+
return $this->name;
|
38 |
+
}
|
39 |
+
|
40 |
+
public function getAddress() {
|
41 |
+
return $this->address;
|
42 |
+
}
|
43 |
+
|
44 |
+
public function setId($id) {
|
45 |
+
$this->id = $id;
|
46 |
+
return $this;
|
47 |
+
}
|
48 |
+
|
49 |
+
public function setMail($mail) {
|
50 |
+
$this->mail = $mail;
|
51 |
+
return $this;
|
52 |
+
}
|
53 |
+
|
54 |
+
public function setPhoneDDI($phoneDDI) {
|
55 |
+
$this->phoneDDI = $phoneDDI;
|
56 |
+
return $this;
|
57 |
+
}
|
58 |
+
|
59 |
+
public function setPhoneNumber($phoneNumber) {
|
60 |
+
$this->phoneNumber = $phoneNumber;
|
61 |
+
return $this;
|
62 |
+
}
|
63 |
+
|
64 |
+
public function setAddress(Address $address) {
|
65 |
+
$this->address = $address;
|
66 |
+
return $this;
|
67 |
+
}
|
68 |
+
|
69 |
+
public function setName($name) {
|
70 |
+
$this->name = $name;
|
71 |
+
return $this;
|
72 |
+
}
|
73 |
+
}
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Koiber_TransactionalMessages</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>beta</stability>
|
6 |
+
<license uri="http://www.opensource.org/licenses/mit-license.php">MIT Licence</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Módulo desenvolvido com a finaliade de integrar o aplicativo Koiber com o magento</summary>
|
10 |
+
<description>O módulo captura eventos dos e-mails enviado pelo magento e os envia para o chat do Koiber</description>
|
11 |
+
<notes>First beta release.</notes>
|
12 |
+
<authors><author><name>Koiber</name><user>natan88</user><email>bsbinfor@gmail.com</email></author></authors>
|
13 |
+
<date>2016-06-17</date>
|
14 |
+
<time>22:20:38</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Koiber"><dir name="TransactionalMessages"><dir name="Block"><dir name="Adminhtml"><dir name="Eventos"><dir name="Edit"><file name="Form.php" hash="54c7a5ea31bcf9ca355422cdce777846"/></dir><file name="Edit.php" hash="7b18f476e40a12e1480d9f415bc96cb0"/><file name="Grid.php" hash="d6d6dc39c4abdc20e0143c5888e00646"/><dir name="Renderer"><file name="Status.php" hash="720a2ccf9f4f1ea8b002b422e40f4443"/><file name="Template.php" hash="d50c6cadff650e79fcf3f9d5a9aebd0b"/></dir></dir><file name="Eventos.php" hash="4a140e8ca0eb7904577437a9a505085d"/><dir name="Historico"><file name="Grid.php" hash="1ac115f473f00fd92ef9c14b2bae2395"/><dir name="Renderer"><file name="Template.php" hash="4ce21c22ca9665f45156d089f7c6f544"/></dir></dir><file name="Historico.php" hash="40ee13477b41c82abdaf3958f8eb0723"/><dir name="Mensagem"><dir name="Edit"><file name="Form.php" hash="81ff2b5542e2ce858abf16f9332a5d2c"/></dir><file name="Edit.php" hash="31641f64a3d53d0588b178d00db10fd5"/></dir><dir name="System"><dir name="Config"><file name="Info.php" hash="3919edd6b80d0ac0abce4807aad5064c"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="8beb660b13e52e9b3e58f757e3b53298"/></dir><dir name="Model"><file name="Eventos.php" hash="7960fe35567a24441e856bb9e0e6dcf0"/><file name="Historico.php" hash="83eb4022cf07a8b3cbfbcf7271e7dad0"/><file name="Mensagem.php" hash="06cdc08ec847d6088a45fbfb4d9f1f87"/><dir name="Mysql4"><dir name="Eventos"><file name="Collection.php" hash="287a37939886deca29bf9c73fa52cc41"/></dir><file name="Eventos.php" hash="f056bbd175658eb6038a40435b292d58"/><dir name="Historico"><file name="Collection.php" hash="c9adc529d688069899d089bf24b8ec77"/></dir><file name="Historico.php" hash="3844dc48717c4ae6cf8298cf0915656e"/><dir name="Mensagem"><file name="Collection.php" hash="466f7f6857b8b1c034bcb0a99225e7b4"/></dir><file name="Mensagem.php" hash="c0d10bb352300c3f43a89aecc50292b8"/><dir name="Padrao"><file name="Collection.php" hash="dfcd43dfc161675525c67e3307de7ccc"/></dir><file name="Padrao.php" hash="2c196737d0e92aa8dae34e871df0de89"/></dir><file name="Padrao.php" hash="2c6cd7f975543c51dea6f1436856c929"/></dir><dir name="controllers"><file name="IndexController.php" hash="29e829c559bee782ea8bf0a72f4b5e26"/><file name="KoiberController.php" hash="efc6f978b9a05a2847a6cfd56dff7f26"/></dir><dir name="etc"><file name="adminhtml.xml" hash="06a98659f3561b50d5af87018c76b719"/><file name="config.xml" hash="0cc55316c50eb38d073c7e1c97fb301e"/><file name="system.xml" hash="6ffaf5fa2445f55ed389741458b0953e"/></dir><dir name="sql"><dir name="koiber_transactionalmessages_setup"><file name="mysql4-install-1.0.0.php" hash="901a2592168136fa577d621f1aa37015"/></dir></dir></dir></dir><dir name="Mage"><dir name="Core"><dir name="Model"><dir name="Email"><file name="Template.php" hash="f8386fc13b558eec1fd06d72995c468d"/></dir></dir></dir></dir></target><target name="magelib"><dir name="koiberPHP"><file name="README.md" hash="40313bec4a86fdee191908b2cf4eaa3b"/><dir name="sample"><file name="canal_busca.php" hash="68e49e82140bd17393e265ff061077a4"/><file name="canal_cria.php" hash="b3ee79e9587008de289676be3f06c2e8"/><file name="canal_lista.php" hash="db2713515eed9aca331259a6fdd63732"/><file name="canal_remove.php" hash="a25032855a1d583923468e16156053e5"/><file name="canal_update.php" hash="71dec32d9c28800af920a19b3f27244b"/><file name="config.php" hash="70f95d8e7f3a98e99f7b862c839cabc5"/><file name="departamento_busca.php" hash="bd5787164cf5ceb34ec6defd5182e39f"/><file name="departamento_cria.php" hash="fa0a4581251d08e58c42c62473ce0219"/><file name="departamento_lista.php" hash="9928a1b8dd36070bea6e7dea825bf5b0"/><file name="departamento_remove.php" hash="ffb748ef329537921c75699255dd88c5"/><file name="departamento_update.php" hash="27739c862edc3fade960b8830abf21e9"/><file name="index.php" hash="14cf1ab791e4b8f2cccc8432a8be912c"/><file name="msg_add_msg.php" hash="3846ef01058f9501cb42f655765d101b"/><file name="msg_busca.php" hash="8505251f206573bdb0625df724357c69"/><file name="msg_cria.php" hash="ad38ea6f8ac9fa31fb0cd3a7c7885d1c"/><file name="msg_encerra.php" hash="8b906391ab0e462e4aaf579adc26d0c1"/><file name="msg_foi_encerra.php" hash="40c0d97b210d50a7f0a98d01da56f72e"/><file name="msg_lista.php" hash="6e235317b4859289e3404e4e60fdcf81"/><file name="user_autorizou.php" hash="36b17bfd5a86b7a709779ceb1fb6a7db"/><file name="user_busca.php" hash="d96491e6de99a2d6205957c5bb1dd973"/><file name="user_lista.php" hash="cd212621d75723144ed92687701a14ae"/></dir><dir name="src"><dir name="Koiber"><file name="Address.php" hash="d3aa0bdbf1c77b210479fead4ade1685"/><file name="Autoload.php" hash="33f976602e7d8663a5e20771a97637fe"/><file name="Channel.php" hash="ca05bf204bc4b45502e17f9726690c7e"/><dir name="Form"><file name="Element.php" hash="3edee6cd585c0750cfd07c99d2414d2f"/><file name="Form.php" hash="d6afe10491cc8bb562b3b0e0ad9e732d"/><file name="IElement.php" hash="b64669708c9434bca8f17ed639b7a525"/><file name="Paragraph.php" hash="15bd556209df0374e70236d98250acb5"/><file name="Textarea.php" hash="e6cc7a8eb25eeea86165093ce996f2b3"/></dir><file name="Koiber.php" hash="02d4749c20ce3e60cc087c1bbd0610c4"/><dir name="Message"><file name="Message.php" hash="064dd20ee4767fefdd468be71167e3c7"/><file name="Talk.php" hash="c50eb69090366cbea23a8f40a86ff137"/><file name="Type.php" hash="93d97d01c19fc2aa763e687a126e7b8a"/></dir><file name="Response.php" hash="495d5f3c2d62926c19d6b5ccbc957332"/><file name="User.php" hash="3fb67967a8794fa9e7699385a79ade58"/></dir></dir><file name=".gitignore" hash="3e25d1398e26cebfd58838233e0ce73d"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Koiber_Koiber.csv" hash="8d0b35167f7b1f81449f81b0e20c450f"/></dir></target><target name="mageetc"><dir name="modules"><file name="Koiber_TransactionalMessages.xml" hash="9f24e90f2ff4dabd9d9bb1b397d7814f"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="koiber.xml" hash="34e17a5124df0a3fc03ad031de5bb088"/></dir></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>4.5.5</min><max>7.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|