<?php
include(dirname(__file__)."/../includes.php");

function plugins_get_all($type=1){
	global $tablePreStr;
	$t_plugins=$tablePreStr."plugins";
	$plugin_rs=array();
	$dbo=new dbex;
  dbplugin('r');
  $type=intval($type);
  $sql="select * from $t_plugins where type=$type";
	$key="plugins_".$type;
	$key_mt="plugins_mt_".$type;
	$plugin_rs=model_cache($key,$key_mt,$dbo,$sql);
  if(empty($plugin_rs)){
  	$plugin_rs=$dbo->getRs($sql);
  }
	return $plugin_rs;
}

function plugins_get_pid($id,$type=1){
	global $tablePreStr;
	$t_plugins=$tablePreStr."plugins";
	$plugin_rs=array();
	$dbo=new dbex;
  dbplugin('r');
	$type=intval($type);
	$id_str=filt_num_array($id);
	$sql="select * from $t_plugins where type=$type and id in ($id_str)";
	return $dbo->getRs($sql);
}

function plugins_get_mine($type=1){
	global $tablePreStr;
	$t_plugins=$tablePreStr."plugins";
	$type=intval($type);
	if($type==1){
		$u_apps=get_sess_apps();
		if(!$u_apps){
			$u_apps=0;
		}
		$condition=" and id in ($u_apps) ";
	}else{
		$u_plugins=get_sess_plugins();
		$condition=" and id not in ($u_plugins) ";
		if(!$u_plugins){
			$condition="";
		}		
	}
	$plugin_rs=array();
	$dbo=new dbex;
  dbplugin('r');
  $sql="select * from $t_plugins where type=$type $condition ";
  $plugin_rs=$dbo->getRs($sql);
	return $plugin_rs;
}

?>