require_once (dirname(__FILE__)."/../lib/group.inc.php");
require_once (dirname(__FILE__)."/../lib/status.inc.php");
require_once (dirname(__FILE__)."/../lib/i18n.inc.php");
header('Content-type: text/plain; charset=UTF-8');
class Action
{
public function __construct ()
{
@session_start();
$groupData = Array (); // Informationen zum Eintrag
$may_set_online = Base::MODE_NONE; // User darf online/offline stellen
$may_edit = Base::MODE_NONE; // User darf editieren
// erweiterte Fehlermeldungen deaktivieren
if (function_exists ('xdebug_disable')) {
xdebug_disable ();
}
// User-Rechte und Informationen zum Eintrag
if (isset ($_REQUEST['site']) && isset ($_REQUEST['group']) && $_REQUEST['site'] && $_REQUEST['group'] && Group::getSiteGroup ($_REQUEST['site'], $_REQUEST['group'])) {
$groupData = Group::getSiteGroup ($_REQUEST['site'], $_REQUEST['group']);
$may_set_online = $groupData['edit_right'] & Base::MODE_ONLINE;
$may_edit = $groupData['edit_right'] & Base::MODE_EDIT;
}
// Zwischenablage einrichten
if (!isset ($_SESSION['cms']['action']['copy'])) {
$_SESSION['cms']['action']['copy'] = array ();
}
$copy = &$_SESSION['cms']['action']['copy'];
$action = isset ($_REQUEST['action']) ? $_REQUEST['action'] : "";
switch ($_REQUEST['action']) {
case "unload":
Group::unsetSiteGroup ($_REQUEST['site']);
echo "Unset site ".$_REQUEST['site'];
break;
case "frame":
Group::setSiteTarget ($_REQUEST['site'], $_REQUEST['target']);
break;
case "message":
echo "".I18n::tr ("cms", $_REQUEST['value'])."";
break;
case "translation":
echo I18n::tr ($_REQUEST['section'], $_REQUEST['name']);
break;
case "status":
// Status abfragen
echo "".$this->status (isset ($_REQUEST['value']) ? $_REQUEST['value'] : 0)."";
if (Setting::get ("system", "disable_cms")) {
echo "".I18n::tr ("edit", "welcome/the editing is disabled")."\n".Setting::get ("system", "disable_message")."";
}
break;
// Dot
case "dotStatus":
if (isset ($_REQUEST['dot'])) {
echo "";
foreach ($_REQUEST['dot'] as $id => $dot) {
echo $this->dotStatus ($id, $dot['name'], $dot['group'], $_REQUEST['site']) . "\n";
}
echo "";
} else if (isset ($_REQUEST['id'])) {
echo $this->dotStatus ($_REQUEST['id'], $_REQUEST['name'], $_REQUEST['group'], $_REQUEST['site']);
}
break;
case "dotDependency":
echo "";
foreach (Status::getDependency ($_REQUEST['site'], $_REQUEST['group']) as $range => $groups) {
echo "";
foreach ($groups as $id) {
echo "";
}
echo "";
}
echo "";
break;
// Kontext Menue
case "kontextmenu":
echo $this->kontextmenu ();
break;
// Main Kontext Menue
case "swapEditMode":
if (!Ticket::selected ()) {
echo "";
echo "".I18n::tr ("cms", "select a ticket")."";
} else {
$id = ($_REQUEST['group']) ? ("{$groupData['parent_id']}_{$groupData['name']}") : 0;
Group::swapEditMode ($id);
echo "";
// echo "Edit mode of $id is ".Group::getEditMode ($id)."";
}
break;
case "swapOnlineMode":
Group::swapOnlineMode ();
echo "";
// echo "Edit mode of 0 is ".Group::getEditMode ()."";
break;
case "help":
$lc = User::get ("lc");
$lc = (file_exists (Setting::get ("config", "documentRoot")."/".Setting::get ("config", "cmsPath")."/docu/usermanual_$lc.pdf")) ? $lc : "en";
echo "";
break;
case "open sidebar":
echo "";
break;
case "logout":
User::logout ();
echo "";
break;
// Dot Kontext Menue
case "online element":
if ($may_set_online) {
$element = new Element (array ('group_id' => $_REQUEST['group'], 'name' => $_REQUEST['name']));
$element->setStatus (Base::STATUS_ONLINE);
echo "";
}
break;
case "online deleted":
$online_deleted = true;
case "online group":
if (Setting::get ("list/{$groupData['parent_id']}/{$groupData['name']}", "max", 0) != 1) { // wenn eine Liste nur eine Gruppe enthalten darf soll diese immer wei eine Liste behandelt werden
if ($may_set_online) {
if ($groupData['id'] && empty ($online_deleted)) {
$group = new Group (array ('id' => $groupData['id']));
$group->setStatus (Base::STATUS_ONLINE);
}
if (!$groupData['id'] || !empty ($online_deleted)) {
// gelöschte Gruppen online löschen
foreach (Group::getChildList ($groupData['parent_id'], $groupData['name'], true) as $row) {
if ($row['status'] & (Base::STATUS_ERASED | Base::STATUS_ARCHIVED)) {
$group = new Group (array ('id' => $row['id']));
$group->setStatus (Base::STATUS_ONLINE);
}
}
}
echo "";
}
break;
}
case "online list":
if ($may_set_online) {
foreach (Group::getChildList ($groupData['parent_id'], $groupData['name'], true) as $row) {
$group = new Group (array ('id' => $row['id']));
$group->setStatus (Base::STATUS_ONLINE);
}
echo "";
}
break;
case "online immediately":
$_SESSION['cms']['action']['immediately_online'] = (isset ($_SESSION['cms']['action']['immediately_online'])) ? !$_SESSION['cms']['action']['immediately_online'] : true;
echo "".$this->status ()."";
break;
case "offline element":
if ($may_set_online) {
$element = new Element (array ('group_id' => $_REQUEST['group'], 'name' => $_REQUEST['name']));
$element->setStatus (Base::STATUS_OFFLINE);
echo "";
}
break;
case "offline group":
if (Setting::get ("list/{$groupData['parent_id']}/{$groupData['name']}", "max", 0) != 1) { // wenn eine Liste nur eine Gruppe enthalten darf soll diese immer wei eine Liste behandelt werden
if ($may_set_online) {
$group = new Group (array ('id' => $groupData['id']));
$group->setStatus (Base::STATUS_OFFLINE);
echo "";
}
break;
}
case "offline list":
if ($may_set_online) {
foreach (Group::getChildList ($groupData['parent_id'], $groupData['name'], true) as $row) {
$group = new Group (array ('id' => $row['id']));
$group->setStatus (Base::STATUS_OFFLINE);
}
echo "";
}
break;
case "delete group timer":
if (!$groupData['id']) {
// es ist ein Timer auf gelöschte Gruppen
foreach (Group::getChildList ($groupData['parent_id'], $groupData['name'], true) as $row) {
if (($row['status'] & (Base::STATUS_ERASED | Base::STATUS_ARCHIVED)) && Group::getTimer ($row['id']) == $_REQUEST['value']) {
Group::delTimer ($row['id']);
}
}
} else {
Group::delTimer ($groupData['id']);
}
echo "";
break;
case "delete complete timer":
if (!$groupData['id']) {
// es ist ein Timer auf gelöschte Gruppen
foreach (Group::getChildList ($groupData['parent_id'], $groupData['name'], true) as $row) {
if (($row['status'] & (Base::STATUS_ERASED | Base::STATUS_ARCHIVED)) && Group::getTimer ($row['id']) == $_REQUEST['value']) {
Group::delTimer ($row['id'], true);
}
}
} else {
Group::delTimer ($groupData['id'], true);
}
echo "";
break;
case "cut element":
case "cut group":
case "cut list":
case "copy element":
case "copy group":
case "copy list":
$copy['type'] = Status::getType ($_REQUEST['site'], $_REQUEST['group'], $_REQUEST['name']);
$copy['group'] = $groupData;
$copy['name'] = $_REQUEST['name'];
$copy['action'] = preg_replace ("/ .*/", "", $_REQUEST['action']);
$copy['range'] = preg_replace ("/.* /", "", $_REQUEST['action']);
echo "".$this->status ()."";
break;
case "paste new":
$group = new Group (array ('parent_id' => $groupData['parent_id'], 'name' => $groupData['name'], 'url' => $groupData['url']));
$group->set ();
$group->move ($groupData['id']);
echo "";
break;
case "force paste":
// Kopie einfügen auch wenn der type nicht stimmt
$force_paste = true;
case "paste":
if ($may_edit && $copy) {
$type = Status::getType ($_REQUEST['site'], $_REQUEST['group'], $_REQUEST['name']);
if (empty ($force_paste) && $copy['range'] == "element" && $copy['type'] != $type) {
// Element Type von quelle und Ziel stimmen nicht überein
echo "".I18n::tr ("cms", "wrong paste dot type. insert even so?")."";
} else if (empty ($force_paste) && $copy['range'] != "element" && $groupData['name'] != $copy['group']['name']) {
// Gruppen Name von Quelle und Ziel stimmen nicht überein
echo "".I18n::tr ("cms", "wrong paste group. insert even so?")."";
} else {
// Eintrag einfügen
switch ($copy['action']) {
case "cut":
switch ($copy['range']) {
case "element":
// aktuelle Daten überschreiben
$src_group = new Group (array ('id' => $copy['group']['id']));
$src_id = $src_group->element ($copy['name'])->id;
$group = new Group (array ('id' => $groupData['id'], 'parent_id' => $groupData['parent_id'], 'name' => $groupData['name'], 'url' => $groupData['url']));
$group->setElementCopy ($_REQUEST['name'], $src_id);
// quelle löschen
$src_group->element ($copy['name'])->del ();
break;
case "group":
// Gruppe verschieben
$group = new Group (array ('id' => $copy['group']['id']));
$group->move ($groupData['id'], $groupData['parent_id'], $groupData['name']);
break;
case "list":
// Gruppen verschieben
$history = new History ("group move all");
$history->groupStart ();
foreach (Group::getChildList ($copy['group']['parent_id'], $copy['group']['name']) as $row) {
$group = new Group (array ('id' => $row['id']));
$group->move ($groupData['id'], $groupData['parent_id'], $groupData['name']);
}
$history->groupEnd();
break;
}
break;
case "copy":
switch ($copy['range']) {
case "element":
// aktuelle Daten überschreiben
$src_group = new Group (array ('id' => $copy['group']['id']));
$src_id = $src_group->element ($copy['name'])->id;
$group = new Group (array ('id' => $groupData['id'], 'parent_id' => $groupData['parent_id'], 'name' => $groupData['name'], 'url' => $groupData['url']));
$group->setElementCopy ($_REQUEST['name'], $src_id);
break;
case "group":
// Kopie einfügen
$group = new Group (array ('parent_id' => $groupData['parent_id'], 'name' => $groupData['name'], 'url' => $groupData['url']));
$group->create ();
$history = new History ("group copy");
$history->groupStart ();
$group->set ($copy['group']['id']);
$group->move ($groupData['id'], $groupData['parent_id'], $groupData['name']);
$history->groupEnd();
break;
case "list":
// Kopien einfügen
$history = new History ("group no changes all");
$history->groupStart ();
$groups = array ();
foreach (Group::getChildList ($copy['group']['parent_id'], $copy['group']['name']) as $row) {
$groups[$row['id']] = new Group (array ('parent_id' => $groupData['parent_id'], 'name' => $groupData['name'], 'url' => $groupData['url']));
$groups[$row['id']]->create ();
}
$history->groupEnd ();
$history = new History ("group copy all");
$history->groupStart ();
foreach ($groups as $id => $group) {
$groups[$id]->set ($id);
$groups[$id]->move ($groupData['id'], $groupData['parent_id'], $groupData['name']);
}
$history->groupEnd ();
break;
}
break;
}
echo "";
}
}
break;
case "paste link":
if ($may_edit && $copy) {
$group = new Group (array ('parent_id' => $groupData['parent_id'], 'name' => $groupData['name'], 'url' => $groupData['url']));
$group->create ();
$history = new History ("group copy");
$history->groupStart ();
switch ($copy['range']) {
case "group":
$group->setLink ($copy['group']['id']);
break;
case "list":
$group->setLink ($copy['group']['parent_id'], $copy['group']['name']);
break;
}
$group->move ($groupData['id'], $groupData['parent_id'], $groupData['name']);
$history->groupEnd ();
echo "";
}
break;
case "paste element settings":
if (User::get ('is_admin') && $copy) {
$history = new History ("element copy config");
$history->groupStart ();
// alte Einstellungen löschen
$settings = Setting::get ("group/{$groupData['name']}/{$_SESSION['cms']['style']}{$_REQUEST['name']}");
foreach ($settings as $name => $value) {
Setting::del ("group/{$groupData['name']}/{$_SESSION['cms']['style']}{$_REQUEST['name']}", $name);
}
// neue Einstellungen setzen
$settings = Setting::get ("group/{$copy['group']['name']}/{$_SESSION['cms']['style']}{$copy['name']}");
foreach ($settings as $name => $value) {
Setting::set ("group/{$groupData['name']}/{$_SESSION['cms']['style']}{$_REQUEST['name']}", $name, $value);
}
$history->groupEnd();
echo "";
}
break;
case "paste list settings":
if (User::get ('is_admin') && $copy) {
$history = new History ("list copy config");
$history->groupStart ();
// alte Einstellungen löschen
$settings = Setting::get ("list/{$groupData['parent_id']}/{$groupData['name']}");
foreach ($settings as $name => $value) {
Setting::del ("list/{$groupData['parent_id']}/{$groupData['name']}", $name);
}
// neue Einstellungen setzen
$settings = Setting::get ("list/{$copy['group']['parent_id']}/{$copy['group']['name']}");
foreach ($settings as $name => $value) {
Setting::set ("list/{$groupData['parent_id']}/{$groupData['name']}", $name, $value);
}
$history->groupEnd();
echo "";
}
break;
case "delete element":
if ($may_edit) {
$group = new Group (array ('id' => $groupData['id']));
$group->element ($_REQUEST['name'])->del ();
echo "";
}
break;
case "delete group":
if ($may_edit) {
$group = new Group (array ('id' => $groupData['id']));
$group->del ();
echo "";
}
break;
case "archive group":
if ($may_edit) {
$group = new Group (array ('id' => $groupData['id']));
$group->archive ();
echo "";
}
break;
case "delete list":
if ($may_edit) {
$history = new History ("group del all");
$history->groupStart ();
foreach (Group::getChildList ($groupData['parent_id'], $groupData['name']) as $row) {
$group = new Group (array ('id' => $row['id']));
$group->del ();
}
$history->groupEnd ();
echo "";
}
break;
case "archive list":
if ($may_edit) {
$history = new History ("group archive all");
$history->groupStart ();
foreach (Group::getChildList ($groupData['parent_id'], $groupData['name']) as $row) {
$group = new Group (array ('id' => $row['id']));
$group->archive ();
}
$history->groupEnd ();
echo "";
}
break;
case "goto history element":
if ($may_edit) {
History::restore ($_REQUEST['value']);
echo "";
}
break;
case "goto link":
$id = $_REQUEST['value'] ? $_REQUEST['value'] : $groupData['link_id'];
$group = new Group (array ('id' => $id));
echo "";
break;
default:
$id = isset ($_REQUEST['id']) ? $_REQUEST['id'] : "";
echo "Undefined action in 'action.php': action='$action' id='$id'";
}
}
private function dotStatus ($id, $name, $group, $site)
{
$status = Status::get ($site, $group, $name);
$childs = "";
$dot = " $value) {
if (is_array ($value)) {
if ($value) {
$childs .= "<$key>";
foreach ($value as $row) {
if ($row) {
$childs .= " $value2) {
$childs .= " $key2='".htmlspecialchars ($value2)."'";
}
$childs .= ">";
}
}
$childs .= "$key>";
} else {
$dot .= " $key=''";
}
} else {
$dot .= " $key='".htmlspecialchars ($value)."'";
}
}
$dot .= ">$childs";
return $dot;
}
private function kontextmenu ()
{
$xml = "";
$path = Array ();
$src = file_get_contents ("kontextmenu.xml");
$src = preg_replace ("/\<\!--.*?--\>/s", "", $src);
if (preg_match_all ("/<(\/?)([^\s>]+)(.*?)(\/?)\s*>/", $src, $tags, PREG_SET_ORDER)) {
foreach ($tags as $tag) {
if (!$tag[1]) {
$attributes = Array ();
if (preg_match_all ("/\s([^=]+)=\"([^\"]*)\"/", $tag[3], $atts, PREG_SET_ORDER)) {
foreach ($atts as $att) {
$attributes[$att[1]] = $att[2];
}
}
if (isset ($attributes['name'])) {
$value = isset ($attributes['value']) ? $attributes['value'] : $attributes['name'];
$title = isset ($attributes['title']) ? $attributes['title'] : $value;
$path[] = isset ($attributes['path']) ? $attributes['path'] : $attributes['name'];
$attributes['value'] = htmlspecialchars (I18n::tr ("kontextmenu", implode("/", array_slice($path, 1)), $value));
$attributes['title'] = htmlspecialchars (I18n::tr ("kontextmenu", implode("/", array_slice($path, 1))." description", $title));
unset ($attributes['path']);
} else {
$path[] = "";
}
$xml .= "<$tag[2]";
foreach ($attributes as $key => $value) {
$xml .= " $key=\"$value\"";
}
$xml .= ">";
}
if ($tag[1] || $tag[4]) {
// ende Tag
array_pop ($path);
$xml .= "$tag[2]>";
}
}
}
/*
echo "
";
$xml = preg_replace ("/>/", ">\n", $xml);
$xml = preg_replace ("/", "<", $xml);
*/
return $xml;
}
private function status ($site=0)
{
$status = "";
$copy = $_SESSION['cms']['action']['copy'];
$status .= "