# Copyright (c) 2003 AdCycle.com All rights reserved.
# http://www.adcycle.com - download the lastest version of adcycle
package AdGroups;
use strict;
sub new {
my $this = shift;
my $class = ref($this) || $this;
my $self = {};
bless $self, $class;
return $self;
}
sub view_groups{
my($self,$master)=@_;
# get config and env vars
my $images_url=$master->{config}->get_images_url;
my $cgi_bin_url=$master->{config}->get_cgi_bin_url;
my $cache=$master->{env}->get_cache;
my $tid=$master->{query}->param('tid')+0;
# print header
$master->{LINK}="groups";
$master->{html}->header($master,"Ad Groups");
#get the groups
my @gidref;
if($tid==0){
(@gidref)=$master->{db}->select_multi_row_hash("SELECT * FROM groups order by WIDTH DESC,GROUP_NAME");
}else{
(@gidref)=$master->{db}->select_multi_row_hash("SELECT * FROM groups WHERE TID=$tid order by WIDTH DESC,GROUP_NAME");
}
my $gidtot=@gidref;
print qq~
~;
my $coo;
for(my $k=0;$k<$gidtot;$k++){
my $geometry=qq~$gidref[$k]->{WIDTH} x $gidref[$k]->{HEIGHT}~;
if($gidref[$k]->{WIDTH}==1 && $gidref[$k]->{HEIGHT}==1){
$geometry="Text";
}
if($gidref[$k]->{WIDTH}==2 && $gidref[$k]->{HEIGHT}==2){
$geometry="Pop";
}
my $rotation="By Cookie";
if($gidref[$k]->{ROTATION_FLAVOR}==1){
$rotation="Random";
}
my $cpgref=$master->{db}->select_single_row_hash("SELECT sum(TOTAL_IMPR) as IMPR,sum(TOTAL_CLICK) as CLICK FROM cp_grouping where GID='$gidref[$k]->{GID}'");
$cpgref->{IMPR}+=0;
$cpgref->{CLICK}+=0;
my $color="td3";
if($coo==1){
$color="td5";
$coo=0;
}else{
$coo++;
}
my $ctp=$master->{tools}->ctp_calculation($cpgref->{IMPR},$cpgref->{CLICK});
$cpgref->{IMPR}=$master->{tools}->comma_insert($cpgref->{IMPR});
$cpgref->{CLICK}=$master->{tools}->comma_insert($cpgref->{CLICK});
print qq~
~;
$master->{html}->footer($master);
}
sub add_group_form{
my($self,$master)=@_;
# get config and env vars
my $images_url=$master->{config}->get_images_url;
my $cgi_bin_url=$master->{config}->get_cgi_bin_url;
my $cache=$master->{env}->get_cache;
# print header
$master->{LINK}="groups";
$master->{html}->header($master,"Add a New Group");
#get the campaigns
my(@tidref)=$master->{db}->select_multi_row_hash("SELECT * FROM adtype order by TID");
my $tidtot=@tidref;
# add group form
print qq~
~;
$master->{html}->footer($master);
}
sub add_group{
my($self,$master)=@_;
# input params
my $group_name=$master->{query}->param('group_name');
my $width=$master->{query}->param('width');
my $height=$master->{query}->param('height');
my $type=$master->{query}->param('type');
# get new gid
my $gid=$master->{tools}->get_id($master,"GID");
# get typeref
my $typeref=$master->{db}->select_single_row_hash("SELECT * FROM adtype WHERE TID='$type'");
# make insert list
my $insert_list=[
["GID",$gid],
["GROUP_NAME",$group_name],
["TID",$type],
["WIDTH",$typeref->{WIDTH}],
["HEIGHT",$typeref->{HEIGHT}]
];
# insert row
$master->{db}->insert_row("groups",$insert_list);
#get the campaigns
my(@cidref)=$master->{db}->select_multi_row_hash("SELECT * FROM cp WHERE WIDTH='$typeref->{WIDTH}' AND HEIGHT='$typeref->{HEIGHT}'");
my $cidtot=@cidref;
#get the adconfig
my $configref=$master->{db}->select_single_row_hash("SELECT * FROM adconfig");
my $status=$configref->{AUTO_ACTIVATE};
for(my $k=0;$k<$cidtot;$k++){
my(@midref)=$master->{db}->select_multi_row_hash("SELECT * FROM cp_media WHERE CID='$cidref[$k]->{CID}'");
my $midtot=@midref;
for(my $t=0;$t<$midtot;$t++){
# make insert list
my $insert_list=[
["GID",$gid],
["AID",$cidref[$k]->{AID}],
["CID",$cidref[$k]->{CID}],
["MID",$midref[$t]->{MID}],
["WEIGHT","100"],
["STATUS","$status"]
];
# insert row
$master->{db}->insert_row("cp_grouping",$insert_list);
}
}
$master->{message}="Group Created";
$master->{groups}->view_groups($master);
}
sub edit_group{
my($self,$master)=@_;
# get config and env vars
my $images_url=$master->{config}->get_images_url;
my $cgi_bin_url=$master->{config}->get_cgi_bin_url;
my $cache=$master->{env}->get_cache;
# input vars
my $gid=$master->{query}->param('gid');
#get the group ref
my $gidref=$master->{db}->select_single_row_hash("SELECT * FROM groups where GID='$gid'");
#get the campaigns
my(@cidref)=$master->{db}->select_multi_row_hash("SELECT * FROM cp WHERE WIDTH='$gidref->{WIDTH}' AND HEIGHT='$gidref->{HEIGHT}'");
my $cidtot=@cidref;
#get the campaigns
my(@gridref)=$master->{db}->select_multi_row_hash("SELECT GID,CID,WEIGHT,STATUS,SUM(TOTAL_IMPR) as TOTAL_IMPR, SUM(TOTAL_CLICK) as TOTAL_CLICK FROM cp_grouping where GID='$gid' GROUP BY CID ORDER BY STATUS DESC,WEIGHT DESC,CID");
my $gridtot=@gridref;
# print header
$master->{LINK}="groups";
$master->{html}->header($master,"Edit Group: $gidref->{GROUP_NAME}");
my %rotation;
$rotation{$gidref->{ROTATION_FLAVOR}}=" checked ";
# >> geomtery
my $geometry=qq~$gidref->{WIDTH} x $gidref->{HEIGHT}~;
if($gidref->{WIDTH}==1 && $gidref->{HEIGHT}==1){
$geometry="Text Links";
}
if($gidref->{WIDTH}==2 && $gidref->{HEIGHT}==2){
$geometry="Pop Windows";
}
# << geometry
# >> top menu
print qq~
~;
#>> black adcycle banner
if($need_default eq "yes"){
print qq~
[ALERT] This group has the potential to generate black adcycle default ads. To eliminate this possibility add an active campaign to the group and set the weight as "0-Default"
~;
}
#<< black adcycle banner
$master->{html}->footer($master);
}
sub update_group{
my($self,$master)=@_;
# input params
my $group_name=$master->{query}->param('group_name');
my $rotation=$master->{query}->param('rotation');
my $gid=$master->{query}->param('gid');
# get the group ref
my $gidref=$master->{db}->select_single_row_hash("SELECT * FROM groups where GID='$gid'");
#$master->{clear_cookie}=$gidref->{TID};
#get the campaigns
my(@cidref)=$master->{db}->select_multi_row_hash("SELECT * FROM cp WHERE WIDTH='$gidref->{WIDTH}' AND HEIGHT='$gidref->{HEIGHT}'");
my $cidtot=@cidref;
#get the campaigns
my(@gridref)=$master->{db}->select_multi_row_hash("SELECT GID,CID,WEIGHT,STATUS,SUM(TOTAL_IMPR) as TOTAL_IMPR, SUM(TOTAL_CLICK) as TOTAL_CLICK FROM cp_grouping where GID='$gid' GROUP BY CID ORDER BY STATUS DESC,WEIGHT DESC");
my $gridtot=@gridref;
my %already_inc;
my @already_inc;
my $count=0;
for(my $k=0;$k<$cidtot;$k++){
my $checked="";
for(my $g=0;$g<$gridtot;$g++){
if($gridref[$g]->{CID}==$cidref[$k]->{CID}){
$already_inc{$cidref[$k]->{CID}}=1;
$already_inc[$count]=$cidref[$k]->{CID};
$count++;
}
}
}
for(my $k=0;$k<$cidtot;$k++){
my $cid=$cidref[$k]->{CID};
my $temp=$master->{query}->param("C|$cid|");
my $weight=$master->{query}->param("WEIGHT|$cid|");
# add a row
if($temp==1 && $already_inc{$cid}!=1){
$master->{db}->{adcycle}->do("INSERT INTO cp_grouping (GID,AID,CID,WEIGHT,STATUS) VALUES ($gid,$cidref[$k]->{AID},$cid,$weight,'1')");
}
# update a row
if($temp==1 && $already_inc{$cid}==1){
$master->{db}->{adcycle}->do("UPDATE cp_grouping SET WEIGHT='$weight',STATUS='1' WHERE GID='$gid' AND CID='$cid'");
}
# update a row
if($temp==0){
$master->{db}->{adcycle}->do("UPDATE cp_grouping SET WEIGHT='$weight',STATUS='0' WHERE GID='$gid' AND CID='$cid'");
}
}
# generate query list
my $c;
$c=$master->{db}->update_cv($c,"GROUP_NAME",$group_name);
$c=$master->{db}->update_cv($c,"ROTATION_FLAVOR",$rotation);
chop($c);
# insert row
$master->{db}->{adcycle}->do("UPDATE groups SET $c WHERE GID='$gid'");
$master->{message}="Group has been updated";
$master->{groups}->edit_group($master);
}
sub delete_group{
my($self,$master)=@_;
# input params
my $gid=$master->{query}->param('gid');
# delete advertiser
$master->{db}->{adcycle}->do("DELETE FROM groups WHERE GID='$gid'");
# delete grouping
$master->{db}->{adcycle}->do("DELETE FROM cp_grouping WHERE GID='$gid'");
$master->{message}="Group has been deleted";
$master->{groups}->view_groups($master);
}
sub get_adcodes{
my($self,$master)=@_;
# input params
my $gid=$master->{query}->param('gid');
my $target=$master->{query}->param('target');
my $keywords=$master->{query}->param('keywords');
my $refresh=$master->{query}->param('refresh')+0;
my $placement=$master->{query}->param('placement');
my $images_url=$master->{config}->get_images_url;
my $cgi_bin_url=$master->{config}->get_cgi_bin_url;
my $cache=$master->{env}->get_cache;
# get the group ref
my $gidref=$master->{db}->select_single_row_hash("SELECT * FROM groups where GID='$gid'");
my $width=$gidref->{WIDTH};
my $height=$gidref->{HEIGHT};
# print header
$master->{LINK}="groups";
$master->{html}->header($master,"Ad codes for $gidref->{GROUP_NAME}");
# relative url construction
my $ul=length($cgi_bin_url);
my $idx=index($cgi_bin_url,"\/",8);
my $relative=substr($cgi_bin_url,$idx,$ul-$idx);
if(length($target)==0){
$target="_top";
}
my %placement;
my %target;
my %keywords;
$placement{$placement}=" selected ";
$target{$target}=" selected ";
$keywords{$keywords}=" selected ";
my $page_layout="";
my $add_on="";
if($placement eq "multi"){
$page_layout=qq~&layout=multi~;
$add_on="[MULTI-AD]";
}
my $kw="";
if($keywords eq "on"){
$kw=qq~&keywords=ENTER+KEYWORD+LIST~;
$add_on.=" [KEYWORD]";
}
# add advertiser form
print qq~
~;
my $refresh_tag="";
my $refreshd="";
if($refresh+0>0){
$refresh_tag=qq~&refresh=$refresh~;
$refreshd="with $refresh second refresh";
}
if($width>2 && $height>2){
#IFRAME CACHE BUST
my $adcode=qq~
~;
$adcode=~s/\\<\;/g;
$adcode=~s/\>/\>\;/g;
$adcode=~s/\"/\"\;/g;
print qq~
~;
#SSI Code
my $adcode=qq~
~;
$adcode=~s/\\<\;/g;
$adcode=~s/\>/\>\;/g;
$adcode=~s/\"/\"\;/g;
print qq~
~;
# STANDARD CACHE BUST
my $adcode=qq~
~;
$adcode=~s/\\<\;/g;
$adcode=~s/\>/\>\;/g;
$adcode=~s/\"/\"\;/g;
print qq~
~;
# STANDARD
my $adcode=qq~
~;
$adcode=~s/\\<\;/g;
$adcode=~s/\>/\>\;/g;
$adcode=~s/\"/\"\;/g;
print qq~
~;
print qq~
If you have more than one ad in a single page, select "Multiple Ads in a Page" from the pulldown menu at the top of this page, and change the "id=\#" to a unique number for each ad code. Creating unique numbers for the ad code id can be accomplished by reloading this page.
~;
}elsif($width==1 && $height==1){
# STANDARD
my $adcode=qq~
~;
$adcode=~s/\\<\;/g;
$adcode=~s/\>/\>\;/g;
$adcode=~s/\"/\"\;/g;
print qq~
~;
}else{
print qq~Rotation functionality for text links and pop-windows is still under development. In the meantime, please use the direct ad codes provided in the campaign creative pages.~;
}
$master->{html}->footer($master);
}
# Copyright (c) 2003 AdCycle.com All rights reserved.
# http://www.adcycle.com - download the lastest version of adcycle
1;