<commit_before>#!/usr/bin/perl -w

use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser';
use CGI::Ajax;
use HTML::Template;
use Data::Dumper;
use CoGe::Accessory::LogUser;
use CoGe::Genome;

use vars qw($USER $UID $LAST_LOGIN $FORM $DATE);

$FORM = new CGI;
($USER, $UID, $LAST_LOGIN) = CoGe::Accessory::LogUser->get_user();

$DATE = sprintf( "%04d-%02d-%02d %02d:%02d:%02d",
		 sub { ($_[5]+1900, $_[4]+1, $_[3]),$_[2],$_[1],$_[0] }->(localtime));
my $pj = new CGI::Ajax(
		       gen_html=>\&gen_html,
		       login=>\&login,
		      );
print $pj->build_html($FORM, \&gen_html);




sub gen_html
  {
    my $template = HTML::Template->new(filename=>'/opt/apache/CoGe/tmpl/generic_page.tmpl');
    $template->param(TITLE=>'Comparative Genomics Homepage');
    $template->param(HELP=>'CoGe');
    $template->param(HEAD=>'<SCRIPT language="JavaScript" type="text/javascript" src="./js/kaj.stable.js"></SCRIPT>');
    if ($FORM->param('logout') || !$USER)
      {
	$template->param(USER=>"Not logged in");
      }
    else
      {
	$template->param(USER=>$USER);
      }
    $template->param(DATE=>$DATE);
    $template->param(BOX_NAME=>"Welcome!");
    $template->param(LOGO_PNG=>"CoGe-logo.png");
    $template->param(BODY=>gen_body());

    my $html;
    $html .= $template->output;
    return $html;
  }

sub gen_body
  {
    my $tmpl = HTML::Template->new(filename=>'/opt/apache/CoGe/tmpl/index.tmpl');
    my $html;
    if ($USER && !$FORM->param('logout'))
      {
	$tmpl->param(ACTIONS=>actions());
      }
    else
      {
	$tmpl->param(LOGIN=>1);
	my $url = $FORM->param('url') if $FORM->param('url');
	$url =~ s/:::/;/g if $url;
	$tmpl->param(url=>$url);
      }
    $html .= $tmpl->output;
    if ($FORM->param('logout'))
      {
	my $c = CoGe::Accessory::LogUser->gen_cookie(user_name=>$USER, uid=>$UID, session=>$LAST_LOGIN, exp=>"Thu, 01-Jan-1970 00:00:01 GMT");
	$html .= "<script language = 'javascript'>window.onload=delete_cookie('$c');</script>";<commit_msg>set {PATH} and added system call to clear tmp of files > 1 day old<commit_after>#!/usr/bin/perl -w

use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser';
use CGI::Ajax;
use HTML::Template;
use Data::Dumper;
use CoGe::Accessory::LogUser;
use CoGe::Genome;

use vars qw($USER $UID $LAST_LOGIN $FORM $DATE);

$ENV{PATH} = "/opt/apache/CoGe";
$FORM = new CGI;
($USER, $UID, $LAST_LOGIN) = CoGe::Accessory::LogUser->get_user();

$DATE = sprintf( "%04d-%02d-%02d %02d:%02d:%02d",
		 sub { ($_[5]+1900, $_[4]+1, $_[3]),$_[2],$_[1],$_[0] }->(localtime));
my $pj = new CGI::Ajax(
		       gen_html=>\&gen_html,
		       login=>\&login,
		      );
print $pj->build_html($FORM, \&gen_html);

#print gen_html();



sub gen_html
  {
    my $template = HTML::Template->new(filename=>'/opt/apache/CoGe/tmpl/generic_page.tmpl');
    $template->param(TITLE=>'Comparative Genomics Homepage');
    $template->param(HELP=>'CoGe');
    $template->param(HEAD=>'<SCRIPT language="JavaScript" type="text/javascript" src="./js/kaj.stable.js"></SCRIPT>');
    if ($FORM->param('logout') || !$USER)
      {
	$template->param(USER=>"Not logged in");
      }
    else
      {
	$template->param(USER=>$USER);
      }
    $template->param(DATE=>$DATE);
    $template->param(BOX_NAME=>"Welcome!");
    $template->param(LOGO_PNG=>"CoGe-logo.png");
    $template->param(BODY=>gen_body());

    my $html;
    $html .= $template->output;
    return $html;
  }

sub gen_body
  {
    my $tmpl = HTML::Template->new(filename=>'/opt/apache/CoGe/tmpl/index.tmpl');
    my $html;
    if ($USER && !$FORM->param('logout'))
      {
	$tmpl->param(ACTIONS=>actions());
      }
    else
      {
	$tmpl->param(LOGIN=>1);
	my $url = $FORM->param('url') if $FORM->param('url');
	$url =~ s/:::/;/g if $url;
	$tmpl->param(url=>$url);
	print STDERR "Clearning old tmp files. . .\n";
	system "/usr/bin/find /opt/apache/CoGe/tmp -depth -mindepth 1 -ctime +1 -delete";

      }
    $html .= $tmpl->output;
    if ($FORM->param('logout'))
      {
	my $c = CoGe::Accessory::LogUser->gen_cookie(user_name=>$USER, uid=>$UID, session=>$LAST_LOGIN, exp=>"Thu, 01-Jan-1970 00:00:01 GMT");
	$html .= "<script language = 'javascript'>window.onload=delete_cookie('$c');</script>";
{'fraction_non_alphanumeric': 0.23120973514674303, 'fraction_numerical': 0.01789549033643522, 'mean_word_length': 3.897196261682243, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 102, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5139714', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1627, 'n_words': 276}