cleaned up problems with utilities classes

This commit is contained in:
seek3r 2001-01-12 04:07:40 +00:00
parent d904f8b239
commit 970c3090cf
13 changed files with 199 additions and 369 deletions

View File

@ -16,8 +16,8 @@
$phpgw_info["flags"] = array("currentapp" => "calendar", "enable_nextmatchs_class" => True);
include("../header.inc.php");
include($phpgw_info["server"]["api_inc"] . "/phpgw_utilities_sbox.inc.php");
$sb = new sbox;
$sb = CreateObject("phpgwapi.sbox");
$cal_info = new calendar_item;

View File

@ -0,0 +1,74 @@
<?php
/**************************************************************************\
* phpGroupWare - API *
* 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. *
\**************************************************************************/
/* $Id$ */
if (!$phpgw_info["flags"]["included_classes"]["portalbox"]){
$phpgw_info["flags"]["included_classes"]["portalbox"] = True;
include($phpgw_info["server"]["include_root"]."/".$appname."/inc/class.portalbox.inc.php");
}
class linkbox extends portalbox {
/*
Set up the Object. You will notice, we have not reserved
memory space for variables. In this circumstance it is not necessary.
*/
/*
This is the constructor for the linkbox. The only thing this does
is to call the constructor of the parent class. Why? Well, whilst
PHP manages a certain part of OO, one of the bits it falls down on
(at the moment) is constructors within sub-classes. So, to
be sure that the sub-class is instantiated with the constructor of
the parent class, I simply call the parent constructor. Of course,
if I then wanted to override any of the values, I could easily do so.
*/
function linkbox($param) {
$title = $param[0];
$primary = $param[1];
$secondary =$param[2];
$tertiary = $param[3];
$this->portalbox($title, $primary, $secondary, $tertiary);
$this->setvar("outerwidth",300);
$this->setvar("innerwidth",300);
$this->setvar("width",300);
}
/*
This is the only method within the class. Quite simply, as you can see
it draws the table(s), placing the required data in the appropriate place.
*/
function draw() {
global $phpgw, $phpgw_info;
$p = new Template($phpgw->common->get_tpl_dir('home'));
$p->set_file(array('portal_main' => 'portal_main.tpl',
'portal_linkbox_header' => 'portal_linkbox_header.tpl',
'portal_linkbox' => 'portal_linkbox.tpl',
'portal_linkbox_footer' => 'portal_linkbox_footer.tpl'));
$p->set_block('portal_main','portal_linkbox_header','portal_linkbox','portal_linkbox_footer');
$p->set_var('outer_border',$this->getvar('outerborderwidth'));
$p->set_var('outer_width',$this->getvar('width'));
$p->set_var('outer_bordercolor',$this->getvar('outerbordercolor'));
$p->set_var('outer_bgcolor',$this->getvar('titlebgcolor'));
$p->set_var('title',$this->getvar('title'));
$p->set_var('inner_width',$this->getvar('width'));
$p->set_var('inner_bgcolor',$this->getvar('innerbgcolor'));
$p->set_var('header_background_image',$this->getvar('header_background_image'));
$p->parse('output','portal_linkbox_header',True);
for ($x = 0; $x < count($this->data); $x++) {
$p->set_var('link',$this->data[$x][1]);
$p->set_var('text',$this->data[$x][0]);
$p->parse('output','portal_linkbox',True);
}
$p->parse('output','portal_linkbox_footer',True);
return $p->parse('out','portal_main');
}
}

View File

@ -0,0 +1,66 @@
<?php
/**************************************************************************\
* phpGroupWare - API *
* 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. *
\**************************************************************************/
/* $Id$ */
class portalbox {
//Set up the Object, reserving memory space for variables
var $outerwidth;
var $outerbordercolor;
var $outerborderwidth;
var $titlebgcolor;
var $width;
var $innerwidth;
var $innerbgcolor;
// Textual variables
var $title;
/*
Use these functions to get and set the values of this
object's variables. This is good OO practice, as it means
that datatype checking can be completed and errors raised accordingly.
*/
function setvar($var,$value="") {
if ($value=="") {
global $$var;
$value = $$var;
}
$this->$var = $value;
// echo $var." = ".$this->$var."<br>\n";
}
function getvar($var="") {
if ($var=="" || !isset($this->$var)) {
global $phpgw;
echo 'Programming Error: '.$this->classname().'->getvar('.$var.')!<br>\n';
$phpgw->common->phpgw_exit();
}
//echo "Var = ".$var."<br>\n";
//echo $var." = ".$this->$var."<br>\n";
return $this->$var;
}
/*
This is the constructor for the object.
*/
function portalbox($title="", $primary="", $secondary="", $tertiary="") {
$this->setvar("title",$title);
// echo "After SetVar Title = ".$this->getvar("title")."<br>\n";
$this->setvar("outerborderwidth",1);
$this->setvar("titlebgcolor",$primary);
$this->setvar("innerbgcolor",$secondary);
$this->setvar("outerbordercolor",$tertiary);
}
// Methods
}

