some code-modernisation while looking for the fix to show title of disabled apps

This commit is contained in:
Ralf Becker 2003-09-22 10:58:57 +00:00
parent 27497d4f21
commit 1433761aa6

View File

@ -1,26 +1,27 @@
<?php <?php
/**************************************************************************\ /**************************************************************************\
* phpGroupWare API - Applications manager functions * * phpGroupWare API - Applications manager functions *
* This file written by Mark Peters <skeeter@phpgroupware.org> * * This file written by Mark Peters <skeeter@phpgroupware.org> *
* Copyright (C) 2001 Mark Peters * * Copyright (C) 2001 Mark Peters *
* -------------------------------------------------------------------------* * -------------------------------------------------------------------------*
* This library is part of the phpGroupWare API * * This library is part of the phpGroupWare API *
* http://www.phpgroupware.org/api * * http://www.phpgroupware.org/api *
* ------------------------------------------------------------------------ * * ------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify it * * This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by * * under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, * * the Free Software Foundation; either version 2.1 of the License, *
* or any later version. * * or any later version. *
* This library is distributed in the hope that it will be useful, but * * This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of * * WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. * * See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License * * You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, * * along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/ \**************************************************************************/
/* $Id$ */
/* $Id$ */
/*! /*!
@class applicatons @class applicatons
@abstract functions for managing and installing apps @abstract functions for managing and installing apps
@ -111,25 +112,24 @@
$this->read_installed_apps(); $this->read_installed_apps();
} }
$this->data = Array(); $this->data = Array();
if($this->account_id == False) { return False; } if(!$this->account_id)
$apps = $GLOBALS['phpgw']->acl->get_user_applications($this->account_id);
reset($GLOBALS['phpgw_info']['apps']);
while ($app = each($GLOBALS['phpgw_info']['apps']))
{ {
// $check = $phpgw->acl->check('run',1,$app[0]); return False;
$check = (isset($apps[$app[0]])?$apps[$app[0]]:False); }
if ($check) $apps = $GLOBALS['phpgw']->acl->get_user_applications($this->account_id);
foreach($GLOBALS['phpgw_info']['apps'] as $app => $data)
{
if (isset($apps[$app]) && $apps[$app])
{ {
$this->data[$app[0]] = array( $this->data[$app] = array(
'title' => $GLOBALS['phpgw_info']['apps'][$app[0]]['title'], 'title' => $GLOBALS['phpgw_info']['apps'][$app]['title'],
'name' => $app[0], 'name' => $app,
'enabled' => True, 'enabled' => True,
'status' => $GLOBALS['phpgw_info']['apps'][$app[0]]['status'], 'status' => $GLOBALS['phpgw_info']['apps'][$app]['status'],
'id' => $GLOBALS['phpgw_info']['apps'][$app[0]]['id'] 'id' => $GLOBALS['phpgw_info']['apps'][$app]['id']
); );
} }
} }
reset($this->data);
return $this->data; return $this->data;
} }
@ -140,11 +140,10 @@
*/ */
function read() function read()
{ {
if (count($this->data) == 0) if (!count($this->data))
{ {
$this->read_repository(); $this->read_repository();
} }
reset($this->data);
return $this->data; return $this->data;
} }
/*! /*!
@ -157,14 +156,14 @@
{ {
if(is_array($apps)) if(is_array($apps))
{ {
while($app = each($apps)) foreach($apps as $app)
{ {
$this->data[$app[1]] = array( $this->data[$app] = array(
'title' => $GLOBALS['phpgw_info']['apps'][$app[1]]['title'], 'title' => $GLOBALS['phpgw_info']['apps'][$app]['title'],
'name' => $app[1], 'name' => $app,
'enabled' => True, 'enabled' => True,
'status' => $GLOBALS['phpgw_info']['apps'][$app[1]]['status'], 'status' => $GLOBALS['phpgw_info']['apps'][$app]['status'],
'id' => $GLOBALS['phpgw_info']['apps'][$app[1]]['id'] 'id' => $GLOBALS['phpgw_info']['apps'][$app]['id']
); );
} }
} }
@ -175,10 +174,9 @@
'name' => $apps, 'name' => $apps,
'enabled' => True, 'enabled' => True,
'status' => $GLOBALS['phpgw_info']['apps'][$apps]['status'], 'status' => $GLOBALS['phpgw_info']['apps'][$apps]['status'],
'id' => $GLOBALS['phpgw_info']['apps'][$app[1]]['id'] 'id' => $GLOBALS['phpgw_info']['apps'][$apps]['id']
); );
} }
reset($this->data);
return $this->data; return $this->data;
} }
/*! /*!
@ -193,7 +191,6 @@
{ {
unset($this->data[$appname]); unset($this->data[$appname]);
} }
reset($this->data);
return $this->data; return $this->data;
} }
/*! /*!
@ -204,10 +201,7 @@
*/ */
function update_data($data) function update_data($data)
{ {
reset($data);
$this->data = Array();
$this->data = $data; $this->data = $data;
reset($this->data);
return $this->data; return $this->data;
} }
/*! /*!
@ -218,16 +212,14 @@
function save_repository() function save_repository()
{ {
$num_rows = $GLOBALS['phpgw']->acl->delete_repository("%%", 'run', $this->account_id); $num_rows = $GLOBALS['phpgw']->acl->delete_repository("%%", 'run', $this->account_id);
reset($this->data); foreach($this->data as $app => $data)
while($app = each($this->data))
{ {
if(!$this->is_system_enabled($app[0])) if(!$this->is_system_enabled($app))
{ {
continue; continue;
} }
$GLOBALS['phpgw']->acl->add_repository($app[0],'run',$this->account_id,1); $GLOBALS['phpgw']->acl->add_repository($app,'run',$this->account_id,1);
} }
reset($this->data);
return $this->data; return $this->data;
} }
@ -237,16 +229,15 @@
function app_perms() function app_perms()
{ {
if (count($this->data) == 0) if (!count($this->data))
{ {
$this->read_repository(); $this->read_repository();
} }
@reset($this->data); foreach ($this->data as $app => $data)
while (list ($key) = each ($this->data))
{ {
$app[] = $this->data[$key]['name']; $apps[] = $this->data[$app]['name'];
} }
return $app; return $apps;
} }
function read_account_specific() function read_account_specific()
@ -255,27 +246,22 @@
{ {
$this->read_installed_apps(); $this->read_installed_apps();
} }
$app_list = $GLOBALS['phpgw']->acl->get_app_list_for_id('run',1,$this->account_id); if ($app_list = $GLOBALS['phpgw']->acl->get_app_list_for_id('run',1,$this->account_id))
if(!$app_list)
{ {
reset($this->data); foreach($app_list as $app)
return $this->data;
}
@reset($app_list);
while ($app = each($app_list))
{
if ($this->is_system_enabled($app[1]))
{ {
$this->data[$app[1]] = array( if ($this->is_system_enabled($app))
'title' => $GLOBALS['phpgw_info']['apps'][$app[1]]['title'], {
'name' => $app[1], $this->data[$app] = array(
'enabled' => True, 'title' => $GLOBALS['phpgw_info']['apps'][$app]['title'],
'status' => $GLOBALS['phpgw_info']['apps'][$app[1]]['status'], 'name' => $app,
'id' => $GLOBALS['phpgw_info']['apps'][$app[1]]['id'] 'enabled' => True,
); 'status' => $GLOBALS['phpgw_info']['apps'][$app]['status'],
'id' => $GLOBALS['phpgw_info']['apps'][$app]['id']
);
}
} }
} }
reset($this->data);
return $this->data; return $this->data;
} }
@ -336,16 +322,13 @@
function id2name($id) function id2name($id)
{ {
@reset($GLOBALS['phpgw_info']['apps']); foreach($GLOBALS['phpgw_info']['apps'] as $appname => $app)
while (list($appname,$app) = each($GLOBALS['phpgw_info']['apps']))
{ {
if(intval($app['id']) == intval($id)) if(intval($app['id']) == intval($id))
{ {
@reset($GLOBALS['phpgw_info']['apps']);
return $appname; return $appname;
} }
} }
@reset($GLOBALS['phpgw_info']['apps']);
return ''; return '';
} }
@ -355,10 +338,7 @@
{ {
return $GLOBALS['phpgw_info']['apps'][$appname]['id']; return $GLOBALS['phpgw_info']['apps'][$appname]['id'];
} }
else return 0;
{
return 0;
}
} }
} }
?> ?>