/src/messenger/webim/operator/settings.php

https://github.com/duk3luk3/mibew · PHP · 107 lines · 75 code · 13 blank · 19 comment · 14 complexity · ce276d976712926fd2cd558a6f5b5feb MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of Mibew Messenger project.
  4. *
  5. * Copyright (c) 2005-2010 Mibew Messenger Community
  6. * All rights reserved. The contents of this file are subject to the terms of
  7. * the Eclipse Public License v1.0 which accompanies this distribution, and
  8. * is available at http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Alternatively, the contents of this file may be used under the terms of
  11. * the GNU General Public License Version 2 or later (the "GPL"), in which case
  12. * the provisions of the GPL are applicable instead of those above. If you wish
  13. * to allow use of your version of this file only under the terms of the GPL, and
  14. * not to allow others to use your version of this file under the terms of the
  15. * EPL, indicate your decision by deleting the provisions above and replace them
  16. * with the notice and other provisions required by the GPL.
  17. *
  18. * Contributors:
  19. * Evgeny Gryaznov - initial API and implementation
  20. */
  21. require_once('../libs/common.php');
  22. require_once('../libs/operator.php');
  23. require_once('../libs/settings.php');
  24. $operator = check_login();
  25. $page = array('agentId' => '');
  26. $errors = array();
  27. $stylelist = array();
  28. $stylesfolder = "../styles";
  29. if($handle = opendir($stylesfolder)) {
  30. while (false !== ($file = readdir($handle))) {
  31. if (preg_match("/^\w+$/", $file) && is_dir("$stylesfolder/$file")) {
  32. $stylelist[] = $file;
  33. }
  34. }
  35. closedir($handle);
  36. }
  37. $options = array(
  38. 'email', 'title', 'logo', 'hosturl', 'usernamepattern',
  39. 'chatstyle', 'chattitle', 'geolink', 'geolinkparams', 'sendmessagekey');
  40. loadsettings();
  41. $params = array();
  42. foreach($options as $opt) {
  43. $params[$opt] = $settings[$opt];
  44. }
  45. if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) {
  46. $params['email'] = getparam('email');
  47. $params['title'] = getparam('title');
  48. $params['logo'] = getparam('logo');
  49. $params['hosturl'] = getparam('hosturl');
  50. $params['usernamepattern'] = getparam('usernamepattern');
  51. $params['chattitle'] = getparam('chattitle');
  52. $params['geolink'] = getparam('geolink');
  53. $params['geolinkparams'] = getparam('geolinkparams');
  54. $params['sendmessagekey'] = verifyparam('sendmessagekey', "/^c?enter$/");
  55. $params['chatstyle'] = verifyparam("chatstyle","/^\w+$/", $params['chatstyle']);
  56. if(!in_array($params['chatstyle'], $stylelist)) {
  57. $params['chatstyle'] = $stylelist[0];
  58. }
  59. if($params['email'] && !is_valid_email($params['email'])) {
  60. $errors[] = getlocal("settings.wrong.email");
  61. }
  62. if($params['geolinkparams']) {
  63. foreach(preg_split("/,/", $params['geolinkparams']) as $oneparam) {
  64. if(!preg_match("/^\s*(toolbar|scrollbars|location|status|menubar|width|height|resizable)=\d{1,4}$/", $oneparam)) {
  65. $errors[] = "Wrong link parameter: \"$oneparam\", should be one of 'toolbar, scrollbars, location, status, menubar, width, height or resizable'";
  66. }
  67. }
  68. }
  69. if (count($errors) == 0) {
  70. foreach($options as $opt) {
  71. $settings[$opt] = $params[$opt];
  72. }
  73. update_settings();
  74. header("Location: $webimroot/operator/settings.php?stored");
  75. exit;
  76. }
  77. }
  78. $page['formemail'] = topage($params['email']);
  79. $page['formtitle'] = topage($params['title']);
  80. $page['formlogo'] = topage($params['logo']);
  81. $page['formhosturl'] = topage($params['hosturl']);
  82. $page['formgeolink'] = topage($params['geolink']);
  83. $page['formgeolinkparams'] = topage($params['geolinkparams']);
  84. $page['formusernamepattern'] = topage($params['usernamepattern']);
  85. $page['formchatstyle'] = $params['chatstyle'];
  86. $page['formchattitle'] = topage($params['chattitle']);
  87. $page['formsendmessagekey'] = $params['sendmessagekey'];
  88. $page['availableStyles'] = $stylelist;
  89. $page['stored'] = isset($_GET['stored']);
  90. prepare_menu($operator);
  91. setup_settings_tabs(0);
  92. start_html_output();
  93. require('../view/settings.php');
  94. ?>