#!/usr/bin/perl -- # Libs use lib '/home/users/zoekenen/www/inloggen/pm'; use CGI; use Dbase; use Html; use Email; # Vars my $q = new CGI; my %vars = $q->Vars; my $HTML = Html->new( script => "./index.cgi", cgi => $q, ); my $self = $HTML->{'script'}; # Dbase Init my $dbase = Dbase::ConnectDbase; ## Login if(!($vars{'em'} && $vars{'session'} )){ if(!($vars{'em'} && $vars{'password'})) { Login(); exit; } else { my $return = Dbase::CheckLogin($vars{'em'},$vars{'password'}); if($return eq "NOTOK") { Login("Login incorrect, please try again"); exit; } else { my $user_id = Dbase::UserId($vars{'em'}, $return); ReloadPage($vars{'em'}, $return, $user_id); } # Process login } } else { my $return = Dbase::CheckSession($vars{'em'}, $vars{'session'}, $vars{'id'}); if($return eq "NOTOK") { Login("Geen grapjes he jongetjes, gewoon netjes inloggen"); exit; } } if($vars{'action'} =~ /edit/) { EditCompany(); } elsif($vars{'action'} =~ /new/) { AddCompany(); } elsif($vars{'action'} =~ /delete/) { Email::DelCompany($vars{'comid'}); Dbase::DelCompanyWithUser($vars{'comid'}); ShowResults(); } elsif($vars{'submit_edit'}) { InsertCompany(%vars); ShowResults(); } elsif($vars{'submit_new'}) { InsertCompany(%vars); ShowResults(); } elsif($vars{'new_account'}) { InsertAccount(%vars); NewAccount(); } else { ShowResults(); } sub ShowResults { $HTML->StartHtml(%vars); ShowCompanies(); END: $HTML->EndHtml( back => 1); } sub ReloadPage { my $email = shift; my $session = shift; my $id = shift; $HTML->StartHtml(); print "" } sub NewAccount { $HTML->StartHtml(); print "" } sub Login { my $error = shift; $HTML->StartHtml(%vars,"1","1"); if($error) { print "$error"; } print '
Email
Password

Bent u uw wachtwoord kwijt of vergeten?
Stuur ons een email met uw naam en email adres.
'; END: $HTML->EndHtml( back => 1); } sub ShowCompanies { print '
'; #print "SOMETEXT: $vars{'id'}
"; my @companies = Dbase::GetCompaniesFromUser($vars{'id'}); foreach my $com (@companies) { PrintCompany($com); } print '
Navigatie:

'; print "Nieuw Bedrijf
"; print "Uitloggen
"; print ' 
'; } sub AddCompany { $HTML->StartHtml(%vars); # Form header print "
\n"; print ""; # com_id cat_id name adress postal city country descr photo url email fax # contact_email contact_tel # Company information print "\n"; print ''; GenInput('text','name','Bedrijfsnaam','75'); GenInput('text','adress','Adres','75'); GenInput('text','postal code','Postcode','10'); GenInput('text','city','Stad','15'); GenInput('text','country','Landcode (NL/BE)','50'); GenArea('descr','Omschrijving','60','7'); GenInput('text','url','Website URL','75'); GenInput('text','email','Algemeen email','75'); GenInput('text','fax','Fax nummer','15'); GenInput('text','tel','Telefoon nummer','15'); ## Generate Catagory fields print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; ## Feature's print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; # Contact information print ''; GenInput('text','contact_name','Contact naam','75'); GenInput('text','contact_email','Contact email','75'); GenInput('text','contact_tel','Contact telefoonnummer','15'); if($vars{'approved'}) { print ""; } print ""; print ""; print ""; print ""; print ""; print ""; print ' '; $HTML->EndHtml(back => 1); } sub Show { print "SHOW"; } sub ErrorPrint { my $text = shift; print '
Bedrijfs informatie  
   
Catagorie ( zoeken )   "; print ""; print "
Catagorie ( zoeken )   "; print ""; print "
Catagorie ( zoeken )   "; print ""; print "
Catagorie ( zoeken )   "; print ""; print "
Catagorie ( zoeken )   "; print ""; print "


Notering

   "; print "Wanneer u kiest voor een rechterkant notering zal er contact met u opgenomen worden omtrent de zoektermen
