liberty
[ class tree: liberty ] [ index: liberty ] [ all elements ]

Source for file content_role_permissions.php

Documentation is available at content_role_permissions.php

  1. <?php
  2. /**
  3.  * @version  $Revision$
  4.  * @package  liberty
  5.  * @subpackage functions
  6.  */
  7.  
  8. /**
  9.  * bit setup
  10.  */
  11. require_once( '../kernel/setup_inc.php' );
  12.  
  13. $gBitSystem->verifyPermission( 'p_liberty_assign_content_perms' );
  14.  
  15. require_once( LIBERTY_PKG_PATH.'lookup_content_inc.php' );
  16.  
  17. if( $gContent == null ) {
  18.     $gBitSystem->fatalError('Could not find the requested content.', NULL, NULL, HttpStatusCodes::HTTP_GONE );
  19. }
  20.  
  21. // Process the form
  22. // send the user to the content page if he wants to
  23. if( !empty( $_REQUEST['back'] )) {
  24.     bit_redirect( $gContent->getDisplayUrl() );
  25. }
  26.  
  27. // Update database if needed
  28. if( !empty( $_REQUEST['action'] ) && @BitBase::verifyId( $gContent->mContentId )) {
  29.     if( $_REQUEST["action"] == 'expunge' ) {
  30.         if( $gContent->expungeContentPermissions() ) {
  31.             $feedback['success'] = tra( 'The content permissions were successfully removed.' );
  32.         } else {
  33.             $feedback['error'] = tra( 'The content permissions were not removed.' );
  34.         }
  35.     }
  36.  
  37.     if( @BitBase::verifyId( $_REQUEST["role_id"] ) && !empty( $_REQUEST["perm"] )) {
  38.         $gBitUser->verifyTicket( TRUE );
  39.         if( $_REQUEST["action"] == 'assign' ) {
  40.             $gContent->storePermission( $_REQUEST["role_id"], $_REQUEST["perm"] );
  41.         } elseif( $_REQUEST["action"] == 'negate' ) {
  42.             $gContent->storePermission( $_REQUEST["role_id"], $_REQUEST["perm"], TRUE );
  43.         } elseif( $_REQUEST["action"] == 'remove' ) {
  44.             $gContent->removePermission( $_REQUEST["role_id"], $_REQUEST["perm"] );
  45.         }
  46.     }
  47. }
  48.  
  49. // Get a list of roles
  50. $listHash = array( 'sort_mode' => 'role_id_asc', 'visible' => 1 );
  51. $contentPerms['roles'] = $gBitUser->getAllRoles( $listHash );
  52.  
  53. if( !empty( $gContent->mType['handler_package'] )) {
  54.     $contentPerms['assignable'] = $gBitUser->getRolePermissions( array( 'package' => $gContent->mType['handler_package'] ));
  55. } else {
  56.     // this is a last resort and will dump all perms a user has
  57.     $contentPerms['assignable'] = $gBitUser->mPerms;
  58. }
  59.  
  60. // Now we have to get the individual object permissions if any
  61. if( $contentPerms['assigned'] = $gContent->getContentPermissionsList() ) {
  62.     // merge assigned permissions with rol permissions
  63.     foreach( array_keys( $contentPerms['roles'] ) as $roleId ) {
  64.         if( !empty( $contentPerms['assigned'][$roleId] )) {
  65.             $contentPerms['roles'][$roleId]['perms'] = array_merge( $contentPerms['roles'][$roleId]['perms'], $contentPerms['assigned'][$roleId] );
  66.         }
  67.     }
  68. }
  69. $gBitSmarty->assign( 'contentPerms', $contentPerms );
  70.  
  71. // if we've called this page as part of an ajax update, we output the appropriate data
  72. if( $gBitThemes->isAjaxRequest() ) {
  73.     if( count( $contentPerms['roles'] <= 10 )) {
  74.         $size = 'large/';
  75.     } else {
  76.         $size = 'small/';
  77.     }
  78.  
  79.     $gid = $_REQUEST['role_id'];
  80.     $perm = $_REQUEST['perm'];
  81.  
  82.     // we're applying the same logic as in the template. if you fix / change anything here, please update the template as well.
  83.     $biticon = array(
  84.         'ipackage' => 'icons',
  85.         'iname'    => $size.'media-playback-stop',
  86.         'iexplain' => '',
  87.         'iforce'   => 'icon',
  88.     );
  89.     $action = 'assign';
  90.     if( !empty( $contentPerms['roles'][$gid]['perms'][$perm] )) {
  91.         $biticon['iname'] = $size.'dialog-ok';
  92.         if( !empty( $contentPerms['assigned'][$gid][$perm] )) {
  93.             $assigned = $contentPerms['assigned'][$gid][$perm];
  94.             $biticon['iname'] = $size.'list-add';
  95.             $action = 'negate';
  96.         }
  97.         if( !empty( $assigned['is_revoked'] )) {
  98.             $biticon['iname'] = $size.'list-remove';
  99.             $action = 'remove';
  100.         }
  101.     }
  102.  
  103.     $gBitSmarty->loadPlugin( 'smarty_function_biticon' );
  104.     $ret = '<a title="'.$contentPerms['roles'][$gid]['role_name']." :: ".$perm.'" '.
  105.             'href="javascript:void(0);" onclick="BitAjax.updater('.
  106.             "'{$perm}{$gid}', ".
  107.             "'".LIBERTY_PKG_URL."content_role_permissions.php', ".
  108.             "'action={$action}&amp;content_id={$gContent->mContentId}&amp;perm={$perm}&amp;role_id={$gid}'".
  109.         ')">'.smarty_function_biticon( $biticon, $gBitSmarty ).'</a>';
  110.     echo $ret;
  111.     die;
  112. }
  113.  
  114. $gBitSystem->display( 'bitpackage:liberty/content_role_permissions.tpl', tra( 'Content Permissions' ), array( 'display_mode' => 'display' ));
  115. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:16 +0000 by phpDocumentor 1.5.0-lsces