Ankündigung

Einklappen
Keine Ankündigung bisher.

Nochmal ein Problem mit dem Datum

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Nochmal ein Problem mit dem Datum

    Also ich hab jetzt noch ein Newsscript, welches auf Textfiles basiert, doch ich find einfach nicht die Funktion, wo die Zeit gespeichert wird und wo ich diese sieben Stunden vorstellen kann, da ich schon mehrere Varianten probiert hab, poste ich mal einfach das ganze script:


    Code:
    <?php
    /************************************************************************
    *                                                                       *
    *    File:      tnAdmin.php                                             *
    *                                                                       *
    *    Author:    Copyright (c) Timo Gnambs <timo@gnambs.at>              *
    *    Website:   http://timo.gnambs.at                                   *
    *    Update:    20.03.2002                                              *
    *    Licence:   GPL                                                     *
    *                                                                       *
    * This program is free software; you can redistribute it and/or         *
    * modify it under the terms of the GNU General Public License           *
    * as published by the Free Software Foundation; either version 2        *
    * of the License, or (at your option) any later version.                *
    *                                                                       *
    * This program 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 General Public License <http://www.gnu.org/copyleft/gpl.html>     *
    * for more details.                                                     *
    ************************************************************************/
    
    
    
    
    
    session_start();
    session_register("login");
    
    include("conf/conf.inc.php");
    
    //prevent cache
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("d.m.Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    
    <title>tn: Administration</title>
    
    <style type="text/css">
    <!--
    body, td, p, div {
        font-size:10pt;
        cursor:default;
        margin:0px;
    }
    
    td.title {
        font-size:14pt;
        font-weight:600;
        border-bottom:2px solid #000000;
    }
    td.title .close {
        color:#000000;
        text-decoration:none;
    }
    td.error, span.error {
        color:#D05050;
    }
    -->
    </style>
    
    </head>
    
    <body>
    &
    
    
    <table border="0" width="80%" align="center" cellspacing="0" cellpadding="0" summary="This table structures the whole page.">
        <tr>
            <td class="title">
                tn: Administration
            </td>
            <td class="title" align="right">
                X
            </td>
        </tr>
        <tr>
            <td>
                &
            </td>
            <td align="right">
                <form action="<?php echo $PHP_SELF; ?>" name="change" method="post">
                    <input type="hidden" name="<?php print session_name(); ?>" value="<?php print session_id(); ?>" />
                    <input type="hidden" name="mode" value="<?php print ($HTTP_POST_VARS["mode"] == "admin") ? "add" : "admin"; ?>" />
                </form>
                <?php print ($HTTP_POST_VARS["mode"] == "admin") ? "Add an entry" : "Administration"; ?>
            </td>
        </tr>
    
        <tr>
            <td>
    <?php
        //login
        $loggedIn = false;
        if(isset($HTTP_POST_VARS["tn"]["login"]) || isset($HTTP_SESSION_VARS["login"])) {
            unset($login);
            $login["name"] = isset($HTTP_POST_VARS["tn"]["login"]["name"]) ? strtolower($HTTP_POST_VARS["tn"]["login"]["name"]) : strtolower($HTTP_SESSION_VARS["login"]["name"]);
            $login["password"] = isset($HTTP_POST_VARS["tn"]["login"]["password"]) ? strtolower($HTTP_POST_VARS["tn"]["login"]["password"]) : strtolower($HTTP_SESSION_VARS["login"]["password"]);
            foreach($tn_login as $value) {
                if(strtolower($value[0]) == $login["name"] && strtolower($value[1]) == $login["password"]) {
                    $loggedIn = true;
                    break;
                }
            unset($login);
            }
        }
    
        if(!$loggedIn) {
            if(isset($HTTP_POST_VARS["tn"]["login"])) print "<span class=\"error\">Invalid login.</span>";
    ?>
                <form action="<?php echo $PHP_SELF."?".$HTTP_ENV_VARS["QUERY_STRING"]; ?>" name="tnLogin" method="post">
                    <input type="hidden" name="<?php print session_name(); ?>" value="<?php print session_id(); ?>" />
                    <table border="0" summary="This table structures the login form.">
                        <tr>
                            <td align="right">
                                <label for="tn[login][name]">
                                    Login:
                                </label
                            </td>
                            <td>
                                <input name="tn[login][name]" size="15" maxlength="30" type="text" value="<?php print $HTTP_POST_VARS["tn"]["login"]["name"]; ?>" onmouseover="this.focus();" onfocus="this.select();" />
                            </td>
                            <td rowspan="2" valign="top">
                                <input name="mode" type="radio" value="add" selected="selected" />Add an entry
    
                                <input name="mode" type="radio" value="admin" />Administration
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <label for="tn[login][password]">
                                    Password:
                                </label
                            </td>
                            <td>
                                <input name="tn[login][password]" size="15" maxlength="30" type="password" value="" onmouseover="this.focus();" onfocus="this.select();" />
                            </td>
                        </tr>
    				    <tr>
    				        <td>
    				            &
    				        </td>
    				    </tr>
                        <tr>
                            <td colspan="2" align="center">
                                <input type="button" value="Submit" onclick="tnLogin.submit()" />
                            </td>
                        </tr>
                    </table>
                </form>
    <?php
            exit;
        }
    ?>
            </td>
        </tr>
    
        <tr>
            <td colspan="2" class="error">
    <?php
    switch($HTTP_POST_VARS["mode"]) {
        default:
            if($HTTP_POST_VARS["tn"]["action"]) {
    		    if(file_exists(TN_FILE)) {
    			    $oldEntries = @file(TN_FILE);
    	    
    			    if((TN_MAX_PAGE * TN_ITEM_CNT) <= count($oldEntries)) {
    	    		    array_pop($oldEntries);
    			    }
    	
    		   	    $nextId = get_id($oldEntries);
    	        	$oldEntries = implode("", $oldEntries);
    		    } else {
    	    	    $nextId = 1;
    		    }
                if(!empty($HTTP_POST_VARS["tn"]["msg"])) {
        		    write_entries(array(array($nextId, mktime(), transform($HTTP_POST_VARS["tn"]["msg"])), $oldEntries), TN_FILE);
                    print "entry has been added successfully.";
                    unset($HTTP_POST_VARS["tn"]);
                } else {
                    print "enter some text.";
                }
            }
            break;
    
        //load all entries
        case "admin":
    		unset($myEntries);
    		if(file_exists(TN_FILE)) {
    		    $m = @file(TN_FILE) or die("data file is empty");
    		
    		    if(is_array($m)) {
    		        $i = 0;
    		        while(list($key, $value) = each($m)) {
    		            $myEntries[$i++] = explode("|", trim($value));
    		        }
    		    } else die("data file is empty.");
    		} else die("could not find data file \"".TN_FILE."\".");
    	
    		//update entries
    		if($HTTP_POST_VARS["action"] == "edit") {
    		    foreach($myEntries as $key=>$value) {
    		        if($value[0] == $HTTP_POST_VARS["tn"]["id"]) {
    				    $l = explode(".", trim($HTTP_POST_VARS["tn"]["date"]));
    $myEntries[$key][1] = mktime(
        date("H", $myEntries[$key][1]),
        date("i", $myEntries[$key][1]),
        date("s", $myEntries[$key][1]),
        $l[1],
        $l[0],
        $l[2]
    );
    
    
    
    
    
    				    $l = ereg_replace("\n", "
    ", $HTTP_POST_VARS["tn"]["msg"]);
    				    $myEntries[$key][2] = ereg_replace("\r", "", $l);
    		        }
    		        $myEntries[$key][2] = transform($myEntries[$key][2]);
    		    }
    		    write_entries($myEntries, TN_FILE);
    		    print "changes have been saved successfully.";
    		//delete entry
    		} else if($HTTP_POST_VARS["action"] == "delete") {
    		        foreach($myEntries as $key=>$value) {
    		            if($value[0] == $HTTP_POST_VARS["tn"]["id"]) {
    		                unset($myEntries[$key]);
    		                break;
    		            }
    		        }
    		        write_entries($myEntries, TN_FILE);
    		        print "entry has been deleted successfully.";
    		        if(empty($myEntries)) print "
    data file is empty.";
    		}
            break;
    }
    ?>
            </td>
        </tr>
        <tr>
            <td>
                &
            </td>
        </tr>
    
        <tr>
            <td>
    <?php
    //the add page
    switch($HTTP_POST_VARS["mode"]) {
        default:
    ?>
                <form action="<?php echo $PHP_SELF; ?>" name="tnForm" method="post">
                    <input type="hidden" name="<?php print session_name(); ?>" value="<?php print session_id(); ?>" />
                    <input type="hidden" name="tn[action]" value="add" />
                   
    
    
                        Write your entry:
                    </p>
                    <textarea name="tn[msg]" rows="10" cols="45"><?php print $HTTP_POST_VARS["tn"]["msg"]; ?></textarea>
                    <input type="button" value="add entry" onclick="document.tnForm.submit();" />
                </form>
    
    <?php
            break;
    
    //the admin page
        case "admin":
    		$count = 0;
    		foreach ($myEntries as $key=>$value) {
    		    $value[2] = str_replace("\n", "", $value[2]);
    		    $value[2] = str_replace("\r", "", $value[2]);
    		    $value[2] = str_replace("[br]", "\n", $value[2]);
    ?>
                <form action="<?php echo $PHP_SELF; ?>" name="tnForm<?php print $value[0]; ?>" method="post">
                    <input type="hidden" name="<?php print session_name(); ?>" value="<?php print session_id(); ?>" />
                    <input type="hidden" name="tn[id]" value="<?php print $value[0]; ?>" />
                    <input type="hidden" name="action" value="edit" />
                    <input type="hidden" name="mode" value="admin" />
    
                    <table border="0" cellspacing="0" cellpadding="3" summary="This table structures a news entry.">
                        <tr>
                            <td colspan="3">
                                <?php print ++$count; ?>.
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <label for="tn[date]">
                                    Date:
                                </label>
                            </td>
                            <td>
                                <input name="tn[date]" type="text" size="10" value="<?php print date("d.m.Y", $value[1]); ?>" />
                            </td>
                            <td align="right">
                                <input type="button" value="delete" onclick="document.tnForm<?php print $value[0]; ?>.action.value='delete';document.tnForm<?php print $value[0]; ?>.submit();" /><input type="button" value="save changes" onclick="document.tnForm<?php print $value[0]; ?>.submit();" />
                            </td>
                        </tr>
                        <tr>
                            <td align="right" valign="top">
                                <label for="tn[msg]">
                                    Entry:
                                </label>
                            </td>
                            <td colspan="2">
                                <textarea name="tn[msg]" rows="6" cols="45"><?php print $value[2]; ?></textarea>
                            </td>
                        </tr>
                    </table>
                </form>
    <?php
        }
        break;
    }
    ?>
    </table>
    
    </body>
    
    </html>
    
    <?php
    /*
    * >>> write data to file <<<
    * array $data: data to write
    * string $file: file to write to
    */
    
    function write_entries($data, $file) {
        foreach($data as $key=>$value) {
            if(is_array($value)) $data[$key] = implode("|", $value);
        }
        //writes to file
        $fp = fopen($file, "w");
        if($fp) {
            flock($fp,1);
            fputs($fp, implode("\n", $data));
            flock($fp,3);
            fclose($fp);
        }
        //if there is an error while trying to open the file
        if(!$fp) {
           die("cannot write to data file");
        }
    
        return true;
    }
    
    
    /*
    * >>> determines next id number <<<
    * array $fileArray: whole news-file as array
    * return integer $nextId: next id
    */
    
    function get_id($fileArray) {
        if(count($fileArray) > 0) {
            //extract all existing ids
            for($i=0;$i<count($fileArray);$i++) {
                $line = explode("|", $fileArray[$i]);
                $allIds[$i] = $line[0];
            }
            sort($allIds);
            
            //get next id
            for($i=0;$i<=count($allIds);$i++) {
                if (!in_array(($i+1),$allIds)) {
                    $nextId = ($i+1);
                    break;
                }
            }
        } else {
            $nextId = 1;
        }    
        
        return $nextId;
    }
    
    
    /*
    * >>> format text <<<
    * string $string: text to be formatted
    * return string $string: formatted string
    */
    
    function transform($string) {
        $string = ereg_replace("\\\'", "'", $string);
        $string = ereg_replace('\\\"', "\"", $string);
        $string = ereg_replace("\|", "|", $string);
        $string = ereg_replace("\r", "", $string);
        $string = ereg_replace("\n", "
    ", $string);
        return $string;
    }
    
    ?>
    besten dank für jede art der hilfe!


  • #2
    Re: Nochmal ein Problem mit dem Datum

    Zitat von phpUnknown
    Also ich hab jetzt noch ein Newsscript, welches auf Textfiles basiert, doch ich find einfach nicht die Funktion, wo die Zeit gespeichert wird und wo ich diese sieben Stunden vorstellen kann,

    besten dank für jede art der hilfe!
    Suche nach mktime(). Das ermittelt (ohne Parameter) den aktuellen Timestamp. Und da addierst Du 25200.
    ... ( mktime() + 25200 ) ...

    Kommentar


    • #3
      super danke, funktioniert!

      Kommentar


      • #4
        Zitat von phpUnknown
        super danke, funktioniert!
        Zusätzlich solltest Du Dir das angucken:
        http://de.php.net/date
        besonders die Parameter T und Z

        Kommentar

        Lädt...
        X