# Copyright (c) 2003 AdCycle.com All rights reserved.
# http://www.adcycle.com - download the lastest version of adcycle
package AdCampaign;
use strict;
sub new {
my $this = shift;
my $class = ref($this) || $this;
my $self = {};
bless $self, $class;
return $self;
}
# >> VIEW CAMPAIGNS
sub view_campaigns{
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 $gid=$master->{query}->param('gid');
my $tid=$master->{query}->param('tid');
# print header
$master->{LINK}="campaigns";
$master->{html}->header($master,"AdCenter");
#get the adconfig
my $configref=$master->{db}->select_single_row_hash("SELECT * FROM adconfig");
#get the groups
my(@gidref)=$master->{db}->select_multi_row_hash("SELECT * FROM groups order by GID");
my $gidtot=@gidref;
#get the campaigns
my @gridref;
my $gridtot;
my @cidref;
my $cidtot;
if($gid ne "all" && length($gid)!=0){
(@gridref)=$master->{db}->select_multi_row_hash("SELECT SUM(TOTAL_IMPR) as IMPR, SUM(TOTAL_CLICK) as CLICK,CID FROM cp_grouping where GID='$gid' GROUP BY CID ORDER BY CID");
$gridtot=@gridref;
}else{
if($tid==0){
(@cidref)=$master->{db}->select_multi_row_hash("SELECT * FROM cp ORDER BY WIDTH DESC,HEIGHT DESC,CAMPAIGN_NAME");
$cidtot=@cidref;
}else{
(@cidref)=$master->{db}->select_multi_row_hash("SELECT * FROM cp WHERE TID=$tid ORDER BY WIDTH DESC,HEIGHT DESC,CAMPAIGN_NAME");
$cidtot=@cidref;
}
}
print qq~
~;
$master->{html}->footer($master);
}
# << VIEW CAMPAIGNS
# >> ADD A CAMPAIGN FORM
sub add_campaign_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;
#get the campaigns
my(@aidref)=$master->{db}->select_multi_row_hash("SELECT * FROM ad order by AID");
my $aidtot=@aidref;
#get the campaigns
my(@tidref)=$master->{db}->select_multi_row_hash("SELECT * FROM adtype order by TID");
my $tidtot=@tidref;
if($aidtot!=0){
# print header
$master->{LINK}="campaigns";
$master->{html}->header($master,"Add a New Campaign");
# add campaign form
print qq~
~;
$master->{html}->footer($master);
}else{
$master->{message}="PLEASE ADD AN ADVERTISER BEFORE ADDING CAMPAIGNS. Message at";
$master->{advertiser}->add_advertiser_form($master);
}
}
# << ADD A CAMPAIGN FORM
sub add_campaign{
my($self,$master)=@_;
# input params
my $aid=$master->{query}->param('aid');
my $campaign_name=$master->{query}->param('campaign_name');
my $width=$master->{query}->param('width');
my $height=$master->{query}->param('height');
my $type=$master->{query}->param('type');
my $date=$master->{env}->get_date;
#figure out start date
my $start_date=$master->{db}->single_result("SELECT DATE_ADD('$date',INTERVAL 0 DAY)");
#figure out end date
my $end_date=$master->{db}->single_result("SELECT DATE_ADD('$date',INTERVAL 30 DAY)");
# get cid
my $cid=$master->{tools}->get_id($master,"CID");
# get typeref
my $typeref=$master->{db}->select_single_row_hash("SELECT * FROM adtype WHERE TID='$type'");
# make insert list
my $insert_list=[
["CID",$cid],
["AID",$aid],
["CAMPAIGN_NAME",$campaign_name],
["TID",$type],
["WIDTH",$typeref->{WIDTH}],
["HEIGHT",$typeref->{HEIGHT}],
["START_DATE",$start_date],
["END_DATE",$end_date]
];
# insert row
$master->{db}->insert_row("cp",$insert_list);
# get mid
my $mid=$master->{tools}->get_id($master,"MID");
# make insert list
my $insert_list=[
["NAME","Ad \#1"],
["AID",$aid],
["CID",$cid],
["MID",$mid]
];
# insert row
$master->{db}->insert_row("cp_media",$insert_list);
#get the campaigns
my(@gidref)=$master->{db}->select_multi_row_hash("SELECT * FROM groups WHERE WIDTH='$typeref->{WIDTH}' AND HEIGHT='$typeref->{HEIGHT}'");
my $gidtot=@gidref;
#get the adconfig
my $configref=$master->{db}->select_single_row_hash("SELECT * FROM adconfig");
my $status=$configref->{AUTO_ACTIVATE};
for(my $k=0;$k<$gidtot;$k++){
# make insert list
my $insert_list=[
["GID",$gidref[$k]->{GID}],
["AID",$aid],
["CID",$cid],
["MID",$mid],
["STATUS",$status],
["WEIGHT","100"]
];
# insert row
$master->{db}->insert_row("cp_grouping",$insert_list);
}
# check campaign status
$master->{campaign}->media_status($master);
# update bin
$master->{cron}->campaign_bin_update($master,$cid);
$master->{message}="Campaign has been created";
$master->{campaign}->view_campaigns($master);
}
sub edit_campaign{
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 $date=$master->{env}->get_date;
my $cache=$master->{env}->get_cache;
# input vars
my $cid=$master->{query}->param('cid');
#get the campaign ref
my $cidref=$master->{db}->select_single_row_hash("SELECT * FROM cp where CID='$cid'");
#get the campaign ref
my $aidref=$master->{db}->select_single_row_hash("SELECT * FROM ad where AID='$cidref->{AID}'");
#get the ad media
my(@midref)=$master->{db}->select_multi_row_hash("SELECT * FROM cp_media where CID='$cid'");
my $midtot=@midref;
# print header
$master->{LINK}="campaigns";
$master->{html}->header($master,"Edit: $cidref->{CAMPAIGN_NAME}");
# start and end dates
my @MONTH; my @DAY; my @MONTH2; my @DAY2; my %YEAR; my %YEAR2;
my ($smonth,$sday,$syear)=$master->{tools}->date_splice("$cidref->{START_DATE}");
$DAY[$sday+0]=" selected";
$MONTH[$smonth+0]=" selected";
$YEAR{"$syear"}=" selected";
my ($emonth,$eday,$eyear)=$master->{tools}->date_splice("$cidref->{END_DATE}");
$DAY2[$eday+0]=" selected";
$MONTH2[$emonth+0]=" selected";
$YEAR2{"$eyear"}=" selected";
# checkboxes
my %ui; if($cidref->{MAX_IMPR}==0){$ui{1}=" checked ";};
my %uc; if($cidref->{MAX_CLICK}==0){$uc{1}=" checked ";};
my %udi;if($cidref->{MAX_DAILY_IMPR}==0){$udi{1}=" checked ";};
my %udc;if($cidref->{MAX_DAILY_CLICK}==0){$udc{1}=" checked ";};
# geometry
my $geometry="$cidref->{WIDTH} x $cidref->{HEIGHT}";
if($cidref->{WIDTH}==1 && $cidref->{HEIGHT}==1){
$geometry="Text Link";
}
if($cidref->{WIDTH}==2 && $cidref->{HEIGHT}==2){
$geometry="Pop Windows";
}
###########################
########### CAMPAIGN ADS ##
my $today_ctp=$master->{tools}->ctp_calculation($cidref->{TODAY_IMPR},$cidref->{TODAY_CLICK});
my $total_ctp=$master->{tools}->ctp_calculation($cidref->{DELIVERED_IMPR},$cidref->{DELIVERED_CLICK});
my $status=qq~Off~;
if($cidref->{IMPR_BIN}+$cidref->{CLICK_BIN}>0){
$status=qq~On~;
}
#print qq~IMPRESSION BIN:$cidref->{IMPR_BIN} ~;
#print qq~CLICK BIN:$cidref->{CLICK_BIN} ~;
# >> top menu
print qq~
~;
# << top menu
my $today_impr=$master->{tools}->comma_insert($cidref->{TODAY_IMPR});
my $today_click=$master->{tools}->comma_insert($cidref->{TODAY_CLICK});
print qq~
Campaign Profile
Impressions
Clicks
CTR
Today
$today_impr
$today_click
$today_ctp\%
Total
$cidref->{DELIVERED_IMPR}
$cidref->{DELIVERED_CLICK}
$total_ctp\%
~;
#get the ad media
my(@dailyref)=$master->{db}->select_multi_row_hash("SELECT sum(IMPR) as IMPR, sum(CLICK) as CLICK,DATE_FORMAT(LOG_DATE,'%b %d, %Y') as COOL,LOG_DATE FROM daily_log where CID='$cid' GROUP BY CID,LOG_DATE ORDER BY LOG_DATE DESC");
my $maxi=0;
for(my $k=0;$k<7;$k++){
if($dailyref[$k]->{IMPR}>$maxi){
$maxi=$dailyref[$k]->{IMPR};
}
}
$maxi++;
for(my $k=0;$k<7;$k++){
my $impr=$dailyref[$k]->{IMPR}+0;
my $widthi=(158/$maxi)*$impr+2;
my $widthi2=160-$widthi;
my $click=$dailyref[$k]->{CLICK}+0;
if(!$dailyref[$k]->{LOG_DATE}){
$dailyref[$k]->{LOG_DATE}="NA";
}
if($dailyref[$k]->{LOG_DATE} eq $date){
$impr=$cidref->{TODAY_IMPR};
}
$impr=$master->{tools}->comma_insert($impr);
print qq~
$dailyref[$k]->{COOL}
$impr
~;
}
print qq~
~;
my $max_iremaining=$cidref->{MAX_IMPR}-$cidref->{DELIVERED_IMPR};
my $max_cremaining=$cidref->{MAX_CLICK}-$cidref->{DELIVERED_CLICK};
my $max_idisplay=$cidref->{MAX_IMPR};
if($cidref->{MAX_IMPR}==0){
$max_idisplay="Unlimited";
$max_iremaining="Unlimited";
}
my $max_cdisplay=$cidref->{MAX_CLICK};
if($cidref->{MAX_CLICK}==0){
$max_cdisplay="Unlimited";
$max_cremaining="Unlimited";
}
$cidref->{START_DATE}=$master->{db}->single_result("SELECT DATE_FORMAT('$cidref->{START_DATE}','%b %d, %Y')");
$cidref->{END_DATE}=$master->{db}->single_result("SELECT DATE_FORMAT('$cidref->{END_DATE}','%b %d, %Y')");
print qq~
~;
########### CAMPAIGN ADS ##
###########################
#delivery rate control
my $dr_control=qq~Controlled by Date or Daily Maximums~;
if($cidref->{RATE_CONTROL}==1){
$dr_control=qq~Controlled by Date or Daily Maximums~;
}
###############################
########### CAMPAIGN OPTIONS ##
print qq~
~;
########### END CAMPAIGN OPTIONS ##
###################################
my %dow;
my @day_priority=split(/\|/,$cidref->{DAY_PRIORITY});
for(my $k=0;$k<7;$k++){
if($day_priority[$k]==1){
$dow{$k}=" checked ";
}
}
my %hour;
my @hour_priority=split(/\|/,$cidref->{HOUR_PRIORITY});
for(my $k=0;$k<24;$k++){
if($hour_priority[$k]==1){
$hour{$k}=" checked ";
}
}
my %uicap;if($cidref->{IMPR_DELAY}==0 || $cidref->{IMPR_LIMIT}==0){$uicap{1}=" checked ";};
my %uccap;if($cidref->{CLICK_DELAY}==0 || $cidref->{CLICK_LIMIT}==0){$uccap{1}=" checked ";};
########################################
########### ADVANCED CAMPAIGN OPTIONS ##
print qq~
~;
########### END ADVANCED CAMPAIGN OPTIONS ##
############################################
print qq~
~;
$master->{html}->footer($master);
}
# >> Update Advanced Campaign
sub update_advanced_campaign{
my($self,$master)=@_;
# input params
my $cid=$master->{query}->param('cid');
my $impr_limit=$master->{query}->param('impr_limit');
my $impr_delay=$master->{query}->param('impr_delay');
my $click_limit=$master->{query}->param('click_limit');
my $click_delay=$master->{query}->param('click_delay');
my $no_impr_cap=$master->{query}->param('no_impr_cap');
my $no_click_cap=$master->{query}->param('no_click_cap');
if($no_impr_cap==1){
$impr_limit=0;
$impr_delay=0;
}
if($no_click_cap==1){
$click_limit=0;
$click_delay=0;
}
my $hour_string;
for(my $k=0;$k<24;$k++){
my $hv=$master->{query}->param("h|$k|")+0;
$hour_string.="$hv|";
}
my $day_string;
for(my $k=0;$k<7;$k++){
my $dv=$master->{query}->param("d|$k|")+0;
$day_string.="$dv|";
}
# generate query list
my $c;
$c=$master->{db}->update_cv($c,"IMPR_DELAY",$impr_delay);
$c=$master->{db}->update_cv($c,"IMPR_LIMIT",$impr_limit);
$c=$master->{db}->update_cv($c,"DAY_PRIORITY",$day_string);
$c=$master->{db}->update_cv($c,"HOUR_PRIORITY",$hour_string);
$c=$master->{db}->update_cv($c,"CLICK_DELAY",$click_delay);
$c=$master->{db}->update_cv($c,"CLICK_LIMIT",$click_limit);
chop($c);
# insert row
$master->{db}->{adcycle}->do("UPDATE cp SET $c WHERE CID='$cid'");
$master->{cron}->campaign_bin_update($master,$cid);
$master->{message}="Campaign has been updated";
$master->{campaign}->edit_campaign($master);
}
# >> Update Campaign
sub update_campaign{
my($self,$master)=@_;
# input params
my $cid=$master->{query}->param('cid');
my $month_start=$master->{query}->param('start_month');
my $day_start=$master->{query}->param('start_day');
my $year_start=$master->{query}->param('start_year');
my $month_end=$master->{query}->param('end_month');
my $day_end=$master->{query}->param('end_day');
my $year_end=$master->{query}->param('end_year');
my $mi=$master->{query}->param('max_impr');
my $mc=$master->{query}->param('max_click');
my $mdi=$master->{query}->param('max_daily_impr');
my $mdc=$master->{query}->param('max_daily_click');
my $ui=$master->{query}->param('unlimited_impr');
my $uc=$master->{query}->param('unlimited_click');
my $udi=$master->{query}->param('unlimited_daily_impr');
my $udc=$master->{query}->param('unlimited_daily_click');
my $click_verify=$master->{query}->param('delivered_click_verify');
my $impr_verify=$master->{query}->param('delivered_impr_verify');
# create dates
my $start_date="$year_start\-$month_start\-$day_start";
my $end_date="$year_end\-$month_end\-$day_end";
# handle unlimited
if($ui==1){$mi=0};
if($uc==1){$mc=0};
if($udi==1){$mdi=0};
if($udc==1){$mdc=0};
# generate query list
my $c;
$c=$master->{db}->update_cv($c,"CAMPAIGN_NAME",$master->{query}->param('campaign_name'));
$c=$master->{db}->update_cv($c,"START_DATE",$start_date);
$c=$master->{db}->update_cv($c,"END_DATE",$end_date);
$c=$master->{db}->update_cv($c,"MAX_IMPR",$mi);
$c=$master->{db}->update_cv($c,"MAX_CLICK",$mc);
$c=$master->{db}->update_cv($c,"MAX_DAILY_CLICK",$mdc);
$c=$master->{db}->update_cv($c,"MAX_DAILY_IMPR",$mdi);
$c=$master->{db}->update_cv($c,"CPM",$master->{query}->param('cpm'));
$c=$master->{db}->update_cv($c,"CPC",$master->{query}->param('cpc'));
if($click_verify==1){
$c=$master->{db}->update_cv($c,"DELIVERED_CLICK",$master->{query}->param('delivered_click'));
}
if($impr_verify==1){
$c=$master->{db}->update_cv($c,"DELIVERED_IMPR",$master->{query}->param('delivered_impr'));
}
chop($c);
# insert row
$master->{db}->{adcycle}->do("UPDATE cp SET $c WHERE CID='$cid'");
$master->{cron}->campaign_bin_update($master,$cid);
$master->{message}="Campaign has been updated";
$master->{campaign}->edit_campaign($master);
}
sub select_campaign_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;
# input vars
my $cid=$master->{query}->param('cid');
#get the campaign ref
my $cidref=$master->{db}->select_single_row_hash("SELECT * FROM cp where CID='$cid'");
#get the groupings for cid
my(@gridref)=$master->{db}->select_multi_row_hash("SELECT GID,WEIGHT,STATUS,SUM(TOTAL_IMPR) as TOTAL_IMPR, SUM(TOTAL_CLICK) as TOTAL_CLICK FROM cp_grouping where CID='$cid' GROUP BY GID");
my $gridtot=@gridref;
# print header
$master->{LINK}="campaigns";
$master->{html}->header($master,"Select Groups: $cidref->{CAMPAIGN_NAME}");
# >> top menu
print qq~
~;
$master->{html}->footer($master);
}
sub update_campaign_grouping{
my($self,$master)=@_;
# input params
my $cid=$master->{query}->param('cid');
#get the campaign ref
my $cidref=$master->{db}->select_single_row_hash("SELECT * FROM cp where CID='$cid'");
#get the groups
my(@gidref)=$master->{db}->select_multi_row_hash("SELECT * FROM groups where WIDTH='$cidref->{WIDTH}' AND HEIGHT='$cidref->{HEIGHT}'");
my $gidtot=@gidref;
#get the groupings for cid
my(@gridref)=$master->{db}->select_multi_row_hash("SELECT GID,WEIGHT,STATUS,SUM(TOTAL_IMPR) as TOTAL_IMPR, SUM(TOTAL_CLICK) as TOTAL_CLICK FROM cp_grouping where CID='$cid' GROUP BY GID");
my $gridtot=@gridref;
for(my $k=0;$k<$gidtot;$k++){
my $gid=$gidref[$k]->{GID};
my $temp=$master->{query}->param("G|$gid|")+0;
$master->{db}->{adcycle}->do("UPDATE cp_grouping SET STATUS=$temp WHERE CID='$cid' AND GID='$gid'");
}
$master->{message}="Campaign grouping has been updated";
$master->{campaign}->select_campaign_groups($master);
}
sub add_standard{
my($self,$master)=@_;
# input params
my $cid=$master->{query}->param('cid');
#get the campaign ref
my $cidref=$master->{db}->select_single_row_hash("SELECT * FROM cp where CID='$cid'");
# ad qty
my $ad_qty=$master->{db}->single_result("SELECT COUNT(*) from cp_media WHERE CID='$cid' and AD_TYPE=0");
$ad_qty++;
# get mid
my $mid=$master->{tools}->get_id($master,"MID");
# make insert list
my $insert_list=[
["NAME","Ad \#$ad_qty"],
["AID",$cidref->{AID}],
["CID",$cid],
["WEIGHT","0"],
["MID",$mid]
];
# insert row
$master->{db}->insert_row("cp_media",$insert_list);
#get the campaigns
my(@gidref)=$master->{db}->select_multi_row_hash("SELECT * FROM groups WHERE WIDTH='$cidref->{WIDTH}' AND HEIGHT='$cidref->{HEIGHT}'");
my $gidtot=@gidref;
#get the campaigns
my(@gidref)=$master->{db}->select_multi_row_hash("SELECT * FROM groups WHERE WIDTH='$cidref->{WIDTH}' AND HEIGHT='$cidref->{HEIGHT}'");
my $gidtot=@gidref;
#get the adconfig
my $configref=$master->{db}->select_single_row_hash("SELECT * FROM adconfig");
for(my $k=0;$k<$gidtot;$k++){
my $gridref=$master->{db}->select_single_row_hash("SELECT * FROM cp_grouping WHERE CID='$cid' AND GID='$gidref[$k]->{GID} LIMIT 1'");
my $status=$gridref->{STATUS}+0;
my $weight=$gridref->{WEIGHT}+0;
# make insert list
my $insert_list=[
["GID",$gidref[$k]->{GID}],
["AID",$cidref->{AID}],
["CID",$cidref->{CID}],
["MID",$mid],
["STATUS",$status],
["WEIGHT",$weight]
];
# insert row
$master->{db}->insert_row("cp_grouping",$insert_list);
}
# check campaign status
$master->{campaign}->media_status($master);
# update bin
$master->{cron}->campaign_bin_update($master,$cid);
$master->{message}="Standard Media Element has been created";
$master->{campaign}->edit_campaign($master);
}
sub add_html{
my($self,$master)=@_;
# input params
my $cid=$master->{query}->param('cid');
my $images_url=$master->{config}->get_images_url;
my $cgi_bin_url=$master->{config}->get_cgi_bin_url;
#get the campaign ref
my $cidref=$master->{db}->select_single_row_hash("SELECT * FROM cp where CID='$cid'");
# rich ad qty
my $ad_qty=$master->{db}->single_result("SELECT COUNT(*) from cp_media WHERE CID='$cid' and AD_TYPE=1");
$ad_qty++;
# get mid
my $mid=$master->{tools}->get_id($master,"MID");
my $rich=qq~{WIDTH} height=$cidref->{HEIGHT} border=0 alt="Click to Visit">~;
# make insert list
my $insert_list=[
["NAME","HTML Ad \#$ad_qty"],
["AID",$cidref->{AID}],
["CID",$cid],
["MID",$mid],
["RICH",$rich],
["WEIGHT","0"],
["AD_TYPE","1"],
];
# insert row
$master->{db}->insert_row("cp_media",$insert_list);
#get the campaigns
my(@gidref)=$master->{db}->select_multi_row_hash("SELECT * FROM groups WHERE WIDTH='$cidref->{WIDTH}' AND HEIGHT='$cidref->{HEIGHT}'");
my $gidtot=@gidref;
#get the adconfig
my $configref=$master->{db}->select_single_row_hash("SELECT * FROM adconfig");
for(my $k=0;$k<$gidtot;$k++){
my $gridref=$master->{db}->select_single_row_hash("SELECT * FROM cp_grouping WHERE CID='$cid' AND GID='$gidref[$k]->{GID} LIMIT 1'");
my $status=$gridref->{STATUS}+0;
my $weight=$gridref->{WEIGHT}+0;
# make insert list
my $insert_list=[
["GID",$gidref[$k]->{GID}],
["AID",$cidref->{AID}],
["CID",$cidref->{CID}],
["MID",$mid],
["STATUS",$status],
["WEIGHT",$weight]
];
# insert row
$master->{db}->insert_row("cp_grouping",$insert_list);
}
# check campaign status
$master->{campaign}->media_status($master);
# update bin
$master->{cron}->campaign_bin_update($master,$cid);
$master->{message}="HTML Element has been created";
$master->{campaign}->edit_campaign($master);
}
sub delete_campaign{
my($self,$master)=@_;
# input params
my $cid=$master->{query}->param('cid');
# delete advertiser
$master->{db}->{adcycle}->do("DELETE FROM cp WHERE CID='$cid'");
# delete media
$master->{db}->{adcycle}->do("DELETE FROM cp_media WHERE CID='$cid'");
# delete grouping
$master->{db}->{adcycle}->do("DELETE FROM cp_grouping WHERE CID='$cid'");
# delete grouping
$master->{db}->{adcycle}->do("DELETE FROM daily_log WHERE CID='$cid'");
# update bin
$master->{cron}->campaign_bin_update($master,$cid);
$master->{message}="Campaign has been deleted";
$master->{campaign}->view_campaigns($master);
}
sub reset_campaign_data{
my($self,$master)=@_;
# input params
my $cid=$master->{query}->param('cid');
# delete campaign data
$master->{db}->{adcycle}->do("UPDATE cp SET
IMPR_BIN=99999999,
CLICK_BIN=99999999,
ACTION_BIN=99999999,
MAX_IMPR=0,
MAX_CLICK=0,
MAX_ACTION=0,
MAX_DAILY_IMPR=0,
MAX_DAILY_CLICK=0,
MAX_DAILY_ACTION=0,
TODAY_IMPR=0,
TODAY_CLICK=0,
TODAY_ACTION=0,
DELIVERED_IMPR=0,
DELIVERED_CLICK=0,
DELIVERED_ACTION=0
WHERE CID='$cid'");
# delete media
$master->{db}->{adcycle}->do("UPDATE cp_media SET
TOTAL_IMPR=0,
TOTAL_CLICK=0,
TOTAL_ACTION=0
WHERE CID='$cid'");
# delete grouping
$master->{db}->{adcycle}->do("UPDATE cp_grouping SET
HOUR_IMPR=0,
HOUR_CLICK=0,
HOUR_ACTION=0,
TOTAL_IMPR=0,
TOTAL_CLICK=0,
TOTAL_ACTION=0
WHERE CID='$cid'");
# delete grouping
$master->{db}->{adcycle}->do("DELETE FROM daily_log WHERE CID='$cid'");
# delete grouping
$master->{db}->{adcycle}->do("DELETE FROM raw_log WHERE CID='$cid'");
# update bin
$master->{cron}->campaign_bin_update($master,$cid);
$master->{message}="Data has been reset";
$master->{campaign}->edit_campaign($master);
}
sub delete_media{
my($self,$master)=@_;
# input params
my $mid=$master->{query}->param('mid');
my $cid=$master->{query}->param('cid');
# delete media
$master->{db}->{adcycle}->do("DELETE FROM cp_media WHERE MID='$mid'");
# check campaign status
$master->{campaign}->media_status($master);
# update bin
$master->{cron}->campaign_bin_update($master,$cid);
$master->{message}="Media has been deleted";
$master->{campaign}->edit_campaign($master);
}
sub media_status{
my($self,$master)=@_;
# input params
my $mid=$master->{query}->param('mid');
my $cid=$master->{query}->param('cid');
# get counts
my $count_standard=$master->{db}->single_result("SELECT COUNT(*) from cp_media WHERE CID='$cid' and AD_TYPE=0 AND WEIGHT > 0");
my $total_count=$master->{db}->single_result("SELECT COUNT(*) from cp_media WHERE CID='$cid' AND WEIGHT > 0");
# generate query list
my $c;
if($count_standard==0){
$c=$master->{db}->update_cv($c,"RICH_ONLY","1");
}else{
$c=$master->{db}->update_cv($c,"RICH_ONLY","0");
}
if($total_count==0){
$c=$master->{db}->update_cv($c,"STATUS","0");
}
chop($c);
# insert row
$master->{db}->{adcycle}->do("UPDATE cp SET $c WHERE CID='$cid'");
return $master
}
sub edit_standard{
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 params
my $mid=$master->{query}->param('mid');
#get the mediaref
my $midref=$master->{db}->select_single_row_hash("SELECT * FROM cp_media where MID='$mid'");
my $cid=$midref->{CID};
#get the campaign ref
my $cidref=$master->{db}->select_single_row_hash("SELECT * FROM cp where CID='$cid'");
my $width=$cidref->{WIDTH};
my $height=$cidref->{HEIGHT};
#get the adconfig
my $configref=$master->{db}->select_single_row_hash("SELECT * FROM adconfig");
# print header
$master->{LINK}="campaigns";
$master->{html}->header($master,"Edit: $midref->{NAME}");
my @border;$border[$midref->{BORDER}]=" SELECTED ";
my %target;$target{$midref->{TARGET}}=" SELECTED ";
my @und;$und[$midref->{WEIGHT}]=" SELECTED ";
my %def;$def{$midref->{USE_AS_HTML_DEFAULT}}=" CHECKED ";
my $under_text="";
if(length($midref->{UNDER_TEXT})>0){
$under_text=qq~$midref->{UNDER_TEXT}~;
}
my $img_url=$midref->{IMG_URL};
my $click_url=$midref->{CLICK_URL};
my $alt=$midref->{ALT};
my $under_text=$midref->{UNDER_TEXT};
my $link=$midref->{UNDER_TEXT};
# convert under text
$midref->{UNDER_TEXT}=~s/\\<\;/g;
$midref->{UNDER_TEXT}=~s/\>/\>\;/g;
$midref->{UNDER_TEXT}=~s/\"/\"\;/g;
# convert alt
$midref->{ALT}=~s/\\<\;/g;
$midref->{ALT}=~s/\>/\>\;/g;
$midref->{ALT}=~s/\"/\"\;/g;
$img_url=~s/IDNUMBER+/$cache/g;
$click_url=~s/IDNUMBER+/$cache/g;
$alt=~s/IDNUMBER+/$cache/g;
$under_text=~s/IDNUMBER+/$cache/g;
if(length($under_text)>0){
$under_text=qq~$under_text~;
}
my $direct_code=qq~[Direct Ad Code]~;
my $single_pixel="";
if(index($midref->{SINGLE_PIXEL_URL},"http:")!=-1){
$single_pixel=qq~~;
}
# >> top menu
print qq~
~;
# << top menu
if($width > 2 && $height > 2){
my $mouseover="";
if(length($midref->{MOUSEOVER})>0){
$mouseover=qq~ onMouseover="$midref->{MOUSEOVER}" ~;
}
print qq~
~;
$master->{html}->footer($master);
}
sub update_standard{
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 params
my $mid=$master->{query}->param('mid');
my $cid=$master->{query}->param('cid');
my $click_verify=$master->{query}->param('delivered_click_verify');
my $impr_verify=$master->{query}->param('delivered_impr_verify');
my $file=$master->{query}->param('upname');
my $configref=$master->{db}->select_single_row_hash("SELECT * FROM adconfig");
my $ad_dir=$configref->{AD_DIR};
my $fn = $file;
my $img_url=$master->{query}->param('image');
$fn =~ s,^.*(\\|/)(.+)$,$2,;
if ($fn =~ /^([-\@\w.]+)$/) {
$fn = $1;
} else {
if($fn ne undef) {
die "'$fn' is an illegal filename.";
}
}
# >> upload file
{
no strict;
my $buffer;
my $bytesread;
if(length($fn)>0){
open(OUTFILE,">$ad_dir/$fn");
binmode OUTFILE;
while($bytesread=read($file,$buffer,1024)){
print OUTFILE $buffer;
}
close(OUTFILE);
$img_url="$configref->{AD_URL}/$fn";
}
}
# << upload file
# generate query list
my $c;
if($impr_verify==1){
$c=$master->{db}->update_cv($c,"TOTAL_IMPR",$master->{query}->param('delivered_impr'));
}
if($click_verify==1){
$c=$master->{db}->update_cv($c,"TOTAL_CLICK",$master->{query}->param('delivered_click'));
}
$c=$master->{db}->update_cv($c,"SINGLE_PIXEL_URL",$master->{query}->param('single'));
$c=$master->{db}->update_cv($c,"IMG_URL",$img_url)."";
$c=$master->{db}->update_cv($c,"NAME",$master->{query}->param('name')."");
$c=$master->{db}->update_cv($c,"CLICK_URL",$master->{query}->param('click')."");
$c=$master->{db}->update_cv($c,"WEIGHT",$master->{query}->param('weight')+0);
$c=$master->{db}->update_cv($c,"BORDER",$master->{query}->param('border')+0);
$c=$master->{db}->update_cv($c,"TARGET",$master->{query}->param('target')."");
$c=$master->{db}->update_cv($c,"ALT",$master->{query}->param('alt')."");
$c=$master->{db}->update_cv($c,"MOUSEOVER",$master->{query}->param('mouseover')."");
$c=$master->{db}->update_cv($c,"UNDER_TEXT",$master->{query}->param('btext')."");
$c=$master->{db}->update_cv($c,"USE_AS_HTML_DEFAULT",$master->{query}->param('default')."");
chop($c);
# insert row
$master->{db}->{adcycle}->do("UPDATE cp_media SET $c WHERE MID='$mid'");
# update bin
$master->{cron}->campaign_bin_update($master,$cid);
# check campaign status
$master->{campaign}->media_status($master);
$master->{message}="Standard media has been updated ";
$master->{campaign}->edit_standard($master);
}
sub edit_html{
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 params
my $mid=$master->{query}->param('mid');
#get the mediaref
my $midref=$master->{db}->select_single_row_hash("SELECT * FROM cp_media where MID='$mid'");
my $cid=$midref->{CID};
#get the campaign ref
my $cidref=$master->{db}->select_single_row_hash("SELECT * FROM cp where CID='$cid'");
my $width=$cidref->{WIDTH};
my $height=$cidref->{HEIGHT};
# print header
$master->{LINK}="campaigns";
$master->{html}->header($master,"Edit: $midref->{NAME}");
my @und;$und[$midref->{WEIGHT}]=" SELECTED ";
my $rich_ad=$midref->{RICH};
$rich_ad=~s/IDNUMBER+/$cache/g;
# >> top menu
print qq~
To enable AdCycle click tracking insert {long} class="ft1"> into your HTML.
If the code you insert has IFRAME or Javascript tags, adcycle may not be able to track clicks since the final ad code to the end user is being dynamically generated by a third party.
If you need the adcode id passed to the HTML above, insert the word "IDNUMBER" (without the quotes) in the HTML code in one or more places.
All links in your html should have a target attribute of "_top" or "_blank" to force the page to open within the complete browser window when the ad is clicked on.
~;
$master->{html}->footer($master);
}
sub update_html{
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 params
my $cid=$master->{query}->param('cid');
my $mid=$master->{query}->param('mid');
my $click_verify=$master->{query}->param('delivered_click_verify');
my $impr_verify=$master->{query}->param('delivered_impr_verify');
# generate query list
my $c;
if($impr_verify==1){
$c=$master->{db}->update_cv($c,"TOTAL_IMPR",$master->{query}->param('delivered_impr'));
}
if($click_verify==1){
$c=$master->{db}->update_cv($c,"TOTAL_CLICK",$master->{query}->param('delivered_click'));
}
$c=$master->{db}->update_cv($c,"NAME",$master->{query}->param('name'));
$c=$master->{db}->update_cv($c,"CLICK_URL",$master->{query}->param('click'));
$c=$master->{db}->update_cv($c,"RICH",$master->{query}->param('html'));
$c=$master->{db}->update_cv($c,"WEIGHT",$master->{query}->param('weight'));
chop($c);
# insert row
$master->{db}->{adcycle}->do("UPDATE cp_media SET $c WHERE MID='$mid'");
# update bin
$master->{cron}->campaign_bin_update($master,$cid);
# check campaign status
$master->{campaign}->media_status($master);
$master->{message}="Standard media has been updated";
$master->{campaign}->edit_html($master);
}
sub reset_media{
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 params
my $mid=$master->{query}->param('mid');
# generate query list
my $c;
$c=$master->{db}->update_cv($c,"TOTAL_IMPR","0");
$c=$master->{db}->update_cv($c,"TOTAL_CLICK","0");
chop($c);
# insert row
$master->{db}->{adcycle}->do("UPDATE cp_media SET $c WHERE MID='$mid'");
$master->{message}="Counters have been reset";
$master->{campaign}->edit_campaign($master);
}
sub delivery_rate{
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 params
my $cid=$master->{query}->param('cid');
my $val=$master->{query}->param('val');
# generate query list
my $c;
$c=$master->{db}->update_cv($c,"RATE_CONTROL","$val");
chop($c);
# insert row
$master->{db}->{adcycle}->do("UPDATE cp SET $c WHERE CID='$cid'");
$master->{cron}->campaign_bin_update($master,$cid);
$master->{message}="Delivery rate controller has been changed";
$master->{campaign}->edit_campaign($master);
}
# >> DIRECT AD CODE
sub direct_adcode{
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 params
my $cid=$master->{query}->param('cid');
my $gid=$master->{query}->param('gid');
my $mid=$master->{query}->param('mid');
#get the campaign ref
my $cidref=$master->{db}->select_single_row_hash("SELECT * FROM cp where CID='$cid'");
my $midref=$master->{db}->select_single_row_hash("SELECT * FROM cp_media where MID='$mid'");
my $width=$cidref->{WIDTH};
my $height=$cidref->{HEIGHT};
#get the campaigns
my(@gidref)=$master->{db}->select_multi_row_hash("SELECT * FROM groups WHERE WIDTH='$width' AND HEIGHT='$height' order by GID");
my $gidtot=@gidref;
# print header
$master->{LINK}="campaigns";
$master->{html}->header($master,"Get a Direct Ad Code for Link: ");
if($gidtot==0){
print "Woops! There are no groups for this ad type. Please create a group, and try again.\n";
}else{
if($gid==0){
$gid=$gidref[0]->{GID};
}
my $gidref=$master->{db}->select_single_row_hash("SELECT * FROM groups where GID='$gid'");
print qq~
Direct Ad Code
The ad codes in this page will directly display the ad you have selected. No ads will rotate using these ad codes. This ad code will effectively force an impression. For banner, button, and text ads, click capping will still be enforced. Stats will be generated for the group you select above. For ad rotation, use the ad codes from the "Groups" page.
~;
print qq~
~;
my $single_pixel="";
if(index($midref->{SINGLE_PIXEL_URL},"http:")!=-1){
$single_pixel=qq~~;
}
my $under_text="";
if(length($midref->{UNDER_TEXT})>0){
$under_text=qq~ $midref->{UNDER_TEXT} ~;
}
# >> standard ad
if($width>2 && $height>2){
my $adcode=qq~
{BORDER} ALT="$midref->{ALT}">$under_text$single_pixel
~;
$adcode=~s/\\<\;/g;
$adcode=~s/\>/\>\;/g;
$adcode=~s/\"/\"\;/g;
print qq~
~;
}
# << standard ad
# >> text
if($width==1 && $height==1){
my $turl=qq~~;
my $link=$midref->{UNDER_TEXT};
# >> Text Link
# $link=~ s/\'/\%27/g;
if(index($link,"[U]")==-1){
$link=qq~$turl$link~;
}else{
$link=~ s/\[U\]/$turl/g;
$link=~ s/\[\/U\]/\<\/a\>/g;
}
# << Text Link
my $adcode=qq~
$link$single_pixel
~;
$adcode=~s/\\<\;/g;
$adcode=~s/\>/\>\;/g;
$adcode=~s/\"/\"\;/g;
print qq~
~;
my $adcode=qq~
$link$single_pixel
~;
$adcode=~s/\\<\;/g;
$adcode=~s/\>/\>\;/g;
$adcode=~s/\"/\"\;/g;
print qq~
~;
}
# << text
# >> pop under window
if($width==2 && $height==2){
my $adcode=qq~
~;
$adcode=~s/\\<\;/g;
$adcode=~s/\>/\>\;/g;
$adcode=~s/\"/\"\;/g;
print qq~
~;
my $adcode=qq~
~;
$adcode=~s/\\<\;/g;
$adcode=~s/\>/\>\;/g;
$adcode=~s/\"/\"\;/g;
print qq~
~;
}
# >> pop under window
}
$master->{html}->footer($master);
}
# << DIRECT AD CODE
# Copyright (c) 2003 AdCycle.com All rights reserved.
# http://www.adcycle.com - download the lastest version of adcycle
1;