PHP Script ändern damit mysqli / PHP 7.2 funktioniert

cliodriver

Mitglied
Hallo

das ist seit langem wieder mal eine Frage / Bitte um Hilfe zu einem PHP-Script.

Ich habe vor einem Jahr eine Homepage für eine Bekannte (Ferienwohnungen) erstellt und ein fertiges Script für einen Belegungskalender eingebaut und dabei nicht bedacht / gewusst das der Server demnächst auf PHP 7.2 umstellt. Ich konnte schon testen und den Rest der Homepage anpassen, doch leider bin ich mit meinem Latein am ende und der Kalender funktioniert natürlich nicht.

Das Problem liegt natürlich an der Datenbankverbindung .... mysqli unter PHP 7.2, welche ich nicht gefixt bekomme

Meine Frage dazu:

Kann sich jemand den Code mal ansehen und sagen er sich anpassen lässt bzw. hätte gleich Tipps für mich? Ich würde gerne verstehen wo der Hund begraben liegt und es selber ändern, doch ohne Hilfe komm ich grad nicht weiter.

Weiters umfasst das ganze ca. 19 Seiten und wenn ich die alle hier poste, wird's wahrscheinlich unübersichtlich. Ich würde das Paket per email versenden wenn ich Hilfe bekomme.

Danke
 
Lösung
So habe mir das mal angeschaut.

Es ist nur die db.class.php anzupassen.

PHP:
<?php
// Class for database connection
class DatabaseConnection {

    public    $error = false;
    public    $version = false;
    private    $link = false;
    private $config = array ();

    /**
     * Wrapper for connect ()
     * @param    $db        Array with vars from config
     * @return            result from connect ()
     */
    public function databaseConnection ($mysql) {
        $this->config = $mysql;
        return $this->connect ();
    }

