#! /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, "$story_id",); push(@links, "", $q->a({-href=>"story.cgi?story_id=$story_id"}, $name), ""); push(@links, "$parts", "" . $i_lang{"$lang $c_lang"} . ""); if ($status == 0) ## Terminated. { push(@links, "$i_s_end{$lang}"); push(@links, " "); } elsif ($status == 1) ## Writing. { if ($user_id eq $owner) { my($part_no) = $parts + 1; # The part after the official story. # my(@parts) = get_parts($story_id, $part_no); my($parts) = scalar(@parts)/2; push(@links, "$i_s_wri{$lang} ($parts)"); } else { push(@links, "$i_s_wri{$lang}"); } is_user_alternative($user_id, $story_id, $parts + 1) ? push(@links, "OK") : push(@links, " "); } elsif ($status == 2) ## Voting { my($tot) = anything_to_vote_on($story_id, $parts + 1); push(@links, "$i_s_vot{$lang} ($tot)$voted"); is_user_vote($user_id, $story_id, $parts + 1) ? push(@links, "OK") : push(@links, " "); } elsif ($status == 3) ## Halted/Paused { push(@links, "$i_s_pau{$lang}"); push(@links, " "); } ## Add the administration link, but for the owner only. ###################### if ($status && ($owner eq $user_id)) { $is_owner++; # The user owns a story. push(@links, "", $q->a({-href=>"adm.cgi?story_id=$story_id"}, $i_adm{$lang}), ""); # As it does not make sense to administer a terminated story. # } push(@links, "\n"); } if ($count) { print "\n" . ""; print @links; @links = (); print "
ID$i_name{$lang}$i_part{$lang}$i_lang{$lang} $i_state{$lang}
\n"; } else { $lang_filter ? box_text($i_nost1{$lang} . " " . $i_lang{"$lang $lang_filter"} . " " . $i_nost2{$lang}, "#FFFF00") # No stories in the chosen language. # : box_text($i_nost3{$lang} . " " . $i_nost2{$lang}, "#FFFF00"); # No stories at all. # } ##!! print $q->p, $q->em($i_comm{$lang}), $q->p; ## Check for a Super User ###################################################### if ($authenticated) # Must be authenticated. { my($su) = 0; foreach (@super_users) { if ($mail eq $_) { $su++; last; } } push(@links, $q->a({-href=>"super.cgi"}, $i_add{$lang})) if $su; } push(@links, $q->a({-href=>"login.cgi"}, $su_reg{$lang})) unless $authenticated; push(@links, $q->a({-href=>"help.cgi?help=logout"}, $i_logou{$lang})); push(@links, $q->a({-href=>"help.cgi?help=main"}, $i_help{$lang})); print $q->p, join(" | ", @links), $q->p; print $q->p; ## Finished #################################################################### print bottom_line(), $q->end_html(); disconnect_db(); ################################################################################ if (1 == 0) { @super_users; # To stop 'perl -w' from complaining. # } ################################################################################