saverating.php 1.4 KB
Newer Older
root's avatar
root committed
1
<?php
2

noplanman's avatar
noplanman committed
3 4
use RedBeanPHP\R;

5 6 7 8 9 10 11 12 13
// Required parameters.
($_username = $_POST['username'] ?? null) || die('no username given');
($_userurl = $_POST['userurl'] ?? null) || die('no userurl given');
($_domain = $_POST['domain'] ?? null) || die('no pod domain given');
($_comment = $_POST['comment'] ?? null) || die('no comment');
($_rating = $_POST['rating'] ?? null) || die('no rating given');

// Other parameters.
$_email = $_POST['email'] ?? '';
14

noplanman's avatar
noplanman committed
15
require_once __DIR__ . '/../vendor/autoload.php';
16 17
require_once __DIR__ . '/../config.php';

noplanman's avatar
noplanman committed
18 19 20 21 22
define('PODUPTIME', microtime(true));

// Set up global DB connection.
R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true);
R::testConnection() || die('Error in DB connection');
dmorley's avatar
dmorley committed
23
R::usePartialBeans(true);
noplanman's avatar
noplanman committed
24 25 26 27 28 29 30 31 32 33 34 35

try {
  $r             = R::dispense('rating_comments');
  $r['domain']   = $_domain;
  $r['comment']  = $_comment;
  $r['rating']   = $_rating;
  $r['username'] = $_username;
  $r['userurl']  = $_userurl;
  R::store($r);
} catch (\RedBeanPHP\RedException $e) {
  die('Error in SQL query: ' . $e->getMessage());
}
36

37
$to      = $adminemail;
38
$headers = ['From: ' . $_email];
39
$subject = 'New rating added to poduptime ';
40 41 42 43 44 45 46 47 48 49

$message_lines = [
  'Pod: ' . $_domain,
  'Username: ' . $_username,
  'User URL: ' . $_userurl,
  'Comment: ' . $_comment,
  'Rating:' . $_rating,
];

@mail($to, $subject, implode("\r\n", $message_lines), implode("\r\n", $headers));
50
echo 'Comment posted!';