<?
class base
{

  public $webset, $dduser, $class, $role, $token, $uid, $user;

  function __construct()
  {

    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
      exit;
    }
    $this->webset = webset();
    $this->dduser = dduser();
    $this->class = get_class($this); //获取子类名
    $this->role = new role([], db());
    $this->check_url();
  }

  function get_url()
  {

    json(0, '', "<iframe id='iframe' src='https://mm.open.com.cn/Login/index'></iframe>");
  }

  function document()
  {

    $url = db()->get_field($_POST['table'], $_POST['id'], "url");
    $url = SITEURL . "/index.php?url=$url";
    json(0, "", $url);
  }
  function check_url()
  {
    $auth_urls = explode("\n", $this->webset['auth_urls']);
    $url = $_SERVER['REQUEST_URI'];
    //无token的情况下,判断这个url如果是在授权范围之内,则跳出授权框
    if (empty($_SERVER['HTTP_TOKEN'])) {
      // if (in_array("$url", $auth_urls))
      //     json(222,"你不是登录用户,当前页面没权限操作");
    } else {

      $uid = db()->select("user", "id", "token='" . $_SERVER['HTTP_TOKEN'] . "'");
      if (empty($uid)) {
        json(223, "账号异常重新登录");
      }

      $this->token = $_SERVER['HTTP_TOKEN'];
      $this->uid = $uid;
      $this->user = db()->get_table("user", $uid);
    }
    //有token的情况下，判断这个token的用户是否真实存在，不存在，清空token,判断这个url如果是在授权范围之内,则跳出授权框

  }
  function selectarr($where = "1=1")
  {
    $class = get_class($this); //获取子类名
    return db()->select_2_field($class, "id,title", "$where order by sort desc, id desc");
  }
  function url($id)
  {
    $url = db()->get_field($this->class, $id, "url");
    return $url ? $url : u($this->class, "view", array("id" => $id));
  }

  function upload()
  {


    if (isset($_FILES["file"])) {
      $file_name = upload("file", $saved_upload_name);
    }
    //等比例缩放
    imagecropper($file_name);

    //后续苹果手机翻转问题
    $result['src'] = ($file_name);
    echo json_encode($result, JSON_UNESCAPED_UNICODE);
    exit();
  }


  function upload122()
  {


    if (isset($_FILES["file"])) {
      $file_name = upload("file", $saved_upload_name);
    }
    //等比例缩放
    imagecropper($file_name);

    echo xcx_img($file_name);
  }





  function editor_upload()
  {

    $temps = $_FILES;
    $res = [];
    foreach ($temps as $key => $value) {
      $file_name = upload($key);
      imagecropper($file_name);
      $res[] = "/" . $file_name;
    }
    json(0, "", $res);
  }
  function set()
  {
    $data['banquan'] = $this->webset['banquan'];
    $data['tkurl'] = $this->webset['tkurl'];
    $data['kfurl'] = $this->webset['kfurl'];
    $data['xjurl'] = $this->webset['xjurl'];
    $data['gzh_img'] = xcx_img($this->webset['gzh_img']);
    $data['mobile'] = ($this->webset['mobile']);
    $data['address'] = ($this->webset['address']);
    $data['wx'] = $this->webset['wx'];
    $data['authindex'] = $this->webset['authindex'];
    $data['gzh_appid'] = $this->webset['gzh_appid'];
    $data['lxr'] = ($this->webset['lxr']);
    $data['company'] = ($this->webset['company']);
    $data['nourls'] = explode("\n", $this->webset['nourls']);
    $data['xls'] = db()->select_all("xl", "id as value,title as label", "1=1 order by sort desc,id desc");
    $data['tgscreen'] = $this->screen();
    $data['jy_img'] = xcx_img($this->webset['jy_img']);
    $data['jy_title'] = $this->webset['jy_title'];
    $data['jy_desc'] = $this->webset['jy_desc'];
    $data['xl_img'] = xcx_img($this->webset['xl_img']);
    $data['xl_title'] = $this->webset['xl_title'];
    $data['xl_desc'] = $this->webset['xl_desc'];
    $data['zhi_img'] = xcx_img($this->webset['zhi_img']);
    $data['zhi_title'] = $this->webset['zhi_title'];
    $data['zhi_desc'] = $this->webset['zhi_desc'];
    $data['new_check_auth'] = $this->webset['new_check_auth'];

    json(0, "", $data);
  }
}
