#!/usr/bin/perl -w
###########################################
# SCRIPT NAME : news.cgi
# DATE: Sep 2004
# VERSION: 1.0
# AUTHOR: Sarun Chinskul
# EMAIL: schinskul@crystalmckenzieinc.com
###########################################
use lib "/home/httpd/vhosts/cminyc.com/httpdocs/admin";
chdir "/home/httpd/vhosts/cminyc.com/httpdocs/";

use CGI;
use DBI;
use HTML::Template;
use cmiModule;
use strict;

########################
# Read Config.conf file
########################
my @info = &cmiModule::ReadConfig("config.conf");
########################
# Logfile config setup
########################
my %Log_Config;
   # Setting EasyLog is ON or OFF in config.conf file
   $Log_Config{SWITCH} = $info[0];
   $Log_Config{FILENAME} = $info[1];
   $Log_Config{MESSAGE} = "-------STARTED LOG [".$0."]-------";
   &cmiModule::EasyLog(\%Log_Config);
########################
# Database config setup
########################
my %DB;
   $DB{DATABASE} = $info[2];
   $DB{ACCOUNT}  = $info[3];
   $DB{PASSWORD} = $info[4];
my $dbh;
unless( $dbh = &cmiModule::ConnectToMySQL(\%DB) ) {
  $Log_Config{"MESSAGE"} = "Bad DBH from ConnectToMySQL.";
  &cmiModule::EasyLog(\%Log_Config);
  print "Content-type:text/html\n\n";
  print "<b>Bad DBH from ConnectToMySQL.</b>";
  exit;
}
###### End config ######

my $cgi = new CGI;

my %NEWSINFO;
   $NEWSINFO{news_template} = HTML::Template->new(filename => 'tmpl/news.tmpl');

&news(\%NEWSINFO);

1;

sub news {
    my ($params_hashref) = @_;
                                                                                                                             
    my %params_hash      = %{ $params_hashref };
    my $news_template = $params_hash{news_template};

    my $sql = "SELECT cmiContentText";
       $sql .= " From cmiContents";
       $sql .= " Where cmiContentType = 'news'";
       $sql .= " And ContentSelect = 'yes'";
       $sql .= " And Active = '1'"; 
    my $news = $dbh->selectrow_array($sql);
   
    $Log_Config{MESSAGE} = "SQL : $sql\n";
    &cmiModule::EasyLog(\%Log_Config);

    $news_template->param(news => $news);

print "Content-type:text/html\n\n";
print $news_template->output;

}



