html_functions.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 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, $class="failure")
  25. {
  26. echo '<p class="' . $class . '">'.$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. $count = 1;
  46. $retval = "<select id=\"$listname\" name=\"$listname\">\n";
  47. foreach($input_array as $key => $value)
  48. {
  49. $value = trim($value);
  50. list($rsync_site,$location) = explode("|", $value);
  51. // We want to print lines with zeros, but not empty lines.
  52. if ( $value !== "0" && empty($value) )
  53. {
  54. continue;
  55. }
  56. if ( $use_only_values === true )
  57. {
  58. # $key = $value;
  59. }
  60. if ( $key == $current_value )
  61. {
  62. $retval .= "<option value='$count' selected='selected'>$rsync_site - $location</option>\n";
  63. }
  64. else
  65. {
  66. $retval .= "<option value='$count'>$rsync_site - $location</option>\n";
  67. }
  68. ++$count;
  69. }
  70. $retval .= "</select>\n";
  71. return $retval;
  72. }
  73. /// Creates HTML drop box from given array with the given listname.
  74. function create_drop_box_from_array($input_array,$listname,$current_value = "", $use_only_values = true)
  75. {
  76. $retval = "<select id=\"$listname\" name=\"$listname\" style=\"max-width:330px;\">\n";
  77. foreach($input_array as $key => $value)
  78. {
  79. // Make sure we don't allow HTML or script
  80. $key = trim(strip_tags($key));
  81. $value = trim(strip_tags($value));
  82. // We want to print lines with zeros, but not empty lines.
  83. if ( empty($value) and $value !="0" )
  84. {
  85. continue;
  86. }
  87. if ( $use_only_values === true )
  88. {
  89. $key = $value;
  90. }
  91. $sel = "";
  92. if ( $key == $current_value )
  93. {
  94. $sel .= "selected='selected'";
  95. }
  96. $retval .= "<option value='$key' $sel>$value</option>\n";
  97. }
  98. $retval .= "</select>\n";
  99. return $retval;
  100. }
  101. /// Creates HTML drop box from given array with the given listname.
  102. /// Used to create a list of users/groups. Remote_readfile is used to read in /etc/passwd and /etc/group
  103. function create_drop_box_from_passwd($input_array,$listname)
  104. {
  105. $retval = "<select name=\"$listname\">\n";
  106. foreach($input_array as $line)
  107. {
  108. $line = trim($line);
  109. if ( empty($line) ) continue;
  110. list($username, $junk, $uid, $gid, $comment, $home_dir, $shell) = explode(':', $line);
  111. if ( $uid < 500 ) continue; #this will filter out system id's, typically under 500
  112. $retval .= "<option value='$uid:$gid'>$username (uid=$uid gid=$gid home=$home_dir)</option>\n";
  113. }
  114. $retval .= "</select>\n";
  115. return $retval;
  116. }
  117. function get_user_uid_gid_from_passwd($input_array,$name)
  118. {
  119. foreach($input_array as $line)
  120. {
  121. $line = trim($line);
  122. if ( empty($line) ) continue;
  123. list($username, $junk, $uid, $gid, $comment, $home_dir, $shell) = explode(':', $line);
  124. if ( $username === $name )
  125. {
  126. $retval = "$uid:$gid";
  127. return $retval;
  128. }
  129. }
  130. }
  131. function check_theme_image($base_image_path)
  132. {
  133. $base_image_path = ltrim($base_image_path, "/");
  134. if(function_exists("getThemePath")){
  135. return file_exists( getThemePath() . $base_image_path ) ?
  136. getThemePath() . $base_image_path :
  137. $base_image_path;
  138. }
  139. return $base_image_path;
  140. }
  141. ?>