summaryrefslogtreecommitdiff
path: root/web/remsaint-subscription.php
diff options
context:
space:
mode:
Diffstat (limited to 'web/remsaint-subscription.php')
-rw-r--r--web/remsaint-subscription.php126
1 files changed, 126 insertions, 0 deletions
diff --git a/web/remsaint-subscription.php b/web/remsaint-subscription.php
new file mode 100644
index 0000000..0c7bfb5
--- /dev/null
+++ b/web/remsaint-subscription.php
@@ -0,0 +1,126 @@
+<?
+/* RemSaint
+ *
+ * (c) 2002 Peter Palfrader <pp@3node.com>
+ */
+
+/**
+ * RemSaint
+ *
+ * @author Peter Palfrader/3node
+ * @version $Id$
+ */
+
+require_once("../include/Namespace.inc");
+require_once("../include/Tools.inc");
+require_once("../include/Template.inc");
+
+$namespace = new Namespace(
+ array( have_database => 1,
+ have_session => 1,
+ have_user => 1 )
+) or
+ die("Nobody loves me. I don't even have space for a name.");
+
+$message = '';
+$username = '';
+
+if (! $namespace->user->check_login()) {
+ $message = 'Not logged in. Nothing done.';
+} else {
+ $username = $namespace->session->data['user']['username'];
+ $rules = Array();
+ $rules['subscription']['ref'] = array(type => 'anything');
+ $refs = param_check($GLOBALS, $rules);
+
+ $rules = Array();
+ foreach ($refs['ref'] as $ref) {
+ if (! is_int($ref + 0) ) {
+ $message = 'Wrong refs';
+ break;
+ } else {
+ $rules['subscription']['warning_'.$ref] = array(type => 'boolean');
+ $rules['subscription']['critical_'.$ref] = array(type => 'boolean');
+ $rules['subscription']['recovery_'.$ref] = array(type => 'boolean');
+ };
+ };
+ if ($message == '') {
+ $arguments = param_check($GLOBALS, $rules);
+ $user_ref = $namespace->session->data['user']['ref'];
+
+ foreach ($refs['ref'] as $ref) {
+ if ($arguments['warning_'.$ref] ||
+ $arguments['critical_'.$ref] ||
+ $arguments['recovery_'.$ref])
+ $user_subs[$ref] = array (
+ notify_warning => $arguments['warning_'.$ref],
+ notify_critical => $arguments['critical_'.$ref],
+ notify_recovery => $arguments['recovery_'.$ref],
+ );
+ }
+ $db_subs = $namespace->database->query_all("SELECT remailer.nick, subscription.ref, subscription.remailer_ref, subscription.notify_warning, subscription.notify_critical, subscription.notify_recovery FROM remailer JOIN subscription ON remailer.ref=subscription.remailer_ref WHERE subscription.account_ref=?", array($user_ref));
+ foreach ($db_subs as $sub) {
+ if (isset ($user_subs[$sub['remailer_ref']])) {
+ $user_sub = $user_subs[$sub['remailer_ref']];
+ $sub['notify_warning'] = $sub['notify_warning'] == 't' ? 1 : false;
+ $sub['notify_critical'] = $sub['notify_critical'] == 't' ? 1 : false;
+ $sub['notify_recovery'] = $sub['notify_recovery'] == 't' ? 1 : false;
+ if (($sub['notify_warning'] == $user_sub['notify_warning']) &&
+ ($sub['notify_critical'] == $user_sub['notify_critical']) &&
+ ($sub['notify_recovery'] == $user_sub['notify_recovery'])) {
+ $message .= 'Not changing subscription to remailer '.$sub['nick'].".<BR>\n";
+ } else {
+ $user = ($user_sub['notify_warning'] ? 'W' : '_') .
+ ($user_sub['notify_critical'] ? 'C' : '_') .
+ ($user_sub['notify_recovery'] ? 'R' : '_');
+ $db = ($sub['notify_warning'] ? 'W' : '_') .
+ ($sub['notify_critical'] ? 'C' : '_') .
+ ($sub['notify_recovery'] ? 'R' : '_');
+ $message .= 'Changing subscription to remailer '.$sub['nick']." from $db to $user: ";
+ $s = array();
+ $s['notify_warning'] = $user_sub['notify_warning'] ? 'T' : 'F';
+ $s['notify_critical'] = $user_sub['notify_critical'] ? 'T' : 'F';
+ $s['notify_recovery'] = $user_sub['notify_recovery'] ? 'T' : 'F';
+ $res = $namespace->database->update('subscription', $sub['ref'], $s);
+ $message .= ($res ? 'OK' : 'FAILED')."<BR>\n";
+ }
+ } else {
+ $message .= 'Deleting subscription to remailer '.$sub['nick'].': ';
+ $res = $namespace->database->delete_row('subscription', $sub['ref']);
+ $message .= ($res ? 'OK' : 'FAILED')."<BR>\n";
+ };
+ unset($user_subs[$sub['remailer_ref']]);
+ }
+ foreach ($user_subs as $ref => $sub) {
+ $rem = $namespace->database->query_row("SELECT remailer.nick FROM remailer WHERE ref=?", array($ref));
+ if ($rem) {
+ $s = array();
+ $s['remailer_ref'] = $ref;
+ $s['account_ref'] = $user_ref;
+ $s['notify_warning'] = $sub['notify_warning'] ? 'T' : 'F';
+ $s['notify_critical'] = $sub['notify_critical'] ? 'T' : 'F';
+ $s['notify_recovery'] = $sub['notify_recovery'] ? 'T' : 'F';
+ $message .= 'Adding subscription to remailer '.$rem['nick'].': ';
+ $res = $namespace->database->insert('subscription', $s);
+ $message .= ($res ? 'OK' : 'FAILED')."<BR>\n";
+ } else {
+ $message .= 'Remailer '.$rem."does not exist.<BR>\n";
+ }
+ }
+ $message .= 'done.<BR>';
+ }
+}
+
+$data = array();
+$data['message'] = $message;
+$data['user'] = $username;
+
+$template = new Template('remsaint-subscription.html', $namespace->config->template_path);
+$template->parse($data);
+print $template->output();
+
+$namespace->stop();
+
+# vim:set ts=4:
+# vim:set shiftwidth=4:
+?>