<?php
/**
 * [LJCMS] (C)2012-2099 LJdev,Inc.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2013.11.19
 */

class languageAModel extends X {

    public function getList($items) {
        $where      = " WHERE 1=1".$items['searchsql'];
        $start      = ($items['page']-1)*$items['pagesize'];
        $countsql   = "SELECT COUNT(*) AS my_count FROM ".DB_PREFIX."lang AS v".$where;
        $total      = parent::$obj->fetch_count($countsql);
        $sql        = "SELECT * FROM ".DB_PREFIX."lang ".
            $where." ORDER BY id ASC LIMIT ".$start.", ".$items['pagesize']."";
        $array = parent::$obj->getall($sql);
        foreach ($array as $key=>$value) {
            $array[$key]['url'] = XUrl::getContentUrl('hr', $value['dirname'], $value['hrid']);
        }
        return array($total, $array);
    }


    public function getData($id) {
        $sql = "SELECT * FROM ".DB_PREFIX."lang".
            " WHERE id='".intval($id)."'";
        $data = parent::$obj->fetch_first($sql);
        return $data;
    }
    public function get_lang_data($id) {
        $lang= parent::$lang;
        $sql = "SELECT * FROM ".DB_PREFIX."language".
            " WHERE name='$id' AND lang='$lang'";
        $data = parent::$obj->fetch_first($sql);
        return $data;
    }
    public function getData1($id) {
        $sql = "SELECT * FROM ".DB_PREFIX."lang".
            " WHERE lang='$id'";
        $data = parent::$obj->fetch_first($sql);
        return $data;
    }

    public function doAdd($array, $attrs) {
        $array['time']=time();
        $result = parent::$obj->insert(DB_PREFIX.'lang', $array);
        return $result;
    }


    public function doEdit($id, $array, $attrs) {
        $result = parent::$obj->update(DB_PREFIX.'lang', $array, "id='".intval($id)."'");
        return $result;
    }
    public function doEdit_lang($id, $array) {
        $lang= parent::$lang;
        $result = parent::$obj->update(DB_PREFIX.'language', $array, "name='$id' AND lang='$lang'");
        return $result;
    }

    public function doDel($id) {
        return parent::$obj->query("DELETE FROM ".DB_PREFIX."lang WHERE id='".intval($id)."'");

    }


    public function doUpdate($id, $type) {
        if ($type == 'flagopen') {
            return parent::$obj->query("UPDATE ".DB_PREFIX."hr SET flag='1' WHERE hrid='".intval($id)."'");
        }
        elseif ($type == 'flagclose') {
            return parent::$obj->query("UPDATE ".DB_PREFIX."hr SET flag='0' WHERE hrid='".intval($id)."'");
        }
        elseif ($type == 'istopopen') {
            return parent::$obj->query("UPDATE ".DB_PREFIX."hr SET istop='1' WHERE hrid='".intval($id)."'");
        }
        elseif ($type == 'istopclose') {
            return parent::$obj->query("UPDATE ".DB_PREFIX."hr SET istop='0' WHERE hrid='".intval($id)."'");
        }
        elseif ($type == 'eliteopen') {
            return parent::$obj->query("UPDATE ".DB_PREFIX."hr SET elite='1' WHERE hrid='".intval($id)."'");
        }
        elseif ($type == 'eliteclose') {
            return parent::$obj->query("UPDATE ".DB_PREFIX."hr SET elite='0' WHERE hrid='".intval($id)."'");
        }
    }


    public function doAddExistsFileName($filename) {
        $sql = "SELECT hrid FROM ".DB_PREFIX."hr WHERE filename='{$filename}'";
        $rows = parent::$obj->fetch_first($sql);
        if (!empty($rows)) {
            return true;
        }
        else {
            return false;
        }
        unset($rows);
    }


    public function doEditExistsFileName($id, $filename) {
        $sql = "SELECT COUNT(hrid) FROM ".DB_PREFIX."hr WHERE filename='{$filename}' AND hrid<>'{$id}'";
        $count = parent::$obj->fetch_count($sql);
        if ($count>0) {
            return true;
        }
        else {
            return false;
        }
    }

}
?>
