PHP Classes
Icontem

File: as_admintool.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alexander Selifonov  >  site administrator tool set  >  as_admintool.php  
File: as_admintool.php
Role: Class source
Content type: text/plain
Description: Main class module
Class: site administrator tool set
Web interface to manage site resources
 

Contents

Class file image Download
<?php
/**
* @package as_admintool
* @desc as_admintool.php - site Administrator functions class (AJAX based)
* @author Alexander Selifonov <as-works@narod.ru>
* @copyright Alexander Selifonov 2007-2008
* @link http://as-works.narod.ru/en/php/
* @version 1.001.005
* modified 18.04.2008 (dd.mm.yyyy)
* Please read "as_admintool.htm" for detailed instructions
*/
require_once('as_dbutils.php');
require_once(
'as_propsheet.php');

if(!
defined('ASADM_CHARSET')) define('ASADM_CHARSET','WINDOWS-1251'); // default charset on HTML pages
if(!defined('ASADM_CHARSETCL')) define('ASADM_CHARSETCL','WINDOWS-1251'); // default charset on HTML pages

// localization is done by setting $as_iface vars
if(empty($as_iface['msg_waiting'])) $as_iface['msg_waiting'] ='waiting for server reply...';
if(empty(
$as_iface['msg_wrongreply'])) $as_iface['msg_wrongreply'] ='Wrong reply from server :';
if(empty(
$as_iface['title_serverresponse'])) $as_iface['title_serverresponse'] ='Response from server';



// css classnames:
if(!is_array($as_cssclass)) $as_cssclass = array();
if(empty(
$as_cssclass['textfield'])) $as_cssclass['textfield'] = 'ibox';
if(empty(
$as_cssclass['button'])) $as_cssclass['button'] = 'button';
if(empty(
$as_cssclass['resultarea'])) $as_cssclass['resultarea'] = 'resultarea';
if(empty(
$as_cssclass['trowhead'])) $as_cssclass['trowhead'] = 'head';
if(empty(
$as_cssclass['tdhead'])) $as_cssclass['tdhead'] = 'head';
if(empty(
$as_cssclass['troweven'])) $as_cssclass['troweven'] = 'even';
if(empty(
$as_cssclass['trowodd'])) $as_cssclass['trowodd'] = 'odd';

$as_admt_charset ASADM_CHARSET// main charset
$as_admt_charsetcl ASADM_CHARSETCL// charset of data came from client

# $as_admt_pages - all added 'admin pages' list  :
#  [*][0]-plugin typeID,
#  [*][1]-page title,
#  [*][2]- user parameter-1 for drawing/handling page
#  [*][3]- user parameter-2 for drawing/handling page
#  [*][4]- user parameter-3 for drawing/handling page
if(!isset($as_admt_pages)) $as_admt_pages=array();

# $as_admt_plugins - array holding all "registered" admin plugins:
#  [0]-Drawing page PHP function name
#  [1]-executing query PHP function name
if(!isset($as_admt_plugins)) $as_admt_plugins=array();

# var for internal needs - remember active page for re-drawing screen after POST
if(!isset($asdt_curpage)) $asdt_curpage false;
# var for internal needs - will hold 'result' message to show after POST
if(!isset($asdt_result)) $asdt_result = array();

