PageRenderTime 1218ms CodeModel.GetById 62ms RepoModel.GetById 2ms app.codeStats 1ms

/src/admin/sort.php

http://emlog.googlecode.com/
PHP | 109 lines | 93 code | 11 blank | 5 comment | 21 complexity | c33124a16e30dc3baf8bfa92bad6a602 MD5 | raw file
  1. <?php
  2. /**
  3. * ????
  4. * @copyright (c) Emlog All Rights Reserved
  5. * $Id: sort.php 1971 2011-05-22 04:07:56Z emloog $
  6. */
  7. require_once 'globals.php';
  8. $Sort_Model = new Sort_Model();
  9. if($action == '')
  10. {
  11. $sorts = $CACHE->readCache('sort');
  12. include View::getView('header');
  13. require_once View::getView('sort');
  14. include View::getView('footer');
  15. View::output();
  16. }
  17. if ($action == 'taxis')
  18. {
  19. $sort = isset($_POST['sort']) ? $_POST['sort'] : '';
  20. if(!empty($sort))
  21. {
  22. foreach($sort as $key=>$value)
  23. {
  24. $value = intval($value);
  25. $key = intval($key);
  26. $Sort_Model->updateSort(array('taxis'=>$value), $key);
  27. }
  28. $CACHE->updateCache('sort');
  29. emDirect("./sort.php?active_taxis=true");
  30. }else{
  31. emDirect("./sort.php?error_b=true");
  32. }
  33. }
  34. if($action== 'add')
  35. {
  36. $taxis = isset($_POST['taxis']) ? intval(trim($_POST['taxis'])) : 0;
  37. $sortname = isset($_POST['sortname']) ? addslashes(trim($_POST['sortname'])) : '';
  38. $alias = isset($_POST['alias']) ? addslashes(trim($_POST['alias'])) : '';
  39. if(empty($sortname)){
  40. emDirect("./sort.php?error_a=true");
  41. }
  42. if (!empty($alias)) {
  43. if (!preg_match("|^[\w-]+$|", $alias)) {
  44. emDirect("./sort.php?error_c=true");
  45. }elseif(preg_match("|^[0-9]+$|", $alias)){
  46. emDirect("./sort.php?error_f=true");
  47. }elseif (in_array($alias, array('post','record','sort','tag','author','page'))) {
  48. emDirect("./sort.php?error_e=true");
  49. }else {
  50. $sort_cache = $CACHE->readCache('sort');
  51. foreach ($sort_cache as $key => $value) {
  52. if ($alias == $value['alias']) {
  53. emDirect("./sort.php?error_d=true");
  54. }
  55. }
  56. }
  57. }
  58. $Sort_Model->addSort($sortname, $alias, $taxis);
  59. $CACHE->updateCache('sort');
  60. emDirect("./sort.php?active_add=true");
  61. }
  62. if($action == 'update')
  63. {
  64. $sid = isset($_GET['sid']) ? intval($_GET['sid']) : '';
  65. $sort_data = array();
  66. if (isset($_GET['name'])) {
  67. $sort_data['sortname'] = addslashes(trim($_GET['name']));
  68. }
  69. if (isset($_GET['alias'])) {
  70. $sort_data['alias'] = addslashes(trim($_GET['alias']));
  71. if (!empty($sort_data['alias'])) {
  72. if (!preg_match("|^[\w-]+$|", $sort_data['alias'])) {
  73. emDirect("./sort.php?error_c=true");
  74. } elseif(preg_match("|^[0-9]+$|", $sort_data['alias'])){
  75. emDirect("./sort.php?error_f=true");
  76. } elseif (in_array($sort_data['alias'], array('post','record','sort','tag','author','page'))) {
  77. emDirect("./sort.php?error_e=true");
  78. } else{
  79. $sort_cache = $CACHE->readCache('sort');
  80. foreach ($sort_cache as $key => $value) {
  81. if ($sort_data['alias'] == $value['alias']) {
  82. emDirect("./sort.php?error_d=true");
  83. }
  84. }
  85. }
  86. }
  87. }
  88. $Sort_Model->updateSort($sort_data, $sid);
  89. $CACHE->updateCache(array('sort', 'logsort'));
  90. emDirect("./sort.php?active_edit=true");
  91. }
  92. if ($action == 'del')
  93. {
  94. $sid = isset($_GET['sid']) ? intval($_GET['sid']) : '';
  95. $Sort_Model->deleteSort($sid);
  96. $CACHE->updateCache(array('sort', 'logsort'));
  97. emDirect("./sort.php?active_del=true");
  98. }