Ignore:
Timestamp:
Jun 18, 2013, 7:23:39 PM (11 years ago)
Author:
chronos
Message:
  • Upraveno: Slovníček přepracován na aplikační modul.
  • Upraveno: Do hlavní levé nabídky mohou nyní moduly přidávat nové položky.
Location:
trunk/Modules/Dictionary
Files:
1 added
1 moved

Legend:

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

    r546 r548  
    11<?php
    22
    3 include('includes/global.php');
     3class ModuleDictionary extends AppModule
     4{
     5  function __construct($System)
     6  {
     7    parent::__construct($System);
     8    $this->Name = 'Dictionary';
     9    $this->Version = '1.0';
     10    $this->Creator = 'Chronos';
     11    $this->License = 'GNU/GPL';
     12    $this->Description = 'Custom dictionary for better translation coordination';
     13    $this->Dependencies = array();
     14  }
     15 
     16  function Start()
     17  {
     18        $this->System->RegisterPage('dictionary.php', 'PageDictionary');
     19        $this->System->RegisterMenuItem(array(
     20        'Title' => 'Slovníček',
     21        'Hint' => 'Slovník WoW výrazů',
     22        'Link' => $this->System->Link('/dictionary.php'),
     23        'Permission' => LICENCE_ANONYMOUS,
     24        'Icon' => '',
     25    ));
     26  }
     27}
     28
     29class PageDictionary extends Page
     30{
    431
    532function WriteTranslatNames($Text,$mode)
     
    4673}
    4774
    48 $LanguageList = GetLanguageList();
    49 
    50 if(!isset($_SESSION['language']))
    51 {
    52         if($User->Licence(LICENCE_USER))
    53         {
    54                 $_SESSION['language'] = $User->Language;
    55   } else $_SESSION['language'] = '';
    56 }
    57 if(array_key_exists('language', $_GET)) {
    58   if($_GET['language'] == '') $_SESSION['language'] = '';
    59           else $_SESSION['language'] = $_GET['language'] * 1;
    60 }
    61 
    62 $Output = '<h3>Slovníček</h3>';
    63 
    6475function DictionaryInsert()
    6576{
    66   global $System, $User;
     77  global $User;
    6778 
    6879  $Output = '';
     
    8697function DictionarySave()
    8798{
    88   global $System, $User, $Config;
     99  global $User, $Config;
    89100 
    90101  if($User->Licence(LICENCE_USER))
     
    93104    {
    94105      // Check if original text exists and determine entry id
    95       $DbResult = $System->Database->query('SELECT * FROM `Dictionary` WHERE '.
     106      $DbResult = $this->Database->query('SELECT * FROM `Dictionary` WHERE '.
    96107        '`Text` = "'.$_POST['Original'].'" AND `Language`= '.$Config['OriginalLanguage']);
    97108      if($DbResult->num_rows > 0)
     
    101112      } else
    102113      {
    103         $DbResult = $System->Database->query('SELECT MAX(`Entry`) FROM `Dictionary`');
     114        $DbResult = $this->Database->query('SELECT MAX(`Entry`) FROM `Dictionary`');
    104115        $DbRow = $DbResult->fetch_row();
    105116        $Entry = $DbRow[0] + 1;
    106         $System->Database->query('INSERT INTO `Dictionary` ( `Text` , `Entry` , `Description` , '.
     117        $this->Database->query('INSERT INTO `Dictionary` ( `Text` , `Entry` , `Description` , '.
    107118          '`User`, `Language` ) VALUES ("'.$_POST['Original'].'", "'.$Entry.'", "", NULL, '.$Config['OriginalLanguage'].');');
    108119      }
    109120 
    110       $DbResult = $System->Database->query('SELECT `Id` FROM `Dictionary` WHERE '.
     121      $DbResult = $this->Database->query('SELECT `Id` FROM `Dictionary` WHERE '.
    111122        '`Entry` = '.$Entry.' AND `Language`='.$_POST['Language'].' AND `User`='.$User->Id);
    112123      if($DbResult->num_rows > 0)
    113124      {
    114125        $DbRow = $DbResult->fetch_assoc();
    115         $System->Database->query('UPDATE `Dictionary` SET `Text`="'.$_POST['Translated'].'", '.
     126        $this->Database->query('UPDATE `Dictionary` SET `Text`="'.$_POST['Translated'].'", '.
    116127          '`Description` = "'.$_POST['Description'].'" WHERE Id='.$DbRow['Id']);
    117128      } else
    118         $System->Database->query('INSERT INTO `Dictionary` ( `Text` , `Entry` , `Description` , '.
     129        $this->Database->query('INSERT INTO `Dictionary` ( `Text` , `Entry` , `Description` , '.
    119130          '`User`, `Language` ) VALUES ("'.$_POST['Translated'].'", "'.$Entry.'", "'.$_POST['Description'].'", '.$User->Id.', '.$_POST['Language'].')');
    120131      $Output = ShowMessage('Záznam byl uložen!');
     
    126137function DictionaryRemove()
    127138{
    128   global $System, $User;
     139  global $User;
    129140 
    130141  if($User->Licence(LICENCE_USER))
    131142  {
    132     $System->Database->query('DELETE FROM `Dictionary` WHERE (`User`='.$User->Id.') AND (`Id`='.($_GET['id'] * 1).')');
     143    $this->Database->query('DELETE FROM `Dictionary` WHERE (`User`='.$User->Id.') AND (`Id`='.($_GET['id'] * 1).')');
    133144    $Output = ShowMessage('Záznam odstraněn.');
    134145  } else $Output = ShowMessage('Nemáte oprávnění', MESSAGE_CRITICAL);
     
    138149function DictionaryModify()
    139150{
    140   global $System, $User, $Config;
     151  global $User, $Config;
    141152 
    142153  if($User->Licence(LICENCE_USER))
    143154  {
    144     $DbResult = $System->Database->query('SELECT * FROM `Dictionary` WHERE `Id`='.($_GET['id'] * 1));
     155    $DbResult = $this->Database->query('SELECT * FROM `Dictionary` WHERE `Id`='.($_GET['id'] * 1));
    145156    if($DbResult->num_rows > 0)
    146157    {
    147158      $DbRow = $DbResult->fetch_assoc();
    148       $DbResult = $System->Database->query('SELECT * FROM `Dictionary` WHERE (`User` IS NULL) '.
     159      $DbResult = $this->Database->query('SELECT * FROM `Dictionary` WHERE (`User` IS NULL) '.
    149160        'AND (`Entry`='.$DbRow['Entry'].') AND (`Language`= '.$Config['OriginalLanguage'].')');
    150161      $DbRow2 = $DbResult->fetch_assoc();
     
    168179function DictionaryGroup()
    169180{
    170   global $System, $User, $TranslationTree;
     181  global $User, $TranslationTree;
    171182 
    172183  $Output = '';
     
    183194        '<a href="?action=group&amp;mode=0&amp;group='.$GroupId.'&amp;ID='.$TextID.'" title="Zobrazit pouze přesné výsledky">Přesné</a> '.
    184195        '<a href="?action=group&amp;mode=2&amp;group='.$GroupId.'&amp;ID='.$TextID.'" title="Zobrazit všechny nepřeložené">Nepřeložené</a> ';
    185     $DbResult = $System->Database->query('SELECT * FROM '.$Table.' WHERE ID = '.$TextID);
     196    $DbResult = $this->Database->query('SELECT * FROM '.$Table.' WHERE ID = '.$TextID);
    186197    $Line = $DbResult->fetch_assoc();
    187198    if(!$Line) $Output .= ShowMessage('Překlad nenalezen.', MESSAGE_CRITICAL);
     
    199210function DictionaryShow()
    200211{
    201   global $System, $User, $LanguageList, $Config;
     212  global $User, $LanguageList, $Config;
    202213 
    203214  $Output = '<form action="dictionary.php" method="get" style="margin: 0px; padding: 0px;">'.
     
    246257      $LanguageFilter.$Condition;
    247258 
    248   $DbResult = $System->Database->query('SELECT COUNT(*) FROM ('.$sql.') AS `T1`');
     259  $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$sql.') AS `T1`');
    249260  $DbRow = $DbResult->fetch_row();
    250261  $PageList = GetPageList($DbRow[0]); 
     
    266277
    267278  $sql_page = $sql.$Order['SQL'].$PageList['SQLLimit'];
    268   $DbResult = $System->Database->query($sql_page);
     279  $DbResult = $this->Database->query($sql_page);
    269280  while($Line = $DbResult->fetch_assoc())
    270281  {
     
    291302}
    292303
    293 $Output = '';
     304function Show()
     305{
     306        global $LanguageList;
     307       
     308$LanguageList = GetLanguageList();
     309
     310if(!isset($_SESSION['language']))
     311{
     312        if($User->Licence(LICENCE_USER))
     313        {
     314                $_SESSION['language'] = $User->Language;
     315  } else $_SESSION['language'] = '';
     316}
     317if(array_key_exists('language', $_GET)) {
     318  if($_GET['language'] == '') $_SESSION['language'] = '';
     319          else $_SESSION['language'] = $_GET['language'] * 1;
     320}
     321
     322$Output = '<h3>Slovníček</h3>';
     323
    294324$ShowList = true;
    295325if(array_key_exists('action', $_GET))
    296326{
    297327  if($_GET['action'] == 'group') {
    298     $Output .= DictionaryGroup();
     328    $Output .= $this->DictionaryGroup();
    299329    $ShowList = false;
    300330  }
    301   else if($_GET['action'] == 'insert') $Output .= DictionaryInsert();
    302   else if($_GET['action'] == 'save') $Output .= DictionarySave();
    303   else if($_GET['action'] == 'remove') $Output .= DictionaryRemove();
    304   else if($_GET['action'] == 'modify') $Output .= DictionaryModify();
     331  else if($_GET['action'] == 'insert') $Output .= $this->DictionaryInsert();
     332  else if($_GET['action'] == 'save') $Output .= $this->DictionarySave();
     333  else if($_GET['action'] == 'remove') $Output .= $this->DictionaryRemove();
     334  else if($_GET['action'] == 'modify') $Output .= $this->DictionaryModify();
    305335  else $Output .= ShowMessage('Neznámá akce', MESSAGE_CRITICAL); 
    306336}
    307 if($ShowList == true) $Output .= DictionaryShow();
    308 
    309 ShowPage($Output);
    310 
    311 ?>
     337if($ShowList == true) $Output .= $this->DictionaryShow();
     338    return($Output);
     339  }
     340}
Note: See TracChangeset for help on using the changeset viewer.