View File

@ -0,0 +1,49 @@
<?php
/**************************************************************************\
* phpGroupWare - API *
* 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. *
\**************************************************************************/
/* $Id$ */
if (!$phpgw_info["flags"]["included_classes"]["portalbox"]){
$phpgw_info["flags"]["included_classes"]["portalbox"] = True;
include($phpgw_info["server"]["include_root"]."/".$appname."/inc/class.portalbox.inc.php");
}
class resultbox extends portalbox {
/*
Set up the Object. You will notice, we have not reserved memory
space for variables. In this circumstance it is not necessary.
*/
//constructor
function resultbox($title="", $primary="", $secondary="", $tertiary="") {
$this->portalbox($title, $primary, $secondary, $tertiary);
$this->setvar("outerwidth",400);
$this->setvar("innerwidth",400);
}
/*
This is the only method within the class. Quite simply, as you can see
it draws the table(s), placing the required data in the appropriate place.
*/
function draw() {
echo '<table border="'.$this->getvar("outerborderwidth").'" cellpadding="0" cellspacing="0" width="'.$this->getvar("outerwidth").'" bordercolor="'.$this->getvar("outerbordercolor").'" bgcolor="'.$this->getvar("titlebgcolor").'">';
echo '<tr><td align="center">'.$this->getvar("title").'</td></tr>';
echo '<tr><td>';
echo '<table border="0" cellpadding="0" cellspacing="0" width="'.$this->getvar("innerwidth").'" bgcolor="'.$this->getvar("innerbgcolor").'">';
for ($x = 0; $x < count($this->data); $x++) {
echo '<tr>';
echo '<td width="50%">'.$this->data[$x][0].'</td>';
echo '<td width="50%">'.$this->data[$x][1].'</td>';
echo '</tr>';
}
echo '</table>';
echo '</td></tr>';
echo '</table>';
}
}

View File

@ -36,6 +36,7 @@
$phpgw->matrixview = CreateObject("phpgwapi.matrixview");
$phpgw->menutree = CreateObject("phpgwapi.menutree");
$phpgw->sbox = CreateObject("phpgwapi.sbox");
$phpgw->sbox = CreateObject("phpgwapi.portalbox");
}
}
?>

View File

