#!/usr/bin/perl -w
###########################################
# SCRIPT NAME : servicecgi
# 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;


##########################################################
#                     Service text
##########################################################
my $text =  qq{<font style="font-size:11px;"><b>Services</b><br><br>};
   $text .= qq{CMI is a full-service communications&nbsp;}; 
   $text .= qq{agency, offering<br>complete in-house&nbsp;}; 
   $text .= qq{facilities for all activities required to<br>};
   $text .= qq{support client marketing, media and public&nbsp;};
   $text .= qq{information<br>service. Some clients use every&nbsp;};
   $text .= qq{service&nbsp;others choose to<br>use only those&nbsp;};
   $text .= qq{services that complement existing internal<br>}; 
   $text .= qq{and external resources.</font>};
##########################################################


my %SERVICEINFO;
   $SERVICEINFO{service_template} = HTML::Template->new(filename => 'tmpl/service.tmpl');
   $SERVICEINFO{servicetext} = $text;
   $SERVICEINFO{servicetype} = $cgi->param('servicetype');

&service(\%SERVICEINFO);

1;

sub service {
    my ($params_hashref) = @_;
                                                                                                                             
    my %params_hash      = %{ $params_hashref };
    my $service_template = $params_hash{service_template};
    my $servicetext      = $params_hash{servicetext};
    my $servicetype      = $params_hash{servicetype};

    $service_template->param(servicetext => $servicetext);

    my $showservicetype = &ShowServiceTypeName();
    $service_template->param(showservicetype => $showservicetype); 
    
    unless ( $servicetype ) { $servicetype = "Collateral";}
    my $sql = "SELECT cmiServiceName";
       $sql .= " From cmiServices";
       $sql .= " Where cmiServiceType = '$servicetype'";
    my $rec = $dbh->prepare($sql);
       $rec->execute;
    
    my (@fld,$servicename);
    $servicetype =~ s/[A-Z]/ $&/g;
    $servicename = "<font style=\"font-size:11px;\"><b>$servicetype</b><br>";
    while(@fld = $rec->fetchrow) {
      $servicename .= "&nbsp;&nbsp;&nbsp;-$fld[0]<br>";
    } $servicename .= "</font>"; 
      $rec->finish;
    $service_template->param(showservicename => $servicename);

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

}


sub ShowServiceTypeName {
                                                                                                                             
  my $sql = "SHOW FIELDS FROM cmiServices LIKE 'cmiServiceType'";
  my $rec = $dbh->prepare($sql);
     $rec->execute;
                                                                                                                             
  my @fld = $rec->fetchrow;
  my $list = $fld[1];
     $list =~ s/enum\(\'//ig;
     $list =~ s/\'\,\'/ /ig;
     $list =~ s/\'\)//ig;
  my @array_tmp = split(/ /,$list);
                                                                                                                             
  my $out = qq{<select style="WIDTH: 130px;font-size:11px;"  class=menu name=servicetype Multiple size=7 onChange=updateservice()>};
     foreach (@array_tmp) {
       my $show = $_;
          $show =~ s/[A-Z]/ $&/g; 
       $out .= qq{<option value="$_" >$show};
     } $out .= qq{</select>};
                                                                                                                             
 return $out;
}




