[20972] Improvement: Better Users and Group handling - added per app admin - 4512:4565

Sigurd Nes <[email protected]> Fri, 22 Jan 2010 09:43:34 +0000
Newsgroups gmane.comp.web.phpgroupware.cvs
Message-ID <[email protected]>
Revision: 20972
          http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=20972
Author:   sigurdne
Date:     2010-01-22 09:43:33 +0000 (Fri, 22 Jan 2010)
Log Message:
-----------
Improvement: Better Users and Group handling - added per app admin - 4512:4565

Modified Paths:
--------------
    people/sigurdne/modules/admin/trunk/inc/class.boaccounts.inc.php
    people/sigurdne/modules/admin/trunk/inc/class.menu.inc.php
    people/sigurdne/modules/admin/trunk/inc/class.uiaccounts.inc.php
    people/sigurdne/modules/admin/trunk/templates/base/groups.xsl
    people/sigurdne/modules/admin/trunk/templates/base/users.xsl

Added Paths:
-----------
    people/sigurdne/modules/admin/trunk/js/base/move.js

Modified: people/sigurdne/modules/admin/trunk/inc/class.boaccounts.inc.php
===================================================================
--- people/sigurdne/modules/admin/trunk/inc/class.boaccounts.inc.php	2010-01-17 12:19:45 UTC (rev 20971)
+++ people/sigurdne/modules/admin/trunk/inc/class.boaccounts.inc.php	2010-01-22 09:43:33 UTC (rev 20972)
@@ -331,9 +331,20 @@
 				);
 			}
 
+			$apps_admin = $values['account_permissions_admin'] ? array_keys($values['account_permissions_admin']) : array();
+			foreach ($apps_admin as $app_admin)
+			{
+				$acls[] = array
+				(
+					'appname' 	=> $app_admin,
+					'location'	=> 'admin',
+					'rights'	=> phpgwapi_acl::ADD
+				);			
+			}
+
 			$apps = $values['account_permissions'] ? array_keys($values['account_permissions']) : array();
 
-			unset($values['account_groups'], $values['account_permissions']);
+			unset($values['account_groups'], $values['account_permissions'], $values['account_permissions_admin']);
 
 			try
 			{

Modified: people/sigurdne/modules/admin/trunk/inc/class.menu.inc.php
===================================================================
--- people/sigurdne/modules/admin/trunk/inc/class.menu.inc.php	2010-01-17 12:19:45 UTC (rev 20971)
+++ people/sigurdne/modules/admin/trunk/inc/class.menu.inc.php	2010-01-22 09:43:33 UTC (rev 20972)
@@ -55,7 +55,8 @@
 			);
 
 			$menus['admin'] = array();
-			if (! $GLOBALS['phpgw']->acl->check('site_config_access', phpgwapi_acl::READ, 'admin'))
+//			if (! $GLOBALS['phpgw']->acl->check('site_config_access', phpgwapi_acl::READ, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$menus['admin']['index'] = array
 				(
@@ -85,7 +86,8 @@
 				);
 			}
 
-			if (! $GLOBALS['phpgw']->acl->check('sync_account', PHPGW_ACL_READ, 'admin'))
+//			if (! $GLOBALS['phpgw']->acl->check('sync_account', PHPGW_ACL_READ, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$menus['admin']['sync_account'] = array
 				(
@@ -94,7 +96,8 @@
 				);
 			}
 
-			if (! $GLOBALS['phpgw']->acl->check('applications_access', phpgwapi_acl::READ, 'admin'))
+//			if (! $GLOBALS['phpgw']->acl->check('applications_access', phpgwapi_acl::READ, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$menus['admin']['apps'] = array
 				(
@@ -104,7 +107,8 @@
 				);
 			}
 
-			if (! $GLOBALS['phpgw']->acl->check('global_categories_access', phpgwapi_acl::READ, 'admin'))
+//			if (! $GLOBALS['phpgw']->acl->check('global_categories_access', phpgwapi_acl::READ, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$menus['admin']['categories'] = array
 				(
@@ -114,7 +118,8 @@
 				);
 			}
 
-			if (! $GLOBALS['phpgw']->acl->check('account_access', phpgwapi_acl::READ, 'admin'))
+//			if (! $GLOBALS['phpgw']->acl->check('account_access', phpgwapi_acl::READ, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$menus['admin']['addressmasters'] = array
 				(
@@ -127,8 +132,9 @@
 				);
 			}
 
