From be3efcfad3f7b0697d458682e847b080a2b5f700 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 26 Jan 2012 21:29:26 +0000 Subject: [PATCH] Adding canned messages during system installation process --- src/messenger/webim/install/index.php | 23 ++++++++++++++++++++++ src/messenger/webim/libs/canned.php | 28 --------------------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/messenger/webim/install/index.php b/src/messenger/webim/install/index.php index 13e84e40..fa68a531 100644 --- a/src/messenger/webim/install/index.php +++ b/src/messenger/webim/install/index.php @@ -256,6 +256,27 @@ function check_admin($link) return false; } +function add_canned_messages($link){ + global $mysqlprefix; + foreach (get_available_locales() as $locale) { + $result = array(); + foreach (explode("\n", getstring_('chat.predefined_answers', $locale)) as $answer) { + $result[] = array('id' => '', 'vcvalue' => $answer); + } + if (count($result) > 0) { + $updatequery = "insert into ${mysqlprefix}chatresponses (vcvalue,locale,groupid) values "; + for ($i = 0; $i < count($result); $i++) { + if ($i > 0) { + $updatequery .= ", "; + } + $updatequery .= "('" . db_escape_string($result[$i]['vcvalue'], $link) . "','$locale', NULL)"; + } + mysql_query($updatequery, $link); + } + } + return; +} + function check_status() { global $page, $webimroot, $settings, $dbversion; @@ -290,6 +311,8 @@ function check_status() return; } + add_canned_messages($link); + check_sound(); $page['done'][] = getlocal("installed.message"); diff --git a/src/messenger/webim/libs/canned.php b/src/messenger/webim/libs/canned.php index 197fd069..a7b9648d 100644 --- a/src/messenger/webim/libs/canned.php +++ b/src/messenger/webim/libs/canned.php @@ -31,34 +31,6 @@ function load_canned_messages($locale, $groupid) ") order by vcvalue"; $result = select_multi_assoc($query, $link); close_connection($link); - if (!$groupid && count($result) == 0) { - $result = load_default_canned_messages($locale); - } - return $result; -} - -function load_default_canned_messages($locale) -{ - global $mysqlprefix; - $link = connect(); - $result = array(); - foreach (explode("\n", getstring_('chat.predefined_answers', $locale)) as $answer) { - $result[] = array('id' => '', 'vcvalue' => $answer); - } - if (count($result) > 0) { - $updatequery = "insert into ${mysqlprefix}chatresponses (vcvalue,locale,groupid) values "; - for ($i = 0; $i < count($result); $i++) { - if ($i > 0) { - $updatequery .= ", "; - } - $updatequery .= "('" . db_escape_string($result[$i]['vcvalue'], $link) . "','$locale', NULL)"; - } - perform_query($updatequery, $link); - $query = "select id, vcvalue from ${mysqlprefix}chatresponses " . - "where locale = '" . $locale . "' AND (groupid is NULL OR groupid = 0) order by vcvalue"; - $result = select_multi_assoc($query, $link); - } - close_connection($link); return $result; }