    /**
     * Tries to connect to db and checks installation.
     * @return            true if no error, else false
     */
    public function connect () {
        // Reset $error
        $this->error...
meine letzte antwort habe ich mit dem Handy unterwegs geschrieben, darum jetzt etwas ausführlicher.

in allen admin/pages/*.php die "mysqli_real_escape_string()" entfernen, dies funktioniert unter php7 nicht mehr.

anbei noch meine *.php welche funktionieren. normal müsstest du sie 1:1 übernehmen können (Datenbankteil), vergleiche aber nochmal da ich den ganzen Kalender doch etwas mehr modifiziert habe, was speziell die Ausgabe betrifft. Auch hab ich den Adminbereich verändert (passworteingabe, etwas andere Ausgabe als im frontend)

classes.php

PHP:
<?php

$pageTitle .= ' - ' . __('adminClasses');

// Save or delete
if (isset ($_POST['class'])) {
    if ($db -> idExists ('classes', $_POST['class'])) {
        $id = $_POST['class'];
        $db -> query ("UPDATE `classes` SET `color`='" . $_POST['color'] . "' WHERE `id`=" . $id);
        $db -> query ("DELETE FROM `classes_per_language` WHERE `class_id`=" . $id);
    }
    else
        $id = $db -> query ("INSERT INTO `classes` SET `color`='" . $_POST['color'] . "'", 'insert_id');
    foreach ($GLOBALS['langsActive'] as $lang)
        $db -> query ("INSERT INTO `classes_per_language` SET `name`='" . $_POST['name_' . $lang['abbr']] . "', `content`='" . $_POST['content_' . $lang['abbr']] . "', `language_id`=" . $lang['id'] . ", `class_id`=" . $id);
}
elseif (isset ($_GET['action']) && $_GET['action'] == 'del2' && $db -> idExists ('classes', $_GET['class'])) {
    $id = $_GET['class'];
    $db -> query ("DELETE `entries_per_language` FROM `entries_per_language` LEFT JOIN `entries` ON `entries`.`id`=`entries_per_language`.`entry_id` WHERE `entries`.`class_id`=" . $id);
    $db -> query ("DELETE `entries_static` FROM `entries_static` LEFT JOIN `entries` ON `entries`.`id`=`entries_static`.`entry_id` WHERE `entries`.`class_id`=" . $id);
    $db -> query ("DELETE `entry_returning` FROM `entry_returning` LEFT JOIN `entries` ON `entries`.`id`=`entry_returning`.`entry_id` WHERE `entries`.`class_id`=" . $id);
    $db -> query ("DELETE FROM `entries` WHERE `class_id`=" . $id);
    $db -> query ("DELETE FROM `classes_per_language` WHERE `class_id`=" . $id);
    $db -> query ("DELETE FROM `classes` WHERE `id`=" . $id);
}

// Read classes
$array = $db -> select ("SELECT `id`, `color` FROM `classes` ORDER BY `id`");
if ($array) {
    foreach ($array as $row)
        $classes[$row['id']] = array ('color' => $row['color']);
    $langs = array ();
    foreach ($GLOBALS['langsActive'] as $lang)
        $langs[] = $lang['id'];
    $array = $db -> select ("SELECT `class_id`, `language_id`, `name`, `content` FROM `classes_per_language` WHERE `language_id`=" . implode (' OR `language_id`=', $langs));
    foreach ($array as $row)
        $classes[$row['class_id']][$row['language_id']] = array (
            'name' => $row['name'],
            'content' => $row['content']
        );
}
else
    $classes = array ();

// Create, edit or delete class
if (isset ($_GET['class']) && array_key_exists ($_GET['class'], $classes)) {
    $id = $_GET['class'];
}
else {
    $id = 0;
}
if (isset ($_GET['action']) && $_GET['action'] == 'del' && $id > 0) {
    $r .= '<p>&nbsp;</p><h3>' . __('adminDeleteClass') . ' (' . $id . '):</h3>';
    $r .= '<p>' . __('adminDeleteClassReally') . '</p>';
    $r .= '<p><input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=classes&amp;action=del2&amp;class=' . $id . '\'" value="' . __('adminContinue') . '" /> <input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=classes\'" value="' . __('adminCancel') . '" /></p>';
}
else {
    if ($id == 0) {
        $r .= '<p>&nbsp;</p><h3>' . __('adminNewClass') . ':</h3>';
    }
    else {
        $r .= '<p>&nbsp;</p><h3>' . __('adminEditClass') . ' (' . $id . '):</h3>';
    }
    // Form
    $r .= '<form action="?page=kalender.admin.php&amp;calpage=classes" method="post">';
    $r .= '<table>';
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<tr><th>' . __('adminName') . ' (' . $lang['name'] . '):</th><td><input class="box" type="text" name="name_' . $lang['abbr'] . '" size="30" maxlength="30"';
        if (isset ($classes[$id][$lang['id']]['name']))
            $r .= ' value="' . $classes[$id][$lang['id']]['name'] . '"';
        $r .= ' /></td></tr>';
    }
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<tr><th>' . __('adminCellContent') . ' (' . $lang['name'] . '):</th><td><input class="box" type="text" name="content_' . $lang['abbr'] . '" size="2" maxlength="2"';
        if (isset ($classes[$id][$lang['id']]['content']))
            $r .= ' value="' . $classes[$id][$lang['id']]['content'] . '"';
        $r .= ' /></td></tr>';
    }
    $r .= '<tr><th>' . __('adminColor') . '</th><td><input class="box" type="text" name="color" size="6" maxlength="6"';
    if (isset ($classes[$id]['color']))
        $r .= ' value="' . $classes[$id]['color'] . '"';
    $r .= ' /></td></tr>';
    $r .= '</table>';
    $r .= '<p><input type="submit" value="' . __('adminSubmit') . '" /> <input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=classes\'" value="' . __('adminCancel') . '" /><input type="hidden" name="class" value="' . $id . '" /></p>';
    $r .= '</form>';
}

// List classes
$r .= '<p>&nbsp;</p><h3>' . __('adminClasses') . ':</h3>';
$r .= '<table>';
$r .= '<tr><th>' . __('adminNo') . '</th>';
foreach ($GLOBALS['langsActive'] as $lang) {
    $r .= '<th>' . __('adminName') . ' (' . $lang['name'] . ')</th>';
}
foreach ($GLOBALS['langsActive'] as $lang) {
    $r .= '<th>' . __('adminCellContent') . ' (' . $lang['name'] . ')</th>';
}
$r .= '<th>' . __('adminColor') . '</th>';
$r .= '</tr>';
foreach ($classes as $id => $values) {
    $r .= '<tr><td>' . $id . '</td>';
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<td>';
        if (isset ($values[$lang['id']]['name']))
            $r .= $values[$lang['id']]['name'];
        $r .= '</td>';
    }
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<td>';
        if (isset ($values[$lang['id']]['content']))
            $r .= $values[$lang['id']]['content'];
        $r .= '</td>';
    }
    $r .= '<td style="background-color: #' . $values['color'] . '">' . $values['color'] . '</td>';
    $r .= '<td>&nbsp;&nbsp;<a href="?page=kalender.admin.php&amp;calpage=classes&amp;class=' . $id . '">' . __('adminEdit') . '</a>&nbsp;&nbsp;<a href="?page=kalender.admin.php&amp;calpage=classes&amp;class=' . $id . '&amp;action=del">' . __('adminDelete') . '</a></td>';
    $r .= '</tr>';
}
$r .= '</table>';


entries.php

PHP:
<?php

// JavaScript
$r .= '<script src="' . BASEDIR . 'admin/js/entries.js" type="text/javascript" charset="utf-8"></script>';

$pageTitle .= ' - ' . __('adminEntries');

if (isset ($_GET['entry']) && $db -> idExists ('entries', $_GET['entry']))
    $id = $_GET['entry'];
else
    $id = 0;

// initiate calendar
$cal = new Calendar ($db, $prefs);
$cal -> enableCellsAsLinks = true;
$cal -> hideExpiredDates = false;
if (isset ($_GET['year']))
    $year = $_GET['year'];
else
    $year = 0;
if (isset ($_GET['object']))
    $object = $_GET['object'];
else
    $object = $prefs['objectDefault'];
$cal -> setObject ($object);
$cal -> setYear ($year);

$weekdaysAbbr = __('weekdaysAbbr');

// Delete entry
if (isset ($_GET['action']) && $_GET['action'] == 'del') {
    $db -> query ("DELETE FROM `entry_returning` WHERE `entry_id`=" . $id);
    $db -> query ("DELETE FROM `entries_static` WHERE `entry_id`=" . $id);
    $db -> query ("DELETE FROM `entries_per_language` WHERE `entry_id`=" . $id);
    $db -> query ("DELETE FROM `entries` WHERE `id`=" . $id);
    $id = 0;
}
// Save entry
elseif (count ($_POST)) {
    // check values
    if ($db -> idExists ('objects', $_POST['object']))
        $object = $_POST['object'];
    else
        $object = 0;
    $cal -> setObject ($object); // display object where changes were made
    if ($db -> idExists ('classes', $_POST['class']))
        $class = $_POST['class'];
    else
        $class = 0;
    if ($_POST['kind'] == 'static' || $_POST['kind'] == 'returning')
        $kind = $_POST['kind'];
    else
        $kind = 'static';
    // insert/update main table
    if ($id == 0)
        $id = $db -> query ("INSERT INTO `entries` SET `object_id`=" . $object . ", `class_id`=" . $class . ", `kind`='" . $kind . "'", 'insert_id');
    else {
        $db -> query ("UPDATE `entries` SET `object_id`=" . $object . ", `class_id`=" . $class . ", `kind`='" . $kind . "' WHERE `id`=" . $id);
        $db -> query ("DELETE FROM `entries_per_language` WHERE `entry_id`=" . $id);
        $db -> query ("DELETE FROM `entries_static` WHERE `entry_id`=" . $id);
        $db -> query ("DELETE FROM `entry_returning` WHERE `entry_id`=" . $id);
    }
    // insert language specific
    foreach ($GLOBALS['langsActive'] as $lang)
        $db -> query ("INSERT INTO `entries_per_language` SET `entry_id`=" . $id . ", `language_id`=" . $lang['id'] . ", `desc`='" . $_POST['desc_' . $lang['abbr']] . "'");
    // insert static
    if ($kind == 'static') {
        if (@checkdate ($_POST['static_fromM'], $_POST['static_fromD'], $_POST['static_fromY'])
            && @checkdate ($_POST['static_toM'], $_POST['static_toD'], $_POST['static_toY'])
            && (mktime (0, 0, 0, $_POST['static_toM'], $_POST['static_toD'], $_POST['static_toY'])
                >= mktime (0, 0, 0, $_POST['static_fromM'], $_POST['static_fromD'], $_POST['static_fromY']))) {
            $from = $_POST['static_fromY'] . '-' . $_POST['static_fromM'] . '-' . $_POST['static_fromD'];
            $to = $_POST['static_toY'] . '-' . $_POST['static_toM'] . '-' . $_POST['static_toD'];
            $db -> query ("INSERT INTO `entries_static` SET `entry_id`=" . $id . ", `from`='" . $from . "', `to`='" . $to . "'");
            $cal -> setYear ($_POST['static_fromY']); // display year where changes were made
        }
    }
    // insert returning
    else {
        foreach ($_POST['returning_wday'] as $wday) {
            if (is_numeric ($wday) && $wday > 0 && $wday < 8 && $wday % 1 == 0)
                $db -> query ("INSERT INTO `entry_returning` SET `entry_id`=" . $id . ", `wday`=" . $wday);
        }
    }
    // reset id if finished editing
    if (isset ($_POST['submit']))
        $id = 0;
}

// display calendar
$r .= '<p>' . $cal -> getHeader () . '</p>';
$r .= $cal -> showSelect ();
$r .= $cal -> display ();

// Values
$entry = array (
    'class_id' => 0,
    'object_id' => $cal -> objectIdViewed,
    'kind' => 'static',
    'from' => date ('Y-m-d'),
    'to' => date ('Y-m-d'),
    'disableStatic' => true,
    'disableReturning' => true
);
for ($i = 1; $i < 8; $i ++) {
    $entry['returning_wday' . $i] = '';
}
foreach ($GLOBALS['langsActive'] as $lang) {
    $entry['desc'][$lang['id']] = '';
}
if ($id == 0) {
    $r .= '<p>&nbsp;</p><h3>' . __('adminNewEntry') . ':</h3>';
    $r .= '<p>(' . __('adminEntryHelpEdit') . ')</p>';
}
else {
    $r .= '<p>&nbsp;</p><h3>' . __('adminEditEntry') . ':</h3>';
    $r .= '<p>(' . __('adminEntryHelpNew') . ')</p>';
    $array = $db -> select ("SELECT `object_id`, `class_id`, `kind` FROM `entries` WHERE `id`=" . $id);
    $entry = array_merge ($entry, $array[0]);
    if ($entry['kind'] == 'static') {
        $array = $db -> select ("SELECT `from`, `to` FROM `entries_static` WHERE `entry_id`=" . $id);
        $entry = array_merge ($entry, $array[0]);
    }
    else {
        $array = $db -> select ("SELECT `wday` FROM `entry_returning` WHERE `entry_id`=" . $id);
        foreach ($array as $row)
            $entry['returning_wday' . $row['wday']] = ' checked="checked"';
    }
    $array = $db -> select ("SELECT `language_id`, `desc` FROM `entries_per_language` WHERE `entry_id`=" . $id);
    foreach ($array as $row)
        $entry['desc'][$row['language_id']] = $row['desc'];
}
if ($entry['kind'] == 'static')
    $entry['disableStatic'] = false;
elseif ($entry['kind'] == 'returning')
    $entry['disableReturning'] = false;

// Form
$r .= '<form action="?page=kalender.admin.php&amp;year=' . $cal -> year . '&amp;object=' . $cal -> objectId . '&amp;entry=' . $id . '" method="post">';
$r .= '<table>';
// class & object
$r .= '<tr><th>' . __('adminClass') . ':</th><td>' . echoSelectClass ($db, $entry['class_id'], 'class') . '</td></tr>';
$r .= '<tr><th>' . __('adminObject') . ':</th><td>' . echoSelectObject ($db, $entry['object_id'], 'object') . '</td></tr>';
// description per language
foreach ($GLOBALS['langsActive'] as $lang)
    $r .= '<tr><th>' . __('adminDesc') . ' (' . $lang['name'] . '):</th><td><input class="box" type="text" name="desc_' . $lang['abbr'] . '" size="50" maxlength="100" value="' . $entry['desc'][$lang['id']] . '" /></td></tr>';
$r .= '<tr><th>' . __('adminEntryDates') . ':</th><td>';
$r .= '<table><tr><td>';
// static
$r .= '<input class="box" type="radio" name="kind" id="static_kind" value="static" onchange="disableKind();"';
if ($entry['kind'] == 'static')
    $r .= ' checked="checked"';
$r .= ' /> <label for="static_kind">' . __('adminEntryStatic') . '</label><br />';
$r .= '<table><tr><th>' . __('adminEntryFrom') . ':</th><td>' . echoSelectDate ('static_from', $entry['from'], $entry['disableStatic'], 'adjustToDate();') . '</td></tr>';
$r .= '<tr><th>' . __('adminEntryTo') . ':</th><td>' . echoSelectDate ('static_to', $entry['to'], $entry['disableStatic']) . '</td></tr></table>';
$r .= '</td><td>';
// returning
$r .= '<input class="box" type="radio" name="kind" id="returning_kind" value="returning" onchange="disableKind();"';
if ($entry['kind'] == 'returning')
    $r .= ' checked="checked"';
$r .= ' /> <label for="returning_kind">' . __('adminEntryReturning') . '</label>';
$r .= '<table><tr><th>' . __('adminEntryWeekly') . ':</th><td>';
for ($i = 1; $i < 8; $i ++) {
    $r .= '<input class="box" type="checkbox" name="returning_wday[]" id="returning_wday' . $i . '" value="' . $i . '"';
    if ($entry['disableReturning'])
        $r .= ' disabled="disabled"';
    $r .= $entry['returning_wday' . $i] . ' /> <label for="returning_wday' . $i . '">' . $weekdaysAbbr[($i - 1)] . '</label> ';
}
$r .= '</td></tr></table>';
$r .= '</td></tr></table></td></tr>';
$r .= '</table>';
$r .= '<p><input type="submit" name="submit" value="' . __('adminSubmit') . '" /> <input type="submit" name="submitAndEdit" value="' . __('adminSubmitAndEdit') . '" /> <input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;year=' . $cal -> year . '&amp;object=' . $cal -> objectId . '\'" value="' . __('adminCancel') . '" />';
if ($id > 0)
    $r .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;year=' . $cal -> year . '&amp;object=' . $cal -> objectId . '&amp;entry=' . $id . '&amp;action=del\'" value="' . __('adminDeleteEntry') . '" />';
$r .= '</p>';
$r .= '</form>';


objects.php

PHP:
<?php

$pageTitle .= ' - ' . __('adminObjects');

// Save or delete
if (isset ($_POST['object'])) {
    $post = $db -> mysql_real_escape_mixed ($_POST);
    if ($db -> idExists ('objects', $post['object'])) {
        $id = $post['object'];
        $db -> query ("DELETE FROM `objects_per_language` WHERE `object_id`=" . $id);
    }
    else
        $id = $db -> query ("INSERT INTO `objects` SET `id`=NULL", 'insert_id');
    foreach ($GLOBALS['langsActive'] as $lang)
        $db -> query ("INSERT INTO `objects_per_language` SET `name`='" . $post['name_' . $lang['abbr']] . "', `desc`='" . $post['desc_' . $lang['abbr']] . "', `language_id`=" . $lang['id'] . ", `object_id`=" . $id);
}
elseif (isset ($_GET['action']) && $_GET['action'] == 'del2' && $db -> idExists ('objects', $_GET['object'])) {
    $id = $_GET['object'];
    $db -> query ("DELETE `entries_per_language` FROM `entries_per_language` LEFT JOIN `entries` ON `entries`.`id`=`entries_per_language`.`entry_id` WHERE `entries`.`object_id`=" . $id);
    $db -> query ("DELETE `entries_static` FROM `entries_static` LEFT JOIN `entries` ON `entries`.`id`=`entries_static`.`entry_id` WHERE `entries`.`object_id`=" . $id);
    $db -> query ("DELETE `entry_returning` FROM `entry_returning` LEFT JOIN `entries` ON `entries`.`id`=`entry_returning`.`entry_id` WHERE `entries`.`object_id`=" . $id);
    $db -> query ("DELETE FROM `entries` WHERE `object_id`=" . $id);
    $db -> query ("DELETE FROM `objects_per_language` WHERE `object_id`=" . $id);
    $db -> query ("DELETE FROM `objects` WHERE `id`=" . $id);
}

// Read objects
$array = $db -> select ("SELECT `id` FROM `objects` ORDER BY `id`");
if ($array) {
    foreach ($array as $row)
        $objects[$row['id']] = array ();
    $langs = array ();
    foreach ($GLOBALS['langsActive'] as $lang)
        $langs[] = $lang['id'];
    $array = $db -> select ("SELECT `object_id`, `language_id`, `name`, `desc` FROM `objects_per_language` WHERE `language_id`=" . implode (' OR `language_id`=', $langs));
    foreach ($array as $row)
        $objects[$row['object_id']][$row['language_id']] = array (
            'name' => $row['name'],
            'desc' => $row['desc']
        );
}
else
    $objects = array ();

// Create, edit or delete object
if (isset ($_GET['object']) && array_key_exists ($_GET['object'], $objects)) {
    $id = $_GET['object'];
}
else {
    $id = 0;
}
if (isset ($_GET['action']) && $_GET['action'] == 'del' && $id > 0) {
    $r .= '<p>&nbsp;</p><h3>' . __('adminDeleteObject') . ' (' . $id . '):</h3>';
    $r .= '<p>' . __('adminDeleteObjectReally') . '</p>';
    $r .= '<p><input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=objects&amp;action=del2&amp;object=' . $id . '\'" value="' . __('adminContinue') . '" /> <input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=objects\'" value="' . __('adminCancel') . '" /></p>';
}
else {
    if ($id == 0) {
        $r .= '<p>&nbsp;</p><h3>' . __('adminNewObject') . ':</h3>';
    }
    else {
        $r .= '<p>&nbsp;</p><h3>' . __('adminEditObject') . ' (' . $id . '):</h3>';
    }
    // Form
    $r .= '<form action="?page=kalender.admin.php&amp;calpage=objects" method="post">';
    $r .= '<table>';
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<tr><th>' . __('adminName') . ' (' . $lang['name'] . '):</th>';
        $r .= '<td><input class="box" type="text" name="name_' . $lang['abbr'] . '" size="30" maxlength="50"';
        if (isset ($objects[$id][$lang['id']]))
            $r .= ' value="' . $objects[$id][$lang['id']]['name'] . '"';
        $r .= ' /></td></tr>';
    }
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<tr><th>' . __('adminDesc') . ' (' . $lang['name'] . '):</th>';
        $r .= '<td><script>edToolbar(\'desc_' . $lang['abbr'] . '\'); </script><textarea class="box" id="desc_' . $lang['abbr'] . '" name="desc_' . $lang['abbr'] . '" rows="5" cols="50">';
        if (isset ($objects[$id][$lang['id']]))
            $r .= $objects[$id][$lang['id']]['desc'];
        $r .= '</textarea></td></tr>';
    }
    $r .= '</table>';
    $r .= '<p><input type="submit" value="' . __('adminSubmit') . '" /> <input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=objects\'" value="' . __('adminCancel') . '" /><input type="hidden" name="object" value="' . $id . '" /></p>';
    $r .= '</form>';
}

// List objects
$r .= '<p>&nbsp;</p><h3>' . __('adminObjects') . ':</h3>';
$r .= '<table>';
$r .= '<tr><th>' . __('adminNo') . '</th>';
foreach ($GLOBALS['langsActive'] as $lang) {
    $r .= '<th>' . __('adminName') . ' (' . $lang['name'] . ')</th>';
    $r .= '<th>' . __('adminDesc') . ' (' . $lang['name'] . ')</th>';
}
$r .= '</tr>';
foreach ($objects as $id => $content) {
    $r .= '<tr><td>' . $id . '</td>';
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<td>';
        if (isset ($content[$lang['id']]))
            $r .= $content[$lang['id']]['name'];
        $r .= '</td><td>';
        if (isset ($content[$lang['id']]))
            $r .= shortenString ($content[$lang['id']]['desc']);
        $r .= '</td>';
    }
    $r .= '<td>&nbsp;&nbsp;<a href="?page=kalender.admin.php&amp;calpage=objects&amp;object=' . $id . '">' . __('adminEdit') . '</a>&nbsp;&nbsp;<a href="?page=kalender.admin.php&amp;calpage=objects&amp;object=' . $id . '&amp;action=del">' . __('adminDelete') . '</a></td>';
    $r .= '</tr>';
}
$r .= '</table>';


prefs.php

PHP:
<?php

// Functions
function echoChangeYesNo ($name, $selected) {
    $r = '';
    $r .= '<input class="box" type="radio" name="' . $name . '" id="' . $name . '1" value="1"';
    if ($selected == 1)
        $r .= ' checked="checked"';
    $r .= ' /> <label for="' . $name . '1">' . __('yes') . '</label>';
    $r .= ' <input class="box" type="radio" name="' . $name . '" id="' . $name . '0" value="0"';
    if ($selected == 0)
        $r .= ' checked="checked"';
    $r .= ' /> <label for="' . $name . '0">' . __('no') . '</label>';
    return $r;
}

function echoSelectLanguage ($selected) {
    $r = '';
    $r .= '<select name="languageDefault" size="1">';
    if (count ($GLOBALS['langsActive'])) {
        foreach ($GLOBALS['langsActive'] as $row) {
            $r .= '<option value="' . $row['id'] . '"';
            if ($selected == $row['id'])
                $r .= ' selected="selected"';
            $r .= '>' . $row['name'] . '</option>';
        }
    }
    $r .= '</select>';
    return $r;
}

function echoActivateLanguages () {
    $r = '<table cellspacing="0" cellpadding="2" border="0">';
    $result = readLanguages (true);
    foreach ($result as $row) {
        $r .= '<tr><td><input class="box" type="checkbox" name="languagesActive[]" value="' . $row['id'] . '"';
        if ($row['active'] == 1)
            $r .= ' checked="checked"';
        $r .= ' /></td>';
        $r .= '<td>' . $row['name'] . '</td>';
        $r .= '</tr>';
    }
    $r .= '</table>';
    return $r;
}

$pageTitle .= ' - ' . __('adminPrefs');

// Save changes
if (count ($_POST)) {
    foreach ($prefs as $name => $value) {
        if (isset ($_POST[$name]) && $_POST[$name] != $value) {
            $db -> query ("UPDATE `prefs` SET `value`='" . $_POST[$name] . "' WHERE `name`='" . $name . "'");
        }
    }
    $prefs = readPrefs ($db);
    $languages = readLanguages (true);
    foreach ($languages as $language) {
        if (isset ($_POST['languagesActive']) && in_array ($language['id'], $_POST['languagesActive'])) {
            if ($language['active'] == 0)
                $db -> query ("UPDATE `languages` SET `active`=1 WHERE `id`=" . $language['id']);
        }
        else {
            if ($language['active'] == 1)
                $db -> query ("UPDATE `languages` SET `active`=0 WHERE `id`=" . $language['id']);
        }
    }
    $GLOBALS['langsActive'] = readLanguages ();
    unset ($_SESSION['lang']);
}

// Prefs table
$r .= '<form action="?page=kalender.admin.php&amp;calpage=prefs" method="post">';
$r .= '<table>';
$r .= '<tr><th>' . __('prefsLanguageDefault') . ':</th><td>' . echoSelectLanguage ($prefs['languageDefault']) . '</td></tr>';
$r .= '<tr><th>' . __('prefsLanguagesActive') . ':</th><td>' . echoActivateLanguages () . '</td></tr>';
$r .= '<tr><th>' . __('prefsObjectDefault') . ':</th><td>' . echoSelectObject ($db, $prefs['objectDefault'], 'objectDefault') . '</td></tr>';
$r .= '<tr><th>' . __('prefsObjectShowSelect') . ':</th><td>' . echoChangeYesNo ('objectShowSelect', $prefs['objectShowSelect']) . '</td></tr>';
$r .= '<tr><th>' . __('prefsClassDefault') . ':</th><td>' . echoSelectClass ($db, $prefs['classDefault'], 'classDefault') . '</td></tr>';
$r .= '<tr><th>' . __('prefsClassFirstAndLastDay') . ':</th><td>' . echoSelectClass ($db, $prefs['classFirstAndLastDay'], 'classFirstAndLastDay', __('none')) . '</td></tr>';
$r .= '<tr><th>' . __('prefsHideExpiredDates') . ':</th><td>' . echoChangeYesNo ('hideExpiredDates', $prefs['hideExpiredDates']) . '</td></tr>';
$r .= '<tr><th>' . __('prefsShowTitleInFrontend') . ':</th><td>' . echoChangeYesNo ('showTitleInFrontend', $prefs['showTitleInFrontend']) . '</td></tr>';
$r .= '</table>';
$r .= '<p><input type="submit" value="' . __('adminSubmit') . '" /> <input type="reset" value="' . __('adminCancel') . '" /></p>';
$r .= '</form>';
 
Zuletzt bearbeitet:
@basti;
Zeile 13 ist noch mysql ohne I drinne.
stimmt aber dies ist eine individuelle funktion keine standard php... daher geht es... die kann mann benennen wie man will... formal richitg wäre es die auch so zu benennen.

Als erstes muss ich euch vielen vielen DANK sagen... manchmal hängt man einfach; Ihr habt mir paar lange Abende geretett!!!! DANKE ! DANKE ! DANKE ! DANKE ! DANKE !

also zur Lösung: es ist aus den MySQL Queries die mysqli_real_escape_string () zu entfernen und mit $post[xxx] zu ersetzen.
die $post muss ich vorher definieren

PHP:
    $post = $db -> mysql_real_escape_mixed ($_POST);


eine ganze objects.php sieht dann so aus:

PHP:
<?php
/**
* This file is part of GuestCal: http://guestcal.sourceforge.net/
*
* ©2012 dotplex e.K. / www.dotplex.de / info@dotplex.de
* Licenced under GPLv3 Open Source Licence: http://www.gnu.org/licenses/gpl-3.0.html
*/

$pageTitle .= ' - ' . __('adminObjects');

// Save or delete
if (isset ($_POST['object'])) {
    $post = $db -> mysql_real_escape_mixed ($_POST);
    if ($db -> idExists ('objects', $post['object'])) {
        $id = $post['object'];
        $db -> query ("DELETE FROM `objects_per_language` WHERE `object_id`=" . $id);
    }
    else
        $id = $db -> query ("INSERT INTO `objects` SET `id`=NULL", 'insert_id');
    foreach ($GLOBALS['langsActive'] as $lang)
        $db -> query ("INSERT INTO `objects_per_language` SET `name`='" . $post['name_' . $lang['abbr']] . "', `desc`='" . $post['desc_' . $lang['abbr']] . "', `language_id`=" . $lang['id'] . ", `object_id`=" . $id);
}
elseif (isset ($_GET['action']) && $_GET['action'] == 'del2' && $db -> idExists ('objects', $_GET['object'])) {
    $id = $_GET['object'];
    $db -> query ("DELETE `entries_per_language` FROM `entries_per_language` LEFT JOIN `entries` ON `entries`.`id`=`entries_per_language`.`entry_id` WHERE `entries`.`object_id`=" . $id);
    $db -> query ("DELETE `entries_static` FROM `entries_static` LEFT JOIN `entries` ON `entries`.`id`=`entries_static`.`entry_id` WHERE `entries`.`object_id`=" . $id);
    $db -> query ("DELETE `entry_returning` FROM `entry_returning` LEFT JOIN `entries` ON `entries`.`id`=`entry_returning`.`entry_id` WHERE `entries`.`object_id`=" . $id);
    $db -> query ("DELETE FROM `entries` WHERE `object_id`=" . $id);
    $db -> query ("DELETE FROM `objects_per_language` WHERE `object_id`=" . $id);
    $db -> query ("DELETE FROM `objects` WHERE `id`=" . $id);
}

// Read objects
$array = $db -> select ("SELECT `id` FROM `objects` ORDER BY `id`");
if ($array) {
    foreach ($array as $row)
        $objects[$row['id']] = array ();
    $langs = array ();
    foreach ($GLOBALS['langsActive'] as $lang)
        $langs[] = $lang['id'];
    $array = $db -> select ("SELECT `object_id`, `language_id`, `name`, `desc` FROM `objects_per_language` WHERE `language_id`=" . implode (' OR `language_id`=', $langs));
    foreach ($array as $row)
        $objects[$row['object_id']][$row['language_id']] = array (
            'name' => $row['name'],
            'desc' => $row['desc']
        );
}
else
    $objects = array ();

// Create, edit or delete object
if (isset ($_GET['object']) && array_key_exists ($_GET['object'], $objects)) {
    $id = $_GET['object'];
}
else {
    $id = 0;
}
if (isset ($_GET['action']) && $_GET['action'] == 'del' && $id > 0) {
    $r .= '<h3>' . __('adminDeleteObject') . ' (' . $id . '):</h3>';
    $r .= '<p>' . __('adminDeleteObjectReally') . '</p>';
    $r .= '<p><input type="button" onclick="document.location=\'?page=objects&amp;action=del2&amp;object=' . $id . '\'" value="' . __('adminContinue') . '" /> <input type="button" onclick="document.location=\'?page=objects\'" value="' . __('adminCancel') . '" /></p>';
}
else {
    if ($id == 0) {
        $r .= '<h3>' . __('adminNewObject') . ':</h3>';
    }
    else {
        $r .= '<h3>' . __('adminEditObject') . ' (' . $id . '):</h3>';
    }
    // Form
    $r .= '<form action="?page=objects" method="post">';
    $r .= '<table>';
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<tr><th>' . __('adminName') . ' (' . $lang['name'] . '):</th>';
        $r .= '<td><input type="text" name="name_' . $lang['abbr'] . '" size="30" maxlength="50"';
        if (isset ($objects[$id][$lang['id']]))
            $r .= ' value="' . $objects[$id][$lang['id']]['name'] . '"';
        $r .= ' /></td></tr>';
    }
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<tr><th>' . __('adminDesc') . ' (' . $lang['name'] . '):</th>';
        $r .= '<td><textarea name="desc_' . $lang['abbr'] . '" rows="5" cols="50">';
        if (isset ($objects[$id][$lang['id']]))
            $r .= $objects[$id][$lang['id']]['desc'];
        $r .= '</textarea></td></tr>';
    }
    $r .= '</table>';
    $r .= '<p><input type="submit" value="' . __('adminSubmit') . '" /> <input type="button" onclick="document.location=\'?page=objects\'" value="' . __('adminCancel') . '" /><input type="hidden" name="object" value="' . $id . '" /></p>';
    $r .= '</form>';
}