-			if ( !$GLOBALS['phpgw']->acl->check('mainscreen_message_access', phpgwapi_acl::READ, 'admin')
-				|| !$GLOBALS['phpgw']->acl->check('mainscreen_message_access', phpgwapi_acl::ADD, 'admin'))
+//			if ( !$GLOBALS['phpgw']->acl->check('mainscreen_message_access', phpgwapi_acl::READ, 'admin')
+//				|| !$GLOBALS['phpgw']->acl->check('mainscreen_message_access', phpgwapi_acl::ADD, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$menus['admin']['mainscreen'] = array
 				(
@@ -138,7 +144,8 @@
 				);
 			}
 
-			if (! $GLOBALS['phpgw']->acl->check('current_sessions_access', phpgwapi_acl::READ, 'admin'))
+//			if (! $GLOBALS['phpgw']->acl->check('current_sessions_access', phpgwapi_acl::READ, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$menus['admin']['sessions'] = array
 				(
@@ -148,7 +155,8 @@
 				);
 			}
 
-			if (! $GLOBALS['phpgw']->acl->check('access_log_access', phpgwapi_acl::READ, 'admin'))
+//			if (! $GLOBALS['phpgw']->acl->check('access_log_access', phpgwapi_acl::READ, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$menus['admin']['access_log'] = array
 				(
@@ -158,7 +166,8 @@
 				);
 			}
 
-			if (! $GLOBALS['phpgw']->acl->check('error_log_access', phpgwapi_acl::READ, 'admin'))
+//			if (! $GLOBALS['phpgw']->acl->check('error_log_access', phpgwapi_acl::READ, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$menus['admin']['error_log'] = array
 				(
@@ -168,7 +177,8 @@
 				);
 			}
 
-			if (! $GLOBALS['phpgw']->acl->check('error_log_access', phpgwapi_acl::READ, 'admin'))
+//			if (! $GLOBALS['phpgw']->acl->check('error_log_access', phpgwapi_acl::READ, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$menus['admin']['log_levels'] = array
 				(
@@ -178,7 +188,8 @@
 				);
 			}
 
-			if (! $GLOBALS['phpgw']->acl->check('applications_access', phpgwapi_acl::PRIV, 'admin'))
+//			if (! $GLOBALS['phpgw']->acl->check('applications_access', phpgwapi_acl::PRIV, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$text = $GLOBALS['phpgw']->translation->translate('Find and Register all Application Hooks',
 						array(), true);
@@ -191,7 +202,8 @@
 				);
 			}
 
-			if (! $GLOBALS['phpgw']->acl->check('asyncservice_access', phpgwapi_acl::READ, 'admin'))
+//			if (! $GLOBALS['phpgw']->acl->check('asyncservice_access', phpgwapi_acl::READ, 'admin'))
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin'))
 			{
 				$menus['admin']['async'] = array
 				(
@@ -201,7 +213,8 @@
 				);
 			}
 
-			if (! $GLOBALS['phpgw']->acl->check('info_access', phpgwapi_acl::READ, 'admin')
+//			if (! $GLOBALS['phpgw']->acl->check('info_access', phpgwapi_acl::READ, 'admin')
+			if ( $GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin')
 					&& function_exists('phpinfo') ) // it is possible to disable commands in php.ini
 			{
 				$menus['admin']['phpinfo'] = array

Modified: people/sigurdne/modules/admin/trunk/inc/class.uiaccounts.inc.php
===================================================================
--- people/sigurdne/modules/admin/trunk/inc/class.uiaccounts.inc.php	2010-01-17 12:19:45 UTC (rev 20971)
+++ people/sigurdne/modules/admin/trunk/inc/class.uiaccounts.inc.php	2010-01-22 09:43:33 UTC (rev 20972)
@@ -514,6 +514,7 @@
 
 			$js =& $GLOBALS['phpgw']->js;
 			$js->validate_file('base', 'groups', 'admin');
+			$js->validate_file('base', 'move', 'admin');
 
 			$accounts =& $GLOBALS['phpgw']->accounts;
 
@@ -531,12 +532,22 @@
 			$user_list = array();
 			foreach ( $account_list as $id => $user )
 			{
-				$user_list[$id] = array
-				(
-					'account_id'	=> $id,
-					'account_name'	=> (string) $user,
- 					'selected'		=> (int) isset($group_members[$id])
-				);
+				if(isset($group_members[$id]))
+				{
+					$member_list[$id] = array
+					(
+						'account_id'	=> $id,
+						'account_name'	=> (string) $user
+					);
+				}
+				else
+				{
+					$user_list[$id] = array
+					(
+						'account_id'	=> $id,
+						'account_name'	=> (string) $user
+					);				
+				}
 			}
 
 			//FIXME this needs to be provided by the app itself - thats why we have hooks
@@ -646,16 +657,11 @@
 											'account_id' => $account_id
 										)),
 				'guser_list'		=> $user_list,
