Files
bm/public_html/public/cms/modules/personlist.class.php
2025-09-24 13:26:28 +02:00

268 lines
6.5 KiB
PHP

<?php
/** Person List
*
* @version 2.1.0
* @date 2007-05-01
* @author martin lenzelbauer
*
* @change 2007-06-15
* fixed PHP4 bug in getMenu() and doPublish()
*
* @change 2007-06-18
* changed editable to USER_GROUP (in C'tor)
*
* @change 2007-07-18
* changed doPublish(): added visibility check for persons
*
* @change 2007-12-16
* added PersonSeparator
* added template sorting
*
* @change 2008-09-23
* updated loading & publishing routines to keep memory low in PHP5
*/
class PersonList extends Page{
var $template;
/** C'tor
*/
//------------------------------------------------
function PersonList($id, $parent){
//------------------------------------------------
parent::Page($id, $parent);
$this->name = "[Personenliste]";
$this->allowedChildObjects = array("person", "separator");
$this->buttonPublish = true;
$this->buttonPreview = true;
$this->editable = USER_GROUP;
}
/** @see CmsObject::load()
*/
//-----------------------------------------------
function load($path=array()){
//-----------------------------------------------
parent::load($path);
if(!$this->classId){
return;
}
$query = sprintf("SELECT * FROM bruckm_personlist WHERE id = %d", $this->classId);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->template = $line['template'];
}
/** @see Page::doSave()
*/
//----------------------------------------------
function doSave(){
//----------------------------------------------
$query = sprintf("UPDATE bruckm_personlist SET template = %s WHERE id = %d",
sqlstring($this->template),
sqlnum($this->classId));
dbQuery($query);
parent::doSave();
}
/** @see Page::doCreate()
*/
//----------------------------------------------
function doCreate(){
//----------------------------------------------
$query = sprintf("INSERT INTO bruckm_personlist (template) VALUES (%s)",
sqlstring($this->template));
dbQuery($query);
$this->classId = mysql_insert_id();
parent::doCreate();
}
/** @see Page::doDelete()
*/
//-----------------------------------------------
function doDelete(){
//-----------------------------------------------
parent::doDelete();
$query = sprintf("DELETE FROM bruckm_personlist WHERE id = %d LIMIT 1", $this->classId);
dbQuery($query);
}
/** @see Page::install()
*/
//-----------------------------------------------
function install(){
//-----------------------------------------------
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_personlist (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
template VARCHAR(100) NOT NULL,
PRIMARY KEY (id)
)");
dbQuery($query);
}
/** @see CmsObject::update()
*/
//-----------------------------------------------
function update(){
//-----------------------------------------------
parent::update();
if(isset($_POST['template'])){
$this->template = $_POST['template'];
}
}
/** @see CmsObject::doPrintClassContent()
*/
//-----------------------------------------------
function doPrintClassContent(){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."stdpage.html");
$templates = "";
$templateFiles = array();
$dir = opendir(TEMPLATE_DIR);
while($file = readdir($dir)){
if(is_file(TEMPLATE_DIR.$file)){
$templateFiles[] = $file;
}
}
sort($templateFiles);
foreach($templateFiles as $file){
if($file == $this->template){
$templates .= "<option value=\"$file\" selected=\"selected\">$file</option>";
}
else{
$templates .= "<option value=\"$file\">$file</option>\n";
}
}
$t->setVar("TEMPLATES", $templates);
if($_SESSION['userlevel'] == USER_ADMIN){
$t->setVar("TEMPLATE_DISABLED", "");
}
else{
$t->setVar("TEMPLATE_DISABLED", "disabled=\"disabled\"");
}
return $t->toString();
}
/** @see CmsObject::publish()
*/
//---------------------------------------------
function doPublish(){
//---------------------------------------------
$t = new Template(TEMPLATE_DIR.$this->template);
$content = "<h1>".$this->toString()."</h1>";
$j = 0;
for($i = 0; $i < sizeof($this->childObjects); $i++) {
$child = $this->childObjects[$i];
$load = !$child->isLoaded();
if($load){
$child->load();
}
if($child->isVisible()){
$child->publish();
$content .= $child->publishForPersonList($j%2);
if(strtolower(get_class($child)) == "person"){
$j++;
}
}
if($load){
$child->unload();
}
}
$t->setVar("CONTENT", $content);
if(!$this->parentObj){
$this->parentObj = FlexiconFactory::instanceById($this->parentId);
}
if(!$this->parentObj->isLoaded()){
$this->parentObj->load();
}
$t = $this->parentObj->printMenu($t);
$t->setVar("TITLE", $this->toString());
return $t->toString();
}
/** @see CmsObject::canBePublished()
*/
//----------------------------------------------
function canBePublished(){
//----------------------------------------------
/*if(sizeof($this->childObjects) == 0 && $this->visible){
$this->addError("Die Personenliste ist leer!");
return false;
}*/
$ok = true;
for($i = 0; $i < sizeof($this->childObjects); $i++) {
$child = $this->childObjects[$i];
$load = !$child->isLoaded();
if($load){
$child->load();
}
if(!$child->canBePublished()){
if($ok){
$ok = false;
$this->addError("Ein oder mehere Seiten können nicht veröffentlicht werden!");
}
$this->addError($child->getErrors());
}
if($load){
$child->unload();
}
}
return $ok;
}
/** @see Element::getCssClass()
*/
//------------------------------------------------
function getCssClass(){
//------------------------------------------------
return "itemPersonPage";
}
// === ADDITIONAL METHODS ============================================================== //
/** returns the name of the template file
* @return template
*/
//-----------------------------------------------
function getTemplate(){
//-----------------------------------------------
return $this->template;
}
/** returns the Menu object
* @return Menu
*/
//-----------------------------------------------
function getMenu(){
//-----------------------------------------------
if(!$this->parentObj){
$this->parentObj = FlexiconFactory::instanceById($this->parentId);
}
if(!$this->parentObj->isLoaded()){
$this->parentObj->load();
}
return $this->parentObj;
}
};
?>