[Phpcms-plugins-cvs] events4phpCMS index.php,NONE,1.1 class.events.php,NONE,1.1 class.events4phpcms.
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2005-02-15 12:13:34
|
Update of /cvsroot/phpcms-plugins/events4phpCMS In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15070 Added Files: index.php class.events.php class.events4phpcms.php .cvsignore Log Message: initial import --- NEW FILE: .cvsignore --- .project events.dat --- NEW FILE: class.events4phpcms.php --- <?php /** * Event4phpCMS * * <b>License</b> * * 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. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2005, Martin Jahn * @version $Id: class.events4phpcms.php,v 1.1 2005/02/15 12:13:24 mjahn Exp $ * @package events4phpcms */ /* * $Log: class.events4phpcms.php,v $ * Revision 1.1 2005/02/15 12:13:24 mjahn * initial import * */ include_once (dirname (__FILE__).'/class.events.php'); class events4phpcms { var $maxEntriesPerPage = 10; var $contentfile = ''; /** * constructor in PHP4-compatible syntax */ function events4phpcms () { return $this->__construct (); } /** * constructor in PHP5 syntax */ function __construct () { $this->datafile = dirname (__FILE__).'/events.dat'; $this->contentfile = $_SERVER ['PHP_SELF']; return true; } /** * displays the events in a paged way */ function view () { $this->_loadEvents (); $start = 0; if (isset ($_REQUEST ['start']) && $_REQUEST ['start'] > 0 && $_REQUEST ['start'] < count ($this->events)) { $start = (int) strip_tags ($_REQUEST ['start']) - 1; } $ids = array_keys ($this->events); for ($i = $start; $i < $start + $this->maxEntriesPerPage && $i < count ($this->events); $i++) { $id = $ids [$i]; $this->_showEvent ($id, $this->events [$id]); } } /** * handles the edit-process */ function edit () { if (!$this->login ()) { return false; } if (isset ($_REQUEST ['delete-id'])) { $this->_delEvent ((int)strip_tags ($_REQUEST ['delete-id'])); } if (isset ($_POST ['submit-event'])) { if (isset ($_POST ['event-id'])) { $this->_delEvent ($_POST ['event-id']); } $data = array (); $data ['title'] = htmlentities (strip_tags ($_POST ['event-title'])); $data ['desc'] = htmlentities (strip_tags ($_POST ['event-desc'])); $id = mktime ((int) strip_tags ($_POST ['event-hour']), (int) strip_tags ($_POST ['event-min']), 0, (int) strip_tags ($_POST ['event-month']), (int) strip_tags ($_POST ['event-day']), (int) strip_tags ($_POST ['event-year'])); $this->_addEvent (array ($id => $data)); } $this->view (); if (isset ($_REQUEST ['edit-id'])) { $this->_showEditform (strip_tags ($_REQUEST ['edit-id'])); } else { $this->_showNewform (); } } /** * @return mixed false if user is not logged in, true if he is */ function login () { @session_start (); if (!isset ($_SESSION ['loggedin']) || !$_SESSION ['loggedin']) { if (isset ($_POST ['passwd']) && $_POST ['passwd'] == 'Enrico') { $_SESSION ['loggedin'] = true; } else { $_SESSION ['loggedin'] = false; } } if ($_SESSION ['loggedin']) { return true; } else { $this->_showLoginform (); return false; } } function _loadEvents () { if (!isset ($this->model) || !is_object ($this->model)) { $this->model = new events (); } if (!isset ($this->events)) { $this->model->load ($this->datafile); $this->events =& $this->model->get (); asort ($this->events); } } function _addEvent ($event) { $this->_loadEvents (); $this->events =& $this->model->add ($event); asort ($this->events); } function _delEvent ($event) { $this->_loadEvents (); $this->events =& $this->model->del ($event); asort ($this->events); } function _showLoginform () { echo '<h2>Bitte geben Sie das Passwort ein</h2>'; echo '<form action="'.$this->contentfile.'" method="post">' . '<input type="hidden" name="edit" value="1" />' . '<input name="passwd" value="" type="password" />' . '<input type="submit" name="submit-login" value="Anmelden" />' . '</form>'; } function _showNewform () { echo '<h2>Neues Ereignis eintragen</h2>'; echo '<form action="'.$this->contentfile.'" method="post">' . '<input type="hidden" name="edit" value="1" />' . 'Titel des Ereignisses<br />' . '<input type="text" name="event-title" value="Titel des Ereignisses" /><br />' . 'Termin des Ereignisses<br />' . '<input txpe="text" name="event-day" value="1" size="2" />. <input txpe="text" name="event-month" value="1" size="2" />. <input txpe="text" name="event-year" value="2005" size="4" /> um <input txpe="text" name="event-hour" value="20" size="2" />:<input txpe="text" name="event-min" value="00" size="2" /><br />' . 'Beschreibung des Ereignisses<br />' . '<textarea name="event-desc" rows="10" cols="40"></textarea>' . '<input type="submit" name="submit-event" value="Eintragen" /></form>'; } function _showEditform ($id) { $data = $this->events [$id]; echo '<h2>Ereignis bearbeiten</h2>'; echo '<form action="'.$this->contentfile.'" method="post">' . '<input type="hidden" name="edit" value="1" />' . '<input type="hidden" name="event-id" value="'.$id.'" />' . 'Titel des Ereignisses<br />' . '<input type="text" name="event-title" value="'.$data ['title'].'" /><br />' . 'Termin des Ereignisses<br />' . '<input txpe="text" name="event-day" value="'.strftime ('%d', $id).'" size="2" />. <input txpe="text" name="event-month" value="'.strftime ('%m', $id).'" size="2" />. <input txpe="text" name="event-year" value="'.strftime ('%Y', $id).'" size="4" /> um <input txpe="text" name="event-hour" value="'.strftime ('%H', $id).'" size="2" />:<input txpe="text" name="event-min" value="'.strftime ('%M', $id).'" size="2" /><br />' . 'Beschreibung des Ereignisses<br />' . '<textarea name="event-desc" rows="10" cols="40">'.$data ['desc'].'</textarea>' . '<input type="submit" name="submit-event" value="Eintrag ändern" /></form>'; } function _showEvent ($time, $data) { if ($time < mktime (0,0,1,strftime ('%m',time()), strftime ('%d',time()), strftime ('%Y',time()) ) ) { return true; } echo '<h2>'.strftime ('%d.%m.%Y um %H:%M', $time).'</h2>'; echo '<h3>'.$data ['title'].'</h3><p>'.$data ['desc']; if (isset ($_SESSION ['loggedin']) && $_SESSION ['loggedin']) { echo '<br /><a href="'.$this->contentfile.'?edit=1&edit-id='.$time.'">Editieren</a> | '; echo '<a href="'.$this->contentfile.'?edit=1&delete-id='.$time.'" onclick="return confirm (\'Wollen Sie diesen Eintrag wirklich löschen?\');">Löschen</a><p>'; } echo '</dl>'; } } ?> --- NEW FILE: class.events.php --- <?php /** * events4phpCMS - Model-class * * <b>License</b> * * 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. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2005, Martin Jahn * @version $Id: class.events.php,v 1.1 2005/02/15 12:13:24 mjahn Exp $ * @package events4phpcms */ /* * $Log: class.events.php,v $ * Revision 1.1 2005/02/15 12:13:24 mjahn * initial import * */ class events { var $datafile = ''; var $data = array (); function load ($filename = '') { if (!file_exists ($filename)) { $this->datafile = ''; return false; } else { $this->datafile = $filename; } $this->data = parse_ini_file ($filename, true); } function save ($filename = '') { return $this->write_ini_file ($this->datafile, $this->data); } function get () { return $this->data; } function add ($event) { foreach ($event as $id=>$data) { $this->data [$id] = $data; } $this->save (); return $this->data; } function del ($id) { unset ($this->data [$id]); return $this->data; } function write_ini_file($path, $assoc_array) { $content = ''; foreach($assoc_array as $key => $item) { if(is_array($item)) { $content .= "\n[{$key}]\n"; foreach ($item as $key2 => $item2) { if(is_numeric($item2) || is_bool($item2)) { $content .= "{$key2} = {$item2}\n"; } else { $content .= "{$key2} = \"{$item2}\"\n"; } } } else { if(is_numeric($item) || is_bool($item)) { $content .= "{$key} = {$item}\n"; } else { $content .= "{$key} = \"{$item}\"\n"; } } } if(!$handle = fopen($path, 'w')) { return false; } if(!fwrite($handle, $content)) { return false; } fclose($handle); return true; } } ?> --- NEW FILE: index.php --- <?php /** * Event4phpCMS * * <b>License</b> * * 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. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2005, Martin Jahn * @version $Id: index.php,v 1.1 2005/02/15 12:13:15 mjahn Exp $ * @package events4phpcms */ /* * $Log: index.php,v $ * Revision 1.1 2005/02/15 12:13:15 mjahn * initial import * */ include_once (dirname (__FILE__).'/class.events4phpcms.php'); $events = new events4phpcms (); if (isset ($_REQUEST ['edit'])) { $events->edit (); } else { $events->view (); } ?> |