-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.php.bak
351 lines (280 loc) · 13.4 KB
/
controller.php.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<?php
require_once 'models/libs/errors/debug.class.php';
require_once 'gglms.conf.php';
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controller');
class gglmsController extends JController {
private $_japp;
public function __construct($config = array()) {
parent::__construct($config);
debug::init();
debug::start(DEBUG_STRATEGY, array('debug_level' => DEBUG_LEVEL));
debug::client_info();
debug::vardump(JRequest::getWord('task'), 'task');
$document = JFactory::getDocument();
$document->addScript('components/com_gglms/js/jquery.min.js');
$document->addStyleSheet('components/com_gglms/css/jquery-ui.css');
$document->addScriptDeclaration('jQuery.noConflict();');
$this->_japp = JFactory::getApplication();
$this->registerTask('corso', 'corso');
$this->registerTask('elemento', 'elemento');
$this->registerTask('coupon', 'coupon');
$this->registerTask('check_coupon', 'check_coupon');
$this->registerTask('generatecoupon', 'generatecoupon');
$this->registerTask('updateTrack', 'updateTrack');
$this->registerTask('enablecoupon', 'enablecoupon');
$this->registerTask('attestato', 'attestato');
$this->registerTask('helpdesk', 'helpdesk');
$this->registerTask('helpdesksubmit', 'helpdesksubmit');
$this->registerTask('openelement', 'openelement');
$this->registerTask('closeelement', 'closeelement');
$this->registerTask('switchviewmode', 'switchviewmode');
}
public function __destruct() {
//debug::end(/*DEBUG_STRATEGY*/'log');
debug::chuck_norris();
}
public function corso() {
JRequest::setVar('view', 'corso');
parent::display();
// $view =& $this->getView('corso', 'html');
// $view->display();
}
public function openelement() {
JRequest::setVar('view', 'corso');
$model = $this->getModel('corso');
if ($model->open_all_element())
$this->_japp->enqueueMessage('Grazie per aver sbloccato il corso');
else
$this->_japp->enqueueMessage('Errore nello sblocco del corso, contatta un amministratore', 'error');
parent::display();
}
public function closeelement() {
JRequest::setVar('view', 'corso');
$model = $this->getModel('corso');
if ($model->close_all_element())
$this->_japp->enqueueMessage('Grazie per aver bloccato il corso');
else
$this->_japp->enqueueMessage('Errore nello blocco del corso, contattaun amministratore', 'error');
parent::display();
}
public function helpdesk() {
JRequest::setVar('view', 'helpdesk');
parent::display();
}
public function helpdesksubmit() {
JRequest::setVar('view', 'helpdesk');
$app = &JFactory::getApplication();
require_once('models/libs/sendmail.class.php');
require_once('models/libs/smarty/EasySmarty.class.php');
// $mail = new sendmail(MIME_HTML);
// $mail->from($_POST['fromname'], $_POST['frommail']);
// $mail->to($_POST['tomail'], RCPT_TO);
// $mail->subject('Richiesta assistenza');
// $smarty = new EasySmarty();
// $smarty->assign('data', $_POST);
// $mail->body($smarty->fetch_template('helpdesk_mail.tpl', null, true, false, 0));
// if (!$mail->send())
// throw new RuntimeException('Error sending mail', E_USER_ERROR);
//echo var_export($_POST, true);
//$app->close();
//// NOVITA' INSERIMENTO ////
$mailer = JFactory::getMailer();
$mailer->setSender($_POST['frommail']);
$recipient = array($_POST['tomail']);
$mailer->addRecipient($recipient);
$mailer->setSubject('Richiesta assistenza');
$smarty = new EasySmarty();
$smarty->assign('data', $_POST);
$mailer->setBody($smarty->fetch_template('helpdesk_mail.tpl', null, true, false, 0));
if (!$mailer->Send())
throw new RuntimeException('Error sending mail', E_USER_ERROR);
$app->close();
parent::display('helpdesk');
}
public function elemento() {
JRequest::setVar('view', 'elemento');
parent::display();
}
public function coupon() {
JRequest::setVar('view', 'coupon');
parent::display();
}
public function check_coupon() {
$app = &JFactory::getApplication();
$coupon = JRequest::getVar('coupon');
$model = $this->getModel('coupon');
$dettagli_coupon = $model->check_Coupon($coupon);
if (empty($dettagli_coupon)) {
$results['report'] = "<p> Il coupon inserito non è valido o è già stato utilizzato. (COD. 01)</p>";
$results['valido'] = 0;
} else {
if (!$dettagli_coupon['abilitato']) {
$results['report'] = "<p> Il coupon è in attesa di abilitazione. (COD. 03)</p>";
$results['valido'] = 0;
} else {
$model->assegnaCoupon($dettagli_coupon['coupon']);
$model->iscriviUtente($dettagli_coupon['corsi_abilitati']);
$model->set_user_groups($dettagli_coupon['coupon']);
$results['valido'] = 1;
$results['report'] = "<p> Coupon valido. (COD.04)</p>";
$results['report'] .= $model->get_listaCorsiFast($dettagli_coupon['corsi_abilitati']);
}
}
echo json_encode($results);
$app->close();
}
/*
* Aggiorna il tempo di permanenza sul contenuto
*
*/
public function updateTrack() {
//funzione AJAX richiamata dall'elemento ogni cambio slide solo per la prima volta che viene visto il contenuto
$japp = & JFactory::getApplication();
$db = & JFactory::getDbo();
$secondi = JRequest::getVar('secondi');
$stato = JRequest::getVar('stato');
$id_elemento = JRequest::getVar('id_elemento');
$user = & JFactory::getUser();
$user_id = $user->get('id');
try {
if ($stato == 0) {
$query = '
UPDATE #__gg_track
set tview = ' . $secondi . '
WHERE id_elemento= ' . $id_elemento . ' AND
id_utente=' . $user_id . ' LIMIT 1';
} else {
$query = '
UPDATE #__gg_track
set tview = ' . $secondi . ',
stato = 1
WHERE id_elemento= ' . $id_elemento . ' AND
id_utente=' . $user_id . ' LIMIT 1';
}
debug::msg($query);
$db->setQuery($query);
if (false === ($results = $db->query()))
throw new RuntimeException($db->getErrorMsg(), E_USER_ERROR);
echo 1;
} catch (Exception $e) {
debug::exception($e);
echo 0;
}
$japp->close();
}
public function attestato() {
JRequest::setVar('view', 'attestato');
parent::display();
}
public function switchviewmode() {
$japp = & JFactory::getApplication();
$session = & JFactory::getSession();
$tpl = JRequest::getVar('tpl');
if ($tpl == 'flash' || $tpl == 'html5') {
$session->set('gg_elemento', $tpl);
}
$japp->close();
}
/**
* Task che esegue la generazione dei numero di coupon.
* Viene eseguito in maniera ajax e legge da get la stringa contenente l'XML in base64
*
* @param unknown_type $cachable
*/
function generatecoupon() {
try {
$app = & JFactory::getApplication();
$dbg = JRequest::getBool('dbg', 0);
// debug::startNested('log', array('debug_level' => $dbg?E_ALL|E_STRICT|DEBUG_INFO|DEBUG_LOG:0, 'logfile' => DEBUG_LOG_FILE, 'append' => false), 'coupon');
$data_base64 = JRequest::getVar('data', null);
// FB::log($data_base64, 'data_base64');
// debug::vardump($data_base64, 'data_base64');
if (!isset($data_base64))
throw new DomainException('No data sent', E_USER_ERROR);
if (false === ($data = base64_decode($data_base64)))
throw new DomainException('Invalid encoded string sent: ' . $data_base64, E_USER_ERROR);
// debug::vardump($data, 'data');
// FB::log($data, 'data');
$xml = new DOMDocument();
$xml->loadXML($data);
$xml_data = array();
// debug::msg('id_iscrizione: ' . $xml->getElementsByTagName('id_iscrizione')->item(0)->nodeValue);
$xml_data['transition_id'] = filter_var($xml->getElementsByTagName('id_iscrizione')->item(0)->nodeValue, FILTER_SANITIZE_STRING);
if (empty($xml_data['transition_id']))
throw new DomainException('id_iscrizione not set or is not valid'.$xml_data['transition_id'], E_USER_ERROR);
$xml_data['course_id'] = filter_var($xml->getElementsByTagName('id_corso')->item(0)->nodeValue, FILTER_SANITIZE_STRING);
if (empty($xml_data['course_id']))
throw new DomainException('id_corso not set or is not valid', E_USER_ERROR);
$xml_data['ragione_sociale'] = $xml->getElementsByTagName('ragione_sociale')->item(0)->nodeValue;
if (empty($xml_data['ragione_sociale']))
throw new DomainException('ragione sociale not set or is not valid', E_USER_ERROR);
$xml_data['username'] = $xml->getElementsByTagName('piva')->item(0)->nodeValue;
if (empty($xml_data['username']))
throw new DomainException('piva not set or is not valid', E_USER_ERROR);
$xml_data['coupon_number'] = filter_var($xml->getElementsByTagName('coupon')->item(0)->nodeValue, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1)));
if (empty($xml_data['coupon_number']))
throw new DomainException('coupon not set or is not valid', E_USER_ERROR);
$xml_data['email'] = filter_var($xml->getElementsByTagName('email')->item(0)->nodeValue, FILTER_VALIDATE_EMAIL);
if (empty($xml_data['email']))
throw new DomainException('email not set or is not valid', E_USER_ERROR);
$xml_data['id_associazione'] = filter_var($xml->getElementsByTagName('id')->item(0)->nodeValue, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1)));
if (empty($xml_data['id_associazione']))
throw new DomainException('id not set or is not valid', E_USER_ERROR);
$xml_data['attestato'] = filter_var($xml->getElementsByTagName('attestato')->item(0)->nodeValue, FILTER_VALIDATE_BOOLEAN);
if (is_null($xml_data['attestato']))
throw new DomainException('attestato not set or is not valid', E_USER_ERROR);
debug::vardump($xml_data, 'xml_data');
$model = $this->getModel('generatecoupon');
$ret = ($model->insert_coupons($xml_data) ? 'ok' : 'no');
// debug::vardump($ret, 'return');
} catch (Exception $e) {
// debug::exception($e);
$ret = 'no';
}
//header('content-type: application/json; charset=utf-8');
//echo $_GET['callback'] . '(' . json_encode($ret) . ')';
echo $ret;
//debug::end('log', 'coupon');
$app->close();
}
public function enablecoupon() {
try {
fopen(DEBUG_LOG_FILE, 'w');
$app = &JFactory::getApplication();
$data_base64 = JRequest::getVar('data', null);
$this->_logger($data_base64);
if (!isset($data_base64))
throw new DomainException('Param data not set', E_USER_ERROR);
if (false === ($data = base64_decode($data_base64)))
throw new DomainException('Param data is not valid', E_USER_ERROR);
$this->_logger($data);
$xml = new DOMDocument();
$xml->loadXML($data);
$xml_data = array();
$xml_data['id_associazione'] = filter_var($xml->getElementsByTagName('id')->item(0)->nodeValue, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1)));
if (empty($xml_data['id_associazione']))
throw new DomainException('id not set or is not valid', E_USER_ERROR);
$xml_data['transition_id'] = filter_var($xml->getElementsByTagName('id_iscrizione')->item(0)->nodeValue, FILTER_SANITIZE_STRING);
if (empty($xml_data['transition_id']))
throw new DomainException('id_iscrizione not set or is not valid', E_USER_ERROR);
$xml_data['token'] = $xml->getElementsByTagName('token')->item(0)->nodeValue;
$this->_logger($xml_data['token']);
if (empty($xml_data['token']))
throw new DomainException('token not set or not valid', E_USER_ERROR);
$model = $this->getModel('enablecoupon');
echo ($model->enable_coupons($xml_data) ? 'ok' : 'no');
} catch (Exception $e) {
echo 'no';
$this->_logger($e);
}
$app->close();
}
private function _logger($msg) {
if ($this->_dbg) {
if (!is_string($msg))
$msg = var_export($msg, true);
error_log($msg . "\n", 3, DEBUG_LOG_FILE);
}
}
}