downservers.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_class('admin','admin',0);
  4. pc_base::load_sys_class('form', '', 0);
  5. class downservers extends admin {
  6. private $db;
  7. function __construct() {
  8. parent::__construct();
  9. $this->db = pc_base::load_model('downservers_model');
  10. $this->sites = pc_base::load_app_class('sites');
  11. }
  12. public function init() {
  13. if(isset($_POST['dosubmit'])) {
  14. $info['siteurl'] = trim($_POST['info']['siteurl']);
  15. $info['sitename'] = trim($_POST['info']['sitename']);
  16. $info['siteid'] = intval($_POST['info']['siteid']);
  17. if(empty($info['sitename'])) showmessage(L('downserver_not_empty'), HTTP_REFERER);
  18. if(empty($info['siteurl']) || !preg_match('/(\w+):\/\/(.+)[^\/]$/i', $info['siteurl'])) showmessage(L('downserver_error'), HTTP_REFERER);
  19. $insert_id = $this->db->insert($info,true);
  20. if($insert_id){
  21. $this->_set_cache();
  22. showmessage(L('operation_success'), HTTP_REFERER);
  23. }
  24. } else {
  25. $infos = $sitelist = array();
  26. $current_siteid = get_siteid();
  27. $where = "`siteid`='$current_siteid' or `siteid`=''";
  28. $sitelists = $this->sites->get_list();
  29. if($_SESSION['roleid'] == '1') {
  30. foreach($sitelists as $key=>$v) $sitelist[$key] = $v['name'];
  31. $default = L('all_site');
  32. } else {
  33. $sitelist[$current_siteid] = $sitelists[$current_siteid]['name'];
  34. $default = '';
  35. }
  36. $page = $_GET['page'] ? $_GET['page'] : '1';
  37. $infos = $this->db->listinfo($where, 'listorder DESC,id DESC', $page, $pagesize = 20);
  38. $pages = $this->db->pages;
  39. include $this->admin_tpl('downservers_list');
  40. }
  41. }
  42. public function edit() {
  43. if(isset($_POST['dosubmit'])) {
  44. $info['siteurl'] = trim($_POST['info']['siteurl']);
  45. $info['sitename'] = trim($_POST['info']['sitename']);
  46. $info['siteid'] = intval($_POST['info']['siteid']);
  47. if(empty($info['sitename'])) showmessage(L('downserver_not_empty'), HTTP_REFERER);
  48. if(empty($info['siteurl']) || !preg_match('/(\w+):\/\/(.+)[^\/]$/i', $info['siteurl'])) showmessage(L('downserver_error'), HTTP_REFERER);
  49. $id = intval(trim($_POST['id']));
  50. $this->_set_cache();
  51. $this->db->update($info,array('id'=>$id));
  52. showmessage(L('operation_success'), '', '', 'edit');
  53. } else {
  54. $info = $sitelist = array();
  55. $default = '';
  56. $sitelists = $this->sites->get_list();
  57. if($_SESSION['roleid'] == '1') {
  58. foreach($sitelists as $key=>$v) $sitelist[$key] = $v['name'];
  59. $default = L('all_site');
  60. } else {
  61. $current_siteid = self::get_siteid();
  62. $sitelist[$current_siteid] = $sitelists[$current_siteid]['name'];
  63. $default = '';
  64. }
  65. $info = $this->db->get_one(array('id'=>intval($_GET['id'])));
  66. extract($info);
  67. $show_validator = true;
  68. $show_header = true;
  69. include $this->admin_tpl('downservers_edit');
  70. }
  71. }
  72. public function delete() {
  73. $id = intval($_GET['id']);
  74. $this->db->delete(array('id'=>$id));
  75. $this->_set_cache();
  76. showmessage(L('downserver_del_success'), HTTP_REFERER);
  77. }
  78. /**
  79. * 排序
  80. */
  81. public function listorder() {
  82. if(isset($_POST['dosubmit'])) {
  83. foreach($_POST['listorders'] as $id => $listorder) {
  84. $this->db->update(array('listorder'=>$listorder),array('id'=>$id));
  85. }
  86. showmessage(L('operation_success'), HTTP_REFERER);
  87. } else {
  88. showmessage(L('operation_failure'), HTTP_REFERER);
  89. }
  90. }
  91. private function _set_cache() {
  92. $infos = $this->db->select();
  93. foreach ($infos as $info){
  94. $servers[$info['id']] = $info;
  95. }
  96. setcache('downservers', $servers,'commons');
  97. return $infos;
  98. }
  99. }
  100. ?>