#!/usr/bin/perl -w
###########################################
# SCRIPT NAME : portfolio.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 "Bad DBH from ConnectToMySQL.";
exit;
}
###### End config ######
my $cgi = new CGI;
my %PORTFOLIOINFO;
$PORTFOLIOINFO{portfolio_template} = HTML::Template->new(filename => 'tmpl/portfolio.tmpl');
$PORTFOLIOINFO{prjtype} = $cgi->param('prjtype');
$PORTFOLIOINFO{industry} = $cgi->param('industry');
$PORTFOLIOINFO{region} = $cgi->param('region');
$PORTFOLIOINFO{client} = $cgi->param('client');
$PORTFOLIOINFO{portcontentid} = $cgi->param('portcontentid');
$PORTFOLIOINFO{pagestart_rec} = $cgi->param('pagestart_rec');
$PORTFOLIOINFO{pagenav} = $cgi->param('pagenav');
$PORTFOLIOINFO{wasselect} = $cgi->param('wasselect');
$PORTFOLIOINFO{imgstart_rec} = $cgi->param('imgstart_rec');
$PORTFOLIOINFO{imgnav} = $cgi->param('imgnav');
&portfolio(\%PORTFOLIOINFO);
1;
sub portfolio {
my ($params_hashref) = @_;
my %params_hash = %{ $params_hashref };
my $portfolio_template = $params_hash{portfolio_template};
my $projecttype = $params_hash{prjtype};
my $industryid = $params_hash{industry};
my $region = $params_hash{region};
my $companyid = $params_hash{client};
my $portcontentid = $params_hash{portcontentid};
my $pagestart_rec = $params_hash{pagestart_rec};
my $pagenav = $params_hash{pagenav};
my $wasselect = $params_hash{wasselect};
my $imgstart_rec = $params_hash{imgstart_rec};
my $imgnav = $params_hash{imgnav};
my $showprojecttype = &select_projecttype($projecttype);
my $showindustry = &select_industrysector($industryid);
my $showregion = &select_region($region);
my $showclient = &select_client($companyid);
my ($companyname,$projectname,$porttext,$portimg1,$portimg2);
my $sql = "SELECT count(M.cmiContentID_1)";
$sql .= " From cmiMerge M";
$sql .= " ,cmiContents C" if ( $projecttype );
$sql .= " ,cmiProjects P" if ( $industryid || $region || $companyid );
$sql .= " Where M.Active = '1'";
$sql .= " And M.cmiContentID_1 = C.cmiContentID" if ( $projecttype );
$sql .= " And M.cmiProjectID = P.cmiProjectID" if ( $industryid || $region || $companyid );
$sql .= " And C.cmiContentType = '$projecttype'" if ( $projecttype );
$sql .= " And P.IndustryID = '$industryid'" if ( $industryid );
$sql .= " And P.Region = '$region'" if ( $region );
$sql .= " And P.cmiMemberID = '$companyid'" if ( $companyid );
$sql .= " Order by M.cmiMergeID";
my $all_rec = $dbh->selectrow_array($sql);
$Log_Config{MESSAGE} = "SQL_p1 : $sql\n";
&cmiModule::EasyLog(\%Log_Config);
my ($remain_rec,$full_rec);
$remain_rec = ( $all_rec % 5 );
if ( $remain_rec > 0 ) {
$full_rec = $all_rec - $remain_rec;
} else {
$full_rec = $all_rec - 5;
}
unless ( $pagestart_rec ) { $pagestart_rec = qq{0}; }
if ( $pagenav eq "prev" ) { $pagestart_rec = $pagestart_rec - 5 if ($pagestart_rec > 0); }
elsif ( $pagenav eq "next" ) { $pagestart_rec = $pagestart_rec + 5 if ($pagestart_rec+5 < $all_rec); }
elsif ( $pagenav eq "first" ) { $pagestart_rec = qq{0}; }
elsif ( $pagenav eq "last" ) { $pagestart_rec = $full_rec; }
$sql = "SELECT M.cmiContentID_1";
$sql .= " From cmiMerge M";
$sql .= " ,cmiContents C" if ( $projecttype );
$sql .= " ,cmiProjects P" if ( $industryid || $region || $companyid );
$sql .= " Where M.Active = '1'";
$sql .= " And M.cmiContentID_1 = C.cmiContentID" if ( $projecttype );
$sql .= " And M.cmiProjectID = P.cmiProjectID" if ( $industryid || $region || $companyid );
$sql .= " And C.cmiContentType = '$projecttype'" if ( $projecttype );
$sql .= " And P.IndustryID = '$industryid'" if ( $industryid );
$sql .= " And P.Region = '$region'" if ( $region );
$sql .= " And P.cmiMemberID = '$companyid'" if ( $companyid );
$sql .= " Order by M.cmiMergeID";
$sql .= " Limit $pagestart_rec,5";
$Log_Config{MESSAGE} = "SQL_p2 : $sql\n";
&cmiModule::EasyLog(\%Log_Config);
my $rec = $dbh->prepare($sql);
$rec->execute;
my (@page,@flk,$j);
while(@flk = $rec->fetchrow) {
$page[$j] = $flk[0]; $j++;
}$rec->finish;
my ($t1,$t2,$t3,$t4,$t5) = @page;
my ($s1,$s2,$s3,$s4,$s5) = (1+$pagestart_rec,2+$pagestart_rec,3+$pagestart_rec,4+$pagestart_rec,5+$pagestart_rec);
my $arrow_ck1 = $s1;
my $arrow_ck2 = $s5;
if ( $wasselect eq "" ) {
$s1 = "".$s1."" if ( $pagenav eq "" ||
$pagenav eq "next" ||
$pagenav eq "last" ||
$pagenav eq "first" ) ;
$s5 = "".$s5."" if ( $pagenav eq "prev" ) ;
} elsif ( $wasselect eq "a" ) { $s1 = "".$s1.""; }
elsif ( $wasselect eq "b" ) { $s2 = "".$s2.""; }
elsif ( $wasselect eq "c" ) { $s3 = "".$s3.""; }
elsif ( $wasselect eq "d" ) { $s4 = "".$s4.""; }
elsif ( $wasselect eq "e" ) { $s5 = "".$s5.""; }
my $style = qq{style="font-family:arial; font-size:11; text-decoration:none; color:black;"};
my ($moreprojects,$goFirst,$arrow1,$n1,$n2,$n3,$n4,$n5,$arrow2,$goLast);
$arrow1 = qq{} if ( $arrow_ck1 ne "1" );
$goFirst = qq{} if ( $arrow1 );
$n1 = qq{$s1} if ( $t1 && $all_rec > 1);
$n2 = qq{$s2} if ( $t2 );
$n3 = qq{$s3} if ( $t3 );
$n4 = qq{$s4} if ( $t4 );
$n5 = qq{$s5} if ( $t5 );
$arrow2 = qq{} if ( $t5 && ( $arrow_ck2 ne $all_rec) );
$goLast = qq{} if ( $arrow2 );
$moreprojects = qq{more projects : } if ( $n1 );
### send var to HTML ####
$portfolio_template->param(moreprojects => $moreprojects);
$portfolio_template->param(goFirst => $goFirst);
$portfolio_template->param(arrow1 => $arrow1);
$portfolio_template->param(n1 => $n1);
$portfolio_template->param(n2 => $n2);
$portfolio_template->param(n3 => $n3);
$portfolio_template->param(n4 => $n4);
$portfolio_template->param(n5 => $n5);
$portfolio_template->param(arrow2 => $arrow2);
$portfolio_template->param(goLast => $goLast);
#########################
if ( $portcontentid eq "" ) { $portcontentid = $t1; }
if ( $pagenav eq "next" ) { $portcontentid = $t1; }
elsif ( $pagenav eq "prev" ) { $portcontentid = $t5; }
$sql = " SELECT E.CompanyName";
$sql .= " ,P.ProjectTitle";
$sql .= " ,C.cmiContentText";
$sql .= " From cmiMerge M";
$sql .= " ,cmiContents C";
$sql .= " ,cmiProjects P";
$sql .= " ,cmiMembers E";
$sql .= " Where M.cmiContentID_1 = C.cmiContentID";
$sql .= " and C.cmiContentID = '$portcontentid'";
$sql .= " and M.cmiProjectID = P.cmiProjectID";
$sql .= " and P.cmiMemberID = E.cmiMemberID";
$sql .= " and P.Active = '1'";
$sql .= " and E.Active = '1'";
$sql .= " Limit 0,1";
$Log_Config{MESSAGE} = "SQL_info1 : $sql\n";
&cmiModule::EasyLog(\%Log_Config);
($companyname,$projectname,$porttext) = $dbh->selectrow_array($sql);
unless ( $companyname && $projectname && $porttext ) {
my %prjtype;
$prjtype{portfolio_CB} = "Corporate Branding";
$prjtype{portfolio_ND} = "Name Development";
$prjtype{portfolio_AD} = "Advertising";
$prjtype{portfolio_IM} = "Interactive Media";
$prjtype{portfolio_MR} = "Marketing Research";
$prjtype{portfolio_MC} = "Marketing Communications";
$prjtype{portfolio_ED} = "Environmental Design";
my $PP = $prjtype{$projecttype};
my $sql = "SELECT IndustryName";
$sql .= " From Industry";
$sql .= " Where IndustryID = '$industryid'";
$Log_Config{MESSAGE} = "SQL_project_empty : $sql\n";
&cmiModule::EasyLog(\%Log_Config);
my $II = $dbh->selectrow_array($sql);
my $tmp = $PP;
$tmp = $II if ( $PP eq "" );
($companyname,$projectname,$porttext) = &default_portfolio( $tmp );
}
my $result_size = &check_size($porttext);
my ($startremark,$endremark);
unless ( $result_size ) {
$startremark = qq{};
}
### send var to HTML ####
$portfolio_template->param(startremark => $startremark);
$portfolio_template->param(endremark => $endremark);
#########################
my ($MAX_REC,$remaider);
$sql = "SELECT count(I.cmiImageName)";
$sql .= " From cmiImages I";
$sql .= " ,cmiMerge M";
$sql .= " ,cmiContents C";
$sql .= " ,cmiProjects P";
$sql .= " Where (M.cmiContentID_1 = C.cmiContentID)";
$sql .= " and (C.cmiContentID = I.cmiContentID)";
$sql .= " and (C.cmiContentID = '$portcontentid')";
$sql .= " and (M.cmiProjectID = P.cmiProjectID)";
$sql .= " and P.Active = '1'";
$sql .= " and I.active = '1'";
$Log_Config{MESSAGE} = "SQL_img1 : $sql\n";
&cmiModule::EasyLog(\%Log_Config);
$MAX_REC = $dbh->selectrow_array($sql);
unless ( $imgstart_rec ) { $imgstart_rec = qq{0}; }
if ( $imgnav eq "prev" ) { $imgstart_rec = $imgstart_rec - 2 if ($imgstart_rec > 0); }
elsif ( $imgnav eq "next" ) { $imgstart_rec = $imgstart_rec + 2 if ($imgstart_rec+2 < $MAX_REC); }
$sql = "SELECT I.cmiImageName";
$sql .= " From cmiImages I";
$sql .= " ,cmiMerge M";
$sql .= " ,cmiContents C";
$sql .= " ,cmiProjects P";
$sql .= " Where (M.cmiContentID_1 = C.cmiContentID)";
$sql .= " and (C.cmiContentID = I.cmiContentID)";
$sql .= " and (C.cmiContentID = '$portcontentid')";
$sql .= " and (M.cmiProjectID = P.cmiProjectID)";
$sql .= " and P.Active = '1'";
$sql .= " and I.active = '1'";
$sql .= " Limit $imgstart_rec,2";
$Log_Config{MESSAGE} = "SQL_img2 : $sql\n";
&cmiModule::EasyLog(\%Log_Config);
$rec = $dbh->prepare($sql);
$rec->execute;
my (@img,@fld,$i);
while(@fld = $rec->fetchrow) {
$img[$i] = $fld[0]; $i++;
}$rec->finish;
my ($tmp1,$tmp2) = @img;
$portimg1 = &gen_click_img($tmp1) if ( $tmp1 );
$portimg2 = &gen_click_img($tmp2) if ( $tmp2 );
unless ( @img ) {
$portimg1 = &default_images();
}
my ($subarrow1,$subarrow2);
if ($MAX_REC > 2) {
$subarrow1 = qq{};
$subarrow2 = qq{};
}
$portfolio_template->param(showprojecttype => $showprojecttype);
$portfolio_template->param(showindustry => $showindustry);
#$portfolio_template->param(showregion => $showregion); ## wait until it have more data
#$portfolio_template->param(showclient => $showclient);
### send var to HTML ####
$portfolio_template->param(t1 => $t1);
$portfolio_template->param(t2 => $t2);
$portfolio_template->param(t3 => $t3);
$portfolio_template->param(t4 => $t4);
$portfolio_template->param(t5 => $t5);
$portfolio_template->param(portcontentid => $portcontentid);
$portfolio_template->param(pagestart_rec => $pagestart_rec);
$portfolio_template->param(wasselect => $wasselect);
$portfolio_template->param(imgstart_rec => $imgstart_rec);
$portfolio_template->param(subarrow1 => $subarrow1);
$portfolio_template->param(subarrow2 => $subarrow2);
$portfolio_template->param(companyname => $companyname);
$portfolio_template->param(projectname => $projectname);
$portfolio_template->param(portimg1 => $portimg1);
$portfolio_template->param(portimg2 => $portimg2);
$portfolio_template->param(porttext => $porttext);
##########################
print "Content-type:text/html\n\n";
print $portfolio_template->output;
}
#############################################
# In case database doesn't have data yet #
#############################################
sub default_portfolio {
my ( $PROJECT_NAME ) = @_;
my $companyname = "Crystal Mckenzie, Inc";
my $projectname = "$PROJECT_NAME";
my $porttext = qq{
Throughout its history, the firm has maintained a level of quality and a
commitment to delivering customer value that has made it one of the most
respected firms in the field. We are a young-thinking agency full of
creative imagination and enthusiasm.
CMI creates and manages Marketing Communications programs and projects for
our clients. Whether it is communicating information using cutting-edge
technology, using state-of-the-art creativity to influence and affect
others, brand management skill-sets or cost-effective ideas that matter the
most to you, the CMI team has what it takes to communicate your message.
Over the years, CMI has gained a reputation within the corporate community
for consistently producing exceptional creative work for a wide range of
clients. What is not always clearly understood and recognized, however, is
how we go about producing the work. More importantly, what the direct
correlation is between the creative work we've done and our clients end
results. There really is no magic formula. Rather, it is the result of the
proper and delicate balance between the right strategy and the right
implementation. While some firms excel at developing a sound strategy for a
client, they fall short in the creative execution. Others, whose execution
is arresting, choose to communicate something irrelevant or unimportant,
which, therefore, does not motivate the audience. CMI is proud to have
assembled over the years a group of people whose talents for deciding what
to emphasize is equally as good as choosing how to emphasize it.
Our experience has given us a unique perspective on today's dynamic
marketplace; a perspective that helps us create an effective programs based
on sound, informed, strategic thinking. Moreover, a perspective that gives
us the insight to prepare communications with just the right degree of
"friendly persuasion" to cohere people to act. CMI will help you get inside
your key-stakeholder's minds. What are their priorities? How can you link
their needs and preferences with your objectives and capabilities? Based on
these answers, we'll work with you to create a solution that delivers
everything your key stakeholder's want: information and services, advice and
tools, immediacy and mobility.
Complexity empowers users -- but that does not mean it has to show. We have
special insight into the capabilities and constraints of technology. That is
why we specialize in packaging and delivering complexity in ways that make
it more quickly understandable, accessible and appealing to the user. At
CMI, we provide recommendations relating to all key areas. Specific
strategies are outlined in order to develop a pragmatic and usable blueprint
for the project.
CMI solutions focus on the essential ingredients for success. Success for
our people means not just being a full-service consultant, but entering into
a partnership with your organization to provide the most cost-effective
response to your needs.
Having worked on numerous diversified projects and Programs in the past, our
core services provide a sharper competitive edge for our clients.
At CMI, we provide recommendations relating to all key areas. Specific
strategies are outlined in order to develop a pragmatic and usable blueprint
for the program. };
return ($companyname,$projectname,$porttext);
}
sub default_images {
my $porimg1 = qq{};
return $porimg1;
}
#############################################
sub check_size {
my ($text) = @_;
my $chars = length( $text );
$Log_Config{MESSAGE} = "CHARS : $chars\n";
&cmiModule::EasyLog(\%Log_Config);
my $result;
if ( $chars > 650 ) {
$result = "SCROLL_SHOW";
}
return $result;
}
sub gen_click_img {
my ($obj) = @_;
my $sql = "SELECT E.cmiImageExtendName";
$sql .= " From cmiImagesExtend E";
$sql .= " ,cmiImages I";
$sql .= " Where E.cmiImageID = I.cmiImageID";
$sql .= " And I.cmiImageName = '$obj'";
$sql .= " And E.Active = '1'";
my $objex = $dbh->selectrow_array($sql);
my $show = qq{'uploadimages/$obj'};
if ( $objex ) { $show = qq{'uploadextendimages/$objex'}; }
my $img = qq{};
my ($out,$cover_front,$cover_back);
$cover_front = qq{};
$cover_back = qq{};
$out = $cover_front.$img.$cover_back;
return $out;
}
sub select_projecttype {
my ($projecttype) = @_;
my %prjtype;
$prjtype{portfolio_CB} = "Corporate Branding";
$prjtype{portfolio_ND} = "Name Development";
$prjtype{portfolio_AD} = "Advertising";
$prjtype{portfolio_IM} = "Interactive Media";
$prjtype{portfolio_MR} = "Marketing Research";
$prjtype{portfolio_MC} = "Marketing Communications";
$prjtype{portfolio_ED} = "Environmental Design";
my $out;
$out = qq{};
return $out;
}
sub select_industrysector {
my ($industryid) = @_;
my $sql = "SELECT IndustryID";
$sql .= ",IndustryName";
$sql .= " From Industry";
$sql .= " Where Active = '1'";
$sql .= " Order by IndustryID";
my $rec = $dbh->prepare($sql);
$rec->execute;
my $out = qq{ };
return $out;
}
sub select_region {
my ($region) = @_;
my $sql = "SHOW FIELDS FROM cmiProjects LIKE 'Region'";
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 @region = split(/ /,$list);
my $out = qq{ };
return $out;
}
sub select_client {
my ($companyid) = @_;
my $sql = "SELECT cmiMemberID";
$sql .= " ,CompanyName";
$sql .= " From cmiMembers ";
$sql .= " Where CompanyName <> ''";
$sql .= " And cmiPortfolioSelect = 'yes'";
$sql .= " And Active = '1'";
my $rec = $dbh->prepare($sql);
$rec->execute;
#$Log_Config{MESSAGE} = "SQL_client : $sql\n";
#&cmiModule::EasyLog(\%Log_Config);
my $out = qq{ };
return $out;
}