PHP&HTML Script cut in PHP and Template file help

Discussion forum for MOD Writers regarding MOD Development.
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

Ah, now i understand what DBAL is :oops: also a friend explain me so now i understand why i have to use it :)

So i test again with the following but i think something is wrong. Also I changed the usernam and passowrd for the connection to the db

Code: Select all

$sql = 'SELECT b.country, b.created, b.name, b.reason, b.length, b.RemoveType,
								    CAST(MID(b.authid, 9, 1) AS UNSIGNED) + CAST("76561197960265728" AS UNSIGNED) + CAST(MID(b.authid, 11, 10) * 2 AS UNSIGNED) AS community_id, 
								    a.user AS admin_name
	FROM ' . sb_bans . " b
		LEFT JOIN sb_admins a
		ON a.aid = b.aid
	ORDER BY created DESC
	LIMIT 0,30";  
Error Messages

Code: Select all

SQL ERROR [ mysql4 ]

Table 'sourcebans.phpbb_forums' doesn't exist [1146]

SQL

SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id FROM phpbb_forums ORDER BY left_id ASC

BACKTRACE

FILE: [ROOT]/includes/db/mysql.php
LINE: 175
CALL: dbal->sql_error()

FILE: [ROOT]/includes/functions_content.php
LINE: 124
CALL: dbal_mysql->sql_query()

FILE: [ROOT]/bans.php
LINE: 94
CALL: make_jumpbox()
EDIT OK i found the problem it is

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

on the end of the file. Is it possible to go back the end of the file to the phpbb db that i can use this?
Last edited by Angel200 on Wed Mar 14, 2012 1:05 pm, edited 1 time in total.
User avatar
AmigoJack
Registered User
Posts: 5774
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by AmigoJack »

You haven't used your own DBAL instance. Show the complete script.
Next time when citing print_r output use the source view of your web site instead of its HTML interpretation - that way linefeeds stay intact.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

I edit my post a few minutes after your post^^
also i see the site with the source view after i edit my post. so as i see it is all correct what i get from the db

Code: Select all

Array
(
    [country] => UA
    [created] => 1328036453
    [name] => NFSNIK
    [reason] => Inappropriate Language
    [length] => 15552000
    [RemoveType] => 
    [community_id] => 76561197999035268
    [admin_name] => Shona
)
EDIT: ok i see that RemoveType is emtpy normal there is an E for expired in it

but here are the complete script

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('ownsites');     

page_header($user->lang['BANS']);

    $sourcebans = 'sourcebans'; //Link to your Sourcebans install (required for the country flags, with a trailing slash)
	
	$dbSourceBan= new $sql_db();  // New DBAL instance
    $dbSourceBan-> sql_connect( 'localhost', 'username', 'password', 'sourcebans', $dbport, FALSE, defined( 'PHPBB_DB_NEW_LINK' )? PHPBB_DB_NEW_LINK: FALSE );  // Actual connection with details

	
	function SecondsToString($sec, $textual=true){
		if($textual) {
			$div = array( 2592000, 604800, 86400, 3600, 60, 1 );
			$desc = array('mo','wk','d','hr','min','sec');
			$ret = null;
			foreach($div as $index => $value){
			$quotent = floor($sec / $value); //greatest whole integer
			
				if($quotent > 0) {
					$ret .= "$quotent {$desc[$index]}, ";
					$sec %= $value;
				}
			}
		
			return substr($ret,0,-2);
		} 
		else {
			$hours = floor ($sec / 3600);
			$sec -= $hours * 3600;
			$mins = floor ($sec / 60);
			$secs = $sec % 60;
			return "$hours:$mins:$secs";
		}
	}
	
	
	$sql = 'SELECT b.country, b.created, b.name, b.reason, b.length, b.RemoveType,
								    CAST(MID(b.authid, 9, 1) AS UNSIGNED) + CAST("76561197960265728" AS UNSIGNED) + CAST(MID(b.authid, 11, 10) * 2 AS UNSIGNED) AS community_id, 
								    a.user AS admin_name
	FROM ' . sb_bans . ' b
		LEFT JOIN ' . sb_admins ." a
		ON a.aid = b.aid
	ORDER BY created DESC
	LIMIT 0,40";    
	
	$result = $dbSourceBan-> sql_query( $sql );
	
	while( $row= $dbSourceBan-> sql_fetchrow( $result ) ) {  // Enumerate zero to many result sets
	  print_r( $row );
	}
	$dbSourceBan-> sql_freeresult( $result );  // Release memory 

