plugins/SpecialUserPrefs.php
changeset 770 62fed244fa1c
parent 741 a216e412c439
child 801 eb8b23f11744
equal deleted inserted replaced
769:1946d845bb25 770:62fed244fa1c
   153 function page_Special_Preferences()
   153 function page_Special_Preferences()
   154 {
   154 {
   155   global $db, $session, $paths, $template, $plugins; // Common objects
   155   global $db, $session, $paths, $template, $plugins; // Common objects
   156   global $lang;
   156   global $lang;
   157   global $timezone;
   157   global $timezone;
       
   158   global $cache;
   158   
   159   
   159   // We need a login to continue
   160   // We need a login to continue
   160   if ( !$session->user_logged_in )
   161   if ( !$session->user_logged_in )
   161     redirect(makeUrlNS('Special', 'Login/' . $paths->page), 'Login required', 'You need to be logged in to access this page. Please wait while you are redirected to the login page.');
   162     redirect(makeUrlNS('Special', 'Login/' . $paths->page), 'Login required', 'You need to be logged in to access this page. Please wait while you are redirected to the login page.');
   162   
   163   
   466       echo $template->tinymce_textarea('new_sig', htmlspecialchars($session->signature));
   467       echo $template->tinymce_textarea('new_sig', htmlspecialchars($session->signature));
   467       echo '<input type="submit" value="' . $lang->get('usercp_signature_btn_save') . '" />';
   468       echo '<input type="submit" value="' . $lang->get('usercp_signature_btn_save') . '" />';
   468       echo '</form>';
   469       echo '</form>';
   469       break;
   470       break;
   470     case "Profile":
   471     case "Profile":
       
   472       $available_ranks = $session->get_user_possible_ranks($session->user_id);
       
   473       $current_rank = $session->get_user_rank($session->user_id);
       
   474       
   471       if ( isset($_POST['submit']) )
   475       if ( isset($_POST['submit']) )
   472       {
   476       {
   473         $real_name = htmlspecialchars($_POST['real_name']);
   477         $real_name = htmlspecialchars($_POST['real_name']);
   474         $real_name = $db->escape($real_name);
   478         $real_name = $db->escape($real_name);
   475         
   479         
   476         $timezone = intval($_POST['timezone']);
   480         $timezone = intval($_POST['timezone']);
   477         $tz_local = $timezone + 1440;
   481         $tz_local = $timezone + 1440;
       
   482         
       
   483         $dst = $db->escape($_POST['dst']);
       
   484         if ( !preg_match('/^[0-9]+;[0-9]+;[0-9]+;[0-9]+;[0-9]+$/', $dst) )
       
   485           $dst = '0;0;0;0;60';
       
   486         
       
   487         $GLOBALS['dst_params'] = explode(';', $dst);
   478         
   488         
   479         $imaddr_aim = htmlspecialchars($_POST['imaddr_aim']);
   489         $imaddr_aim = htmlspecialchars($_POST['imaddr_aim']);
   480         $imaddr_aim = $db->escape($imaddr_aim);
   490         $imaddr_aim = $db->escape($imaddr_aim);
   481         
   491         
   482         $imaddr_msn = htmlspecialchars($_POST['imaddr_msn']);
   492         $imaddr_msn = htmlspecialchars($_POST['imaddr_msn']);
   545             $colval = "'" . $db->escape($user_title) . "'";
   555             $colval = "'" . $db->escape($user_title) . "'";
   546             $session->user_title = $user_title;
   556             $session->user_title = $user_title;
   547           }
   557           }
   548           $user_title_col = ", user_title = $colval";
   558           $user_title_col = ", user_title = $colval";
   549         }
   559         }
   550         
   560         $user_rank_col = '';
   551         $q = $db->sql_query('UPDATE '.table_prefix."users SET real_name='$real_name', user_timezone = $tz_local{$user_title_col} WHERE user_id=$session->user_id;");
   561         if ( intval($_POST['user_rank']) != $current_rank['rank_id'] && count($available_ranks) > 1 )
       
   562         {
       
   563           if ( $_POST['user_rank'] == 'NULL' )
       
   564           {
       
   565             $user_rank_col = ", user_rank = NULL, user_rank_userset = 0";
       
   566           }
       
   567           else
       
   568           {
       
   569             $new_rank = intval($_POST['user_rank']);
       
   570             $rank_allowed = false;
       
   571             foreach ( $available_ranks as $rank )
       
   572             {
       
   573               if ( $rank['rank_id'] == $new_rank )
       
   574               {
       
   575                 $rank_allowed = true;
       
   576                 break;
       
   577               }
       
   578             }
       
   579             if ( $rank_allowed )
       
   580             {
       
   581               $user_rank_col = ", user_rank = $new_rank, user_rank_userset = 1";
       
   582               // hack
       
   583               $current_rank['rank_id'] = $new_rank;
       
   584               $cache->purge('ranks');
       
   585             }
       
   586           }
       
   587         }
       
   588         
       
   589         $q = $db->sql_query('UPDATE '.table_prefix."users SET real_name='$real_name', user_timezone = {$tz_local}, user_dst = '$dst'{$user_title_col}{$user_rank_col} WHERE user_id=$session->user_id;");
   552         if ( !$q )
   590         if ( !$q )
   553           $db->_die();
   591           $db->_die();
   554         
   592         
   555         $q = $db->sql_query('UPDATE '.table_prefix."users_extra SET user_aim='$imaddr_aim',user_yahoo='$imaddr_yahoo',user_msn='$imaddr_msn',
   593         $q = $db->sql_query('UPDATE '.table_prefix."users_extra SET user_aim='$imaddr_aim',user_yahoo='$imaddr_yahoo',user_msn='$imaddr_msn',
   556                                user_xmpp='$imaddr_xmpp',user_homepage='$homepage',user_location='$location',user_job='$occupation',
   594                                user_xmpp='$imaddr_xmpp',user_homepage='$homepage',user_location='$location',user_job='$occupation',
   569         if ( $db->numrows() > 0 )
   607         if ( $db->numrows() > 0 )
   570         {
   608         {
   571           $db->free_result();
   609           $db->free_result();
   572           
   610           
   573           // unload / reload $lang, this verifies that the selected language works
   611           // unload / reload $lang, this verifies that the selected language works
       
   612           // enano should die a violent death if the language fails to load
   574           unset($GLOBALS['lang']);
   613           unset($GLOBALS['lang']);
   575           unset($lang);
   614           unset($lang);
   576           $lang_id = intval($lang_id);
   615           $lang_id = intval($lang_id);
   577           $GLOBALS['lang'] = new Language($lang_id);
   616           $GLOBALS['lang'] = new Language($lang_id);
   578           global $lang;
   617           global $lang;
   678               </td>
   717               </td>
   679               <td class="row1">
   718               <td class="row1">
   680                 <input type="text" name="user_title" value="<?php echo htmlspecialchars($session->user_title); ?>" />
   719                 <input type="text" name="user_title" value="<?php echo htmlspecialchars($session->user_title); ?>" />
   681               </td>
   720               </td>
   682             </tr>
   721             </tr>
       
   722           <?php
       
   723           endif;
       
   724           if ( count($available_ranks) > 1 ):
       
   725           ?>
       
   726           <tr>
       
   727             <td class="row2">
       
   728               <?php echo $lang->get('usercp_publicinfo_field_rank_title'); ?><br />
       
   729               <small><?php echo $lang->get('usercp_publicinfo_field_rank_hint'); ?></small>
       
   730             </td>
       
   731             <td class="row1">
       
   732               <select name="user_rank">
       
   733                 <?php
       
   734                 foreach ( $available_ranks as $rank )
       
   735                 {
       
   736                   $sel = ( $rank['rank_id'] == $current_rank['rank_id'] ) ? ' selected="selected"' : '';
       
   737                   echo '<option' . $sel . ' value="' . $rank['rank_id'] . '" style="' . htmlspecialchars($rank['rank_style']) . '">';
       
   738                   echo htmlspecialchars($lang->get($rank['rank_title']));
       
   739                   echo '</option>';
       
   740                 }
       
   741                 ?>
       
   742               </select>
       
   743             </td>
       
   744           </tr>
   683           <?php
   745           <?php
   684           endif;
   746           endif;
   685           ?>
   747           ?>
   686           <tr>
   748           <tr>
   687             <th class="subhead" colspan="2">
   749             <th class="subhead" colspan="2">