// List objects
$r .= '<h3>' . __('adminObjects') . ':</h3>';
$r .= '<table>';
$r .= '<tr><th>' . __('adminNo') . '</th>';
foreach ($GLOBALS['langsActive'] as $lang) {
    $r .= '<th>' . __('adminName') . ' (' . $lang['name'] . ')</th>';
    $r .= '<th>' . __('adminDesc') . ' (' . $lang['name'] . ')</th>';
}
$r .= '</tr>';
foreach ($objects as $id => $content) {
    $r .= '<tr><td>' . $id . '</td>';
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<td>';
        if (isset ($content[$lang['id']]))
            $r .= $content[$lang['id']]['name'];
        $r .= '</td><td>';
        if (isset ($content[$lang['id']]))
            $r .= shortenString ($content[$lang['id']]['desc']);
        $r .= '</td>';
    }
    $r .= '<td><a href="?page=objects&amp;object=' . $id . '">' . __('adminEdit') . '</a> | <a href="?page=objects&amp;object=' . $id . '&amp;action=del">' . __('adminDelete') . '</a></td>';
    $r .= '</tr>';
}
$r .= '</table>';
 
Zuletzt bearbeitet:
Hallo zusammen,

ich stehe genau vor demselben Problem. Auch ich verwende diesen (schönen) Belegungsplan. Und wahrscheinlich werde ich nicht der Letzte mit diesem Problem sein. Das zugrundeliegende Projekt "GuestCal" [LINK] ist ja unter GPL3 lizensiert, wird aber offiziell nicht weiter entwickelt (also auch keine php7 Kompatibilität hergestellt).