+				'member_list'		=> $member_list,
 				'img_close'			=> $GLOBALS['phpgw']->common->image('phpgwapi', 'stock_close', '.png', false),
 				'img_save'			=> $GLOBALS['phpgw']->common->image('phpgwapi', 'stock_save', '.png', false),
-				'lang_account_name'	=> lang('group name'),
-				'lang_acl'			=> lang('acl'),
-				'lang_application'	=> lang('application'),
 				'lang_cancel'		=> lang('cancel'),
 				'lang_close'		=> lang('close'),
-				'lang_grant'		=> lang('grant'),
-				'lang_include_user'	=> lang('members'),
-				'lang_permissions'	=> lang('applications'),
 				'lang_save'			=> lang('save'),
 				'msgbox_data'		=> $error_list,
 				'select_size'		=> 5,
@@ -708,9 +714,11 @@
 		 */
 		public function _user_save()
 		{
-			$values							= phpgw::get_var('values', 'string', 'POST');
-			$values['account_groups']		= (array) phpgw::get_var('account_groups', 'int', 'POST');
-			$values['account_permissions']	= phpgw::get_var('account_permissions', 'bool', 'POST');
+			$values									= phpgw::get_var('values', 'string', 'POST');
+			$values['account_groups']				= (array) phpgw::get_var('account_groups', 'int', 'POST');
+			$values['account_permissions']			= phpgw::get_var('account_permissions', 'bool', 'POST');
+			$values['account_permissions_admin']	= phpgw::get_var('account_permissions_admin', 'int', 'POST');
+
 			//FIXME Caeies fix waiting for JSCAL
 			$values['account_expires_year']	= phpgw::get_var('account_expires_year', 'int', 'POST');
 			// we use string here to allow for MMM formatted months
@@ -735,6 +743,7 @@
 					'account_expires_month',
 					'account_expires_day',
 					'account_permissions',
+					'account_permissions_admin',
 					'account_groups'
 				);
 
@@ -916,6 +925,8 @@
 			$apps = createObject('phpgwapi.applications', $account_id ? $account_id : -1);
 			$db_perms = $apps->read_account_specific();
 
+			$apps_admin = $GLOBALS['phpgw']->acl->get_app_list_for_id('admin', phpgwapi_acl::ADD, $account_id);
+
 			$available_apps = $GLOBALS['phpgw_info']['apps'];
 			asort($available_apps);
 			foreach ( $available_apps as $key => $application )
@@ -930,7 +941,6 @@
 				}
 			}
 			asort($perm_display);
-
 			foreach ( $perm_display as $perm )
 			{
 				$checked = false;
@@ -943,9 +953,11 @@
 
 				$app_list[] = array
 				(
-					'app_title'		=> $perm['translated_name'],
-					'checkbox_name'	=> "account_permissions[{$perm['app_name']}]",
-					'checked'		=> $checked
+					'app_title'				=> $perm['translated_name'],
+					'checkbox_name'			=> "account_permissions[{$perm['app_name']}]",
+					'checked'				=> $checked,
+					'checkbox_name_admin'	=> "account_permissions_admin[{$perm['app_name']}]",
+					'checked_admin'			=> in_array($perm['app_name'],$apps_admin)
 				);
 			}
 

