Ignore:
Timestamp:
Aug 1, 2008, 9:23:03 AM (16 years ago)
Author:
george
Message:
  • Opraveno: Jídelníček.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/www/jidelna/menuedit.php

    r89 r99  
    11<?php
    2 include_once('../style.php');
    3 Header('Cache-Control: no-cache');
    4 ShowHeader('Jídleníček jídelny Na kopečku','Editace jídelníčku');
     2include_once('../global.php');
    53
    6 $Dny = array('Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota');
    7 $Status = array('Nezveřejněno', 'Otevřeno', 'Zavřeno - svátek', 'Zavřeno - dovolená');
    8 $Count = 20;    // počet dopředu zobrazených dnů
     4class EatingPlaceEdit extends Page
     5{
     6  var $FullTitle = 'Jídleníček jídelny Na kopečku';
     7  var $ShortTitle = 'Editace jídelníčku';
     8  var $DayNames = array('Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota');
     9  var $Status = array('Nezveřejněno', 'Otevřeno', 'Zavřeno - svátek', 'Zavřeno - dovolená');
     10  var $DayCount = 20;    // počet dopředu zobrazených dnů
    911
    10 function PrintTableRow($Row)
    11 {
    12   global $Dny, $Status, $LastWeekOfYear;
     12  function PrintTableRow($Row)
     13  {
     14    global $LastWeekOfYear;
    1315
    14   $Selected = array('','','','');
    15   $Selected[$Row['status']] = 'selected ';   
    16   $Date = explode('-',$Row['date']);
    17   $Week = date('w',mktime(0,0,0,$Date[1],$Date[2],$Date[0]));
    18   //$Week = ;
    19   $WeekOfYear = date('W',mktime(0,0,0,$Date[1],$Date[2],$Date[0]));
    20   if($WeekOfYear != $LastWeekOfYear)
    21     $WeekRowSpan = '<td align="center" rowspan="'.(7-(($Week+7-1) % 7)).'">'.$WeekOfYear.'<br><a href="tisk.php?date='.date('Y-m-d',mktime(0,0,0,$Date[1],$Date[2],$Date[0])-($Week-1)*86400).'">Tisk</a></td>';
    22     else $WeekRowSpan = '';
    23   if($Week == 0) $Color = ' style="color: #ff0000;" '; else $Color = '';
    24   echo('<tr><td'.$Color.'>'.$Dny[$Week].'</td><td>'.HumanDate($Row['date']).'</td>
    25   '.$WeekRowSpan.'
    26   <td><input name="soap_'.$Row['date'].'" size="30" value="'.$Row['soap'].'"></td>
    27   <td><input name="meal_'.$Row['date'].'" size="30" value="'.$Row['meal'].'"></td>
    28   <td><select name="status_'.$Row['date'].'">');
    29   for($I=0; $I<4; $I++) echo('    <option '.$Selected[$I].'value="'.$I.'">'.$Status[$I].'</option>');
    30   echo('</select></td></tr>');
    31   $LastWeekOfYear = $WeekOfYear;
     16    $Selected = array('', '', '', '');
     17    $Selected[$Row['Status']] = 'selected ';
     18    $Date = explode('-', $Row['Date']);
     19    $Week = date('w', mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]));
     20    $WeekOfYear = date('W', mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]));
     21    if($WeekOfYear != $LastWeekOfYear)
     22      $WeekRowSpan = '<td align="center" rowspan="'.(7 - (($Week + 7 - 1) % 7)).'">'.$WeekOfYear.'<br /><a href="tisk.php?date='.date('Y-m-d', mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]) - ($Week - 1) * 86400).'">Tisk</a></td>';
     23      else $WeekRowSpan = '';
     24    if($Week == 0) $Color = ' style="color: #ff0000;" '; else $Color = '';
     25    $Output = '<tr><td'.$Color.'>'.$this->DayNames[$Week].'</td><td>'.HumanDate($Row['Date']).'</td>'.$WeekRowSpan.'
     26    <td><input name="soup_'.$Row['Date'].'" size="30" value="'.$Row['Soup'].'"></td>
     27    <td><input name="meal_'.$Row['Date'].'" size="30" value="'.$Row['Meal'].'"></td>
     28    <td><select name="status_'.$Row['Date'].'">';
     29    for($I = 0; $I < 4; $I++) $Output .= '    <option '.$Selected[$I].'value="'.$I.'">'.$this->Status[$I].'</option>';
     30    $Output .= '</select></td></tr>';
     31    $LastWeekOfYear = $WeekOfYear;
     32    return($Output);
     33  }
     34
     35  function Show()
     36  {
     37    Header('Cache-Control: no-cache');
     38
     39    $Output = '';
     40    if(array_key_exists('action', $_GET))
     41    {
     42      if($_GET['action'] == 'savemenu')
     43      {
     44        for($I = 0; $I < $this->DayCount; $I++)
     45        {
     46          $Time = time() + $I * 86400;
     47          $Date = date('Y-m-d', $Time);
     48          $this->Database->replace('Meals', array('Date' => $Date, 'Meal' => $_POST['meal_'.$Date], 'Soup' => $_POST['soup_'.$Date], 'Status' => $_POST['status_'.$Date]));
     49        }
     50        $Output .= '<div style="color: red; font-size: larger;">Menu uloženo!</div>';
     51      }
     52      if($_GET['action'] == 'saveinfo')
     53      {
     54        $this->Database->delete('MealsInfo', '1');
     55        $this->Database->insert('MealsInfo', array('Info' => $_POST['info'], 'Price' => $_POST['price']));
     56        $Output .= '<div style="color: red; font-size: larger;">Informační údaje uloženy!</div>';
     57      }
     58    }
     59    $Output = '<form action="menuedit.php?action=savemenu" method="post">
     60<fieldset><legend>Jídlo pro jednotlivé dny</legend>
     61<table align="center" border="1" cellspacing="0" cellpadding="5"><tr><th>Den</th><th>Datum</th><th>Týden</th><th>Polévka</th><th>Hlavní jídlo</th><th>Stav</th></tr>';
     62    for($I = 0; $I < $this->DayCount; $I++)
     63    {
     64      $Time = time() + $I * 86400;
     65      $DbResult = $this->Database->select('Meals', '*', 'Date = "'.date('Y-m-d', $Time).'"');
     66      if($Row = $DbResult->fetch_array())
     67        $Output .= $this->PrintTableRow($Row);
     68      else
     69      {
     70        $Row = array('Status' => 0, 'Meal' => '', 'Soup' => '', 'Date' => date('Y-m-d', $Time));
     71        $Output .= $this->PrintTableRow($Row);
     72      }
     73    }
     74    $Output .= '</table><br />
     75<div align="center"><input type="submit" value="Uložit menu"></div>
     76</fieldset></form>';
     77    $Output .= '<form action="menuedit.php?action=saveinfo" method="post">
     78<fieldset><legend>Informační údaje</legend>';
     79
     80    $DbResult = $this->Database->select('MealsInfo', '*');
     81    $Row = $DbResult->fetch_array();
     82    $Output .= '<textarea name="info" rows="20" cols="80" >'.$Row['Info'].'</textarea><br />'.
     83'Cena: <input type="text" name="price" size="5" value="'.$Row['Price'].'"> Kč<br />'.
     84'<div align="center"><input type="submit" value="Uložit údaje"></div>
     85</fieldset></form>';
     86    return($Output);
     87  }
    3288}
    3389
    34 if(array_key_exists('action',$_GET))
    35 {
    36   if($_GET['action'] == 'savemenu')
    37   {
    38     for($I=0; $I<$Count; $I++)
    39     {
    40       $Time = time() + $I * 86400;
    41       $Date = date('Y-m-d', $Time);
    42       $Database->replace('meals', array('date' => $Date, 'meal' => $_POST['meal_'.$Date], 'soap' => $_POST['soap_'.$Date], 'status' => $_POST['status_'.$Date]));
    43       //echo($Database->error.'<br>');
    44     }
    45     echo('<div style="color: red; font-size: larger;">Menu uloženo!</div>');
    46   }
    47   if($_GET['action'] == 'saveinfo')
    48   {
    49     $Database->delete('meals_info','1');
    50     $Database->insert('meals_info',array('info' => $_POST['info'], 'price' => $_POST['price']));
    51     echo('<div style="color: red; font-size: larger;">Informační údaje uloženy!</div>');
    52   }
    53 }
    54 echo('
    55 <form action="menuedit.php?action=savemenu" method="post">
    56 <fieldset><legend>Jídlo pro jednotlivé dny</legend>
     90$System->AddModule(new EatingPlaceEdit());
     91$System->Modules['EatingPlaceEdit']->GetOutput();
    5792
    58 <table align="center" border="1" cellspacing="0" cellpadding="5"><tr><th>Den</th><th>Datum</th><th>Týden</th><th>Polévka</th><th>Hlavní jídlo</th><th>Stav</th></tr>');
    59 for($I=0; $I<$Count; $I++)
    60 {
    61   $Time = time()+$I*86400;
    62   $DbResult = $Database->select('meals','*','date = "'.date('Y-m-d',$Time).'"');
    63   if($Row = $DbResult->fetch_array())
    64     PrintTableRow($Row);
    65   else {
    66     $Row = array('status' => 0, 'meal' => '', 'soap' => '', 'date' => date('Y-m-d',$Time));
    67     PrintTableRow($Row);
    68   }
    69 }
    70 echo('</table><br>
    71 <div align="center"><input type="submit" value="Uložit menu"></div>
    72 </fieldset></form>');
    73 echo('<form action="menuedit.php?action=saveinfo" method="post">
    74 <fieldset><legend>Informační údaje</legend>');
    75 
    76 $DbResult = $Database->select('meals_info','*');
    77 $Row = $DbResult->fetch_array();
    78 echo('<textarea name="info" rows="20" cols="80" >'.$Row['info'].'</textarea><br>'.
    79 'Cena: <input type="text" name="price" size="5" value="'.$Row['price'].'"> Kč<br>'.
    80 '<div align="center"><input type="submit" value="Uložit údaje"></div>
    81 </fieldset></form>');
    82 
    83 ShowFooter();
    8493?>
    8594
Note: See TracChangeset for help on using the changeset viewer.