Avatar billede tirra Nybegynder
30. maj 2004 - 21:33 Der er 3 kommentarer og
1 løsning

Kan man lave en tekstfil til calender (ikke database)

Jeg har brug for hjælp til at finde ud af om en kalender kan hente info fra en tekstfil og ikke fra database.

Jeg paster her kode fra filen calendar.php

<?php

define('NEWLINE', "\n");

class DHTML_Calendar {
    var $calendar_lib_path;

    var $calendar_file;
    var $calendar_lang_file;
    var $calendar_setup_file;
    var $calendar_theme_file;
    var $calendar_options;

    function DHTML_Calendar($calendar_lib_path = '/calendar/',
                            $lang              = 'en',
                            $theme            = 'calendar-win2k-1',
                            $stripped          = true) {
        if ($stripped) {
            $this->calendar_file = 'calendar_stripped.js';
            $this->calendar_setup_file = 'calendar-setup_stripped.js';
        } else {
            $this->calendar_file = 'calendar.js';
            $this->calendar_setup_file = 'calendar-setup.js';
        }
        $this->calendar_lang_file = 'lang/calendar-' . $lang . '.js';
        $this->calendar_theme_file = $theme.'.css';
        $this->calendar_lib_path = preg_replace('/\/+$/', '/', $calendar_lib_path);
        $this->calendar_options = array('ifFormat' => '%Y/%m/%d',
                                        'daFormat' => '%Y/%m/%d');
    }

    function set_option($name, $value) {
        $this->calendar_options[$name] = $value;
    }

    function load_files() {
        echo $this->get_load_files_code();
    }

    function get_load_files_code() {
        $code  = ( '<link rel="stylesheet" type="text/css" media="all" href="' .
                  $this->calendar_lib_path . $this->calendar_theme_file .
                  '" />' . NEWLINE );
        $code .= ( '<script type="text/javascript" src="' .
                  $this->calendar_lib_path . $this->calendar_file .
                  '"></script>' . NEWLINE );
        $code .= ( '<script type="text/javascript" src="' .
                  $this->calendar_lib_path . $this->calendar_lang_file .
                  '"></script>' . NEWLINE );
        $code .= ( '<script type="text/javascript" src="' .
                  $this->calendar_lib_path . $this->calendar_setup_file .
                  '"></script>' );
        return $code;
    }

    function _make_calendar($other_options = array()) {
        $js_options = $this->_make_js_hash(array_merge($this->calendar_options, $other_options));
        $code  = ( '<script type="text/javascript">Calendar.setup({' .
                  $js_options .
                  '});</script>' );
        return $code;
    }

    function make_input_field($cal_options = array(), $field_attributes = array()) {
        $id = $this->_gen_id();
        $attrstr = $this->_make_html_attr(array_merge($field_attributes,
                                                      array('id'  => $this->_field_id($id),
                                                            'type' => 'text')));
        echo '<input ' . $attrstr .'/>';
        echo '<a href="#" id="'. $this->_trigger_id($id) . '">' .
            '<img align="middle" border="0" src="' . $this->calendar_lib_path . 'img.gif" alt="" /></a>';

        $options = array_merge($cal_options,
                              array('inputField' => $this->_field_id($id),
                                    'button'    => $this->_trigger_id($id)));
        echo $this->_make_calendar($options);
    }

    /// PRIVATE SECTION

    function _field_id($id) { return 'f-calendar-field-' . $id; }
    function _trigger_id($id) { return 'f-calendar-trigger-' . $id; }
    function _gen_id() { static $id = 0; return ++$id; }

    function _make_js_hash($array) {
        $jstr = '';
        reset($array);
        while (list($key, $val) = each($array)) {
            if (is_bool($val))
                $val = $val ? 'true' : 'false';
            else if (!is_numeric($val))
                $val = '"'.$val.'"';
            if ($jstr) $jstr .= ',';
            $jstr .= '"' . $key . '":' . $val;
        }
        return $jstr;
    }

    function _make_html_attr($array) {
        $attrstr = '';
        reset($array);
        while (list($key, $val) = each($array)) {
            $attrstr .= $key . '="' . $val . '" ';
        }
        return $attrstr;
    }
};

?>
Avatar billede tirra Nybegynder
30. maj 2004 - 21:34 #1
Jeg må tilføje at der ellers er lagt op til at hente info fra index.php med den her kode:

