Changeset 354 for trunk


Ignore:
Timestamp:
Jan 18, 2012, 9:17:11 AM (13 years ago)
Author:
chronos
Message:
  • Upraveno: Jídelna přetvořena na systémový modul Meals.
Location:
trunk/Modules
Files:
4 deleted
1 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Log/Log.php

    r353 r354  
    9494  }
    9595 
     96  function Install()
     97  {
     98    parent::Install();
     99  }
     100 
     101  function UnInstall()
     102  {
     103    parent::UnInstall();
     104  }
     105
    96106  function Init()
    97107  {
  • trunk/Modules/Meals/Meals.php

    r348 r354  
    11<?php
    2 include_once('../global.php');
    32
    43class EatingPlace extends Page
    54{
    65  var $FullTitle = 'Jídleníček jídelny Na kopečku';
    7   var $ShortTitle = 'Jídelníček';
     6  var $ShortTitle = 'Jídelníček';
     7  var $DayNames = array('Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota');
     8  var $DayNamesShort = array('NE', 'PO', 'ÚT', 'ST', 'ČT', 'PÁ', 'SO');
     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ů
    811
    912  function Show()
    1013  {
    11     $Dny = array('Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota');
    12     $Status = array('Nezveřejněno', 'Otevřeno', 'Zavřeno - svátek', 'Zavřeno - dovolená');
    13 
     14    if(count($this->System->PathItems) > 1)
     15    {
     16      if($this->System->PathItems[1] == 'tisk') return($this->ShowPrint());
     17        else if($this->System->PathItems[1] == 'edit') return($this->ShowEdit());
     18        else return(PAGE_NOT_FOUND);
     19    } else return($this->ShowMenu());
     20  }
     21
     22  function ShowMenu()
     23  {
    1424    //echo('Dnes je '.HumanDate(date('Y-m-d')).'<br>');
    1525    $Output = '<table align="center" class="WideTable"><tr><th>Den</th><th>Datum</th><th>Polévka</th><th>Hlavní jídlo</th></tr>';
     
    1727    while($Row = $DbResult->fetch_array())
    1828    {
    19       if($Row['Status'] == 1) $Output .= '<tr><td>'.$Dny[date('w', $Row['UNIX_TIMESTAMP(Date)'])].'</td><td align="right">'.HumanDate($Row['Date']).'</td><td>'.$Row['Soup'].'</td><td>'.$Row['Meal'].'</td></tr>';
     29      if($Row['Status'] == 1) $Output .= '<tr><td>'.$this->DayNames[date('w', $Row['UNIX_TIMESTAMP(Date)'])].'</td><td align="right">'.HumanDate($Row['Date']).'</td><td>'.$Row['Soup'].'</td><td>'.$Row['Meal'].'</td></tr>';
    2030      else if(($Row['Status' ] == 2) or ($Row['Status'] == 3))
    2131      {
    22         $Output .= '<tr><td>'.$Dny[date('w',$Row['UNIX_TIMESTAMP(Date)'])].'</td><td align="right">'.HumanDate($Row['Date']).'</td><td colspan="2" align="center">'.$Status[$Row['Status']].'</td></tr>';
     32        $Output .= '<tr><td>'.$this->DayNames[date('w', $Row['UNIX_TIMESTAMP(Date)'])].'</td><td align="right">'.HumanDate($Row['Date']).'</td><td colspan="2" align="center">'.$this->Status[$Row['Status']].'</td></tr>';
    2333      }
    2434    }
     
    3141    return($Output);
    3242  }
    33 }
    34 
    35 $System->AddModule(new EatingPlace());
    36 $System->Modules['EatingPlace']->GetOutput();
     43 
     44  function ShowPrint()
     45  {
     46    $this->SimplePage = true;
     47   
     48    $Output = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     49<html>
     50<head>
     51<meta http-equiv="Content-Type" content="text/html; charset='.$this->System->Config['Web']['Charset'].'">
     52<meta http-equiv="Content-language" content="cs">
     53<title>Tisk jídelníčku</title>
     54</head><body style="margin: 0px 0px 0px 0px;">'; // onload="print()">');
     55
     56    //echo('Dnes je '.HumanDate(date('Y-m-d')).'<br>');
     57    $Output .= '<table height="99%" width="100%" align="center" border="0" cellspacing="0" cellpadding="3">';
     58    $Date = explode('-', $_GET['date']);
     59    $Output .= '<tr><td style="border-bottom-style: solid; border-bottom-color: black; border-bottom-width: 2;" colspan="2">
     60<table cellspacing="0" cellpadding="0" width="100%"><tr><td width="50%"><strong>DATUM:</strong> '.HumanDate($_GET['date']).' - '.HumanDate(date('Y-m-d',mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]) + 4 * 86400)).'</td>
     61<td align="right">CENY SMLUVNÍ</td></tr></table>
     62<div align="center" style="font-size: xx-large;">&bdquo;JÍDELNA NA KOPEČKU&rdquo;</div>
     63<div align="center" style="font-size: x-large;">JÍDELNÍČEK</div>
     64</td></tr>';
     65    $Date = explode('-', $_GET['date']);
     66    $Time2 = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]);
     67    for($I = 0; $I < 5; $I++)
     68    {
     69      $Time = $Time2 + $I * 86400;
     70      $Date = date('Y-m-d', $Time);
     71      $DayOfWeek = date('w', $Time);
     72      $DbResult = $this->Database->select('Meals', '*', 'Date="'.$Date.'"');
     73      $Row = $DbResult->fetch_array();
     74      $Output .= '<tr><td style="border-style: solid; border-color: black; border-width: 2; font-size: xx-large;" width="10%">'.$this->DayNamesShort[$DayOfWeek].'</td><td style="font-size: x-large; border-style: solid; border-color: black; border-width: 2;" width="90%">';
     75      if($Row['Status'] == 0) $Output .= '&nbsp;<br><br>&nbsp;';
     76      if($Row['Status'] == 1) $Output .= 'Polévka: '.$Row['Soup'].'<br><br>'.$Row['Meal'];
     77      else if(($Row['Status'] == 2) or ($Row['Status'] == 3))
     78      {
     79        $Output .= '<br>'.$this->Status[$Row['Status']].'<br>&nbsp;';
     80      }
     81      $Output .= '</td></tr>';
     82    }
     83    $DbResult = $this->Database->select('MealsInfo','*');
     84    $Row = $DbResult->fetch_array();
     85    $Output .= '<tr><td style="border-top-style: solid; border-top-color: black; border-top-width: 2;" colspan="2"><table cellspacing="0" cellpadding="0" width="100%"><tr><td width="50%"><strong>JÍDLA PŘIPRAVILA: Matochová</strong></td>
     86    <td align="right"><strong>PROVOZOVATEL:</strong></td></tr></table>
     87    <br>
     88    <strong>CENA JEDNOHO MENU JE '.$Row['Price'].' Kč</strong></td></tr>';
     89    //echo('<tr><td colspan="2">dd</td></tr>');
     90    $Output .= '</table>';
     91
     92    //DB_Select('meals_info','*');
     93    //$Row = DB_Row();
     94    //echo($Row['info']);
     95
     96    $Output .= '</body></html>';
     97    return($Output);   
     98  }
     99
     100  function PrintTableRow($Row)
     101  {
     102    global $LastWeekOfYear;
     103
     104    $Selected = array('', '', '', '');
     105    $Selected[$Row['Status']] = 'selected ';
     106    $Date = explode('-', $Row['Date']);
     107    $Week = date('w', mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]));
     108    $WeekOfYear = date('W', mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]));
     109    if($WeekOfYear != $LastWeekOfYear)
     110      $WeekRowSpan = '<td align="center" rowspan="'.(7 - (($Week + 7 - 1) % 7)).'">'.
     111        $WeekOfYear.'<br /><a href="tisk/?date='.
     112        date('Y-m-d', mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]) - ($Week - 1) * 86400).
     113        '">Tisk</a></td>';
     114      else $WeekRowSpan = '';
     115    if($Week == 0) $Color = ' style="color: #ff0000;" '; else $Color = '';
     116    $Output = '<tr><td'.$Color.'>'.$this->DayNames[$Week].'</td><td>'.HumanDate($Row['Date']).'</td>'.$WeekRowSpan.'
     117    <td><input name="soup_'.$Row['Date'].'" size="30" value="'.$Row['Soup'].'"></td>
     118    <td><input name="meal_'.$Row['Date'].'" size="30" value="'.$Row['Meal'].'"></td>
     119    <td><select name="status_'.$Row['Date'].'">';
     120    for($I = 0; $I < 4; $I++) $Output .= '    <option '.$Selected[$I].'value="'.$I.'">'.$this->Status[$I].'</option>';
     121    $Output .= '</select></td></tr>';
     122    $LastWeekOfYear = $WeekOfYear;
     123    return($Output);
     124  }
     125
     126  function ShowEdit()
     127  {
     128    Header('Cache-Control: no-cache');
     129
     130    $Output = '';
     131    if(array_key_exists('action', $_GET))
     132    {
     133      if($_GET['action'] == 'savemenu')
     134      {
     135        for($I = 0; $I < $this->DayCount; $I++)
     136        {
     137          $Time = time() + $I * 86400;
     138          $Date = date('Y-m-d', $Time);
     139          $this->Database->replace('Meals', array('Date' => $Date, 'Meal' => $_POST['meal_'.$Date], 'Soup' => $_POST['soup_'.$Date], 'Status' => $_POST['status_'.$Date]));
     140        }
     141        $Output .= '<div style="color: red; font-size: larger;">Menu uloženo!</div>';
     142        $this->System->Modules['Log']->NewRecord('EatingPlace', 'MenuSave');
     143      }
     144      if($_GET['action'] == 'saveinfo')
     145      {
     146        $this->Database->delete('MealsInfo', '1');
     147        $this->Database->insert('MealsInfo', array('Info' => $_POST['info'], 'Price' => $_POST['price']));
     148        $Output .= '<div style="color: red; font-size: larger;">Informační údaje uloženy!</div>';
     149        $this->System->Modules['Log']->NewRecord('EatingPlace', 'InfoSave');
     150      }
     151    }
     152    $Output = '<form action="?action=savemenu" method="post">
     153<fieldset><legend>Jídlo pro jednotlivé dny</legend>
     154<table align="center" class="WideTable"><tr><th>Den</th><th>Datum</th><th>Týden</th><th>Polévka</th><th>Hlavní jídlo</th><th>Stav</th></tr>';
     155    for($I = 0; $I < $this->DayCount; $I++)
     156    {
     157      $Time = time() + $I * 86400;
     158      $DbResult = $this->Database->select('Meals', '*', 'Date = "'.date('Y-m-d', $Time).'"');
     159      if($Row = $DbResult->fetch_array())
     160        $Output .= $this->PrintTableRow($Row);
     161      else
     162      {
     163        $Row = array('Status' => 0, 'Meal' => '', 'Soup' => '', 'Date' => date('Y-m-d', $Time));
     164        $Output .= $this->PrintTableRow($Row);
     165      }
     166    }
     167    $Output .= '</table><br />
     168<div align="center"><input type="submit" value="Uložit menu"></div>
     169</fieldset></form>';
     170    $Output .= '<form action="?action=saveinfo" method="post">
     171<fieldset><legend>Informační údaje</legend>';
     172
     173    $DbResult = $this->Database->select('MealsInfo', '*');
     174    $Row = $DbResult->fetch_array();
     175    $Output .= '<textarea name="info" rows="20" cols="80" >'.$Row['Info'].'</textarea><br />'.
     176'Cena: <input type="text" name="price" size="5" value="'.$Row['Price'].'"> Kč<br />'.
     177'<div align="center"><input type="submit" value="Uložit údaje"></div>
     178</fieldset></form>';
     179    return($Output);
     180  }
     181}
     182
     183class Meals extends Model
     184{
     185  function __construct($Database, $System)
     186  {
     187    parent::__construct($Database, $System);
     188    $this->Name = 'Meals';
     189    $this->AddPropertyDate('Date');
     190    $this->AddPropertyString('Soup');
     191    $this->AddPropertyString('Meal');
     192    $this->AddPropertyInteger('Status');
     193  }
     194}
     195
     196class MealsInfo extends Model
     197{
     198  function __construct($Database, $System)
     199  {
     200    parent::__construct($Database, $System);
     201    $this->Name = 'MealsInfo';
     202    $this->AddPropertyText('Info');
     203    $this->AddPropertyInteger('Price');   
     204  }
     205}
     206
     207class ModuleMeals extends Module
     208{
     209  function __construct($Database, $System)
     210  {
     211    parent::__construct($Database, $System);
     212    $this->Name = 'Meals';
     213    $this->Version = '1.0';
     214    $this->Creator = 'Chronos';
     215    $this->License = 'GNU/GPL';
     216    $this->Description = 'Module for management meals. Can print week menu.';
     217    $this->Dependencies = array('Log');
     218    $this->Models = array('Meals', 'MealsInfo');
     219  }
     220 
     221  function Install()
     222  {
     223    parent::Install();
     224  }
     225 
     226  function UnInstall()
     227  {
     228    parent::UnInstall();
     229  }
     230
     231  function Init()
     232  {
     233    $this->System->Pages['jidelna'] = 'EatingPlace';
     234  }
     235}
    37236
    38237?>
Note: See TracChangeset for help on using the changeset viewer.