add.php 1.69 KB
Newer Older
1
<!-- /* Copyright (c) 2011, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. */ -->
David Morley's avatar
David Morley committed
2 3
<?php
 include('config.php');
4 5 6 7 8 9 10 11 12 13 14 15 16
if (!$_POST['url']){
  echo "no url given";
 die;
}
if (!$_POST['email']){
  echo "no email given";
 die;
}
if (!$_POST['domain']){
  echo "no pod domain given";
 die;
}

David Morley's avatar
David Morley committed
17 18 19 20
 $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
     if (!$dbh) {
         die("Error in connection: " . pg_last_error());
     }
21 22 23 24 25 26 27 28 29 30 31 32 33 34
 $sql = "SELECT domain,pingdomurl FROM pods";
 $result = pg_query($dbh, $sql);
 if (!$result) {
     die("Error in SQL query: " . pg_last_error());
 }
 while ($row = pg_fetch_array($result)) {
if ($row["domain"] == $_POST['domain']) {
echo "domain already exists";die;
}
if ($row["pingdomurl"] == $_POST['url']) {
echo "pingdom report already exists";die;
}
 }

David Morley's avatar
David Morley committed
35
    
36
     $pingdomurl = pg_escape_string($_POST['url']);
David Morley's avatar
David Morley committed
37 38 39
     $domain = pg_escape_string($_POST['domain']);
     $email = pg_escape_string($_POST['email']);
    
40
     $sql = "INSERT INTO pods (domain, pingdomurl, email) VALUES('$domain', '$pingdomurl', '$email')";
David Morley's avatar
David Morley committed
41 42 43 44
     $result = pg_query($dbh, $sql);
     if (!$result) {
         die("Error in SQL query: " . pg_last_error());
     }
45 46 47 48 49 50
     $to = $adminemail;
     $subject = "New pod added to poduptime ";
     $message = "http://podupti.me\n\n Pingdom Url:" . $_POST["url"] . "\n\n Pod:" . $_POST["domain"] . "\n\n";
     $headers = "From: ".$_POST["email"]."\r\nReply-To: ".$_POST["email"]."\r\n";
     @mail( $to, $subject, $message, $headers );    

51
     echo "Data successfully inserted! Your pod will be reviewed and live on the list soon!";
David Morley's avatar
David Morley committed
52 53 54 55 56 57
    
     pg_free_result($result);
    
     pg_close($dbh);

?>