#!/usr/bin/perl
#------------------------------------------------------------------------------
# Copyright (C) 2001 Thomax Kaulmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.



use lib '/opt/oma/oma-bin';
use DBI;
use OMA;
use PARSE;
use lib '/opt/oma/ora/perl';
use ORAPARSE;
use lib '/opt/oma/ova/perl';
use OVAPARSE;
use lib '/opt/oma/opa/perl';
use OPAPARSE;
use lib '/opt/oma/ota/perl';
use OTAPARSE;

$|=1;

local $st;
local @row;
local $path;
local $nodecond="";
local $itemcond="";
local $node;

local $COMMENT = 1;

##   ##            ##            ######         ##   ##
### ###           ####             ##           ###  ##
#######          ##  ##            ##           #### ##
#######          ##  ##            ##           ## ####
## # ##          ######            ##           ##  ###
##   ##          ##  ##            ##           ##   ##
##   ##          ##  ##          ######         ##   ##

$db = OMA::opendb();

#$stmain=$db->prepare("
#    SELECT item.*
#	FROM item
#	WHERE item.published <> 0
#");
#$stmain->execute();
#while(@rowmain=$stmain->fetchrow()) {
#$in{'node'} = $rowmain[1];
#$in{'item'} = $rowmain[0];


$node = $in{'node'} if($in{'node'});

$nodecond="AND item.node_sid=$in{'node'}" if($in{'node'});
if($in{'item'}) {
#	toggleitem($in{'item'});
	$itemcond="AND item.sid=$in{'item'}";
}
PARSE::getmap(1);

undef(%in); undef(%ENV);

print "publish meta\n" if($COMMENT);

chdir("$OMA::PATHPREFIX/$OMA::OMABIN");
$st=$db->prepare("
		SELECT *
		FROM item
		WHERE type='meta'
		AND published > 0
		$nodecond
		$itemcond
");
$st->execute();
while(@row=$st->fetchrow()) {
	$path = OMA::getpath($row[1]);
	$cont = PARSE::showitem($row[0]);
	print "#" if($COMMENT);
}
$st->finish();


print "\npublish ora\n" if($COMMENT);
chdir("$OMA::PATHPREFIX/ora/perl/");
$st=$db->prepare("
		SELECT	item.sid,item.node_sid,item.description,
				audio_conn.audio_page, audio_conn.location
		FROM	item,audio_conn
		WHERE	item.type='ora'
		AND		item.sid=audio_conn.item_sid
		AND		item.published > 0
		$nodecond
		$itemcond
");
$st->execute();
while(@row=$st->fetchrow()) {
  $path = OMA::getpath($row[1]);
	$cont = ORAPARSE::showitem($row[0]);
	print "#" if($COMMENT);
}
$st->finish();


print "\npublish ova\n" if($COMMENT);
chdir("$OMA::PATHPREFIX/ova/perl/");
$st=$db->prepare("
		SELECT	item.sid,item.node_sid,item.description,
				video_conn.video_page, video_conn.location
		FROM	item,video_conn
		WHERE	item.type='ova'
		AND		item.sid=video_conn.item_sid
		AND		item.published > 0
		$nodecond
		$itemcond
");
$st->execute();
while(@row=$st->fetchrow()) {
  $path = OMA::getpath($row[1]);
	$cont = OVAPARSE::showitem($row[0]);
	print "#" if($COMMENT);
}
$st->finish();


print "\npublish opa\n" if($COMMENT);
chdir("$OMA::PATHPREFIX/opa/perl/");
$st=$db->prepare("
		SELECT	item.sid,item.node_sid,item.description,
				picture_conn.picture_page, picture_conn.location
		FROM	item,picture_conn
		WHERE	item.type='opa'
		AND		item.sid=picture_conn.item_sid
		AND		item.published > 0
		$nodecond
		$itemcond
");
$st->execute();
while(@row=$st->fetchrow()) {
  $path = OMA::getpath($row[1]);
	$cont = OPAPARSE::showitem($row[0]);
	print "#" if($COMMENT);
}
$st->finish();


print "\npublish ota\n" if($COMMENT);
# publish text objects
chdir("$OMA::PATHPREFIX/ota/perl/");
$st=$db->prepare("
		SELECT	item.sid,item.node_sid,item.description,
				text_conn.text_page, text_conn.location
		FROM	item,text_conn
		WHERE	item.type='ota'
		AND		item.sid=text_conn.item_sid
		AND		item.published > 0
		$nodecond
		$itemcond
");
$st->execute();
while(@row=$st->fetchrow()) {
  $path = OMA::getpath($row[1]);
	$cont = OTAPARSE::showitem($row[0]);
	print "#" if($COMMENT);
}
$st->finish();

