-
Notifications
You must be signed in to change notification settings - Fork 0
/
IndexController.php
executable file
·49 lines (42 loc) · 2.04 KB
/
IndexController.php
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
<?php
public function postAction()
{
//avoid notices warnings
!isset($_POST['livechat_license_number']) ? $livechat_license_number = '' : $livechat_license_number = $_POST['livechat_license_number'];
!isset($_POST['livechat_groups']) ? $livechat_groups = '0' : $livechat_groups = $_POST['livechat_groups'];
!isset($_POST['livechat_params']) ? $livechat_params = '' : $livechat_params = $_POST['livechat_params'];
$config_table = Mage::getSingleton('core/resource')->getTableName('core_config_data');
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$query = 'SELECT * FROM ' . $config_table;
$query .= ' WHERE scope="default" AND scope_id=0 AND path="livechat/general/license"';
$results = $read->fetchAll($query);
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
//check for existing configurations
if ($row = array_pop($results)) {
$license_id = $row['config_id'];
$query = 'UPDATE ' . $config_table;
$query .= ' SET value="' . $livechat_license_number . '"';
$query .= ' WHERE config_id=' . $license_id;
$write->query($query);
$query = 'UPDATE ' . $config_table;
$query .= ' SET value="' . $livechat_groups . '"';
$query .= ' WHERE config_id=' . ++$license_id;
$write->query($query);
$query = 'UPDATE ' . $config_table;
$query .= ' SET value="' . $livechat_params . '"';
$query .= ' WHERE config_id=' . ++$license_id;
$write->query($query);
}
else {
$query = 'INSERT INTO ' . $config_table;
$query .= ' (scope, scope_id, path, value)';
$query .= ' VALUES ("default", 0, "livechat/general/license", "' . $livechat_license_number . '"),';
$query .= ' ("default", 0, "livechat/advanced/group", "0"),';
$query .= ' ("default", 0, "livechat/advanced/params", "")';
$write->query($query);
}
// Refresh the config.
Mage::getConfig()->cleanCache();
Mage::getConfig()->reinit();
$this->_redirect('*/*/index');
}