Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Aug 2nd, 2010 | Syntax: PHP | Size: 2.39 KB | Hits: 290 | Expires: Never
Copy text to clipboard
  1. <?php
  2.         //index.php
  3.  
  4.         define('FORUM_ROOT', '/var/www/nginx-default/punbb/');
  5.         require FORUM_ROOT . 'include/common.php';
  6.  
  7.         #Full URL to current event
  8.         $forum_page['redirect_url'] = "/nibbleblog/test2/";
  9.         $forum_page['form_action'] = forum_link($forum_url['login']);
  10.         $forum_page['hidden_fields'] = array(
  11.                 'form_sent'     => '<input type="hidden" name="form_sent" value="1" />',
  12.                 'redirect_url'  => '<input type="hidden" name="redirect_url" value="'.forum_htmlencode($forum_page['redirect_url']).'" />',
  13.                 'csrf_token'    => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
  14.         );
  15.  
  16.         if(!$forum_user['is_guest']) {
  17.         $link = sprintf('<a href="%s&amp;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']);
  18.     print $link;
  19.  
  20.                 //Check SQLite to display subscribed users, and button: Subscribe or Unsubscribe
  21.                 try
  22.                 {
  23.                 $dbh = new PDO('sqlite:events.sqlite');
  24.  
  25.                         //TEMP : TO REMOVE ONCE ISSUE SOLVED!
  26.                         $var_url['idpost'] = 7;
  27.                         //TEMP : TO REMOVE ONCE ISSUE SOLVED!
  28.  
  29.                         //Check if current user is subscribed or not -> display Subscribe or Unsubscribe
  30.                 $sql = sprintf("SELECT COUNT(id) FROM subscription WHERE event=%s AND username='%s'",$var_url['idpost'],$forum_user['username']);
  31.                         $subscribed = $dbh->query($sql)->fetchColumn();
  32.                         //Choose button value depending on subscribed/unsubscribed
  33.                         if($subscribed) {
  34.                                 $value = "Unsubscribe";
  35.                         } else {
  36.                                 $value = "Subscribe";
  37.                         }
  38.                         ?>
  39.         <form method="post" action="action.php">
  40.                 <input type="hidden" name="event" value="<?php echo $var_url['idpost']; ?>" />
  41.                 <input type="submit" name="subscribe" value="<?php echo $value; ?>" />
  42.                                 </form>
  43.                         <?php
  44.  
  45.                         $dbh = null;
  46.                 } catch(PDOException $e) {
  47.                         echo $e->getMessage();
  48.         }
  49.  
  50.         } else {
  51.                 ?>
  52.                 Authentication required<p>
  53.                
  54.     <form method="post" action="<?php echo $forum_page['form_action'] ?>">
  55.                 <?php echo implode("\n\t\t", $forum_page['hidden_fields'])."\n" ?>
  56.  
  57.                 User: <input type="text" id="fld1" name="req_username" value="" /> <br />
  58.  
  59.                 Password: <input type="password" id="fld2" name="req_password" value="" /> <br />
  60.  
  61.             <input type="submit" name="login" id="login" value="Login" />
  62.                  </form>
  63.                 <?php
  64.         }
  65. ?>