Ignore:
Timestamp:
Feb 15, 2009, 8:07:45 PM (16 years ago)
Author:
george
Message:
  • Upraveno: Přepracována stránka jídelny.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • www/jidelna/menuedit.php

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