/* I don't know if this is correct or if i forget something */	
/* 	while( $row= $dbSourceBan-> sql_fetchrow( $result ) )   // Enumerate zero to many result sets
      {
          $template->assign_block_vars('sbans', array(
            'BAN_COUNTRY'      	=> $row['country'],
            'BAN_DATE'      	=> $row['created'],
            'BAN_PLAYER'      	=> $row['name'],
            'BAN_REASON'      	=> $row['reason'],
            'BAN_ADMIN'      	=> $row['admin_name'],
            'BAN_LENGTH'      	=> $row['length'],
            'BAN_IDK'         	=> $row['RemoveType'],
			'BAN_PROTEST'      	=> $user->lang['PROTEST_BAN'],
          ));
       }
    $dbSourceBan-> sql_freeresult( $result );  // Release memory 
*/

$template->set_filenames(array(
        'body' => 'bans_body.html',
    ));

/* make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx")); */
page_footer();

?>
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

CODE UPDATE

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('ownsites');     

page_header($user->lang['BANS']);

    $sourcebans = '../sourcebans/'; //Link to your Sourcebans install (required for the country flags, with a trailing slash)
	
	$dbSourceBan= new $sql_db();  // New DBAL instance
    $dbSourceBan-> sql_connect( 'localhost', 'xxxxxx', 'xxxxxxx', 'sourcebans', $dbport, FALSE, defined( 'PHPBB_DB_NEW_LINK' )? PHPBB_DB_NEW_LINK: FALSE );  // Actual connection with details

	
	function SecondsToString($sec, $textual=true){
		if($textual) {
			$div = array( 2592000, 604800, 86400, 3600, 60, 1 );
			$desc = array('mo','wk','d','hr','min','sec');
			$ret = null;
			foreach($div as $index => $value){
			$quotent = floor($sec / $value); //greatest whole integer
			
				if($quotent > 0) {
					$ret .= "$quotent {$desc[$index]}, ";
					$sec %= $value;
				}
			}
		
			return substr($ret,0,-2);
		} 
		else {
			$hours = floor ($sec / 3600);
			$sec -= $hours * 3600;
			$mins = floor ($sec / 60);
			$secs = $sec % 60;
			return "$hours:$mins:$secs";
		}
	}
	
	
	$sql = 'SELECT b.country, b.created, b.name, b.reason, b.length, b.RemoveType,
								    CAST(MID(b.authid, 9, 1) AS UNSIGNED) + CAST("76561197960265728" AS UNSIGNED) + CAST(MID(b.authid, 11, 10) * 2 AS UNSIGNED) AS community_id, 
								    a.user AS admin_name
	FROM ' . sb_bans . ' b
		LEFT JOIN ' . sb_admins ." a
		ON a.aid = b.aid
	ORDER BY created DESC
	LIMIT 0,40";    
	
	$result = $dbSourceBan-> sql_query( $sql );
	
	while( $row= $dbSourceBan-> sql_fetchrow( $result ) )
	{  
		array_walk($row, "trim");
		// Country
		if(!empty($row['country']) && $row['country'] != ' ')
		{
			$scountry = '<img src="'.$sourcebans.'images/country/'.strtolower($row['country']).'.gif" />';
		}
		else
		{
			$scountry = '<img src="'.$sourcebans.'images/country/zz.gif" />';
		}
		// date
		$bandate = date('d/m/Y', $row['created']);
		
		// Player name
		if(!empty($row['name']) && $row['name'] != ' ')
		{
			$playername = '<a href="http://steamcommunity.com/profiles/'.$row['community_id'].'" target="_blank">'.$row['name'].'</a>';
		}
		else
		{
			$playername = $user->lang['NO_NICKNAME_PRESENT'];
		}
		
		// Reasons
		if(!empty($row['reason']) && $row['reason'] != ' ')
		{
			$sreasons = $row['reason'];
		}
		else
		{
			$sreasons = $user->lang['NO_REASON_PRESENT'];
		}		
		
		// Admin name
		$adminname = $row['admin_name'];
		
		// Length of ban
		if($row['length'] == 0)
		{
			$banlength = $user->lang['PERM'];
		}
		else
		{
			$banlength = SecondsToString($row['length']).(empty($row['RemoveType'])?'':' (' . $row['RemoveType'] . ')');
		}
	}
	$dbSourceBan-> sql_freeresult( $result );  // Release memory 
	
	
	

