Changeset 237


Ignore:
Timestamp:
Jul 29, 2009, 11:07:21 AM (15 years ago)
Author:
george
Message:
  • Přidáno: Třída file pro obsluhu ukládání načtených souborů. Seznam uchovaných souborů je v tabulce File.
  • Opraveno: Zobrazení otvíracích dob včetně zbývajícího času do otevření/zavření.
  • Přidáno: Přímá editace otvíracích dob na webu.
  • Přidáno: Možnost načíst obrázek s otvírací dobou.
Location:
trunk
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Readme.txt

    r221 r237  
    2020  aktuality/uploads - přílohy aktualit
    2121  galerie - fotogalerie obrázků
    22 
     22  files - načtené soubory přes web
    2323
    24244) Práva složek
    2525
    2626  webcam - vlastníka nastavit na apache
     27  files - vlastníka nastavit na apache
    2728  finance/doklady - vlastníka nastavit na apache
    2829  aktuality/uploads - vlastníka nastavit na apache
    2930
    3031 
    31 5) Generování PDF dokumentů
     325) Požadované balíky
     33  Možnost instalovat na Fedoře přes yum install
     34 
     35  htmldoc - Pro generování PDF z HTML
     36  php-pecl-Fileinfo - pro zjištění MIME type ze souboru
    3237
    33   Nutno nainstalovat balík htmldoc. Na Fedoře pomocí yum install htmldoc.
    3438
  • trunk/config.sample.php

    r213 r237  
    3030    'WebcamRefresh' => 5,
    3131    'UserSupport' => 1,
     32    'UploadFileFolder' => 'files',
    3233    'News' => array
    3334    (
  • trunk/global.php

    r229 r237  
    1818include_once('forms.php');
    1919include_once('page.php');
     20include_once('file.php');
    2021
    2122$PrefixMultipliers = array
  • trunk/otevreno.php

    r203 r237  
    77  var $ShortTitle = 'Otvírací doby';
    88  var $DaysOfWeek = array('Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota', 'Neděle');
    9   var $DayShift = 3;
    10 
    11   function Show()
     9  var $EventType = array('Žádný', 'Otevřeno', 'Zavřeno');
     10
     11  function ToHumanTime($Time)
     12  {
     13    $Hours = floor($Time / 60);
     14    $Minutes = $Time - $Hours * 60;
     15    if($Minutes < 10) $Minutes = '0'.$Minutes;   
     16    $Hours = $Hours % 24;
     17    return($Hours.':'.$Minutes);
     18  }
     19
     20  function ToHumanTime2($Time)
     21  {
     22    $Days = floor($Time / 24 / 60);
     23    $Time = $Time - $Days * 24 * 60;
     24    $Hours = floor($Time / 60);
     25    $Time = $Time - $Hours * 60;
     26    $Minutes = $Time;
     27    $Output = '';
     28    if($Days > 0) $Output .= $Days.' dnů, ';
     29    if($Hours > 0) $Output .= $Hours.' hodin, ';
     30    if($Minutes > 0) $Output .= $Minutes.' minut';
     31    return($Output);
     32  }
     33 
     34  function EditSubject($Id)
     35  {
     36    if($this->System->Modules['User']->CheckPermission('SubjectOpenTime', 'Edit'))
     37    {
     38      $Output = '<div class="Centred">';
     39      $DbResult = $this->Database->select('Subject', 'Name', 'Id='.$Id);
     40      $DbRow = $DbResult->fetch_assoc();
     41      $Output .= '<form method="post" action="?Action=Save&amp;Subject='.$Id.'" enctype="multipart/form-data">'.
     42      '<strong>'.$DbRow['Name'].'</strong>'.
     43      '<table class="WideTable"><tr><th>Den</th><th>Od</th><th>Do</th><th>Od</th><th>Do</th></tr>';
     44      $Day = array();
     45      $DbResult = $this->Database->query('SELECT * FROM SubjectOpenTimeDay WHERE Subject = '.$Id);
     46      while($DbRow = $DbResult->fetch_assoc())
     47        $Day[$DbRow['Day']] = $DbRow;
     48      foreach($this->DaysOfWeek as $Index => $Name)
     49      {
     50        if(!array_key_exists($Index, $Day)) $Day[$Index] = array('Open1' => 0, 'Close1' => 0, 'Open2' => 0, 'Close2' => 0);
     51        $Output .= '<tr><td>'.$Name.'</td>'.
     52          '<td><input type="text" name="day'.$Index.'_open1_h" value="'.floor($Day[$Index]['Open1'] / 60).'" size="2" />'.
     53          ':<input type="text" name="day'.$Index.'_open1_m" value="'.($Day[$Index]['Open1'] - floor($Day[$Index]['Open1'] / 60) * 60).'" size="2" /></td>'.
     54          '<td><input type="text" name="day'.$Index.'_close1_h" value="'.floor($Day[$Index]['Close1'] / 60).'" size="2" />'.
     55          ':<input type="text" name="day'.$Index.'_close1_m" value="'.($Day[$Index]['Close1'] - floor($Day[$Index]['Close1'] / 60) * 60).'" size="2" /></td>'.
     56          '<td><input type="text" name="day'.$Index.'_open2_h" value="'.floor($Day[$Index]['Open2'] / 60).'" size="2" />'.
     57          ':<input type="text" name="day'.$Index.'_open2_m" value="'.($Day[$Index]['Open2'] - floor($Day[$Index]['Open2'] / 60) * 60).'" size="2" /></td>'.
     58          '<td><input type="text" name="day'.$Index.'_close2_h" value="'.floor($Day[$Index]['Close2'] / 60).'" size="2" />'.
     59          ':<input type="text" name="day'.$Index.'_close2_m" value="'.($Day[$Index]['Close2'] - floor($Day[$Index]['Close2'] / 60) * 60).'" size="2" /></td>'.
     60          '</tr>';
     61      }
     62      $DbResult = $this->Database->select('SubjectOpenTime', 'Notice', 'Subject='.$Id);
     63      $DbRow = $DbResult->fetch_assoc();
     64      $Output .= '</table>'.
     65      'Poznámka: <input type="text" name="notice" value="'.$DbRow['Notice'].'" size="50" /><br />'.
     66      'Fotka: <input type="file" name="photo" size="38" /><br />'.
     67      '<input type="submit" value="Uložit" />'.
     68      '</form></div>';
     69    } else $Output = 'Nemáte oprávnění';
     70    return($Output);
     71  }
     72 
     73  function SaveSubject($Id)
     74  {
     75    global $Config;
     76   
     77    $Output = '';
     78    if($this->System->Modules['User']->CheckPermission('SubjectOpenTime', 'Edit'))
     79    {
     80      $this->Database->delete('SubjectOpenTimeDay', 'Subject='.$Id);
     81      foreach($this->DaysOfWeek as $Index => $Name)
     82      {
     83        if($_POST['day'.$Index.'_open1_h'] > 24) $_POST['day'.$Index.'_open1_h'] = 24;
     84        if($_POST['day'.$Index.'_close1_h'] > 24) $_POST['day'.$Index.'_close1_h'] = 24;
     85        if($_POST['day'.$Index.'_open2_h'] > 24) $_POST['day'.$Index.'_open2_h'] = 24;
     86        if($_POST['day'.$Index.'_close2_h'] > 24) $_POST['day'.$Index.'_close2_h'] = 24;
     87        if($_POST['day'.$Index.'_open1_m'] > 59) $_POST['day'.$Index.'_open1_m'] = 59;
     88        if($_POST['day'.$Index.'_close1_m'] > 59) $_POST['day'.$Index.'_close1_m'] = 59;
     89        if($_POST['day'.$Index.'_open2_m'] > 59) $_POST['day'.$Index.'_open2_m'] = 59;
     90        if($_POST['day'.$Index.'_close2_m'] > 59) $_POST['day'.$Index.'_close2_m'] = 59;
     91        $Day = array('Subject' => $Id, 'Day' => $Index);
     92        $Day['Open1'] = $_POST['day'.$Index.'_open1_m'] + $_POST['day'.$Index.'_open1_h'] * 60;
     93        $Day['Close1'] = $_POST['day'.$Index.'_close1_m'] + $_POST['day'.$Index.'_close1_h'] * 60;
     94        $Day['Open2'] = $_POST['day'.$Index.'_open2_m'] + $_POST['day'.$Index.'_open2_h'] * 60;
     95        $Day['Close2'] = $_POST['day'.$Index.'_close2_m'] + $_POST['day'.$Index.'_close2_h'] * 60;
     96        $this->Database->insert('SubjectOpenTimeDay', $Day);
     97      }   
     98      $Output .= 'Uloženo'; 
     99     
     100      $File = new File($this->Database);
     101
     102      // Delete old file
     103      $DbResult = $this->Database->select('SubjectOpenTime', 'Photo', 'Subject='.$Id);
     104      $DbRow = $DbResult->fetch_assoc();
     105      $File->Delete($DbRow['Photo']);
     106
     107      // Create new file
     108      $FileId = $File->CreateFromUpload('photo');
     109      $this->Database->update('SubjectOpenTime', 'Subject='.$Id, array('UpdateTime' => 'NOW()', 'Notice' => $_POST['notice'], 'Photo' => $FileId));
     110    } else $Output = 'Nemáte oprávnění';
     111    return($Output);
     112  } 
     113 
     114  function ShowAll()
    12115  {
    13116    $Output = '<div class="Centred">';
    14     $DbResult = $this->Database->query('SELECT SubjectOpenTime.*, DATE_FORMAT(SubjectOpenTime.UpdateTime, "%e.%c.%Y") as UpdateTime, Subject.Name as Name FROM SubjectOpenTime JOIN Subject ON Subject.Id = SubjectOpenTime.Subject ORDER BY Name');
     117    $DbResult = $this->Database->query('SELECT SubjectOpenTime.*, DATE_FORMAT(SubjectOpenTime.UpdateTime, "%e.%c.%Y") as UpdateTime, Subject.Id, Subject.Name as Name FROM SubjectOpenTime JOIN Subject ON Subject.Id = SubjectOpenTime.Subject ORDER BY Name');
    15118    while($Subject = $DbResult->fetch_assoc())
    16119    {
    17120      $Output .= '<strong>'.$Subject['Name'].':</strong><br />';
    18          
    19       $DbResult2 = $this->Database->query('SELECT Subject, OpenTime, CloseTime, TIMEDIFF(DATE_FORMAT(CloseTime, "0000-01-%w %T"), DATE_FORMAT(NOW(), "0000-01-%w %T")) as RemainTime FROM `SubjectOpenTimeInterval` WHERE DATE_FORMAT(NOW(), "0000-01-%w %T") > OpenTime AND DATE_FORMAT(NOW(), "0000-01-%w %T") < CloseTime AND Subject='.$Subject['Subject']);
    20       if($DbResult2->num_rows > 0)
    21       {
    22         $DbRow = $DbResult2->fetch_assoc();
    23         $Output .= 'Zavírá za '.$DbRow['RemainTime'];
    24       } else
    25       {
    26         $DbResult2 = $this->Database->query('SELECT Subject, OpenTime, CloseTime, TIMEDIFF(OpenTime, DATE_FORMAT(NOW(), "0000-01-%w %T")) as RemainTime FROM `SubjectOpenTimeInterval` WHERE DATE_FORMAT(NOW(), "0000-01-%w %T") < OpenTime AND Subject='.$Subject['Subject'].' ORDER BY OpenTime LIMIT 1');
    27         $DbRow = $DbResult2->fetch_assoc();
    28         $Output .= 'Otevírá za '.$DbRow['RemainTime'];
    29       }
    30 
    31             $Output .= '<table class="WideTable">
    32 <tr><th>Den</th><th>Čas</th></tr>';
     121   
     122      // Load time event list
     123      $Events = array();
     124      $DbResult2 = $this->Database->query('SELECT * FROM `SubjectOpenTimeDay` WHERE Subject='.$Subject['Subject'].' ORDER BY Day ASC');
     125      while($DbRow = $DbResult2->fetch_assoc())
     126      {
     127        if(($DbRow['Open1'] != $DbRow['Close1']) and ($DbRow['Open1'] < $DbRow['Close1']))
     128        {
     129          $Events[] = array('Time' => $DbRow['Open1'] + $DbRow['Day'] * 24 * 60, 'Type' => 1);
     130          $Events[] = array('Time' => $DbRow['Close1'] + $DbRow['Day'] * 24 * 60, 'Type' => 2);
     131        }
     132        if(($DbRow['Open2'] != $DbRow['Close2']) and ($DbRow['Open2'] < $DbRow['Close2']) and ($DbRow['Close1'] < $DbRow['Open2']))
     133        {
     134          $Events[] = array('Time' => $DbRow['Open2'] + $DbRow['Day'] * 24 * 60, 'Type' => 1);
     135          $Events[] = array('Time' => $DbRow['Close2'] + $DbRow['Day'] * 24 * 60, 'Type' => 2);
     136        }
     137      }
     138      //print_r($Events);
     139     
     140      // Calculate time to next event
     141      if(count($Events) > 0)
     142      {
     143        $CurrentTime = ((date('w') + 6) % 7) * 24 * 60 + date('G') * 60 + date('i');
     144     
     145        $I = 0;
     146        while(($I < count($Events)) and ($Events[$I]['Time'] < $CurrentTime))
     147          $I++;
     148        if($I < count($Events))
     149        {
     150          $NextTime = $Events[$I]['Time'];
     151          $NextEventType = $Events[$I]['Type'];
     152        } else
     153        {
     154          $NextTime = $Events[0]['Time'] + 7 * 24 * 60;
     155          $NextEventType = $Events[0]['Type'];
     156        }
     157     
     158        $TimeDelta = $NextTime - $CurrentTime;
     159        //$Output .= $CurrentTime.' '.$NextTime;
     160        if($NextEventType == 2) $Output .= 'Zavírá za '.$this->ToHumanTime2($TimeDelta);
     161          else $Output .= 'Otevírá za '.$this->ToHumanTime2($TimeDelta);
     162      }
     163     
     164      // Show time inteval table 
     165      $Output .= '<table class="WideTable"><tr><th>Den</th><th>Čas</th></tr>';
    33166      foreach($this->DaysOfWeek as $DayIndex => $DayOfWeek)
    34167      {
    35         $DbResult2 = $this->Database->query('SELECT *, DATE_FORMAT(OpenTime, "%k:%i") as OpenTime2, DATE_FORMAT(CloseTime, "%k:%i") as CloseTime2, DAYOFWEEK(OpenTime) as Week FROM SubjectOpenTimeInterval WHERE SubjectOpenTimeInterval.Subject = '.$Subject['Subject'].' AND ((DAYOFWEEK(OpenTime) + 7) MOD 7)='.$DayIndex);
     168        $DbResult2 = $this->Database->query('SELECT * FROM SubjectOpenTimeDay WHERE Subject = '.$Subject['Subject'].' AND Day='.$DayIndex);
    36169        $Output .= '<tr><td>'.$DayOfWeek.'</td><td align="center">';
    37170        if($DbResult2->num_rows)
    38171        {
    39           while($TimeInterval = $DbResult2->fetch_assoc())
     172          $DbRow = $DbResult2->fetch_assoc();
     173          if(($DbRow['Open1'] != $DbRow['Close1']) and ($DbRow['Open1'] < $DbRow['Close1']))
    40174          {
    41             $Output .= $TimeInterval['OpenTime2'].' - '.$TimeInterval['CloseTime2'].' &nbsp;&nbsp; ';
     175            $Output .= $this->ToHumanTime($DbRow['Open1']).' - '.$this->ToHumanTime($DbRow['Close1']).' &nbsp;&nbsp; ';
     176          }
     177          if(($DbRow['Open2'] != $DbRow['Close2']) and ($DbRow['Open2'] < $DbRow['Close2']) and ($DbRow['Close1'] < $DbRow['Open2']))
     178          {
     179            $Output .= $this->ToHumanTime($DbRow['Open2']).' - '.$this->ToHumanTime($DbRow['Close2']).'';
    42180          }
    43181        } else
     
    47185      $Output .= '</table>Aktualizováno: '.$Subject['UpdateTime'].'<br />';
    48186      if($Subject['Notice'] != '') $Output .= 'Poznámka: '.$Subject['Notice'].'<br />';
     187     
     188      if($Subject['Photo'] != 0) $Output .= '<a href="FileDownload.php?Id='.$Subject['Photo'].'">Fotka</a> ';
     189     
     190      if($this->System->Modules['User']->CheckPermission('SubjectOpenTime', 'Edit'))
     191        $Output .= '<a href="?Action=Edit&amp;Subject='.$Subject['Id'].'">Editovat</a><br />';
    49192      $Output .= '<br />';
    50193    }
     
    52195    return($Output);
    53196  }
     197 
     198  function Show()
     199  {
     200    if(array_key_exists('Action', $_GET))
     201    {
     202      if($_GET['Action'] == 'Edit') $Output = $this->EditSubject($_GET['Subject']);
     203      else if($_GET['Action'] == 'Save')
     204      {
     205        $Output = $this->SaveSubject($_GET['Subject']);
     206        $Output .= $this->ShowAll();
     207      }
     208      else $Output = $this->ShowAll();
     209    } else $Output = $this->ShowAll();
     210    return($Output);
     211  }
    54212}
    55213
Note: See TracChangeset for help on using the changeset viewer.