/**
* @desc This class is a container for 'admininstaror task' plugins
*/
class CAsAdminTool {
  var 
$wnd_w 0;
  var 
$wnd_h 0;
  var 
$sheet '';
  var 
$b_sqlqry true;
  var 
$b_export false;
  var 
$b_import false;
  var 
$tovar false;
//  var $charset = ASADM_CHARSET;
  
var $js_path ''// 'relative' path to as_jsfunclib.js module
  
var $udfpages = array(); // registered 'external user pages' list
  
var $_debug 0;
  function 
SetJsPath($strk) { $this->js_path $strk; }
  function 
ReadStdSqlFromFile($filename='') {
    global 
$as_adm_stdsqls;
    if(
$filename==='' || !is_file($filename)) $as_adm_stdsqls = array();
    else {
      
$tlst file($filename);
      foreach(
$tlst as $strk) {
        
$tval explode('|',trim($strk));
        if(
count($tval)>1$as_adm_stdsqls[$tval[0]] = $tval[1];
      }
    }
  }

/**
* @desc class constructor, sets up width and height for a wrapper window
*/
  
function CAsAdminTool($w_width=920$w_height=600) { // constructor
    
$this->wnd_w $w_width;
    
$this->wnd_h $w_height;
  }

  
/**
  * @desc registering new plugin
  * @param string $plgtype - unique plugin string ID
  * @param string $funchtml - user PHP function name, that draws HTML code
  * @param string $funcexec - name of 'request executing' function
  */
  
function RegisterPlugin($plgtype,$funchtml,$funcexec=''$func_stdpost='') {
    global 
$as_admt_plugins;
    
$as_admt_plugins[$plgtype] = array($funchtml,$funcexec,$func_stdpost);
  }
  function 
AddPage($pagetype$pagetitle$usrparam1=false,$usrparam2=false,$usrparam3=false) {
    global 
$as_admt_pages;
    
$as_admt_pages[] = array($pagetype$pagetitle$usrparam1,$usrparam2,$usrparam3);
#    return count($as_admt_pages);
  
}

   
/**
   * @desc draws "Property sheet" with all registered pages
   * @param $startpage - initially active page number
   * @paqram $tovar - if true/1, all HTML/JS code redirected to variable and function returns it
   * @return none or the whole HTML/JS code
   */
  
function Draw($startpage=false$tovar=false) {
    global 
$as_admt_plugins$as_admt_pages$asdt_curpage;
    static 
$as_admt_jsdrawn=false;
    
$this->tovar $tovar;
    if(empty(
$as_admt_jsdrawn)) {
       
$as_admt_jsdrawn true// draw JS functions once !
       
$this->DrawJsFunctions();
    }
    
$sheet = new CPropertySheet('admintool',$this->wnd_w,$this->wnd_hTABSTYLE);

    for(
$pgno=0$pgno<count($as_admt_pages); $pgno++) {
       
$pagetype $as_admt_pages[$pgno][0];
       
$funcname $as_admt_plugins[$pagetype][0];
       if(!empty(
$funcname) && function_exists($funcname))
         
$sheet->AddPage($as_admt_pages[$pgno][1],$funcname,  '', array($pgno,$this->wnd_w,$this->wnd_h),
           
$as_admt_pages[$pgno][2],$as_admt_pages[$pgno][3],$as_admt_pages[$pgno][4]);
    }
    if(
$startpage===false$startpage=$asdt_curpage;
    
$ret true;
    if(!empty(
$this->tovar)) ob_start();
    
$sheet->Draw($startpage$this->tovar);
    if(!empty(
$this->tovar)) $ret ob_get_flush();
    return 
$ret;
  }

  
// draw all plugin-specific javascript code
  
function DrawJsFunctions() {
    global 
$as_admt_plugins;
    echo 
"<script language='javascript' src='{$this->js_path}as_jsfunclib.js'></script>\n<script language='javascript'>\n";
    foreach(
$as_admt_plugins as $as_type=>$asdata) {
      if(!empty(
$asdata[2]) && function_exists($asdata[1])) call_user_func($asdata[1]);
    }
    echo 
"\n</script>\n";
  }

  
/**
  * You call this func from Your code if POST or GET var 'adm_action_type' has come
  * @return none, exits (PHP execution stops) when done
  * PHP5 : keyword "static" may be nessesary before 'function'
  */
  
function PerformAction() {
    global 
$as_admt_charset$as_admt_charsetcl$as_admt_plugins$asdt_curpage;
    
$parms array_merge($_POST,$_GET);
    if(!isset(
$parms['adm_action_type'])) return; // no need to do anything, just go on...
    
$typeid $parms['adm_action_type'];
    
$pageid = isset($parms['pageid'])?$parms['pageid']:'1';
    
$ret "$pageid{|}Wrong call / $typeid";
    if(!isset(
$as_admt_plugins[$typeid])) { echo "$pageid{|}undefined type: $typeid"; exit; }
    if(!empty(
$parms['as_stdpost'])) {
      
# non-ajax mode, so call 'std-post' user function
      
$asdt_curpage $pageid// to make the same page initially active, we came from
      
if(function_exists($as_admt_plugins[$typeid][2]))
        
$ret call_user_func($as_admt_plugins[$typeid][2]);
      return;
    }
    else { 
// ajax mode - echo result and EXIT
#      $parms = $_POST;
      
if(function_exists($as_admt_plugins[$typeid][1])) {
        if(
$as_admt_charsetcl!=='' && $as_admt_charsetcl !== 'UTF-8' && function_exists('mb_convert_variables'))
           
mb_convert_variables($as_admt_charsetcl,'UTF-8',$parms);
        
$ret call_user_func($as_admt_plugins[$typeid][1],$parms);
        if(
$as_admt_charset !== 'UTF-8' && $as_admt_charset!=='' && function_exists('mb_convert_encoding'))
          
$ret mb_convert_encoding($ret,'UTF-8',$as_admt_charset);
      }
      else 
$ret "as_admintool: Wrong function for $typeid: {$as_admt_plugins[$typeid][1]}";
      echo 
$ret;
      exit;
    }
  }
# class CAsAdminTool end
/**
* @desc returns file extension (lower case) : "path/image.jpg" -> "jpg"
*/
function asadmtFileExt($fname) {
  if(empty(
$fname)) return '';
  
$path_info pathinfo($fname);
  return 
strtolower($path_info['extension']);
}

?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products