<?php
//index.php
define('FORUM_ROOT', '/var/www/nginx-default/punbb/');
require FORUM_ROOT . 'include/common.php';
#Full URL to current event
$forum_page['redirect_url'] = "/nibbleblog/test2/";
$forum_page['form_action'] = forum_link($forum_url['login']);
$forum_page['hidden_fields'] = array(
'form_sent' => '<input type="hidden" name="form_sent" value="1" />',
'redirect_url' => '<input type="hidden" name="redirect_url" value="'.forum_htmlencode($forum_page['redirect_url']).'" />',
'csrf_token' => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
);
if(!$forum_user['is_guest']) {
$link = sprintf('<a href="%s&redirect_url=%s">%s</a><p>',forum_link($forum_url['logout'], array($forum_user['id'], generate_form_token('logout'.$forum_user['id']))),$forum_page['redirect_url'],$lang_common['Logout']);
print $link;
//Check SQLite to display subscribed users, and button: Subscribe or Unsubscribe
try
{
$dbh = new PDO('sqlite:events.sqlite');
//TEMP : TO REMOVE ONCE ISSUE SOLVED!
$var_url['idpost'] = 7;
//TEMP : TO REMOVE ONCE ISSUE SOLVED!
//Check if current user is subscribed or not -> display Subscribe or Unsubscribe
$sql = sprintf("SELECT COUNT(id) FROM subscription WHERE event=%s AND username='%s'",$var_url['idpost'],$forum_user['username']);
$subscribed = $dbh->query($sql)->fetchColumn();
//Choose button value depending on subscribed/unsubscribed
if($subscribed) {
$value = "Unsubscribe";
} else {
$value = "Subscribe";
}
?>
<form method="post" action="action.php">
<input type="hidden" name="event" value="<?php echo $var_url['idpost']; ?>" />
<input type="submit" name="subscribe" value="<?php echo $value; ?>" />
</form>
<?php
$dbh = null;
} catch(PDOException $e) {
echo $e->getMessage();
}
} else {
?>
Authentication required<p>
<form method="post" action="<?php echo $forum_page['form_action'] ?>">
<?php echo implode("\n\t\t", $forum_page['hidden_fields'])."\n" ?>
User: <input type="text" id="fld1" name="req_username" value="" /> <br />
Password: <input type="password" id="fld2" name="req_password" value="" /> <br />
<input type="submit" name="login" id="login" value="Login" />
</form>
<?php
}
?>