Move custom field functions to new bo class, and implement in calls within this application

This commit is contained in:
Miles Lott 2005-07-02 20:20:06 +00:00
parent 47d7968d60
commit 8e4a4edb51
4 changed files with 121 additions and 97 deletions

View File

@ -247,7 +247,7 @@
// return array with all addressbook customfields (for xmlrpc)
function customfields($new_fields=False)
{
$fields = CreateObject('addressbook.uifields',True); // no extra bo-class
$fields = CreateObject('addressbook.bofields');
if(is_array($new_fields) && count($new_fields))
{
@ -257,17 +257,17 @@
}
foreach($new_fields as $new)
{
$fields->save_custom_field('',$new);
$fields->_save('',$new);
}
}
$customfields = array();
foreach($fields->read_custom_fields() as $data)
foreach($fields->_read() as $data)
{
$customfields[$data['name']] = $data['title'];
}
if($this->xmlrpc && !isset($customfields['freebusy_url']))
{
$fields->save_custom_field('','freebusy URL');
$fields->_save('','freebusy URL');
$customfields['freebusy_url'] = 'freebusy URL';
}
return $customfields;

View File

@ -0,0 +1,98 @@
<?php
/**************************************************************************\
* eGroupWare - Addressbook *
* http://www.egroupware.org *
* Written by Joseph Engo <jengo@phpgroupware.org> and *
* Miles Lott <milosch@groupwhere.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 bofields
{
var $so;
function bofields()
{
/* Config class here is the so object */
$this->so = CreateObject('phpgwapi.config','addressbook');
}
function _read($start=0,$limit=5,$query='')
{
$i = 0;
$fields = array();
$this->so->read_repository();
while(list($name,$descr) = @each($this->so->config_data['custom_fields']))
{
/*
if($start < $i)
{
continue;
}
*/
$test = @strtolower($name);
//if($query && !strstr($test,strtolower($query)))
if($query && ($query != $test))
{
}
else
{
$fields[$i]['name'] = $name;
$fields[$i]['title'] = $descr;
$fields[$i]['id'] = $i;
/*
if($i >= $limit)
{
break;
}
*/
$i++;
}
}
switch($sort)
{
case 'DESC';
krsort($fields);
break;
case 'ASC':
default:
ksort($fields);
}
@reset($fields);
return $fields;
}
function _save($old='',$new='')
{
$this->so->read_repository();
if(!is_array($this->so->config_data['custom_fields']))
{
$this->so->config_data['custom_fields'] = array();
}
if($old)
{
unset($this->so->config_data['custom_fields'][$old]);
}
if($new)
{
$tmp = strtolower(str_replace(' ','_',$new));
$this->so->config_data['custom_fields'][$tmp] = $new;
}
$this->so->save_repository();
}
}
?>

View File

