diff --git a/src/messenger/tests/webim/libs/classes/SettingsTest.php b/src/messenger/tests/webim/libs/classes/SettingsTest.php new file mode 100644 index 00000000..8a21db9e --- /dev/null +++ b/src/messenger/tests/webim/libs/classes/SettingsTest.php @@ -0,0 +1,67 @@ +query( + "INSERT INTO {chatconfig} (vckey, vcvalue) " . + "VALUES (?, ?)", + array('some_test_key', 'some_test_value') + ); + } + + public static function tearDownAfterClass() { + $db = Database::getInstance(); + $db->query( + "DELETE FROM {chatconfig} WHERE vckey = ? OR vckey = ?", + array('some_test_key', 'some_another_test_key') + ); + } + + public function testGet() { + $this->assertEquals('some_test_value', Settings::get('some_test_key')); + } + + public function testSet() { + Settings::set('some_test_key', 'some_another_value'); + $this->assertEquals('some_another_value', Settings::get('some_test_key')); + Settings::set('some_test_key', 'some_test_value'); + } + + public function testUpdate() { + $db = Database::getInstance(); + Settings::set('some_test_key', 'some_value_for_update'); + Settings::set('some_another_test_key', 'some_another_value_for_update'); + Settings::update(); + list($count) = $db->query( + "SELECT COUNT(*) FROM {chatconfig} WHERE vckey = ? AND vcvalue = ?", + array('some_test_key', 'some_value_for_update'), + array( + 'return_rows' => Database::RETURN_ONE_ROW, + 'fetch_type' => Database::FETCH_NUM + ) + ); + $this->assertEquals(1, $count); + list($count) = $db->query( + "SELECT COUNT(*) FROM {chatconfig} WHERE vckey = ? AND vcvalue = ?", + array('some_another_test_key', 'some_another_value_for_update'), + array( + 'return_rows' => Database::RETURN_ONE_ROW, + 'fetch_type' => Database::FETCH_NUM + ) + ); + $this->assertEquals(1, $count); + } + +} + +?> diff --git a/src/messenger/webim/libs/classes/settings.php b/src/messenger/webim/libs/classes/settings.php new file mode 100644 index 00000000..981cf410 --- /dev/null +++ b/src/messenger/webim/libs/classes/settings.php @@ -0,0 +1,168 @@ +settings = array( + 'dbversion' => 0, + 'featuresversion' => 0, + 'title' => 'Your Company', + 'hosturl' => 'http://mibew.org', + 'logo' => '', + 'usernamepattern' => '{name}', + 'chatstyle' => 'default', + 'chattitle' => 'Live Support', + 'geolink' => 'http://api.hostip.info/get_html.php?ip={ip}', + 'geolinkparams' => 'width=440,height=100,toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1', + 'max_uploaded_file_size' => 100000, + 'max_connections_from_one_host' => 10, + 'thread_lifetime' => 600, + + 'email' => '', /* inbox for left messages */ + 'left_messages_locale' => $home_locale, + 'sendmessagekey' => 'center', + + 'enableban' => '0', + 'enablessl' => '0', + 'forcessl' => '0', + 'usercanchangename' => '1', + 'enablegroups' => '0', + 'enablegroupsisolation' => '0', + 'enablestatistics' => '1', + 'enabletracking' => '0', + 'enablepresurvey' => '1', + 'surveyaskmail' => '0', + 'surveyaskgroup' => '1', + 'surveyaskmessage' => '0', + 'enablepopupnotification' => '0', + 'showonlineoperators' => '0', + 'enablecaptcha' => '0', + + 'online_timeout' => 30, /* Timeout (in seconds) when online operator becomes offline */ + 'updatefrequency_operator' => 2, + 'updatefrequency_chat' => 2, + 'updatefrequency_oldchat' => 7, + + 'updatefrequency_tracking' => 10, + 'visitors_limit' => 20, /* Number of visitors to look over */ + 'invitation_lifetime' => 60, /* Lifetime for invitation to chat */ + 'tracking_lifetime' => 600, /* Time to store tracked old visitors' data */ + ); + + // Load values from database + $db = Database::getInstance(); + $rows = $db->query( + "select vckey,vcvalue from {chatconfig}", + NULL, + array('return_rows' => Database::RETURN_ALL_ROWS) + ); + + foreach ($rows as $row) { + $name = $row['vckey']; + $this->settings[$name] = $row['vcvalue']; + $this->settingsInDb[$name] = true; + } + } + + /** + * Get setting value. + * + * @param string $name Variable's name + * @return mixed + */ + public static function get($name) { + $instance = self::getInstance(); + return $instance->settings[$name]; + } + + /** + * Set setting value. + * + * @param string $name Variables's name + * @param mixed $value Variable's value + */ + public static function set($name, $value) { + $instance = self::getInstance(); + $instance->settings[$name] = $value; + } + + /** + * Updates settings in database. + */ + public static function update() { + $instance = self::getInstance(); + $db = Database::getInstance(); + foreach ($instance->settings as $key => $value) { + if (!isset($instance->settingsInDb[$key])) { + $db->query( + "insert into {chatconfig} (vckey) values (?)", + array($key) + ); + } + $db->query( + "update {chatconfig} set vcvalue=? where vckey=?", + array($value, $key) + ); + } + } + + /** + * Implementation of destructor + */ + public function __destruct() {} +} + +?> \ No newline at end of file