2008-09-30 03:07:06 +04:00
< ? php
/*
2013-03-07 01:22:53 +04:00
* Copyright 2005 - 2013 the original author or authors .
*
* Licensed under the Apache License , Version 2.0 ( the " License " );
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http :// www . apache . org / licenses / LICENSE - 2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an " AS IS " BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
2008-09-30 03:07:06 +04:00
*/
require_once ( '../libs/common.php' );
require_once ( '../libs/operator.php' );
2008-12-24 04:32:42 +03:00
require_once ( '../libs/settings.php' );
2008-09-30 03:07:06 +04:00
$operator = check_login ();
2012-06-27 11:51:16 +04:00
csrfchecktoken ();
2008-09-30 03:07:06 +04:00
$page = array ( 'agentId' => '' );
$errors = array ();
2008-10-15 01:34:27 +04:00
$stylelist = array ();
$stylesfolder = " ../styles " ;
2011-02-26 17:06:19 +03:00
if ( $handle = opendir ( $stylesfolder )) {
2008-10-15 01:34:27 +04:00
while ( false !== ( $file = readdir ( $handle ))) {
if ( preg_match ( " /^ \ w+ $ / " , $file ) && is_dir ( " $stylesfolder / $file " )) {
$stylelist [] = $file ;
}
}
closedir ( $handle );
}
2008-12-09 04:12:08 +03:00
$options = array (
2011-02-26 17:06:19 +03:00
'email' , 'title' , 'logo' , 'hosturl' , 'usernamepattern' ,
'chatstyle' , 'chattitle' , 'geolink' , 'geolinkparams' , 'sendmessagekey' );
2008-12-09 04:12:08 +03:00
2008-09-30 03:07:06 +04:00
loadsettings ();
2008-12-09 04:12:08 +03:00
$params = array ();
2011-02-26 17:06:19 +03:00
foreach ( $options as $opt ) {
2008-12-09 04:12:08 +03:00
$params [ $opt ] = $settings [ $opt ];
}
2008-09-30 03:07:06 +04:00
if ( isset ( $_POST [ 'email' ]) && isset ( $_POST [ 'title' ]) && isset ( $_POST [ 'logo' ])) {
2011-02-26 17:06:19 +03:00
$params [ 'email' ] = getparam ( 'email' );
$params [ 'title' ] = getparam ( 'title' );
$params [ 'logo' ] = getparam ( 'logo' );
$params [ 'hosturl' ] = getparam ( 'hosturl' );
$params [ 'usernamepattern' ] = getparam ( 'usernamepattern' );
$params [ 'chattitle' ] = getparam ( 'chattitle' );
$params [ 'geolink' ] = getparam ( 'geolink' );
2008-12-09 04:12:08 +03:00
$params [ 'geolinkparams' ] = getparam ( 'geolinkparams' );
2009-04-10 20:06:20 +04:00
$params [ 'sendmessagekey' ] = verifyparam ( 'sendmessagekey' , " /^c?enter $ / " );
2008-09-30 03:07:06 +04:00
2011-02-26 17:06:19 +03:00
$params [ 'chatstyle' ] = verifyparam ( " chatstyle " , " /^ \ w+ $ / " , $params [ 'chatstyle' ]);
if ( ! in_array ( $params [ 'chatstyle' ], $stylelist )) {
2008-12-09 04:12:08 +03:00
$params [ 'chatstyle' ] = $stylelist [ 0 ];
2008-10-15 01:34:27 +04:00
}
2011-02-26 17:06:19 +03:00
if ( $params [ 'email' ] && ! is_valid_email ( $params [ 'email' ])) {
$errors [] = getlocal ( " settings.wrong.email " );
}
2008-12-09 04:12:08 +03:00
2011-02-26 17:06:19 +03:00
if ( $params [ 'geolinkparams' ]) {
foreach ( preg_split ( " /,/ " , $params [ 'geolinkparams' ]) as $oneparam ) {
if ( ! preg_match ( " /^ \ s*(toolbar|scrollbars|location|status|menubar|width|height|resizable)= \ d { 1,4} $ / " , $oneparam )) {
2013-09-06 14:23:13 +04:00
$errors [] = " Wrong link parameter: \" " . htmlspecialchars ( $oneparam ) . " \" , should be one of 'toolbar, scrollbars, location, status, menubar, width, height or resizable' " ;
2011-02-26 17:06:19 +03:00
}
}
}
if ( count ( $errors ) == 0 ) {
foreach ( $options as $opt ) {
2008-12-09 04:12:08 +03:00
$settings [ $opt ] = $params [ $opt ];
}
2011-02-26 17:06:19 +03:00
update_settings ();
header ( " Location: $webimroot /operator/settings.php?stored " );
exit ;
}
2008-09-30 03:07:06 +04:00
}
2008-12-09 04:12:08 +03:00
$page [ 'formemail' ] = topage ( $params [ 'email' ]);
$page [ 'formtitle' ] = topage ( $params [ 'title' ]);
2011-02-26 17:06:19 +03:00
$page [ 'formlogo' ] = topage ( $params [ 'logo' ]);
$page [ 'formhosturl' ] = topage ( $params [ 'hosturl' ]);
2008-12-09 04:12:08 +03:00
$page [ 'formgeolink' ] = topage ( $params [ 'geolink' ]);
$page [ 'formgeolinkparams' ] = topage ( $params [ 'geolinkparams' ]);
$page [ 'formusernamepattern' ] = topage ( $params [ 'usernamepattern' ]);
$page [ 'formchatstyle' ] = $params [ 'chatstyle' ];
$page [ 'formchattitle' ] = topage ( $params [ 'chattitle' ]);
2009-04-10 20:06:20 +04:00
$page [ 'formsendmessagekey' ] = $params [ 'sendmessagekey' ];
2008-10-15 01:34:27 +04:00
$page [ 'availableStyles' ] = $stylelist ;
2008-12-24 04:32:42 +03:00
$page [ 'stored' ] = isset ( $_GET [ 'stored' ]);
2008-09-30 03:07:06 +04:00
2009-03-16 04:20:04 +03:00
prepare_menu ( $operator );
2008-12-24 04:32:42 +03:00
setup_settings_tabs ( 0 );
2008-09-30 03:07:06 +04:00
start_html_output ();
require ( '../view/settings.php' );
2012-04-30 19:41:55 +04:00
?>