@ -1,155 +0,0 @@
<?php
/**************************************************************************\
* phpGroupWare - API *
* 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. *
\**************************************************************************/
/* $Id$ */
class baseportalbox {
//Set up the Object, reserving memory space for variables
var $outerwidth;
var $outerbordercolor;
var $outerborderwidth;
var $titlebgcolor;
var $width;
var $innerwidth;
var $innerbgcolor;
// Textual variables
var $title;
/*
Use these functions to get and set the values of this
object's variables. This is good OO practice, as it means
that datatype checking can be completed and errors raised accordingly.
*/
function setvar($var,$value="") {
if ($value=="") {
global $$var;
$value = $$var;
}
$this->$var = $value;
// echo $var." = ".$this->$var."<br>\n";
}
function getvar($var="") {
if ($var=="" || !isset($this->$var)) {
global $phpgw;
echo 'Programming Error: '.$this->classname().'->getvar('.$var.')!<br>\n';
$phpgw->common->phpgw_exit();
}
//echo "Var = ".$var."<br>\n";
//echo $var." = ".$this->$var."<br>\n";
return $this->$var;
}
/*
This is the constructor for the object.
*/
function baseportalbox($title="", $primary="", $secondary="", $tertiary="") {
$this->setvar("title",$title);
// echo "After SetVar Title = ".$this->getvar("title")."<br>\n";
$this->setvar("outerborderwidth",1);
$this->setvar("titlebgcolor",$primary);
$this->setvar("innerbgcolor",$secondary);
$this->setvar("outerbordercolor",$tertiary);
}
// Methods
}
class linkbox extends baseportalbox {
/*
Set up the Object. You will notice, we have not reserved
memory space for variables. In this circumstance it is not necessary.
*/
/*
This is the constructor for the linkbox. The only thing this does
is to call the constructor of the parent class. Why? Well, whilst
PHP manages a certain part of OO, one of the bits it falls down on
(at the moment) is constructors within sub-classes. So, to
be sure that the sub-class is instantiated with the constructor of
the parent class, I simply call the parent constructor. Of course,
if I then wanted to override any of the values, I could easily do so.
*/
function linkbox($title="", $primary="", $secondary="", $tertiary="") {
$this->baseportalbox($title, $primary, $secondary, $tertiary);
$this->setvar("outerwidth",300);
$this->setvar("innerwidth",300);
$this->setvar("width",300);
}
/*
This is the only method within the class. Quite simply, as you can see
it draws the table(s), placing the required data in the appropriate place.
*/
function draw() {
global $phpgw, $phpgw_info;
$p = new Template($phpgw->common->get_tpl_dir('home'));
$p->set_file(array('portal_main' => 'portal_main.tpl',
'portal_linkbox_header' => 'portal_linkbox_header.tpl',
'portal_linkbox' => 'portal_linkbox.tpl',
'portal_linkbox_footer' => 'portal_linkbox_footer.tpl'));
$p->set_block('portal_main','portal_linkbox_header','portal_linkbox','portal_linkbox_footer');
$p->set_var('outer_border',$this->getvar('outerborderwidth'));
$p->set_var('outer_width',$this->getvar('width'));
$p->set_var('outer_bordercolor',$this->getvar('outerbordercolor'));
$p->set_var('outer_bgcolor',$this->getvar('titlebgcolor'));
$p->set_var('title',$this->getvar('title'));
$p->set_var('inner_width',$this->getvar('width'));
$p->set_var('inner_bgcolor',$this->getvar('innerbgcolor'));
$p->set_var('header_background_image',$this->getvar('header_background_image'));
$p->parse('output','portal_linkbox_header',True);
for ($x = 0; $x < count($this->data); $x++) {
$p->set_var('link',$this->data[$x][1]);
$p->set_var('text',$this->data[$x][0]);
$p->parse('output','portal_linkbox',True);
}
$p->parse('output','portal_linkbox_footer',True);
return $p->parse('out','portal_main');
}
}
class resultbox extends baseportalbox {
/*
Set up the Object. You will notice, we have not reserved memory
space for variables. In this circumstance it is not necessary.
*/
//constructor
function resultbox($title="", $primary="", $secondary="", $tertiary="") {
$this->baseportalbox($title, $primary, $secondary, $tertiary);
$this->setvar("outerwidth",400);
$this->setvar("innerwidth",400);
}
/*
This is the only method within the class. Quite simply, as you can see
it draws the table(s), placing the required data in the appropriate place.
*/
function draw() {
echo '<table border="'.$this->getvar("outerborderwidth").'" cellpadding="0" cellspacing="0" width="'.$this->getvar("outerwidth").'" bordercolor="'.$this->getvar("outerbordercolor").'" bgcolor="'.$this->getvar("titlebgcolor").'">';
echo '<tr><td align="center">'.$this->getvar("title").'</td></tr>';
echo '<tr><td>';
echo '<table border="0" cellpadding="0" cellspacing="0" width="'.$this->getvar("innerwidth").'" bgcolor="'.$this->getvar("innerbgcolor").'">';
for ($x = 0; $x < count($this->data); $x++) {
echo '<tr>';
echo '<td width="50%">'.$this->data[$x][0].'</td>';
echo '<td width="50%">'.$this->data[$x][1].'</td>';
echo '</tr>';
}
echo '</table>';
echo '</td></tr>';
echo '</table>';
}
}
?>

View File