@ -62,7 +62,7 @@
$GLOBALS['egw']->country = CreateObject('phpgwapi.country');
$GLOBALS['egw']->browser = CreateObject('phpgwapi.browser');
$GLOBALS['egw']->nextmatchs = CreateObject('phpgwapi.nextmatchs');
$this->fields = CreateObject('addressbook.uifields');
$this->fields = CreateObject('addressbook.bofields');
$this->bo = CreateObject('addressbook.boaddressbook',True);
$this->cat = CreateObject('phpgwapi.categories');
@ -282,7 +282,7 @@
unset($aar);
unset($char);
$custom = $this->fields->read_custom_fields();
$custom = $this->fields->_read();
$customfields = array();
// while(list($x,$y) = @each($custom))
foreach($custom as $x => $y)
@ -685,7 +685,7 @@
function copy()
{
$custom = $this->fields->read_custom_fields();
$custom = $this->fields->_read();
$customfields = array();
// while(list($x,$y) = @each($custom))
foreach($custom as $x => $y)
@ -740,7 +740,7 @@
$GLOBALS['egw']->common->phpgw_header();
echo parse_navbar();
$custom = $this->fields->read_custom_fields();
$custom = $this->fields->_read();
foreach($custom as $x => $y)
{
$customfields[$y['name']] = $y['title'];
@ -803,7 +803,7 @@
echo parse_navbar();
/* Read in user custom fields, if any */
$custom = $this->fields->read_custom_fields();
$custom = $this->fields->_read();
$customfields = array();
// while(list($x,$y) = @each($custom))
foreach($custom as $x => $y)
@ -962,7 +962,7 @@
$GLOBALS['egw']->template->set_block('view_t','view_footer','view_footer');
$GLOBALS['egw']->template->set_block('view_t','view_buttons','view_buttons');
$custom = $this->fields->read_custom_fields();
$custom = $this->fields->_read();
$customfields = array();
// while(list($x,$y) = @each($custom))
foreach($custom as $x => $y)
@ -1188,7 +1188,7 @@
$other = $_POST['other'];
$fcat_id = (int)$_POST['fcat_id'];
$custom = $this->fields->read_custom_fields();
$custom = $this->fields->_read();
$customfields = array();
// while(list($x,$y) = @each($custom))
foreach($custom as $x => $y)
@ -1451,7 +1451,7 @@
}
$fields['adr_two_type'] = substr($typeb,0,-1);
$custom = $this->fields->read_custom_fields();
$custom = $this->fields->_read();
foreach($custom as $name => $val)
{
$fields[$val['name']] = $entry[$val['name']];

View File

@ -21,15 +21,13 @@
'edit' => True,
'delete' => True
);
var $bo;
function uifields($only_bo=False)
function uifields()
{
if (!$only_bo)
{
$GLOBALS['egw']->template = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$GLOBALS['egw']->nextmatchs = CreateObject('phpgwapi.nextmatchs');
}
$this->config = CreateObject('phpgwapi.config','addressbook');
$GLOBALS['egw']->template = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$GLOBALS['egw']->nextmatchs = CreateObject('phpgwapi.nextmatchs');
$this->bo = CreateObject('addressbook.bofields');
}
function index()
@ -79,7 +77,7 @@
$sort = 'ASC';
}
$fields = $this->read_custom_fields($start,$limit,$query,$sort);
$fields = $this->bo->_read($start,$limit,$query,$sort);
$total_records = count($fields);
$GLOBALS['egw']->common->phpgw_header();
@ -157,7 +155,7 @@
$error[$errorcount++] = lang('Please enter a name for that field !');
}
$fields = $this->read_custom_fields($start,$limit,$field_name);
$fields = $this->bo->_read($start,$limit,$field_name);
if($fields[0]['name'])
{
$error[$errorcount++] = lang('That field name has been used already !');
@ -165,7 +163,7 @@
if(!$error)
{
$this->save_custom_field($field,$field_name);
$this->bo->_save($field,$field_name);
}
}
@ -245,7 +243,7 @@
if(!$error)
{
$this->save_custom_field($field,$field_name);
$this->bo->_save($field,$field_name);
}
}
@ -271,7 +269,7 @@
}
else
{
$fields = $this->read_custom_fields($start,$limit,$field);
$fields = $this->bo->_read($start,$limit,$field);
$field = $GLOBALS['egw']->strip_html($fields[0]['title']);
$fn = $fields[0]['name'];
}
@ -320,7 +318,7 @@
if($_POST['confirm'])
{
$this->save_custom_field($field);
$this->bo->_save($field);
Header('Location: ' . $GLOBALS['egw']->link('/index.php',"menuaction=addressbook.uifields.index&start=$start&query=$query&sort=$sort"));
}
else
@ -356,77 +354,5 @@
$GLOBALS['egw']->template->pparse('out','field_delete');
}
}
function read_custom_fields($start=0,$limit=5,$query='')
{
$i = 0;
$fields = array();
$this->config->read_repository();
while(list($name,$descr) = @each($this->config->config_data['custom_fields']))
{
/*
if($start < $i)
{
continue;
}
*/
$test = @strtolower($name);
//if($query && !strstr($test,strtolower($query)))
if($query && ($query != $test))
{
}
else
{
$fields[$i]['name'] = $name;
$fields[$i]['title'] = $descr;
$fields[$i]['id'] = $i;
/*
if($i >= $limit)
{
break;
}
*/
$i++;
}
}
switch($sort)
{
case 'DESC';
krsort($fields);
break;
case 'ASC':
default:
ksort($fields);
}
@reset($fields);
return $fields;
}
function save_custom_field($old='',$new='')
{
$this->config->read_repository();
if(!is_array($this->config->config_data['custom_fields']))
{
$this->config->config_data['custom_fields'] = array();
}
if($old)
{
unset($this->config->config_data['custom_fields'][$old]);
}
if($new)
{
$tmp = strtolower(str_replace(' ','_',$new));
$this->config->config_data['custom_fields'][$tmp] = $new;
}
$this->config->save_repository();
}
}
?>