Ich würde die Anpassungen gerne selbst vornehmen und das Projekt auf Github für die Gemeinschaft forken, aber mit php habe ich noch nie etwas gemacht.

Wie seht ihr das: würden einige von euch dabei mithelfen, das Projekt mit php7-Kompatibilität um ein Minorrelease auf 2.1.5 zu erhöhen? Es wäre wirklich schade, wenn guestcal in Zukunft nicht mehr lauffähig wäre. Es geht wirklich nur um die oben genannten Änderungen, um es mit php7 lauffähig zu machen.

Ich habe jetzt das letzte Release (2.1.4) von sourceforge in mein gitea eingepflegt und einen allgemeinen Account mit Schreibrechten auf das Projekt erstellt. Das Repository mit den fertigen Änderungen würde ich dann für die bessere Auffindbarkeit zu github umziehen.

Mein gitea-Repository: https://geimist.eu:30443/geimist/GuestCal
User und PW: tutorials_de_for_guestcal

Über Unterstützung von euch würde ich mich (und in Zukunft sicherlich auch viele andere) freuen :)

Vielen Dank im Voraus.

Gruß
Stephan
 
Die admin-Seite /guestcal/admin/?page=prefs funktioniert noch nicht. Geänderte Werte werden nicht übernommen.
 
