From b8b73e82fed95b1a1fd5f7ea59d779437b3f6b8a Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 15 Feb 2013 13:43:52 +0000 Subject: [PATCH] Update setup_survey function to return data --- src/messenger/webim/client.php | 5 +++- src/messenger/webim/libs/chat.php | 41 ++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php index 3c9d3b98..a440b078 100644 --- a/src/messenger/webim/client.php +++ b/src/messenger/webim/client.php @@ -99,7 +99,10 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { if(Settings::get('enablepresurvey') == '1' && !(isset($_POST['survey']) && $_POST['survey'] == 'on') && !$visitor_is_invited) { $page = array(); setup_logo($group); - setup_survey($visitor['name'], $email, $groupid, $info, $referrer); + $page = array_merge_recursive( + $page, + setup_survey($visitor['name'], $email, $groupid, $info, $referrer) + ); expand("styles/dialogs", getchatstyle(), "survey.tpl"); exit; } diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index 5ce9dbe2..3c45783d 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -160,28 +160,41 @@ function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info } -function setup_survey($name, $email, $groupid, $info, $referrer) -{ - global $page; +/** + * Prepare data to dispaly pre-chat survey + * + * @param string $name User name + * @param string $email User email + * @param int $groupid Id of selected group + * @param string $info User info + * @param string $referrer URL of referrer page + * @return array Array of survey data + * + * @todo Think about $info param. It seems to be meaningless. + */ +function setup_survey($name, $email, $groupid, $info, $referrer) { + $data = array(); - $page['formname'] = topage($name); - $page['formemail'] = topage($email); - $page['formgroupid'] = $groupid; - $page['forminfo'] = topage($info); - $page['referrer'] = urlencode(topage($referrer)); + $data['formname'] = topage($name); + $data['formemail'] = topage($email); + $data['formgroupid'] = $groupid; + $data['forminfo'] = topage($info); + $data['referrer'] = urlencode(topage($referrer)); if (Settings::get('enablegroups') == '1' && Settings::get('surveyaskgroup') == '1') { $groups = setup_groups_select($groupid, true); 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']; } } - $page['showemail'] = Settings::get("surveyaskmail") == "1" ? "1" : ""; - $page['showmessage'] = Settings::get("surveyaskmessage") == "1" ? "1" : ""; - $page['showname'] = Settings::get('usercanchangename') == "1" ? "1" : ""; + $data['showemail'] = Settings::get("surveyaskmail") == "1" ? "1" : ""; + $data['showmessage'] = Settings::get("surveyaskmessage") == "1" ? "1" : ""; + $data['showname'] = Settings::get('usercanchangename') == "1" ? "1" : ""; + + return $data; } function setup_groups_select($groupid, $markoffline)