PageRenderTime 96ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/inc/admin_banlist.php

#
PHP | 482 lines | 451 code | 1 blank | 30 comment | 39 complexity | 676903623bf0ca5defd0586961e64746 MD5 | raw file
  1. <?php
  2. /*
  3. eTicket, Open Source Support Ticket System
  4. http://eticket.sourceforge.net/
  5. Released under the GNU General Public License
  6. */
  7. if(!defined('ISINC')) die('serious error');
  8. if ($_SESSION['user']['type'] !== 'admin') { die(LANG_ERROR_DENIED); }
  9. if ($login[$a] || $login['ID'] == ADMIN) {
  10. if (isset($_REQUEST['e'])) {
  11. $e=$_REQUEST['e'];
  12. switch($e) {
  13. case "add":
  14. if (!$_POST['Action']) {
  15. $inc = 'admin_banlist_addedit.html';
  16. }
  17. ob_start();
  18. // get action
  19. $ab=$_POST['ab'];
  20. if (empty($ab)) {
  21. $ab=$_GET['key']?'C':'I'; //copy record or display blank
  22. }
  23. switch ($ab) {
  24. case "C":
  25. // get a record to display
  26. $tkey = (int) $_GET['key'];
  27. $strsql = "SELECT * FROM ".$db_table['banlist']." WHERE `value_id`=".$tkey;
  28. $rs = mysql_query($strsql);
  29. if (mysql_num_rows($rs) == 0) {
  30. ob_end_clean();
  31. header('Location: admin.php?a=banlist'); die();
  32. } else {
  33. $row = mysql_fetch_array($rs);
  34. // get the field contents
  35. $x_value = @$row['value'];
  36. }
  37. mysql_free_result($rs);
  38. break;
  39. case "A":
  40. // add
  41. // get the form values
  42. $x_value = @$_POST['x_value'];
  43. $x_value_id = @$_POST['x_value_id'];
  44. // add the values into an array
  45. if ($x_value != '') {
  46. // value
  47. $theValue = get_magic_quotes_gpc()?$x_value:addslashes($x_value);
  48. $theValue = ($theValue != '') ? "'$theValue'" : "NULL";
  49. $fieldList['value'] = $theValue;
  50. // insert into database
  51. $strsql = "INSERT INTO ".$db_table['banlist']." (" . implode(',', array_keys($fieldList)) . ") VALUES (" . implode(',', array_values($fieldList)) . ")";
  52. mysql_query($strsql) or die(mysql_error());
  53. ob_end_clean();
  54. }
  55. header('Location: admin.php?a=banlist'); die();
  56. break;
  57. }
  58. break;
  59. case "delete":
  60. if (!$_POST['submit']) {
  61. $inc = 'admin_banlist_delete.html';
  62. }
  63. ob_start();
  64. $page = 'admin.php';
  65. // multiple delete records
  66. $key = $_REQUEST['key'];
  67. if (count($key) == 0) {
  68. header('Location: admin.php?a=banlist'); die();
  69. }
  70. $sqlKey = '';
  71. foreach ($key as $reckey) {
  72. $reckey = (int) $reckey;
  73. // build the SQL
  74. $sqlKey .= "(" . "`value_id`=" . "" . $reckey . "" . " AND ";
  75. if (substr($sqlKey, -5) == " AND ") {
  76. $sqlKey = substr($sqlKey, 0, strlen($sqlKey) - 5);
  77. }
  78. $sqlKey .= ") OR ";
  79. }
  80. if (substr($sqlKey, -4) == " OR ") {
  81. $sqlKey = substr($sqlKey, 0, strlen($sqlKey) - 4);
  82. }
  83. // get action
  84. if (isset($_POST['ab'])) { $ab = $_POST['ab']; }
  85. if (empty($ab)) { $ab='I'; }
  86. switch ($ab) {
  87. case "I":
  88. // display
  89. $strsql = "SELECT * FROM ".$db_table['banlist']." WHERE " . $sqlKey;
  90. $rs = mysql_query($strsql) or die(mysql_error());
  91. if (mysql_num_rows($rs) == 0) {
  92. ob_end_clean();
  93. header('Location: admin.php?a=banlist'); die();
  94. }
  95. $recCount = 0;
  96. while ($row = mysql_fetch_array($rs)) {
  97. $recCount = $recCount++;
  98. $x_value=@$row['value'];
  99. $items[]=$x_value;
  100. }
  101. mysql_free_result($rs);
  102. break;
  103. case "D":
  104. // delete
  105. $strsql = "DELETE FROM ".$db_table['banlist']." WHERE " . $sqlKey;
  106. $rs = mysql_query($strsql) or die(mysql_error());
  107. ob_end_clean();
  108. header('Location: admin.php?a=banlist'); die();
  109. break;
  110. }
  111. break;
  112. case "edit":
  113. if (!$_POST['submit']) { $inc = 'admin_banlist_addedit.html'; }
  114. ob_start();
  115. $page = 'admin.php';
  116. $key = (int) $_REQUEST['key'];
  117. if (empty($key)) {
  118. header('Location: admin.php?a=banlist'); die();
  119. }
  120. // get action
  121. $ab = @$_POST["ab"];
  122. if (empty($ab)) {
  123. //display with input box
  124. $ab = "I";
  125. }
  126. // get fields from form
  127. $x_value = @$_POST["x_value"];
  128. $x_value_id = @$_POST["x_value_id"];
  129. switch ($ab) {
  130. case "I":
  131. // get a record to display
  132. $tkey = "" . $key . "";
  133. $strsql = "SELECT * FROM ".$db_table['banlist']." WHERE `value_id`=" . $tkey;
  134. $rs = mysql_query($strsql) or die(mysql_error());
  135. if (!($row = mysql_fetch_array($rs))) {
  136. ob_end_clean();
  137. header('Location: admin.php?a=banlist'); die();
  138. }
  139. // get the field contents
  140. $x_value = @$row["value"];
  141. $x_value_id = @$row["value_id"];
  142. mysql_free_result($rs);
  143. break;
  144. case "U":
  145. // update
  146. $tkey = "" . $key . "";
  147. // get the form values
  148. $x_value = @$_POST["x_value"];
  149. $x_value_id = @$_POST["x_value_id"];
  150. // add the values into an array
  151. // value
  152. $theValue = (!get_magic_quotes_gpc()) ? addslashes($x_value) : $x_value;
  153. $theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
  154. $fieldList["`value`"] = $theValue;
  155. // update
  156. $updateSQL = "UPDATE ".$db_table['banlist']." SET ";
  157. foreach ($fieldList as $key => $temp) {
  158. $updateSQL .= "$key = $temp, ";
  159. }
  160. if (substr($updateSQL, -2) == ", ") {
  161. $updateSQL = substr($updateSQL, 0, strlen($updateSQL) - 2);
  162. }
  163. $updateSQL .= " WHERE `value_id`=" . $tkey;
  164. $rs = mysql_query($updateSQL) or die(mysql_error());
  165. ob_end_clean();
  166. header('Location: admin.php?a=banlist'); die();
  167. }
  168. break;
  169. }
  170. }
  171. else {
  172. if (!$_POST['submit']) {
  173. $inc = 'admin_banlist.html';
  174. }
  175. $displayRecs = 20;
  176. $recRange = 10;
  177. $dbwhere = "";
  178. $masterdetailwhere = "";
  179. $searchwhere = "";
  180. $a_search = "";
  181. $b_search = "";
  182. $whereClause = "";
  183. // get search criteria for basic search
  184. $pSearch = @$_GET["psearch"];
  185. $pSearchType = @$_GET["psearchtype"];
  186. if ($pSearch <> "") {
  187. $pSearch = str_replace("'", "\'", $pSearch);
  188. if ($pSearchType <> "") {
  189. while (strpos($pSearch, " ") > 0) {
  190. $pSearch = str_replace(" ", " ", $pSearch);
  191. }
  192. $arpSearch = explode(" ", trim($pSearch));
  193. foreach ($arpSearch as $kw) {
  194. $b_search .= "(";
  195. $b_search .= "`value` LIKE '%" . trim($kw) . "%' OR ";
  196. if (substr($b_search, -4) == " OR ") {
  197. $b_search = substr($b_search, 0, strlen($b_search) - 4);
  198. }
  199. $b_search .= ") " . $pSearchType . " ";
  200. }
  201. } else {
  202. $b_search .= "`value` LIKE '%" . $pSearch . "%' OR ";
  203. }
  204. }
  205. if (substr($b_search, -4) == " OR ") {
  206. $b_search = substr($b_search, 0, strlen($b_search) - 4);
  207. }
  208. if (substr($b_search, -5) == " AND ") {
  209. $b_search = substr($b_search, 0, strlen($b_search) - 5);
  210. }
  211. // build search criteria
  212. if ($a_search <> "") {
  213. //advanced search
  214. $searchwhere = $a_search;
  215. } elseif ($b_search <> "") {
  216. //basic search
  217. $searchwhere = $b_search;
  218. }
  219. // save search criteria
  220. if ($searchwhere <> "") {
  221. $_SESSION['banlist']['searchwhere'] = $searchwhere;
  222. $_SESSION['banlist']['pSearch'] = $pSearch;
  223. $_SESSION['banlist']['pSearchType'] = $pSearchType;
  224. //reset start record counter (new search)
  225. $startRec = 1;
  226. $_SESSION['banlist']['REC'] = $startRec;
  227. } else {
  228. $searchwhere = @$_SESSION['banlist']["searchwhere"];
  229. $pSearch = $_SESSION['banlist']['pSearch'];
  230. $pSearchType = $_SESSION['banlist']['pSearchType'];
  231. }
  232. // get clear search cmd
  233. if (@$_GET["cmd"] <> "") {
  234. $cmd = $_GET["cmd"];
  235. if (strtoupper($cmd) == "RESET") {
  236. //reset search criteria
  237. $searchwhere = '';
  238. $_SESSION['banlist']['searchwhere'] = $searchwhere;
  239. $pSearch = '';
  240. $_SESSION['banlist']['pSearch'] = $pSearch;
  241. $pSearchType = '';
  242. $_SESSION['banlist']['pSearchType'] = $pSearchType;
  243. } elseif (strtoupper($cmd) == "RESETALL") {
  244. //reset search criteria
  245. $searchwhere = '';
  246. $_SESSION['banlist']["searchwhere"] = $searchwhere;
  247. $pSearch = '';
  248. $_SESSION['banlist']['pSearch'] = $pSearch;
  249. $pSearchType = '';
  250. $_SESSION['banlist']['pSearchType'] = $pSearchType;
  251. }
  252. //reset start record counter (reset command)
  253. $startRec = 1;
  254. $_SESSION['banlist']['REC'] = $startRec;
  255. }
  256. // build dbwhere
  257. if ($masterdetailwhere <> "") {
  258. $dbwhere .= "(" . $masterdetailwhere . ") AND ";
  259. }
  260. if ($searchwhere <> "") {
  261. $dbwhere .= "(" . $searchwhere . ") AND ";
  262. }
  263. if (strlen($dbwhere) > 5) {
  264. // trim rightmost AND
  265. $dbwhere = substr($dbwhere, 0, strlen($dbwhere) - 5);
  266. }
  267. // default order
  268. $DefaultOrder = '';
  269. $DefaultOrderType = '';
  270. // default filter
  271. $DefaultFilter = '';
  272. // check for an Order parameter
  273. $OrderBy = '';
  274. if (@$_GET['order'] <> "") {
  275. $OrderBy = $_GET["order"];
  276. // check if an ASC/DESC toggle is required
  277. if (@$_SESSION['banlist']["OB"] == $OrderBy) {
  278. if (@$_SESSION['banlist']["OT"] == "ASC") {
  279. $_SESSION['banlist']["OT"] = "DESC";
  280. } else {
  281. $_SESSION['banlist']["OT"] = "ASC";
  282. }
  283. } else {
  284. $_SESSION['banlist']["OT"] = "ASC";
  285. }
  286. $_SESSION['banlist']["OB"] = $OrderBy;
  287. $_SESSION['banlist']['REC'] = 1;
  288. } else {
  289. $OrderBy = @$_SESSION['banlist']["OB"];
  290. if ($OrderBy == "") {
  291. $OrderBy = $DefaultOrder;
  292. $_SESSION['banlist']["OB"] = $OrderBy;
  293. $_SESSION['banlist']["OT"] = $DefaultOrderType;
  294. }
  295. }
  296. // build SQL
  297. $strsql = "SELECT * FROM ".$db_table['banlist'];
  298. if ($DefaultFilter <> "") {
  299. $whereClause .= "(" . $DefaultFilter . ") AND ";
  300. }
  301. if ($dbwhere <> "") {
  302. $whereClause .= "(" . $dbwhere . ") AND ";
  303. }
  304. if (substr($whereClause, -5) == " AND ") {
  305. $whereClause = substr($whereClause, 0, strlen($whereClause) - 5);
  306. }
  307. if ($whereClause <> "") {
  308. $strsql .= " WHERE " . $whereClause;
  309. }
  310. if ($OrderBy <> "") {
  311. $strsql .= " ORDER BY `" . $OrderBy . "` " . @$_SESSION['banlist']["OT"];
  312. }
  313. //echo $strsql; // comment out this line to view the SQL
  314. $rs = mysql_query($strsql);
  315. $totalRecs = intval(@mysql_num_rows($rs));
  316. // check for a START parameter
  317. if (@$_GET["start"] <> "") {
  318. $startRec = $_GET["start"];
  319. $_SESSION['banlist']['REC'] = $startRec;
  320. } elseif (@$_GET["pageno"] <> "") {
  321. $pageno = $_GET["pageno"];
  322. if (is_numeric($pageno)) {
  323. $startRec = ($pageno - 1) * $displayRecs + 1;
  324. if ($startRec <= 0) {
  325. $startRec = 1;
  326. } elseif ($startRec >= (($totalRecs - 1) / $displayRecs) * $displayRecs + 1) {
  327. $startRec = (($totalRecs - 1) / $displayRecs) * $displayRecs + 1;
  328. }
  329. $_SESSION['banlist']['REC'] = $startRec;
  330. } else {
  331. $startRec = @$_SESSION['banlist']['REC'];
  332. if (!is_numeric($startRec)) {
  333. // reset start record counter
  334. $startRec = 1;
  335. $_SESSION['banlist']['REC'] = $startRec;
  336. }
  337. }
  338. } else {
  339. $startRec = @$_SESSION['banlist']['REC'];
  340. if (!is_numeric($startRec)) {
  341. // reset start record counter
  342. $startRec = 1;
  343. $_SESSION['banlist']['REC'] = $startRec;
  344. }
  345. }
  346. }
  347. }
  348. /* html vars start */
  349. $vars=array();
  350. //psearchtype
  351. $tmp='';
  352. $check_var=$_SESSION['banlist']['pSearchType'];
  353. $types=array('' => LANG_EXACT_PHRASE,'AND' => LANG_ALL_WORDS,'OR' => LANG_ANY_WORD);
  354. foreach ($types as $type => $val) {
  355. $checked=($check_var == $type) ? ' checked': '';
  356. $tmp.=sprintf($html['banlist']['input'],'radio','psearchtype',$type,$checked,$val);
  357. }
  358. $vars['psearchtype']=$tmp;
  359. $vars['pSearch']=htmlspecialchars($_SESSION['banlist']['pSearch']);
  360. if ($OrderBy == 'value') {
  361. $vars['orderby']=(@$_SESSION['banlist']['OT'] == 'ASC') ? 5 : ((@$_SESSION['banlist']['OT'] == 'DESC') ? 6 : '');
  362. }
  363. // avoid starting record > total records
  364. if ($startRec > $totalRecs) { $startRec = $totalRecs; }
  365. // set the last record to display
  366. $stopRec = $startRec + $displayRecs - 1;
  367. $recCount = $startRec - 1;
  368. // move to the first record
  369. @mysql_data_seek($rs, $recCount);
  370. $recActual = 0;
  371. $tmp='';
  372. while (($row = @mysql_fetch_array($rs)) && ($recCount < $stopRec)) {
  373. $recCount++;
  374. if ($recCount >= $startRec) {
  375. $recActual++;
  376. // load key for record
  377. $key = @$row["value_id"];
  378. $x_value = @$row["value"];
  379. $x_value_id = @$row["value_id"];
  380. $edit_href=(!is_null(@$row["value_id"])) ? "admin.php?a=banlist&amp;e=edit&key=".urlencode($row["value_id"]) : "javascript:alert('".LANG_INVALID_RECORD."');";
  381. $copy_href=(!is_null(@$row["value_id"])) ? "admin.php?a=banlist&amp;e=add&key=".urlencode($row["value_id"]) : "javascript:alert('".LANG_INVALID_RECORD."');";
  382. $tmp.=sprintf($html['banlist']['main_table_content'],$key,$edit_href,$copy_href,$x_value);
  383. }
  384. }//end while
  385. @mysql_free_result($rs);// close connection
  386. $vars['main_table_content']=$tmp;
  387. $tmp='';
  388. // display page numbers
  389. if ($totalRecs > 0) {
  390. $rsEof = ($totalRecs < ($startRec + $displayRecs));
  391. // find out if there should be backward or forward Buttons on the table
  392. if ($startRec == 1) {
  393. $isPrev = False;
  394. }
  395. else {
  396. $isPrev = True;
  397. $PrevStart = $startRec - $displayRecs;
  398. if ($PrevStart < 1) { $PrevStart = 1; }
  399. $tmp.=sprintf($html['banlist']['prev'],$PrevStart);
  400. }
  401. if ($isPrev || $totalRecs != 0) {
  402. $x = 1;
  403. $y = 1;
  404. $dx1 = intval(($startRec-1)/($displayRecs*$recRange))*$displayRecs*$recRange+1;
  405. $dy1 = intval(($startRec-1)/($displayRecs*$recRange))*$recRange+1;
  406. if (($dx1+$displayRecs*$recRange-1) > $totalRecs ) {
  407. $dx2 = intval($totalRecs/$displayRecs)*$displayRecs+1;
  408. $dy2 = intval($totalRecs/$displayRecs)+1;
  409. } else {
  410. $dx2 = $dx1+$displayRecs*$recRange-1;
  411. $dy2 = $dy1+$recRange-1;
  412. }
  413. while ($x <= $totalRecs) {
  414. if ($x >= $dx1 && $x <= $dx2) {
  415. if ($startRec == $x) {
  416. $tmp.=sprintf($html['banlist']['b'],$y);
  417. }
  418. else {
  419. $tmp.=sprintf($html['banlist']['ab'],$x,$y);
  420. }
  421. $x = $x + $displayRecs;
  422. $y = $y + 1;
  423. } elseif ($x >= ($dx1-$displayRecs*$recRange) && $x <= ($dx2+$displayRecs*$recRange)) {
  424. if ($x+$recRange*$displayRecs < $totalRecs) {
  425. $tmp.=sprintf($html['banlist']['ab'],$x,$y.'-'.$y+$recRange-1);
  426. }
  427. else {
  428. $ny = intval(($totalRecs-1)/$displayRecs) + 1;
  429. if ($ny == $y) {
  430. $tmp.=sprintf($html['banlist']['ab'],$x,$y);
  431. }
  432. else {
  433. $tmp.=sprintf($html['banlist']['ab'],$x,$y.'-'.$ny);
  434. }
  435. }
  436. $x = $x + $recRange*$displayRecs;
  437. $y = $y + $recRange;
  438. } else {
  439. $x = $x + $recRange*$displayRecs;
  440. $y = $y + $recRange;
  441. }
  442. }
  443. }
  444. // next link
  445. if ($totalRecs >= $startRec + $displayRecs) {
  446. $NextStart = $startRec + $displayRecs;
  447. $isMore = True;
  448. $tmp.=sprintf($html['banlist']['next'],$NextStart);
  449. }
  450. else { $isMore = FALSE; }
  451. if ($startRec > $totalRecs) { $startRec = $totalRecs; }
  452. $stopRec = $startRec + $displayRecs - 1;
  453. $recCount = $totalRecs - 1;
  454. if ($rsEof) { $recCount = $totalRecs; }
  455. if ($stopRec > $recCount) { $stopRec = $recCount; }
  456. $RecText=LANG_BANLIST_RECORD_TOTAL;
  457. $RecText=str_replace('%start',$startRec,$RecText);
  458. $RecText=str_replace('%stop',$stopRec,$RecText);
  459. $RecText=str_replace('%total',$totalRecs,$RecText);
  460. $tmp.="($RecText)";
  461. } else { $tmp.=LANG_NO_RECORDS_FOUND; }
  462. $vars['pagination']=$tmp;
  463. /* html vars end */
  464. ?>