<?php
class qcmsSoft extends qcms {
	var $cate = array();

	function qcmsSoft() {
		$this -> qcms();
	} 

	function param() {
		parent :: param();
		if ($this -> param['cid'] < 1) qbase::showmsg("请选择栏目");
		$this -> cate = qdb::queryFirst("select child, pur_browse from ".TABLEPRE."acategory where cid='{$this->param['cid']}' limit 1");
		if (empty($this -> cate)) qbase::showmsg("出错了，当前所属栏目不存");
		if ($this -> cate['child'] > 0) qbase::showmsg("此栏目有子栏目，不能添加内容");

		$this -> param['subject'] = trim($_POST['subject']);
		$this -> param['size'] = intval($_POST['size']);
		if (strlen($this -> param['subject']) < 4) qbase::showmsg($this -> channeltitle . "名称不能为空");

		$systems = $_POST['systems'];
		if (is_array($systems)) $this -> param['systems'] = implode(",", $systems);

		$this -> param['pic'] = trim($_POST['pic']);
		if (strlen($this -> param['pic']) > 6) $this -> param['is_pic'] = 1;
		else $this -> param['is_pic'] = 0;

		$this -> param['type'] = intval($_POST['type']);
		$this -> param['author'] = trim($_POST['author']);
		$this -> param['authorhttp'] = trim($_POST['authorhttp']);
		$this -> param['softtype'] = trim($_POST['softtype']);
		$this -> param['language'] = trim($_POST['language']);
		$this -> param['use_type'] = trim($_POST['use_type']);
		$this -> param['plugin'] = trim($_POST['plugin']);
		$this -> param['demourl'] = trim($_POST['demourl']);
		$this -> param['regurl'] = trim($_POST['regurl']);

		$this -> param['description'] = qbase::FilterString(trim($_POST['content']));
		$search = array ("'<script[^>]*?>.*?</script>'si" , "'<iframe[^>]*?>.*?</iframe>'si");
		$this -> param['description'] = preg_replace($search, '', $this -> param['description']);

		$str = $this -> param['subject'];
		$p = ord(substr($str, 0, 1));
		if ($p > 160) {
			$this -> param['a-z'] = strtoupper(substr(c($str), 0, 1)) . "-Z" ;
		} else if (($p < 48 && $p > 0) || ($p < 160 && $p > 57)) {
			$this -> param['a-z'] = strtoupper(substr($str, 0, 1));
		} else if ($p > 47 && $p < 58) {
			$this -> param['a-z'] = "0-9";
		} else {
			$this -> param['a-z'] = "xxx";
		} 

		$temp =  keyword($this -> param['description'], $this->param['subject']);
		$keyword = array();
		foreach($temp as $val){
			if(trim($val['name']) && $val['rank'] > 10) $keyword[] = trim($val['name']);
		}
		$this->param['keyword'] = implode(" ", $keyword);

	} 

	function addAction() {
		$this -> param();
		$sql = qbase::createSql($this -> table, $this -> param, 'insert');
		$id = qdb::query($sql, true);
		$this -> formatUrl($id);
		$this -> add($id);
		$this -> extend_insert($id);
	} 

	function editAction() {
		$id = intval($_POST['id']);
		$this -> param();
		$this -> formatUrl($id);
		$this -> modify($id);
		$this -> extend_update($id);
	} 

	function del($id){
		$data = parent.del($id);
		qdb::Query("delete from ".TABLEPRE."downloads_{$this->channelid}  where id='$id'" );
		return $data;
	}

	function formatUrl($id) {
		$type = intval($_POST['type']);
		$url_name = $_POST['url_name'];
		$urls = $_POST['urls'];
		$serverid = $_POST['serverid'];
		qdb::query("delete from ".TABLEPRE."downloads_{$this->channelid} where id = '{$id}' ");
		if ($type == 0) {
			if (is_array($urls)) {
				for($m = 0; $m < count($urls); $m++) {
					if ($urls[$m]) {
						qdb::query("INSERT INTO ".TABLEPRE."downloads_{$this->channelid} (id,url_name,urls, serverid) values ('{$id}','{$url_name[$m]}','{$urls[$m]}', '')");
					} 
				} 
			} 
		} else {
			if (isset($serverid) && is_array($serverid) && !empty($serverid)) {
				$serverids = implode(',', $serverid);
			} else {
				$serverids = intval($serverid);
			} 
			if ($serverids) qdb::query("INSERT INTO ".TABLEPRE."downloads_{$this->channelid} (id,urls, serverid) values ('{$id}','{$urls}', '{$serverids}')");
		} 
	} 
} 

?>