#! /usr/bin/perl ################################################################################ # # # super.cgi # # --------- # # INDIW-2000 / Futurama-prosjektet # # # ################################################################################ # # # This file is © Arne Sommer - rev. 10. May 2000. # # # ################################################################################ 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. # ################################################################################ $q = new CGI; my($header, $user_id) = cookie_header($q); # Set up (parse and maintain) the cookie. # my($mail, $authenticated) = get_mailaddress($user_id); print $header; print start_doc($q, "indifu $su_title{$lang}"); print $q->h2($su_title{$lang}), "\n"; ## Check for a Super User ###################################################### my($su) = 0; my($add_ok) = 0; if ($authenticated) # Must be authenticated. { foreach (@super_users) { if ($mail eq $_) { $su++; last; } } $add_ok = &do_add if $su; } box_text($su_noper{$lang}, "#FF0000") unless ($su); ## Finished #################################################################### push(@links, $q->a({-href=>"index.cgi"}, $i_main{$lang})); push(@links, $q->a({-href=>"super.cgi"}, $i_add{$lang})) if $add_ok; # $su; push(@links, $q->a({-href=>"help.cgi?help=logout"}, $i_logou{$lang})); push(@links, $q->a({-href=>"help.cgi?help=adm"}, $i_help{$lang})); print $q->p, join(" | ", @links), $q->p; print bottom_line(), $q->end_html(); disconnect_db(); ################### Do Add ##################################################### # # # What: Add the story to the system. # # In: None. # # Out: Shall we show the 'add anither story' link?. # # # ################################################################################ sub do_add { if ($q->param) { my($story_name) = $q->param('title'); my($limit) = $q->param('limit'); my($owner) = $q->param('owner'); my($s_lang) = $q->param('lang'); my($rules) = $q->param('rules'); ## Check for errors in the argument list ################################### my($ok) = 1; # So that we can skip the form if everything was ok. # if (length($story_name) < 7) { box_text($su_nolen{$lang}, "#FF0000"); $ok = 0; } if ($limit =~ /\D/) { box_text($su_nonum{$lang}, "#FF0000"); $ok = 0; } elsif ($limit < 100 or $limit > 10000) { box_text($su_erlim{$lang}, "#FF0000"); $ok = 0; } unless (authenticated($owner)) { box_text($su_noaut{$lang}, "#FF0000"); $ok = 0; } unless ($lang{$s_lang}) { box_text("$su_nolan{$lang}, $s_lang.", "#FF0000"); $ok = 0; } ## All is well ############################################################# if ($ok) { my($id) = add_story($owner, $story_name, $limit, $s_lang, $rules); if ($id) { box_text("$su_hist{$lang} '$story_name' $su_isreg{$lang} '$id'.", "#00FF00"); return 1; } box_text($su_error{$lang}, "#FF0000"); } } ############################################################################## my($count, %users) = get_users(); # Get a list of authenticated users (on the 'id', 'mail' form). # unless ($count) { box_text($su_n_usr{$lang}, "#FF0000"); return 1; } print $q->start_multipart_form, "$su_name{$lang}: ", $q->textfield(-name => 'title', -size => 30, -maxlength => 30), $q->br, "$su_limit{$lang}: ", $q->textfield(-name => 'limit', -default => '5000', -size => 10, -maxlength => 10), $q->br, "$su_owner{$lang}: "; ## Owner/editor. if ($count > 30) { print $q->scrolling_list(-name =>'owner', -default => $user_id, -size => 10, -values => \%users); } else { print $q->popup_menu(-name =>'owner', -values => \%users, -default => $user_id); } print $q->br, "$i_lang{$lang}: ", ## Language. $q->popup_menu(-name =>'lang', -values => \%lang, -default => $lang), $q->br, "$i_rules{$lang}: ", ## Rules/comments $q->p, $q->textarea(-name => 'rules', -rows => 5, -columns => 70), $q->br, $q->reset('Undo'), $q->defaults('Clear'), $q->submit(undef, $su_reg{$lang}), ## Register. $q->endform; return 0; } ################################################################################