PageRenderTime 57ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/zarafa-7.0.8/php-webclient-ajax/client/layout/dialogs/utils.php

#
PHP | 134 lines | 83 code | 1 blank | 50 comment | 0 complexity | 7125f101efd9dfbfe073a4fa2a1cb480 MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright 2005 - 2012 Zarafa B.V.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License, version 3,
  7. * as published by the Free Software Foundation with the following additional
  8. * term according to sec. 7:
  9. *
  10. * According to sec. 7 of the GNU Affero General Public License, version
  11. * 3, the terms of the AGPL are supplemented with the following terms:
  12. *
  13. * "Zarafa" is a registered trademark of Zarafa B.V. The licensing of
  14. * the Program under the AGPL does not imply a trademark license.
  15. * Therefore any rights, title and interest in our trademarks remain
  16. * entirely with us.
  17. *
  18. * However, if you propagate an unmodified version of the Program you are
  19. * allowed to use the term "Zarafa" to indicate that you distribute the
  20. * Program. Furthermore you may use our trademarks where it is necessary
  21. * to indicate the intended purpose of a product or service provided you
  22. * use it in accordance with honest practices in industrial or commercial
  23. * matters. If you want to propagate modified versions of the Program
  24. * under the name "Zarafa" or "Zarafa Server", you may only do so if you
  25. * have a written permission by Zarafa B.V. (to acquire a permission
  26. * please contact Zarafa at trademark@zarafa.com).
  27. *
  28. * The interactive user interface of the software displays an attribution
  29. * notice containing the term "Zarafa" and/or the logo of Zarafa.
  30. * Interactive user interfaces of unmodified and modified versions must
  31. * display Appropriate Legal Notices according to sec. 5 of the GNU
  32. * Affero General Public License, version 3, when you propagate
  33. * unmodified or modified versions of the Program. In accordance with
  34. * sec. 7 b) of the GNU Affero General Public License, version 3, these
  35. * Appropriate Legal Notices must retain the logo of Zarafa or display
  36. * the words "Initial Development by Zarafa" if the display of the logo
  37. * is not reasonably feasible for technical reasons. The use of the logo
  38. * of Zarafa in Legal Notices is allowed for unmodified and modified
  39. * versions of the software.
  40. *
  41. * This program is distributed in the hope that it will be useful,
  42. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  44. * GNU Affero General Public License for more details.
  45. *
  46. * You should have received a copy of the GNU Affero General Public License
  47. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  48. *
  49. */
  50. ?>
  51. <?php
  52. // Constants for regular expressions which are used in get method to verify the input string
  53. define("ID_REGEX", "/^[a-z0-9_]+$/im");
  54. define("STRING_REGEX", "/^[a-z0-9_\s()@]+$/im");
  55. define("ALLOWED_EMAIL_CHARS_REGEX", "/^[-a-z0-9_\.@!#\$%&'\*\+/=\?\^_`\{\|\}~]+$/im");
  56. define("TIMESTAMP_REGEX", "/^[0-9]+$/im");
  57. define("NUMERIC_REGEX", "/^[0-9]+$/im");
  58. // Don't allow "\/:*?"<>|" characters in filename.
  59. define("FILENAME_REGEX", "/^[^\/\:\*\?\"\<\>\|\\\]+$/im");
  60. /**
  61. * Function to retrieve a $_GET variable to prevent XSS
  62. *
  63. * $var = varibale requested
  64. * $default = default result when $var doesn't exist
  65. * $usequote = if $var must be surrounded by quotes, note that $default isn't surrounded by quotes even if this is set here!
  66. * $regex = To prevent unusual hackers attack / validate the values send from client.
  67. */
  68. function get($var, $default="", $usequote=false, $regex = false){
  69. $result = $default;
  70. if (isset($_GET[$var])){
  71. $result = addslashes($_GET[$var]);
  72. if($regex) {
  73. $match = preg_match_all($regex, $result, $matches);
  74. if(!$match){
  75. $result = false;
  76. $usequote = false;
  77. }
  78. }
  79. if ($usequote===true)
  80. $usequote = "'";
  81. if ($usequote!==false)
  82. $result = $usequote.$result.$usequote;
  83. }
  84. return $result;
  85. }
  86. function createConfirmButtons($onclick)
  87. {
  88. $buttons = "<div class=\"confirmbuttons\">\n";
  89. $buttons .= "<input class=\"buttonsize\" type=\"button\" value=\"" . _("Ok") . "\" onclick=\"" . $onclick . "\">\n";
  90. $buttons .= "<input class=\"buttonsize\" type=\"button\" value=\"". _("Cancel") . "\" onclick=\"window.close();\">\n";
  91. $buttons .= "</div>\n";
  92. return $buttons;
  93. }
  94. function createCloseButton($onclick)
  95. {
  96. $buttons = "<div class=\"closebutton\">\n";
  97. $buttons .= "<input class=\"buttonsize\" type=\"button\" value=\"" . _("Close") . "\" onclick=\"" . $onclick . "\">\n";
  98. $buttons .= "</div>\n";
  99. return $buttons;
  100. }
  101. /**
  102. * Function to get some buttons
  103. *
  104. * one button is specified as an array argument, use multiple arguments for more buttons
  105. *
  106. * array("title"=>"Ok", "handler"=>"submit();", "shortcut"=>"S")
  107. */
  108. function createButtons()
  109. {
  110. $argc = func_num_args();
  111. $argv = func_get_args();
  112. $buttons = "<div class=\"buttons\">\n";
  113. for($i=0; $i<$argc; $i++){
  114. $title = isset($argv[$i]["title"]) ? $argv[$i]["title"] : _("Button");
  115. $handler = isset($argv[$i]["handler"]) ? $argv[$i]["handler"] : "alert('Not implemented');";
  116. $shortcut= isset($argv[$i]["shortcut"])? " accesskey=\"".$argv[$i]["shortcut"]."\"": "";
  117. $buttons .= "<input class=\"buttonsize\" type=\"button\" value=\"" . $title . "\" onclick=\"" . $handler . "\"".$shortcut.">\n";
  118. }
  119. $buttons .= "</div>\n";
  120. return $buttons;
  121. }
  122. ?>