[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] infolog/inc class.customfields_widget.inc.php, 1.2 cl
From: |
ceb |
Subject: |
[Phpgroupware-cvs] infolog/inc class.customfields_widget.inc.php, 1.2 class.uicustomfields.inc.php, 1.2 |
Date: |
Thu, 24 Feb 2005 13:29:36 -0000 |
Update of infolog/inc
Added Files:
Branch: MAIN
class.customfields_widget.inc.php lines: +125 -0
class.uicustomfields.inc.php lines: +342 -0
Log Message:
added confirmation + email notification
====================================================
Index: class.customfields_widget.inc.php
<?php
/**********************************************************************\
* phpGroupWare - InfoLog *
* http://www.phpgroupware.org *
* This program is part of the GNU project, see http://www.gnu.org/ *
* *
* Copyright 2002, 2003 Free Software Foundation, Inc. *
* *
* Originally Written by Ralf Becker - <address@hidden> *
* -------------------------------------------- *
* 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.customfields_widget.inc.php,v 1.2 2005/01/05 22:12:05 ceb Exp $
*/
/*!
@class customfields_widget
@author ralfbecker
@abstract generates a template based on an array with definitions
@discussion This widget has neither a render nor a post_process
function as it only generates a template
*/
class customfields_widget
{
var $public_functions = array(
'pre_process' => True
);
var $human_name = 'InfoLog custom fields';
function customfields_widget($ui)
{
}
function
pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
{
if (!is_array($value))
{
$cell['type'] = 'label';
return True;
}
$tpl = new etemplate;
$tpl->init('*** generated custom fields for
InfoLog','','',0,'',0,0); // make an empty template
$typ = $value['###typ###'];
unset($value['###typ###']);
//echo '<pre style="text-aling: left;">';
print_r($value); echo "</pre>\n";
foreach($value as $name => $field)
{
if (!empty($field['typ']) && $field['typ'] !=
$typ)
{
continue; // not for our typ
}
$row_class = 'row';
$label =
&$tpl->new_cell(++$n,'label',$field['label'],'',array(
'no_lang' =>
substr(lang($field['label']),-1) == '*' ? 2 : 0
));
if (count($field['values'])) // selectbox
{
foreach($field['values'] as $key =>
$val)
{
if (substr($val =
lang($val),-1) != '*')
{
$field['values'][$key]
= $val;
}
}
$input =
&$tpl->new_cell($n,'select','','#'.$name,array(
'sel_options' =>
$field['values'],
'size' => $field['rows'],
'no_lang' => True
));
}
elseif ($field['rows'] > 1) //
textarea
{
$input =
&$tpl->new_cell($n,'textarea','','#'.$name,array(
'size' =>
$field['rows'].($field['len'] > 0 ? ','.intval($field['len']) : '')
));
}
elseif (intval($field['len']) > 0) //
regular input field
{
list($max,$shown) =
explode(',',$field['len']);
$input =
&$tpl->new_cell($n,'text','','#'.$name,array(
'size' => intval($shown > 0 ?
$shown : $max).','.intval($max)
));
}
else // header-row
{
$label['span'] = 'all';
$tpl->new_cell($n); // is
needed even if its over-span-ed
$row_class = 'th';
}
if (!empty($field['help']) && $row_class !=
'th')
{
$input['help'] = $field['help'];
$input['no_lang'] =
substr(lang($help),-1) == '*' ? 2 : 0;
}
$tpl->set_row_attributes($n,0,$row_class);
}
// create an empty line which (should) take all the
remaining height
$tpl->new_cell(++$n,'label','','',array(
'span' => 'all'
));
$tpl->set_row_attributes($n,'99%','row');
// set width of 1. (label) column to 100
$tpl->set_column_attributes(0,'100');
$tpl->set_rows_cols(); // msie (at least 5.5
shows nothing with div overflow=auto)
$tpl->size = '100%,100%'.($tpl->html->user_agent !=
'msie' ? ',,,,,auto' : '');
//echo '<pre style="text-align: left;">';
print_r($tpl); echo "</pre>\n";
if (count($tpl->data) < 2)
{
$cell['type'] = 'label';
return True;
}
$cell['size'] = ''; // no separate namespace
$cell['type'] = 'template';
$cell['name'] = $tpl->name;
$cell['obj'] = &$tpl;
return True; // extra Label is ok
}
}
====================================================
Index: class.uicustomfields.inc.php
<?php
/**********************************************************************\
* phpGroupWare - InfoLog *
* http://www.phpgroupware.org *
* This program is part of the GNU project, see http://www.gnu.org/ *
* *
* Copyright 2002, 2003 Free Software Foundation, Inc. *
* *
* Originally Written by Ralf Becker - <address@hidden> *
* -------------------------------------------- *
* 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.uicustomfields.inc.php,v 1.2 2005/01/05 22:12:05 ceb Exp $ */
class uicustomfields
{
var $public_functions = array
(
'edit' => True
);
function uicustomfields( )
{
$this->bo = CreateObject('infolog.boinfolog');
$this->tmpl = CreateObject('etemplate.etemplate');
$this->types = &$this->bo->enums['type'];
$this->status = &$this->bo->status;
$this->config = &$this->bo->config;
$this->fields = &$this->bo->customfields;
}
/*!
@function edit
@syntax edit( $content=0 )
@author ralfbecker
@abstract Edit/Create an InfoLog Custom fields, typ and status
@param $content Content from the eTemplate Exec
*/
function edit($content = 0)
{
$GLOBALS['phpgw_info']['flags']['app_header'] =
lang('InfoLog').' - '.lang('Custom fields, typ and status');
if (is_array($content))
{
//echo '<pre style="text-align: left;">';
print_r($content); echo "</pre>\n";
list($action) = @each($content['button']);
switch($action)
{
case 'create':
$this->create($content);
break;
case 'delete':
$this->delete($content);
break;
default:
if
(!$content['status']['create'] && !$content['status']['delete'] &&
!$content['fields']['create'] && !$content['fields']['delete'])
{
break; // typ change
}
case 'save':
case 'apply':
$this->update($content);
if ($action != 'save')
{
break;
}
case 'cancel':
$GLOBALS['phpgw']->redirect_link('/admin/');
exit;
}
}
else
{
list($typ) = each($this->types);
$content = array(
'typ' => $typ,
);
}
$readonlys = array();
$readonlys['button[delete]'] =
isset($this->bo->stock_enums['type'][$content['typ']]);
$content['status'] = array(
'default' =>
$this->status['defaults'][$content['typ']]
);
$n = 0;
foreach($this->status[$content['typ']] as $name =>
$label)
{
$content['status'][++$n] = array(
'name' => $name,
'label' => $label,
'disabled' => False
);
$preserv_status[$n]['old_name'] = $name;
if
(isset($this->bo->stock_status[$content['typ']][$name]))
{
$readonlys['status']["delete[$name]"] =
$readonlys['status'][$n.'[name]'] =
True;
}
$readonlys['status']["create$name"] = True;
}
$content['status'][++$n] = array('name'=>''); // new
line for create
$readonlys['status']["delete[]"] = True;
//echo 'customfields=<pre style="text-align: left;">';
print_r($this->fields); echo "</pre>\n";
$content['fields'] = array();
$n = 0;
foreach($this->fields as $name => $data)
{
if (is_array($data['values']))
{
$values = '';
foreach($data['values'] as $var =>
$value)
{
$values .= (!empty($values) ?
"\n" : '').$var.'='.$value;
}
$data['values'] = $values;
}
$content['fields'][++$n] = $data + array(
'name' => $name
);
$preserv_fields[$n]['old_name'] = $name;
$readonlys['fields']["create$name"] = True;
}
$content['fields'][++$n] = array('typ'=>'','order' =>
10 * $n); // new line for create
$readonlys['fields']["delete[]"] = True;
//echo '<p>uicustomfields.edit(content = <pre
style="text-align: left;">'; print_r($content); echo "</pre>\n";
//echo 'readonlys = <pre style="text-align: left;">';
print_r($readonlys); echo "</pre>\n";
$this->tmpl->read('infolog.customfields');
$this->tmpl->exec('infolog.uicustomfields.edit',$content,array(
'typ' => $this->types,
),$readonlys,array(
'status' => $preserv_status,
'fields' => $preserv_fields
));
}
function update_fields(&$content)
{
$typ = $content['typ'];
$fields = &$content['fields'];
$create = $fields['create'];
unset($fields['create']);
if ($fields['delete'])
{
list($delete) = each($fields['delete']);
unset($fields['delete']);
}
foreach($fields as $field)
{
$name = trim($field['name']);
$old_name = $field['old_name'];
if (!empty($delete) && $delete == $old_name)
{
unset($this->fields[$old_name]);
continue;
}
if (isset($field['name']) && empty($name) &&
($create || !empty($old_name))) // empty name not allowed
{
$content['error_msg'] = lang('Name must
not be empty !!!');
}
if (isset($field['old_name']))
{
if (!empty($name) && $old_name !=
$name) // renamed
{
unset($this->fields[$old_name]);
}
elseif (empty($name))
{
$name = $old_name;
}
}
elseif (empty($name)) // new item and
empty ==> ignore it
{
continue;
}
$values = array();
if (!empty($field['values']))
{
foreach(explode("\n",$field['values'])
as $line)
{
list($var,$value) =
split('=',trim($line),2);
$var = trim($var);
$values[$var] = empty($value) ?
$var : $value;
}
}
$this->fields[$name] = array(
'typ' => $field['typ'],
'label' => empty($field['label']) ?
$name : $field['label'],
'help' => $field['help'],
'values'=> $values,
'len' => $field['len'],
'rows' => intval($field['rows']),
'order' => intval($field['order'])
);
}
if (!function_exists('sort_by_order'))
{
function sort_by_order($arr1,$arr2)
{
return $arr1['order'] - $arr2['order'];
}
}
uasort($this->fields,sort_by_order);
$n = 0;
foreach($this->fields as $name => $data)
{
$this->fields[$name]['order'] = ($n += 10);
}
}
function update_status(&$content)
{
$typ = $content['typ'];
$status = &$content['status'];
$default = $status['default'];
unset($status['default']);
$create = $status['create'];
unset($status['create']);
if ($status['delete'])
{
list($delete) = each($status['delete']);
unset($status['delete']);
}
foreach($status as $stat)
{
$name = trim($stat['name']);
$old_name = $stat['old_name'];
if (!empty($delete) && $delete == $old_name)
{
unset($this->status[$typ][$old_name]);
continue;
}
if (isset($stat['name']) && empty($name) &&
($create || !empty($old_name))) // empty name not allowed
{
$content['error_msg'] = lang('Name must
not be empty !!!');
}
if (isset($stat['old_name']))
{
if (!empty($name) && $old_name !=
$name) // renamed
{
unset($this->status[$typ][$old_name]);
if ($default == $old_name)
{
$default = $name;
}
}
elseif (empty($name))
{
$name = $old_name;
}
}
elseif (empty($name)) // new item and
empty ==> ignore it
{
continue;
}
$this->status[$typ][$name] =
empty($stat['label']) ? $name : $stat['label'];
}
$this->status['defaults'][$typ] = empty($default) ?
$name : $default;
if
(!isset($this->status[$typ][$this->status['defaults'][$typ]]))
{
list($this->status['defaults'][$typ]) =
@each($this->status[$typ]);
}
}
function update(&$content)
{
$this->update_status($content);
$this->update_fields($content);
// save changes to repository
$this->save_repository();
}
function delete(&$content)
{
if
(isset($this->bo->stock_enums['type'][$content['typ']]))
{
$content['error_msg'] .= lang("You can't delete
one of the stock types !!!");
return;
}
unset($this->types[$content['typ']]);
unset($this->status[$content['typ']]);
unset($this->status['defaults'][$content['typ']]);
$content['typ'] = '';
// save changes to repository
$this->save_repository();
}
function create(&$content)
{
$new_name = trim($content['new_name']);
unset($content['new_name']);
if (empty($new_name) || isset($this->types[$new_name]))
{
$content['error_msg'] .= empty($new_name) ?
lang('You have to enter a name, to
create a new typ!!!') :
lang("Typ '%1' already exists
!!!",$new_name);
}
else
{
$this->types[$new_name] = $new_name;
$this->status[$new_name] = array(
'ongoing' => 'ongoing',
'done' => 'done'
);
$this->status['defaults'][$new_name] =
'ongoing';
// save changes to repository
$this->save_repository();
$content['typ'] = $new_name; // show the new
entry
}
}
function save_repository()
{
// save changes to repository
$this->config->value('types',$this->types);
//echo '<p>uicustomfields::save_repository()
\$this->status=<pre style="text-aling: left;">'; print_r($this->status); echo
"</pre>\n";
$this->config->value('status',$this->status);
//echo '<p>uicustomfields::save_repository()
\$this->fields=<pre style="text-aling: left;">'; print_r($this->fields); echo
"</pre>\n";
$this->config->value('customfields',$this->fields);
$this->config->save_repository();
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] infolog/inc class.customfields_widget.inc.php, 1.2 class.uicustomfields.inc.php, 1.2,
ceb <=
- Prev by Date:
[Phpgroupware-cvs] infolog/templates/idsociety/images phone.png, 1.2 reject.gif, 1.2 phone.gif, 1.2 reject.png, 1.2 parent.png, 1.2 parent.gif, 1.2 task.gif, 1.2 will-call.png, 1.2 will-call.gif, 1.2 view.gif, 1.2 task.png, 1.2 ongoing.png, 1.2 view.png, 1.2 edit.gif, 1.2 edit.png, 1.2 done.png, 1.2 done.gif, 1.2 ongoing.gif, 1.2 email.png, 1.2 email.gif, 1.2 new.gif, 1.2 offer.png, 1.2 note.png, 1.2 offer.gif, 1.2 note.gif, 1.2 new.png, 1.2
- Next by Date:
[Phpgroupware-cvs] infolog/templates/probusiness/images navbar.png, 1.2 folder.png, 1.2
- Previous by thread:
[Phpgroupware-cvs] infolog/templates/idsociety/images phone.png, 1.2 reject.gif, 1.2 phone.gif, 1.2 reject.png, 1.2 parent.png, 1.2 parent.gif, 1.2 task.gif, 1.2 will-call.png, 1.2 will-call.gif, 1.2 view.gif, 1.2 task.png, 1.2 ongoing.png, 1.2 view.png, 1.2 edit.gif, 1.2 edit.png, 1.2 done.png, 1.2 done.gif, 1.2 ongoing.gif, 1.2 email.png, 1.2 email.gif, 1.2 new.gif, 1.2 offer.png, 1.2 note.png, 1.2 offer.gif, 1.2 note.gif, 1.2 new.png, 1.2
- Next by thread:
[Phpgroupware-cvs] infolog/templates/probusiness/images navbar.png, 1.2 folder.png, 1.2
- Index(es):