Changeset 455 for trunk/team.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/team.php

    r411 r455  
    88function ShowTeamList()
    99
    10   global $Config, $Database, $User;
     10  global $Config, $System, $User;
    1111 
    1212  echo('<h3>Seznam překladatelských týmů</h3>');
    1313  echo('Týmy jsou seskupení překladatelů, kteří se hlásí k něčemu společnému jako např. WoW serveru, způsobu překladu, ke stejnému hernímu spolku, aj. Být členem týmu samo o sobě nemá žádný zásadní důsledek a spíše to může pomoci se lépe orientovat mezi překladateli někomu, kdo sestavuje export.<br/>');
    14   $DbResult = $Database->SQLCommand('SELECT COUNT(*) FROM `Team`');
    15   $DbRow = mysql_fetch_row($DbResult);
     14  $DbResult = $System->Database->query('SELECT COUNT(*) FROM `Team`');
     15  $DbRow = $DbResult->fetch_row();
    1616  $PageList = GetPageList($DbRow[0]);   
    1717
     
    3535    if (array_key_exists('search', $_GET) and ($_GET['search'] == '')) $_SESSION['search'] = '';
    3636
    37     $ID = $Database->SQLCommand('SELECT *, (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) AS `NumberUser`, (SELECT `Name` FROM `User` WHERE `User`.`ID`=`Team`.`Leader`) AS `LeaderName` FROM `Team` '.$_SESSION['search'].$Order['SQL'].$PageList['SQLLimit']);
    38     while($Team = mysql_fetch_assoc($ID))
     37    $DbResult = $System->Database->query('SELECT *, (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) AS `NumberUser`, (SELECT `Name` FROM `User` WHERE `User`.`ID`=`Team`.`Leader`) AS `LeaderName` FROM `Team` '.$_SESSION['search'].$Order['SQL'].$PageList['SQLLimit']);
     38    while($Team = $DbResult->fetch_assoc())
    3939    {
    4040      echo('<tr>'.
     
    6161function TeamJoin()
    6262{
    63   global $Database, $User;
     63  global $System, $User;
    6464 
    6565  if($User->Licence(LICENCE_USER))
     
    6767    if(array_key_exists('id', $_GET))
    6868    {
    69       $Database->SQLCommand('UPDATE `User` SET `Team` = '.$_GET['id'].' WHERE `ID` = '.$User->Id);
     69      $System->Database->query('UPDATE `User` SET `Team` = '.$_GET['id'].' WHERE `ID` = '.$User->Id);
    7070      echo('<strong>Vstoupil jsi do týmu</strong><br /><br />');   
    7171      WriteLog('Uživatel vstoupil do týmu '.$_GET['id'], LOG_TYPE_USER);
    7272
    7373      // Delete all teams without users
    74       $Database->SQLCommand('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0');
     74      $System->Database->query('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0');
    7575       
    7676      // Set new leader for teams where old leader went to other team
    77       $Database->SQLCommand('UPDATE `Team` SET `Leader`=(SELECT `Id` FROM `User` WHERE `User`.`Team`=`Team`.`Id` ORDER BY `User`.`RegistrationTime` LIMIT 1) WHERE `Leader` NOT IN (SELECT `ID` FROM `User` WHERE `User`.`Team`=`Team`.`Id`);');
     77      $System->Database->query('UPDATE `Team` SET `Leader`=(SELECT `Id` FROM `User` WHERE `User`.`Team`=`Team`.`Id` ORDER BY `User`.`RegistrationTime` LIMIT 1) WHERE `Leader` NOT IN (SELECT `ID` FROM `User` WHERE `User`.`Team`=`Team`.`Id`);');
    7878       
    7979      ShowTeamList();
     
    8484function TeamCreateFinish()
    8585{
    86   global $Database, $User;
     86  global $System, $User;
    8787 
    8888  if($User->Licence(LICENCE_USER))
     
    9090    if(array_key_exists('Name', $_POST) and array_key_exists('Description', $_POST))
    9191    {
    92       $DbResult = $Database->SQLCommand('SELECT COUNT(*) FROM `Team` WHERE `Name` = "'.trim($_POST['Name']).'"'); 
    93       $DbRow = mysql_fetch_row($DbResult);
     92      $DbResult = $System->Database->query('SELECT COUNT(*) FROM `Team` WHERE `Name` = "'.trim($_POST['Name']).'"'); 
     93      $DbRow = $DbResult->fetch_row();
    9494      $Count = $DbRow[0];
    9595      if(($Count == 0) and ($_POST['Name'] != ''))
    9696      {
    97         $Database->SQLCommand('INSERT INTO `Team` (`Name` ,`Description`, `URL`, `TimeCreate`,`Leader`) VALUES ("'.trim($_POST['Name']).'", "'.trim($_POST['Description']).'", "'.$_POST['URL'].'", NOW(), '.$User->Id.')'); 
    98         $Database->SQLCommand('UPDATE `User` SET `Team` = '.mysql_insert_id().' WHERE `ID` = '.$User->Id);
     97        $System->Database->query('INSERT INTO `Team` (`Name` ,`Description`, `URL`, `TimeCreate`,`Leader`) VALUES ("'.trim($_POST['Name']).'", "'.trim($_POST['Description']).'", "'.$_POST['URL'].'", NOW(), '.$User->Id.')'); 
     98        $System->Database->query('UPDATE `User` SET `Team` = '.mysql_insert_id().' WHERE `ID` = '.$User->Id);
    9999        echo('<strong>Překladatelský tým vytvořen</strong><br /><br />');
    100100        WriteLog('Překladatelský tým vytvořen '.$_POST['Name'], LOG_TYPE_USER);
    101101
    102102        // Delete all teams without users
    103         $Database->SQLCommand('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0');   
     103        $System->Database->query('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0');   
    104104      } else echo('Již existuje tým se stejným jménem');
    105105    } else echo('Chybí údaje formuláře');
     
    110110function TeamModify()
    111111{
    112   global $Database, $User;
     112  global $System, $User;
    113113 
    114114  if($User->Licence(LICENCE_USER))
     
    116116    if(array_key_exists('id', $_GET))
    117117    {
    118       $DbResult = $Database->SQLCommand('SELECT * FROM `Team` WHERE `Id`='.$_GET['id'].' AND `Leader`='.$User->Id);
    119       if(mysql_num_rows($DbResult) > 0)
    120       {
    121         $Team = mysql_fetch_assoc($DbResult);
     118      $DbResult = $System->Database->query('SELECT * FROM `Team` WHERE `Id`='.$_GET['id'].' AND `Leader`='.$User->Id);
     119      if($DbResult->num_rows > 0)
     120      {
     121        $Team = $DbResult->fetch_assoc();
    122122        echo('<form action="?action=finish_modify&amp;id='.$_GET['id'].'" method="post">'.
    123123      '<fieldset><legend>Nastavení týmu</legend>'.
     
    134134function TeamModifyFinish()
    135135{
    136   global $Database, $User;
     136  global $System, $User;
    137137 
    138138  if($User->Licence(LICENCE_USER))
     
    140140    if(array_key_exists('id', $_GET) and array_key_exists('Name', $_POST) and array_key_exists('Description', $_POST) and array_key_exists('URL', $_POST))
    141141    {
    142       $DbResult = $Database->SQLCommand('SELECT * FROM `Team` WHERE `Id`='.$_GET['id'].' AND `Leader`='.$User->Id);
    143       if(mysql_num_rows($DbResult) > 0)
    144       {
    145         $Team = mysql_fetch_assoc($DbResult);
    146         $DbResult = $Database->SQLCommand('SELECT COUNT(*) FROM `Team` WHERE `Name` = "'.trim($_POST['Name']).'"'); 
    147         $DbRow = mysql_fetch_row($DbResult);
     142      $DbResult = $System->Database->query('SELECT * FROM `Team` WHERE `Id`='.$_GET['id'].' AND `Leader`='.$User->Id);
     143      if($DbResult->num_rows > 0)
     144      {
     145        $Team = $DbResult->fetch_assoc();
     146        $DbResult = $System->Database->query('SELECT COUNT(*) FROM `Team` WHERE `Name` = "'.trim($_POST['Name']).'"'); 
     147        $DbRow = $DbResult->fetch_row();
    148148        $Count = $DbRow[0];
    149149        if(($Count == 0) and ($_POST['Name'] != ''))
    150150        {         
    151           $Database->SQLCommand('UPDATE `Team` SET `Name`="'.$_POST['Name'].'", `Description`="'.$_POST['Description'].'", `URL`="'.$_POST['URL'].'" WHERE Id='.$Team['Id']);
     151          $System->Database->query('UPDATE `Team` SET `Name`="'.$_POST['Name'].'", `Description`="'.$_POST['Description'].'", `URL`="'.$_POST['URL'].'" WHERE Id='.$Team['Id']);
    152152          echo('Nastavení týmu uloženo.<br/>');
    153153          WriteLog('Překladatelský tým upraven '.$_POST['Name'], LOG_TYPE_USER);
     
    177177function TeamShow()
    178178{
    179   global $Database, $TranslationTree, $User, $Config;
     179  global $System, $TranslationTree, $User, $Config;
    180180 
    181181  if(array_key_exists('id', $_GET) and is_numeric($_GET['id']))
     
    183183    ImgLevelUpdate();
    184184     
    185     $DbResult = $Database->SQLCommand('SELECT *, (SELECT COUNT(*) FROM `User` WHERE `Team` = `Team`.`Id`) AS `NumberUser`, (SELECT SUM(`TranslatedCount`) FROM `User` WHERE `team` = `Team`.`Id`) AS `NumberTranslate` FROM `Team` WHERE `Id`='.$_GET['id']);
    186     if(mysql_num_rows($DbResult) > 0)
    187     {
    188       $Team = mysql_fetch_assoc($DbResult);
    189       $DbResult = $Database->SQLCommand('SELECT `Name` FROM `User` WHERE `ID`='.$Team['Leader']);
    190       if(mysql_num_rows($DbResult) > 0)
    191       {
    192         $Leader = mysql_fetch_assoc($DbResult);
     185    $DbResult = $System->Database->query('SELECT *, (SELECT COUNT(*) FROM `User` WHERE `Team` = `Team`.`Id`) AS `NumberUser`, (SELECT SUM(`TranslatedCount`) FROM `User` WHERE `team` = `Team`.`Id`) AS `NumberTranslate` FROM `Team` WHERE `Id`='.$_GET['id']);
     186    if($DbResult->num_rows > 0)
     187    {
     188      $Team = $DbResult->fetch_assoc();
     189      $DbResult2 = $System->Database->query('SELECT `Name` FROM `User` WHERE `ID`='.$Team['Leader']);
     190      if($DbResult2->num_rows > 0)
     191      {
     192        $Leader = $DbResult2->fetch_assoc();
    193193        $Leader = $Leader['Name'];
    194194      } else $Leader = '';
     
    210210  $GroupListQuery = 'SELECT `Group`.* FROM `Group`';
    211211  $Query = '';
    212   $DbResult = $Database->SQLCommand($GroupListQuery);
    213   while($DbRow = mysql_fetch_assoc($DbResult))
     212  $DbResult = $System->Database->query($GroupListQuery);
     213  while($DbRow = $DbResult->fetch_assoc())
    214214  {
    215215    $Query .= 'SELECT (SELECT COUNT(DISTINCT(`Entry`)) FROM ('.
     
    224224  $Query = substr($Query, 0, - 6);
    225225
    226   $DbResult = $Database->SQLCommand('SELECT COUNT(*) FROM ('.$GroupListQuery.') AS `T`');
    227   $DbRow = mysql_fetch_row($DbResult);
     226  $DbResult = $System->Database->query('SELECT COUNT(*) FROM ('.$GroupListQuery.') AS `T`');
     227  $DbRow = $DbResult->fetch_row();
    228228  $PageList = GetPageList($DbRow[0]); 
    229229  echo($PageList['Output']);
     
    242242  $Translated = 0;
    243243  $Total = 0;
    244   $ID = $Database->SQLCommand('SELECT *, ROUND(`Translated` / `Total` * 100, 2) AS `Percent` FROM ('.$Query.') AS `C3` '.$Order['SQL'].$PageList['SQLLimit']);
    245   while($Group = mysql_fetch_assoc($ID))
     244  $DbResult = $System->Database->query('SELECT *, ROUND(`Translated` / `Total` * 100, 2) AS `Percent` FROM ('.$Query.') AS `C3` '.$Order['SQL'].$PageList['SQLLimit']);
     245  while($Group = $DbResult->fetch_assoc())
    246246  {
    247247    echo('<tr><td>'.$Group['Name'].'</td><td>'.$Group['Translated'].'</td><td>'.$Group['Total'].'</td><td>'.ProgressBar(150, $Group['Percent']).'</td></tr>');
     
    259259function TeamLeave()
    260260{
    261   global $Database, $User;
    262  
    263   if($User->Licence(LICENCE_USER))
    264   {   
    265     $Database->SQLCommand('UPDATE `User` SET `Team` = 0 WHERE `ID` = '.$User->Id);
     261  global $System, $User;
     262 
     263  if($User->Licence(LICENCE_USER))
     264  {   
     265    $System->Database->query('UPDATE `User` SET `Team` = 0 WHERE `ID` = '.$User->Id);
    266266    echo('<strong>Nyní nejste členem žádného týmu</strong><br /><br />');   
    267267    WriteLog('Uživatel vystoupil z týmu', LOG_TYPE_USER);
    268268
    269269    // Delete all teams without users
    270     $Database->SQLCommand('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0');
     270    $System->Database->query('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0');
    271271       
    272272    // Set new leader for teams where old leader went to other team
    273     $Database->SQLCommand('UPDATE `Team` SET `Leader`=(SELECT `Id` FROM `User` WHERE `User`.`Team`=`Team`.`Id` ORDER BY `User`.`RegistrationTime` LIMIT 1) WHERE `Leader` NOT IN (SELECT `ID` FROM `User` WHERE `User`.`Team`=`Team`.`Id`);');
     273    $System->Database->query('UPDATE `Team` SET `Leader`=(SELECT `Id` FROM `User` WHERE `User`.`Team`=`Team`.`Id` ORDER BY `User`.`RegistrationTime` LIMIT 1) WHERE `Leader` NOT IN (SELECT `ID` FROM `User` WHERE `User`.`Team`=`Team`.`Id`);');
    274274       
    275275    ShowTeamList();
Note: See TracChangeset for help on using the changeset viewer.