Dotclear


Ignore:
Timestamp:
07/13/11 15:21:44 (13 years ago)
Author:
Franck <carnet.franck.paul@…>
Branch:
default
Message:

Contrôle du nombre de favoris sélectionnés avant traitement -> message si sélection vide.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin/preferences.php

    r536 r590  
    4444$default_tab = !empty($_GET['tab']) ? html::escapeHTML($_GET['tab']) : 'user-profile'; 
    4545 
    46 if (!empty($_GET['append']) || !empty($_GET['removed']) || !empty($_GET['neworder']) || !empty($_GET['replaced'])) { 
     46if (!empty($_GET['append']) || !empty($_GET['removed']) || !empty($_GET['neworder']) ||  
     47     !empty($_GET['replaced']) || !empty($_POST['appendaction']) || !empty($_POST['removeaction'])) { 
    4748     $default_tab = 'user-favorites'; 
    4849} elseif (!empty($_GET['updated'])) { 
     
    122123 
    123124# Update user options 
    124 if (isset($_POST['user_post_format'])) { 
     125if (isset($_POST['user_post_format']))  
     126{ 
    125127     try 
    126128     { 
     
    175177 
    176178# Add selected favorites 
    177 if (!empty($_POST['appendaction']) && !empty($_POST['append'])) { 
    178      $ws = $core->auth->user_prefs->addWorkspace('favorites'); 
    179      $user_favs = $ws->DumpLocalPrefs(); 
    180      $count = count($user_favs); 
    181      foreach ($_POST['append'] as $k => $v) 
    182      { 
     179if (!empty($_POST['appendaction']))  
     180{ 
     181     try { 
     182          if (empty($_POST['append'])) { 
     183               throw new Exception(__('No favorite selected')); 
     184          } 
     185 
     186          $ws = $core->auth->user_prefs->addWorkspace('favorites'); 
     187          $user_favs = $ws->DumpLocalPrefs(); 
     188          $count = count($user_favs); 
     189          foreach ($_POST['append'] as $k => $v) 
     190          { 
     191               try { 
     192                    $found = false; 
     193                    foreach ($user_favs as $f) { 
     194                         $f = unserialize($f['value']); 
     195                         if ($f['name'] == $v) { 
     196                              $found = true; 
     197                              break; 
     198                         } 
     199                    } 
     200                    if (!$found) { 
     201                         $uid = sprintf("u%03s",$count); 
     202                         $fav = array('name' => $_fav[$v][0],'title' => $_fav[$v][1],'url' => $_fav[$v][2],'small-icon' => $_fav[$v][3], 
     203                              'large-icon' => $_fav[$v][4],'permissions' => $_fav[$v][5],'id' => $_fav[$v][6],'class' => $_fav[$v][7]); 
     204                         $core->auth->user_prefs->favorites->put($uid,serialize($fav),'string'); 
     205                         $count++; 
     206                    } 
     207               } catch (Exception $e) { 
     208                    $core->error->add($e->getMessage()); 
     209                    break; 
     210               } 
     211          } 
     212      
     213          if (!$core->error->flag()) { 
     214               http::redirect('preferences.php?append=1'); 
     215          } 
     216     } catch (Exception $e) { 
     217          $core->error->add($e->getMessage()); 
     218     } 
     219} 
     220 
     221# Delete selected favorites 
     222if (!empty($_POST['removeaction'])) 
     223{ 
     224     try { 
     225          if (empty($_POST['remove'])) { 
     226               throw new Exception(__('No favorite selected')); 
     227          } 
     228           
     229          $ws = $core->auth->user_prefs->addWorkspace('favorites'); 
     230          foreach ($_POST['remove'] as $k => $v) 
     231          { 
     232               try { 
     233                    $core->auth->user_prefs->favorites->drop($v); 
     234               } catch (Exception $e) { 
     235                    $core->error->add($e->getMessage()); 
     236                    break; 
     237               } 
     238          } 
     239          // Update pref_id values 
    183240          try { 
    184                $found = false; 
    185                foreach ($user_favs as $f) { 
    186                     $f = unserialize($f['value']); 
    187                     if ($f['name'] == $v) { 
    188                          $found = true; 
    189                          break; 
    190                     } 
    191                } 
    192                if (!$found) { 
     241               $user_favs = $ws->DumpLocalPrefs(); 
     242               $core->auth->user_prefs->favorites->dropAll(); 
     243               $count = 0; 
     244               foreach ($user_favs as $k => $v) 
     245               { 
    193246                    $uid = sprintf("u%03s",$count); 
    194                     $fav = array('name' => $_fav[$v][0],'title' => $_fav[$v][1],'url' => $_fav[$v][2],'small-icon' => $_fav[$v][3], 
    195                          'large-icon' => $_fav[$v][4],'permissions' => $_fav[$v][5],'id' => $_fav[$v][6],'class' => $_fav[$v][7]); 
     247                    $f = unserialize($v['value']); 
     248                    $fav = array('name' => $f['name'],'title' => $f['title'],'url' => $f['url'],'small-icon' => $f['small-icon'], 
     249                         'large-icon' => $f['large-icon'],'permissions' => $f['permissions'],'id' => $f['id'],'class' => $f['class']); 
    196250                    $core->auth->user_prefs->favorites->put($uid,serialize($fav),'string'); 
    197251                    $count++; 
     
    199253          } catch (Exception $e) { 
    200254               $core->error->add($e->getMessage()); 
    201                break; 
    202           } 
    203      } 
     255          } 
    204256      
    205      if (!$core->error->flag()) { 
    206           http::redirect('preferences.php?append=1'); 
    207      } 
    208 } 
    209  
    210 # Delete selected favorites 
    211 if (!empty($_POST['removeaction']) && !empty($_POST['remove'])) { 
    212      $ws = $core->auth->user_prefs->addWorkspace('favorites'); 
    213      foreach ($_POST['remove'] as $k => $v) 
    214      { 
    215           try { 
    216                $core->auth->user_prefs->favorites->drop($v); 
    217           } catch (Exception $e) { 
    218                $core->error->add($e->getMessage()); 
    219                break; 
    220           } 
    221      } 
    222      // Update pref_id values 
    223      try { 
    224           $user_favs = $ws->DumpLocalPrefs(); 
    225           $core->auth->user_prefs->favorites->dropAll(); 
    226           $count = 0; 
    227           foreach ($user_favs as $k => $v) 
    228           { 
    229                $uid = sprintf("u%03s",$count); 
    230                $f = unserialize($v['value']); 
    231                $fav = array('name' => $f['name'],'title' => $f['title'],'url' => $f['url'],'small-icon' => $f['small-icon'], 
    232                     'large-icon' => $f['large-icon'],'permissions' => $f['permissions'],'id' => $f['id'],'class' => $f['class']); 
    233                $core->auth->user_prefs->favorites->put($uid,serialize($fav),'string'); 
    234                $count++; 
     257          if (!$core->error->flag()) { 
     258               http::redirect('preferences.php?removed=1'); 
    235259          } 
    236260     } catch (Exception $e) { 
    237261          $core->error->add($e->getMessage()); 
    238      } 
    239       
    240      if (!$core->error->flag()) { 
    241           http::redirect('preferences.php?removed=1'); 
    242262     } 
    243263} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map