Unsupported scripts and control panel web app for a hosting company
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?PHP
  2. if (defined('LIB_COMMON')) { return; }
  3. require_once('lib/database.php');
  4. //require_once('lib/account.php');
  5. require_once('lib/log.php');
  6. define('CP_PATH', '/issues/');
  7. function stripSlashesDeep($value) {
  8. $value = is_array($value) ? array_map('stripslashesDeep', $value) : (isset($value) ? stripslashes($value) : null);
  9. return $value;
  10. }
  11. function stripSlashesOnInput() {
  12. if (get_magic_quotes_gpc()) {
  13. $_POST = stripSlashesDeep($_POST);
  14. $_GET = stripSlashesDeep($_GET);
  15. $_COOKIE = stripSlashesDeep($_COOKIE);
  16. }
  17. }
  18. function repairPost($data) {
  19. $rawpost = "&".file_get_contents("php://input");
  20. while(list($key,$value)= each($data)) {
  21. $pos = preg_match_all("/&".$key."=([^&]*)/i",$rawpost, $regs, PREG_PATTERN_ORDER);
  22. if((!is_array($value)) && ($pos > 1)) {
  23. $qform[$key] = array();
  24. for($i = 0; $i < $pos; $i++) {
  25. $qform[$key][$i] = urldecode($regs[1][$i]);
  26. }
  27. } else {
  28. $qform[$key] = $value;
  29. }
  30. }
  31. return $qform;
  32. }
  33. function getAdmins() {
  34. $sql = 'SELECT user_id, user_name FROM users WHERE user_admin = 1 AND user_pass != \'invalid\' ORDER BY user_name';
  35. $adminsRes = mysql_query($sql);
  36. if (mysql_num_rows($adminsRes) == 0) {
  37. return array();
  38. }
  39. while ($adminsData = mysql_fetch_assoc($adminsRes)) {
  40. $admins[$adminsData['user_id']] = $adminsData['user_name'];
  41. }
  42. return $admins;
  43. }
  44. function getCategories() {
  45. $sql = 'SELECT icat_id, icat_name, icat_assign FROM issues_categories ORDER BY icat_name';
  46. $categoriesRes = mysql_query($sql);
  47. if (mysql_num_rows($categoriesRes) == 0) {
  48. return array();
  49. }
  50. $categories = array();
  51. while ($categoriesData = mysql_fetch_assoc($categoriesRes)) {
  52. $categories[$categoriesData['icat_id']] = $categoriesData['icat_name'];
  53. }
  54. return $categories;
  55. }
  56. function getCategoriesInfo() {
  57. $sql = 'SELECT icat_id, icat_name, icat_assign FROM issues_categories ORDER BY icat_name';
  58. $categoriesRes = mysql_query($sql);
  59. if (mysql_num_rows($categoriesRes) == 0) {
  60. return array();
  61. }
  62. $categories = array();
  63. while ($categoriesData = mysql_fetch_assoc($categoriesRes)) {
  64. $categories[$categoriesData['icat_id']] = array('name'=>$categoriesData['icat_name'], 'assign'=>$categoriesData['icat_assign']);
  65. }
  66. return $categories;
  67. }
  68. function getUserID($name) {
  69. $sql = 'SELECT user_id FROM users WHERE user_name = \''.m($name).'\'';
  70. $res = mysql_query($sql);
  71. if (mysql_num_rows($res) == 0) {
  72. return 0;
  73. }
  74. $result = mysql_fetch_assoc($res);
  75. return $result['user_id'];
  76. }
  77. function getUserName($id) {
  78. $sql = 'SELECT user_name FROM users WHERE user_id = '.m($id);
  79. $res = mysql_query($sql);
  80. if (mysql_num_rows($res) == 0) {
  81. return 'Unknown';
  82. }
  83. $result = mysql_fetch_assoc($res);
  84. return $result['user_name'];
  85. }
  86. function getCategoryID($name) {
  87. $sql = 'SELECT icat_id FROM issues_categories WHERE icat_name = \''.m($name).'\'';
  88. $res = mysql_query($sql);
  89. if (mysql_num_rows($res) == 0) {
  90. return 0;
  91. }
  92. $result = mysql_fetch_assoc($res);
  93. return $result['icat_id'];
  94. }
  95. function getCategoryName($id) {
  96. $sql = 'SELECT icat_name FROM issues_categories WHERE icat_id = '.m($id);
  97. $res = mysql_query($sql);
  98. if (mysql_num_rows($res) == 0) {
  99. return 'Unknown';
  100. }
  101. $result = mysql_fetch_assoc($res);
  102. return $result['icat_name'];
  103. }
  104. function getIssueTitle($id) {
  105. $sql = 'SELECT i_title FROM issues_issues WHERE i_id = '.m($id);
  106. $res = mysql_query($sql);
  107. if (mysql_num_rows($res) == 0) {
  108. return 'Unknown';
  109. }
  110. $result = mysql_fetch_assoc($res);
  111. return $result['i_title'];
  112. }
  113. function getIssueInfo($id) {
  114. $sql = 'SELECT i_title, icat_name FROM issues_issues NATURAL JOIN issues_categories WHERE i_id = '.m($id);
  115. $res = mysql_query($sql);
  116. if (mysql_num_rows($res) == 0) {
  117. return 'Unknown : Unknown';
  118. }
  119. $result = mysql_fetch_assoc($res);
  120. return $result['icat_name'].': '.$result['i_title'];
  121. }
  122. function NiceSize($bytes) {
  123. $sizes = array();
  124. $sizes[1024] = ' <abbr title="Kibibytes">KiB</abbr>';
  125. $sizes[(1024*1024)] = ' <abbr title="Mebibytes">MiB</abbr>';
  126. $sizes[(1024*1024*1024)] = ' <abbr title="Gibibytes">GiB</abbr>';
  127. krsort($sizes);
  128. foreach ($sizes as $val => $name) {
  129. if ($bytes > ($val * 1.2)) {
  130. return round($bytes/$val, 2).$name;
  131. }
  132. }
  133. return $bytes.' <abbr title="Bytes">B</abbr>';
  134. }
  135. function h ($text) { return htmlspecialchars($text); }
  136. function m ($a) { return mysql_real_escape_string($a); }
  137. function n ($user) {
  138. if (strtolower($user) == strtolower($_SERVER['REDIRECT_REMOTE_USER'])) {
  139. return '<strong>You</strong>';
  140. } elseif ($user == '') {
  141. return '<span style="font-style: italic;">None</span>';
  142. } else {
  143. return h($user);
  144. }
  145. }
  146. function d($format, $timestamp) {
  147. if ($timestamp == 0) {
  148. return '<span style="font-style: italic;">None</span>';
  149. }
  150. return date($format, $timestamp);
  151. }
  152. function duration($seconds=0, $max_periods=7)
  153. {
  154. if (empty($seconds)) {
  155. return '0 seconds';
  156. }
  157. $periods = array("year" => 31536000, "month" => 2419200, "week" => 604800, "day" => 86400, "hour" => 3600, "minute" => 60, "second" => 1);
  158. $i = 1;
  159. foreach ( $periods as $period => $period_seconds )
  160. {
  161. $period_duration = floor($seconds / $period_seconds);
  162. $seconds = $seconds % $period_seconds;
  163. if ( $period_duration == 0 )
  164. {
  165. continue;
  166. }
  167. $duration[] = "{$period_duration} {$period}" . ($period_duration > 1 ? 's' : '');
  168. $i++;
  169. if ( $i > $max_periods )
  170. {
  171. break;
  172. }
  173. }
  174. return implode(' ', $duration);
  175. }
  176. stripSlashesOnInput();
  177. define('LIB_COMMON', true);
  178. ?>