#!/usr/bin/perl
use strict;
push(@INC,'/home/oc/cgi-bin/');
use lib '/home/oc/cgi-bin/';
use lib './';
use OC;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use HTML::Template;
use Tie::IxHash;
use Digest::MD5 qw(md5_hex);
use Mail::Sender;
use vars qw/
%CONFIG
$template
%form
%cookie
$self_url
$TITLE
@LINKS
$BODY
@DISPLAYED
$CAN_EDIT
$LOGGED_IN
@NOTE
$NAVIGATION
$USERNAME
$AC_TYPE
$PANEL
/;
sub Initialize {
%form=();
my $query=new CGI;
foreach ($query->param) {
$form{$_}=$query->param($_);
}
foreach ($query->cookie) {
$cookie{$_}=$query->cookie($_);
}
%CONFIG=%OC::CONFIG;
$self_url=$CONFIG{account_url};
# $self_url=$ENV{REQUEST_URI};
# $self_url=~s/^(.*)\?.*$/$1/;
# $self_url=~s/^(.*.cgi).*$/$1/;
@DISPLAYED=();
@LINKS=();
$TITLE='';
$BODY='';
$PANEL='';
@NOTE=();
$NAVIGATION='';
$LOGGED_IN=0;
$AC_TYPE='';
}
sub ConnectToDatabase {
if (!defined $::db) {
$::db = DBI->connect("DBI:mysql:$CONFIG{db_name}:$CONFIG{db_host}:
$CONFIG{db_port}",$CONFIG{db_username},$CONFIG{db_password})
|| die "Can't connect to database server: $CONFIG{db_name} $CONFIG{db_host} $CONFIG{db_port}";
}
return $::db;
}
sub PrepareSQL {
my ($str) = (@_);
$::sth=$::db->prepare($str);
}
sub ExecuteSQL {
$::sth->execute(@_) || die "Could not execute SQL statement";
}
sub SendSQL {
PrepareSQL(@_);
ExecuteSQL();
}
sub FetchSQLData {
return $::sth->fetchrow_array();
}
sub Note {
push(@NOTE,$_[0]);
}
sub Output_Notes {
my $result="";
foreach (@NOTE) {
$result.="$_
";
}
$result.="
"; return $result; } sub Prepare_Template { $template=HTML::Template->new( filename=>$_[0], die_on_bad_params=>0, loop_context_vars=>1, global_vars=>0, shared_cache=>0, ); $template->param(table_color1=>$CONFIG{color}{table1}); $template->param(table_color3=>$CONFIG{color}{table3}); } sub Block_Edit_Link { my ($account)=@_; if ($CAN_EDIT) { return ""; } else { return ''; } } sub Right_Table { my $selected=$_[0]; my $table="Accounts"; if ($selected eq 'login') { $table.=OC::Li("Login"); } else { $table.=OC::Li("Login"); } if ($selected eq 'lost_password') { $table.=OC::Li("Lost password?"); } else { $table.=OC::Li("Lost password?"); } if ($LOGGED_IN<1 || $selected eq 'get_account') { if ($selected eq 'get_account') { $table.=OC::Li("Get account"); } else { $table.=OC::Li("Get account"); } } if ($selected eq 'people') { $table.=OC::Li("People at OpenCores"); } else { $table.=OC::Li("People at OpenCores"); } return $table; } sub Admin_Links { my $screen=$_[0]; my %row=(); $row{name}="Account queue"; if ($screen ne 'queue') { $row{link}="$self_url?cmd=queue"; } push(@LINKS,\%row); my %row=(); $row{name}="Browse accounts"; if ($screen ne 'browse') { $row{link}="$self_url"; } push(@LINKS,\%row); } sub Request_Form { $TITLE="Get account"; $BODY.="Note: account is required only for maintainig your projects and/or writing news and articles. All other feature of OpenCores web are available to anyone. Are you sure that you need account?
"; $BODY.="Please make sure you provide a valid email address because email with password will be sent to that address. Without password you are unable to login. Also you must provide information why you need account. If you are going to start new project or join an existing one please let as know more about this.
"; $BODY.=Output_Notes; $BODY.="
"; $BODY.=" | "; my $table=OC::Li("to grab files from CVS"); $table.=OC::Li("to join discussion in our forums"); $BODY.=OC::Small_Table("Account is NOT required",$table); $BODY.=" |
";
$BODY.="
"; $BODY.="
Skills".Block_Edit_Link($username)." $skils"; } my @project=(); SendSQL("select project from project_maintainers where username='$username'"); while (my $result=FetchSQLData) { push(@project,$result); } if (scalar(@project)) { $fullname=ucfirst($username) if ($fullname eq ''); $BODY.=" Projects of $fullname "; foreach (@project) { SendSQL("select display_name,short_desc from project where name='$_'"); my @result=FetchSQLData(); $result[1]=${OC::Smart_Reformat(\$result[1])}; $BODY.=" $result[1] "; } } my %news=(); tie (%news,'Tie::IxHash'); SendSQL("select id,title from news where author='$username' and status='approved' order by added desc"); while (my @result=FetchSQLData) { $news{$result[0]}=$result[1]; } if (scalar(keys %news)) { $BODY.=" Posted news "; foreach (keys %news) { $BODY.=" Posted articles "; foreach (keys %article) { $BODY.=" "; SendSQL("select email from email_aliases where alias='$username\@opencores.org'"); my $email=FetchSQLData(); $help=~s/KEY_USERNAME/$username/g; $help=~s/KEY_EMAIL/$email/g; $help=${OC::Smart_Reformat(\$help)}; $BODY.=$help; } sub Requests { my ($username)=@_; $TITLE="Requests"; $BODY.="Project requests"; SendSQL("select display_name,status,response,added from project_queue where username='$username' order by added desc"); my $cnt=0; while (my @result=FetchSQLData) { $BODY.=" $result[0] - ".OC::Time_To_Str($result[3],'nice')." No requests till now"; } $BODY.=" "; $BODY.="News requests"; SendSQL("select title,status,response,added from news where author='$username' order by added desc"); my $cnt=0; while (my @result=FetchSQLData) { $BODY.=" $result[0] - ".OC::Time_To_Str($result[3],'nice')." No requests till now"; } $BODY.=" "; $BODY.="Article requests"; SendSQL("select title,status,response from article where author='$username' order by added desc"); my $cnt=0; while (my @result=FetchSQLData) { $BODY.=" $result[0] - ".OC::Time_To_Str($result[3],'nice')." No requests till now"; } } sub Admin { my ($account)=@_; $TITLE="Administration"; SendSQL("select fullname, type, email, homepage, skils, city, state, country from account where username='$account'"); my ($fullname,$type,$email,$homepage,$skils,$city,$state,$country)=FetchSQLData; $BODY.="
| ".Right_Table('login')." |