<?php
/**
 * @package linea21.modules
 * @subpackage workshoprep
 * @author linea21 <info@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 * 'Workshoprep' (as Workshop Report) module is used by 'Workshop' modules
 */

//////////// Check Inclusion de pages ////////////
if (!function_exists('AuthenthificationProcess')) {
    include_once("../lib/lib_common.php");
    ReloadIndex('admin');
} 
////////////

$req_list_theme = "SELECT T.theme_id, T.theme_name, T.theme_statut, SDT.sdtheme_name, SDT.sdtheme_id FROM " . T_THEME . " AS T LEFT OUTER JOIN ". T_SD_THEME ." AS SDT ON SDT.sdtheme_id=T.theme_sd_theme WHERE T.theme_statut  <> 'E' ORDER BY sdtheme_range DESC, sdtheme_name DESC, theme_name ASC;";
$req_list_level = "SELECT level_id, level_name FROM " . T_LEVEL. " WHERE level_statut<>'E' ORDER BY level_range DESC;";
$req_list_scale = "SELECT scale_id, scale_denomination FROM " . T_SCALE . " WHERE scale_statut<>'E' ORDER BY scale_denomination ASC;";

$req_quickbox_add = "SELECT workrep_id, substring(workrep_title from 1 for 50) as workrep_title, to_char(workrep_date_crea, '".toStringSqlDate('long')."') AS workrep_date_crea_display FROM " . T_WORK_REP . " WHERE workrep_statut  = 'P' OR workrep_statut = 'D'  ORDER BY workrep_date_crea DESC OFFSET 0 LIMIT 10;";
$req_quickbox_sup = "SELECT workrep_id,  substring(workrep_title from 1 for 50) as workrep_title, to_char(workrep_last_modify, '".toStringSqlDate('long')."') AS workrep_last_modify_display, to_char(workrep_date_crea, '".toStringSqlDate()."') AS workrep_date_crea_display FROM " . T_WORK_REP . " WHERE workrep_statut = 'E' ORDER BY workrep_last_modify DESC OFFSET 0 LIMIT 10;";
$req_quickbox_mod = "SELECT workrep_id, substring(workrep_title from 1 for 50) as workrep_title, to_char(workrep_last_modify, '".toStringSqlDate('long')."') AS workrep_last_modify_display, to_char(workrep_date_crea, '".toStringSqlDate()."') AS workrep_date_crea_display FROM " . T_WORK_REP . " WHERE workrep_statut  <> 'E' ORDER BY workrep_last_modify DESC OFFSET 0 LIMIT 10;";


function SQL_getoneCompleteWorkshopRep($work_id, $statut='E') {
	if($statut=='E') $statut= "<>'".$statut."'";
	else $statut= "='".$statut."'";
	$requete =	"SELECT WR.workrep_title , WR. workrep_resume, WR.workrep_comment, WR.workrep_statut, ".
				"W.workshop_denomination, WR.workrep_workshop_id, ".
				"to_char(WR.workrep_date_crea, '".toStringSqlDate()."') AS workrep_date_crea_display, ".
				"to_char(WR.workrep_last_modify, '".toStringSqlDate('long')."') AS workrep_last_modify_display, ".
				"to_char(WR.workrep_published_date, '".toStringSqlDate()."') AS workrep_published_date_display ".
				"FROM " . T_WORK_REP . " AS  WR ".
				"LEFT OUTER JOIN ".T_WORK." AS W on W.workshop_id=WR.workrep_workshop_id ".
				"WHERE workrep_id='".$work_id."' AND workrep_statut".$statut." LIMIT 1;";
	#echo $requete; 
	return $requete;
}

if(!function_exists('SQL_getWorkshopParts')) {
	function SQL_getWorkshopParts($work_id) {
		$requete =	"SELECT WC.workrepcon_id, WC.workrepcon_title FROM " . J_PARTS ." AS JW ".
					"LEFT OUTER JOIN ".T_WORK_REP_CONT." AS WC ON JW.j_parts_id=WC.workrepcon_id ".
					"WHERE  JW.j_root_id='".$work_id."' AND j_type='W' AND workrepcon_validity='Y' ORDER BY WC.workrepcon_date_crea ASC;";
		#echo $requete;
		return $requete;
	}
}

function SQL_getWorkshopDenomination($work_id) {
	$requete =	"SELECT workshop_denomination FROM " . T_WORK . " WHERE workshop_id='".$work_id."';";
	return $requete;
}

function SQL_getWorkshopRepTitle($workrep_id) {
	$requete =	"SELECT workrep_title FROM " . T_WORK_REP . " WHERE workrep_id='".$workrep_id."';";
	return $requete;
}

// Copie conforme de celle qui se trouve dans publication
function SQL_GetResources($ID, $type, $ressource, $sql_object)
    {
		switch ($ressource) {
        case 'BIBLIO':
            $TDB_LIAISON = J_BIBLIO;
			$ACTIVE_TABLE = T_BIBLIO_RES;
			$join_active="bibliores";
			$champ2="j_biblio_id";
            break;
        case 'LINK':
            $TDB_LIAISON = J_LINK;
			$ACTIVE_TABLE = T_LINK_RES;
			$join_active="linkres";
			$champ2="j_link_id";
            break;
        case 'MULTI':
            $TDB_LIAISON = J_MULTI;
			$ACTIVE_TABLE = T_MULTI_RES;
			$join_active="multires";
			$champ2="j_multi_id";
            break;
        default:
            return false;
        } 

        $requete = "SELECT * FROM " . $ACTIVE_TABLE . " LEFT OUTER JOIN ".$TDB_LIAISON." ON ".$champ2."=".$join_active."_id WHERE j_root_id='".$ID."' AND j_type='".substr($type, 0, 1)."' AND ".$join_active."_validity='Y' ORDER BY ".$join_active."_date_crea ASC;";
		#echo $requete;
        $result = $sql_object -> DBSelect ($requete);
				
        return $result;
    } 

?>
