<?php
class Mversion extends Model
{
	var $vt;
	
	function Mversion()
	{
		parent::Model();
		$this->vt = '`cadline2`.`version`';
	}
	
	function get_all($where="",$order="projectid, pkgid"){
		$query = " SELECT * FROM ".$this->vt." WHERE `deleted` = '0'";
		if($where!="")
			$query .= " AND ".$where;
		
		if($order)
			$query .= " ORDER BY ".$order;
		
		$re = $this->db->query($query)->result();
		if( count($re) > 0 )
			return $re;
		else
			return false;
	}
	
	function get_row($ver_id){
		$query = " SELECT * FROM ".$this->vt." WHERE ver_id = '".$ver_id."'";
		
		$re = $this->db->query($query)->row();
		if( count($re) > 0 )
			return $re;
		else
			return false;
	}
	
	function get_public(){
		$query = " SELECT * FROM ".$this->vt." WHERE `deleted` = '0' AND teszt='0' AND public='1' AND aktiv='1' AND projectid != 'ArchlineXP2011' AND projectid != 'ArchlineXP2012' AND projectid != 'ArchlineXP2013' ORDER BY datum DESC";
		
		$re = $this->db->query($query)->result();
		if( count($re) > 0 )
			return $re;
		else
			return false;
	}
	
	function get_latest($project,$pkgid,$sorozatszam,$teszt='0'){
		$query = " SELECT * FROM ".$this->vt." WHERE (`usertype` LIKE '%;".$sorozatszam.";%' OR `usertype` LIKE '%;".substr($sorozatszam,0,2).";%' OR `usertype` LIKE '%all%' ) AND projectid = '".$project."' AND teszt = '".$teszt."' AND `deleted` = '0' AND `aktiv` = '1' ORDER BY pkgid DESC ";
		
		$re = $this->db->query($query)->row();
		if(isset($re->fajl))
			return $re;
		else
			return false;
	}
	
	// a kulcs kaphat-e automatikusan aktiváló kódot
	function get_aktkod($kulcs){
		$kulcs  = substr($kulcs,0,6);
		$query  = "SELECT ver_id FROM {$this->vt}";
		$query .= " WHERE ver_id=1182 AND (`usertype` LIKE '%;".$kulcs.";%' OR `usertype` LIKE '%;".substr($kulcs,0,2).";%')";
		$re = $this->db->query($query)->row();
		if( is_numeric($re->ver_id) && $re->ver_id > 0 )
			return true;
		else
			return false;
	}
	
}