Trying to work out some code...

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
Without_Boundaries
Registered User
Posts: 75
Joined: Sat Jul 20, 2002 6:35 pm
Location: England
Contact:

Trying to work out some code...

Post by Without_Boundaries »

Just a brief explanation before I show the code:
The MOD I'm trying to create will be a page where users can download rewards (such as wallpapers or avatars) once they have the required amount of posts. I'm not too sure on how to set the arrays correctly though, but here's the code I've got so far:

Code: Select all

<?php
/***************************************************************************
 *                               claim.php
 *                            -------------------
 *   begin                : Monday, Jan 05, 2004
 *   copyright            : (C) 2003 Bob
 *   email                : bob@subtle-edge.com
 *
 *   $Id: claim.php,v 1.0.0.0 2004/01/05 01:20:53 Bob $
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   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 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

$rewards_list = "";

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//



$template->set_filenames(array(
	'body' => 'memberlist_body.tpl')
);

// Login check
if ( !$userdata['session_logged_in'] )
{
	redirect(append_sid("login.$phpEx?redirect=claim.$phpEx", true));
}

// Who are they?
$view_user_id = ANONYMOUS;
if ( isset($HTTP_POST_VARS[POST_USERS_URL]) || isset($HTTP_GET_VARS[POST_USERS_URL]) )
{
	$view_user_id = isset($HTTP_POST_VARS[POST_USERS_URL]) ? intval($HTTP_POST_VARS[POST_USERS_URL]) : intval($HTTP_GET_VARS[POST_USERS_URL]);
}
if ($view_user_id==ANONYMOUS) $view_user_id = $userdata['user_id'];

// We know where their data lives...
$sql = "SELECT * FROM " . USERS_TABLE . " WHERE user_id=$view_user_id";
if(!$result = $db->sql_query($sql))
{
	message_die(GENERAL_ERROR, 'Couldn\'t obtain user information.', '', __LINE__, __FILE__, $sql);
}
if (!$user_row = $db->sql_fetchrow($result) )
{
	message_die(GENERAL_ERROR, $lang['No_such_user']);
}

$template->assign_vars(array(
  'L_REQUIREDPOSTS' => $lang['Req_Posts'],
  'L_DOWNLOAD_YES' => $lang['Download_Yes'],
  'L_DOWNLOAD_NO' => $lang['Download_No']));

// Now we want to find the claims they can get
$sql = "SELECT * FROM " . CLAIMS_TABLE . "";
if(!$result = $db->sql_query($sql))
{
	message_die(GENERAL_ERROR, 'Couldn\'t obtain claim information.', '', __LINE__, __FILE__, $sql);
}
else{
    while( $row = $db->sql_fetchrow($result) )
	{ if($row['claim_req'] <= $userdata['user_posts']){
        $rewards_list .= "<b>" . $row['claim_name'] . "</b><br />" . L_REQUIREDPOSTS . ": <font color='green'>" . $row['claim_req'] . "</font>
                         <br /><a href='" . $row['claim_file'] . "'>" . L_DOWNLOAD_YES . "</a><br /><br />";
      }
      else{
         $rewards_list .= "<b>" . $row['claim_name'] . "</b><br />" . L_REQUIREDPOSTS . ": <font color='red'>" . $row['claim_req'] . "</font>
                         <br />" . L_DOWNLOAD_NO . "<br /><br />";
      }
   }
}
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
$template->assign_vars(array(
  'REWARDS_LIST' => $rewards_list
  ));

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
?>
It should select the current user, then select all the rewards. Then, in the while loop, it check whether the user has enough posts or not, and adds it to the variable $rewards_list.

Could someone have a quick look to check it is correct for me? :)
Also, this is like an ALPHA bit of code - so no fancy looking output just yet ;)

I figured out what I want to do - I want it like the memberlist, so it performs a loop for each member. Would anyone like to show me how to do this for what I want? I'm not too experienced the phpBB code. :roll:
Post Reply

Return to “[2.0.x] MOD Writers Discussion”