"; print "
   "; print "
Notering   "; print ""; print "


   Communicatie omtrent de inschrijving van dit bedrijf zal geschieden met onderstaande contact persoon.  
   
"; print '
'; print "Fout
'; print "$text"; print '

'; } sub PrintCompany { my $com = shift; my %company = Dbase::SingleCompany($com); print '"; print "

' . $company{$com}{'name'} . '  ( ' . "Wijzig | Verwijder ) " . '
'; print $company{$com}{'descr'}; print '
 
Adres:
'; print $company{$com}{'name'} . "
"; print $company{$com}{'adress'} . "
"; print $company{$com}{'postal'} . " " . $company{$com}{'city'} . "
"; print '
Tel: ' . $company{$com}{'tel'} . "
"; print 'Fax: ' . $company{$com}{'fax'} . "
"; $company{$com}{'email'} =~ s/\@/_at_/g; print 'E-mail: ' . $company{$com}{'email'} . "
"; print 'Url:: ' . $company{$com}{'url'} . "

Dit bedrijf is ingedeeld in de catagorieën:
"; for($i=1;$i<6;$i++) { if($company{$com}{"cat_id$i"}) { my %catagory = Dbase::SingleCatagoryCode($company{$com}{"cat_id$i"}); print "- $catagory{'name'}
"; } } print "

"; print $company{$com}{'url'} . "-Bezoek de website
"; print '

'; } sub EditCompany { $HTML->StartHtml(%vars); my $number = Dbase::CheckCompany($vars{'comid'}, $vars{'id'}); if($number != 1) { return 0; } #print "AAA: $vars{'comid'}"; my %companies = Dbase::GetSingleCompany($vars{'comid'}); my $cat1 = $companies{'cat_id1'}; my $cat2 = $companies{'cat_id2'}; my $cat3 = $companies{'cat_id3'}; my $cat4 = $companies{'cat_id4'}; my $cat5 = $companies{'cat_id5'}; #print "CATAOGIRES: $cat1, $cat2, $cat3, $cat4, $cat5"; my @features = Dbase::GetFeatures($vars{'comid'},$dbase); my $feat1 = @features[0]; my $feat2 = @features[1]; # Form header print "
\n"; print ""; print ""; # com_id cat_id name adress postal city country descr photo url email fax tel contact_name # contact_email contact_tel # Company information print "\n"; print ''; print ""; GenInput('text','name','Bedrijfsnaam','75',"$companies{'name'}"); GenInput('text','adress','Adres','75',"$companies{'adress'}"); GenInput('text','postal','Postcode','10',"$companies{'postal'}"); GenInput('text','city','Stad','15',"$companies{'city'}"); GenInput('text','country','Landcode (NL/BE)','50',"$companies{'country'}"); GenArea('descr','Omschrijving','60','7',"$companies{'descr'}"); GenInput('text','url','Website URL','75',"$companies{'url'}"); GenInput('text','email','Algemeen email','75',"$companies{'email'}"); GenInput('text','fax','Fax nummer','15',"$companies{'fax'}"); GenInput('text','tel','Telefoon nummer','15',"$companies{'tel'}"); ## Generate Catagory fields print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; ## Feature's print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; # Contact information print ''; GenInput('text','contact_name','Contact naam','75',"$companies{'contact_name'}"); GenInput('text','contact_email','Contact email','75',"$companies{'contact_email'}"); GenInput('text','contact_tel','Contact telefoon nummer','15',"$companies{'contact_tel'}"); if($vars{'approved'}) { print ""; } print ""; print ""; print ' '; print "
Bedrijfs informatie  
   
Catagorie ( zoeken )   "; print ""; print "
Catagorie ( zoeken )   "; print ""; print "
Catagorie ( zoeken )   "; print ""; print "
Catagorie ( zoeken )   "; print ""; print "
Catagorie ( zoeken )   "; print ""; print "
Notering   "; print ""; print "
Notering   "; print ""; print "


Contact informatie
 
"; $HTML->EndHtml( back => 1); } sub GenInput { my ($type,$name,$descr,$size,$value) = @_; print ""; print "$descr"; print "   "; print ""; print ""; } sub GenArea { my ($name,$descr,$size,$size2,$value) = @_; print ""; print "$descr"; print "   "; } else { print ">"; } } sub InsertAccount { my %newhash = %vars; if("$newhash{'password'}" == "$newhash{'password2'}") { $statement = 'INSERT INTO users VALUES (NULL, 1, ' . "\"$newhash{'email'}\"," . "\"$newhash{'name'}\"," . "\"$newhash{'password'}\"" . ')'; $prep = $dbase->prepare($statement) or die "Couldn't prepare statement: $DBI::errstr; stopped"; $prep->execute() or die "Couldn't execute statement: $DBI::errstr; stopped"; } } sub InsertCompany { my %newhash = %vars; if($vars{'submit_new'}) { ## Check for HTML foreach my $key ( keys %newhash ) { if($newhash{$key} =~ /<(.|\n)*?>/) { return 0; } } $statement = 'INSERT INTO companies values (NULL, ' . "\"$newhash{'name'}\"," . "\"$newhash{'adress'}\"," . "\"$newhash{'postal'}\"," . "\"$newhash{'city'}\"," . "\"$newhash{'country'}\"," . "\"$newhash{'descr'}\"," . "\"$newhash{'photo'}\"," . "\"$newhash{'url'}\"," . "\"$newhash{'email'}\"," . "\"$newhash{'fax'}\"," . "\"$newhash{'tel'}\"," . "\"$newhash{'contact_name'}\"," . "\"$newhash{'contact_email'}\"," . "\"$newhash{'contact_tel'}\"," . '"' . time . '",' . '0, ' . "\"$newhash{'cat1'}\"," . "\"$newhash{'cat2'}\"," . "\"$newhash{'cat3'}\"," . "\"$newhash{'cat4'}\"," . "\"$newhash{'cat5'}\"" . ')'; $prep = $dbase->prepare($statement); $prep->execute(); } else { my $number = Dbase::CheckCompany($vars{'com_id'}, $vars{'id'}); if($number != 1) { return 0; } $statement = 'UPDATE companies SET ' . "name = \"$newhash{'name'}\"," . "adress = \"$newhash{'adress'}\"," . "postal = \"$newhash{'postal'}\"," . "city = \"$newhash{'city'}\"," . "country = \"$newhash{'country'}\"," . "descr = \"$newhash{'descr'}\"," . "photo = \"$newhash{'photo'}\"," . "url = \"$newhash{'url'}\"," . "email = \"$newhash{'email'}\"," . "fax = \"$newhash{'fax'}\"," . "tel = \"$newhash{'tel'}\"," . "contact_name = \"$newhash{'contact_name'}\"," . "contact_email = \"$newhash{'contact_email'}\"," . "contact_tel = \"$newhash{'contact_tel'}\"," . "cat_id1 = \"$newhash{'cat1'}\"," . "cat_id2 = \"$newhash{'cat2'}\"," . "cat_id3 = \"$newhash{'cat3'}\"," . "cat_id4 = \"$newhash{'cat4'}\"," . "cat_id5 = \"$newhash{'cat5'}\"," . "lastchange = \"" . time . "\" WHERE com_id = \"$vars{'com_id'}\""; $prep = $dbase->prepare($statement); $prep->execute(); } # Ok, this is quick and DIRTY way to get this information, but at this time # i got no clue what to do .. my $com_id; my $statement = "SELECT com_id FROM companies WHERE name = \"$newhash{'name'}\" AND contact_email = \"$newhash{'contact_email'}\""; $prep = $dbase->prepare($statement); $prep->execute(); while(my $ref = $prep->fetchrow_hashref()) { $com_id = $ref->{'com_id'}; } # If we edit a company we need to delete all features from this company first if(!$vars{'submit_new'}) { my $statement = "DELETE FROM feat_con WHERE com_id = $com_id"; my $prep = $dbase->prepare($statement); $prep->execute(); } for(my $i=1;$i<3;$i++) { if($newhash{"feat$i"}) { Dbase::AddFeature("$com_id","$newhash{\"feat$i\"}",$dbase); } } if($vars{'submit_new'}) { Dbase::CompanyWithUser($vars{'id'}, $com_id); } #Send email Email::AddCompany($com_id); }