Files
IPB/upload/sources/lib/admin_functions.php
T
2025-12-19 00:21:15 -08:00

1607 lines
46 KiB
PHP

<?php
/*
+--------------------------------------------------------------------------
| Invision Power Board 2.1.7
| =============================================
| by Matthew Mecham
| (c) 2001 - 2005 Invision Power Services, Inc.
| http://www.invisionpower.com
| =============================================
| Web: http://www.invisionboard.com
| http://www.ibresource.ru/products/invisionpowerboard/
| Time: Tuesday 18th of July 2006 05:56:00 PM
| Release: 52f408a29988b02f45b5e6f4ba5af0ae
| Licence Info: http://www.invisionboard.com/?license
| http://www.ibresource.ru/license
+---------------------------------------------------------------------------
| INVISION POWER BOARD IS NOT FREE / OPEN SOURCE!
+---------------------------------------------------------------------------
| INVISION POWER BOARD ÍÅ ßÂËßÅÒÑß ÁÅÑÏËÀÒÍÛÌ ÏÐÎÃÐÀÌÌÍÛÌ ÎÁÅÑÏÅ×ÅÍÈÅÌ!
| Ïðàâà íà ÏÎ ïðèíàäëåæàò Invision Power Services
| Ïðàâà íà ïåðåâîä IBResource (http://www.ibresource.ru)
+---------------------------------------------------------------------------
| > $Date: 2005-12-08 16:32:40 +0000 (Thu, 08 Dec 2005) $
| > $Revision: 96 $
| > $Author: bfarber $
+---------------------------------------------------------------------------
|
| > Admin functions library
| > Script written by Matt Mecham
| > Date started: 1st march 2002
|
| > DBA Checked: Tue 25th May 2004
+--------------------------------------------------------------------------
*/
class admin_functions
{
# Global
var $ipsclass;
var $img_url;
var $page_title = "Äîáðî ïîæàëîâàòü â àäìèíöåíòð Invision Power Board";
var $page_detail = "Âû ìîæåòå íàñòðàèâàòü âàø ôîðóì, èñïîëüçóÿ ýòîò àäìèíöåíòð.<br><br>Íàæàòèå íà îäíó èç ññûëîê â ëåâîì ìåíþ çàãðóçèò âûáðàííûå íàñòðîéêè â îêíå ñïðàâà äëÿ àäìèíèñòðèðîâàíèÿ. Êàæäàÿ îïöèÿ ñîäåðæèò êàêóþ-òî èíôîðìàöèþ.";
var $html;
var $errors = "";
var $nav = array();
var $time_offset = 0;
var $jump_menu = "";
var $no_jump = 0;
var $master_skin = array();
var $depth_guide = '--';
var $menu_ids = array();
/*-------------------------------------------------------------------------*/
// CONSTRUCTOR
/*-------------------------------------------------------------------------*/
function admin_functions()
{
$this->ipsclass->base_url = $this->ipsclass->base_url;
$this->img_url = $this->ipsclass->skin_url;
}
/*-------------------------------------------------------------------------*/
// ACP PERMISSION CHECK
/*-------------------------------------------------------------------------*/
function cp_permission_check( $perm)
{
//----------------------------------
// Got actual restrictions?
//----------------------------------
if ( ! $this->ipsclass->member['row_perm_cache'] )
{
return TRUE;
}
//-------------------------------
// Get lang: NEEDS SORTIN'
//-------------------------------
if ( ! is_array( $this->perm_lang ) OR ! count( $this->perm_lang ) )
{
require_once( ROOT_PATH."cache/lang_cache/ru/acp_lang_acpperms.php" );
$this->perm_lang = $lang;
}
//----------------------------------
// Got restrictions in place...
// 1) Check tab root and parent
//----------------------------------
list( $perm_main , $_data ) = explode( '|', $perm );
list( $perm_child, $perm_bit ) = explode( ':', $_data );
if ( ! $this->ipsclass->member['_perm_cache'][ $perm_main ] )
{
$this->ipsclass->kill_menu = 1;
$this->ipsclass->admin->error("Âû íå èìååò äîñòóïà ê ýòîé òàáëèöå: ".$this->perm_lang[ $perm_main ] );
exit();
}
//----------------------------------
// Got restrictions in place...
// 2) Check feature parent
//----------------------------------
if ( $perm_child )
{
if ( ! $this->ipsclass->member['_perm_cache'][ $perm_main .':'. $perm_child ] )
{
if ( $this->perm_lang[ $perm_main .':'. $perm_child ] )
{
$this->ipsclass->admin->error("Âû íå èìååò äîñòóïà ê âîçìîæíîñòè: ".$this->perm_lang[ $perm_main .':'. $perm_child ]);
}
else
{
$this->ipsclass->admin->error("Âû íå èìååò äîñòóïà ê ýòîé âîçìîæíîñòè");
}
exit();
}
}
//----------------------------------
// Got restrictions in place...
// 3) Check feature parent
//----------------------------------
if ( $perm_bit )
{
if ( ! $this->ipsclass->member['_perm_cache'][ $perm_main .':'. $perm_child .':'. $perm_bit ] )
{
$this->ipsclass->admin->error("Âû íå èìååò äîñòóïà ê ôóíêöèè ýòîé âîçìîæíîñòè");
exit();
}
}
return TRUE;
}
/*-------------------------------------------------------------------------*/
// ACP_SESSION
/*-------------------------------------------------------------------------*/
function acp_session_validation( $check_ip=1 )
{
if ( ! $this->ipsclass->input['adsess'] )
{
//----------------------------------
// No URL adsess found, lets log in.
//----------------------------------
$this->ipsclass->admin_session['_session_validated'] = 0;
$this->ipsclass->admin_session['_session_message'] = "Ñåññèé àäìèíèñòðàòîðà íå íàéäåíî";
return FALSE;
}
else
{
//----------------------------------
// We have a URL adsess, lets verify...
//----------------------------------
$this->ipsclass->DB->query("SELECT * FROM ibf_admin_sessions WHERE session_id='".$this->ipsclass->input['adsess']."'");
$row = $this->ipsclass->DB->fetch_row();
if ( $row['session_id'] == "" )
{
//----------------------------------
// Fail-safe, no DB record found, lets log in..
//----------------------------------
$this->ipsclass->admin_session['_session_validated'] = 0;
$this->ipsclass->admin_session['_session_message'] = "Íåâîçìîæíî çàïðîñèòü ñåññèþ";
return FALSE;
}
else if ($row['session_member_id'] == "")
{
//----------------------------------
// No member ID is stored, log in!
//----------------------------------
$this->ipsclass->admin_session['_session_validated'] = 0;
$this->ipsclass->admin_session['_session_message'] = "Íåâîçìîæíî îïðåäåëèòü ïðàâèëüíûé ID";
return FALSE;
}
else
{
//----------------------------------
// Key is good, check the member details
//----------------------------------
$this->ipsclass->DB->build_query( array( 'select' => 'm.*',
'from' => array( 'members' => 'm' ),
'where' => 'm.id='.intval($row['session_member_id']),
'add_join' => array( 0 => array(
'select' => 'g.*',
'from' => array( 'groups' => 'g' ),
'where' => 'g.g_id=m.mgroup',
'type' => 'left' ),
1 => array(
'select' => 'p.*',
'from' => array( 'admin_permission_rows' => 'p' ),
'where' => 'm.id=p.row_member_id',
'type' => 'left' )
)
) );
$this->ipsclass->DB->exec_query();
$this->ipsclass->member = $this->ipsclass->DB->fetch_row();
$this->ipsclass->member['_perm_cache'] = unserialize( $this->ipsclass->member['row_perm_cache'] );
//----------------------------------
// Get perms
//----------------------------------
$this->ipsclass->sess->member = $this->ipsclass->member;
$this->ipsclass->sess->build_group_permissions();
$this->ipsclass->member = $this->ipsclass->sess->member;
if ($this->ipsclass->member['id'] == "")
{
//----------------------------------
// Ut-oh, no such member, log in!
//----------------------------------
$this->ipsclass->admin_session['_session_validated'] = 0;
$this->ipsclass->admin_session['_session_message'] = "ID ïîëüçîâàòåëÿ íåâåðíî";
return FALSE;
}
else
{
//----------------------------------
// Member found, check passy
//----------------------------------
if ($row['session_member_login_key'] != $this->ipsclass->member['member_login_key'])
{
//----------------------------------
// Passys don't match..
//----------------------------------
$this->ipsclass->admin_session['_session_validated'] = 0;
$this->ipsclass->admin_session['_session_message'] = "Ñåññèÿ ïàðîëÿ íå ñîâïàäàåò";
return FALSE;
}
else
{
//----------------------------------
// Do we have admin access?
//----------------------------------
if ($this->ipsclass->member['g_access_cp'] != 1)
{
$this->ipsclass->admin_session['_session_validated'] = 0;
$this->ipsclass->admin_session['_session_message'] = "Âû íå èìååò äîñòóïà â àäìèíöåíòð";
return FALSE;
}
else
{
$this->ipsclass->admin_session = $row;
$this->ipsclass->admin_session['_session_validated'] = 1;
}
}
}
}
}
//----------------------------------
// If we're here, we're valid...
//----------------------------------
if ( $this->ipsclass->admin_session['_session_validated'] == 1 )
{
if ( $this->ipsclass->admin_session['session_running_time'] < ( time() - 60*60*2) )
{
$this->ipsclass->admin_session['_session_validated'] = 0;
$this->ipsclass->admin_session['_session_message'] = "Òåêóùàÿ ñåññèÿ àäìèíèñòðàòîðà èñòåêëà";
}
//------------------------------
// Are we checking IP's?
//------------------------------
else if ($check_ip == 1)
{
$first_ip = preg_replace( "/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", "\\1.\\2.\\3", $this->ipsclass->admin_session['session_ip_address'] );
$second_ip = preg_replace( "/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", "\\1.\\2.\\3", $this->ipsclass->ip_address );
if ( $first_ip != $second_ip )
{
$this->ipsclass->admin_session['_session_validated'] = 0;
$this->ipsclass->admin_session['_session_message'] = "Âàø òåêóùèé IP íå ñîâïàäàåò íè ñ îäíîé íàøåé çàïèñüþ";
return FALSE;
}
}
//------------------------------
// Lets update the sessions table:
//------------------------------
$this->ipsclass->DB->do_update( 'admin_sessions', array( 'session_running_time' => time(), 'session_location' => $this->ipsclass->input['act'] ),
'session_member_id='.intval($this->ipsclass->member['id'])." and session_id='".$this->ipsclass->input['adsess']."'" );
return TRUE;
}
}
/*-------------------------------------------------------------------------*/
// Get mysql version
/*-------------------------------------------------------------------------*/
function get_mysql_version()
{
$this->ipsclass->DB->sql_get_version();
$this->ipsclass->true_version = $this->ipsclass->DB->true_version;
$this->ipsclass->mysql_version = $this->ipsclass->DB->mysql_version;
}
/*-------------------------------------------------------------------------*/
// Get mysql version
/*-------------------------------------------------------------------------*/
function get_fulltextindex_status()
{
if ( $this->ipsclass->DB->sql_is_currently_fulltext( 'posts' ) == TRUE )
{
return 1;
}
else
{
return 0;
}
}
/*-------------------------------------------------------------------------*/
// make template / text data safe for forms
/*-------------------------------------------------------------------------*/
function text_to_form($t="")
{
// Use forward look up to only convert & not &#123;
//$t = preg_replace("/&(?!#[0-9]+;)/s", '&#38;', $t );
$t = str_replace("&", "&#38;" , $t );
$t = str_replace( "<" , "&#60;" , $t );
$t = str_replace( ">" , "&#62;" , $t );
$t = str_replace( '"' , "&#34;" , $t );
$t = str_replace( "'" , '&#039;' , $t );
$t = str_replace( "\\", "&#092;" , $t );
return $t; // A nice cup of?
}
/*-------------------------------------------------------------------------*/
// Converts form data back into raw text
/*-------------------------------------------------------------------------*/
function form_to_text($t="")
{
$t = str_replace( '\\' , '\\\\', $t );
$t = str_replace( "&#38;" , "&", $t );
$t = str_replace( "&#60;" , "<", $t );
$t = str_replace( "&#62;" , ">", $t );
$t = str_replace( "&#34;" , '"', $t );
$t = str_replace( "&#039;" , "'", $t );
$t = str_replace( '&#092;' ,'\\', $t );
return $t;
}
/*-------------------------------------------------------------------------*/
// Generate skin list
/*-------------------------------------------------------------------------*/
function skin_get_skin_dropdown()
{
$skin_array = array();
foreach( $this->ipsclass->cache['skin_id_cache'] as $id => $data )
{
if ( $data['set_parent'] < 1 and $id > 1 )
{
$data['set_parent'] = 'root';
}
$this->master_skin[ $data['set_parent'] ][ $id ] = $data;
}
foreach( $this->master_skin['root'] as $id => $data )
{
$skin_array[] = array( $id, $data['set_name'] );
if ( is_array( $this->master_skin[ $id ] ) )
{
foreach( $this->master_skin[ $id ] as $id => $data )
{
$skin_array[] = array( $id, $this->depth_guide.$data['set_name'] );
$skin_array = $this->skin_get_skin_dropdown_recurse( $id, $skin_array, $this->depth_guide.$this->depth_guide );
}
}
}
return $skin_array;
}
/*-------------------------------------------------------------------------*/
// Recurse
/*-------------------------------------------------------------------------*/
function skin_get_skin_dropdown_recurse( $root_id, $skin_array=array(), $depth_guide='' )
{
if ( is_array( $this->master_skin[ $root_id ] ) )
{
foreach( $this->master_skin[ $root_id ] as $id => $data )
{
$skin_array[] = array( $id, $this->depth_guide.$data['set_name'] );
$skin_array = $this->skin_get_skin_dropdown_recurse( $id, $skin_array, $this->depth_guide.$this->depth_guide );
}
}
return $skin_array;
}
/*-------------------------------------------------------------------------*/
// IMPORT FUNCTION
/*-------------------------------------------------------------------------*/
function import_xml( $infilename )
{
//-----------------------------------------
// Allowed file-types
//-----------------------------------------
$allowed_files = array( 'xml', 'gz' );
//-----------------------------------------
// Upload
//-----------------------------------------
$FILE_NAME = $_FILES['FILE_UPLOAD']['name'];
$FILE_SIZE = $_FILES['FILE_UPLOAD']['size'];
$FILE_TYPE = $_FILES['FILE_UPLOAD']['type'];
//-----------------------------------------
// Naughty Opera adds the filename on the end of the
// mime type - we don't want this.
//-----------------------------------------
$FILE_TYPE = preg_replace( "/^(.+?);.*$/", "\\1", $FILE_TYPE );
//-----------------------------------------
// Naughty Mozilla likes to use "none" to indicate an empty upload field.
// I love universal languages that aren't universal.
//-----------------------------------------
if ( $_FILES['FILE_UPLOAD']['name'] == "" or ! $_FILES['FILE_UPLOAD']['name'] or ($_FILES['FILE_UPLOAD']['name'] == "none") )
{
continue;
}
//-----------------------------------------
// Not a naughty file?
//-----------------------------------------
$file_extension = preg_replace( "#^.*\.(.+?)$#si", "\\1", strtolower( $_FILES['FILE_UPLOAD']['name'] ) );
if ( ! in_array( $file_extension, $allowed_files ) )
{
@unlink( $_FILES[ $postfield ]['tmp_name'] );
return '';
}
$content = "";
if ( strstr( $FILE_NAME, $infilename ) )
{
if ( move_uploaded_file( $_FILES[ 'FILE_UPLOAD' ]['tmp_name'], $this->ipsclass->vars['upload_dir']."/".$FILE_NAME) )
{
if ( $FILE_NAME == $infilename.'.gz' )
{
if ( $FH = @gzopen( $this->ipsclass->vars['upload_dir']."/".$FILE_NAME, 'rb' ) )
{
while ( ! @gzeof( $FH ) )
{
$content .= @gzread( $FH, 1024 );
}
@gzclose( $FH );
}
}
else if ( $FILE_NAME == $infilename )
{
if ( $FH = @fopen( $this->ipsclass->vars['upload_dir']."/".$FILE_NAME, 'rb' ) )
{
$content = @fread( $FH, filesize($this->ipsclass->vars['upload_dir']."/".$FILE_NAME) );
@fclose( $FH );
}
}
@unlink( $this->ipsclass->vars['upload_dir']."/".$FILE_NAME );
}
}
return $content;
}
/*-------------------------------------------------------------------------*/
// Shows dialogue download box
/*-------------------------------------------------------------------------*/
function show_download( $data, $name, $type="unknown/unknown", $compress=1 )
{
if ( $compress and @function_exists('gzencode') )
{
$name .= '.gz';
}
else
{
$compress = 0;
}
header('Content-Type: '.$type);
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Disposition: attachment; filename="' . $name . '"');
if ( ! $compress )
{
@header('Content-Length: ' . strlen($data) );
}
@header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
@header('Pragma: public');
if ( $compress )
{
print gzencode($data);
}
else
{
print $data;
}
exit();
}
/*-------------------------------------------------------------------------*/
// Makes good raw form text
/*-------------------------------------------------------------------------*/
function make_safe($t)
{
$t = stripslashes($t);
$t = preg_replace( "/\\\/", "&#092;", $t );
return $t;
}
/*-------------------------------------------------------------------------*/
// Sets up time offset for ACP use
/*-------------------------------------------------------------------------*/
function get_date($date="", $method="")
{
$this->time_options = array( 'JOINED' => $this->ipsclass->vars['clock_joined'],
'SHORT' => $this->ipsclass->vars['clock_short'],
'LONG' => $this->ipsclass->vars['clock_long']
);
if (!$date)
{
return '--';
}
if (empty($method))
{
$method = 'LONG';
}
$this->time_offset = (($this->ipsclass->member['time_offset'] != "") ? $this->ipsclass->member['time_offset'] : $this->ipsclass->vars['time_offset']) * 3600;
if ($this->ipsclass->vars['time_adjust'] != "" and $this->ipsclass->vars['time_adjust'] != 0)
{
$this->time_offset += ($this->ipsclass->vars['time_adjust'] * 60);
}
if ($this->ipsclass->member['dst_in_use'])
{
$this->time_offset += 3600;
}
return gmdate($this->time_options[$method], ($date + $this->time_offset) );
}
/*-------------------------------------------------------------------------*/
// save_log
/*-------------------------------------------------------------------------*/
function save_log($action="")
{
$this->ipsclass->DB->do_insert( 'admin_logs', array(
'act' => $this->ipsclass->input['act'],
'code' => $this->ipsclass->input['code'],
'member_id' => $this->ipsclass->member['id'],
'ctime' => time(),
'note' => $action,
'ip_address' => $this->ipsclass->input['IP_ADDRESS'],
) );
return true;
}
/*-------------------------------------------------------------------------*/
// get_tar_names
/*-------------------------------------------------------------------------*/
function get_tar_names($start='lang-')
{
$files = array();
$dir = $this->ipsclass->vars['base_dir']."archive_in";
if ( is_dir($dir) )
{
$handle = opendir($dir);
while (($filename = readdir($handle)) !== false)
{
if (($filename != ".") && ($filename != ".."))
{
if (preg_match("/^$start.+?\.tar$/", $filename))
{
$files[] = $filename;
}
}
}
closedir($handle);
}
return $files;
}
/*-------------------------------------------------------------------------*/
// copy_dir
/*-------------------------------------------------------------------------*/
function copy_dir($from_path, $to_path, $mode = 0777)
{
// Strip off trailing slashes...
$from_path = preg_replace( "#/$#", "", $from_path);
$to_path = preg_replace( "#/$#", "", $to_path);
if ( ! is_dir($from_path) )
{
$this->errors = "Íåâîçìîæíî íàéòè ïàïêó /$from_path";
return FALSE;
}
if ( ! is_dir($to_path) )
{
if ( ! @mkdir($to_path, $mode) )
{
$this->errors = "Íåâîçìîæíî ñîçäàòü ïàïêó /$to_path/! Ïîæàëóéñòà, ïðîâåðüòå ïðàâà äîñòóïà (CHMOD) è ïîïðîáóéòå ñíîâà.";
return FALSE;
}
else
{
@chmod($to_path, $mode);
}
}
//$this_path = getcwd();
if (is_dir($from_path))
{
//chdir($from_path);
$handle = opendir($from_path);
while (($file = readdir($handle)) !== false)
{
if (($file != ".") && ($file != ".."))
{
if ( is_dir( $from_path."/".$file ) )
{
$this->copy_dir($from_path."/".$file, $to_path."/".$file);
//chdir($from_path);
}
if ( is_file( $from_path."/".$file ) )
{
copy($from_path."/".$file, $to_path."/".$file);
@chmod($to_path."/".$file, 0777);
}
}
}
closedir($handle);
}
if ($this->errors == "")
{
return TRUE;
}
}
/*-------------------------------------------------------------------------*/
// rm_dir
/*-------------------------------------------------------------------------*/
function rm_dir($file)
{
$errors = 0;
// Remove trailing slashes..
$file = preg_replace( "#/$#", "", $file );
if ( file_exists($file) )
{
// Attempt CHMOD
@chmod($file, 0777);
if ( is_dir($file) )
{
$handle = opendir($file);
while (($filename = readdir($handle)) !== false)
{
if (($filename != ".") && ($filename != ".."))
{
$this->rm_dir($file."/".$filename);
}
}
closedir($handle);
if ( ! @rmdir($file) )
{
$errors++;
}
}
else
{
if ( ! @unlink($file) )
{
$errors++;
}
}
}
if ($errors == 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
/*-------------------------------------------------------------------------*/
// rebuild_config:
/*-------------------------------------------------------------------------*/
function rebuild_config( $new = "" )
{
//-----------------------------------------
// Check to make sure this is a valid array
//-----------------------------------------
if (! is_array($new) )
{
$ibforums->admin->error("Îøèáêà! Íå óäàëîñü îáíîâèòü êîíôèãóðàöèîííûé ôàéë ôîðóìà. Äåéñòâèå îòìåíåíî!");
}
//-----------------------------------------
// Do we have anything to save out?
//-----------------------------------------
if ( count($new) < 1 )
{
return "";
}
//-----------------------------------------
// Get an up to date copy of the config file
// (Imports $INFO)
//-----------------------------------------
require ROOT_PATH.'conf_global.php';
//-----------------------------------------
// Rebuild the $INFO hash
//-----------------------------------------
foreach( $new as $k => $v )
{
// Update the old...
$v = preg_replace( "/'/", "\\'" , $v );
$v = preg_replace( "/\r/", "" , $v );
$INFO[ $k ] = $v;
}
//-----------------------------------------
// Rename the old config file
//-----------------------------------------
@rename( ROOT_PATH.'conf_global.php', ROOT_PATH.'conf_global-bak.php' );
@chmod( ROOT_PATH.'conf_global-bak.php', 0777);
//-----------------------------------------
// Rebuild the old file
//-----------------------------------------
ksort($INFO);
$file_string = "<?php\n";
foreach( $INFO as $k => $v )
{
if ($k == 'skin' or $k == 'languages')
{
// Protect serailized arrays..
$v = stripslashes($v);
$v = addslashes($v);
}
$file_string .= '$INFO['."'".$k."'".']'."\t\t\t=\t'".$v."';\n";
}
$file_string .= "\n".'?'.'>'; // Question mark + greater than together break syntax hi-lighting in BBEdit 6 :p
if ( $fh = fopen( ROOT_PATH.'conf_global.php', 'w' ) )
{
fwrite($fh, $file_string, strlen($file_string) );
fclose($fh);
}
else
{
$this->ipsclass->admin->error("Êðèòè÷åñêàÿ îøèáêà! Íå óäàëîñü îòêðûòü äëÿ çàïèñè ôàéë conf_global.php - èçìåíåíèÿ íå áóäóò âíåñåíû. Íåîáõîäèìî èçìåíèòü ïðàâà äîñòóïà (CHMOD) ê ôàéëó íà 0777.");
}
// Pass back the new $INFO array to anyone who cares...
return $this->ipsclass->vars;
}
/*-------------------------------------------------------------------------*/
// compile_forum_perms:
//
// Returns the READ/REPLY/START DB strings
//
/*-------------------------------------------------------------------------*/
function compile_forum_perms()
{
$r_array = array( 'READ' => '', 'REPLY' => '', 'START' => '', 'UPLOAD' => '' );
if ($this->ipsclass->input['READ_ALL'] == 1)
{
$r_array['READ'] = '*';
}
if ($this->ipsclass->input['REPLY_ALL'] == 1)
{
$r_array['REPLY'] = '*';
}
if ($this->ipsclass->input['START_ALL'] == 1)
{
$r_array['START'] = '*';
}
if ($this->ipsclass->input['UPLOAD_ALL'] == 1)
{
$r_array['UPLOAD'] = '*';
}
if ($this->ipsclass->input['SHOW_ALL'] == 1)
{
$r_array['SHOW'] = '*';
}
$this->ipsclass->DB->simple_construct( array( 'select' => 'perm_id, perm_name', 'from' => 'forum_perms', 'order' => "perm_id" ) );
$this->ipsclass->DB->simple_exec();
while ( $data = $this->ipsclass->DB->fetch_row() )
{
if ($r_array['SHOW'] != '*')
{
if ($this->ipsclass->input[ 'SHOW_'.$data['perm_id'] ] == 1)
{
$r_array['SHOW'] .= $data['perm_id'].",";
}
}
//-----------------------------------------
if ($r_array['READ'] != '*')
{
if ($this->ipsclass->input[ 'READ_'.$data['perm_id'] ] == 1)
{
$r_array['READ'] .= $data['perm_id'].",";
}
}
//-----------------------------------------
if ($r_array['REPLY'] != '*')
{
if ($this->ipsclass->input[ 'REPLY_'.$data['perm_id'] ] == 1)
{
$r_array['REPLY'] .= $data['perm_id'].",";
}
}
//-----------------------------------------
if ($r_array['START'] != '*')
{
if ($this->ipsclass->input[ 'START_'.$data['perm_id'] ] == 1)
{
$r_array['START'] .= $data['perm_id'].",";
}
}
//-----------------------------------------
if ($r_array['UPLOAD'] != '*')
{
if ($this->ipsclass->input[ 'UPLOAD_'.$data['perm_id'] ] == 1)
{
$r_array['UPLOAD'] .= $data['perm_id'].",";
}
}
}
$r_array['START'] = preg_replace( "/,$/", "", $r_array['START'] );
$r_array['REPLY'] = preg_replace( "/,$/", "", $r_array['REPLY'] );
$r_array['READ'] = preg_replace( "/,$/", "", $r_array['READ'] );
$r_array['UPLOAD'] = preg_replace( "/,$/", "", $r_array['UPLOAD'] );
$r_array['SHOW'] = preg_replace( "/,$/", "", $r_array['SHOW'] );
return $r_array;
}
/*-------------------------------------------------------------------------*/
// OUTPUT FUNCTIONS
/*-------------------------------------------------------------------------*/
function print_popup()
{
global $use_gzip;
//--------------------------------------
// Message in a bottle?
//--------------------------------------
if ( $this->ipsclass->main_msg )
{
$html = $this->ipsclass->skin_global_acp->global_message();
}
$html .= $this->ipsclass->skin_global_acp->global_popup( $this->ipsclass->html );
print $html;
exit();
}
/*-------------------------------------------------------------------------*/
// Multi-redirect
/*-------------------------------------------------------------------------*/
function output_multiple_redirect_init( $url, $text='', $addtotext=1 )
{
//$this->nav[] = array( $url, 'Redirecting...' );
if ( $this->ipsclass->can_use_fancy_js )
{
$this->ipsclass->html .= "<script type='text/javascript'>ajax_refresh( '$url', '$text', $addtotext );</script>\n<div style='height:300px;overflow:auto;font-weight:bold;line-height:140%;padding:5px;border:1px solid #000' id='refreshbox'>Èíèöèàëèçàöèÿ...</div>";
}
else
{
$this->ipsclass->html .= "<iframe src='$url' scrolling='auto' style='border:1px solid #000' border='0' frameborder='0' width='100%' height='300'></iframe>";
}
$this->output();
}
/*-------------------------------------------------------------------------*/
// Multi-redirect (hit)
/*-------------------------------------------------------------------------*/
function output_multiple_redirect_hit( $url, $text='', $addtotext=1 )
{
if ( $this->ipsclass->can_use_fancy_js )
{
print "ajax_refresh( '$url', '$text', $addtotext );";
exit();
}
else
{
print $this->ipsclass->skin_global_acp->global_redirect_hit( $url, $text );
exit();
}
}
/*-------------------------------------------------------------------------*/
// Multi-redirect (hit)
/*-------------------------------------------------------------------------*/
function output_multiple_redirect_done($text='Ãîòîâî!')
{
if ( $this->ipsclass->can_use_fancy_js )
{
$text = str_replace( "'", "\\'", $text );
print "document.getElementById('refreshbox').innerHTML = '<span style=\"color:red\">$text</span>' + '<br />' + document.getElementById('refreshbox').innerHTML;";
exit();
}
else
{
print $this->ipsclass->skin_global_acp->global_redirect_done( $text );
exit();
}
}
/*-------------------------------------------------------------------------*/
// OUTPUT
/*-------------------------------------------------------------------------*/
function output()
{
global $use_gzip;
//-----------------------------------------
// Debug?
//-----------------------------------------
if ($this->ipsclass->DB->obj['debug'])
{
flush();
print "<html><head><title>SQL Îòëàä÷èê</title><body bgcolor='white'><style type='text/css'> TABLE, TD, TR, BODY { font-family: verdana,arial, sans-serif;color:black;font-size:11px }</style>";
print "<h1 align='center'>SQL Îáùåå âðåìÿ: {$this->ipsclass->DB->sql_time} äëÿ {$this->ipsclass->DB->query_cnt} çàïðîñîâ</h1><br />".$this->ipsclass->DB->debug_html;
print "<br /><div align='center'><strong>Îáùåå âðåìÿ ðàáîòû SQL: {$this->ipsclass->DB->sql_time}</div></body></html>";
exit();
}
//-----------------------------------------
// Start function proper
//-----------------------------------------
$html = str_replace( '<%CONTENT%>', $this->ipsclass->skin_global_acp->global_frame_wrapper(), $this->ipsclass->skin_global_acp->global_main_wrapper() );
$this->ipsclass->DB->close_db();
$navigation = array( "<a href='{$this->ipsclass->base_url}&act=index'>Íà ãëàâíóþ</a>" );
if ( count($this->nav) > 0 )
{
foreach ( $this->nav as $idx => $links )
{
if ($links[0] != "")
{
$navigation[] = "<a href='{$this->ipsclass->base_url}&{$links[0]}'>{$links[1]}</a>";
}
else
{
$navigation[] = $links[1];
}
}
}
//--------------------------------------
// Navigation?
//--------------------------------------
if ( count($navigation) > 0 )
{
$html = str_replace( "<%NAV%>", $this->ipsclass->skin_global_acp->global_wrap_nav( implode( " &gt; ", $navigation ) ), $html );
}
//--------------------------------------
// Message in a bottle?
//--------------------------------------
if ( $this->ipsclass->main_msg )
{
$message = $this->ipsclass->skin_global_acp->global_message();
}
//--------------------------------------
// Help?
//--------------------------------------
$this->ipsclass->html_help_msg = $this->ipsclass->html_help_msg ? $this->ipsclass->html_help_msg : $this->page_detail;
$this->ipsclass->html_help_title = $this->ipsclass->html_help_title ? $this->ipsclass->html_help_title : $this->page_title;
if ( $this->ipsclass->html_help_title )
{
$help = $this->ipsclass->skin_global_acp->global_help_block( $this->ipsclass->html_help_title, $this->ipsclass->html_help_msg );
}
//-----------------------------------------
// Quick Jump?
//-----------------------------------------
if ( $this->no_jump != 1 )
{
$html = str_replace( "<!--JUMP-->", $this->build_jump_menu(), $html );
}
//-----------------------------------------
// Kill menu?
// For when we don't want to show the menu
// during a tab error from cp_permission_check
//-----------------------------------------
if ( $this->ipsclass->kill_menu )
{
$html .= "<script type='text/javascript'>\ntry {\ndocument.getElementById('leftblock').style.display = 'none';\n}\ncatch(e){}\n</script>";
}
//-----------------------------------------
// Show queries
//-----------------------------------------
$query_html = "";
if ( IN_DEV and count( $this->ipsclass->DB->obj['cached_queries']) )
{
$queries = "";
foreach( $this->ipsclass->DB->obj['cached_queries'] as $q )
{
if ( strlen($q) > 300 )
{
$q = substr( $q, 0, 300 ).'...';
}
$queries .= htmlspecialchars($q).'<hr />';
}
$query_html .= $this->ipsclass->skin_global_acp->global_query_output($queries);
}
global $Debug;
$query_html .= "<div align='center'><br />Âðåìÿ ãåíåðàöèè ñòðàíèöû: ".$Debug->endTimer()."</div>";
//-----------------------------------------
// Other tags...
//-----------------------------------------
$html = str_replace( "<%TITLE%>" , $this->ipsclass->html_title, $html );
$html = str_replace( "<%MENU%>" , $this->build_menu() , $html );
$html = str_replace( "<%TABS%>" , $this->build_tabs() , $html );
$html = str_replace( "<%SECTIONCONTENT%>", $this->ipsclass->html, $html );
$html = str_replace( "<%MSG%>" , $message , $html );
$html = str_replace( "<%HELP%>" , $help , $html );
$html = str_replace( "<%QUERIES%>" , $query_html , $html );
//-----------------------------------------
// Got BODY EXTRA?
//-----------------------------------------
if ( $this->ipsclass->body_extra )
{
$html = str_replace( "<body", "<body ".$this->ipsclass->body_extra, $html );
}
//-----------------------------------------
// Gzip?
//-----------------------------------------
if ($use_gzip == 1)
{
$buffer = ob_get_contents();
ob_end_clean();
@ob_start('ob_gzhandler');
print $buffer;
}
@header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
@header("Cache-Control: no-cache, must-revalidate");
@header("Pragma: no-cache");
print $html;
exit();
}
/*-------------------------------------------------------------------------*/
// Build menu tree
/*-------------------------------------------------------------------------*/
function build_tabs()
{
$onoff['content'] = 'taboff';
$onoff['lookandfeel'] = 'taboff';
$onoff['tools'] = 'taboff';
$onoff['components'] = 'taboff';
$onoff['admin'] = 'taboff';
$onoff[ $this->ipsclass->menu_type ] = 'tabon';
return $this->ipsclass->skin_global_acp->global_tabs( $onoff );
}
/*-------------------------------------------------------------------------*/
// BUILD MENU
/*-------------------------------------------------------------------------*/
function build_menu()
{
//--------------------------------
// Catch log in pages, etc
//--------------------------------
if ( ! $this->ipsclass->menu_type )
{
return;
}
//--------------------------------
// Import $PAGES and $CATS
//--------------------------------
require_once( ROOT_PATH."sources/acp_loaders/acp_pages_".$this->ipsclass->menu_type.".php" );
$this->pages = $PAGES;
$this->cats = $CATS;
$this->desc = $DESC;
$html = $this->build_tree();
return $html;
}
/*-------------------------------------------------------------------------*/
// Show in frame
/*-------------------------------------------------------------------------*/
function show_inframe($url="", $html="")
{
if ( $url )
{
$this->ipsclass->html .= "<iframe src='$url' scrolling='auto' style='border:1px solid #000' border='0' frameborder='0' width='100%' height='500'></iframe>";
}
else
{
$this->ipsclass->html .= "<iframe scrolling='auto' style='border:1px solid #000' border='0' frameborder='0' width='100%' height='500'>{$html}</iframe>";
}
$this->output();
}
/*-------------------------------------------------------------------------*/
// Redirect:
/*-------------------------------------------------------------------------*/
function redirect($url, $text, $is_popup=0, $time=2)
{
//--------------------------------
// Got board URL in url?
//--------------------------------
if ( ! strstr( $url, $this->ipsclass->vars['board_url'] ) )
{
$url = $this->ipsclass->base_url.'&'.$url;
}
if ( $this->ipsclass->main_msg )
{
if( strlen($this->ipsclass->main_msg) > 1500 )
{
$this->ipsclass->main_msg = substr( $this->ipsclass->main_msg, 0, 1500 );
}
$url .= '&messageinabottleacp='.urlencode( $this->ipsclass->main_msg );
}
$this->ipsclass->main_msg = "";
$this->ipsclass->html_title = "IPB: Àäìèíöåíòð: Ïåðåàäðåñàöèÿ...";
$html = $this->ipsclass->skin_global_acp->global_redirect( $url, $time, $text );
$this->ipsclass->html = str_replace( '<%CONTENT%>', $html, $this->ipsclass->skin_global_acp->global_main_wrapper() );
$this->ipsclass->html = str_replace( '<%TITLE%>' , $this->ipsclass->html_title, $this->ipsclass->html );
$this->ipsclass->html = str_replace( "<body", "<body style='background-image:url({$this->ipsclass->skin_url}/images/blank.gif)'", $this->ipsclass->html );
@header("Content-type: text/html");
print $this->ipsclass->html;
exit();
}
/*-------------------------------------------------------------------------*/
// No waiting redirect
/*-------------------------------------------------------------------------*/
function redirect_noscreen($url)
{
$extra = "";
if ( $this->ipsclass->main_msg )
{
$extra = '&messageinabottleacp='.urlencode( $this->ipsclass->main_msg );
}
$url = str_replace( "&amp;", "&", $url ) . $extra;
if ($this->ipsclass->vars['header_redirect'] == 'refresh')
{
@header("Refresh: 0;url=".$url);
}
else if ($this->ipsclass->vars['header_redirect'] == 'html')
{
echo("<html><head><meta http-equiv='refresh' content='0; url=$url'></head><body></body></html>");
exit();
}
else
{
@header("Location: ".$url);
}
exit();
}
/*-------------------------------------------------------------------------*/
// Error:
/*-------------------------------------------------------------------------*/
function error($error="", $is_popup=0)
{
$this->page_title = "Ñîîáùåíèå àäìèíöåíòðà";
$this->page_detail = "&nbsp;";
$this->ipsclass->html .= "<div class='tableborder'>
<div class='maintitle'>Ñîîáùåíèå àäìèíöåíòðà</div>
<div class='tdrow1' style='padding:8px'>
<span style='font-size:12px'>$error</span>
</div>
</div>";
if ($is_popup == 0)
{
$this->output();
}
else
{
$this->print_popup();
}
}
/*-------------------------------------------------------------------------*/
// Done Screen:
/*-------------------------------------------------------------------------*/
function done_screen($title, $link_text="", $link_url="", $redirect="")
{
if ( $redirect )
{
$this->redirect( $this->ipsclass->base_url.'&'.$link_url, "<b>$title</b><br />Ïåðåìåùåíèå ê: ".$link_text );
}
$this->page_title = $title;
$this->page_detail = "Äåéñòâèå âûïîëíåíî óñïåøíî";
$this->ipsclass->adskin->td_header[] = array( "&nbsp;" , "100%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Ðåçóëüòàò");
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic( "<a href='{$this->ipsclass->base_url}&{$link_url}'>Ïåðåéòè â: $link_text</a>", "center" );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic( "<a href='{$this->ipsclass->base_url}&act=index'>Ïåðåéòè íà ãëàâíóþ ñòðàíèöó àäìèíöåíòðà</a>", "center" );
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->output();
}
/*-------------------------------------------------------------------------*/
// INFO screen
/*-------------------------------------------------------------------------*/
function info_screen($text="", $title='Ïðåäóïðåæäåíèå Safe Mode')
{
$this->page_title = $title;
$this->page_detail = "Ïîæàëóéñòà, ïîìíèòå ñëåäóþùåå:";
$this->ipsclass->adskin->td_header[] = array( "&nbsp;" , "100%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Ðåçóëüòàò");
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic( $text );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic( "<a href='{$this->ipsclass->base_url}&act=index'>Ïåðåéòè íà: ãëàâíóþ ñòðàíèöó àäìèíöåíòðà</a>", "center" );
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->output();
}
/*-------------------------------------------------------------------------*/
// Build menu tree
/*-------------------------------------------------------------------------*/
function build_tree()
{
//----------------------------------
// INIT
//----------------------------------
$html = "";
$links = "";
//----------------------------------
// Known menu stuff
//----------------------------------
# Section Module CODE => Real Perm Key
$menu_limits = array( 'content:mem:add' => 'content:mem:add',
'content:mem:title' => 'content:mem:title-view',
);
foreach($this->cats as $cid => $data)
{
$name = $data[0];
$color = $data[1];
$extra = $data[2];
$this->menu_ids[] = $cid;
$this->ipsclass->admin->jump_menu .= "<optgroup label='$name'>\n";
foreach($this->pages[ $cid ] as $pid => $pdata)
{
if ( $pdata[2] != "" )
{
if ( ! @is_dir( ROOT_PATH.$pdata[2] ) )
{
continue;
}
}
//----------------------------------
// Got actual restrictions?
//----------------------------------
$no_access = 0;
if ( $this->ipsclass->member['row_perm_cache'] )
{
//-------------------------------
// Yup.. so extract link info
//-------------------------------
$_tmp = str_replace( '&amp;', '&', $pdata[1] );
$perm_child = "";
$perm_main = "";
$perm_bit = "";
foreach( explode( '&', $_tmp ) as $_urlbit )
{
list( $k, $v ) = explode( '=', $_urlbit );
if ( $k == 'act' )
{
$perm_child = $v;
}
else if ( $k == 'section' )
{
$perm_main = $v;
}
else if ( $k == 'code' )
{
$perm_bit = $v;
}
if ( $perm_child AND $perm_main AND $perm_bit )
{
break;
}
}
if ( $perm_child AND $perm_main AND $perm_bit AND $menu_limits[ $perm_main.':'.$perm_child.':'.$perm_bit ] )
{
if ( ! $this->ipsclass->member['_perm_cache'][ $menu_limits[ $perm_main.':'.$perm_child.':'.$perm_bit ] ] )
{
$no_access = 1;
}
}
else if ( $perm_child AND $perm_main )
{
if ( ! $this->ipsclass->member['_perm_cache'][ $perm_main .':'. $perm_child ] )
{
$no_access = 1;
}
}
}
$links .= $this->ipsclass->adskin->menu_cat_link($pid, $cid, $pdata[1], $pdata[0], $pdata[3], $pdata[4], $no_access);
}
$html .= $this->ipsclass->adskin->menu_cat_wrap( $show, $name, $links, $cid, $this->desc[$cid], $color, $extra );
unset($links);
$this->ipsclass->admin->jump_menu .= "</optgroup>\n";
}
return $html;
}
/*-------------------------------------------------------------------------*/
// BUILDS JUMP MENU, yay!
/*-------------------------------------------------------------------------*/
function build_jump_menu()
{
return "";
global $PAGES, $CATS, $DESC;
$html = "<script type='text/javascript'>
function dojump()
{
if ( document.jumpmenu.val.options[document.jumpmenu.val.selectedIndex].value != '' )
{
window.location.href = '{$this->ipsclass->base_url}' + '&' + document.jumpmenu.val.options[document.jumpmenu.val.selectedIndex].value;
}
}
</script>
";
$html .= "<form name='jumpmenu'>\n<select class='jmenu' name='val'>";
foreach($CATS as $cid => $name)
{
$html .= "<optgroup label='$name[0]'>\n";
foreach($PAGES[ $cid ] as $pid => $pdata)
{
$html .= "<option value='$pdata[1]'>$pdata[0]</option>\n";
}
$html .= "</optgroup>\n";
}
$html .= "</select>&nbsp;<input type='button' class='jmenubutton' value='Âïåðåä!' onclick='dojump();' />\n</form>";
return $html;
}
/*-------------------------------------------------------------------------*/
// BUILD SKIN JUMP MENU
/*-------------------------------------------------------------------------*/
function skin_jump_menu($set_id="")
{
if ( $set_id == "" )
{
$set_id = $this->ipsclass->input['id'];
}
$set_id = intval($set_id);
$r = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'skin_sets', 'where' => 'set_skin_set_id='.$set_id ) );
$html = "<form name='gobaakaachoo'>
<select name='chooseacardanycard' class='realbutton' onchange=\"autojumpmenu(this)\">
<option value=''>Áûñòðûé ïåðåõîä ïî ñòèëþ: {$r['set_name']}</option>
<option value=''>-------------------</option>
<option value='{$this->ipsclass->adskin->base_url}&section=lookandfeel&act=wrap&code=edit&id={$r['set_skin_set_id']}&p={$r['set_skin_set_parent']}'>Èçìåíèòü ãëàâíûé øàáëîí ôîðóìà</option>
<option value='{$this->ipsclass->adskin->base_url}&section=lookandfeel&act=templ&code=edit&id={$r['set_skin_set_id']}&p={$r['set_skin_set_parent']}'>Èçìåíèòü HTML øàáëîíû ñòèëÿ</option>
<option value='{$this->ipsclass->adskin->base_url}&section=lookandfeel&act=style&code=edit&id={$r['set_skin_set_id']}&p={$r['set_skin_set_parent']}'>Èçìåíèòü CSS ñòèëè (ðàñøèðåííûé ðåæèì)</option>
<option value='{$this->ipsclass->adskin->base_url}&section=lookandfeel&act=style&code=colouredit&id={$r['set_skin_set_id']}&p={$r['set_skin_set_parent']}'>Èçìåíèòü CSS ñòèëè (ïðîñòîé ðåæèì)</option>
<option value='{$this->ipsclass->adskin->base_url}&section=lookandfeel&act=image&code=edit&id={$r['set_skin_set_id']}&p={$r['set_skin_set_parent']}'>Èçìåíèòü ìàêðîñû</option>
</select>
</form>";
return $html;
}
}
?>