Changeset 2863

Show
Ignore:
Timestamp:
11/24/08 04:47:48 (7 weeks ago)
Author:
MattRead
Message:

wsse update from arthus

Location:
trunk/htdocs/system
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/htdocs/system/admin/groups.php

    r2861 r2863  
    4545    </div> 
    4646     
     47    <input type="hidden" name="nonce" id="nonce" value="<?php echo $wsse['nonce']; ?>"> 
     48    <input type="hidden" name="timestamp" id="timestamp" value="<?php echo $wsse['timestamp']; ?>"> 
     49    <input type="hidden" name="PasswordDigest" id="PasswordDigest" value="<?php echo $wsse['digest']; ?>"> 
     50     
    4751    <div class="item submit clear"> 
    4852        <span class="pct25"> 
     
    5256 
    5357     
    54 </div> 
    55 </form> 
    56  
    57  
    58 <div class="container hidden"> 
    59     <div class="controls item"> 
    60         <span class="checkboxandselected pct25"> 
    61             <input type="checkbox" id="master_checkbox" name="master_checkbox"> 
    62             <label class="selectedtext minor none" for="master_checkbox"><?php _e('None selected'); ?></label> 
    63         </span> 
    64  
    65         <input type="hidden" name="nonce" id="nonce" value="<?php echo $wsse['nonce']; ?>"> 
    66         <input type="hidden" name="timestamp" id="timestamp" value="<?php echo $wsse['timestamp']; ?>"> 
    67         <input type="hidden" name="PasswordDigest" id="PasswordDigest" value="<?php echo $wsse['digest']; ?>"> 
    68      
    69         <span class="reassign minor"> 
    70             <?php printf( _t('Reassign posts to %s'), Utils::html_select('reassign', $authors )); ?> and 
    71             <input type="submit" name="delete" value="<?php _e('Delete Selected'); ?>"> 
    72         </span> 
    73     </div> 
    7458</div> 
    7559</form> 
  • trunk/htdocs/system/classes/adminhandler.php

    r2862 r2863  
    22362236 
    22372237    public function update_groups($handler_vars, $ajax = TRUE) { 
    2238         if($ajax) { 
    2239             $wsse = Utils::WSSE( $handler_vars['nonce'], $handler_vars['timestamp'] ); 
    2240             if ( isset($handler_vars['digest']) && $handler_vars['digest'] != $wsse['digest'] ) { 
    2241                 Session::error( _t('WSSE authentication failed.') ); 
    2242                 return Session::messages_get( true, 'array' ); 
    2243             } 
    2244         } 
    2245  
    2246         if(( isset($handler_vars['action']) && $handler_vars['action'] == 'add') || isset($handler_vars['newgroup'])) { 
    2247             if(isset($handler_vars['newgroup'])) { 
    2248                 $name= $handler_vars['new_groupname']; 
    2249             } 
    2250             else { 
    2251                 $name= $handler_vars['name']; 
    2252             } 
    2253  
    2254             $settings= array('name' => $name); 
    2255  
    2256             $this->theme->addform= $settings; 
    2257  
    2258             if ( UserGroup::exists($name) ) { 
    2259                 Session::notice( sprintf(_t( 'The group %s already exists'), $name ) ); 
     2238        $wsse = Utils::WSSE( $handler_vars['nonce'], $handler_vars['timestamp'] ); 
     2239        if ( (isset($handler_vars['digest']) && $handler_vars['digest'] != $wsse['digest']) || (isset($handler_vars['PasswordDigest']) && $handler_vars['PasswordDigest'] != $wsse['digest']) ) { 
     2240            Session::error( _t('WSSE authentication failed.') ); 
     2241            return Session::messages_get( true, 'array' ); 
     2242        } 
     2243                         
     2244        if(isset($handler_vars['PasswordDigest']) || isset($handler_vars['digest'])) { 
     2245             
     2246            if(( isset($handler_vars['action']) && $handler_vars['action'] == 'add') || isset($handler_vars['newgroup'])) { 
     2247                if(isset($handler_vars['newgroup'])) { 
     2248                    $name= $handler_vars['new_groupname']; 
     2249                } 
     2250                else { 
     2251                    $name= $handler_vars['name']; 
     2252                } 
     2253 
     2254                $settings= array('name' => $name); 
     2255 
     2256                $this->theme->addform= $settings; 
     2257 
     2258                if ( UserGroup::exists($name) ) { 
     2259                    Session::notice( sprintf(_t( 'The group %s already exists'), $name ) ); 
     2260                    if($ajax) { 
     2261                        return Session::messages_get( true, 'array' ); 
     2262                    } 
     2263                    else { 
     2264                        return; 
     2265                    } 
     2266                } 
     2267                else { 
     2268                    $groupdata = array( 
     2269                        'name' => $name 
     2270                    ); 
     2271                    $group = UserGroup::create($groupdata); 
     2272                    Session::notice( sprintf(_t( 'Added group %s'), $name ) ); 
     2273                    // reload the groups 
     2274                    $this->theme->groups = UserGroups::get_all(); 
     2275 
     2276                    $this->theme->addform= array(); 
     2277                } 
     2278 
    22602279                if($ajax) { 
    22612280                    return Session::messages_get( true, 'array' ); 
    22622281                } 
    22632282                else { 
    2264                     return; 
    2265                 } 
    2266             } 
    2267             else { 
    2268                 $groupdata = array( 
    2269                     'name' => $name 
    2270                 ); 
    2271                 $group = UserGroup::create($groupdata); 
    2272                 Session::notice( sprintf(_t( 'Added group %s'), $name ) ); 
    2273                 // reload the groups 
    2274                 $this->theme->groups = UserGroups::get_all(); 
    2275  
    2276                 $this->theme->addform= array(); 
    2277             } 
    2278  
    2279             if($ajax) { 
     2283                    if(!$ajax) { 
     2284                        Utils::redirect(URL::get('admin', 'page=groups')); 
     2285                        exit; 
     2286                    } 
     2287                } 
     2288 
     2289            } 
     2290 
     2291            if( isset($handler_vars['action']) && $handler_vars['action'] == 'delete' && $ajax = true) { 
     2292 
     2293 
     2294 
     2295                $ids= array(); 
     2296 
     2297                foreach ( $_POST as $id => $delete ) { 
     2298 
     2299                    // skip POST elements which are not log ids 
     2300                    if ( preg_match( '/^p\d+/', $id ) && $delete ) { 
     2301                        $id = substr($id, 1); 
     2302 
     2303                        $ids[] = array( 'id' => $id ); 
     2304 
     2305                    } 
     2306 
     2307                } 
     2308 
     2309                $count = 0; 
     2310 
     2311                if( !isset($ids) ) { 
     2312                    Session::notice( _t('No groups deleted.') ); 
     2313                    return Session::messages_get( true, 'array' ); 
     2314                } 
     2315 
     2316                foreach ( $ids as $id ) { 
     2317                    $id = $id['id']; 
     2318                    $group = UserGroup::get_by_id( $id ); 
     2319 
     2320                    $group->delete(); 
     2321 
     2322                    $count++; 
     2323                } 
     2324 
     2325                if ( !isset($msg_status) ) { 
     2326                    $msg_status = sprintf( _t('Deleted %d groups.'), $count ); 
     2327                } 
     2328 
     2329                Session::notice( $msg_status ); 
     2330 
    22802331                return Session::messages_get( true, 'array' ); 
    22812332            } 
    2282             else { 
    2283                 if(!$ajax) { 
    2284                     Utils::redirect(); 
    2285                     exit; 
    2286                 } 
    2287             } 
    2288  
    2289         } 
    2290  
    2291         if( isset($handler_vars['action']) && $handler_vars['action'] == 'delete' && $ajax = true) { 
    2292  
    2293  
    2294  
    2295             $ids= array(); 
    2296  
    2297             foreach ( $_POST as $id => $delete ) { 
    2298  
    2299                 // skip POST elements which are not log ids 
    2300                 if ( preg_match( '/^p\d+/', $id ) && $delete ) { 
    2301                     $id = substr($id, 1); 
    2302  
    2303                     $ids[] = array( 'id' => $id ); 
    2304  
    2305                 } 
    2306  
    2307             } 
    2308  
    2309             $count = 0; 
    2310  
    2311             if( !isset($ids) ) { 
    2312                 Session::notice( _t('No groups deleted.') ); 
    2313                 return Session::messages_get( true, 'array' ); 
    2314             } 
    2315  
    2316             foreach ( $ids as $id ) { 
    2317                 $id = $id['id']; 
    2318                 $group = UserGroup::get_by_id( $id ); 
    2319  
    2320                 $group->delete(); 
    2321  
    2322                 $count++; 
    2323             } 
    2324  
    2325             if ( !isset($msg_status) ) { 
    2326                 $msg_status = sprintf( _t('Deleted %d groups.'), $count ); 
    2327             } 
    2328  
    2329             Session::notice( $msg_status ); 
    2330  
    2331             return Session::messages_get( true, 'array' ); 
    23322333        } 
    23332334 
     
    23482349 
    23492350        $this->update_groups($this->handler_vars, false); 
    2350  
    2351         if ( isset( $this->handler_vars['delete_group'] ) ) { 
    2352             $name = $this->handler_vars['group']; 
    2353             if ( !UserGroup::exists($name) ) { 
    2354                 Session::notice( sprintf(_t( 'The group %s does not exist'), $name ) ); 
    2355             } 
    2356             else { 
    2357                 $group = UserGroup::get($name); 
    2358                 $group->delete(); 
    2359                 Session::notice( sprintf( _t( 'Removed group %s' ), $name ) ); 
    2360                 // reload the groups 
    2361                 $this->theme->groups = UserGroups::get_all(); 
    2362             } 
    2363         } 
    2364  
    2365         if ( isset( $this->handler_vars['edit_group'] ) ) { 
    2366             $name = $this->handler_vars['group']; 
    2367             if ( !UserGroup::exists($name) ) { 
    2368                 Session::notice( sprintf(_t( 'The group %s does not exist'), $name ) ); 
    2369             } 
    2370             else { 
    2371                 $group = UserGroup::get($name); 
    2372                 $this->theme->group_edit = $group; 
    2373                 $this->theme->members = $group->members; 
    2374                 $this->theme->users = Users::get_all(); 
    2375                 $this->theme->permissions = ACL::all_permissions( 'description' ); 
    2376                 $this->theme->permissions_granted = $group->permissions; 
    2377             } 
    2378         } 
    2379  
    2380         if ( isset( $this->handler_vars['users'] ) ) { 
    2381             $name = $this->handler_vars['group']; 
    2382             if ( ! UserGroup::exists($name) ) { 
    2383                 Session::notice( sprintf(_t( 'The group %s does not exist'), $name ) ); 
    2384             } 
    2385             else { 
    2386                 $group = UserGroup::get($name); 
    2387                 $add_users = array(); 
    2388                 $remove_users = array(); 
    2389                 $form_users = array(); 
    2390                 if ( isset( $this->handler_vars['user_id'] ) ) { 
    2391                     $form_users = $this->handler_vars['user_id']; 
    2392                 } 
    2393                 foreach ( Users::get_all() as $user ) { 
    2394                     if ( in_array( $user->id, $form_users ) ) { 
    2395                         $add_users[]= (int) $user->id; 
    2396                     } 
    2397                     else { 
    2398                         $remove_users[]= (int) $user->id; 
    2399                     } 
    2400                 } 
    2401                 if ( ! empty( $add_users ) ) { 
    2402                     $group->add( $add_users ); 
    2403                 } 
    2404                 if ( ! empty( $remove_users ) ) { 
    2405                     $group->remove( $remove_users ); 
    2406                 } 
    2407                 $group->update(); 
    2408                 Session::notice( sprintf(_t( 'Modified membership of group %s'), $name ) ); 
    2409                 // reload the groups 
    2410                 $this->theme->groups = UserGroups::get_all(); 
    2411             } 
    2412         } 
    2413  
    2414         if ( isset( $this->handler_vars['permissions'] ) ) { 
    2415             $group_name = $this->handler_vars['group']; 
    2416             if ( !UserGroup::exists( $group_name ) ) { 
    2417                 Session::notice( sprintf(_t( 'The group %s does not exist'), $name ) ); 
    2418             } 
    2419             else { 
    2420                 $grant = array(); 
    2421                 $revoke = array(); 
    2422                 $group = UserGroup::get( $group_name ); 
    2423  
    2424                 foreach( ACL::all_permissions() as $permission ) { 
    2425                     // grab the type of access for each permission 
    2426                     if ( isset( $this->handler_vars['perm' + $permission->id] ) ) { 
    2427                         $grant[$permission->id] = $this->handler_vars['perm' + $permission->id]; 
    2428                     } 
    2429                     // if it isn't set, then revoke it 
    2430                     else { 
    2431                         $revoke[] = (int) $permission->id; 
    2432                     } 
    2433                 } 
    2434                 if ( ! empty( $grant ) ) { 
    2435                     /* the following call does not yet work as used 
    2436                      * need to re-write UserGroup::grant() */ 
    2437                     $group->grant( $grant ); 
    2438                 } 
    2439                 if ( ! empty( $revoke ) ) { 
    2440                     $group->revoke( $revoke ); 
    2441                 } 
    2442                 $group->update(); 
    2443                 Session::notice( sprintf(_t( 'Granted the permission to group %s'), $group_name ) ); 
    2444                 // reload the groups 
    2445                 $this->theme->groups = UserGroups::get_all(); 
    2446             } 
    2447         } 
    24482351 
    24492352        $this->display( 'groups' );