2002-02-18 17:05:07 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-01-27 17:58:19 +01:00
|
|
|
* eGroupWare - eTemplates - Tutoria Example - a simple MediaDB *
|
|
|
|
* http://www.egroupware.org *
|
2002-02-18 17:05:07 +01:00
|
|
|
* 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$ */
|
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
include_once(EGW_INCLUDE_ROOT . '/etemplate/inc/class.so_sql.inc.php');
|
2002-02-18 17:05:07 +01:00
|
|
|
|
|
|
|
class et_media extends so_sql
|
|
|
|
{
|
|
|
|
var $types = array(
|
|
|
|
'' => 'Select one ...',
|
|
|
|
'cd' => 'Compact Disc',
|
|
|
|
'dvd' => 'DVD',
|
|
|
|
'book' => 'Book',
|
|
|
|
'video' => 'Video Tape'
|
|
|
|
);
|
|
|
|
|
2003-08-08 18:29:34 +02:00
|
|
|
function et_media()
|
2002-02-18 17:05:07 +01:00
|
|
|
{
|
2005-11-09 21:50:45 +01:00
|
|
|
$this->tmpl =& CreateObject('etemplate.etemplate','et_media.edit');
|
2002-02-18 17:05:07 +01:00
|
|
|
|
|
|
|
$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']))
|
|
|
|
{
|
2005-02-22 22:02:26 +01:00
|
|
|
$msg .= !$this->save() ? lang('Entry saved') : lang('Error: while saving !!!');
|
2002-02-18 17:05:07 +01:00
|
|
|
}
|
|
|
|
elseif (isset($content['read']))
|
|
|
|
{
|
|
|
|
unset($content['id']);
|
|
|
|
$found = $this->search($content,False,'name,author');
|
|
|
|
|
|
|
|
if (!$found)
|
|
|
|
{
|
2003-08-08 18:29:34 +02:00
|
|
|
$msg .= lang('Nothing matched search criteria !!!');
|
2002-02-18 17:05:07 +01:00
|
|
|
}
|
|
|
|
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(
|
2003-08-08 18:29:34 +02:00
|
|
|
'msg' => lang('%1 matches on search criteria',count($found)),
|
2002-02-18 17:05:07 +01:00
|
|
|
'entry' => $entry
|
|
|
|
);
|
|
|
|
$this->tmpl->read('et_media.show');
|
|
|
|
|
|
|
|
$this->tmpl->exec('et_media.et_media.edit',$content);
|
|
|
|
}
|
|
|
|
|
2005-11-09 21:50:45 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2002-02-18 17:05:07 +01:00
|
|
|
function writeLangFile()
|
|
|
|
{
|
2003-08-08 18:29:34 +02:00
|
|
|
return $this->tmpl->writeLangFile('et_media','en',$this->types);
|
2002-02-18 17:05:07 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|