Changeset 455 for trunk/action.php


Ignore:
Timestamp:
Apr 13, 2010, 10:03:12 AM (15 years ago)
Author:
george
Message:
  • Upraveno: Přístup k databázi převeden na objektový pomocí rozšířené PHP třídy mysqli. Při práci s databází použít globální objekt $System a jeho prvek $Database ($System->Database->query("SELECT ...");.
  • Upraveno: Při vkládání nové zprávy do Kecátka neprovádět přesměrování, ale rovnou zobrazit výpis. U některých překladatelů toto způsobovalo opakované vložení zprávy.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/action.php

    r436 r455  
    55function Search()
    66{
    7   global $Database, $TranslationTree;
     7  global $System, $TranslationTree;
    88 
    99  if(array_key_exists('search', $_GET)) $Search = $_GET['search'];
     
    2222      if($Item['Column'] != '') $sql .= ' OR `'.$Item['Column'].'` LIKE "%'.$Search.'%"';
    2323    }
    24     $Line = mysql_fetch_row($Database->SQLCommand($sql));
     24    $DbResult = $System->Database->query($sql);
     25    $Line = $DbResult->fetch_row();
    2526    echo('<tr><td><a href="TranslationList.php?group='.$Group['Id'].'&amp;user=0&amp;state=0&amp;text='.$Search.'&amp;entry=">'.$Group['Name'].'</a></td><td>'.$Line[0].'</td></tr>');
    2627  }
    2728 
    28     $Line = mysql_fetch_row($Database->SQLCommand('SELECT count(*) FROM `User` WHERE `Name` LIKE "%'.$Search.'%"'));
     29  $DbResult = $System->Database->query('SELECT count(*) FROM `User` WHERE `Name` LIKE "%'.$Search.'%"');
     30  $Line = $DbResult->fetch_row();
    2931  echo('<tr><td><a href="userlist.php?search='.$Search.'">Uživatelé</a></td><td>'.$Line[0].'</td></tr>');
    30     $Line = mysql_fetch_row($Database->SQLCommand('SELECT count(*) FROM `Team` WHERE `Name` LIKE "%'.$Search.'%" OR `Description` LIKE "%'.$Search.'%"'));
     32 
     33  $DbResult = $System->Database->query('SELECT count(*) FROM `Team` WHERE `Name` LIKE "%'.$Search.'%" OR `Description` LIKE "%'.$Search.'%"');
     34  $Line = $DbResult->fetch_row();
    3135  echo('<tr><td><a href="team.php?search='.$Search.'">Týmy</a></td><td>'.$Line[0].'</td></tr>');
    32     $Line = mysql_fetch_row($Database->SQLCommand('SELECT count(*) FROM `CzWoWPackageVersion` WHERE `Text` LIKE "%'.$Search.'%"'));
     36 
     37  $DbResult = $System->Database->query('SELECT count(*) FROM `CzWoWPackageVersion` WHERE `Text` LIKE "%'.$Search.'%"');
     38  $Line = $DbResult->fetch_row();
    3339  echo('<tr><td><a href="download.php?addon">Čeština pro klienta</a></td><td>'.$Line[0].'</td></tr>');
    3440  echo('<tr><td><a href="aowow/?search='.$Search.'">Vyhledávací databáze AoWoW</a></td></tr>');
    35     $Line = mysql_fetch_row($Database->SQLCommand('SELECT count(*) FROM `Dictionary` WHERE (`Text` LIKE "%'.$Search.'%" OR `Description` LIKE "%'.$Search.'%") AND `Language` = 0'));
     41 
     42  $DbResult = $System->Database->query('SELECT count(*) FROM `Dictionary` WHERE (`Text` LIKE "%'.$Search.'%" OR `Description` LIKE "%'.$Search.'%") AND `Language` = 0');
     43  $Line = $DbResult->fetch_row();
    3644  echo('<tr><td><a href="dictionary.php?search='.$Search.'">Slovníček</a></td><td>'.$Line[0].'</td></tr>');
    3745 
     
    4149function DatabaseKit()
    4250{
    43   global $Database, $TranslationTree, $User;
     51  global $System, $TranslationTree, $User;
    4452 
    4553  if($User->Licence(LICENCE_ADMIN))
     
    6169    {
    6270      $sql = 'DELETE FROM `Log` WHERE `Type` = '.$_POST['Type'];
    63       $Database->SQLCommand($sql);
     71      $System->Database->query($sql);
    6472      WriteLog('Vymazán log '.$_POST['Type'], LOG_TYPE_MODERATOR);
    6573      echo(' Vymazán log '.$_POST['Type']);
     
    8593        $sql .= ')';
    8694     
    87         $ID = $Database->SQLCommand($sql);
    88         while ($Line = mysql_fetch_assoc($ID))
     95        $DbResult = $System->Database->query($sql);
     96        while ($Line = $DbResult->fetch_assoc())
    8997        {
    9098          $sql = 'UPDATE '.$Table.' SET ';
     
    96104          $sql = substr($sql,0,strlen($sql)-1);
    97105          $sql .= ' WHERE `ID` = '.$Line['ID'];
    98           $Database->SQLCommand($sql);
     106          $System->Database->query($sql);
    99107          echo ('.');
    100108        }
     
    123131      FROM `'.$Table.'` AS `Tran` WHERE (`Language` <> 0) AND ((`Take` = 0) OR (`ID` = `Take`) OR NOT EXISTS(SELECT 1 FROM `'.$Table.'` WHERE `ID` = `Tran`.`Take`))';
    124132     
    125         $ID = $Database->SQLCommand($sql);
    126         while($Line = mysql_fetch_assoc($ID))
     133        $DbResult = $System->Database->query($sql);
     134        while($Line = $DbResult->fetch_assoc())
    127135        {
    128136          $sql = 'UPDATE `'.$Table.'` SET `Take` = '.$Line['IDOrig'].' WHERE `ID` = '.$Line['ID'];
    129           $Database->SQLCommand($sql);
     137          $System->Database->query($sql);
    130138          echo('.');
    131139        }
     
    150158        echo ($Table.' ');
    151159        $sql = 'SELECT `gs_orig`.`ID`, `gs_tran`.`Entry`, `gs_tran`.`ShortCut` AS `ShortCut_tran`, `gs_orig`.`ShortCut`  AS `ShortCut_orig` FROM `'.$Table.'` AS `gs_tran` JOIN `'.$Table.'` AS `gs_orig` ON `gs_orig`.`Entry` = `gs_tran`.`Entry` WHERE `gs_tran`.`Language` <> 0 AND `gs_tran`.`ShortCut` <> `gs_orig`.`ShortCut`';     
    152         $ID = $Database->SQLCommand($sql);
    153         while ($Line = mysql_fetch_assoc($ID))
     160        $DbResult = $System->Database->query($sql);
     161        while ($Line = $DbResult->fetch_assoc())
    154162        {
    155163          $sql = 'UPDATE `'.$Table.'` SET `ShortCut` = '.$Line['ShortCut_orig'].' WHERE `ID` = '.$Line['ID'];
    156           $Database->SQLCommand($sql);
     164          $System->Database->query($sql);
    157165          echo ('.');
    158166        }
    159167   
    160168        echo (' <strong>Hotovo</strong> <br />');
    161         if(mysql_num_rows($ID) > 0)
    162         {
    163           WriteLog('Použita oprava DB na sloupec ShortCut '.mysql_num_rows($ID).' řádků z tabulky '.$Table, LOG_TYPE_MODERATOR);
    164           echo (' Použita oprava DB na sloupec ShortCut '.mysql_num_rows($ID).' řádků z tabulky '.$Table.'<br />');
     169        if($DbResult->num_rows > 0)
     170        {
     171          WriteLog('Použita oprava DB na sloupec ShortCut '.$DbResult->num_rows.' řádků z tabulky '.$Table, LOG_TYPE_MODERATOR);
     172          echo (' Použita oprava DB na sloupec ShortCut '.$DbResult->num_rows.' řádků z tabulky '.$Table.'<br />');
    165173        }
    166174      }
     
    171179function Delete()
    172180{
    173   global $Database, $User;
     181  global $System, $User;
    174182 
    175183  if($User->Licence(LICENCE_MODERATOR))
    176184  {
    177185    $TextID = $_GET['ID'];       
    178     $Database->SQLCommand('DELETE FROM `'.$Table.'` WHERE `ID` = '.$TextID.' AND `Language` <> 0');
     186    $System->Database->query('DELETE FROM `'.$Table.'` WHERE `ID` = '.$TextID.' AND `Language` <> 0');
    179187    echo('Překlad byl smazán!');   
    180188    WriteLog('Překlad byl smazán! <a href="form.php?group='.$GroupID.'&amp;ID='.$TextID.'">'.$TextID.'</a>', LOG_TYPE_MODERATOR);
     
    184192function ShoutBox()
    185193{
    186   global $Database, $User;
    187  
    188   if(array_key_exists('shoutbox', $_GET)) $shoutbox = $_GET['shoutbox'];
    189   else $shoutbox = '';
    190   if($shoutbox == '')
    191   {
    192     echo('<form action="action.php?action=shoutbox&amp;shoutbox=1" method="post"><fieldset><legend>Nová zpráva kecátka</legend>
    193       Uživatel: ');
     194  global $System, $User;
     195 
     196  if(!array_key_exists('add', $_POST))
     197  {
     198    echo('<form action="action.php?action=shoutbox" method="post">'.
     199    '<fieldset><legend>Nová zpráva kecátka</legend>
     200     Uživatel: ');
    194201    if($User->Licence(LICENCE_USER)) echo('<b>'.$User->Name.'</b><br />');
    195   else echo('<input type="text" name="user" /><br />');
     202    else echo('<input type="text" name="user" /><br />');
    196203    echo('Text zprávy: <br>
    197204      <textarea  onkeydown="ResizeTextArea(this)" name="text" cols="40"></textarea> <br />
    198       <input type="submit" value="Odeslat" /><br /></fieldset>
     205      <input type="submit" name="add" value="Odeslat" /><br /></fieldset>
    199206      </form>');
    200207  } else
     
    202209    if($User->Licence(LICENCE_USER))
    203210    {
    204       $Text = $_POST['text'];
    205       $Database->SQLCommand('INSERT INTO `ShoutBox` ( `User` , `Text` , `Date` , `IP` ) '.
     211      if(array_key_exists('text', $_POST))
     212      {
     213        $Text = $_POST['text'];
     214        $System->Database->query('INSERT INTO `ShoutBox` ( `User` , `Text` , `Date` , `IP` ) '.
    206215      ' VALUES ("'.$User->Name.'", "'.$Text.'", NOW(), "'.$_SERVER['REMOTE_ADDR'].'")');
    207       echo('Zpráva vložena!<br>Budete přesměrováni...');   
    208       echo('
    209         <script type="text/javascript" language="JavaScript" charset="utf-8">
    210             setTimeout("parent.location.href=\'index.php\'",1000)
    211         </script>');
    212     } else echo('Pro vkládaní musíte byt registrováni!');
    213   }
     216        echo('Zpráva vložena!<br/>');   
     217      } else echo('Nezadán text pro novou zprávu!<br/>');   
     218    } else echo('Pro vkládaní musíte byt registrováni!<br/>');
     219  }
     220  echo('<br/>');
     221  ShoutBoxView();
    214222}
    215223
    216224function ShoutBoxView()
    217225{
    218   global $Database, $User;
    219  
    220   $DbResult = $Database->SQLCommand('SELECT COUNT(*) FROM `ShoutBox`');
    221   $DbRow = mysql_fetch_row($DbResult);
     226  global $System, $User;
     227 
     228  $DbResult = $System->Database->query('SELECT COUNT(*) FROM `ShoutBox`');
     229  $DbRow = $DbResult->fetch_row();
    222230  $PageList = GetPageList($DbRow[0]);   
    223231
     
    226234  if($User->Licence(LICENCE_USER)) echo(' <a href="action.php?action=shoutbox">Vložit</a>');
    227235  echo('<div class="shoutbox">');
    228   $ID = $Database->SQLCommand('SELECT * FROM `ShoutBox` ORDER BY `ID` DESC '.$PageList['SQLLimit']);
    229   while($Line = mysql_fetch_assoc($ID))
     236  $DbResult = $System->Database->query('SELECT * FROM `ShoutBox` ORDER BY `ID` DESC '.$PageList['SQLLimit']);
     237  while($Line = $DbResult->fetch_assoc())
    230238    echo('<div><strong>'.$Line['User'].'</strong>: '.htmlspecialchars($Line['Text']).'</div>');
    231239  echo('</div>');
     
    235243function ShowNewsHistory()
    236244{
    237   global $Database, $User;
    238  
    239   $DbResult = $Database->SQLCommand('SELECT COUNT(*) FROM `News`');
    240   $DbRow = mysql_fetch_row($DbResult);
     245  global $System, $User;
     246 
     247  $DbResult = $System->Database->query('SELECT COUNT(*) FROM `News`');
     248  $DbRow = $DbResult->fetch_row();
    241249  $PageList = GetPageList($DbRow[0]);   
    242250
     
    245253  if($User->Licence(LICENCE_USER)) echo(' <a href="admin.php?action=addnew">Vložit</a>');
    246254  echo('<div class="shoutbox">');
    247   $ID = $Database->SQLCommand('SELECT `News`.`Time`, `News`.`Text`, `User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`ID`=`News`.`User` ORDER BY `News`.`Time` DESC '.$PageList['SQLLimit']);
    248   while($Line = mysql_fetch_assoc($ID))
     255  $dbResult = $System->Database->query('SELECT `News`.`Time`, `News`.`Text`, `User`.`Name` AS `User` FROM `News` JOIN `User` ON `User`.`ID`=`News`.`User` ORDER BY `News`.`Time` DESC '.$PageList['SQLLimit']);
     256  while($Line = $DbResult->fetch_assoc())
    249257    echo('<div><strong>'.HumanDate($Line['Time']).'</strong> '.$Line['Text'].' ('.$Line['User'].')</div>');
    250258  echo('</div>');
Note: See TracChangeset for help on using the changeset viewer.