@ -1,208 +0,0 @@
<?PHP
/**
*
* class for creating predefines select boxes
*
* @author Marc Logemann [loge@mail.com]
* @version 0.9
* $Id$
*/
class sbox {
var $monthnames = array ("", "january", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
function hour_formated_text($name, $selected = 0)
{
global $phpgw;
$s = '<select name="' . $name . '">';
$t_s[$selected] = " selected";
for ($i=0; $i<24; $i++) {
$s .= '<option value="' . $i . '"' . $t_s[$i] . '>'
. $phpgw->common->formattime($i+1,"00") . '</option>';
$s .= "\n";
}
$s .= "</select>";
return $s;
}
function hour_text($name, $selected = 0)
{
global $phpgw;
$s = '<select name="' . $name . '">';
$t_s[$selected] = " selected";
for ($i=1; $i<13; $i++) {
$s .= '<option value="' . $i . '"' . $t_s[$i] . '>'
. $i . '</option>';
$s .= "\n";
}
$s .= "</select>";
return $s;
}
// I would like to add a increment feature
function sec_minute_text($name, $selected = 0)
{
$s = '<select name="' . $name . '">';
$t_s[$selected] = " selected";
for ($i=0; $i<60; $i++) {
$s .= '<option value="' . $i . '"' . $t_s[sprintf("%02d",$i)] . '>' . sprintf("%02d",$i) . '</option>';
$s .= "\n";
}
$s .= "</select>";
return $s;
}
function ap_text($name,$selected)
{
$selected = strtolower($selected);
$t[$selected] = " selected";
$s = '<select name="' . $name . '">'
. ' <option value="am"' . $t["am"] . '>am</option>'
. ' <option value="pm"' . $t["pm"] . '>pm</option>';
$s .= "</select>";
return $s;
}
function full_time($hour_name,$hour_selected,$min_name,$min_selected,$sec_name,$sec_selected,$ap_name,$ap_selected)
{
// This needs to be changed to support there time format preferences
$s = $this->hour_text($hour_name,$hour_selected)
. $this->sec_minute_text($min_name,$min_selected)
. $this->sec_minute_text($sec_name,$sec_selected)
. $this->ap_text($ap_name,$ap_selected);
return $s;
}
function getMonthText($name, $selected=0)
{
$out = "<select name=\"$name\">\n";
for($i=0;$i<count($this->monthnames);$i++)
{
$out .= "<option value=\"$i\"";
if($selected==$i) $out .= " SELECTED";
$out .= ">";
if($this->monthnames[$i]!="")
$out .= lang($this->monthnames[$i]);
else
$out .= "";
$out .= "</option>\n";
}
$out .= "</select>\n";
return $out;
}
function getDays($name, $selected=0)
{
$out = "<select name=\"$name\">\n";
for($i=0;$i<32;$i++)
{
if($i==0) $val = ""; else $val = $i;
$out .= "<option value=\"$val\"";
if($selected==$i) $out .= " SELECTED";
$out .= ">$val</option>\n";
}
$out .= "</select>\n";
return $out;
}
function getYears($name, $selected=0, $startYear=0)
{
if(!$startYear) $startYear = date("Y");
$out = "<select name=\"$name\">\n";
$out .= "<option value=\"\"";
if($selected == 0 OR $selected == "") $out .= " SELECTED";
$out .= "></option>\n";
for($i=$startYear - 1;$i<$startYear + 5;$i++)
{
$out .= "<option value=\"$i\"";
if($selected==$i) $out .= " SELECTED";
$out .= ">$i</option>\n";
}
$out .= "</select>\n";
return $out;
}
function getPercentage($name, $selected=0)
{
$out = "<select name=\"$name\">\n";
for($i=0;$i<101;$i=$i+10)
{
$out .= "<option value=\"$i\"";
if($selected==$i) $out .= " SELECTED";
$out .= ">$i%</option>\n";
}
$out .= "</select>\n";
// echo $out;
return $out;
}
function getPriority($name, $selected=2)
{
$arr = array("", "low", "normal", "high");
$out = "<select name=\"$name\">\n";
for($i=1;$i<count($arr);$i++)
{
$out .= "<option value=\"";
$out .= $i;
$out .= "\"";
if($selected==$i) $out .= " SELECTED";
$out .= ">";
$out .= lang($arr[$i]);
$out .= "</option>\n";
}
$out .= "</select>\n";
return $out;
}
function getAccessList($name, $selected="private")
{
$arr = array("private" => "Private",
"public" => "Global public",
"group" => "Group public");
if (ereg(",", $selected))
{
$selected = "group";
}
$out = "<select name=\"$name\">\n";
for(reset($arr);current($arr);next($arr))
{
$out .= '<option value="' . key($arr) . '"';
if($selected==key($arr)) $out .= " SELECTED";
$out .= ">" . pos($arr) . "</option>\n";
}
$out .= "</select>\n";
return $out;
}
function getGroups($groups, $selected="", $name="")
{
global $phpgw;
if(!$name) $name = "n_groups[]";
$out = '<select name="' . $name . '" multiple>';
while (list($null,$group) = each($groups)) {
$out .= '<option value="' . $group[0] . '"';
if (ereg("," . $group[0] . ",", $selected))
{
$out .= " SELECTED";
}
$out .= ">" . $group[1] . "</option>\n";
}
$out .= "</select>\n";
return $out;
}
}

View File

@ -27,11 +27,14 @@
function CreateObject($classname, $constructor_param = ""){
global $phpgw, $phpgw_info, $phpgw_domain;
$classpart = explode (".", $classname);
if (!$phpgw_info["flags"]["included_classes"][$classpart[1]]){
$phpgw_info["flags"]["included_classes"][$classpart[1]] = True;
include($phpgw_info["server"]["include_root"]."/".$classpart[0]."/inc/class.".$classpart[1].".inc.php");
$appname = $classpart[0];
$classname = $classpart[1];
if (!$phpgw_info["flags"]["included_classes"][$classname]){
$phpgw_info["flags"]["included_classes"][$classname] = True;
include($phpgw_info["server"]["include_root"]."/".$appname."/inc/class.".$classname.".inc.php");
}
$obj = new $classpart[1]($constructor_param);
// if ($constructor_param == ""){ $obj = new $classname; }else{$obj = new $classname($constructor_param); }
$obj = new $classname($constructor_param);
return $obj;
}