$template->assign_vars(array(
	'BAN_COUNTRY'      	=> $scountry,
	'BAN_DATE'      	=> $bandate,
	'BAN_PLAYER'      	=> $playername,
	'BAN_REASON'      	=> $sreasons,
	'BAN_ADMIN'      	=> $adminname,
	'BAN_LENGTH'      	=> $banlength,
));


$template->set_filenames(array(
        'body' => 'bans_body.html',
    ));

page_footer();

?>
RESULT
Image
(Click the PIcture for a bigger one)

EDIT:
Found my fault why the country, date, reason and name not showing^^

So now the last problem is that only 1 ban is showing but i want 40
User avatar
HGN
Former Team Member
Posts: 4706
Joined: Wed Dec 03, 2008 1:53 pm
Location: The Netherlands
Name: Alfred
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by HGN »

To assign template vars, use:

Code: Select all

$template->assign_block_vars('ban_info', array(
   'BAN_COUNTRY'         => $scountry,
   'BAN_DATE'         => $bandate,
   'BAN_PLAYER'         => $playername,
   'BAN_REASON'         => $sreasons,
   'BAN_ADMIN'         => $adminname,
   'BAN_LENGTH'         => $banlength,
));
Than in your HTML you can use this:

Code: Select all

<!-- BEGIN ban_info -->
{ban_info.BAN_COUNTRY}
{ban_info.BAN_DATE}
{ban_info.BAN_PLAYER}
{ban_info.BAN_REASON}
{ban_info.BAN_ADMIN}
{ban_info.BAN_LENGTH}
<!-- END ban_info -->
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

Thx but my problem that only one ban get displayed is always there
User avatar
RMcGirr83
Former Team Member
Posts: 21493
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: PHP&HTML Script cut in PHP and Template file help

Post by RMcGirr83 »

That's because you aren't including the template vars within the while loop.
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

Oh my god *facepalm* know it works perfekt^^

Thx to all they help me :) it works now perfekt and i make something for all of you on the End of the banlist :mrgreen:

http://www.taverne-gaming.eu/bans.php

I will also release it on our Site to download. If someone want the script now he/she can ask me over PM ;)
User avatar
RMcGirr83
Former Team Member
Posts: 21493
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: PHP&HTML Script cut in PHP and Template file help

Post by RMcGirr83 »

Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

I know you made such a list for phpbb^^ but this is a external List from our Sourcebans Banlist ;)

"SourceBans is a free global administration and banning system for Source engine based servers."
Servers like CSS, L4D, L4D2, Team Fortress 2
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

Hey @All,

yeah long time nothing from me because i'm still happy that the banlist is so good working :D

But i was thinking a little bit in the time and i was confused if it is hard to add the pagination.html and make on each page 20 bans?

I'm looking in the mod from RMcGirr83 she linked and i see that the template file is easy but how is it whit the php part? Is it easy to add or did i have to rewrite my php file?
eric0279
Registered User
Posts: 244
Joined: Fri Apr 13, 2007 9:22 pm

Re: PHP&HTML Script cut in PHP and Template file help

Post by eric0279 »

Hello,

could you make one integration of your .zip?

I'm interested: p

cordially
Locked

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