From f904f05dc9292dd543040c6a6c0b6a256dcb57db Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 15 Feb 2013 14:25:42 +0000 Subject: [PATCH] Update setup_leavemessage function to return data --- src/messenger/webim/client.php | 5 ++- src/messenger/webim/leavemessage.php | 5 ++- src/messenger/webim/libs/chat.php | 46 +++++++++++++++++++--------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php index a440b078..2270f941 100644 --- a/src/messenger/webim/client.php +++ b/src/messenger/webim/client.php @@ -89,7 +89,10 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { if(!has_online_operators($groupid)) { $page = array(); setup_logo($group); - setup_leavemessage($visitor['name'],$email,$firstmessage,$groupid,$groupname,$info,$referrer,can_show_captcha()); + $page = array_merge_recursive( + $page, + setup_leavemessage($visitor['name'],$email,$firstmessage,$groupid,$groupname,$info,$referrer) + ); expand("styles/dialogs", getchatstyle(), "leavemessage.tpl"); exit; } diff --git a/src/messenger/webim/leavemessage.php b/src/messenger/webim/leavemessage.php index f5df8f9e..9e1ea739 100644 --- a/src/messenger/webim/leavemessage.php +++ b/src/messenger/webim/leavemessage.php @@ -99,7 +99,10 @@ if(Settings::get("enablecaptcha") == "1" && can_show_captcha()) { } if( count($errors) > 0 ) { - setup_leavemessage($visitor_name,$email,$message,$groupid,$groupname,$info,$referrer,can_show_captcha()); + $page = array_merge_recursive( + $page, + setup_leavemessage($visitor_name,$email,$message,$groupid,$groupname,$info,$referrer) + ); setup_logo($group); expand("styles/dialogs", getchatstyle(), "leavemessage.tpl"); exit; diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index 3c45783d..e249e600 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -137,27 +137,43 @@ function setup_logo($group = NULL) $page['webimHost'] = topage(empty($toplevelgroup['vchosturl'])?Settings::get('hosturl'):$toplevelgroup['vchosturl']); } -function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info, $referrer, $canshowcaptcha) -{ - global $page; - $page['formname'] = topage($name); - $page['formemail'] = topage($email); - $page['formmessage'] = $message ? topage($message) : ""; - $page['showcaptcha'] = Settings::get("enablecaptcha") == "1" && $canshowcaptcha ? "1" : ""; - $page['formgroupid'] = $groupid; - $page['formgroupname'] = $groupname; - $page['forminfo'] = topage($info); - $page['referrer'] = urlencode(topage($referrer)); +/** + * Prepare data to display leave message form + * + * @param string $name User name + * @param string $email User email + * @param string $message First message text + * @param int $groupid Id of selected group + * @param string $groupname Name of selected group + * @param string $info User info + * @param string $referrer URL of referrer page + * @return array Array of leave message form data + * + * @todo Think about $info param. It seems to this param is meaningless. + */ +function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info, $referrer) { + $data = array(); + + $canshowcaptcha = can_show_captcha(); + $data['formname'] = topage($name); + $data['formemail'] = topage($email); + $data['formmessage'] = $message ? topage($message) : ""; + $data['showcaptcha'] = Settings::get("enablecaptcha") == "1" && $canshowcaptcha ? "1" : ""; + $data['formgroupid'] = $groupid; + $data['formgroupname'] = $groupname; + $data['forminfo'] = topage($info); + $data['referrer'] = urlencode(topage($referrer)); if (Settings::get('enablegroups') == '1') { $groups = setup_groups_select($groupid, false); if ($groups) { - $page['groups'] = $groups['select']; - $page['group.descriptions'] = json_encode($groups['descriptions']); - $page['default.department.description'] = $groups['defaultdescription']; + $data['groups'] = $groups['select']; + $data['group.descriptions'] = json_encode($groups['descriptions']); + $data['default.department.description'] = $groups['defaultdescription']; } } + return $data; } /** @@ -170,7 +186,7 @@ function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info * @param string $referrer URL of referrer page * @return array Array of survey data * - * @todo Think about $info param. It seems to be meaningless. + * @todo Think about $info param. It seems to this param is meaningless. */ function setup_survey($name, $email, $groupid, $info, $referrer) { $data = array();