Added: people/sigurdne/modules/admin/trunk/js/base/move.js
===================================================================
--- people/sigurdne/modules/admin/trunk/js/base/move.js	                        (rev 0)
+++ people/sigurdne/modules/admin/trunk/js/base/move.js	2010-01-22 09:43:33 UTC (rev 20972)
@@ -0,0 +1,99 @@
+
+			function move(fboxname, tboxname, sboxname, cboxname) {
+				var arrFbox = new Array();
+				var arrTbox = new Array();
+				var arrLookup = new Array();
+				var i;
+
+				fbox = document.body_form.elements[fboxname];
+				tbox = document.body_form.elements[tboxname];
+
+				for (i = 0; i < tbox.options.length; i++) 
+				{
+					arrLookup[tbox.options[i].text] = tbox.options[i].value;
+					arrTbox[i] = tbox.options[i].text;
+				}
+				var fLength = 0;
+				var tLength = arrTbox.length;
+				for(i = 0; i < fbox.options.length; i++) 
+				{
+					arrLookup[fbox.options[i].text] = fbox.options[i].value;
+					if (fbox.options[i].selected && fbox.options[i].value != "") 
+					{
+						arrTbox[tLength] = fbox.options[i].text;
+						tLength++;
+					}
+					else 
+					{
+						arrFbox[fLength] = fbox.options[i].text;
+						fLength++;
+					}
+				}
+				arrFbox.sort();
+				arrTbox.sort();
+				fbox.length = 0;
+				tbox.length = 0;
+
+				var c;
+				for(c = 0; c < arrFbox.length; c++) 
+				{
+					var no = new Option();
+					no.value = arrLookup[arrFbox[c]];
+					no.text = arrFbox[c];
+					fbox[c] = no;
+				}
+				for(c = 0; c < arrTbox.length; c++) 
+				{
+					var no = new Option();
+					no.value = arrLookup[arrTbox[c]];
+					no.text = arrTbox[c];
+					tbox[c] = no;
+				}
+
+				move_cbo(sboxname, cboxname);
+			}
+
+		function move_cbo(sboxname, cboxname) {
+			sbox = document.body_form.elements[sboxname];
+			cbox = document.body_form.elements[cboxname];
+			if(sbox.length > 0)
+			{
+				sel_opt = sbox.options[sbox.selectedIndex].text;
+			}
+			else
+			{
+				sel_opt="";
+			}
+			sbox.length = 0;
+			for(c = 0; c < cbox.length; c++) 
+			{
+				var no = new Option();
+				no.value = cbox[c].value;
+				no.text = cbox[c].text;
+				if(no.text == sel_opt)
+				{
+					i = c;
+				}
+				sbox[c] = no;
+			}
+			if(i>0)
+			{
+				sbox.options[i].selected = true;
+			}
+		}
+
+		function process_list(allboxname, myboxname) {
+			mybox = document.body_form.elements[myboxname];
+			for(c = 0; c < mybox.options.length; c++) 
+			{
+				mybox.options[c].selected = true;
+			}
+		}
+
+		function showHide(sDiv)
+		{
+			var oDiv = document.getElementById(sDiv);
+			if (oDiv)
+				oDiv.style.display = oDiv.style.display == "none" ? "" : "none";
+		}
+

Modified: people/sigurdne/modules/admin/trunk/templates/base/groups.xsl
===================================================================
--- people/sigurdne/modules/admin/trunk/templates/base/groups.xsl	2010-01-17 12:19:45 UTC (rev 20971)
+++ people/sigurdne/modules/admin/trunk/templates/base/groups.xsl	2010-01-22 09:43:33 UTC (rev 20972)
@@ -84,37 +84,70 @@
 <!-- END group_list -->
 
 <!-- BEGIN group_edit -->
-	<xsl:template match="group_edit">
+	<xsl:template match="group_edit" xmlns:php="http://php.net/xsl">
 		<div id="admin_group_edit">
 			<h1><xsl:value-of select="page_title" /></h1>
 			<xsl:if test="msgbox_data != ''">
 				<xsl:call-template name="msgbox"/>
 			</xsl:if>
-			<form action="{edit_url}" method="post">
+
+			<form name='body_form' action="{edit_url}" method="post"  onsubmit="process_list('all_users[]',	'account_user[]')">
 				<div class="yui-navset" id="group_edit_tabview">
 					<xsl:value-of disable-output-escaping="yes" select="tabs" />
 
 						<div class="yui-content">
 
 							<div id="group">
-								<h2><xsl:value-of select="lang_group" /></h2>
+								<h2><xsl:value-of select="php:function('lang', 'group')" /></h2>
 								<input type="hidden" name="values[account_id]" value="{account_id}"/>
 								<ul id="admin_account_form">
 									<li>
-										<label for="account_name"><xsl:value-of select="lang_account_name" /></label>
+										<label for="account_name"><xsl:value-of select="php:function('lang', 'group name')" /></label>
 										<input name="values[account_name]" value="{value_account_name}" id="account_name" /><br class="eol" />
 									</li>
-									<li>
-										<label for="account_user"><xsl:value-of select="lang_include_user" /></label>
-										<select name="account_user[]" id="account_user" multiple="multiple" size="5">
-											<xsl:apply-templates select="guser_list"/>
-										</select><br class="eol" />
-									</li>
 								</ul>
