[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] CVS: sitemgr/inc class.Block_SO.inc.php,NONE,1.1 clas
From: |
Michael Totschnig <address@hidden> |
Subject: |
[Phpgroupware-cvs] CVS: sitemgr/inc class.Block_SO.inc.php,NONE,1.1 class.Blocks_BO.inc.php,NONE,1.1 class.Blocks_SO.inc.php,NONE,1.1 class.ManageBlocks_UI.inc.php,NONE,1.1 |
Date: |
Thu, 05 Dec 2002 23:57:20 -0500 |
Update of /cvsroot/phpgroupware/sitemgr/inc
In directory subversions:/tmp/cvs-serv30281/inc
Added Files:
class.Block_SO.inc.php class.Blocks_BO.inc.php
class.Blocks_SO.inc.php class.ManageBlocks_UI.inc.php
Log Message:
new files for the blockmanager
--- NEW FILE ---
<?php
class Block_SO
{
var $id;
var $filename;
var $side;
var $pos;
var $title;
var $view;
var $description;
var $actif;
function Block_SO()
{
}
}
?>
--- NEW FILE ---
<?php
class Blocks_BO
{
var $so;
var $preferenceso;
var $blockdir;
function Blocks_BO()
{
$this->so = CreateObject('sitemgr.Blocks_SO', True);
$this->preferenceso =
CreateObject('sitemgr.sitePreference_SO', true);
$this->blockdir =
$this->preferenceso->getPreference('sitemgr-site-dir') . SEP . 'blocks';
}
function getavailableblocks()
{
$d = dir($this->blockdir);
if (!$d)
{
return 1;
}
while ($entry = $d->read())
{
if (preg_match ("/block-.*.php$/", $entry,
$block))
{
$blocks_filesystem[] = $block[0];
}
}
$d->close();
if (count($blocks_filesystem) < 1)
{
return 2;
}
//delete vanished blocks from database
$blocks_database = $this->so->getblocknames();
foreach ($blocks_database as $blockname)
{
if (!in_array($blockname,$blocks_filesystem))
{
$this->so->deleteblock($blockname);
}
}
return $blocks_filesystem;
}
function getblockinfo($blockname)
{
$blockinfo = $this->so->getblockinfo($blockname);
if ($blockinfo)
{
return $blockinfo;
}
else
{
$blockinfo =
$this->getblockinfo_fromfile($blockname);
$blockinfo->id =
$this->so->addblock($blockinfo);
if (!$blockinfo->id)
{
$blockinfo->title = lang("There was an
error writing to the database");
}
return $blockinfo;
}
}
function getblockinfo_fromfile($blockname)
{
$blockinfo = CreateObject('sitemgr.Block_SO', True);
$blockinfo->filename = $blockname;
$filename = $this->blockdir . SEP . $blockname;
$blockfile = file($filename);
$blockconfig = preg_grep('/\\\* blockconfig:
.*\\\*/',$blockfile);
if ($blockconfig)
{
foreach (array("title", "description", "view")
as $config)
{
foreach ($blockconfig as $configline)
{
if
(preg_match('/<'.$config.'>(.*)<\/'.$config.'>/',$configline,$value))
{
$blockinfo->$config =
$value[1];
continue 2;
}
}
$blockinfo->$config = lang('No value
for %1 found in blockfile',$config);
}
}
else
{
$blockinfo->title = lang('No blockinfo found in
blockfile');
}
return $blockinfo;
}
function saveblockinfo($blockinfo)
{
return $this->so->saveblockinfo($blockinfo);
}
}
?>
--- NEW FILE ---
<?php
class Blocks_SO
{
var $db;
function Blocks_SO()
{
$this->db = $GLOBALS['phpgw']->db;
$this->sides = array('0' => 'l','1' => 'c','2' => 'r');
}
function getblockinfo($blockname)
{
$sql = "SELECT * FROM phpgw_sitemgr_blocks WHERE
filename='$blockname'";
$this->db->query($sql,__LINE__,__FILE__);
if ($this->db->next_record())
{
$blockinfo = CreateObject('sitemgr.Block_SO',
True);
$blockinfo->id = $this->db->f('block_id');
$blockinfo->actif = $this->db->f('actif');
$blockinfo->title =
stripslashes($this->db->f('title'));
$blockinfo->description =
stripslashes($this->db->f('description'));
$blockinfo->filename = $blockname;
$blockinfo->side = $this->db->f('side');
$blockinfo->view = $this->db->f('view');
$blockinfo->pos = $this->db->f('pos');
return $blockinfo;
}
else
{
return false;
}
}
function addblock($blockinfo)
{
$sql = "INSERT INTO phpgw_sitemgr_blocks
(filename,title,description,view) VALUES ('" .
$blockinfo->filename . "', '" .
addslashes($blockinfo->title) .
"', '" . addslashes($blockinfo->description) .
"', " . (int)$blockinfo->view . ")";
$this->db->query($sql,__LINE__,__FILE__);
return
$this->db->get_last_insert_id('phpgw_sitemgr_blocks','block_id');
}
function saveblockinfo($blockinfo)
{
$sql = "UPDATE phpgw_sitemgr_blocks SET " .
"title='" . addslashes($blockinfo->title) .
"', actif=" . (int)$blockinfo->actif .
", pos=" . (int)$blockinfo->pos .
", side=" . (int)$blockinfo->side .
", view=" . (int)$blockinfo->view .
" WHERE block_id=" . $blockinfo->id;
$this->db->query($sql,__LINE__,__FILE__);
}
function getactiveblocks()
{
$sql = "SELECT title,filename,view,side FROM
phpgw_sitemgr_blocks WHERE actif=1 ORDER BY pos";
$this->db->query($sql,__LINE__,__FILE__);
$i=0;
while ($this->db->next_record())
{
$blocks[$i]['title'] =
stripslashes($this->db->f('title'));
$blocks[$i]['filename'] =
$this->db->f('filename');
$blocks[$i]['view'] = $this->db->f('view');
$blocks[$i]['side'] =
$this->sides[$this->db->f('side')];
$i++;
}
return $blocks;
}
function getblocknames()
{
$sql = "SELECT filename FROM phpgw_sitemgr_blocks";
$this->db->query($sql,__LINE__,__FILE__);
while ($this->db->next_record())
{
$blocks[] = $this->db->f('filename');
}
return $blocks;
}
function deleteblock($blockname)
{
$sql = "DELETE FROM phpgw_sitemgr_blocks WHERE
filename='$blockname'";
return $this->db->query($sql,__LINE__,__FILE__);
}
}
?>
--- NEW FILE ---
<?php
/***************************************************************************\
* phpGroupWare - Web Content Manager
*
* http://www.phpgroupware.org
*
* -------------------------------------------------
*
* 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.
*
\***************************************************************************/
class ManageBlocks_UI
{
var $t;
var $block_bo;
var $common_ui;
var $public_functions = array
(
'_manageBlocks' => True
);
function ManageBlocks_UI()
{
$this->t = $GLOBALS['phpgw']->template;
$this->block_bo = CreateObject('sitemgr.Blocks_BO',
True);
$this->common_ui =
CreateObject('sitemgr.Common_UI',True);
}
function globalize($varname)
{
if (is_array($varname))
{
foreach($varname as $var)
{
$GLOBALS[$var] = $_POST[$var];
}
}
else
{
$GLOBALS[$varname] = $_POST[$varname];
}
}
function inputOption($name = '', $options='', $default = '')
{
$returnValue = '<SELECT NAME="'.$name.'">'."\n";
while (list($value,$display) = each($options))
{
$selected='';
if ($default == $value)
{
$selected = 'SELECTED ';
}
$returnValue.='<OPTION
'.$selected.'VALUE="'.$value.'">'.
$display.'</OPTION>'."\n";
}
$returnValue .= '</SELECT>';
return $returnValue;
}
function _manageBlocks()
{
$this->globalize(array('blocktitle','blockactif','blockpos','blockside','blockview','btnSaveBlock'));
global $blocktitle, $blockactif, $blockpos, $blockside,
$blockview, $btnSaveBlock;
$this->common_ui->DisplayHeader();
if ($btnSaveBlock)
{
$blockinfo = CreateObject('sitemgr.Block_SO',
True);
foreach ($blocktitle as $id => $title)
{
$blockinfo->id = $id;
$blockinfo->title = $title;
$blockinfo->actif = $blockactif[$id] ?
1 : 0;
$blockinfo->pos = $blockpos[$id];
$blockinfo->side = $blockside[$id];
$blockinfo->view = $blockview[$id];
$this->block_bo->saveblockinfo($blockinfo);
}
}
$blocks = $this->block_bo->getavailableblocks();
if (is_array($blocks))
{
$this->t->set_file('ManageBlocks',
'manage_blocks.tpl');
$this->t->set_block('ManageBlocks',
'BlockBlock', 'BBlock');
$this->t->set_var(Array('block_manager' =>
lang('Block Manager'),
'lang_description' =>
lang('Description'),
'lang_actif' => lang('actif'),
'lang_name' => lang('Name'),
'lang_title' => lang('Title'),
'lang_side' => lang('side'),
'lang_view' => lang('seen by'),
'lang_reset' => lang('Reset'),
'lang_save' => lang('Save'),
'lang_position' => lang('Position')));
foreach ($blocks as $blockname)
{
$blockinfo =
$this->block_bo->getblockinfo($blockname);
preg_match("/block-(.*).php$/",
$blockname, $match);
$this->t->set_var(Array(
'blockname' => $match[1],
'blockdescription' =>
$blockinfo->description,
'blockid' => $blockinfo->id,
'blockactif' =>
($blockinfo->actif ? 'checked="checked"' : ''),
'blocktitle' =>
$blockinfo->title,
'sideselect' =>
$this->inputOption(
'blockside['.$blockinfo->id.']',
array('0' => 'left','1' => 'center','2' => 'right'),
$blockinfo->side),
'viewselect' =>
$this->inputOption(
'blockview['.$blockinfo->id.']',
array(
'0'
=> 'everybody',
'1'
=> 'phpgw users',
'2'
=> 'administrators',
'3'
=> 'anonymous'),
$blockinfo->view),
'blockpos' =>
(int)$blockinfo->pos
)
);
$this->t->parse('BBlock','BlockBlock',
true);
}
$this->t->pfp('out', 'ManageBlocks');
}
else
{
echo '<b>' .
(($blocks == 1) ?
lang('Blockfile directory not found') :
lang('No blockfiles found in blockfile
directory')) .
'</b>';
}
$this->common_ui->DisplayFooter();
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] CVS: sitemgr/inc class.Block_SO.inc.php,NONE,1.1 class.Blocks_BO.inc.php,NONE,1.1 class.Blocks_SO.inc.php,NONE,1.1 class.ManageBlocks_UI.inc.php,NONE,1.1,
Michael Totschnig <address@hidden> <=