<?php
/**
 * @package linea21.modules
 * @subpackage content
 * @author linea21 <info@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 * 'Content' module is used by 'Publication' and 'Workshop' modules
 */

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

$req_max_publi_content_id = "SELECT MAX(publicon_id) AS maxid FROM " . T_PUBLI_CONT . ";";

function SQL_getPublicationParts($publi_id, $orderby='CREA', $statut='Y', $limit=-1) {
	$requete =	"SELECT PC.publicon_id, PC.publicon_title, DATE_FORMAT(PC.publicon_date_crea, '".toStringSqlDate()."') AS publicon_date_crea_display, DATE_FORMAT(PC.publicon_last_modify, '".toStringSqlDate('long')."') AS publicon_last_modify_display FROM " . J_PARTS ." AS JP ".
				"LEFT OUTER JOIN ".T_PUBLI_CONT." AS PC ON  JP.j_parts_id=PC.publicon_id ".
				"WHERE  JP.j_root_id='".$publi_id."' ".
				"AND JP.j_type='P' AND PC.publicon_validity='".$statut."' ";
	if($orderby=='CREA')	$requete.="ORDER BY PC.publicon_date_crea DESC";
	if($orderby=='MODIFY')	$requete.="ORDER BY PC.publicon_last_modify DESC";
	if($limit!=-1) $requete.= " LIMIT 0 , ".$limit;
	$requete.=";";
	return $requete;
}


function SQL_getWorkshopParts($workrep_id, $orderby='CREA', $statut='Y', $limit=-1) {
	$requete =	"SELECT W.workrepcon_id , W.workrepcon_title, DATE_FORMAT(W.workrepcon_date_crea, '".toStringSqlDate()."') AS workrepcon_date_crea_display, DATE_FORMAT(W.workrepcon_last_modify, '".toStringSqlDate('long')."') AS workrepcon_last_modify_display FROM " . J_PARTS ." AS JW ".
				"LEFT OUTER JOIN ".T_WORK_REP_CONT." AS W ON  JW.j_parts_id=W.workrepcon_id ".
				"WHERE  JW.j_root_id='".$workrep_id."' ".
				"AND JW.j_type='W' AND W.workrepcon_validity='".$statut."' ";
	if($orderby=='CREA')	$requete.="ORDER BY W.workrepcon_date_crea DESC";
	if($orderby=='MODIFY')	$requete.="ORDER BY W.workrepcon_last_modify DESC";
	if($limit!=-1) $requete.= " LIMIT 0 , ".$limit;
	$requete.=";";
	#echo $requete;
	return $requete;
}


function SQL_getPublicationTitle($publi_id) {
	$requete =	"SELECT publi_title, publi_id, publi_posted_by FROM " . T_PUBLI . " WHERE publi_id='".$publi_id."' LIMIT 1;";
	return $requete;
}

function SQL_getWorkshopRepTitleAndGroup($workrep_id) {
	$requete =	"SELECT workrep_title, workrep_id, workshop_denomination, workshop_id, workrep_workshop_id  FROM " . T_WORK_REP . " ".
				"LEFT OUTER JOIN ".T_WORK." on workshop_id=workrep_workshop_id ".
				"WHERE workrep_id='".$workrep_id."' LIMIT 1;";
	return $requete;
}

function SQL_getOnePublicationParts($publi_id) {
	$requete =	"SELECT PC.publicon_title, PC.publicon_body, PC.publicon_template, PC.publicon_photos_uri, DATE_FORMAT(PC.publicon_date_crea, '".toStringSqlDate()."') AS publicon_date_crea_display, DATE_FORMAT(PC.publicon_last_modify, '".toStringSqlDate('long')."') AS publicon_last_modify_display FROM " . T_PUBLI_CONT." AS PC ".
				"WHERE  PC.publicon_id='".$publi_id."' LIMIT 1;";
	return $requete;
}

function SQL_getOneWorkshopParts($workrep_id) {
	$requete =	"SELECT WC.workrepcon_title, WC.workrepcon_body, DATE_FORMAT( WC.workrepcon_date_crea, '".toStringSqlDate()."') AS  workrepcon_date_crea_display, DATE_FORMAT(WC.workrepcon_last_modify, '".toStringSqlDate('long')."') AS  workrepcon_last_modify_display FROM " . T_WORK_REP_CONT." AS WC ".
				"WHERE  WC.workrepcon_id='".$workrep_id."' LIMIT 1;";
	return $requete;
}

function SQL_getPreviousPublicationParts($id, $parentid) {
	$requete =	"SELECT publicon_id AS part_id, publicon_title AS part_title FROM " . J_PARTS . " ".
				"LEFT OUTER JOIN ".T_PUBLI_CONT." ON publicon_id=j_parts_id ".
				"WHERE publicon_id<'".$id."'AND j_root_id='".$parentid."' AND j_type='P' AND publicon_validity = 'Y' ORDER BY  publicon_date_crea DESC LIMIT 0,1;";
	#echo $requete;
	return $requete;
}

function SQL_getPreviousWorkshopRepParts($id, $parentid) {
	$requete =	"SELECT workrepcon_id AS part_id, workrepcon_title AS part_title FROM " . J_PARTS . " ".
				"LEFT OUTER JOIN ".T_WORK_REP_CONT." ON workrepcon_id=j_parts_id ".
				"WHERE workrepcon_id<'".$id."'AND j_root_id='".$parentid."' AND j_type='W' AND workrepcon_validity = 'Y' ORDER BY  workrepcon_date_crea DESC LIMIT 0,1;";
	#echo $requete;
	return $requete;
}

function SQL_getNextWorkshopRepParts($id, $parentid) {
	$requete =	"SELECT workrepcon_id AS part_id, workrepcon_title AS part_title FROM " . J_PARTS . " ".
				"LEFT OUTER JOIN ".T_WORK_REP_CONT." ON workrepcon_id=j_parts_id ".
				"WHERE workrepcon_id>'".$id."'AND j_root_id='".$parentid."' AND j_type='W' AND workrepcon_validity = 'Y' ORDER BY  workrepcon_date_crea ASC LIMIT 0,1;";
	#echo $requete;
	return $requete;
}

function SQL_getNextPublicationParts($id, $parentid) {
	$requete =	"SELECT publicon_id AS part_id, publicon_title AS part_title FROM " . J_PARTS . " ".
				"LEFT OUTER JOIN ".T_PUBLI_CONT." ON publicon_id=j_parts_id ".
				"WHERE publicon_id>'".$id."'AND j_root_id='".$parentid."' AND j_type='P' AND publicon_validity = 'Y' ORDER BY  publicon_date_crea ASC LIMIT 0,1;";
	#echo $requete;
	return $requete;
}

?>
