Location: PHPKode > projects > PhpGuestbook > phpGuestbook/admin/admin.php
<?php

/***************************************************************************
 *   Copyright (C) 2004 by Thomas Flueeli                                  *
 *   hide@address.com                                                    *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/ 
 
/***************************************************************************
 * Version                                                                 *
 *   $Id: admin.php,v 1.6 2004/05/18 07:58:59 thatrix Exp $                *
 ***************************************************************************/ 

/***************************************************************************
 * History                                                                 *
 *   03.06.2003 : Initial release [thatrix]                                *
 *   24.11.2003 : Config bug fixed [thatrix]                               *
 *   25.11.2003 : Table prefix [thatrix]                                   *
 ***************************************************************************/ 

 // Load Libraries
 require_once('Auth/Auth.php'); // PEAR::Auth
        
 // Session Settings
 $phpGB_Admin = new Auth('DB', array('dsn' => $config['DSN'], 'table' => $config['prefix'] . 'Users', 'usernamecol' => 'Username', 'passwordcol' => 'Password'), 'writeLoginForm');
 $phpGB_Admin->setSessionname('phpGuestbookSessionID');
 $phpGB_Admin->setIdle(600);
 $phpGB_Admin->start();
 
 /********************************************************************
  * Function    : writeLoginForm
  * Description : Writes the login form.
  * Params      : -
  * Return      : -
  ********************************************************************/
 function writeLoginForm()
 {
        global $template, $config;
        
        $template->assign('FILE_INDEX' , $_SERVER['PHP_SELF']);
        $template->assign('DIR_IMAGES' , $config['URL'] . 'templates/Standard/images/');
        $template->assign('TITLE'      , $config['Title'] . ' Administration');
        $template->display('Standard/admin_login.tpl');
 }

 /********************************************************************
  * Function    : formatBytes
  * Description : Formats a number of bytes into human readable format.
  * Params      : Bytes, [Base10], [round to], [Labels]
  * Return      : Formatted Bytes or NULL
  ********************************************************************/
 function formatBytes($bytes, $base10=false, $round=2, $labels=array('bytes', 'KB', 'MB', 'GB', 'TB'))
 {
        if (($bytes <= 0) || (! is_array($labels)) || (count($labels) <= 0)) {
                return null;
        }
   
        $step = $base10 ? 3 : 10 ;
        $base = $base10 ? 10 : 2;
   
        $log = (int)(log10($bytes)/log10($base)); 
   
        krsort($labels);
  
        foreach ($labels as $p=>$lab) {
                $pow = $p * $step;
                if ($log < $pow) continue;
                $text = round($bytes / pow($base, $pow), $round) . ' ' . $lab;
                break;
        }
   
        return $text;
 }

?>
Return current item: PhpGuestbook