Ignore:
Timestamp:
Mar 6, 2023, 1:48:45 AM (21 months ago)
Author:
chronos
Message:
  • Fixed: Class types casting for better type checking.
  • Fixed: XML direct export.
  • Modified: User class instance moved from Core class to ModuleUser class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Export/Page.php

    r888 r893  
    1616  function ExportList()
    1717  {
     18    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    1819    $Output = '<a href="?Action=ViewList">'.T('All').'</a>';
    19     if ($this->System->User->Licence(LICENCE_USER))
     20    if ($User->Licence(LICENCE_USER))
    2021    {
    2122      $Output .= ' <a href="?Action=ViewList&amp;Filter=Others">'.T('Others').'</a>'.
     
    2324    }
    2425
    25     if ($this->System->User->Licence(LICENCE_USER))
     26    if ($User->Licence(LICENCE_USER))
    2627      $Output .= '<br/><div style="text-align: center;"><a href="?Action=Create">'.T('Create new export').'</a></div><br/>';
    2728
     
    2930    if (array_key_exists('Filter', $_GET))
    3031    {
    31       if ($_GET['Filter'] == 'My') $Filter = ' WHERE `Export`.`User` = '.$this->System->User->Id;
    32       if ($_GET['Filter'] == 'Others') $Filter = ' WHERE `Export`.`User` != '.$this->System->User->Id;
     32      if ($_GET['Filter'] == 'My') $Filter = ' WHERE `Export`.`User` = '.$User->Id;
     33      if ($_GET['Filter'] == 'Others') $Filter = ' WHERE `Export`.`User` != '.$User->Id;
    3334    }
    3435
     
    6667      $Action = '<a href="?Action=View&amp;ExportId='.$Export['Id'].'&amp;Tab=0">'.T('View').'</a> '.
    6768        '<a href="?Action=View&amp;ExportId='.$Export['Id'].'&amp;Tab=7">'.T('Make export').'</a>';
    68       if ($Export['User'] == $this->System->User->Id) $Action .= ' <a href="?Action=Delete&amp;ExportId='.$Export['Id'].'" onclick="return confirmAction(\''.T('Realy delete item?').'\');">'.T('Delete').'</a>';
    69       if ($this->System->User->Id != null) $Action .= ' <a href="?Action=Clone&amp;ExportId='.$Export['Id'].'" onclick="return confirmAction(\''.T('Realy clone item?').'\');">'.T('Clone').'</a>';
     69      if ($Export['User'] == $User->Id) $Action .= ' <a href="?Action=Delete&amp;ExportId='.$Export['Id'].'" onclick="return confirmAction(\''.T('Realy delete item?').'\');">'.T('Delete').'</a>';
     70      if ($User->Id != null) $Action .= ' <a href="?Action=Clone&amp;ExportId='.$Export['Id'].'" onclick="return confirmAction(\''.T('Realy clone item?').'\');">'.T('Clone').'</a>';
    7071      $Output .= '<tr><td>'.HumanDate($Export['TimeCreate']).'</td>'.
    7172          '<td><a href="'.$this->System->Link('/user/?user='.$Export['User']).'">'.$Export['UserName'].'</a></td>'.
     
    8485  function ExportCreate()
    8586  {
    86     if ($this->System->User->Licence(LICENCE_USER))
    87     {
    88       $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Export` WHERE `User`='.$this->System->User->Id);
     87    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
     88    if ($User->Licence(LICENCE_USER))
     89    {
     90      $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Export` WHERE `User`='.$User->Id);
    8991      $DbRow = $DbResult->fetch_row();
    90       if ($DbRow[0] < $this->System->Config['MaxExportPerUser'])
     92      if ($DbRow[0] < Core::Cast($this->System)->Config['MaxExportPerUser'])
    9193      {
    9294        $Output = '<form action="?Action=CreateFinish" method="post">'.
     
    9698            '<tr><td colspan="2"><input type="submit" value="'.T('Create').'" /></td></tr>'.
    9799            '</table></fieldset></form>';
    98       } else $Output = ShowMessage(sprintf(T('You can\'t create another export. Max for one user is %d.'), $this->System->Config['MaxExportPerUser']), MESSAGE_CRITICAL);
     100      } else $Output = ShowMessage(sprintf(T('You can\'t create another export. Max for one user is %d.'), Core::Cast($this->System)->Config['MaxExportPerUser']), MESSAGE_CRITICAL);
    99101    } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
    100102    return $Output;
     
    103105  function ExportCreateFinish()
    104106  {
    105     if ($this->System->User->Licence(LICENCE_USER))
     107    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
     108    if ($User->Licence(LICENCE_USER))
    106109    {
    107110      if (array_key_exists('Title', $_POST) and array_key_exists('Description', $_POST))
    108111      {
    109         $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Export` WHERE `User`='.$this->System->User->Id);
     112        $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Export` WHERE `User`='.$User->Id);
    110113        $DbRow = $DbResult->fetch_row();
    111         if ($DbRow[0] < $this->System->Config['MaxExportPerUser'])
     114        if ($DbRow[0] < Core::Cast($this->System)->Config['MaxExportPerUser'])
    112115        {
    113           $this->System->Database->query('INSERT INTO `Export` (`Title`, `User`, `TimeCreate`, `WithDiacritic`, `Description`) VALUES ("'.$_POST['Title'].'", '.$this->System->User->Id.', NOW(), 1, "'.$_POST['Description'].'")');
     116          $this->System->Database->query('INSERT INTO `Export` (`Title`, `User`, `TimeCreate`, `WithDiacritic`, `Description`) VALUES ("'.$_POST['Title'].'", '.$User->Id.', NOW(), 1, "'.$_POST['Description'].'")');
    114117          $ExportId = $this->System->Database->insert_id;
    115118          $Output = ShowMessage(T('New export created.<br />Direct link to export').': <a href="?Action=View&amp;ExportId='.$ExportId.'">'.T('here').'</a>');
     
    117120          $_GET['Filter'] = 'my';
    118121          $this->ExportList();
    119         } else $Output = ShowMessage(sprintf(T('You can\'t create another export. Max for one user is %d.'),$this->System->Config['MaxExportPerUser']), MESSAGE_CRITICAL);
     122        } else $Output = ShowMessage(sprintf(T('You can\'t create another export. Max for one user is %d.'), Core::Cast($this->System)->Config['MaxExportPerUser']), MESSAGE_CRITICAL);
    120123      } else $Output = ShowMessage(T('Missing data in form.'), MESSAGE_CRITICAL);
    121124    } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
     
    125128  function ExportDelete()
    126129  {
    127     if ($this->System->User->Licence(LICENCE_USER))
    128     {
    129       $DbResult = $this->System->Database->query('SELECT * FROM `Export` WHERE (`Id`='.($_GET['ExportId'] * 1).') AND (`User`='.$this->System->User->Id.')');
     130    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
     131    if ($User->Licence(LICENCE_USER))
     132    {
     133      $DbResult = $this->System->Database->query('SELECT * FROM `Export` WHERE (`Id`='.($_GET['ExportId'] * 1).') AND (`User`='.$User->Id.')');
    130134      if ($DbResult->num_rows > 0)
    131135      {
     
    157161  function ExportViewTranslators()
    158162  {
     163    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    159164    $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    160165
     
    163168    $DbResult = $this->System->Database->query('SELECT * FROM `Export` WHERE `Id`='.$_GET['ExportId']);
    164169    $Export = $DbResult->fetch_assoc();
    165     if ($this->System->User->Licence(LICENCE_USER) and ($this->System->User->Id == $Export['User'])) $Editable = true;
     170    if ($User->Licence(LICENCE_USER) and ($User->Id == $Export['User'])) $Editable = true;
    166171    else $Editable = false;
    167172
     
    273278  function ExportViewGeneral()
    274279  {
     280    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    275281    $DisabledInput = array(false => ' disabled="disabled"', true => '');
    276282    $DisabledTextArea = array(false => ' readonly="yes"', true => '');
     
    278284    $DbRows = $this->System->Database->query('SELECT * FROM `Export` WHERE `Id`='.$_GET['ExportId']);
    279285    $Export = $DbRows->fetch_assoc();
    280     if ($this->System->User->Licence(LICENCE_USER) and ($this->System->User->Id == $Export['User'])) $Editable = true;
     286    if ($User->Licence(LICENCE_USER) and ($User->Id == $Export['User'])) $Editable = true;
    281287    else $Editable = false;
    282288
     
    300306      $Output .= '<form action="?Action=View&amp;Tab=0&amp;ExportId='.$Export['Id'].'" method="post">'.
    301307          '<table>';
    302       if ($this->System->User->Id != null)
     308      if ($User->Id != null)
    303309      {
    304310        $Output .= '<input type="hidden" name="Operation" value="Save"/>'.
     
    306312        if ($Editable) $Output .= ' <input type="submit" value="'.T('Save').'" '.$DisabledInput[$Editable].'/>';
    307313        $Output .= ' <a href="?Action=Clone&amp;ExportId='.$Export['Id'].'" onclick="return confirmAction(\''.T('Realy clone item?').'\');">'.T('Clone').'</a> ';
    308         if ($this->System->User->Licence(LICENCE_ADMIN))
     314        if ($User->Licence(LICENCE_ADMIN))
    309315          $Output .= CheckBox('Featured', $Export['Featured'], '', 'CheckBox', !$Editable). ' '.T('Recommended').' ';
    310316        $Output .= '</td></tr>';
     
    319325  function ExportViewLanguages()
    320326  {
     327    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    321328    $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    322329
     
    325332    $DbRows = $this->System->Database->query('SELECT * FROM `Export` WHERE `Id`='.$_GET['ExportId']);
    326333    $Export = $DbRows->fetch_assoc();
    327     if ($this->System->User->Licence(LICENCE_USER) and ($this->System->User->Id == $Export['User'])) $Editable = true;
     334    if ($User->Licence(LICENCE_USER) and ($User->Id == $Export['User'])) $Editable = true;
    328335    else $Editable = false;
    329336
     
    410417  function ExportViewGroups()
    411418  {
     419    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    412420    $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    413421
     
    416424    $DbRows = $this->System->Database->query('SELECT * FROM Export WHERE Id='.$_GET['ExportId']);
    417425    $Export = $DbRows->fetch_assoc();
    418     if ($this->System->User->Licence(LICENCE_USER) and ($this->System->User->Id == $Export['User'])) $Editable = true;
     426    if ($User->Licence(LICENCE_USER) and ($User->Id == $Export['User'])) $Editable = true;
    419427    else $Editable = false;
    420428
     
    538546  function ExportViewOutputFormat()
    539547  {
     548    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    540549    $Output = '';
    541550    $DisabledInput = array(false => ' disabled="disabled"', true => '');
     
    546555      {
    547556        $Export = $DbRows->fetch_assoc();
    548         if ($this->System->User->Licence(LICENCE_USER) and ($this->System->User->Id == $Export['User'])) $Editable = true;
     557        if ($User->Licence(LICENCE_USER) and ($User->Id == $Export['User'])) $Editable = true;
    549558        else $Editable = false;
    550559
     
    583592  function ExportViewVersion()
    584593  {
     594    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    585595    $Output = '';
    586596    $DisabledInput = array(false => ' disabled="disabled"', true => '');
    587597    $DbRows = $this->System->Database->query('SELECT * FROM `Export` WHERE `Id`='.$_GET['ExportId']);
    588598    $Export = $DbRows->fetch_assoc();
    589     if ($this->System->User->Licence(LICENCE_USER) and ($this->System->User->Id == $Export['User'])) $Editable = true;
     599    if ($User->Licence(LICENCE_USER) and ($User->Id == $Export['User'])) $Editable = true;
    590600    else $Editable = false;
    591601
     
    697707            '(SELECT COUNT(DISTINCT(`Entry`)) FROM ('.
    698708            ' SELECT `T`.* FROM `'.$DbRow['TablePrefix'].'` AS `T`'.
    699             ' WHERE (`Language` = '.$this->System->Config['OriginalLanguage'].') AND (`VersionStart` <= '.$Export->ClientVersion['BuildNumber'].') AND (`VersionEnd` >= '.$Export->ClientVersion['BuildNumber'].')'.
     709            ' WHERE (`Language` = '.Core::Cast($this->System)->Config['OriginalLanguage'].') AND (`VersionStart` <= '.$Export->ClientVersion['BuildNumber'].') AND (`VersionEnd` >= '.$Export->ClientVersion['BuildNumber'].')'.
    700710            ') AS `C2`) AS `Total`, "'.$DbRow['Name'].'" AS `Name`';
    701711      }
     
    777787  function ExportClone()
    778788  {
    779     if ($this->System->User->Licence(LICENCE_USER))
     789    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
     790    if ($User->Licence(LICENCE_USER))
    780791    {
    781792      if (array_key_exists('ExportId', $_GET) and is_numeric($_GET['ExportId']))
    782793      {
    783         $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Export` WHERE `User`='.$this->System->User->Id);
     794        $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM `Export` WHERE `User`='.$User->Id);
    784795        $DbRow = $DbResult->fetch_row();
    785         if ($DbRow[0] < $this->System->Config['MaxExportPerUser'])
     796        if ($DbRow[0] < Core::Cast($this->System)->Config['MaxExportPerUser'])
    786797        {
    787798          $DbResult = $this->System->Database->query('SELECT * FROM `Export` WHERE `Id`='.$_GET['ExportId']);
     
    791802            unset($DbRow['Id']);
    792803            $DbRow['UsedCount'] = '0';
    793             $DbRow['User'] = $this->System->User->Id;
     804            $DbRow['User'] = $User->Id;
    794805            $DbRow['TimeCreate'] = 'NOW()';
    795806            $DbRow['Title'] .= ' - '.T('clone');
     
    807818          } else $Output = ShowMessage('Zdrojový export nenalezen', MESSAGE_CRITICAL);
    808819        } else $Output = ShowMessage(sprintf(T('You can\'t create another export. Max for one user is %d.'),
    809           $this->System->Config['MaxExportPerUser']), MESSAGE_CRITICAL);
     820        Core::Cast($this->System)->Config['MaxExportPerUser']), MESSAGE_CRITICAL);
    810821      } else $Output = ShowMessage(T('Export not found.'), MESSAGE_CRITICAL);
    811822    } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
Note: See TracChangeset for help on using the changeset viewer.