<?php

/*
 * lib_instructs相关函数库
 * ============================================================================
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。 ============================================================================
 * $Author: Yukey $
*/

if (!defined('YUKEY'))
{
    die('Hacking attempt');
}

/**
 * 获得wi下的项目列表
 *
*/

function get_wi_list($star,$num)
{
    $sql='';
	
	if($_SESSION['tbRank']>='50')
	{
	   $factory=$client='';
	}
	elseif($_SESSION['tbRank']<='40' && $_SESSION['tbRank']>'20')
	{
	   $factory="AND a.tbFactoryID='" . $_SESSION['tbCompanyID'] . "'";
	   $client='';
	}
	elseif($_SESSION['tbRank']<='20'){
	   $factory='';
	   $client="AND a.tbClientID='" . $_SESSION['tbCompanyID'] . "'";
	}
	   $sql = "SELECT a.tbWN,a.tbClientID,a.tbProductName,a.tbVersion,a.tbIssueDate,a.tbEffect,a.tbCriteria,a.tbTestPlan,a.tbKitBom,a.tbFactoryID,b.tbCompanyName,b.tbNickName,c.tbNickName AS factory FROM" . $GLOBALS['prefix']->table('instructs') . "AS a LEFT JOIN " . $GLOBALS['si']->table('companys') . " AS b ON a.tbClientID = b.tbCompanyID LEFT JOIN " . $GLOBALS['si']->table('companys') . " AS c ON a.tbFactoryID=c.tbCompanyID where UNIX_timestamp(a.`tbIssueDate`) > unix_timestamp('2007-01-01 00:00:00') ". $factory . $client . "ORDER BY a.tbProductName asc limit $star,$num";

	 if ($sql!='')
     {
     return $GLOBALS['db']->getAll($sql);
     }
     else
     {
     return false;
     }
} 
 
 function get_wi($id)
{
    $sql='';
	if($_SESSION['tbRank']!=''){
	   $sql = "SELECT a.*,b.tbCompanyName,b.tbNickName,c.tbNickName AS factory FROM" . $GLOBALS['prefix']->table('instructs') . "AS a LEFT JOIN" . $GLOBALS['si']->table('companys') . " AS b ON a.tbClientID = b.tbCompanyID LEFT JOIN" . $GLOBALS['si']->table('companys') . " AS c ON a.tbFactoryID = c.tbCompanyID WHERE a.tbWN='" . $id . "' LIMIT 1";
	}
	 
	 if ($sql!='')
     {
     return $GLOBALS['db']->getRow($sql);
     }
     else
     {
     return false;
     }
} 
 
 function get_wi_summary($product,$ver)
{
     $sql='';
	 $sql = "SELECT a.*,b.tbCompanyName,b.tbNickName,c.tbNickName AS factory,d.tbNickName AS provide FROM " . $GLOBALS['prefix']->table('instructs') . "AS a LEFT JOIN " . $GLOBALS['si']->table('companys') . " AS b ON a.tbClientID = b.tbCompanyID LEFT JOIN " . $GLOBALS['si']->table('companys') . " AS c ON a.tbFactoryID = c.tbCompanyID LEFT JOIN " . $GLOBALS['si']->table('companys') . " AS d ON a.tbProvide = d.tbCompanyID WHERE a.tbProductName='" . $product . "' AND a.tbVersion='" . $ver . "' limit 1";

	 if ($sql!='')
     {
     return $GLOBALS['db']->getRow($sql);
     }
     else
     {
     return false;
     }
} 

function get_max_ver($product)
{
     $sql='';
	 $sql = "SELECT MAX(tbVersion) FROM " . $GLOBALS['prefix']->table('instructs') . " WHERE tbProductName='" . $product . "'";
	 if ($sql!='')
     {
     return $GLOBALS['db']->getOne($sql);
     }
     else
     {
     return false;
     }
} 
?>