<?php
/**
 * Filename : subject_item.class.php
 * Author : zhaobin
 * Creation time : 14:28:28 - 2012-11-13
 * Description : 【橙创家校通v4.0】 (C)2010-2012 Tuntron Inc.
 * 
 * 科目设置类文件
 * 
 */

if (!defined('IS_RUN')) die('Forbidden');


class tj_subject_item extends tj_model {
	var $dbinfo;
	var $table;
    var $key = 'sid';
    var $dbpre;
    
	function __construct() {
		global $_G;
		parent::__construct();
		$this->init_field();
		$this->dbinfo = $_G['dbinfo'];
		$this->table = $this->dbinfo['dbpre'] . 'subject_item';
		$this->dbpre = $this->dbinfo['dbpre'];
	}

    function msm_fileouncement() {
        $this->__construct();
    }

	function init_field() {
		$this->add_field('sid,sort,bid,subjectname');
		$this->add_field_fun();
		$this->add_field_fun();
        $this->add_field_fun();
	}
	
	function read_all($bid){
		$sql = "
			SELECT * FROM {$this->table} WHERE bid in (0,{$bid}) ORDER BY sort desc;
		";
		return $this->db->fetch_all_assoc($sql);
	}
	
	function read_one($sid) {
        $this->db->from($this->table);
        $this->db->where('sid', $sid);
        $this->db->select('sid,subjectname');
        return $this->db->once_fetch_assoc();
    }
	
	function add_subject_item($post){
		$subjectname = $post['subjectname'];
		$sort = $post['sort'];
		$bid = $post['bid'];
		$sql = "
			INSERT {$this->table}
			(sort, bid, subjectname)
			VALUES
			('$sort', '$bid', '$subjectname')
		";
		return $this->db->ady_query($sql, 'insert');
	}
	
	function edit_subject_item($post){
		$subjectname = $post['subjectname'];
		$sort = $post['sort'];
		$sid = $post['sid'];
		$sql = "
			UPDATE {$this->table}
			SET sort='$sort',subjectname='$subjectname'
			WHERE sid='$sid'
		";
		return $this->db->ady_query($sql, 'update');
	}
	
	function del_subject_item($sid){
		$sql = "
			DELETE FROM {$this->table} WHERE sid='$sid'
		";
		return $this->db->ady_query($sql);
	}
	
	function get_sid_by_name($name){
		$sql = "
			SELECT sid FROM {$this->dbpre}subject_item WHERE subjectname='$name'
		";
		return $this->db->fetch_all_assoc($sql);
	}

}
?>