%args>
$c => 'news_list'
%args>
<%shared>
my %IARGS;
my $database = 'homesbyhanes';
my $database_login = 'homesbyhanes';
my $database_pass = 'blackpaper4';
my $cookieName = 'hanes';
my $domainName = 'www.homesbyhanes.com';
my $dbh;
my $isAdmin=0;
%shared>
<%init>
%IARGS =%ARGS;
$dbh = DBI->connect("DBI:mysql:$database", $database_login, $database_pass);
$m->comp("check_login");
%init>
<& $c &>
<%def default>
You have reaced the default defblock
%def>
<%def insert_news>
<%init>
$dbh->do("Insert into News set news_title = 'New Entry' ");
$m->redirect("?");
%init>
%def>
<%def news_list>
<%init>
%init>
% if ($isAdmin) {
<& admin_menu&>
%}
|
Date
|
Article
|
% my $sth = $dbh->prepare("Select * from News ORDER BY news_date_sort DESC");
% $sth->execute();
% my $data_ref;
% my $count=0;
% while ($data_ref = $sth->fetchrow_hashref()) {
<& news_row , 'data_ref' => $data_ref, 'count' => $count &>
% $count++;
%}
%def>
<%def news_row>
<%args>
$data_ref
$count
%args>
<%init>
use Date::Calc qw(:all);
my @colors = qw|FFFFFF DEDEE7|;
my $temp_url;
if ($isAdmin) {
$temp_url = "?c=edit_news&id=$data_ref->{'news_id'}";
} else {
$temp_url = "$data_ref->{'news_url'}";
}
my ($month,$day,$year) = split ('/',$data_ref->{news_date});
$month = $month || 1;
$year = $year || 1998;
$day = $day || 1;
%init>
>
|
<%Date_to_Text_Long($year,$month,$day)%>
|
<%$data_ref->{'news_title'}%>
|
>
|
|
<%$data_ref->{'news_short_description'}%>
|
%def>
<%def admin_menu>
<%init>
%init>
%def>
<%def edit_news>
<%init>
my $data_ref = $dbh->selectrow_hashref("Select * from News where news_id=?",undef,$IARGS{id});
%init>
%def>
<%def update_news>
<%init>
my @valid = qw|
news_date
news_title
news_short_description
news_url
|;
foreach (@valid) {
#print $_. " = " .$IARGS{$_} . "
";
$dbh->do("Update News set $_ = ? Where news_id = ?",undef,$IARGS{$_},$IARGS{id});
}
my ($day, $month, $year) = split ('/',$IARGS{news_date});
my $new_date = sprintf ("%04d%02d%02d",$year,$month,$day);
$dbh->do("Update News set news_date_sort = ? Where news_id = ?",undef,$new_date,$IARGS{id});
$m->redirect("?");
%init>
%def>
<%def check_login>
<%init>
my %cookies = Apache::Cookie->fetch;
if ($cookies{$cookieName}) {
$isAdmin = 1;
}
%init>
%def>
<%def login>
%def>
<%def listing_login_submit>
<%init>
my $sth;
my $login_ref;
$sth = $dbh->prepare("Select user_login_name,user_login_pass From User Where user_login_name=?");
$sth->execute($IARGS{'login_name'});
$login_ref = $sth->fetchrow_hashref;
$sth->finish;
if ( $IARGS{'login_name'} eq '') {
$m->comp("error_noreturn",message => "400 | Your login name or pass is invalid");
}
if ( $login_ref->{'user_login_name'} ne $IARGS{'login_name'} ){
$m->comp("error_noreturn",message => "401 | Your login name or pass is invalid");
}
if ($login_ref->{'user_login_pass'} ne $IARGS{'login_pass'}) {
$m->comp("error_noreturn",message => "402 | Your login name or pass is invalid");
}
my $cookie = Apache::Cookie->new(
$r,
-name => $cookieName,
-value => $IARGS{login_name},
-expires => '+100h',
-domain => $domainName,
-path => '/',
);
$cookie->bake;
$m->redirect("?");
%init>
%def>
<%def error_noreturn>
<%args>
$message => 'Error'
%args>
<%init>
%init>
%$m->flush_buffer;
%$m->abort;
%def>
<%def logout>
<%init>
my $cookie = Apache::Cookie->new(
$r,
-name => $cookieName,
-value => -1,
-expires => '-100h',
-domain => $domainName,
-path => '/',
);
$cookie->bake;
$m->redirect("?");
%init>
%def>
<%def delete_news>
<%init>
if ($IARGS{news_id} eq $IARGS{news_id_del}) {
$dbh->do("Delete from News where news_id = ?",undef,$IARGS{news_id});
}
$m->redirect("?");
%init>
%def>