Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

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

    r738 r873  
    1515    $Hours = floor($Time / 60);
    1616    $Minutes = $Time - $Hours * 60;
    17     if($Minutes < 10) $Minutes = '0'.$Minutes;
     17    if ($Minutes < 10) $Minutes = '0'.$Minutes;
    1818    $Hours = $Hours % 24;
    19     return($Hours.':'.$Minutes);
     19    return ($Hours.':'.$Minutes);
    2020  }
    2121
     
    2828    $Minutes = $Time;
    2929    $Output = '';
    30     if($Days > 0) $Output .= $Days.' dnů, ';
    31     if($Hours > 0) $Output .= $Hours.' hodin, ';
    32     if($Minutes > 0) $Output .= $Minutes.' minut';
    33     return($Output);
     30    if ($Days > 0) $Output .= $Days.' dnů, ';
     31    if ($Hours > 0) $Output .= $Hours.' hodin, ';
     32    if ($Minutes > 0) $Output .= $Minutes.' minut';
     33    return ($Output);
    3434  }
    3535
    3636  function EditSubject($Id)
    3737  {
    38     if($this->System->User->CheckPermission('OpeningHours', 'Edit'))
     38    if ($this->System->User->CheckPermission('OpeningHours', 'Edit'))
    3939    {
    4040      $Output = '<div class="Centred">';
     
    4646      $Day = array();
    4747      $DbResult = $this->Database->query('SELECT * FROM SubjectOpenTimeDay WHERE Subject = '.$Id);
    48       while($DbRow = $DbResult->fetch_assoc())
     48      while ($DbRow = $DbResult->fetch_assoc())
    4949        $Day[$DbRow['Day']] = $DbRow;
    50       foreach($this->DaysOfWeek as $Index => $Name)
    51       {
    52         if(!array_key_exists($Index, $Day)) $Day[$Index] = array('Open1' => 0, 'Close1' => 0, 'Open2' => 0, 'Close2' => 0);
     50      foreach ($this->DaysOfWeek as $Index => $Name)
     51      {
     52        if (!array_key_exists($Index, $Day)) $Day[$Index] = array('Open1' => 0, 'Close1' => 0, 'Open2' => 0, 'Close2' => 0);
    5353        $Output .= '<tr><td>'.$Name.'</td>'.
    5454          '<td><input type="text" name="day'.$Index.'_open1_h" value="'.floor($Day[$Index]['Open1'] / 60).'" size="2" />'.
     
    7070      '</form></div>';
    7171    } else $Output = 'Nemáte oprávnění';
    72     return($Output);
     72    return ($Output);
    7373  }
    7474
     
    7878
    7979    $Output = '';
    80     if($this->System->User->CheckPermission('OpeningHours', 'Edit'))
     80    if ($this->System->User->CheckPermission('OpeningHours', 'Edit'))
    8181    {
    8282      $this->Database->delete('SubjectOpenTimeDay', 'Subject='.$Id);
    83       foreach($this->DaysOfWeek as $Index => $Name)
    84       {
    85         if($_POST['day'.$Index.'_open1_h'] > 24) $_POST['day'.$Index.'_open1_h'] = 24;
    86         if($_POST['day'.$Index.'_close1_h'] > 24) $_POST['day'.$Index.'_close1_h'] = 24;
    87         if($_POST['day'.$Index.'_open2_h'] > 24) $_POST['day'.$Index.'_open2_h'] = 24;
    88         if($_POST['day'.$Index.'_close2_h'] > 24) $_POST['day'.$Index.'_close2_h'] = 24;
    89         if($_POST['day'.$Index.'_open1_m'] > 59) $_POST['day'.$Index.'_open1_m'] = 59;
    90         if($_POST['day'.$Index.'_close1_m'] > 59) $_POST['day'.$Index.'_close1_m'] = 59;
    91         if($_POST['day'.$Index.'_open2_m'] > 59) $_POST['day'.$Index.'_open2_m'] = 59;
    92         if($_POST['day'.$Index.'_close2_m'] > 59) $_POST['day'.$Index.'_close2_m'] = 59;
     83      foreach ($this->DaysOfWeek as $Index => $Name)
     84      {
     85        if ($_POST['day'.$Index.'_open1_h'] > 24) $_POST['day'.$Index.'_open1_h'] = 24;
     86        if ($_POST['day'.$Index.'_close1_h'] > 24) $_POST['day'.$Index.'_close1_h'] = 24;
     87        if ($_POST['day'.$Index.'_open2_h'] > 24) $_POST['day'.$Index.'_open2_h'] = 24;
     88        if ($_POST['day'.$Index.'_close2_h'] > 24) $_POST['day'.$Index.'_close2_h'] = 24;
     89        if ($_POST['day'.$Index.'_open1_m'] > 59) $_POST['day'.$Index.'_open1_m'] = 59;
     90        if ($_POST['day'.$Index.'_close1_m'] > 59) $_POST['day'.$Index.'_close1_m'] = 59;
     91        if ($_POST['day'.$Index.'_open2_m'] > 59) $_POST['day'.$Index.'_open2_m'] = 59;
     92        if ($_POST['day'.$Index.'_close2_m'] > 59) $_POST['day'.$Index.'_close2_m'] = 59;
    9393        $Day = array('Subject' => $Id, 'Day' => $Index);
    9494        $Day['Open1'] = $_POST['day'.$Index.'_open1_m'] + $_POST['day'.$Index.'_open1_h'] * 60;
     
    111111      $this->Database->update('SubjectOpenTime', 'Subject='.$Id, array('UpdateTime' => 'NOW()', 'Notice' => $_POST['notice'], 'Photo' => $FileId));
    112112    } else $Output = 'Nemáte oprávnění';
    113     return($Output);
     113    return ($Output);
    114114  }
    115115
     
    118118    $Output = '<div class="Centred">';
    119119    $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');
    120     while($Subject = $DbResult->fetch_assoc())
     120    while ($Subject = $DbResult->fetch_assoc())
    121121    {
    122122      $Output .= '<strong>'.$Subject['Name'].':</strong><br />';
     
    125125      $Events = array();
    126126      $DbResult2 = $this->Database->query('SELECT * FROM `SubjectOpenTimeDay` WHERE Subject='.$Subject['Subject'].' ORDER BY Day ASC');
    127       while($DbRow = $DbResult2->fetch_assoc())
    128       {
    129         if(($DbRow['Open1'] != $DbRow['Close1']) and ($DbRow['Open1'] < $DbRow['Close1']))
     127      while ($DbRow = $DbResult2->fetch_assoc())
     128      {
     129        if (($DbRow['Open1'] != $DbRow['Close1']) and ($DbRow['Open1'] < $DbRow['Close1']))
    130130        {
    131131          $Events[] = array('Time' => $DbRow['Open1'] + $DbRow['Day'] * 24 * 60, 'Type' => 1);
    132132          $Events[] = array('Time' => $DbRow['Close1'] + $DbRow['Day'] * 24 * 60, 'Type' => 2);
    133133        }
    134         if(($DbRow['Open2'] != $DbRow['Close2']) and ($DbRow['Open2'] < $DbRow['Close2']) and ($DbRow['Close1'] < $DbRow['Open2']))
     134        if (($DbRow['Open2'] != $DbRow['Close2']) and ($DbRow['Open2'] < $DbRow['Close2']) and ($DbRow['Close1'] < $DbRow['Open2']))
    135135        {
    136136          $Events[] = array('Time' => $DbRow['Open2'] + $DbRow['Day'] * 24 * 60, 'Type' => 1);
     
    141141
    142142      // Calculate time to next event
    143       if(count($Events) > 0)
     143      if (count($Events) > 0)
    144144      {
    145145        $CurrentTime = ((date('w') + 6) % 7) * 24 * 60 + date('G') * 60 + date('i');
    146146
    147147        $I = 0;
    148         while(($I < count($Events)) and ($Events[$I]['Time'] < $CurrentTime))
     148        while (($I < count($Events)) and ($Events[$I]['Time'] < $CurrentTime))
    149149          $I++;
    150         if($I < count($Events))
     150        if ($I < count($Events))
    151151        {
    152152          $NextTime = $Events[$I]['Time'];
     
    160160        $TimeDelta = $NextTime - $CurrentTime;
    161161        //$Output .= $CurrentTime.' '.$NextTime;
    162         if($NextEventType == 2) $Output .= 'Zavírá za '.$this->ToHumanTime2($TimeDelta);
     162        if ($NextEventType == 2) $Output .= 'Zavírá za '.$this->ToHumanTime2($TimeDelta);
    163163          else $Output .= 'Otevírá za '.$this->ToHumanTime2($TimeDelta);
    164164      }
     
    166166      // Show time inteval table
    167167      $Output .= '<table class="WideTable"><tr><th>Den</th><th>Čas</th></tr>';
    168       foreach($this->DaysOfWeek as $DayIndex => $DayOfWeek)
     168      foreach ($this->DaysOfWeek as $DayIndex => $DayOfWeek)
    169169      {
    170170        $DbResult2 = $this->Database->query('SELECT * FROM SubjectOpenTimeDay WHERE Subject = '.$Subject['Subject'].' AND Day='.$DayIndex);
    171171        $Output .= '<tr><td>'.$DayOfWeek.'</td><td align="center">';
    172         if($DbResult2->num_rows)
     172        if ($DbResult2->num_rows)
    173173        {
    174174          $DbRow = $DbResult2->fetch_assoc();
    175           if(($DbRow['Open1'] != $DbRow['Close1']) and ($DbRow['Open1'] < $DbRow['Close1']))
     175          if (($DbRow['Open1'] != $DbRow['Close1']) and ($DbRow['Open1'] < $DbRow['Close1']))
    176176          {
    177177            $Output .= $this->ToHumanTime($DbRow['Open1']).' - '.$this->ToHumanTime($DbRow['Close1']).' &nbsp;&nbsp; ';
    178178          }
    179           if(($DbRow['Open2'] != $DbRow['Close2']) and ($DbRow['Open2'] < $DbRow['Close2']) and ($DbRow['Close1'] < $DbRow['Open2']))
     179          if (($DbRow['Open2'] != $DbRow['Close2']) and ($DbRow['Open2'] < $DbRow['Close2']) and ($DbRow['Close1'] < $DbRow['Open2']))
    180180          {
    181181            $Output .= $this->ToHumanTime($DbRow['Open2']).' - '.$this->ToHumanTime($DbRow['Close2']).'';
     
    186186      }
    187187      $Output .= '</table>Aktualizováno: '.$Subject['UpdateTime'].'<br />';
    188       if($Subject['Notice'] != '') $Output .= 'Poznámka: '.$Subject['Notice'].'<br />';
    189 
    190       if($Subject['Photo'] != 0) $Output .= '<a href="file?id='.$Subject['Photo'].'">Fotka</a> ';
    191 
    192       if($this->System->User->CheckPermission('SubjectOpenTime', 'Edit'))
     188      if ($Subject['Notice'] != '') $Output .= 'Poznámka: '.$Subject['Notice'].'<br />';
     189
     190      if ($Subject['Photo'] != 0) $Output .= '<a href="file?id='.$Subject['Photo'].'">Fotka</a> ';
     191
     192      if ($this->System->User->CheckPermission('SubjectOpenTime', 'Edit'))
    193193        $Output .= '<a href="edit?Subject='.$Subject['Id'].'">Editovat</a><br />';
    194194      $Output .= '<br />';
    195195    }
    196196    $Output .= '</div>';
    197     return($Output);
     197    return ($Output);
    198198  }
    199199
    200200  function Show()
    201201  {
    202     if(count($this->System->PathItems) > 1)
    203     {
    204       if($this->System->PathItems[1] == 'edit') $Output = $this->EditSubject($_GET['Subject']);
    205       else if($this->System->PathItems[1] == 'save')
     202    if (count($this->System->PathItems) > 1)
     203    {
     204      if ($this->System->PathItems[1] == 'edit') $Output = $this->EditSubject($_GET['Subject']);
     205      else if ($this->System->PathItems[1] == 'save')
    206206      {
    207207        $Output = $this->SaveSubject($_GET['Subject']);
     
    209209      } else $Output = PAGE_NOT_FOUND;
    210210    } else $Output = $this->ShowAll();
    211     return($Output);
     211    return ($Output);
    212212  }
    213213}
Note: See TracChangeset for help on using the changeset viewer.