Zuletzt bearbeitet:
Da wirst du die Klassen wohl etwas umbauen und einen Construktur rein bauen müssen. Wenn du klever bist, baust du gleich auf abstrakte Klasse mit Driver für verschiedene Datenbanken um.
 
Die admin-Seite /guestcal/admin/?page=prefs funktioniert noch nicht. Geänderte Werte werden nicht übernommen.


Hallo gamma,ich hatte das gleiche Problem, mit der Unterstützung der Forumsmitgleider wurde das gelöst, dh. die Lösungen stecken bereits in den geposteten QuellCodes...

ich habe mal auf der Seite von geimist https://geimist.eu:30443/geimist/GuestCal/src/branch/master/Guestcal_PHP7.zip meine funktionierende Version abgelegt.

eventuell hilft dir das...

Viel Glück ;)
 
prefs.php: https://www.alpila.de/guestcal/admin/?page=prefs
GuestCal: GuestCal - Haus Sander - 2019
Gästebuch: Gästebuch-Eintrag Haus Sander

PHP:
<?php
/**
* This file is part of GuestCal: http://guestcal.sourceforge.net/
*
* ©2012 dotplex e.K. / www.dotplex.de / info@dotplex.de
* Licenced under GPLv3 Open Source Licence: http://www.gnu.org/licenses/gpl-3.0.html
*/

// Functions
function echoChangeYesNo ($name, $selected) {
    $r = '';
    $r .= '<input type="radio" name="' . $name . '" id="' . $name . '1" value="1"';
    if ($selected == 1)
        $r .= ' checked="checked"';
    $r .= ' /> <label for="' . $name . '1">' . __('yes') . '</label>';
    $r .= ' <input type="radio" name="' . $name . '" id="' . $name . '0" value="0"';
    if ($selected == 0)
        $r .= ' checked="checked"';
    $r .= ' /> <label for="' . $name . '0">' . __('no') . '</label>';
    return $r;
}

function echoSelectLanguage ($selected) {
    $r = '';
    $r .= '<select name="languageDefault" size="1">';
    if (count ($GLOBALS['langsActive'])) {
        foreach ($GLOBALS['langsActive'] as $row) {
            $r .= '<option value="' . $row['id'] . '"';
            if ($selected == $row['id'])
                $r .= ' selected="selected"';
            $r .= '>' . $row['name'] . '</option>';
        }
    }
    $r .= '</select>';
    return $r;
}

function echoActivateLanguages () {
    $r = '<table cellspacing="0" cellpadding="2" border="0">';
    $result = readLanguages (true);
    foreach ($result as $row) {
        $r .= '<tr><td><input type="checkbox" name="languagesActive[]" value="' . $row['id'] . '"';
        if ($row['active'] == 1)
            $r .= ' checked="checked"';
        $r .= ' /></td>';
        $r .= '<td>' . $row['name'] . '</td>';
        $r .= '</tr>';
    }
    $r .= '</table>';
    return $r;
}

$pageTitle .= ' - ' . __('adminPrefs');

// Save changes
if (count ($_POST)) {
    foreach ($prefs as $name => $value) {
        if (isset ($_POST[$name]) && $_POST[$name] != $value) {
            $db -> query ("UPDATE `prefs` SET `value`='" . $_POST[$name] . "' WHERE `name`='" . $name . "'"); //alte Zeile: $db -> query ("UPDATE `prefs` SET `value`='" . mysql_real_escape_string ($_POST[$name]) . "' WHERE `name`='" . $name . "'");
        }
    }
    $prefs = readPrefs ($db);
    $languages = readLanguages (true);
    foreach ($languages as $language) {
        if (isset ($_POST['languagesActive']) && in_array ($language['id'], $_POST['languagesActive'])) {
            if ($language['active'] == 0)
                $db -> query ("UPDATE `languages` SET `active`=1 WHERE `id`=" . $language['id']);
        }
        else {
            if ($language['active'] == 1)
                $db -> query ("UPDATE `languages` SET `active`=0 WHERE `id`=" . $language['id']);
        }
    }
    $GLOBALS['langsActive'] = readLanguages ();
    unset ($_SESSION['lang']);
}

// Prefs table
$r .= '<form action="?page=prefs" method="post">';
$r .= '<table>';
$r .= '<tr><th>' . __('prefsLanguageDefault') . ':</th><td>' . echoSelectLanguage ($prefs['languageDefault']) . '</td></tr>';
$r .= '<tr><th>' . __('prefsLanguagesActive') . ':</th><td>' . echoActivateLanguages () . '</td></tr>';
$r .= '<tr><th>' . __('prefsObjectDefault') . ':</th><td>' . echoSelectObject ($db, $prefs['objectDefault'], 'objectDefault') . '</td></tr>';
$r .= '<tr><th>' . __('prefsObjectShowSelect') . ':</th><td>' . echoChangeYesNo ('objectShowSelect', $prefs['objectShowSelect']) . '</td></tr>';
$r .= '<tr><th>' . __('prefsClassDefault') . ':</th><td>' . echoSelectClass ($db, $prefs['classDefault'], 'classDefault') . '</td></tr>';
$r .= '<tr><th>' . __('prefsClassFirstAndLastDay') . ':</th><td>' . echoSelectClass ($db, $prefs['classFirstAndLastDay'], 'classFirstAndLastDay', __('none')) . '</td></tr>';
$r .= '<tr><th>' . __('prefsHideExpiredDates') . ':</th><td>' . echoChangeYesNo ('hideExpiredDates', $prefs['hideExpiredDates']) . '</td></tr>';
$r .= '<tr><th>' . __('prefsShowTitleInFrontend') . ':</th><td>' . echoChangeYesNo ('showTitleInFrontend', $prefs['showTitleInFrontend']) . '</td></tr>';
$r .= '</table>';
$r .= '<p><input type="submit" value="' . __('adminSubmit') . '" /> <input type="reset" value="' . __('adminCancel') . '" /></p>';
$r .= '</form>';
 
Zuletzt bearbeitet:
meine letzte antwort habe ich mit dem Handy unterwegs geschrieben, darum jetzt etwas ausführlicher.

