diff options
| -rw-r--r-- | LibertyContent.php | 93 | ||||
| -rw-r--r-- | content_permissions.php | 59 | ||||
| -rw-r--r-- | templates/content_permissions.tpl | 122 |
3 files changed, 116 insertions, 158 deletions
diff --git a/LibertyContent.php b/LibertyContent.php index 6fd9c91..6713de7 100644 --- a/LibertyContent.php +++ b/LibertyContent.php @@ -3,7 +3,7 @@ * Management of Liberty content * * @package liberty -* @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyContent.php,v 1.253 2007/07/06 15:43:23 squareing Exp $ +* @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyContent.php,v 1.254 2007/07/06 22:04:37 squareing Exp $ * @author spider <spider@steelsun.com> */ @@ -856,24 +856,36 @@ class LibertyContent extends LibertyBase { * * @access public */ - function loadAllObjectPermissions( $pParamHash = NULL ) { + function getContentPermissionsList() { global $gBitUser; $ret = FALSE; - if( empty( $pParamHash['sort_mode'] )) { - $pParamHash['sort_mode'] = 'group_name_asc'; - } - - LibertyContent::prepGetList( $pParamHash ); if( $this->isValid() && $this->mContentTypeGuid ) { $query = " - SELECT lcperm.`perm_name`, ug.`group_id`, ug.`group_name`, up.`perm_desc` + SELECT lcperm.`perm_name`, lcperm.`is_excluded`, ug.`group_id`, ug.`group_name`, up.`perm_desc` FROM `".BIT_DB_PREFIX."liberty_content_permissions` lcperm INNER JOIN `".BIT_DB_PREFIX."users_groups` ug ON( lcperm.`group_id`=ug.`group_id` ) LEFT OUTER JOIN `".BIT_DB_PREFIX."users_permissions` up ON( up.`perm_name`=lcperm.`perm_name` ) - WHERE lcperm.`content_id` = ? - ORDER BY ".$this->mDb->convertSortmode( $pParamHash['sort_mode'] ); + WHERE lcperm.`content_id` = ?"; $bindVars = array( $this->mContentId ); - $ret = $this->mDb->getAll( $query, $bindVars ); + $perms = $this->mDb->getAll( $query, $bindVars ); + foreach( $perms as $perm ) { + $ret[$perm['group_id']][$perm['perm_name']] = $perm; + } + } + return $ret; + } + + /** + * Expunge Object Permissions + * + * @access public + * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + */ + function expungeContentPermissions() { + $ret = FALSE; + if( $this->isValid() ) { + $query = "DELETE FROM `".BIT_DB_PREFIX."liberty_content_permissions` WHERE `content_id` = ?"; + $ret = $this->mDb->query( $query, array( $this->mContentId )); } return $ret; } @@ -1020,24 +1032,22 @@ class LibertyContent extends LibertyBase { * @param integer Content Itentifier * @return bool true ( will not currently report a failure ) */ - function storePermission( $pGroupId, $pPermName, $pContentId=NULL ) { - if( !@$this->verifyId( $pContentId )) { - $pContentId = $this->mContentId; - } - - if( @BitBase::verifyId( $pGroupId ) && !empty( $pPermName ) && @BitBase::verifyId( $pContentId )) { - $query = " - DELETE FROM `".BIT_DB_PREFIX."liberty_content_permissions` - WHERE `group_id` = ? AND `perm_name` = ? AND `content_id` = ?"; - $result = $this->mDb->query( $query, array( $pGroupId, $pPermName, $pContentId ), -1, -1 ); - $query = " - INSERT INTO `".BIT_DB_PREFIX."liberty_content_permissions` - ( `group_id`,`content_id`, `perm_name` ) - VALUES( ?, ?, ? )"; - $result = $this->mDb->query( $query, array( $pGroupId, $pContentId, $pPermName )); - return TRUE; + function storePermission( $pGroupId, $pPermName ) { + $ret = FALSE; + if( @BitBase::verifyId( $pGroupId ) && !empty( $pPermName ) && $this->isValid() ) { + $this->removePermission( $pGroupId, $pPermName ); + $storeHash = array( + 'group_id' => $pGroupId, + 'perm_name' => $pPermName, + 'content_id' => $this->mContentId, + ); + // check to see if this is an exclusion + if( $this->isExcludedPermission( $pGroupId, $pPermName )) { + $storeHash['is_excluded'] = 'y'; + } + $ret = $this->mDb->associateInsert( BIT_DB_PREFIX."liberty_content_permissions", $storeHash ); } - return FALSE; + return $ret; } /** @@ -1052,25 +1062,22 @@ class LibertyContent extends LibertyBase { WHERE `group_id` = ? and `content_id` = ? and `perm_name` = ?"; $bindVars = array( $pGroupId, $this->mContentId, $pPermName ); $result = $this->mDb->query( $query, $bindVars ); - return true; + return TRUE; } /** - * Copy current permissions to another content - * - * @param integer Content Identifier of the target content - * @return bool true ( will not currently report a failure ) - */ - function copyPermissions( $destinationObjectId ) { - $query = "SELECT `perm_name`, `group_name` - FROM `".BIT_DB_PREFIX."liberty_content_permissions` - WHERE `content_id` =?"; - $bindVars = array( $this->mContentId ); - $result = $this->mDb->query( $query, $bindVars ); - while( $res = $result->fetchRow() ) { - $this->storePermission( $res["group_name"], $this->mContentTypeGuid, $res["perm_name"], $destinationObjectId ); + * Check to see if this permission is already in the global permissions table. + * + * @param array $pGroupId + * @param array $pPermName + * @access public + * @return TRUE if present, FALSE if not + */ + function isExcludedPermission( $pGroupId, $pPermName ) { + if( @BitBase::verifyId( $pGroupId ) && !empty( $pPermName )) { + $query = "SELECT `perm_name` FROM `".BIT_DB_PREFIX."users_group_permissions` WHERE `group_id` = ? AND `perm_name` = ?"; + return( $this->mDb->getOne( $query, array( $pGroupId, $pPermName )) == $pPermName ); } - return TRUE; } diff --git a/content_permissions.php b/content_permissions.php index abd8348..b250f46 100644 --- a/content_permissions.php +++ b/content_permissions.php @@ -1,6 +1,6 @@ <?php /** - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * @package liberty * @subpackage functions */ @@ -16,9 +16,7 @@ $gBitSystem->verifyPermission( 'p_liberty_assign_content_perms' ); if( empty( $gContent )) { // make sure we have a content_id we can work with if( empty( $_REQUEST["content_id"] ) || $_REQUEST["content_id"] < 1 ) { - $gBitSmarty->assign( 'msg', tra( "No valid content id given." )); - $gBitSystem->display( 'error.tpl' ); -die; + $gBitSystem->fatalError( tra( "No valid content id given." )); } $gContent = new LibertyContent(); @@ -29,37 +27,50 @@ $gBitSmarty->assign_by_ref( 'gContent', $gContent ); // Process the form // send the user to the content page if he wants to if( !empty( $_REQUEST['back'] )) { - header( "Location: ".$gContent->getDisplayUrl() ); - die; + bit_redirect( $gContent->getDisplayUrl() ); } // Update database if needed -if( @BitBase::verifyId( $_REQUEST["group_id"] ) && @BitBase::verifyId( $gContent->mContentId ) && !empty( $_REQUEST["perm"] ) && !empty( $_REQUEST['action'] )) { - $gBitUser->verifyTicket( TRUE ); - if( $_REQUEST["action"] == 'assign' ) { - $gContent->storePermission( $_REQUEST["group_id"], $_REQUEST["perm"], $gContent->mContentId ); - } elseif( $_REQUEST["action"] == 'remove' ) { - $gContent->removePermission( $_REQUEST["group_id"], $_REQUEST["perm"] ); +if( !empty( $_REQUEST['action'] ) && @BitBase::verifyId( $gContent->mContentId )) { + if( $_REQUEST["action"] == 'expunge' ) { + if( $gContent->expungeContentPermissions() ) { + $feedback['success'] = tra( 'The content permissions were successfully removed.' ); + } else { + $feedback['error'] = tra( 'The content permissions were not removed.' ); + } } -} -// Now we have to get the individual object permissions if any -$contentPerms['assigned'] = $gContent->loadAllObjectPermissions( $_REQUEST ); + if( @BitBase::verifyId( $_REQUEST["group_id"] ) && !empty( $_REQUEST["perm"] )) { + $gBitUser->verifyTicket( TRUE ); + if( $_REQUEST["action"] == 'assign' ) { + $gContent->storePermission( $_REQUEST["group_id"], $_REQUEST["perm"] ); + } elseif( $_REQUEST["action"] == 'remove' ) { + $gContent->removePermission( $_REQUEST["group_id"], $_REQUEST["perm"] ); + } + } +} // Get a list of groups -$listHash = array( 'sort_mode' => 'group_name_asc' ); +$listHash = array( 'sort_mode' => 'group_id_asc' ); $contentPerms['groups'] = $gBitUser->getAllGroups( $listHash ); -// Get a list of permissions -if( empty( $assignPerms )) { - if( !empty( $gContent->mType['handler_package'] )) { - $contentPerms['assignable'] = $gBitUser->getGroupPermissions( array( 'package' => $gContent->mType['handler_package'] )); - } else { - // this is a last resort and will dump all perms a user has - $contentPerms['assignable'] = $gBitUser->mPerms; +if( !empty( $gContent->mType['handler_package'] )) { + $contentPerms['assignable'] = $gBitUser->getGroupPermissions( array( 'package' => $gContent->mType['handler_package'] )); +} else { + // this is a last resort and will dump all perms a user has + $contentPerms['assignable'] = $gBitUser->mPerms; +} + +// Now we have to get the individual object permissions if any +if( $contentPerms['assigned'] = $gContent->getContentPermissionsList() ) { + // merge assigned permissions with group permissions + foreach( array_keys( $contentPerms['groups'] ) as $groupId ) { + if( !empty( $contentPerms['assigned'][$groupId] )) { + $contentPerms['groups'][$groupId]['perms'] = array_merge( $contentPerms['groups'][$groupId]['perms'], $contentPerms['assigned'][$groupId] ); + } } } -$gBitSmarty->assign( 'contentPerms', $contentPerms ); +$gBitSmarty->assign( 'contentPerms', $contentPerms ); $gBitSystem->display( 'bitpackage:liberty/content_permissions.tpl', tra( 'Content Permissions' )); ?> diff --git a/templates/content_permissions.tpl b/templates/content_permissions.tpl index 0ea9b71..e4d123a 100644 --- a/templates/content_permissions.tpl +++ b/templates/content_permissions.tpl @@ -1,6 +1,6 @@ {strip} -<div class="admin permission"> +<div class="admin liberty"> <div class="header"> <h1>{tr}Assign permissions{/tr}</h1> </div> @@ -9,101 +9,41 @@ <h2>{tr}Assign permissions to{/tr}: {$gContent->getTitle()}</h2> {if !$contentPerms.assigned} - {formhelp warning="No Individual permissions set. Global Permissions apply."} + {formfeedback warning="No Individual permissions set. Global Permissions apply."} + {else} + {smartlink ititle="Remove all custom content permissions" action=expunge content_id=$gContent->mContentId} {/if} - {if count($contentPerms.groups) lt 8} - - <table class="data"> - <tr> - <th>{tr}Permission{/tr}</th> - {foreach from=$contentPerms.groups item=group} - <th>{$group.group_name}</th> - {/foreach} - </tr> - {foreach from=$contentPerms.assignable item=perm} - <tr class="{cycle values="odd,even"}"> - <td>{$perm.perm_desc}<br /><em>({$perm.perm_name})</em></td> - {foreach from=$contentPerms.groups item=group} - {assign var=icon value="icons/media-playback-stop"} - {assign var=action value="assign"} - {foreach from=$contentPerms.assigned item=ass} - {if $ass.group_id == $group.group_id and $ass.perm_name == $perm.perm_name} - {assign var=icon value="icons/dialog-ok"} - {assign var=action value="remove"} - {/if} - {/foreach} - <td style="text-align:center">{smartlink itra=false ititle=$perm.perm_name ibiticon=$icon action=$action content_id=$gContent->mContentId perm=$perm.perm_name group_id=$group.group_id}</td> - {/foreach} - </tr> + <table class="data"> + <tr> + <th>{tr}Permission{/tr}</th> + {foreach from=$contentPerms.groups item=group} + <th>{$group.group_name}</th> {/foreach} - </table> - <br /><hr /><br /> - - {else} - - {form} - <input type="hidden" name="content_id" value="{$gContent->mContentId}" /> - <input type="hidden" name="action" value="assign" /> + </tr> - <div class="row"> - {formlabel label="Assign this Permission" for="perm"} - {forminput} - <select name="perm" id="perm"> - {foreach from=$contentPerms.assignable item=perm} - <option value="{$perm.perm_name}">{$perm.perm_desc}</option> - {/foreach} - </select> - {formhelp note=""} - {/forminput} - </div> - - <div class="row"> - {formlabel label="To this Group" for="group_id"} - {forminput} - <select name="group_id" id="group_id"> - {foreach from=$contentPerms.groups item=group} - <option value="{$group.group_id}">{$group.group_name}</option> - {/foreach} - </select> - {formhelp note=""} - {/forminput} - </div> - - <div class="row submit"> - <input type="submit" name="back" value="{tr}Go back to content{/tr}" /> - <input type="submit" name="assign" value="{tr}Assign Permission{/tr}" /> - </div> - {/form} - - {if $contentPerms.assigned} - <br /> - - <table class="data"> - <caption>{tr}Permissions assigned to this content{/tr}</caption> - <tr> - <th>{smartlink content_id=$gContent->mContentId ititle=Group isort=group_name idefault=1}</th> - <th>{smartlink content_id=$gContent->mContentId ititle=Permission isort=perm_name}</th> - <th>{tr}Action{/tr}</th> - </tr> - {foreach from=$contentPerms.assigned item=perm} - <tr class="{cycle values="even,odd"}"> - <td>{$perm.group_name}</td> - <td>{$perm.perm_desc} <em>({$perm.perm_name})</em></td> - <td align="right"> - {smartlink ititle="Remove Permission" ibiticon="icons/edit-delete" action=remove content_id=$gContent->mContentId perm=$perm.perm_name group_id=$perm.group_id} - </td> - </tr> - {foreachelse} - <tr class="norecords"> - <td colspan="3">{tr}No individual permissions, global permissions apply{/tr}</td> - </tr> + {foreach from=$contentPerms.assignable key=perm item=permInfo} + <tr class="{cycle values="odd,even"}"> + <td>{$permInfo.perm_desc}<br /><em>({$permInfo.perm_name})</em></td> + {foreach from=$contentPerms.groups key=group_id item=groupInfo} + {assign var=icon value="icons/media-playback-stop"} {* default icon *} + {assign var=action value="assign"} {* default action *} + {if $groupInfo.perms.$perm} {* global active permissions *} + {assign var=icon value="icons/dialog-ok"} {* default active permission icon *} + {if $contentPerms.assigned.$group_id.$perm} + {assign var=icon value="icons/list-add"} {* custon permission icon *} + {assign var=action value="remove"} {* remove permission if we have a custom one *} + {/if} + {if $contentPerms.assigned.$group_id.$perm.is_excluded} + {assign var=icon value="icons/list-remove"} {* is_excluded icon *} + {/if} + {/if} + <td style="text-align:center">{smartlink itra=false ititle=$perm ibiticon=$icon action=$action content_id=$gContent->mContentId perm=$perm group_id=$group_id}</td> {/foreach} - </table> - {/if} - - {/if} + </tr> + {/foreach} + </table> </div><!-- end .body --> -</div><!-- end .permission --> +</div><!-- end .liberty --> {/strip} |
