po/src/subscription.add.php

110 lines
3.6 KiB
PHP

<?php
// Copyright (C) 2002-2006 Balint Kis (balint@k-i-s.net)
// Copyright (C) 2005-2013 Solomon Peachy (pizza@shaftnet.org)
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
include_once "include/config.php";
include_once "include/common.php";
include_once "include/site.php";
include_once "include/mail.php";
$database = site_prolog(PO_USER_TYPE_CLIENT);
$user_id = pg_escape_string($database, $_REQUEST['user']);
if ($user_id == ""){
site_referer_error('no_user');
site_epilog($database);
exit();
}
/* Are we kicking off the add? */
if (isset($_REQUEST['go'])) {
$type = $_REQUEST['type'];
if ($type == "sub") {
$result = pg_query($database, "insert into client (identifier, users, client, status, trusted)
values (nextval('client_id_sequence'), '$po_user[id]', '$user_id', 2, 't')");
} else {
$result = pg_query($database, "insert into client (identifier, users, client, status, trusted)
values (nextval('client_id_sequence'), '$user_id', '$po_user[id]', 1, 'f')");
if ($result) {
send_new_client_notification($database, $user_id, $po_user['id']);
}
}
if ($result == FALSE) {
site_push_error($strings['errors_db_insert_failed']);
}
if ($type == "sub") {
$referer = generate_link('user', $po_user['id'], array(), TRUE);
} else {
$referer = generate_link('user', $user_id, array(), TRUE);
}
site_epilog($database);
header("Location: $referer");
exit();
}
/* Back to your regularly-scheduled form */
$make_client_request = isset($_REQUEST['make_client']);
if (!$make_client_request) {
$client = pg_fetch_row(pg_query($database, "select identifier from client where users='$user_id' and client='$po_user[id]' and status=2"));
if ($client != "") {
site_referer_error('not_client');
site_epilog($database);
exit();
}
}
site_header($strings['users_add_subscription']);
site_navigator(1);
site_navigator_status(emit_a(generate_link('user', ''), $strings['generic_users'])." : ".$strings['users_add_subscription'], "");
if ($make_client_request) {
print emit_contact_info($database, $user_id);
} else {
print emit_contact_info($database, $po_user['id']);
}
if (!$make_client_request) {
$user_display_string = disp_user_string($database, $user_id);
print "<p>";
print $strings['users_confirm_subscription'] . " $user_display_string.\n";
print "</p>";
}
print "<form method=\"post\" action=\"subscription.add.php\" accept-charset=\"".$strings['formats_encoding']."\">";
print "<input type=\"hidden\" name=\"go\" value=\"go\"/>\n";
if ($make_client_request) {
print "<input type=\"hidden\" name=\"type\" value=\"sub\"/>\n";
}
print "<input type=\"hidden\" name=\"user\" value=\"$user_id\"/>\n";
print "<center>";
print $thm_elem['button.confirm.subscription'];
print $thm_elem['button.cancel'];
print "</form>";
print "</center>";
site_footer($database);
site_epilog($database);
?>