+
+								<table border="0" align="center" width="100%">
+									<tbody align="center">
+										<tr bgcolor="">
+											<td width="45%"><xsl:value-of select="php:function('lang', 'all users')" /></td>
+											<td width="10%"></td>
+											<td width="45%"><xsl:value-of select="php:function('lang', 'members')" /></td>
+										</tr>
+										<tr bgcolor="">
+										<td width="45%">
+											<select multiple ='multiple' size="10" name="all_users[]" style="width:220">
+												<xsl:apply-templates select="guser_list"/>
+											</select>
+										</td>
+										<td width="10%">
+											<table border="0" align="center">
+											<tbody align="center">
+												<tr>
+												<td>
+													<input type="button" onClick="move('all_users[]','account_user[]','','account_user[]')" value="&gt;&gt;"/>
+												</td>
+												</tr>
+												<tr>
+												<td>
+													<input type="button" onClick="move('account_user[]','all_users[]','','account_user[]')" value="&lt;&lt;"/>
+												</td>
+												</tr>
+											</tbody>
+											</table>
+										</td>
+										<td width="45%">
+											<select multiple = 'multiple' size="10" name="account_user[]" id="account_user" style="width:220">
+												<xsl:apply-templates select="member_list"/>
+											</select>
+										</td>
+										</tr>
+									</tbody>
+								</table>	
 							</div>
 
 							<div id="apps">
-								<h2><xsl:value-of select="lang_permissions" /></h2>
+								<h2><xsl:value-of select="php:function('lang', 'applications')" /></h2>
 								<ul class="app_list">
 									<xsl:apply-templates select="app_list" />
 								</ul>
@@ -131,13 +164,16 @@
 
 	<xsl:template match="guser_list">
 		<option value="{account_id}">
-			<xsl:if test="selected != 0">
-				<xsl:attribute name="selected" value="selected" />
-			</xsl:if>
 			<xsl:value-of select="account_name" />
 		</option>
 	</xsl:template>
 
+	<xsl:template match="member_list">
+		<option value="{account_id}">
+			<xsl:value-of select="account_name" />
+		</option>
+	</xsl:template>
+
 	<xsl:template match="app_list">
 		<li>
 			<xsl:attribute name="class">

Modified: people/sigurdne/modules/admin/trunk/templates/base/users.xsl
===================================================================
--- people/sigurdne/modules/admin/trunk/templates/base/users.xsl	2010-01-17 12:19:45 UTC (rev 20971)
+++ people/sigurdne/modules/admin/trunk/templates/base/users.xsl	2010-01-22 09:43:33 UTC (rev 20972)
@@ -143,7 +143,7 @@
 
 <!-- BEGIN account_edit -->
 
-	<xsl:template match="account_edit">
+	<xsl:template match="account_edit" xmlns:php="http://php.net/xsl">
 		<div id="admin_account_edit">
 			<h1><xsl:value-of select="page_title" /></h1>
 			<xsl:if test="msgbox_data != ''">
@@ -242,9 +242,24 @@
 						</div>
 						<div id="apps">
 							<h2><xsl:value-of select="lang_applications" /></h2>
-							<ul class="app_list">
-								<xsl:apply-templates select="app_list" />
-							</ul>
+							<table class="app_list">
+								<thead>
+									<tr>
+										<th>
+											<xsl:value-of select="php:function('lang', 'Application')" />
+										</th>
+										<th>
+										 	<xsl:value-of select="php:function('lang', 'User access')" />
+										</th>
+										<th>
+											<xsl:value-of select="php:function('lang', 'Admin')" />
+										</th>
+									</tr>
+								</thead>
+								<tbody>
+									<xsl:apply-templates select="app_list" />
+								</tbody>
+							</table>
 						</div>
 					</div>
 					<div class="button_group">
@@ -283,7 +298,7 @@
 <!-- BEGIN app_list -->
 
 	<xsl:template match="app_list">
-		<li>
+		<tr>
 			<xsl:attribute name="class">
 				<xsl:choose>
 					<xsl:when test="position() mod 2 = 0">
@@ -294,6 +309,11 @@
 					</xsl:otherwise>
 				</xsl:choose>
 			</xsl:attribute>
+			<td>
+				<xsl:value-of select="app_title"/>
+
+			</td>
+			<td>
 			<input type="checkbox" id="{checkbox_name}" name="{checkbox_name}" value="1">
 				<xsl:choose>
 					<xsl:when test="checked = '1'">
@@ -301,10 +321,17 @@
 					</xsl:when>
 				</xsl:choose>
 			</input>
-			<label for="{checkbox_name}">
-				<xsl:value-of select="app_title" />
-			</label>
-		</li>
+			</td>
+			<td>
+			<input type="checkbox" id="{checkbox_name_admin}" name="{checkbox_name_admin}" value="2">
+				<xsl:choose>
+					<xsl:when test="checked_admin = '1'">
+						<xsl:attribute name="checked" value="checked" />
+					</xsl:when>
+				</xsl:choose>
+			</input>
+			</td>
+		</tr>
 	</xsl:template>
 
 <!-- permissions - applist for view -->