mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-03-03 01:21:42 +01:00
some fixes and updates for the eTemplate tutorial
This commit is contained in:
parent
9e61aaf90d
commit
6211b1457d
42
etemplate/doc/et_media/inc/class.bo_et_media.inc.php
Normal file
42
etemplate/doc/et_media/inc/class.bo_et_media.inc.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare editable Templates - Example media database (et_media)
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package etemplate
|
||||
* @subpackage et_media
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
include_once(EGW_INCLUDE_ROOT . '/etemplate/inc/class.so_sql.inc.php');
|
||||
|
||||
/**
|
||||
* Business object for et_media
|
||||
*/
|
||||
class bo_et_media extends so_sql
|
||||
{
|
||||
/**
|
||||
* Availible media types
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $types = array(
|
||||
'' => 'Select one ...',
|
||||
'cd' => 'Compact Disc',
|
||||
'dvd' => 'DVD',
|
||||
'book' => 'Book',
|
||||
'video' => 'Video Tape'
|
||||
);
|
||||
/**
|
||||
* Constructor initialising so_sql
|
||||
*
|
||||
* @return so_et_media
|
||||
*/
|
||||
function bo_et_media()
|
||||
{
|
||||
$this->so_sql('et_media','egw_et_media');
|
||||
$this->empty_on_write = "''";
|
||||
}
|
||||
}
|
@ -1,144 +0,0 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* eGroupWare - eTemplates - Tutoria Example - a simple MediaDB *
|
||||
* http://www.egroupware.org *
|
||||
* Written by Ralf Becker <RalfBecker@outdoor-training.de> *
|
||||
* -------------------------------------------- *
|
||||
* 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$ */
|
||||
|
||||
include_once(EGW_INCLUDE_ROOT . '/etemplate/inc/class.so_sql.inc.php');
|
||||
|
||||
class et_media extends so_sql
|
||||
{
|
||||
var $types = array(
|
||||
'' => 'Select one ...',
|
||||
'cd' => 'Compact Disc',
|
||||
'dvd' => 'DVD',
|
||||
'book' => 'Book',
|
||||
'video' => 'Video Tape'
|
||||
);
|
||||
|
||||
function et_media()
|
||||
{
|
||||
$this->tmpl =& CreateObject('etemplate.etemplate','et_media.edit');
|
||||
|
||||
$this->so_sql('et_media','phpgw_et_media'); // sets up our storage layer using the table 'phpgw_et_media'
|
||||
$this->empty_on_write = "''"; // that means if a column is empty how to write in the db, the default is NULL
|
||||
|
||||
$this->public_functions += array(
|
||||
'edit' => True,
|
||||
'writeLangFile' => True
|
||||
);
|
||||
}
|
||||
|
||||
function edit($content='',$msg = '')
|
||||
{
|
||||
if (is_array($content)) // not first call from index
|
||||
{
|
||||
if ($content['id'] > 0)
|
||||
{
|
||||
$this->read($content);
|
||||
}
|
||||
//echo "<p>edit: content ="; _debug_array($content);
|
||||
$this->data_merge($content);
|
||||
//echo "<p>edit: data ="; _debug_array($this->data);
|
||||
|
||||
if (isset($content['save']))
|
||||
{
|
||||
$msg .= !$this->save() ? lang('Entry saved') : lang('Error: while saving !!!');
|
||||
}
|
||||
elseif (isset($content['read']))
|
||||
{
|
||||
unset($content['id']);
|
||||
$found = $this->search($content,False,'name,author');
|
||||
|
||||
if (!$found)
|
||||
{
|
||||
$msg .= lang('Nothing matched search criteria !!!');
|
||||
}
|
||||
elseif (count($found) == 1)
|
||||
{
|
||||
$this->init($found[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->show($found);
|
||||
return;
|
||||
}
|
||||
}
|
||||
elseif (isset($content['cancel']))
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
elseif (isset($content['delete']))
|
||||
{
|
||||
$this->delete();
|
||||
$this->init();
|
||||
}
|
||||
elseif (isset($content['entry']['edit']))
|
||||
{
|
||||
list($id) = each($content['entry']['edit']);
|
||||
if ($id > 0)
|
||||
{
|
||||
$this->read(array('id' => $id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now we filling the content array for the next call to etemplate.exec
|
||||
|
||||
$content = $this->data + array(
|
||||
'msg' => $msg
|
||||
);
|
||||
$sel_options = array(
|
||||
'type' => $this->types
|
||||
);
|
||||
$no_button = array(
|
||||
'delete' => !$this->data[$this->db_key_cols[$this->autoinc_id]]
|
||||
);
|
||||
$this->tmpl->exec('et_media.et_media.edit',$content,$sel_options,$no_button,array(
|
||||
'id' => $this->data['id']
|
||||
));
|
||||
}
|
||||
|
||||
function show($found)
|
||||
{
|
||||
if (!is_array($found) || !count($found))
|
||||
{
|
||||
$this->edit();
|
||||
return;
|
||||
}
|
||||
reset($found);
|
||||
for ($row=1; list($key,$data) = each($found); ++$row)
|
||||
{
|
||||
$entry[$row] = $data;
|
||||
}
|
||||
$content = array(
|
||||
'msg' => lang('%1 matches on search criteria',count($found)),
|
||||
'entry' => $entry
|
||||
);
|
||||
$this->tmpl->read('et_media.show');
|
||||
|
||||
$this->tmpl->exec('et_media.et_media.edit',$content);
|
||||
}
|
||||
|
||||
/**
|
||||
* writes langfile with all templates and types here
|
||||
*
|
||||
* can be called via [write Langfile] in the eTemplate editor or
|
||||
* http://domain/egroupware/index.php?et_media.et_media.writeLangFile
|
||||
*/
|
||||
function writeLangFile()
|
||||
{
|
||||
return $this->tmpl->writeLangFile('et_media','en',$this->types);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
136
etemplate/doc/et_media/inc/class.ui_et_media.inc.php
Normal file
136
etemplate/doc/et_media/inc/class.ui_et_media.inc.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare editable Templates - Example media database (et_media)
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package etemplate
|
||||
* @subpackage et_media
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
include_once(EGW_INCLUDE_ROOT . '/et_media/inc/class.bo_et_media.inc.php');
|
||||
|
||||
class ui_et_media extends bo_et_media
|
||||
{
|
||||
/**
|
||||
* Public functions callable via menuaction
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $public_functions = array(
|
||||
'edit' => True,
|
||||
'writeLangFile' => True
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return ui_et_media
|
||||
*/
|
||||
function ui_et_media()
|
||||
{
|
||||
$this->bo_et_media(); // calling the constructor of the extended bo object
|
||||
|
||||
$this->tmpl =& CreateObject('etemplate.etemplate','et_media.edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a media database entry
|
||||
*
|
||||
* @param array $content=null
|
||||
* @param string $msg=''
|
||||
*/
|
||||
function edit($content=null,$msg = '')
|
||||
{
|
||||
if (is_array($content)) // not first call from index
|
||||
{
|
||||
if ($content['id'] > 0)
|
||||
{
|
||||
$this->read($content);
|
||||
}
|
||||
//echo "<p>edit: content ="; _debug_array($content);
|
||||
$this->data_merge($content);
|
||||
//echo "<p>edit: data ="; _debug_array($this->data);
|
||||
|
||||
if (isset($content['save']))
|
||||
{
|
||||
$msg .= !$this->save() ? lang('Entry saved') : lang('Error: while saving !!!');
|
||||
}
|
||||
elseif (isset($content['read']))
|
||||
{
|
||||
unset($content['id']);
|
||||
$found = $this->search($content,False,'name,author');
|
||||
|
||||
if (!$found)
|
||||
{
|
||||
$msg .= lang('Nothing matched search criteria !!!');
|
||||
}
|
||||
elseif (count($found) == 1)
|
||||
{
|
||||
$this->init($found[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->show($found);
|
||||
return;
|
||||
}
|
||||
}
|
||||
elseif (isset($content['cancel']))
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
elseif (isset($content['delete']))
|
||||
{
|
||||
$this->delete();
|
||||
$this->init();
|
||||
}
|
||||
elseif (isset($content['entry']['edit']))
|
||||
{
|
||||
list($id) = each($content['entry']['edit']);
|
||||
if ($id > 0)
|
||||
{
|
||||
$this->read(array('id' => $id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now we filling the content array for the next call to etemplate.exec
|
||||
|
||||
$content = $this->data + array(
|
||||
'msg' => $msg
|
||||
);
|
||||
$sel_options = array(
|
||||
'type' => $this->types
|
||||
);
|
||||
$no_button = array(
|
||||
'delete' => !$this->data[$this->db_key_cols[$this->autoinc_id]]
|
||||
);
|
||||
$this->tmpl->exec('et_media.et_media.edit',$content,$sel_options,$no_button,array(
|
||||
'id' => $this->data['id']
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Showing entries from the media database
|
||||
*
|
||||
* @param array $found
|
||||
*/
|
||||
function show($found=null)
|
||||
{
|
||||
if (!is_array($found) || !count($found))
|
||||
{
|
||||
$this->edit();
|
||||
return;
|
||||
}
|
||||
array_unshift($found,false); // change the array to start with index 1
|
||||
$content = array(
|
||||
'msg' => lang('%1 matches on search criteria',count($found)),
|
||||
'entry' => $found,
|
||||
);
|
||||
$this->tmpl->read('et_media.show');
|
||||
|
||||
$this->tmpl->exec('et_media.et_media.edit',$content);
|
||||
}
|
||||
}
|
@ -1,24 +1,22 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* eGroupWare - eTemplates - Example App et_media *
|
||||
* http://www.egroupware.org *
|
||||
* Written by Ralf Becker <RalfBecker@outdoor-training.de> *
|
||||
* -------------------------------------------- *
|
||||
* 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. *
|
||||
\**************************************************************************/
|
||||
/**
|
||||
* eGroupWare editable Templates - Example media database (et_media)
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package etemplate
|
||||
* @subpackage et_media
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
$GLOBALS['egw_info'] = array(
|
||||
'flags' => array(
|
||||
'currentapp' => 'et_media',
|
||||
'noheader' => True,
|
||||
'nonavbar' => True,
|
||||
),
|
||||
);
|
||||
include('../header.inc.php');
|
||||
|
||||
$GLOBALS['egw_info'] = array(
|
||||
'flags' => array(
|
||||
'currentapp' => 'et_media',
|
||||
'noheader' => True,
|
||||
'nonavbar' => True,
|
||||
),
|
||||
);
|
||||
include('../header.inc.php');
|
||||
|
||||
$GLOBALS['egw']->redirect_link('/index.php','menuaction=et_media.et_media.edit');
|
||||
$GLOBALS['egw']->redirect_link('/index.php','menuaction=et_media.ui_et_media.edit');
|
||||
|
@ -34,9 +34,9 @@
|
||||
/* Dependencies for this app to work */
|
||||
$setup_info['et_media']['depends'][] = array(
|
||||
'appname' => 'phpgwapi',
|
||||
'versions' => Array('1.0.0','1.0.1','1.2','1.3')
|
||||
'versions' => Array('1.2','1.3','1.4')
|
||||
);
|
||||
$setup_info['et_media']['depends'][] = array(
|
||||
'appname' => 'etemplate',
|
||||
'versions' => Array('1.0.0','1.0.1','1.2','1.3')
|
||||
'versions' => Array('1.2','1.3','1.4')
|
||||
);
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user