Beispiel #1
0
 function update()
 {
     //检测是否具有配置权限
     if ($this->user['group_type'] > MAX_ADMIN_TYPE) {
         if (!$this->user['prms']['app_prms'][APP_UNIQUEID]['setting']) {
             $this->errorOutput(NO_PRIVILEGE);
         }
     }
     $id = intval($this->input['id']);
     if (!$id) {
         $this->errorOutput('未找到分类id');
     }
     $data = array('sort_name' => urldecode($this->input['sort_name']), 'sort_dir' => trim(urldecode($this->input['sort_dir'])), 'agent_switch' => intval($this->input['agent_switch']), 'agent' => trim($this->input['agent']));
     //如果结尾没有/自动加上
     $sort_dir = substr($data['sort_dir'], -1, 1);
     if ($sort_dir != '/') {
         $data['sort_dir'] = $data['sort_dir'] . '/';
     }
     //判断分类目录是否存在
     if ($data['sort_dir']) {
         $sql = "SELECT sort_dir FROM " . DB_PREFIX . "mobile_sort WHERE id = " . $id;
         $res = $this->db->query_first($sql);
         if ($res['sort_dir'] != $data['sort_dir']) {
             $sql = "SELECT id FROM " . DB_PREFIX . "mobile_sort WHERE sort_dir = '" . $data['sort_dir'] . "'";
             $res2 = $this->db->query_first($sql);
             if ($res2['id']) {
                 $this->errorOutput('目录已经存在');
             }
         }
     }
     $sql = "UPDATE " . DB_PREFIX . "mobile_sort SET ";
     foreach ($data as $k => $v) {
         $sql .= "`" . $k . "`='" . $v . "',";
     }
     $sql = rtrim($sql, ',');
     $sql = $sql . ' WHERE id = ' . $id;
     $this->db->query($sql);
     if ($res['sort_dir'] != $data['sort_dir']) {
         //模板文件路径
         if (!defined('MOBILE_API_TPL')) {
             define('MOBILE_API_TPL', '../api/apitpl.php');
         }
         $tpl = MOBILE_API_TPL;
         //获取模板文件
         $tpl_str = @file_get_contents($tpl);
         if ($tpl_str) {
             $con = " AND m.sort_id = " . $id;
             //查询文件配置
             $sql = "SELECT m.*,s.sort_dir FROM " . DB_PREFIX . "mobile_deploy m \r\n\t\t\t\t\t\tLEFT JOIN " . DB_PREFIX . "mobile_sort s\r\n\t\t\t\t\t\t\tON m.sort_id=s.id \r\n\t\t\t\t\t\tWHERE 1 " . $con;
             $g = $this->db->query($sql);
             while ($j = $this->db->fetch_array($g)) {
                 $return[] = $j;
             }
             //生成文件,支持批量
             if (is_array($return) && count($return)) {
                 foreach ($return as $k => $v) {
                     mobile_build_file($v, $tpl_str);
                 }
             }
             rmdir(DATA_DIR . $res['sort_dir']);
         }
     }
     $this->addItem('success');
     $this->output();
 }
