Ignore:
Timestamp:
Feb 22, 2015, 11:20:50 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Tabs converted to spaces.
  • Modified: Remove spaces from end of lines.
  • Added: Code format script.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/User/Options.php

    r787 r816  
    33class PageUserOptions extends Page
    44{
    5         function UserOptionsFrom()
    6         {
    7                 $Output = '<form action="Options.php?action=save" method="post">
    8                 <fieldset><legend>Nastavení uživatele</legend>
    9                 <table>
    10                 <tr><td>Email:</td><td><input type="text" name="Email" value="'.$this->System->User->Email.'" /></td></tr>
    11                 <tr><td>Původní heslo:</td><td><input type="password" name="OldPass" /></td></tr>
    12                 <tr><td>Nové heslo:</td><td><input type="password" name="NewPass" /></td></tr>
    13                 <tr><td>Nové heslo pro potvrzení: </td><td><input type="password" name="NewPass2" /></td></tr>
    14                 <tr><td>Normálně budu překládat do: </td><td>'.WriteLanguages($this->System->User->Language).'</td></tr>
    15                 <tr><td>Po uložení překladu přesměrovat: </td><td>';
    16                 $Output .= '<select name="redirecting">'.
    17                                 '<option value="0">Nikam</option>'.
    18                                 '<option value="1"';
    19                 if($this->System->User->Redirecting == '1') $Output .= ' selected="selected"';
    20                 $Output .= '>Na nepřeložené</option>';
    21                 $Output .= '<option value="2"';
    22                 if($this->System->User->Redirecting == '2') $Output .= ' selected="selected"';
    23                 $Output .= '>Na další překlad</option>';
    24                 $Output .= '<option value="3"';
    25                 if($this->System->User->Redirecting == '3') $Output .= ' selected="selected"';
    26                 $Output .= '>Na předchozí překlad</option>';
    27                 $Output .= '</select>';
    28        
    29                 $Output .= '</td></tr>'.
    30                                 '<tr><td>Upřednostněná verze klienta: </td><td>'.ClientVersionSelection($this->System->User->PreferredVersion).'</td></tr>'.
    31                                 '<tr><td>Veřejný text profilu:</td><td>'.
    32                                 '<textarea name="info" cols="60" rows="10">'.$this->System->User->Info.'</textarea></td></tr>';
    33        
    34        
     5  function UserOptionsFrom()
     6  {
     7    $Output = '<form action="Options.php?action=save" method="post">
     8    <fieldset><legend>Nastavení uživatele</legend>
     9    <table>
     10    <tr><td>Email:</td><td><input type="text" name="Email" value="'.$this->System->User->Email.'" /></td></tr>
     11    <tr><td>Původní heslo:</td><td><input type="password" name="OldPass" /></td></tr>
     12    <tr><td>Nové heslo:</td><td><input type="password" name="NewPass" /></td></tr>
     13    <tr><td>Nové heslo pro potvrzení: </td><td><input type="password" name="NewPass2" /></td></tr>
     14    <tr><td>Normálně budu překládat do: </td><td>'.WriteLanguages($this->System->User->Language).'</td></tr>
     15    <tr><td>Po uložení překladu přesměrovat: </td><td>';
     16    $Output .= '<select name="redirecting">'.
     17        '<option value="0">Nikam</option>'.
     18        '<option value="1"';
     19    if($this->System->User->Redirecting == '1') $Output .= ' selected="selected"';
     20    $Output .= '>Na nepřeložené</option>';
     21    $Output .= '<option value="2"';
     22    if($this->System->User->Redirecting == '2') $Output .= ' selected="selected"';
     23    $Output .= '>Na další překlad</option>';
     24    $Output .= '<option value="3"';
     25    if($this->System->User->Redirecting == '3') $Output .= ' selected="selected"';
     26    $Output .= '>Na předchozí překlad</option>';
     27    $Output .= '</select>';
     28
     29    $Output .= '</td></tr>'.
     30        '<tr><td>Upřednostněná verze klienta: </td><td>'.ClientVersionSelection($this->System->User->PreferredVersion).'</td></tr>'.
     31        '<tr><td>Veřejný text profilu:</td><td>'.
     32        '<textarea name="info" cols="60" rows="10">'.$this->System->User->Info.'</textarea></td></tr>';
     33
     34
    3535    $Output .= '<tr><td>';
    36                 $Query = 'SELECT * FROM UserTagType';
    37                 $DbResult = $this->Database->query($Query);
     36    $Query = 'SELECT * FROM UserTagType';
     37    $DbResult = $this->Database->query($Query);
    3838    $Output .= 'Překladatel se řídí zaškrtnutými pravidly:</td><td>';
    39     while ($UserTag = $DbResult->fetch_array()) { 
    40                  $Query = 'SELECT * FROM `UserTag` '.
     39    while ($UserTag = $DbResult->fetch_array()) {
     40     $Query = 'SELECT * FROM `UserTag` '.
    4141     //'LEFT JOIN `UserTagType` ON `UserTagType`.`ID` = `UserTag`.`UserTagType` '.
    4242     'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
    43                   $DbResult2 = $this->Database->query($Query);
     43      $DbResult2 = $this->Database->query($Query);
    4444      if ($DbResult2->num_rows != 0) $checked = true;
    45       else  $checked = false; 
    46      
    47       $Output .= CheckBox('Tag'.$UserTag['ID'], $checked, 'CheckBox');   
     45      else  $checked = false;
     46
     47      $Output .= CheckBox('Tag'.$UserTag['ID'], $checked, 'CheckBox');
    4848      $Output .= ''.$UserTag['Text'].'<br />';
    4949    }
    5050    $Output .= '</td></tr>';
    51    
    52                 $Output .= '<tr><td colspan="2"><input type="submit" value="Uložit" /></td></tr>'.
    53                                 '</table></fieldset>'.
    54                                 '</form>';
    55        
    56                 $Output .= '  <fieldset><legend>Překladatelský tým</legend>';
    57                 $DbResult = $this->Database->query('SELECT `Id`, `Name` FROM `Team`');
    58                 $Output .= '<a href="team/?action=create">Vytvořit tým</a><br />'.
    59                                 '<a href="team/?action=leave">Opustit tým</a><br />'.
    60                                 '<br /><form action="team/" method="get">'.
    61                                 '<input type="hidden" name="action" value="gointeam"/>'.
    62                                 '<select name="id">';
    63                 while($LineTeam = $DbResult->fetch_assoc())
    64                 {
    65                         $Output .= '<option value="'.$LineTeam['Id'].'"';
    66                         if ($LineTeam['Id'] == $this->System->User->Team) $Output .= ' selected="selected"';
    67                         $Output .= '>'.$LineTeam['Name'].'</option>';
    68                 }
    69                 $Output .= '</select> <input type="submit" value="Vstoupit" />
    70                 </form>';
    71                 $Output .= '</fieldset>';
    72                 return($Output);
    73         }
    74        
    75         function UserOptionsSave()
    76         {
    77                 $Output = '';
    78                 if(array_key_exists('Email', $_POST))
    79                 {
    80                         $Email = $_POST['Email'];
    81                         $OldPass = $_POST['OldPass'];
    82                         $NewPass = $_POST['NewPass'];
    83                         $NewPass2 = $_POST['NewPass2'];
    84                         $Language = $_POST['Language'];
    85                         $Redirecting = $_POST['redirecting'];
    86                         $PreferredVersion = $_POST['ClientVersion'];
    87                         if($PreferredVersion == '') $PreferredVersion = null;
    88                         $Info = $_POST['info'];
    89        
    90                         // Do user want to change password?
    91                         if(($OldPass != '') or ($NewPass != '') or ($NewPass2 != ''))
    92                         {
    93                                 if($NewPass == $NewPass2)
    94                                 {
    95                                         $DbResult = $this->System->Database->query('SELECT `Pass`, '.$this->System->User->CryptPasswordSQL('"'.$OldPass.'"', '`Salt`').' AS `Hash` FROM `User` WHERE `ID`= '.$this->System->User->Id);
    96                                         $DbRow = $DbResult->fetch_assoc();
    97                                         if($DbRow['Hash'] == $DbRow['Pass'])
    98                                         {
    99                                                 // Update password
    100                                                 $Salt = $this->System->User->GetPasswordSalt();
    101                                                 $this->Database->query('UPDATE `User` SET `Pass` = '.$this->System->User->CryptPasswordSQL('"'.$NewPass.'"', '"'.$Salt.'"').', `Salt`="'.$Salt.'" WHERE `ID` = '.$this->System->User->Id);
    102                                                 $Output .= ShowMessage('Heslo změněno.');
    103                                         } else $Output .= ShowMessage('Staré heslo neodpovídá.', MESSAGE_CRITICAL);
    104                                 } else $Output .= ShowMessage('Hesla se neshodují.', MESSAGE_CRITICAL);
    105                         }
     51
     52    $Output .= '<tr><td colspan="2"><input type="submit" value="Uložit" /></td></tr>'.
     53        '</table></fieldset>'.
     54        '</form>';
     55
     56    $Output .= '  <fieldset><legend>Překladatelský tým</legend>';
     57    $DbResult = $this->Database->query('SELECT `Id`, `Name` FROM `Team`');
     58    $Output .= '<a href="team/?action=create">Vytvořit tým</a><br />'.
     59        '<a href="team/?action=leave">Opustit tým</a><br />'.
     60        '<br /><form action="team/" method="get">'.
     61        '<input type="hidden" name="action" value="gointeam"/>'.
     62        '<select name="id">';
     63    while($LineTeam = $DbResult->fetch_assoc())
     64    {
     65      $Output .= '<option value="'.$LineTeam['Id'].'"';
     66      if ($LineTeam['Id'] == $this->System->User->Team) $Output .= ' selected="selected"';
     67      $Output .= '>'.$LineTeam['Name'].'</option>';
     68    }
     69    $Output .= '</select> <input type="submit" value="Vstoupit" />
     70    </form>';
     71    $Output .= '</fieldset>';
     72    return($Output);
     73  }
     74
     75  function UserOptionsSave()
     76  {
     77    $Output = '';
     78    if(array_key_exists('Email', $_POST))
     79    {
     80      $Email = $_POST['Email'];
     81      $OldPass = $_POST['OldPass'];
     82      $NewPass = $_POST['NewPass'];
     83      $NewPass2 = $_POST['NewPass2'];
     84      $Language = $_POST['Language'];
     85      $Redirecting = $_POST['redirecting'];
     86      $PreferredVersion = $_POST['ClientVersion'];
     87      if($PreferredVersion == '') $PreferredVersion = null;
     88      $Info = $_POST['info'];
     89
     90      // Do user want to change password?
     91      if(($OldPass != '') or ($NewPass != '') or ($NewPass2 != ''))
     92      {
     93        if($NewPass == $NewPass2)
     94        {
     95          $DbResult = $this->System->Database->query('SELECT `Pass`, '.$this->System->User->CryptPasswordSQL('"'.$OldPass.'"', '`Salt`').' AS `Hash` FROM `User` WHERE `ID`= '.$this->System->User->Id);
     96          $DbRow = $DbResult->fetch_assoc();
     97          if($DbRow['Hash'] == $DbRow['Pass'])
     98          {
     99            // Update password
     100            $Salt = $this->System->User->GetPasswordSalt();
     101            $this->Database->query('UPDATE `User` SET `Pass` = '.$this->System->User->CryptPasswordSQL('"'.$NewPass.'"', '"'.$Salt.'"').', `Salt`="'.$Salt.'" WHERE `ID` = '.$this->System->User->Id);
     102            $Output .= ShowMessage('Heslo změněno.');
     103          } else $Output .= ShowMessage('Staré heslo neodpovídá.', MESSAGE_CRITICAL);
     104        } else $Output .= ShowMessage('Hesla se neshodují.', MESSAGE_CRITICAL);
     105      }
    106106      //tag
    107                 $Query = 'SELECT * FROM UserTagType';
    108                 $DbResult = $this->Database->query($Query);
    109       while ($UserTag = $DbResult->fetch_array()) { 
     107      $Query = 'SELECT * FROM UserTagType';
     108      $DbResult = $this->Database->query($Query);
     109      while ($UserTag = $DbResult->fetch_array()) {
    110110       if (array_key_exists('Tag'.$UserTag['ID'], $_POST)) {
    111                    $Query = 'SELECT * FROM `UserTag` '.
     111         $Query = 'SELECT * FROM `UserTag` '.
    112112         'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
    113                 $DbResult2 = $this->Database->query($Query);
     113        $DbResult2 = $this->Database->query($Query);
    114114         if ($DbResult2->num_rows == 0) {
    115                    $Query = 'INSERT INTO `UserTag` (`ID` ,`UserTagType`,`User` ) '.
     115           $Query = 'INSERT INTO `UserTag` (`ID` ,`UserTagType`,`User` ) '.
    116116           'VALUES (NULL, '.$UserTag['ID'].' , '.($this->System->User->Id * 1).')';
    117                 $DbResult2 = $this->Database->query($Query);
     117          $DbResult2 = $this->Database->query($Query);
    118118         }
    119119       } else {
    120                    $Query = 'DELETE FROM `UserTag` '.
     120         $Query = 'DELETE FROM `UserTag` '.
    121121         'WHERE `UserTagType` = '.$UserTag['ID'].' AND `User` = '.($this->System->User->Id * 1);
    122                      $DbResult2 = $this->Database->query($Query);
     122         $DbResult2 = $this->Database->query($Query);
    123123       }
    124124      }
    125      
    126                         $this->Database->update('User', '`ID` = '.$this->System->User->Id, array('Email' => $Email,
    127                           'Language' => $Language, 'Redirecting' => $Redirecting, 'Info' => $Info,
    128                           'PreferredVersion' => $PreferredVersion));
    129                         $Output .= ShowMessage('Úprava nastavení proběhla v pořádku, Email: <b>'.$Email.'</b> Uživatel: <b>'.$this->System->User->Name.'</b>');
    130                         $this->System->ModuleManager->Modules['Log']->WriteLog('Úprava nastavení!', LOG_TYPE_USER);
    131                         $this->System->User->Load();
    132                 } else $Output .= ShowMessage('Nezadány údaje.', MESSAGE_CRITICAL);
    133                 return($Output);
    134         }
    135        
    136         function Show()
    137         {
    138                 $this->Title = T('User settings');
    139                 $Output = '';
    140                 if($this->System->User->Licence(LICENCE_USER))
    141                 {
    142                         if(array_key_exists('action', $_GET) and ($_GET['action'] == 'save'))
    143                         {
    144                                 $Output .= $this->UserOptionsSave();
    145                         }
    146                         $Output .= $this->UserOptionsFrom();
    147                 } else $Output .= ShowMessage('Nejste přihlášený.', MESSAGE_CRITICAL);
    148                 return($Output);
    149         }       
    150 }   
     125
     126      $this->Database->update('User', '`ID` = '.$this->System->User->Id, array('Email' => $Email,
     127        'Language' => $Language, 'Redirecting' => $Redirecting, 'Info' => $Info,
     128        'PreferredVersion' => $PreferredVersion));
     129      $Output .= ShowMessage('Úprava nastavení proběhla v pořádku, Email: <b>'.$Email.'</b> Uživatel: <b>'.$this->System->User->Name.'</b>');
     130      $this->System->ModuleManager->Modules['Log']->WriteLog('Úprava nastavení!', LOG_TYPE_USER);
     131      $this->System->User->Load();
     132    } else $Output .= ShowMessage('Nezadány údaje.', MESSAGE_CRITICAL);
     133    return($Output);
     134  }
     135
     136  function Show()
     137  {
     138    $this->Title = T('User settings');
     139    $Output = '';
     140    if($this->System->User->Licence(LICENCE_USER))
     141    {
     142      if(array_key_exists('action', $_GET) and ($_GET['action'] == 'save'))
     143      {
     144        $Output .= $this->UserOptionsSave();
     145      }
     146      $Output .= $this->UserOptionsFrom();
     147    } else $Output .= ShowMessage('Nejste přihlášený.', MESSAGE_CRITICAL);
     148    return($Output);
     149  }
     150}
Note: See TracChangeset for help on using the changeset viewer.