<?php

/* ========================================================================
 * $Id: list.class.php 1714 2017-06-15 14:47:35Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onezphp.com
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
onez('page.item');
class onezphp_page_item_list extends onezphp_page_item{
  var $pagemode='page';
  function __construct(){
  }
  function header(){
    global $G;
    $pagemode=$this->pagemode=onez()->gp('pagemode');
    $tablename=$this->get('tablename');
    $label=$this->get('label');
    if($pagemode=='form'){
      
    }elseif($pagemode=='view'){
      
    }else{
      #分页列表
      $action=onez()->gp('action');
      if($action=='delete'){
        ob_clean();
        $id=(int)onez()->gp('id');
        $G['this']->data()->open($tablename)->delete("id='$id'");
        onez()->ok('删除'.$label.'成功','reload');
      }elseif($action=='steps'){
        ob_clean();
        $ids=explode(',',onez()->gp('ids'));
        $n=-1000;
        foreach($ids as $k=>$id){
          $rs=array();
          $rs['step']=$n;
          $G['this']->data()->open($tablename)->update($rs,"id='$id'");
          $n++;
        }
        onez()->ok('重新排序成功','reload');
      }elseif($action=='savestep'){
        ob_clean();
        $steps=onez()->gp('step');
        foreach($steps as $id=>$step){
          $rs=array();
          $rs['step']=(int)$step;
          $G['this']->data()->open($tablename)->update($rs,"id='$id'");
        }
        onez()->ok('保存排序成功','reload');
      }
    }
    return $this;
  }
  function body(){
    global $G;
    $tablename=$this->get('tablename');
    $label=$this->get('label');
    if($this->pagemode=='form'){
      include(dirname(__FILE__).'/list/edit.php');
    }elseif($this->pagemode=='view'){
      include(dirname(__FILE__).'/list/view.php');
    }else{
      include(dirname(__FILE__).'/list/page.php');
    }
  }
}