Beispiel #2
0
 /**
  * 
  * 生成接口文件(支持生成分类下接口)
  * @param id 接口文件Id
  * @param sort_id 分类id
  */
 function build_api_file()
 {
     //检测是否具有配置权限
     if ($this->user['group_type'] > MAX_ADMIN_TYPE) {
         if (!$this->user['prms']['app_prms'][APP_UNIQUEID]['setting']) {
             $this->errorOutput(NO_PRIVILEGE);
         }
     }
     $ids = urldecode($this->input['id']);
     //接口文件Id
     $sort_ids = urldecode($this->input['sort_id']);
     //分类id
     if (!$ids && !$sort_ids) {
         $this->errorOutput(NOID);
     }
     //模板文件路径
     if (!defined('MOBILE_API_TPL')) {
         define('MOBILE_API_TPL', '../api/apitpl.php');
     }
     $tpl = MOBILE_API_TPL;
     if (!is_readable($tpl)) {
         $this->errorOutput(NOT_ALLOW_READ);
     }
     $tpl_str = '';
     //获取模板文件
     $tpl_str = @file_get_contents($tpl);
     if (!$tpl_str) {
         $this->errorOutput(NOT_ALLOW_READ);
     }
     $con = '';
     if ($ids) {
         $con = " AND m.id IN (" . $ids . ")";
     } else {
         if ($sort_ids) {
             $con = " AND m.sort_id IN (" . $sort_ids . ")";
         }
     }
     //查询文件配置
     $sql = "SELECT m.*,s.sort_dir,s.agent_switch,s.agent FROM " . DB_PREFIX . "mobile_deploy m \r\n\t\t\t\tLEFT JOIN " . DB_PREFIX . "mobile_sort s\r\n\t\t\t\t\tON m.sort_id=s.id \r\n\t\t\t\tWHERE 1 " . $con;
     $g = $this->db->query($sql);
     while ($j = $this->db->fetch_array($g)) {
         if (!$j['agent_switch']) {
             $j['agent'] = '';
         }
         unset($j['agent_switch']);
         $return[] = $j;
     }
     //生成文件,支持批量
     if (is_array($return) && count($return)) {
         foreach ($return as $k => $v) {
             mobile_build_file($v, $tpl_str);
         }
     }
     $this->addItem('success');
     $this->output();
 }
 public function lead_file()
 {
     $sort_id = intval($this->input['sort_id']);
     if (!$sort_id) {
         $this->errorOutput('分类id不存在');
     }
     $sort_dir = $this->input['sort_dir'];
     if (!$sort_dir) {
         $sql = "SELECT sort_dir FROM " . DB_PREFIX . "mobile_sort WHERE id = " . $sort_id;
         $res = $this->db->query($sql);
         $sort_dir = $res['sort_dir'];
     }
     if (!$sort_dir) {
         $this->errorOutput('sort_dir不存在');
     }
     if (!$_FILES['filedata']['tmp_name']) {
         $this->errorOutput(NO_FILE);
     }
     $original = urldecode($_FILES['filedata']['name']);
     $filetype = strtolower(strrchr($original, '.'));
     if (!in_array($filetype, array('.json'))) {
         $this->errorOutput('此文件格式不支持');
     }
     $name = date('Y-m-d', TIMENOW) . '-' . TIMENOW . hg_rand_num(6);
     $filename = $name . $filetype;
     $filepath = DATA_DIR . $sort_dir;
     if (!hg_mkdir($filepath) || !is_writeable($filepath)) {
         $this->errorOutput(NOWRITE);
     }
     if (!@move_uploaded_file($_FILES['filedata']['tmp_name'], $filepath . $filename)) {
         $this->errorOutput(FAIL_MOVE);
     }
     $json = @file_get_contents($filepath . $filename);
     if ($json) {
         $data = json_decode($json, 1);
         if (!$data) {
             return false;
         }
         //模板文件路径
         if (!defined('MOBILE_API_TPL')) {
             define('MOBILE_API_TPL', '../api/apitpl.php');
         }
         $tpl = MOBILE_API_TPL;
         //获取模板文件
         $tpl_str = @file_get_contents($tpl);
         foreach ($data as $val) {
             if (empty($val)) {
                 continue;
             }
             unset($val['id']);
             $val['sort_id'] = $sort_id;
             $sql = "INSERT INTO " . DB_PREFIX . "mobile_deploy SET ";
             foreach ($val as $k => $v) {
                 $sql .= '`' . $k . "`='" . $v . "',";
             }
             $sql = rtrim($sql, ',');
             $this->db->query($sql);
             if ($tpl_str) {
                 $val['sort_dir'] = $sort_dir;
                 mobile_build_file($val, $tpl_str);
             }
         }
         unlink($filepath . $filename);
         $this->addItem('success');
     }
     $this->output();
 }
Beispiel #4
0
 /**
  *查询生成文件api的参数 
  * 
  * @param int $id api文件id
  */
 private function create_mobile_api_file($id)
 {
     //模板文件路径
     if (!defined('MOBILE_API_TPL')) {
         define('MOBILE_API_TPL', '../api/apitpl.php');
     }
     $tpl = MOBILE_API_TPL;
     if (!is_readable($tpl)) {
         $this->errorOutput(NOT_ALLOW_READ);
     }
     $tpl_str = '';
     //获取模板文件
     $tpl_str = @file_get_contents($tpl);
     if (!$tpl_str) {
         $this->errorOutput(NOT_ALLOW_READ);
     }
     //查询文件配置
     $sql = "SELECT m.*,s.sort_dir FROM " . DB_PREFIX . "mobile_deploy m \r\n\t\t\t\tLEFT JOIN " . DB_PREFIX . "mobile_sort s\r\n\t\t\t\t\tON m.sort_id=s.id \r\n\t\t\t\tWHERE m.id = " . $id;
     $setting = $this->db->query_first($sql);
     //生成文件
     mobile_build_file($setting, $tpl_str);
 }