<script type="text/javascript">
  function dateChanged(calendar) {
    // Beware that this function is called even if the end-user only
    // changed the month/year.  In order to determine if a date was
    // clicked you can use the dateClicked property of the calendar:
    if (calendar.dateClicked) {
      // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
      var y = calendar.date.getFullYear();
      var m = calendar.date.getMonth();    // integer, 0..11
      var d = calendar.date.getDate();      // integer, 1..31
      // redirect...
      window.location = "/" + y + "/" + m + "/" + d + "/index.php";
    }
  };

  Calendar.setup(
    {
      flat        : "calendar-container", // ID of the parent element
      flatCallback : dateChanged          // our callback function
    }
  );
</script>
Avatar billede knudx Nybegynder
31. maj 2004 - 17:46 #2
javascriptet omdirigerer når du har trykket på en dato:

      // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php

Der må være et php-script mere, som kan 'fylde kalenderen op' med data, og placerer dem i en [genereret] php-fil i den relevante undermappe !?!
Avatar billede tirra Nybegynder
01. juni 2004 - 15:31 #3
Tak til Knudx

Der test.php som jeg paster forneden
Håber den kan sige noget, jeg er på bar bund :)

<?php

$lang = $_GET['lang'];
if (!$lang) {
    $lang = $_REQUEST['lang'];
}
if (!$lang) {
    $lang = 'en';
}
setcookie('lang', $lang);

?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>
Test for calendar.php
</title>

<?php

// put here the correct path to "calendar.php"; don't move the file
// "calendar.php" -- I think it's best if you leave it inside the
// "/jscalendar/" directory.  Just put here the correct path to it, such as
// "../jscalendar/calendar.php" or something.
require_once ('calendar.php');

// parameters to constructor:
//    1. the absolute URL path to the calendar files
//    2. the languate used for the calendar (see the lang/ dir)
//    3. the theme file used for the clanedar, without the ".css" extension
//    4. boolean that specifies if the "_stripped" files are to be loaded
//        The stripped files are smaller as they have no whitespace and comments
$calendar = new DHTML_Calendar('/jscalendar/', $lang, 'calendar-win2k-2', false);

// call this in the <head> section; it will "echo" code that loads the calendar
// scripts and theme file.
$calendar->load_files();

?>

</head>

<body>

<?php if ($_REQUEST['submitted']) { ?>

<h1>Form submitted</h1>

<?php foreach ($_REQUEST as $key => $val) {
    echo htmlspecialchars($key) . ' = ' . htmlspecialchars($val) . '<br />';
} ?>

<?php } else { ?>

<h1>Calendar.php test</h1>

    <form action="test.php" method="get">
    Select language: <select name="lang" onchange="this.form.submit()">
    <?php
$cwd = getcwd();
chdir('lang');
foreach (glob('*.js') as $filename) {
    $l = preg_replace('/(^calendar-|.js$)/', '', $filename);
    $selected = '';
    if ($l == $lang)
        $selected = 'selected="selected" ';
    $display = $l;
    if ($l == 'en')
        $display = 'EN';
    echo '<option ' . $selected . 'value="' . $l . '">' . $display . '</option>';
}
    ?>
    </select>
    <blockquote style="font-size: 90%">
      <b>NOTE</b>: as of this release, 0.9.6, only "EN" and "RO", which I
      maintain, function correctly.  Other language files do not work
      because they need to be updated.  If you update some language file,
      please consider sending it back to me so that I can include it in the
      calendar distribution.
    </blockquote>
    </form>

    <form action="test.php" method="get">
    <input type="hidden" name="submitted" value="1" />

    <table>
    <tr>
    <td>
      Date 1:
    </td>
    <td>
      <?php $calendar->make_input_field(
          // calendar options go here; see the documentation and/or calendar-setup.js
          array('firstDay'      => 1, // show Monday first
                'showsTime'      => true,
                'showOthers'    => true,
                'ifFormat'      => '%Y-%m-%d %I:%M %P',
                'timeFormat'    => '12'),
          // field attributes go here
          array('style'      => 'width: 15em; color: #840; background-color: #ff8; border: 1px solid #000; text-align: center',
                'name'        => 'date1',
                'value'      => strftime('%Y-%m-%d %I:%M %P', strtotime('now')))); ?>
    </td>
    </tr>
    </table>

    <hr />
    <button>Submit</button>

    </form>

<?php } ?>

</body>
</html>
Avatar billede tirra Nybegynder
02. juni 2004 - 20:16 #4
lukker
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester