home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / FAQ / discus_admin_1357211388 / source / ui-main.pl < prev    next >
Text File  |  2009-11-06  |  10KB  |  259 lines

  1. # FILE: ui-main.pl
  2. # DESCRIPTION: Discus User Interface
  3. #-------------------------------------------------------------------------------
  4. # DISCUS COPYRIGHT NOTICE
  5. #
  6. # Discus is copyright (c) 2002 by DiscusWare, LLC, all rights reserved.
  7. # The use of Discus is governed by the Discus License Agreement which is
  8. # available from the Discus WWW site at:
  9. #    http://www.discusware.com/discus/license
  10. #
  11. # Pursuant to the Discus License Agreement, this copyright notice may not be
  12. # removed or altered in any way.
  13. #-------------------------------------------------------------------------------
  14.  
  15. use strict;
  16. use vars qw($GLOBAL_OPTIONS $DCONF $PARAMS);
  17.  
  18. ###
  19. ### user_interface_main_control
  20. ###
  21. ### Main Discus User Interface
  22. ###
  23.  
  24. sub user_interface_main_control {
  25.     my ($FORMref, $cookie_str, $error, $extra) = @_;
  26.     $FORMref = parse_form($ENV{'QUERY_STRING'}, $ENV{'CONTENT_LENGTH'}) if ! defined $FORMref;
  27.     my $subst = {};
  28.     $subst->{general}->{authentication_error} = 1 if ($FORMref->{username} ne "" || $FORMref->{password} ne "");
  29.     dreq("template");
  30.     ui_show_topics(undef, $FORMref) if $FORMref->{pg} eq "topics";
  31.     $subst->{extra} = $extra;
  32.     $FORMref->{pg} = "uilogin" if $error;
  33.     $FORMref->{pg} = "" if $FORMref->{pg} eq "flogin" && ! $DCONF->{pro};
  34.     my $flag = ( $error ? 1 : 0 );
  35.     if ($FORMref->{pg} eq "emergency") {
  36.         dreq("emergpw");
  37.         make_emergency_password($FORMref);
  38.     }
  39.     if ($FORMref->{pg} eq "logout") {
  40.         dreq("ui-prfle");
  41.         $cookie_str .= uiprfle_logout($FORMref, 2);
  42.         screen_out("usrlgout", {}, $cookie_str);
  43.     }
  44.     if ($FORMref->{pg} eq "flogout") {
  45.         dreq("ui-prfle");
  46.         $cookie_str .= uiprfle_logout($FORMref, 2);
  47.         $subst->{general}->{screen} = "uilogin";
  48.         $subst->{general}->{forcedest} = "topics";
  49.         $GLOBAL_OPTIONS->{secure_topics_file} = 2 if $GLOBAL_OPTIONS->{secure_topics_file} == 0;
  50.         screen_out("usrlogin", $subst, $cookie_str);
  51.     }
  52.     if ($FORMref->{pg} eq "uilogin") {
  53.         $FORMref->{pg} = "";
  54.     }
  55.     $FORMref->{pg} = $FORMref->{forcedest} if $FORMref->{forcedest};
  56.     if (ref $extra eq 'HASH') {
  57.         $subst->{general}->{screen} = "uilogin";
  58.         $subst->{general}->{forcedest} = $extra->{forcedest};
  59.         screen_out("usrlogin", $subst, undef);
  60.     } elsif ($FORMref->{script} ne "" && $FORMref->{script} ne "discus") {
  61.         my $script = $FORMref->{script}; $FORMref->{script} = "";
  62.         my $fr = parse_form(unescape($FORMref->{query_string}), 0, undef);
  63.         $FORMref = hash_merge($FORMref, $fr, 1);
  64.         discus($script, $FORMref, undef);
  65.     } elsif ($FORMref->{pg} eq "flogin") {
  66.         $subst->{general}->{screen} = "uilogin";
  67.         $subst->{general}->{forcedest} = "topics";
  68.         $GLOBAL_OPTIONS->{secure_topics_file} = 2 if $GLOBAL_OPTIONS->{secure_topics_file} == 0;
  69.         screen_out("usrlogin", $subst, undef);
  70.     } elsif ($FORMref->{pg} eq "" && $FORMref->{sameframe} == 0 && $GLOBAL_OPTIONS->{use_no_frames} == 0) {
  71.         $subst->{general}->{screen} = "framesetter";
  72.         if ($ENV{QUERY_STRING} =~ m|^(\d+)/(\d+)|) {
  73.             my $l = $ENV{QUERY_STRING};
  74.             if ($l =~ m|^(\d+)/(\d+)#POST(\d+)|) {
  75.                 if ($DCONF->{pro}) {
  76.                     $subst->{general}->{right_frame_url} = "$DCONF->{authorize_reader}?file=/$1/$2.$DCONF->{ext}#POST$3";
  77.                 } else {
  78.                     $subst->{general}->{right_frame_url} = "$DCONF->{message_url}/$1/$2.$DCONF->{ext}#POST$3";
  79.                 }
  80.             } elsif ($l =~ m|^(\d+)/(\d+)|) {
  81.                 if ($DCONF->{pro}) {
  82.                     $subst->{general}->{right_frame_url} = "$DCONF->{authorize_reader}?file=/$1/$2.$DCONF->{ext}";
  83.                 } else {
  84.                     $subst->{general}->{right_frame_url} = "$DCONF->{message_url}/$1/$2.$DCONF->{ext}";
  85.                 }
  86.             }
  87.         } elsif ($FORMref->{post} != 0) {
  88.             my $post = $FORMref->{post};
  89.             my ($topic, $page) = ui_get_post_location($FORMref->{tpc}, $post);
  90.             if ($page == 0) {
  91.                 my $l = read_language()->{POST_WAS_NOT_FOUND_EXPLANATION};
  92.                 $l =~ s/\%showurl/$DCONF->{script_url}\/show.$DCONF->{cgi_extension}?$topic\/$topic/g;
  93.                 error_message(read_language()->{POST_WAS_NOT_FOUND}, $l, 0, 1);
  94.             } elsif ($DCONF->{pro}) {
  95.                 $subst->{general}->{right_frame_url} = "$DCONF->{authorize_reader}?file=/$topic/$page.$DCONF->{ext}#POST$post";
  96.             } else {
  97.                 $subst->{general}->{right_frame_url} = "$DCONF->{message_url}/$topic/$page.$DCONF->{ext}#POST$post";
  98.             }
  99.         } else {
  100.             $subst->{general}->{right_frame_url} = "$DCONF->{script_url}/discus.$DCONF->{cgi_extension}?pg=topics";
  101.         }
  102.     } elsif ($FORMref->{pg} eq "" && ($GLOBAL_OPTIONS->{use_no_frames} == 1 || $FORMref->{sameframe} == 1)) {
  103.         if ($ENV{QUERY_STRING} =~ m|^(\d+)/(\d+)|) {
  104.             my $l = $ENV{QUERY_STRING};
  105.             if ($l =~ m|^(\d+)/(\d+)#POST(\d+)|) {
  106.                 if ($DCONF->{pro}) {
  107.                     dreq("authwrap-PRO");
  108.                     $FORMref->{file} = "/$1/$2.$DCONF->{ext}";
  109.                     auth_wrapper($FORMref);
  110.                 } else {
  111.                     seturl("$DCONF->{message_url}/$1/$2.$DCONF->{ext}#POST$3");
  112.                 }
  113.             } elsif ($l =~ m|^(\d+)/(\d+)|) {
  114.                 if ($DCONF->{pro}) {
  115.                     dreq("authwrap-PRO");
  116.                     $FORMref->{file} = "/$1/$2.$DCONF->{ext}";
  117.                     $FORMref->{anchor} = undef;
  118.                     auth_wrapper($FORMref);
  119.                 } else {
  120.                     seturl("$DCONF->{message_url}/$1/$2.$DCONF->{ext}");
  121.                 }
  122.             }
  123.         } elsif ($FORMref->{post} != 0) {
  124.             my $post = $FORMref->{post};
  125.             my ($topic, $page) = ui_get_post_location($FORMref->{tpc}, $post);
  126.             if ($page == 0) {
  127.                 my $l = read_language()->{POST_WAS_NOT_FOUND_EXPLANATION};
  128.                 $l =~ s/\%showurl/$DCONF->{script_url}\/show.$DCONF->{cgi_extension}?$topic\/$topic/g;
  129.                 error_message(read_language()->{POST_WAS_NOT_FOUND}, $l, 0, 1);
  130.             } elsif ($DCONF->{pro}) {
  131.                 dreq("authwrap-PRO");
  132.                 $FORMref->{file} = "/$topic/$page.$DCONF->{ext}";
  133.                 $FORMref->{anchor} = undef;
  134.                 auth_wrapper($FORMref);
  135.             } else {
  136.                 seturl("$DCONF->{message_url}/$topic/$page.$DCONF->{ext}#POST$post");
  137.             }
  138.         } elsif ($FORMref->{topic} != 0 && $DCONF->{pro}) {
  139.             dreq("authwrap-PRO");
  140.             my ($v, $cache, $ckstr, $result, $privcache) = ui_validate_login($FORMref, 0);
  141.             auth_wrap_page($FORMref->{topic}, $FORMref->{page}, $ckstr);
  142.         } else {
  143.             $subst->{general}->{screen} = "topics";
  144.             ui_show_topics(undef, $FORMref, $cookie_str, $flag, $extra);
  145.         }
  146.     } elsif (($FORMref->{pg} eq "next" || $FORMref->{pg} eq "prev") && $FORMref->{topic} =~ m|^\d+$|) {
  147.         my ($page, $tree) = ui_get_next_prev_page($FORMref->{topic}, $FORMref->{page}, $FORMref->{pg});
  148.         my $topic = $FORMref->{topic};
  149.         if (-e "$DCONF->{message_dir}/$topic") {
  150.             my $hashref = GetPage($topic, $page, { no_lock => 1, no_unlock => 1 });
  151.             $hashref->{general}->{subtopic_raw} = 0;
  152.             $hashref->{general}->{messages_raw} = 0;
  153.             $hashref->{sublist} = expand_sublist($hashref->{sublist}, $topic, $tree);
  154.             header($cookie_str);
  155.             print SetPage($hashref, { return_val => 1 });
  156.             program_exit(0);
  157.         } elsif ($DCONF->{pro}) {
  158.             dreq("authwrap-PRO");
  159.             my $u = {};
  160.             $u->{file} = "/$topic/$page.$DCONF->{ext}";
  161.             $u->{COOKIE} = $FORMref->{COOKIE};
  162.             auth_wrapper($u);
  163.         }
  164.     } else {
  165.         $subst->{general}->{screen} = $FORMref->{pg};
  166.         ui_show_topics(undef, $FORMref, $cookie_str, $flag) if $FORMref->{pg} eq "topics";
  167.     }
  168.     screen_out("uimain", $subst, $cookie_str);
  169. }
  170.  
  171. ###
  172. ### ui_get_post_location
  173. ###
  174. ### Locates a post by post number and topic number by looking in the tree file
  175. ###
  176.  
  177. sub ui_get_post_location {
  178.     my ($topic, $post, $treecache) = @_;
  179.     $treecache = read_tree($topic, { no_lock => 1, no_unlock => 1 }) if ! defined $treecache;
  180.     foreach my $line (@{ $treecache }) {
  181.         foreach my $postnum (split(/,/, $line->{post_list})) {
  182.             return ($topic, $line->{page}, $line, $treecache) if $post == $postnum;
  183.         }
  184.     }
  185.     return ($topic, 0, undef, $treecache);
  186. }
  187.  
  188. ###
  189. ### ui_show_topics
  190. ###
  191. ### Spits out a skinned version of the board-topics.html file
  192. ###
  193.  
  194. sub ui_show_topics {
  195.     my ($in_topiclist, $FORMref, $cookie_str, $flag, $extra) = @_;
  196.     if ($FORMref->{action} ne "login" && $GLOBAL_OPTIONS->{use_static_topic_document} == 1 && -e "$DCONF->{message_dir}/$DCONF->{board_topics_file}") {
  197.         my $X = readfile("$DCONF->{message_dir}/$DCONF->{board_topics_file}", "ui_show_topics", { no_lock => 1, no_unlock => 1 });
  198.         header($cookie_str);
  199.         print @{$X};
  200.         program_exit(0);
  201.     }
  202.     dreq("topic-pg");
  203.     $in_topiclist = read_topic_page({ no_lock => 1, no_unlock => 1, zero_ok => 1 }) if ! defined $in_topiclist;
  204.     if ($DCONF->{pro}) {
  205.         dreq("authwrap-PRO");
  206.         ($in_topiclist, $cookie_str) = topic_list_manipulate($in_topiclist, $FORMref, $cookie_str, $flag, $extra);
  207.     }
  208.     $in_topiclist->{return_val} = 1;
  209.     if ($FORMref->{action} eq "login" && $FORMref->{script} =~ m%\W(search|allusers|board-viewtree|board-newmessages)\.$DCONF->{cgi_extension}$%) {
  210.         my $script = $1;
  211.         my $FORM = parse_form(unescape($FORMref->{query_string}), 0);
  212.         $FORM->{COOKIE} = $FORMref->{COOKIE};
  213.         while ($cookie_str =~ m|Set-Cookie: (\w+)$DCONF->{COOKIE_ID}=(.*?);|g) {
  214.             $FORM->{COOKIE}->{$1} = unescape($2);
  215.         }
  216.         discus($1, $FORM, $cookie_str);
  217.     }
  218. #    print "Content-type: text/plain\n\n";
  219.     header($cookie_str);
  220.     print write_topic_page($in_topiclist);
  221.     program_exit(0);
  222. }
  223.  
  224. ###
  225. ### ui_get_next_prev_page
  226. ###
  227. ### Returns next or previous page number
  228. ###
  229.  
  230. sub ui_get_next_prev_page {
  231.     my ($topic, $page, $action, $tree_cache) = @_;
  232.     my $t = (defined $tree_cache ? $tree_cache : read_tree($topic, { no_lock => 1, no_unlock => 1 }));
  233.     my $lc = 0;
  234.     my @j = @{ $t };
  235.     my $parent = $topic;
  236.     while (my $x = _ui_grab_page(\@j, $action)) {
  237.         $parent = $x->{parent} if $x->{page} == $page;
  238.         next if $x->{islink};
  239.         if ($x->{page} == $page) {
  240.             $lc = $x->{level};
  241.         } elsif ($lc == 0) {
  242.             next;
  243.         } elsif ($lc == $x->{level}) {
  244.             return ($x->{page}, $t);
  245.         } elsif ($lc > $x->{level}) {
  246.             return ($parent, $t);
  247.         }
  248.     }
  249.     return $parent;
  250. }
  251.  
  252. sub _ui_grab_page {
  253.     my ($array, $action) = @_;
  254.     return pop @{ $array } if $action eq "prev";
  255.     return shift @{ $array } if $action eq "next";
  256. }
  257.  
  258. 1;
  259.