#!/usr/bin/perl --
$localTest=1 if(-e "local.txt");
$data_dir="/home/sites/www.lidget.co.uk/web/data/";
$data_dir="/home/lidget.co.uk/data/" if($localTest);
use Date::Parse;
require 'dmc-lib.pl';
require $data_dir.'vars.txt';
require 'cgi-lib.pl';
require 'cookies.pl';
require 'dmc-mysql.pl';
require 'admin.pl';
$cgi_lib'maxdata=104857600; # '
&ReadParse;
($aname,$admin,$c_cid)=&get_admin_status;
&set_incs;
# Admin Commands
if($in{'Command'} eq "AdminLogin"){
&admin_login;
}
elsif($in{'Command'} eq "AdminLogout"){
&admin_logout;
} # News Commands
elsif($in{'Command'} eq "ShowAddNews"){
&show_add_news;
}
elsif($in{'Command'} eq "AddNews"){
&add_news;
}
elsif($in{'Command'} eq "ChangeStatus"){
&change_status;
}
elsif($in{'Command'} eq "SaveAllNews"){
&save_all_news;
}
elsif($in{'Command'} eq "ShowEditNews"){
&show_edit_news;
}
elsif($in{'Command'} eq "EditNews"){
&edit_news;
}
elsif($in{'Command'} eq "ShowNews"){
&show_news;
}
elsif($in{'Command'} eq "SubmitNews"){
&submit_news;
}
elsif($in{'Command'} eq "ShowPreviewNews"){
&show_preview_news;
}
elsif($in{'Command'} eq "SearchNews"){
&search_news;
}
elsif($in{'Command'} eq "ListNews"){
&list_news;
}
elsif($in{'Command'} eq "ListNewsU"){
&list_news_u;
}
elsif($in{'Command'} eq "ListAllNews"){
&list_all_news;
}
elsif($in{'Command'} eq "ListAllCatsNews"){
&list_all_cats_news;
}
elsif($in{'Command'} eq "ShowRemoveNews"){
&show_remove_news;
}
elsif($in{'Command'} eq "RemoveNews"){
&remove_news;
}
elsif($in{'Command'} eq "KickNewsletters"){
&kick_newsletters;
}
elsif($in{'Command'} eq "SendNewsletter"){
&send_newsletter;
} # Images Commands
elsif($in{'Command'} eq "ShowAddImage"){
&show_add_image;
}
elsif($in{'Command'} eq "AddImage"){
&add_image;
}
elsif($in{'Command'} eq "ShowEditImage"){
&show_edit_image;
}
elsif($in{'Command'} eq "EditImage"){
&edit_image;
}
elsif($in{'Command'} eq "ListImages"){
&list_images;
}
elsif($in{'Command'} eq "ShowImage"){
&show_image;
}
elsif($in{'Command'} eq "ShowRemoveImage"){
&show_remove_image;
}
elsif($in{'Command'} eq "RemoveImage"){
&remove_gal_image;
}
elsif($in{'Command'} eq "ManageImages"){
&manage_images;
}
elsif($in{'Command'} eq "ShowImageGallery"){
&show_image_gallery;
} # Agents Commands
elsif($in{'Command'} eq "ShowAddAgent"){
&show_add_agent;
}
elsif($in{'Command'} eq "AddAgent"){
&add_agent;
}
elsif($in{'Command'} eq "ShowEditAgent"){
&show_edit_agent;
}
elsif($in{'Command'} eq "EditAgent"){
&edit_agent;
}
elsif($in{'Command'} eq "ListAgents"){
&list_agents;
}
elsif($in{'Command'} eq "ShowSendAgentMessage"){
&show_send_agent_message;
}
elsif($in{'Command'} eq "SendAgentMessage"){
&send_agent_message;
}
elsif($in{'Command'} eq "ShowSelectRegion"){
&show_select_region;
}
elsif($in{'Command'} eq "SearchAgents"){
&search_agents;
}
elsif($in{'Command'} eq "ShowAgent"){
&show_agent;
}
elsif($in{'Command'} eq "ShowRemoveAgent"){
&show_remove_agent;
}
elsif($in{'Command'} eq "RemoveAgent"){
&remove_agent;
}
elsif($in{'Command'} eq "ManageImages"){
&manage_images;
}
elsif($in{'Command'} eq "ShowImageGallery"){
&show_image_gallery;
} # Search Commands
elsif($in{'Command'} eq "RebuildPages"){
&rebuild_pages;
}
elsif($in{'Command'} eq "Search"){
&search;
} # Misc. Commands
elsif($in{'Command'} eq "ShowImage"){
&show_image;
}
elsif($in{'Command'} eq "ShowEditPage"){
&show_edit_page;
}
elsif($in{'Command'} eq "EditPage"){
&edit_page;
}
elsif($in{'Command'} eq "SendBrochureReq"){
&send_brochure_req;
}
elsif($in{'C'} eq "US"){
&remove_email;
}
elsif($in{'Command'} eq "US"){
&remove_email;
}
elsif($in{'Command'} eq "ShowContact"){
&show_contact;
}
elsif($in{'Command'} eq "AddEMail"){
&add_email;
}
elsif($in{'Command'} eq "ListEMails"){
&list_emails;
}
elsif($in{'Command'} eq "EditEMails"){
&edit_emails;
}
elsif($in{'Command'} eq "ListPeople"){
&list_people;
}
elsif($in{'Command'} eq "EditPeople"){
&edit_people;
}
elsif($in{'Command'} eq "ShowFramed"){
&show_framed;
}
elsif($in{'Command'} eq "ShowMessage"){
&show_message;
}
elsif($in{'Command'} eq "ShowImage"){
&show_image;
}
elsif($in{'Command'} eq "GoTo"){
&go_to;
}
elsif($in{'Command'} eq "Checkups"){
&checkups;
}
elsif($in{'Command'} eq "SaveAllAds"){
&save_all_ads;
}
elsif($in{'Command'} eq "AddEMail"){
&add_email;
}
elsif($in{'Command'} eq "LoadAgents"){
&load_agents;
}
elsif($in{'Command'} eq "Housekeeping"){
&special_housekeeping;
message_exit("Updated");
}
else{
message_exit("No Command $in{'Command'}",$home_link);
}
# Admin subs
sub admin_login{
my($ret)=do_admin_login($in{'Name'},$in{'Pass'});
redirect($base_url."adminlogin/admin.htm","parent");
exit(0);
}
sub admin_logout{
set_cookie($site_name.".cid","","PATH","/");
&do_admin_logout;
redirect($base_url."index.shtml","_top");
exit(0);
}
# News subs
sub show_add_news{
eval << 'END';
require 'news.pl';
&needs_to_be_admin;
&header_out;
&do_show_add_news;
exit(0);
END
}
sub add_news{
eval << 'END';
require 'news.pl';
&needs_to_be_admin;
&header_out;
my($aid)=&do_add_news(\%in);
# &save_sitemap;
redirect_to_command("ListNews");
exit(0);
END
}
sub show_edit_news{
eval << 'END';
require 'news.pl';
# save_place("LastList");
&needs_to_be_admin;
&header_out;
&do_show_edit_news($in{'db_nid'});
exit(0);
END
}
sub edit_news{
eval << 'END';
require 'news.pl';
&needs_to_be_admin;
&header_out;
&do_edit_news(\%in);
# &save_sitemap;
go_to_place("LastNewsPlace");
exit(0);
END
}
sub show_remove_news{
eval << 'END';
require 'news.pl';
&needs_to_be_admin;
&header_out;
&do_show_remove_news($in{'db_nid'});
exit(0);
END
}
sub remove_news{
eval << 'END';
require 'news.pl';
&needs_to_be_admin;
&header_out;
&do_remove_news($in{'db_nid'});
# &save_sitemap;
go_to_place("LastNewsList");
exit(0);
END
}
sub send_newsletter{
eval << 'END';
require 'news.pl';
&needs_to_be_admin;
&header_out;
&do_send_newsletter($in{'db_nid'});
go_to_place("LastNewsPlace");
exit(0);
END
}
sub kick_newsletters{
eval << 'END';
require 'news.pl';
&do_kick_newsletters($in{'db_nid'});
exit(0);
END
}
sub show_news{
eval << 'END';
require 'news.pl';
# save_place("LastList");
# save_place("LastNewsList");
save_place("LastNewsPlace");
&header_out;
&do_show_news(\%in);
exit(0);
END
}
sub list_news{
eval << 'END';
require 'news.pl';
save_place("LastList");
save_place("LastNewsList");
save_place("LastNewsPlace");
&header_out;
# message_exit($c_cid);
&do_list_news(\%in);
exit(0);
END
}
sub list_all_news{
eval << 'END';
require 'news.pl';
save_place("LastNewsList");
&header_out;
&do_list_all_news;
exit(0);
END
}
sub show_image_gallery{
eval << 'END';
require 'projects.pl';
&header_out;
&do_show_image_gallery($in{'db_pid'});
exit(0);
END
}
# Agents subs
sub show_add_agent{
eval << 'END';
require 'agents.pl';
&needs_to_be_admin;
&header_out;
&do_show_add_agent;
exit(0);
END
}
sub add_agent{
eval << 'END';
require 'agents.pl';
&needs_to_be_admin;
&header_out;
&do_add_agent(\%in);
go_to_place("LastAgentsList");
exit(0);
END
}
sub show_edit_agent{
eval << 'END';
require 'agents.pl';
save_place("LastAgentsEdit");
&needs_to_be_admin;
&header_out;
&do_show_edit_agent($in{'db_aid'});
exit(0);
END
}
sub edit_agent{
eval << 'END';
require 'agents.pl';
&needs_to_be_admin;
&header_out;
&do_edit_agent(\%in);
go_to_place("LastAgentsPlace");
exit(0);
END
}
sub show_remove_agent{
eval << 'END';
require 'agents.pl';
&needs_to_be_admin;
&header_out;
&do_show_remove_agent($in{'db_aid'});
exit(0);
END
}
sub remove_agent{
eval << 'END';
require 'agents.pl';
&needs_to_be_admin;
&header_out;
&do_remove_agent($in{'db_aid'});
go_to_place("LastAgentsList");
exit(0);
END
}
sub list_agents{
eval << 'END';
require 'agents.pl';
save_place("LastList");
save_place("LastAgentsList");
save_place("LastAgentsPlace");
&header_out;
&do_list_agents(\%in);
exit(0);
END
}
sub show_send_agent_message{
eval << 'END';
require 'agents.pl';
save_place("LastList");
save_place("LastAgentsList");
save_place("LastAgentsPlace");
&header_out;
&do_show_send_agent_message(\%in);
exit(0);
END
}
sub send_agent_message{
eval << 'END';
require 'agents.pl';
&needs_to_be_admin;
&header_out;
&do_send_agent_message(\%in);
go_to_place("LastAgentsPlace");
exit(0);
END
}
sub show_select_region{
eval << 'END';
require 'agents.pl';
&header_out;
&do_show_select_region;
exit(0);
END
}
sub search_agents{
eval << 'END';
require 'agents.pl';
save_place("LastList");
save_place("LastAgentsList");
save_place("LastAgentsPlace");
&header_out;
&do_search_agents(\%in);
exit(0);
END
}
sub show_contact{
eval << 'END';
require 'wheres.pl';
# &needs_to_be_admin;
&header_out;
&do_show_contact;
exit(0);
END
}
# Images subs
sub show_add_image{
eval << 'END';
require 'images.pl';
&needs_to_be_admin;
&header_out;
&do_show_add_image;
exit(0);
END
}
sub add_image{
eval << 'END';
require 'images.pl';
&needs_to_be_admin;
&header_out;
&do_add_image(\%in);
go_to_place("LastImagesList");
exit(0);
END
}
sub show_edit_image{
eval << 'END';
require 'images.pl';
save_place("LastImagesEdit");
&needs_to_be_admin;
&header_out;
&do_show_edit_image($in{'db_iid'});
exit(0);
END
}
sub edit_image{
eval << 'END';
require 'images.pl';
&needs_to_be_admin;
&header_out;
&do_edit_image(\%in);
go_to_place("LastImagesPlace");
exit(0);
END
}
sub show_remove_image{
eval << 'END';
require 'images.pl';
&needs_to_be_admin;
&header_out;
&do_show_remove_image($in{'db_iid'});
exit(0);
END
}
sub remove_gal_image{
eval << 'END';
require 'images.pl';
&needs_to_be_admin;
&header_out;
&do_remove_image($in{'db_iid'});
go_to_place("LastImagesList");
exit(0);
END
}
sub list_images{
eval << 'END';
require 'images.pl';
save_place("LastList");
save_place("LastImagesList");
save_place("LastImagesPlace");
&header_out;
&do_list_images(\%in);
exit(0);
END
}
sub search_images{
eval << 'END';
require 'images.pl';
save_place("LastList");
save_place("LastImagesList");
save_place("LastImagesPlace");
&header_out;
&do_search_images(\%in);
exit(0);
END
}
sub show_contact{
eval << 'END';
require 'wheres.pl';
# &needs_to_be_admin;
&header_out;
&do_show_contact;
exit(0);
END
}
# Search subs
sub rebuild_pages{
eval << 'END';
require 'search.pl';
&header_out;
&do_rebuild_pages;
exit(0);
END
}
sub search{
eval << 'END';
require 'search.pl';
save_place("LastList");
&header_out;
&do_search_pages($data_dir."lg_search_res.htm",$data_dir."lg_search_res_fmt.htm",\%in);
END
}
# Misc. subs
sub set_incs{
my($dbh)=&connect_to_db;
my(@news)=get_records($all_news_fields,"news","db_nid is not null order by db_date desc,db_nid desc limit 0,3",$dbh);
foreach $i (0..$#news){
$news[$i]{'db_date'}=format_date_day_month_year_num($news[$i]{'db_date'});
$news[$i]{'SN'}=$i;
}
$inc_2=fill_in_list($data_dir."lg_recent_news.htm",$data_dir."lg_recent_news_fmt.htm","NLIST","$all_news_fields,SN",@news);
if(count_records("images","db_iid is not null",$dbh) > 0){
my(%image)=get_record($all_images_fields,"images","db_iid is not null order by db_date desc limit 0,1",$dbh);
my(%cat)=get_record($all_cats_fields,"cats","db_cid=$image{'db_cid'}",$dbh);
$image{'db_date'}=format_date_day_month_year_num($image{'db_date'});
$image{'cat'}=$cat{'db_name'};
$image{'SN'}=0;
$inc_5=fill_in($data_dir."lg_latest_image.htm","$all_images_fields,cat,SN",%image);
}
else{
$inc_5="";
}
disconnect_from_db($dbh);
}
sub add_email{
error_exit("The email address: $in{'db_email'} is invalid",$back_link) if(check_email($in{'db_email'}));
add_record("db_email","emails",qq(db_email="$in{'db_email'}"),%in);
redirect($base_url."newsletter_confirm.shtml");
exit(0);
}
sub remove_email{
error_exit("The email address: $in{'db_email'} is invalid",$back_link) if(check_email($in{'db_email'}));
my($dbh)=&connect_to_db;
do_command(qq(delete from emails where db_email="$in{'db_email'}"),$dbh);
disconnect_from_db($dbh);
redirect($base_url."unsubscribe_confirm.shtml");
exit(0);
}
sub show_edit_page{
eval << 'END';
require 'pages.pl';
&needs_to_be_admin;
&header_out;
&do_show_edit_page($in{'db_pid'});
exit(0);
END
}
sub edit_page{
eval << 'END';
require 'ads.pl';
require 'pages.pl';
&needs_to_be_admin;
&header_out;
my($redir)=&do_edit_page(\%in);
if(-e $base_dir.$rdir){
redirect($base_url.$redir);
}
else{
error_exit("Can't find page: $redir",$home_link);
}
exit(0);
END
}
sub list_emails{
&needs_to_be_admin;
&header_out;
my(@emails)=get_records($all_emails_fields,"emails","db_eid is not null order by db_email");
my(%tok);
foreach $i (0..$#emails){
$tok{'EMAILS'}.=$emails[$i]{'db_email'}."\n";
}
$tok{'NUM'}=($#emails+1);
print replace_tokens_f($data_dir."lg_list_emails.htm",%tok);
exit(0);
}
sub edit_emails{
eval << 'END';
&needs_to_be_admin;
&header_out;
$in{'db_emails'} =~ s/\r+/\n/g;
$in{'db_emails'} =~ s/\n+/\n/g;
$in{'db_emails'} =~ tr/A-Z/a-z/;
$in{'db_emails'} =~ s/\,/\n/g;
$in{'db_emails'} =~ s/[^a-z0-9\.\@\-\_\n]//g;
my(@emails)=split(/\n/,$in{'db_emails'});
my($dbh)=&connect_to_db;
do_command("delete from emails",$dbh);
my($rv);
my(@invalid);
foreach (sort(@emails)){
my(%email);
$email{'db_email'}=$_;
if(check_email($email{'db_email'})){
push(@invalid,$email{'db_email'});
}
else{
$rv=add_record_ac($all_emails_fields,"emails",qq(db_email="$email{'db_email'}"),$dbh,%email);
$count++ unless($rv);
}
}
disconnect_from_db($dbh);
my($mess)="EMail List updated with $count E-Mail address".($count == 1 ? "":"es");
if($#invalid > -1){
$mess.="
The following ".($#invalid+1);
$mess.=" ".($#invalid == 0 ? "address was ":"addresses were ");
$mess.=" found to be invlaid:-
".join("
",@invalid); $mess.="