Author: Not specified Language: php
Description: Not specified Timestamp: 2017-01-29 17:11:06 +0000
View raw paste Reply
require_once './Page.php';

class HTML_Tester extends Page

    protected $name;
    protected $code;
    private $loadname;

    protected function __construct() {
        $this->name = NULL;
        $this->code = NULL;
        $this->loadname ='Absatz';
    protected function __destruct() {
        // to do: if necessary, destruct attribute objects representing substructures/blocks
    public static function main() {
        try {
            $page = new HTML_Tester();
        catch (Exception $e) {
            header("Content-type: text/plain; charset=UTF-8");
            echo $e->getMessage();

    protected function getViewData() {

        $sql = "SELECT name, code FROM html";

        $recordset = $this->_database->query($sql);
        if (!$recordset)
                throw new Exception("Fehler in Abfrage: ".$this->_database->error);

        $fragments = array();

        while ($html = $recordset->fetch_assoc()){
            $fragments[$html['name']] = $html['code'];
        return $fragments;
        catch(Exception $ex){
            echo $ex->getMessage();

    protected function generateView() {

        $fragments = $this->getViewData(); // hier müssen die Daten rein, die auf der Seite benutzt werden
        $initCode = htmlspecialchars($fragments[$this->loadname]); // 'Absatz'

        $this->generatePageHeader('HTML Tester');

        echo "<form methode='GET' action='HTML_Tester.php'>";
        echo "<div class ='HTML_TesterDiv'>
        <select name='loadname' size='1'>

        foreach ($fragments as $name => $code){
            if ($this->loadname == $name){
                $selected = htmlspecialchars($name);
            } else {
                $selected = "";
            $name2 = htmlspecialchars($name);
            echo "<option $selected> $name2 </option>";
        echo "</select>";
        echo "<input type='submit' name='load' value='laden' </input>";
        echo "</form>";
        echo "<form methode='POST' action='HTML_Tester.php' onsubmit='return tagsOK();'>
        <p> <label> Code bearbeiten: </label></p>
        <textarea name='source' class ='box' id='sourcecode' rows='10' cols='40'
          required> $initCode </textarea>
        <p> <input type='button' name='show' value='Vorschau aktualisieren'  
        onclick='showPreview();' </input></p>
        <div class='box' id ='preview'> </div>
        <label> Code unter
        <input type= 'text' name='storename' placeholder='neuem Namen' required size='12'>
        <input type='submit' name='store' value='speichern'</>
        // das erste lable links vom feld das zweite darüber...

    protected function processReceivedData() {
        // to do: call processReceivedData() for all member variables:
        if (isset($_GET['loadname']) && $_GET['loadname']) {
            $this->loadname = $_GET['loadname'];
        if(isset($_POST['storename']) && isset($_POST['storename'])&&
        isset($_POST['source']) && $_POST['source']){
            $name = $this->_database->real_escape_string($_POST['storename']);
            $source = $this->_database->real_escape_string($_POST['source']);

            $sql = "INSERT INTO html(name, code) VALUES ('$name', '$source');";
            $ok = $this->_database->query($sql);
            if (!$ok)
                throw new Exception("Speichern fehlgeschlagen");
View raw paste Reply