in allen admin/pages/*.php die "mysqli_real_escape_string()" entfernen, dies funktioniert unter php7 nicht mehr.

anbei noch meine *.php welche funktionieren. normal müsstest du sie 1:1 übernehmen können (Datenbankteil), vergleiche aber nochmal da ich den ganzen Kalender doch etwas mehr modifiziert habe, was speziell die Ausgabe betrifft. Auch hab ich den Adminbereich verändert (passworteingabe, etwas andere Ausgabe als im frontend)

Edit: Bitte wirklich nur die Änderungen vom DB-Teil übernehmen. Wenn die Eingabemasken bzw. der untere Teil vom Code übernommen wird, funktioniert euer Adminbereich nicht mehr.

classes.php

PHP:
<?php

$pageTitle .= ' - ' . __('adminClasses');

// Save or delete
if (isset ($_POST['class'])) {
    if ($db -> idExists ('classes', $_POST['class'])) {
        $id = $_POST['class'];
        $db -> query ("UPDATE `classes` SET `color`='" . $_POST['color'] . "' WHERE `id`=" . $id);
        $db -> query ("DELETE FROM `classes_per_language` WHERE `class_id`=" . $id);
    }
    else
        $id = $db -> query ("INSERT INTO `classes` SET `color`='" . $_POST['color'] . "'", 'insert_id');
    foreach ($GLOBALS['langsActive'] as $lang)
        $db -> query ("INSERT INTO `classes_per_language` SET `name`='" . $_POST['name_' . $lang['abbr']] . "', `content`='" . $_POST['content_' . $lang['abbr']] . "', `language_id`=" . $lang['id'] . ", `class_id`=" . $id);
}
elseif (isset ($_GET['action']) && $_GET['action'] == 'del2' && $db -> idExists ('classes', $_GET['class'])) {
    $id = $_GET['class'];
    $db -> query ("DELETE `entries_per_language` FROM `entries_per_language` LEFT JOIN `entries` ON `entries`.`id`=`entries_per_language`.`entry_id` WHERE `entries`.`class_id`=" . $id);
    $db -> query ("DELETE `entries_static` FROM `entries_static` LEFT JOIN `entries` ON `entries`.`id`=`entries_static`.`entry_id` WHERE `entries`.`class_id`=" . $id);
    $db -> query ("DELETE `entry_returning` FROM `entry_returning` LEFT JOIN `entries` ON `entries`.`id`=`entry_returning`.`entry_id` WHERE `entries`.`class_id`=" . $id);
    $db -> query ("DELETE FROM `entries` WHERE `class_id`=" . $id);
    $db -> query ("DELETE FROM `classes_per_language` WHERE `class_id`=" . $id);
    $db -> query ("DELETE FROM `classes` WHERE `id`=" . $id);
}

// Read classes
$array = $db -> select ("SELECT `id`, `color` FROM `classes` ORDER BY `id`");
if ($array) {
    foreach ($array as $row)
        $classes[$row['id']] = array ('color' => $row['color']);
    $langs = array ();
    foreach ($GLOBALS['langsActive'] as $lang)
        $langs[] = $lang['id'];
    $array = $db -> select ("SELECT `class_id`, `language_id`, `name`, `content` FROM `classes_per_language` WHERE `language_id`=" . implode (' OR `language_id`=', $langs));
    foreach ($array as $row)
        $classes[$row['class_id']][$row['language_id']] = array (
            'name' => $row['name'],
            'content' => $row['content']
        );
}
else
    $classes = array ();

// Create, edit or delete class
if (isset ($_GET['class']) && array_key_exists ($_GET['class'], $classes)) {
    $id = $_GET['class'];
}
else {
    $id = 0;
}
if (isset ($_GET['action']) && $_GET['action'] == 'del' && $id > 0) {
    $r .= '<p>&nbsp;</p><h3>' . __('adminDeleteClass') . ' (' . $id . '):</h3>';
    $r .= '<p>' . __('adminDeleteClassReally') . '</p>';
    $r .= '<p><input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=classes&amp;action=del2&amp;class=' . $id . '\'" value="' . __('adminContinue') . '" /> <input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=classes\'" value="' . __('adminCancel') . '" /></p>';
}
else {
    if ($id == 0) {
        $r .= '<p>&nbsp;</p><h3>' . __('adminNewClass') . ':</h3>';
    }
    else {
        $r .= '<p>&nbsp;</p><h3>' . __('adminEditClass') . ' (' . $id . '):</h3>';
    }
    // Form
    $r .= '<form action="?page=kalender.admin.php&amp;calpage=classes" method="post">';
    $r .= '<table>';
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<tr><th>' . __('adminName') . ' (' . $lang['name'] . '):</th><td><input class="box" type="text" name="name_' . $lang['abbr'] . '" size="30" maxlength="30"';
        if (isset ($classes[$id][$lang['id']]['name']))
            $r .= ' value="' . $classes[$id][$lang['id']]['name'] . '"';
        $r .= ' /></td></tr>';
    }
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<tr><th>' . __('adminCellContent') . ' (' . $lang['name'] . '):</th><td><input class="box" type="text" name="content_' . $lang['abbr'] . '" size="2" maxlength="2"';
        if (isset ($classes[$id][$lang['id']]['content']))
            $r .= ' value="' . $classes[$id][$lang['id']]['content'] . '"';
        $r .= ' /></td></tr>';
    }
    $r .= '<tr><th>' . __('adminColor') . '</th><td><input class="box" type="text" name="color" size="6" maxlength="6"';
    if (isset ($classes[$id]['color']))
        $r .= ' value="' . $classes[$id]['color'] . '"';
    $r .= ' /></td></tr>';
    $r .= '</table>';
    $r .= '<p><input type="submit" value="' . __('adminSubmit') . '" /> <input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=classes\'" value="' . __('adminCancel') . '" /><input type="hidden" name="class" value="' . $id . '" /></p>';
    $r .= '</form>';
}

// List classes
$r .= '<p>&nbsp;</p><h3>' . __('adminClasses') . ':</h3>';
$r .= '<table>';
$r .= '<tr><th>' . __('adminNo') . '</th>';
foreach ($GLOBALS['langsActive'] as $lang) {
    $r .= '<th>' . __('adminName') . ' (' . $lang['name'] . ')</th>';
}
foreach ($GLOBALS['langsActive'] as $lang) {
    $r .= '<th>' . __('adminCellContent') . ' (' . $lang['name'] . ')</th>';
}
$r .= '<th>' . __('adminColor') . '</th>';
$r .= '</tr>';
foreach ($classes as $id => $values) {
    $r .= '<tr><td>' . $id . '</td>';
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<td>';
        if (isset ($values[$lang['id']]['name']))
            $r .= $values[$lang['id']]['name'];
        $r .= '</td>';
    }
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<td>';
        if (isset ($values[$lang['id']]['content']))
            $r .= $values[$lang['id']]['content'];
        $r .= '</td>';
    }
    $r .= '<td style="background-color: #' . $values['color'] . '">' . $values['color'] . '</td>';
    $r .= '<td>&nbsp;&nbsp;<a href="?page=kalender.admin.php&amp;calpage=classes&amp;class=' . $id . '">' . __('adminEdit') . '</a>&nbsp;&nbsp;<a href="?page=kalender.admin.php&amp;calpage=classes&amp;class=' . $id . '&amp;action=del">' . __('adminDelete') . '</a></td>';
    $r .= '</tr>';
}
$r .= '</table>';


entries.php

PHP:
<?php

// JavaScript
$r .= '<script src="' . BASEDIR . 'admin/js/entries.js" type="text/javascript" charset="utf-8"></script>';

$pageTitle .= ' - ' . __('adminEntries');

if (isset ($_GET['entry']) && $db -> idExists ('entries', $_GET['entry']))
    $id = $_GET['entry'];
else
    $id = 0;

// initiate calendar
$cal = new Calendar ($db, $prefs);
$cal -> enableCellsAsLinks = true;
$cal -> hideExpiredDates = false;
if (isset ($_GET['year']))
    $year = $_GET['year'];
else
    $year = 0;
if (isset ($_GET['object']))
    $object = $_GET['object'];
else
    $object = $prefs['objectDefault'];
$cal -> setObject ($object);
$cal -> setYear ($year);

$weekdaysAbbr = __('weekdaysAbbr');

// Delete entry
if (isset ($_GET['action']) && $_GET['action'] == 'del') {
    $db -> query ("DELETE FROM `entry_returning` WHERE `entry_id`=" . $id);
    $db -> query ("DELETE FROM `entries_static` WHERE `entry_id`=" . $id);
    $db -> query ("DELETE FROM `entries_per_language` WHERE `entry_id`=" . $id);
    $db -> query ("DELETE FROM `entries` WHERE `id`=" . $id);
    $id = 0;
}
// Save entry
elseif (count ($_POST)) {
    // check values
    if ($db -> idExists ('objects', $_POST['object']))
        $object = $_POST['object'];
    else
        $object = 0;
    $cal -> setObject ($object); // display object where changes were made
    if ($db -> idExists ('classes', $_POST['class']))
        $class = $_POST['class'];
    else
        $class = 0;
    if ($_POST['kind'] == 'static' || $_POST['kind'] == 'returning')
        $kind = $_POST['kind'];
    else
        $kind = 'static';
    // insert/update main table
    if ($id == 0)
        $id = $db -> query ("INSERT INTO `entries` SET `object_id`=" . $object . ", `class_id`=" . $class . ", `kind`='" . $kind . "'", 'insert_id');
    else {
        $db -> query ("UPDATE `entries` SET `object_id`=" . $object . ", `class_id`=" . $class . ", `kind`='" . $kind . "' WHERE `id`=" . $id);
        $db -> query ("DELETE FROM `entries_per_language` WHERE `entry_id`=" . $id);
        $db -> query ("DELETE FROM `entries_static` WHERE `entry_id`=" . $id);
        $db -> query ("DELETE FROM `entry_returning` WHERE `entry_id`=" . $id);
    }
    // insert language specific
    foreach ($GLOBALS['langsActive'] as $lang)
        $db -> query ("INSERT INTO `entries_per_language` SET `entry_id`=" . $id . ", `language_id`=" . $lang['id'] . ", `desc`='" . $_POST['desc_' . $lang['abbr']] . "'");
    // insert static
    if ($kind == 'static') {
        if (@checkdate ($_POST['static_fromM'], $_POST['static_fromD'], $_POST['static_fromY'])
            && @checkdate ($_POST['static_toM'], $_POST['static_toD'], $_POST['static_toY'])
            && (mktime (0, 0, 0, $_POST['static_toM'], $_POST['static_toD'], $_POST['static_toY'])
                >= mktime (0, 0, 0, $_POST['static_fromM'], $_POST['static_fromD'], $_POST['static_fromY']))) {
            $from = $_POST['static_fromY'] . '-' . $_POST['static_fromM'] . '-' . $_POST['static_fromD'];
            $to = $_POST['static_toY'] . '-' . $_POST['static_toM'] . '-' . $_POST['static_toD'];
            $db -> query ("INSERT INTO `entries_static` SET `entry_id`=" . $id . ", `from`='" . $from . "', `to`='" . $to . "'");
            $cal -> setYear ($_POST['static_fromY']); // display year where changes were made
        }
    }
    // insert returning
    else {
        foreach ($_POST['returning_wday'] as $wday) {
            if (is_numeric ($wday) && $wday > 0 && $wday < 8 && $wday % 1 == 0)
                $db -> query ("INSERT INTO `entry_returning` SET `entry_id`=" . $id . ", `wday`=" . $wday);
        }
    }
    // reset id if finished editing
    if (isset ($_POST['submit']))
        $id = 0;
}

// display calendar
$r .= '<p>' . $cal -> getHeader () . '</p>';
$r .= $cal -> showSelect ();
$r .= $cal -> display ();

// Values
$entry = array (
    'class_id' => 0,
    'object_id' => $cal -> objectIdViewed,
    'kind' => 'static',
    'from' => date ('Y-m-d'),
    'to' => date ('Y-m-d'),
    'disableStatic' => true,
    'disableReturning' => true
);
for ($i = 1; $i < 8; $i ++) {
    $entry['returning_wday' . $i] = '';
}
foreach ($GLOBALS['langsActive'] as $lang) {
    $entry['desc'][$lang['id']] = '';
}
if ($id == 0) {
    $r .= '<p>&nbsp;</p><h3>' . __('adminNewEntry') . ':</h3>';
    $r .= '<p>(' . __('adminEntryHelpEdit') . ')</p>';
}
else {
    $r .= '<p>&nbsp;</p><h3>' . __('adminEditEntry') . ':</h3>';
    $r .= '<p>(' . __('adminEntryHelpNew') . ')</p>';
    $array = $db -> select ("SELECT `object_id`, `class_id`, `kind` FROM `entries` WHERE `id`=" . $id);
    $entry = array_merge ($entry, $array[0]);
    if ($entry['kind'] == 'static') {
        $array = $db -> select ("SELECT `from`, `to` FROM `entries_static` WHERE `entry_id`=" . $id);
        $entry = array_merge ($entry, $array[0]);
    }
    else {
        $array = $db -> select ("SELECT `wday` FROM `entry_returning` WHERE `entry_id`=" . $id);
        foreach ($array as $row)
            $entry['returning_wday' . $row['wday']] = ' checked="checked"';
    }
    $array = $db -> select ("SELECT `language_id`, `desc` FROM `entries_per_language` WHERE `entry_id`=" . $id);
    foreach ($array as $row)
        $entry['desc'][$row['language_id']] = $row['desc'];
}
if ($entry['kind'] == 'static')
    $entry['disableStatic'] = false;
elseif ($entry['kind'] == 'returning')
    $entry['disableReturning'] = false;

// Form
$r .= '<form action="?page=kalender.admin.php&amp;year=' . $cal -> year . '&amp;object=' . $cal -> objectId . '&amp;entry=' . $id . '" method="post">';
$r .= '<table>';
// class & object
$r .= '<tr><th>' . __('adminClass') . ':</th><td>' . echoSelectClass ($db, $entry['class_id'], 'class') . '</td></tr>';
$r .= '<tr><th>' . __('adminObject') . ':</th><td>' . echoSelectObject ($db, $entry['object_id'], 'object') . '</td></tr>';
// description per language
foreach ($GLOBALS['langsActive'] as $lang)
    $r .= '<tr><th>' . __('adminDesc') . ' (' . $lang['name'] . '):</th><td><input class="box" type="text" name="desc_' . $lang['abbr'] . '" size="50" maxlength="100" value="' . $entry['desc'][$lang['id']] . '" /></td></tr>';
$r .= '<tr><th>' . __('adminEntryDates') . ':</th><td>';
$r .= '<table><tr><td>';
// static
$r .= '<input class="box" type="radio" name="kind" id="static_kind" value="static" onchange="disableKind();"';
if ($entry['kind'] == 'static')
    $r .= ' checked="checked"';
$r .= ' /> <label for="static_kind">' . __('adminEntryStatic') . '</label><br />';
$r .= '<table><tr><th>' . __('adminEntryFrom') . ':</th><td>' . echoSelectDate ('static_from', $entry['from'], $entry['disableStatic'], 'adjustToDate();') . '</td></tr>';
$r .= '<tr><th>' . __('adminEntryTo') . ':</th><td>' . echoSelectDate ('static_to', $entry['to'], $entry['disableStatic']) . '</td></tr></table>';
$r .= '</td><td>';
// returning
$r .= '<input class="box" type="radio" name="kind" id="returning_kind" value="returning" onchange="disableKind();"';
if ($entry['kind'] == 'returning')
    $r .= ' checked="checked"';
$r .= ' /> <label for="returning_kind">' . __('adminEntryReturning') . '</label>';
$r .= '<table><tr><th>' . __('adminEntryWeekly') . ':</th><td>';
for ($i = 1; $i < 8; $i ++) {
    $r .= '<input class="box" type="checkbox" name="returning_wday[]" id="returning_wday' . $i . '" value="' . $i . '"';
    if ($entry['disableReturning'])
        $r .= ' disabled="disabled"';
    $r .= $entry['returning_wday' . $i] . ' /> <label for="returning_wday' . $i . '">' . $weekdaysAbbr[($i - 1)] . '</label> ';
}
$r .= '</td></tr></table>';
$r .= '</td></tr></table></td></tr>';
$r .= '</table>';
$r .= '<p><input type="submit" name="submit" value="' . __('adminSubmit') . '" /> <input type="submit" name="submitAndEdit" value="' . __('adminSubmitAndEdit') . '" /> <input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;year=' . $cal -> year . '&amp;object=' . $cal -> objectId . '\'" value="' . __('adminCancel') . '" />';
if ($id > 0)
    $r .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;year=' . $cal -> year . '&amp;object=' . $cal -> objectId . '&amp;entry=' . $id . '&amp;action=del\'" value="' . __('adminDeleteEntry') . '" />';
$r .= '</p>';
$r .= '</form>';


objects.php

PHP:
<?php

$pageTitle .= ' - ' . __('adminObjects');

// Save or delete
if (isset ($_POST['object'])) {
    $post = $db -> mysql_real_escape_mixed ($_POST);
    if ($db -> idExists ('objects', $post['object'])) {
        $id = $post['object'];
        $db -> query ("DELETE FROM `objects_per_language` WHERE `object_id`=" . $id);
    }
    else
        $id = $db -> query ("INSERT INTO `objects` SET `id`=NULL", 'insert_id');
    foreach ($GLOBALS['langsActive'] as $lang)
        $db -> query ("INSERT INTO `objects_per_language` SET `name`='" . $post['name_' . $lang['abbr']] . "', `desc`='" . $post['desc_' . $lang['abbr']] . "', `language_id`=" . $lang['id'] . ", `object_id`=" . $id);
}
elseif (isset ($_GET['action']) && $_GET['action'] == 'del2' && $db -> idExists ('objects', $_GET['object'])) {
    $id = $_GET['object'];
    $db -> query ("DELETE `entries_per_language` FROM `entries_per_language` LEFT JOIN `entries` ON `entries`.`id`=`entries_per_language`.`entry_id` WHERE `entries`.`object_id`=" . $id);
    $db -> query ("DELETE `entries_static` FROM `entries_static` LEFT JOIN `entries` ON `entries`.`id`=`entries_static`.`entry_id` WHERE `entries`.`object_id`=" . $id);
    $db -> query ("DELETE `entry_returning` FROM `entry_returning` LEFT JOIN `entries` ON `entries`.`id`=`entry_returning`.`entry_id` WHERE `entries`.`object_id`=" . $id);
    $db -> query ("DELETE FROM `entries` WHERE `object_id`=" . $id);
    $db -> query ("DELETE FROM `objects_per_language` WHERE `object_id`=" . $id);
    $db -> query ("DELETE FROM `objects` WHERE `id`=" . $id);
}

// Read objects
$array = $db -> select ("SELECT `id` FROM `objects` ORDER BY `id`");
if ($array) {
    foreach ($array as $row)
        $objects[$row['id']] = array ();
    $langs = array ();
    foreach ($GLOBALS['langsActive'] as $lang)
        $langs[] = $lang['id'];
    $array = $db -> select ("SELECT `object_id`, `language_id`, `name`, `desc` FROM `objects_per_language` WHERE `language_id`=" . implode (' OR `language_id`=', $langs));
    foreach ($array as $row)
        $objects[$row['object_id']][$row['language_id']] = array (
            'name' => $row['name'],
            'desc' => $row['desc']
        );
}
else
    $objects = array ();

// Create, edit or delete object
if (isset ($_GET['object']) && array_key_exists ($_GET['object'], $objects)) {
    $id = $_GET['object'];
}
else {
    $id = 0;
}
if (isset ($_GET['action']) && $_GET['action'] == 'del' && $id > 0) {
    $r .= '<p>&nbsp;</p><h3>' . __('adminDeleteObject') . ' (' . $id . '):</h3>';
    $r .= '<p>' . __('adminDeleteObjectReally') . '</p>';
    $r .= '<p><input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=objects&amp;action=del2&amp;object=' . $id . '\'" value="' . __('adminContinue') . '" /> <input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=objects\'" value="' . __('adminCancel') . '" /></p>';
}
else {
    if ($id == 0) {
        $r .= '<p>&nbsp;</p><h3>' . __('adminNewObject') . ':</h3>';
    }
    else {
        $r .= '<p>&nbsp;</p><h3>' . __('adminEditObject') . ' (' . $id . '):</h3>';
    }
    // Form
    $r .= '<form action="?page=kalender.admin.php&amp;calpage=objects" method="post">';
    $r .= '<table>';
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<tr><th>' . __('adminName') . ' (' . $lang['name'] . '):</th>';
        $r .= '<td><input class="box" type="text" name="name_' . $lang['abbr'] . '" size="30" maxlength="50"';
        if (isset ($objects[$id][$lang['id']]))
            $r .= ' value="' . $objects[$id][$lang['id']]['name'] . '"';
        $r .= ' /></td></tr>';
    }
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<tr><th>' . __('adminDesc') . ' (' . $lang['name'] . '):</th>';
        $r .= '<td><script>edToolbar(\'desc_' . $lang['abbr'] . '\'); </script><textarea class="box" id="desc_' . $lang['abbr'] . '" name="desc_' . $lang['abbr'] . '" rows="5" cols="50">';
        if (isset ($objects[$id][$lang['id']]))
            $r .= $objects[$id][$lang['id']]['desc'];
        $r .= '</textarea></td></tr>';
    }
    $r .= '</table>';
    $r .= '<p><input type="submit" value="' . __('adminSubmit') . '" /> <input type="button" onclick="document.location=\'?page=kalender.admin.php&amp;calpage=objects\'" value="' . __('adminCancel') . '" /><input type="hidden" name="object" value="' . $id . '" /></p>';
    $r .= '</form>';
}

// List objects
$r .= '<p>&nbsp;</p><h3>' . __('adminObjects') . ':</h3>';
$r .= '<table>';
$r .= '<tr><th>' . __('adminNo') . '</th>';
foreach ($GLOBALS['langsActive'] as $lang) {
    $r .= '<th>' . __('adminName') . ' (' . $lang['name'] . ')</th>';
    $r .= '<th>' . __('adminDesc') . ' (' . $lang['name'] . ')</th>';
}
$r .= '</tr>';
foreach ($objects as $id => $content) {
    $r .= '<tr><td>' . $id . '</td>';
    foreach ($GLOBALS['langsActive'] as $lang) {
        $r .= '<td>';
        if (isset ($content[$lang['id']]))
            $r .= $content[$lang['id']]['name'];
        $r .= '</td><td>';
        if (isset ($content[$lang['id']]))
            $r .= shortenString ($content[$lang['id']]['desc']);
        $r .= '</td>';
    }
    $r .= '<td>&nbsp;&nbsp;<a href="?page=kalender.admin.php&amp;calpage=objects&amp;object=' . $id . '">' . __('adminEdit') . '</a>&nbsp;&nbsp;<a href="?page=kalender.admin.php&amp;calpage=objects&amp;object=' . $id . '&amp;action=del">' . __('adminDelete') . '</a></td>';
    $r .= '</tr>';
}
$r .= '</table>';


prefs.php

PHP:
<?php

// Functions
function echoChangeYesNo ($name, $selected) {
    $r = '';
    $r .= '<input class="box" type="radio" name="' . $name . '" id="' . $name . '1" value="1"';
    if ($selected == 1)
        $r .= ' checked="checked"';
    $r .= ' /> <label for="' . $name . '1">' . __('yes') . '</label>';
    $r .= ' <input class="box" type="radio" name="' . $name . '" id="' . $name . '0" value="0"';
    if ($selected == 0)
        $r .= ' checked="checked"';
    $r .= ' /> <label for="' . $name . '0">' . __('no') . '</label>';
    return $r;
}

function echoSelectLanguage ($selected) {
    $r = '';
    $r .= '<select name="languageDefault" size="1">';
    if (count ($GLOBALS['langsActive'])) {
        foreach ($GLOBALS['langsActive'] as $row) {
            $r .= '<option value="' . $row['id'] . '"';
            if ($selected == $row['id'])
                $r .= ' selected="selected"';
            $r .= '>' . $row['name'] . '</option>';
        }
    }
    $r .= '</select>';
    return $r;
}

function echoActivateLanguages () {
    $r = '<table cellspacing="0" cellpadding="2" border="0">';
    $result = readLanguages (true);
    foreach ($result as $row) {
        $r .= '<tr><td><input class="box" type="checkbox" name="languagesActive[]" value="' . $row['id'] . '"';
        if ($row['active'] == 1)
            $r .= ' checked="checked"';
        $r .= ' /></td>';
        $r .= '<td>' . $row['name'] . '</td>';
        $r .= '</tr>';
    }
    $r .= '</table>';
    return $r;
}

$pageTitle .= ' - ' . __('adminPrefs');

// Save changes
if (count ($_POST)) {
    foreach ($prefs as $name => $value) {
        if (isset ($_POST[$name]) && $_POST[$name] != $value) {
            $db -> query ("UPDATE `prefs` SET `value`='" . $_POST[$name] . "' WHERE `name`='" . $name . "'");
        }
    }
    $prefs = readPrefs ($db);
    $languages = readLanguages (true);
    foreach ($languages as $language) {
        if (isset ($_POST['languagesActive']) && in_array ($language['id'], $_POST['languagesActive'])) {
            if ($language['active'] == 0)
                $db -> query ("UPDATE `languages` SET `active`=1 WHERE `id`=" . $language['id']);
        }
        else {
            if ($language['active'] == 1)
                $db -> query ("UPDATE `languages` SET `active`=0 WHERE `id`=" . $language['id']);
        }
    }
    $GLOBALS['langsActive'] = readLanguages ();
    unset ($_SESSION['lang']);
}

// Prefs table
$r .= '<form action="?page=kalender.admin.php&amp;calpage=prefs" method="post">';
$r .= '<table>';
$r .= '<tr><th>' . __('prefsLanguageDefault') . ':</th><td>' . echoSelectLanguage ($prefs['languageDefault']) . '</td></tr>';
$r .= '<tr><th>' . __('prefsLanguagesActive') . ':</th><td>' . echoActivateLanguages () . '</td></tr>';
$r .= '<tr><th>' . __('prefsObjectDefault') . ':</th><td>' . echoSelectObject ($db, $prefs['objectDefault'], 'objectDefault') . '</td></tr>';
$r .= '<tr><th>' . __('prefsObjectShowSelect') . ':</th><td>' . echoChangeYesNo ('objectShowSelect', $prefs['objectShowSelect']) . '</td></tr>';
$r .= '<tr><th>' . __('prefsClassDefault') . ':</th><td>' . echoSelectClass ($db, $prefs['classDefault'], 'classDefault') . '</td></tr>';
$r .= '<tr><th>' . __('prefsClassFirstAndLastDay') . ':</th><td>' . echoSelectClass ($db, $prefs['classFirstAndLastDay'], 'classFirstAndLastDay', __('none')) . '</td></tr>';
$r .= '<tr><th>' . __('prefsHideExpiredDates') . ':</th><td>' . echoChangeYesNo ('hideExpiredDates', $prefs['hideExpiredDates']) . '</td></tr>';
$r .= '<tr><th>' . __('prefsShowTitleInFrontend') . ':</th><td>' . echoChangeYesNo ('showTitleInFrontend', $prefs['showTitleInFrontend']) . '</td></tr>';
$r .= '</table>';
$r .= '<p><input type="submit" value="' . __('adminSubmit') . '" /> <input type="reset" value="' . __('adminCancel') . '" /></p>';
$r .= '</form>';
 
Zurück