2003-07-25 20:28:35 +00:00
< ? php
require_once ( 'forum.inc' );
2003-08-13 22:08:59 +00:00
require_once ( '../util.inc' );
2003-07-25 20:28:35 +00:00
function subscribe ( $thread , $user = null ) {
if ( ! $thread ) {
2003-07-26 00:20:44 +00:00
show_result_page ( " subscribe " , false , NULL );
2003-07-25 20:28:35 +00:00
exit ();
}
if ( ! $user ) {
2003-07-26 00:20:44 +00:00
$user = get_logged_in_user ( true , '../' );
2003-07-25 20:28:35 +00:00
}
2003-07-26 00:20:44 +00:00
$sql = " SELECT * FROM subscriptions WHERE (userid = " . $user -> id . " ) AND (threadid = " . $thread -> id . " ) " ;
2003-08-13 22:08:59 +00:00
$result = mysql_query ( $sql );
2003-07-26 00:20:44 +00:00
// If they're already subscribed, don't add them again;
2003-08-13 22:08:59 +00:00
if ( mysql_num_rows ( $result ) > 0 ) {
2003-07-26 00:20:44 +00:00
// TODO: Specific "error" page for this case.
show_result_page ( " subscribe " , true , $thread );
2003-08-14 00:56:05 +00:00
exit ();
2003-07-26 00:20:44 +00:00
}
2003-07-25 20:28:35 +00:00
$sql = " INSERT INTO subscriptions SET userid = " . $user -> id . " , threadid = " . $thread -> id ;
2003-08-13 22:08:59 +00:00
show_result_page ( " subscribe " , ( mysql_query ( $sql ) != null ), $thread );
2003-07-26 00:20:44 +00:00
}
function unsubscribe ( $thread , $user = null ) {
if ( ! $thread ) {
show_result_page ( " unsubscribe " , false , NULL );
exit ();
}
if ( ! $user ) {
$user = get_logged_in_user ( true , '../' );
}
$sql = " DELETE FROM subscriptions WHERE (userid = " . $user -> id . " ) AND (threadid = " . $thread -> id . " ) " ;
2003-08-13 22:08:59 +00:00
show_result_page ( " unsubscribe " , ( mysql_query ( $sql ) != null ), $thread );
2003-07-26 00:20:44 +00:00
2003-07-25 20:28:35 +00:00
}
2003-07-26 00:20:44 +00:00
function show_result_page ( $action , $success , $thread ) {
if ( $action == " subscribe " && $success ) {
2003-08-15 01:01:00 +00:00
page_head ( " Subscription Successful " );
2003-07-25 20:28:35 +00:00
echo " <span class= \" title \" >Subscription successful</span> " ;
2003-08-01 20:28:58 +00:00
echo " <p>You are now subscribed to <b> " , stripslashes ( $thread -> title ), " </b>. You will receive an email whenever another user posts to this thread.</p> " ;
2003-07-26 00:20:44 +00:00
} else if ( $action == " unsubscribe " && $success ) {
2003-08-15 01:01:00 +00:00
page_head ( " Unsubscription Successful " );
2003-07-26 00:20:44 +00:00
echo " <span class= \" title \" >Unsubscription successful</span> " ;
2003-08-01 20:28:58 +00:00
echo " <p>You have successfully unsubscribed from <b> " , stripslashes ( $thread -> title ), " </b>. You will no longer receive emails for posts to this thread.</p> " ;
2003-07-26 00:20:44 +00:00
} else if ( $action == " subscribe " && ! $success ) {
2003-08-15 01:01:00 +00:00
page_head ( " Subscription Failed " );
2003-07-25 20:28:35 +00:00
echo " <span class= \" title \" >Subscription failed</span> " ;
if ( $thread ) {
2003-08-01 20:28:58 +00:00
echo " <p>There was a problem subscribing you to " , stripslashes ( $thread -> title ), " . Please try again later.</p> " ;
2003-07-25 20:28:35 +00:00
} else {
echo " <p>The thread you tried to subscribe to does not exist.</p> " ;
}
2003-07-26 00:20:44 +00:00
} else if ( $action == " unsubscribe " && ! $success ) {
2003-08-15 01:01:00 +00:00
page_head ( " Unsubscription Failed " );
2003-07-26 00:20:44 +00:00
echo " <span class= \" title \" >Unsubscription failed</span> " ;
if ( $thread ) {
2003-08-01 20:28:58 +00:00
echo " <p>There was a problem unsubscribing you from " , stripslashes ( $thread -> title ), " . Please try again later.</p> " ;
2003-07-26 00:20:44 +00:00
} else {
echo " <p>The thread you tried to unsubscribe from does not exist.</p> " ;
}
} else {
2003-08-15 01:01:00 +00:00
page_head ( " Unknown action " );
2003-07-26 00:20:44 +00:00
echo " <span class= \" title \" >Unknown action</span> " ;
2003-07-30 00:52:14 +00:00
echo " <p>The action you requested is not known</p> " ;
2003-07-25 20:28:35 +00:00
}
2003-07-30 00:52:14 +00:00
echo " <a href= \" thread.php?id= " , $thread -> id , " \" >Return to thread</a> " ;
2003-08-15 01:01:00 +00:00
page_tail ();
2003-07-25 20:28:35 +00:00
}
2003-08-14 00:56:05 +00:00
function notify_subscribers ( $threadID ) {
$sql = " SELECT DISTINCT * FROM subscriptions WHERE threadid = " . $threadID ;
2003-08-13 22:08:59 +00:00
$result = mysql_query ( $sql );
2003-07-25 20:28:35 +00:00
while ( $row = mysql_fetch_assoc ( $result )) {
2003-08-14 00:56:05 +00:00
send_notice_email ( $row [ 'userid' ], $threadID );
2003-07-25 20:28:35 +00:00
}
}
2003-08-14 00:56:05 +00:00
function send_notice_email ( $userId , $threadID ) {
$thread = getThread ( $threadID );
2003-08-13 22:08:59 +00:00
$result = mysql_query ( " SELECT * FROM user WHERE id = $userId " );
2003-07-25 20:28:35 +00:00
$row = mysql_fetch_assoc ( $result );
$title = PROJECT . " : A user has posted to your subscribed thread. " ;
2003-08-14 00:56:05 +00:00
$link = URL_BASE . " forum/thread.php?id= " . $threadID ;
2003-08-01 20:28:58 +00:00
$body = " Another " . PROJECT . " user has posted to the thread \" " . stripslashes ( $thread -> title ) . " \" . \n "
2003-07-26 00:20:44 +00:00
. " To view the updated thread, direct your web browser to the following URL: \n \n $link " ;
2003-07-25 20:28:35 +00:00
mail ( $row [ 'email_addr' ], $title , $body );
}
?>