#! /usr/bin/perl
################################################################################
# #
# index.cgi #
# --------- #
# INDIW-2000 / Futurama-prosjektet #
# #
################################################################################
# #
# This file is © Arne Sommer - rev. 10. May 2000. #
# #
################################################################################
# #
# This is an example site homepage (or entry page) script. It is not part of #
# the story infrastructure, but it uses the user logging provided by this #
# system (cookies). #
# #
################################################################################
use FindBin;
use lib "$FindBin::Bin/mylib";
# Get the directory where the program resides, and add the 'mylib' #
# subdirectory to the library lookup table. #
use CGI;
require "lib/indifu.pl";
## Language Specific ###########################################################
my($lang) = language();
# Get the user's prefered language. #
################################################################################
error_doc($lang) unless connect_db();
# Die gracefully if the database failed to respond. #
## Print the headers ###########################################################
$q = new CGI;
my($change_user_id) = $q->url_param('chuid') || 0;
my($lang_filter) = $q->url_param('lang') || "";
# Show only the stories in this language. #
if ($lang_filter ne "all")
{
$lang_filter = "" unless $lang{$lang_filter};
# Get rid of an unsupported language. #
}
## Set up (parse and maintain) the cookie. #####################################
my($new_user) = $q->cookie('UID') ? 0 : 1;
my($header, $user_id, $c_lang) = $change_user_id
? cookie_header($q, 0, $lang_filter) ## Change the user_id. #
: cookie_header($q, undef, $lang_filter); ## Keep the user_id. #
$lang_filter = $c_lang if $c_lang;
$lang_filter = "" if $lang_filter eq "all";
print $header;
my($mail, $authenticated) = get_mailaddress($user_id);
print start_doc($q, 'indifu story site');
my($links);
#print "[X:$c_lang/D:$lang_filter]
";
## Show a help text screen for first time visitors #############################
if ($new_user)
{
print $h_help{"$lang gen"}, $h_help{"$lang gen2"};
print_links2($q->a({-href=>"index.cgi"}, $i_main{$lang}));
print bottom_line(), $q->end_html();
disconnect_db();
exit;
}
## A Registered User ###########################################################
if ($authenticated)
{
my($ref) = $lang_filter
? "index.cgi?chuid=1\&lang=$lang_filter" ## Language filter in use. #
: "index.cgi?chuid=1"; ## No language. #
print "$i_wel1{$lang}, $mail. ",
$q->a({-href=>$ref}, $i_click{$lang}),
" ", $i_clic2{$lang}, $q->p;
}
## An Unregistered User ########################################################
else
{
print $i_wel2{$lang};
# print "$s_noreg{$lang}$s_noall{$lang}";
}
## Language Filter #############################################################
print $q->h2($i_avail{$lang});
my(@links);
$lang_filter
? push(@links, $q->a({-href=>"index.cgi?lang=all"}, $i_all{$lang}))
: push(@links, $q->b($i_all{$lang}));
# Showing all stories. #
foreach (@lang)
{
($_ ne $lang_filter)
? push(@links, $q->a({-href=>"index.cgi?lang=$_"}, $i_lang{"$lang $_"}))
: push(@links, $q->b($i_lang{"$lang $_"}));
}
print $q->p, $i_show{$lang}, join(" | ", @links), $q->p;
@links = ();
## Show the Stories ############################################################
@stories = list_stories();
my($exists, $name, $owner, $status, $parts, $limit, $created, $last_write, $c_lang);
my($count) = 0;
# The number of found stories. #
my($is_owner) = 0;
# Set if the user is the owner of at least one story. #
foreach $story_id (@stories)
{
($exists, $name, $owner, $status, $parts, $limit, $created, $last_write, $c_lang)
= get_status($story_id);
# Limit, Created and Last_write are not used here. #
if ($lang_filter) # Skip stories in other languages. #
{
next unless $c_lang eq $lang_filter;
}
next unless $exists;
# Skip stories that does not exist. #
$count++;
push(@links, "
| ID | $i_name{$lang} | $i_part{$lang} | " . "$i_lang{$lang} | $i_state{$lang} |
|---|