Location: PHPKode > projects > SAPID > etc/interface/ddc.inc.php
<?PHP
// vim: set expandtab tabstop=4 shiftwidth=4:
// +----------------------------------------------------------------------+
// | SAPID: XML Sapiens Engine Demonstrator                               |
// +----------------------------------------------------------------------+
// | Author:  Max Baryshnikov aka Mephius <hide@address.com>                      |
// | Copyright (c) 2004 Max Baryshnikov                                   |
// | http://sapid.sourceforge.net                                             |
// +----------------------------------------------------------------------+
// | This source file is free software; you can redistribute it and/or    |
// | modify it under the terms of the GNU Lesser General Public           |
// | License as published by the Free Software Foundation; either         |
// | version 2.1 of the License, or (at your option) any later version.   |
// |                                                                      |
// | This source file 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    |
// | Lesser General Public License for more details.                      |
// +----------------------------------------------------------------------+
// Release: 28.11.04 (dd/mm/yy)
// $Id: ddc.inc.php,v 1.4 2006/03/11 18:24:28 sapidaddons Exp $

if (!defined("SAPID_STARTED")) die("Hacking attempt!");

if($env["user"]["GROUP"]=="wheel")
switch ($_GET["option"]){
        case "ddc":
        $d = dir($root_path . "usr/xml/ddc/");
        $panel="<div style=\"padding-left: 20px; padding-bottom: 10px;\">
                        ".$lang["DDCInterfaceDescription"]."
                        <div style=\"padding: 10px 0px 5px 0px;\"><input class=\"sapidcms_cont_btn\" type=\"button\" onclick=\"location.href='".$env["http_path"]."?option=create_ddc';\" value=\"".$lang["CreateNewDDC"]."\" /></div>
                        </div><form method=\"post\" style=\"margin: 0px 0px 0px 0px;\"><table class=\"tpanel\" cellpadding=0 cellspacing=0><tr><td width=\"20%\" class=\"header\"><b>".$lang["Container"]."</b></td><td class=\"header\"><b>".$lang["Description"]."</b></td><td class=\"header\"><b>".$lang["Author"]."</b></td></tr>";
        while (false !== ($entry = $d->read())) {
                if ($entry!="." and $entry!=".." and !is_dir($root_path . "usr/xml/ddc/" . $entry)) {
                        $fp=fopen($root_path . "usr/xml/ddc/" . $entry, "r");
                        $size=filesize($root_path . "usr/xml/ddc/" . $entry);
                        $ddc=fread($fp, $size);
                        fclose($fp);
                        preg_match("/<sapi:author>\s{0,}<sapi:name>(.*)<\/sapi:name>\s{0,}<sapi:email>([a-zA-Z\_\-\.]+@[a-zA-Z\_\-\.]+[a-zA-Z]+)<\/sapi:email>\s{0,}<sapi:url>([a-zA-Z\_\-\.]+)<\/sapi:url>\s{0,}<\/sapi:author>/", $ddc, $matches);
                        $author="<a href=\"mailto:".$matches[2]."\">" . $matches[1] . "</a>&nbsp;&nbsp;Site:&nbsp;<a href=\"".(preg_match("/^http:\/\//", $matches[3])?$matches[3]:"http://" . $matches[3])."\">" . $matches[3] . "</a>";
                        preg_match("/<sapi:comments>(.*?)<\/sapi:comments>/s", $ddc, $matches);
                        $description = $matches[1];
                        $panel.="<td><a href=\"".$env["http_path"]."?option=edit_ddc&name=".$entry."\"><img src=\"".$env["http_path"]."usr/system/images/edit.gif\" alt=\"".$lang["Edit"]."\" width=\"12\" hight=\"14\" border=\"0\" /></a>&nbsp;<a href=\"".$env["http_path"]."?option=delete_ddc&name=".$entry."\" onClick=\"return confirm('".$lang["confirm_delete"]."')\"><img src=\"".$env["http_path"]."usr/system/images/delete.gif\" alt=\"".$lang["Delete"]."\" width=\"12\" hight=\"14\" border=\"0\" /></a>&nbsp;<a href=\"#\" onclick=\"window.open('".$env["http_path"]."usr/system/plotter.php?name=".$entry."&sid=".session_id()."', 'alg', 'scrollbars=yes,status=no,resizable=1,toolbar=no,width=400,height=400')\"><img src=\"".$env["http_path"]."usr/system/images/uml.gif\" alt=\"".$lang["ViewAlg"]."\" width=\"12\" hight=\"14\" border=\"0\" /></a>&nbsp;" . $entry .  "</td><td><i>".$description."</i></td><td>".$author."</td></tr>";
                }
        }
        $d->close();
        $panel='<div style="margin-top: 3px;" class="panel">' . $panel . "</table><br /></div>";
        break;
        case "edit_ddc":

        if ($_POST["html"] and $_POST["name"] and $DEMO_MODE!="enabled") {
                //$_POST["html"]=preg_replace("/\[(\/)?textarea(.*?)\]/is", "<\\1textarea\\2>", $_POST["html"]);
                $fp=fopen($root_path . "usr/xml/ddc/" . $_POST["name"], "w+");
                fwrite($fp, (ini_get("magic_quotes_gpc")?stripslashes($_POST["html"]):$_POST["html"]));
                fclose($fp);
                $_GET["option"]="ddc";
                option_switch();
                break;
        }

        $template=preg_replace("/\//", "", $_GET["name"]);
        $fp=fopen($root_path . "usr/xml/ddc/" . $template, "r");
        $size=filesize($root_path . "usr/xml/ddc/" . $template);
        $data=fread($fp, $size);
        $data=preg_replace("/<(\/)?textarea(.*?)>/is", "&lt;\\1textarea\\2&gt;", $data);
        fclose($fp);
        include($root_path."usr/system/edit_template.inc.php");
        $panel = "<div class=\"panel\" style=\"margin-top: 3px; text-align: center;\"><b>".$lang["Container"].":</b> ".$_GET["name"]."&nbsp;<a href=\"#\" onclick=\"window.open('".$env["http_path"]."usr/system/plotter.php?name=".$_GET["name"]."&sid=".session_id()."', 'alg', 'scrollbars=yes,status=no,resizable=1,toolbar=no,width=400,height=400')\"><img src=\"".$env["http_path"]."usr/system/images/uml.gif\" alt=\"".$lang["ViewAlg"]."\" width=\"12\" hight=\"14\" border=\"0\" /></a><br /><br /><form method=\"post\"  onClick=\"id_form_focus='form_1'\" id=\"form_1\"><input type=\"hidden\" name=\"name\" value=\"".$_GET["name"]."\">".$panel."
        <textarea name=\"html\" id=\"html\" ONSELECT=\"storeCaret(html);\" ONCLICK=\"storeCaret(html);\" ONKEYUP=\"storeCaret(html);\" style=\"width: 100%; height: 395px; margin: 5px 15px 5px 5px; ".($SystemTextAreaStyle ? $SystemTextAreaStyle : "background-color: white; font-family: Courier new,Tahoma, Arial; font-size: 12px;")."\" cols=\"100\">".$data."</textarea>
        ".$bottom_panel."<br /></form></div>";
        break;
        case "create_ddc":
        include($root_path."usr/system/edit_template.inc.php");
        if ($_POST["html"] and stripslashes($_POST["name"]) and $DEMO_MODE!="enabled") {
                $fp=fopen($root_path . "usr/xml/ddc/" . $_POST["name"] . ".xml", "w+");
                fwrite($fp, (ini_get("magic_quotes_gpc")?stripslashes($_POST["html"]):$_POST["html"]));
                fclose($fp);
                $_GET["option"]="ddc";
                option_switch();
                break;
        }
        $panel .= "<div class=\"panel\" style=\"margin-top: 3px; text-align: center;\"><form style=\"margin: 0px 0px 0px 0px\" method=\"post\"  onClick=\"id_form_focus='form_1'\" id=\"form_1\"><b>".$lang["Container"].":</b> <input type=\"text\" name=\"name\">.xml<br />".$panel."
<textarea name=\"html\" id=\"html\" ONSELECT=\"storeCaret(html);\" ONCLICK=\"storeCaret(html);\" ONKEYUP=\"storeCaret(html);\" style=\"width: 100%; height: 400px; margin: 5px 15px 5px 5px; ".($SystemTextAreaStyle ? $SystemTextAreaStyle : "background-color: white; font-family: Courier new,Tahoma, Arial; font-size: 12px;")."\" cols=\"100\">".$data."</textarea>".$bottom_panel."<br /></form></div>";
        break;
        case "delete_ddc":
        if ($_GET["name"] and $DEMO_MODE!="enabled") {
                @unlink($root_path . "usr/xml/ddc/" . $_GET["name"]);
                $_GET["option"]="ddc";
                option_switch();
                break;
        }
        break;
}

?>
Return current item: SAPID