html_functions.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) Copyright (C) 2008 - 2013 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. function print_failure($text)
  25. {
  26. echo '<p class="failure">'.$text.'</p>';
  27. }
  28. function print_success($text)
  29. {
  30. echo '<p class="success">'.$text.'</p>';
  31. }
  32. function create_back_button($module,$subpage = "")
  33. {
  34. $retval = "<p><a href='?m=$module";
  35. if ( !empty($subpage) )
  36. {
  37. $retval .= "&amp;p=$subpage";
  38. }
  39. $retval .= "'>&lt;&lt; ".get_lang('back')."</a></p>\n";
  40. return $retval;
  41. }
  42. /// Creates HTML drop box from given array with the given listname, custom for Rsync sites
  43. function create_drop_box_from_array_rsync($input_array,$listname,$current_value = "", $use_only_values = true)
  44. {
  45. $retval = "<select id=\"$listname\" name=\"$listname\">\n";
  46. foreach($input_array as $key => $value)
  47. {
  48. $value = trim($value);
  49. list($rsync_site,$location) = explode("|", $value);
  50. // We want to print lines with zeros, but not empty lines.
  51. if ( $value !== "0" && empty($value) )
  52. {
  53. continue;
  54. }
  55. if ( $use_only_values === true )
  56. {
  57. # $key = $value;
  58. }
  59. if ( $key == $current_value )
  60. {
  61. $retval .= "<option value='$rsync_site' selected='selected'>$rsync_site - $location</option>\n";
  62. }
  63. else
  64. {
  65. $retval .= "<option value='$rsync_site'>$rsync_site - $location</option>\n";
  66. }
  67. }
  68. $retval .= "</select>\n";
  69. return $retval;
  70. }
  71. /// Creates HTML drop box from given array with the given listname.
  72. function create_drop_box_from_array($input_array,$listname,$current_value = "", $use_only_values = true)
  73. {
  74. $retval = "<select id=\"$listname\" name=\"$listname\" style=\"max-width:330px;\">\n";
  75. foreach($input_array as $key => $value)
  76. {
  77. // Make sure we don't allow HTML or script
  78. $key = trim(strip_tags($key));
  79. $value = trim(strip_tags($value));
  80. // We want to print lines with zeros, but not empty lines.
  81. if ( empty($value) and $value !="0" )
  82. {
  83. continue;
  84. }
  85. if ( $use_only_values === true )
  86. {
  87. $key = $value;
  88. }
  89. $sel = "";
  90. if ( $key == $current_value )
  91. {
  92. $sel .= "selected='selected'";
  93. }
  94. $retval .= "<option value='$key' $sel>$value</option>\n";
  95. }
  96. $retval .= "</select>\n";
  97. return $retval;
  98. }
  99. /// Creates HTML drop box from given array with the given listname.
  100. /// Used to create a list of users/groups. Remote_readfile is used to read in /etc/passwd and /etc/group
  101. function create_drop_box_from_passwd($input_array,$listname)
  102. {
  103. $retval = "<select name=\"$listname\">\n";
  104. foreach($input_array as $line)
  105. {
  106. $line = trim($line);
  107. if ( empty($line) ) continue;
  108. list($username, $junk, $uid, $gid, $comment, $home_dir, $shell) = explode(':', $line);
  109. if ( $uid < 500 ) continue; #this will filter out system id's, typically under 500
  110. $retval .= "<option value='$uid:$gid'>$username (uid=$uid gid=$gid home=$home_dir)</option>\n";
  111. }
  112. $retval .= "</select>\n";
  113. return $retval;
  114. }
  115. function get_user_uid_gid_from_passwd($input_array,$name)
  116. {
  117. foreach($input_array as $line)
  118. {
  119. $line = trim($line);
  120. if ( empty($line) ) continue;
  121. list($username, $junk, $uid, $gid, $comment, $home_dir, $shell) = explode(':', $line);
  122. if ( $username === $name )
  123. {
  124. $retval = "$uid:$gid";
  125. return $retval;
  126. }
  127. }
  128. }
  129. function check_theme_image($base_image_path)
  130. {
  131. $base_image_path = ltrim($base_image_path, "/");
  132. global $settings;
  133. return file_exists( 'themes/' . $settings['theme'] . "/" . $base_image_path ) ?
  134. 'themes/'.$settings['theme'] . "/" . $base_image_path :
  135. $base_image_path;
  136. }
  137. ?>