Changeset 64 for www


Ignore:
Timestamp:
Apr 4, 2008, 8:11:34 AM (17 years ago)
Author:
george
Message:

Uživatelské nastavení zobrazování aktualit na hlavní stránce ukládané do cookie prohlížeče.

Location:
www
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • www/index.php

    r55 r64  
    66
    77$Database->select_db('share');
     8
     9function CategoryItemCompare($Item1, $Item2)
     10{
     11  if ($Item1['Index'] == $Item2['Index']) return(0);
     12  return ($Item1['Index'] > $Item2['Index']) ? -1 : 1;
     13}
     14
     15// Process cookies
     16if(array_key_exists('Action', $_GET))
     17{
     18  if($_GET['Action'] == 'CustomizeNewsSave')
     19  {
     20    $Checkbox = array('' => 0, 'on' => 1);
     21    // print_r($_POST);
     22    $Setting = array();
     23    for($I = 0; $I < $_POST['NewsCategoryCount']; $I++)
     24    {
     25      if(($_POST['NewsCategoryDaysAgo'.$I]*1) < 0) $_POST['NewsCategoryIndex'.$I] = 0;
     26      if(($_POST['NewsCategoryCount'.$I]*1) < 0) $_POST['NewsCategoryCount'.$I] = 0;
     27      if(!array_key_exists('NewsCategoryEnabled'.$I, $_POST)) $_POST['NewsCategoryEnabled'.$I] = '';
     28      $Setting[] = array('CategoryId' => $_POST['NewsCategoryId'.$I], 'Enabled' => $Checkbox[$_POST['NewsCategoryEnabled'.$I]], 'ItemCount' => ($_POST['NewsCategoryCount'.$I]*1), 'DaysAgo' => ($_POST['NewsCategoryDaysAgo'.$I]*1), 'Index' => ($_POST['NewsCategoryIndex'.$I]*1));
     29    }
     30    // Sort indexes
     31    usort($Setting, 'CategoryItemCompare');
     32    $Setting = array_reverse($Setting);
     33    // Normalize indexes
     34    foreach($Setting as $Index => $Item)
     35      $Setting[$Index]['Index'] = $Index + 1;
     36   
     37    // print_r($Setting);
     38
     39    // Store new cookie value
     40    $_COOKIE['NewsSetting'] = serialize($Setting);
     41    setcookie('NewsSetting', $_COOKIE['NewsSetting']);
     42  }
     43}
    844
    945?>
     
    142178
    143179// Zobrazení času běhu počítače
    144 $Data = explode(' ',exec('uptime'));
    145 $Data = array_slice($Data,3,-8);
    146 $Uptime = '';
    147 foreach($Data as $Item)
    148 {
    149   if(strpos($Item,':')) $Uptime .= substr($Item,0,-1).' hodin';
    150   else $Uptime .= $Item.' ';
    151 }
    152 $Uptime = str_replace('2 days,','2 dny a',$Uptime);
    153 $Uptime = str_replace('3 days,','3 dny a',$Uptime);
    154 $Uptime = str_replace('4 days,','4 dny a',$Uptime);
    155 $Uptime = str_replace('days,','dní a',$Uptime);
    156 $Uptime = str_replace('day,','den a',$Uptime);
    157 $Uptime = str_replace('min,','minut',$Uptime);
    158 echo('Server běží '.$Uptime);
     180function GetServerUptime()
     181{
     182  $Data = explode(' ',exec('uptime'));
     183  $Data = array_slice($Data,3,-8);
     184  $Uptime = '';
     185  foreach($Data as $Item)
     186  {
     187    if(strpos($Item,':')) $Uptime .= substr($Item,0,-1).' hodin';
     188    else $Uptime .= $Item.' ';
     189  }
     190  $Uptime = str_replace('2 days,','2 dny a',$Uptime);
     191  $Uptime = str_replace('3 days,','3 dny a',$Uptime);
     192  $Uptime = str_replace('4 days,','4 dny a',$Uptime);
     193  $Uptime = str_replace('days,','dní a',$Uptime);
     194  $Uptime = str_replace('day,','den a',$Uptime);
     195  $Uptime = str_replace('min,','minut',$Uptime);
     196  return('Server běží '.$Uptime);
     197}
     198
     199echo(GetServerUptime());
    159200
    160201echo('</td><td width="50%" valign="top" style="font-size: smaller;">');
     
    169210
    170211echo('<table width="100%"><tr><td><strong>Aktuálně:</strong></td><td align="right">
    171 <img alt="Teplomer" width="10" height="18" src="images/teplomer3.png"><a href="statistic/trafficview2.php?type=temp">'.$Teplota
    172 .'°C (mimo provoz)</a></td></tr></table>');
    173 
    174 $NewsCountPerCategory = 3;
     212<a href="?Action=CustomizeNews">Upravit</a></td></tr></table>');
     213//<img alt="Teplomer" width="10" height="18" src="images/teplomer3.png"><a href="statistic/trafficview2.php?type=temp">'.$Teplota.'°C (mimo provoz)</a></td></tr></table>');
     214
    175215$UploadedFilesFolder = 'aktuality/uploads/';
    176216
     217// Initialize default news setting
     218$NewsSetting = array();
     219$I = 1;
     220$DbResult = $Database->select('news_category', '*');
     221while($NewsCategory = $DbResult->fetch_array())
     222{
     223  $NewsSetting[] = array('CategoryId' => $NewsCategory['id'], 'Index' => $I, 'Enabled' => 1, 'ItemCount' => 5, 'DaysAgo' => 14);
     224  $I++;
     225}
     226// Merge defaults with user setting
     227if(array_key_exists('NewsSetting', $_COOKIE))
     228{
     229  $NewsSettingCookie = unserialize($_COOKIE['NewsSetting']);
     230  foreach($NewsSetting as $Index => $NewSetting)
     231  {
     232    $NewsSetting[$Index] = array_merge($NewSetting, $NewsSettingCookie[$Index]);
     233  }
     234}
     235
     236if(array_key_exists('Action', $_GET))
     237{
     238  // Show news customize menu
     239  if($_GET['Action'] == 'CustomizeNews')
     240  {
     241    echo('<form action="?Action=CustomizeNewsSave" method="post">');
     242    echo('<table width="100%" cellspacing="0" border="1"><tr><td><table cellspacing="0" width="100%">');
     243    echo('<tr><th>Kategorie</th><th>Pozice</th><th>Zobrazit</th><th>Max. počet</th><th>Posledních dnů</th></tr>');
     244    $I = 0;
     245    foreach($NewsSetting as $SettingItem)
     246    {
     247      $DbResult = $Database->select('news_category', '*', 'id='.$SettingItem['CategoryId']);
     248      $NewsCategory = $DbResult->fetch_array();
     249      echo('<tr><td>'.$NewsCategory['caption'].'</td><td align="center"><input type="text" size="1" name="NewsCategoryIndex'.$I.'" value="'.$SettingItem['Index'].'"></td><td align="center"><input type="checkbox" name="NewsCategoryEnabled'.$I.'"');
     250      if($SettingItem['Enabled'] == 1) echo(' CHECKED');
     251      echo('></td>'.
     252      '<td align="center"><input type="text" size="1" name="NewsCategoryCount'.$I.'" value="'.$SettingItem['ItemCount'].'">'.
     253      '<input type="hidden" name="NewsCategoryId'.$I.'" value="'.$SettingItem['CategoryId'].'"></td><td align="center"><input type="text" size="1" name="NewsCategoryDaysAgo'.$I.'" value="'.$SettingItem['DaysAgo'].'"></td></tr>');
     254      $I++;
     255    }
     256    echo('</table><input type="hidden" name="NewsCategoryCount" value="'.count($NewsSetting).'"><input type="submit" value="Uložit"></form></td></tr></table>');
     257  }
     258}
     259
    177260echo('<div onmouseout="skryj(predchozi)">');
    178261
    179 function ShowNews($Category)
     262function ShowNews($Category, $ItemCount, $DaysAgo)
    180263{
    181264  global $Database, $NewsCategoryNames, $NewsCountPerCategory, $UploadedFilesFolder;
    182265
     266  $ItemCount = abs($ItemCount);
     267  $DaysAgo = abs($DaysAgo);
    183268  $DbResult = $Database->select('news_category', '*', 'id='.$Category);
    184269  $Row = $DbResult->fetch_array();
     
    189274  echo('</td></tr><tr><td colspan="2">');
    190275  echo('<table cellspacing="0" width="100%" style="padding: 2px 2px 2px 2px; font-size: small; border-style: solid; border-color: red; border-width: 1; background-color: #FFF0F0;">');
    191   $DbResult = $Database->select('news', '*', 'category='.$Category.' ORDER BY date DESC LIMIT 0,'.$NewsCountPerCategory);
     276  $DbResult = $Database->query('SELECT * FROM `news` WHERE (`category`='.$Category.') AND (DATE_SUB(NOW(), INTERVAL '.$DaysAgo.' DAY) < `date`) ORDER BY `date` DESC LIMIT 0,'.$ItemCount);
     277  //echo($Database->error.'<br>');
     278  //echo($Database->LastQuery.'<br>');
    192279//echo('<table cellpadding="0" cellspacing="0" width="100%"><tr><td>');
    193280  $Index = 0;
    194281  $FontSize = 12;
     282  if($DbResult->num_rows > 0)
    195283  while($Row = $DbResult->fetch_array())
    196284  {
     
    212300    echo('</div></td></tr>');
    213301    $Index = $Index + 1;   
    214     $FontSize = $FontSize - 2;
     302    $FontSize = $FontSize - 1;
    215303  }
    216304  echo('</table></td></tr></table>'."\n\n");
    217305}
    218306
    219 ShowNews(5);
    220 ShowNews(3);
    221 ShowNews(1);
    222 ShowNews(2);
    223 ShowNews(4);
    224 ShowNews(6);
    225 ShowNews(8);
    226 ShowNews(9);
    227 ShowNews(10);
     307foreach($NewsSetting as $SettingItem)
     308  if($SettingItem['Enabled'] == 1) ShowNews($SettingItem['CategoryId'], $SettingItem['ItemCount'], $SettingItem['DaysAgo']);
    228309
    229310echo('<a href="aktuality/subscription.php"><img style="margin: 0px 0px 0px 0px;" border="0" src="images/rss20.png" alt="Aktuality přes RSS"></a>  <a href="aktuality/subscription.php">Automatické sledování novinek</a>');
Note: See TracChangeset for help on using the changeset viewer.