<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
$CS_Path=$_SERVER['PHP_SELF'];
$CS_Pathall=explode("/",$CS_Path);
$CS_Admin=$CS_Pathall[1]."/";
	if(empty($_COOKIE['CS_AdminID'])){
		die("<script>window.parent.location='".CS_WebPath.$CS_Admin."login.php'</script>");
	}elseif($_COOKIE['CS_Login']!=md5($_COOKIE['CS_AdminID'].$_COOKIE['CS_AdminUserName'].$_COOKIE['CS_AdminPassWord'].$_COOKIE['CS_Quanx'])){
		die("<script>window.parent.location='".CS_WebPath.$CS_Admin."login.php'</script>");
        }else{
                 global $db;
	         $rowa=$db->getrow("SELECT * FROM ".Getdbname('admin')." Where CS_ID=".$_COOKIE['CS_AdminID']."");
	         if($rowa){
                       if($rowa['CS_AdminName']!=$_COOKIE['CS_AdminUserName'] && md5($rowa['CS_AdminName'])!=$_COOKIE['CS_AdminPassWord']){
		         die("<script>window.parent.location='".CS_WebPath.$CS_Admin."login.php'</script>");
		       }
	         }else{
		         die("<script>window.parent.location='".CS_WebPath.$CS_Admin."login.php'</script>");
                 }
	}
//后台权限判断
function SystemPer($Column){
   if(empty($_COOKIE['CS_Quanx'])){
        die("<script>alert('对不起，您无权限操作此功能！');window.location='javascript:history.go(-1);'</script>");
        exit();
   }else{
        $SystemPermission=explode(",",$_COOKIE['CS_Quanx']);
        $StateOK=0;
        $ArrSystemPermission=count($SystemPermission);
           for($k=0;$k<$ArrSystemPermission;$k++){
              if($SystemPermission[$k]==$Column){
                     $StateOK=1;   
              }
           }
       if($StateOK==0){
            die("<script>alert('对不起，您无权限操作此功能！');window.location='javascript:history.go(-1);'</script>");
            exit();
       } 
   }
}
//翻页函数
function getpagerow($mysql,$pagesize){
  global $db;
  $url=$_SERVER["QUERY_STRING"];
   if(stristr($url,'&pages')){
      $url=preg_replace('/&pages=([\S]+?)$/','',$url);
   }
   if(stristr($url,'pages')){
         $url=preg_replace('/&pages=([\S]+?)$/','',$url);
   }
   if(stristr($url,'pages')){
       $url=preg_replace('/pages=([\S]+?)$/','',$url);
   }
   if(IsNull($url)) $url.="&";
      $pages=CS_Request("pages");
      $pagesok=$pagesize;
      if (!isset($pages)||$pages==""||!is_numeric($pages)||$pages<=0){
        $pages=1;
      }
      $sqlstr=$mysql;
      $res=$db ->query($sqlstr);
      $nums= $db ->num_rows($res);
      if($nums==0) $nums=1;
      $pagejs=ceil($nums/$pagesok);
      if($pages>$pagejs){
            $pages=$pagejs;
      }
      $sql=$sqlstr." LIMIT ".$pagesok*($pages-1).",".$pagesok;
      $str="";
      $result = $db ->query($sql);
      if($pages>1){
          $str.= "<a href=?".$url."pages=1 class='pages_pre J_pages_pre'>&laquo;&nbsp;上一页</a>";
      }
      if($pagejs<=10){
            for($i=1;$i<=$pagejs;$i++){
                if($i==$pages){
                    $str.="<strong>".$i."</strong>";
                }else{
                    $str.="<a href='?".$url."pages=".$i."'>".$i."</a>";
                }
            }
      }else{
            if($pages>=12){
                  for($i=$pages-5;$i<=$pages+6;$i++){
                         if($i<=$pagejs){
                                if($i==$pages){
                                    $str.="<strong>".$i."</strong>";
                                }else{
                                    $str.="<a href='?".$url."pages=".$i."'>".$i."</a>";
                                }
                         }
                  }
                  if($i<=$pagejs){
                         $str.="<a href='?".$url."pages=".$pagejs." '>".$pagejs."</a>";
                  }
            }else{
                  for($i=1;$i<=12;$i++){
                                if($i==$pages){
                                    $str.="<strong>".$i."</strong>";
                                }else{
                                    $str.="<a href='?".$url."pages=".$i."'>".$i."</a>";
                                }
                  }
                  if($i<=$pagejs){
                        $str.="<a href='?".$url."pages=".$pagejs." '>".$pagejs."</a>";
                  }
            }
      }
 if($pagejs>2 && $pages<$pagejs){
      $str.="<a href=?".$url."pages=".($pages+1)." class='pages_next J_pages_next'>下一页&nbsp;&raquo;</a>";
 }
// $str.="转<input type=text size=4 name='gopage' style='margin-top:4px;' value='".$pages."'/>&nbsp;<a style='cursor:pointer;' onclick=window.location='?".$url."pages='+gopage.value+''>GO>></a>&nbsp;";
 $arr=array($str,$result,$sql,$pagejs);
 return $arr;
}
?>
