2001-01-19 05:10:45 +01:00
|
|
|
<?php
|
2008-03-15 16:52:27 +01:00
|
|
|
/**
|
|
|
|
* eGroupWare API - Applications
|
2008-08-18 11:00:19 +02:00
|
|
|
*
|
2008-03-15 16:52:27 +01:00
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Mark Peters <skeeter@phpgroupware.org>
|
|
|
|
* Copyright (C) 2001 Mark Peters
|
|
|
|
* @license http://opensource.org/licenses/lgpl-license.php LGPL - GNU Lesser General Public License
|
|
|
|
* @package api
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* functions for managing and installing apps
|
|
|
|
*
|
|
|
|
* Author: skeeter
|
|
|
|
*/
|
|
|
|
class applications
|
|
|
|
{
|
|
|
|
var $account_id;
|
|
|
|
var $data = Array();
|
|
|
|
/**
|
|
|
|
* Reference to the global db class
|
|
|
|
*
|
|
|
|
* @var egw_db
|
|
|
|
*/
|
|
|
|
var $db;
|
|
|
|
var $table_name = 'egw_applications';
|
|
|
|
|
2003-09-22 12:58:57 +02:00
|
|
|
/**************************************************************************\
|
2008-03-15 16:52:27 +01:00
|
|
|
* Standard constructor for setting $this->account_id *
|
2003-09-22 12:58:57 +02:00
|
|
|
\**************************************************************************/
|
|
|
|
|
2005-11-02 12:45:52 +01:00
|
|
|
/**
|
2008-03-15 16:52:27 +01:00
|
|
|
* standard constructor for setting $this->account_id
|
2005-11-02 12:45:52 +01:00
|
|
|
*
|
2008-03-15 16:52:27 +01:00
|
|
|
* @param $account_id account id
|
2005-11-02 12:45:52 +01:00
|
|
|
*/
|
2016-02-15 12:17:09 +01:00
|
|
|
function __construct($account_id = '')
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
if (is_object($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']->db))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
$this->db = $GLOBALS['egw_setup']->db;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->db = $GLOBALS['egw']->db;
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
$this->account_id = get_account_id($account_id);
|
|
|
|
}
|
2001-11-19 06:50:08 +01:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
/**************************************************************************\
|
|
|
|
* These are the standard $this->account_id specific functions *
|
|
|
|
\**************************************************************************/
|
2001-01-21 22:34:36 +01:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
/**
|
|
|
|
* read from repository
|
|
|
|
*
|
|
|
|
* private should only be called from withing this class
|
|
|
|
*/
|
|
|
|
function read_repository()
|
|
|
|
{
|
|
|
|
if (!isset($GLOBALS['egw_info']['apps']) || !is_array($GLOBALS['egw_info']['apps']))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
$this->read_installed_apps();
|
|
|
|
}
|
|
|
|
$this->data = Array();
|
|
|
|
if(!$this->account_id)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$apps = $GLOBALS['egw']->acl->get_user_applications($this->account_id);
|
|
|
|
foreach($GLOBALS['egw_info']['apps'] as $app => $data)
|
|
|
|
{
|
|
|
|
if (isset($apps[$app]) && $apps[$app])
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-08-18 11:00:19 +02:00
|
|
|
$this->data[$app] =& $GLOBALS['egw_info']['apps'][$app];
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
return $this->data;
|
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
/**
|
|
|
|
* read from the repository
|
|
|
|
*
|
|
|
|
* pubic function that is used to determine what apps a user has rights to
|
|
|
|
*/
|
|
|
|
function read()
|
|
|
|
{
|
|
|
|
if (!count($this->data))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
$this->read_repository();
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* add an app to a user profile
|
|
|
|
*
|
|
|
|
* @discussion
|
|
|
|
* @param $apps array containing apps to add for a user
|
|
|
|
*/
|
|
|
|
function add($apps)
|
|
|
|
{
|
|
|
|
if(is_array($apps))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
foreach($apps as $app)
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-08-18 11:00:19 +02:00
|
|
|
$this->data[$app] =& $GLOBALS['egw_info']['apps'][$app];
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
elseif(gettype($apps))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-08-18 11:00:19 +02:00
|
|
|
$this->data[$apps] =& $GLOBALS['egw_info']['apps'][$apps];
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* delete an app from a user profile
|
|
|
|
*
|
|
|
|
* @discussion
|
|
|
|
* @param $appname appname to remove
|
|
|
|
*/
|
|
|
|
function delete($appname)
|
|
|
|
{
|
|
|
|
if($this->data[$appname])
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
unset($this->data[$appname]);
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* update the array(?)
|
|
|
|
*
|
|
|
|
* @discussion
|
|
|
|
* @param $data update the repository array(?)
|
|
|
|
*/
|
|
|
|
function update_data($data)
|
|
|
|
{
|
|
|
|
$this->data = $data;
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* save the repository
|
|
|
|
*
|
|
|
|
* @discussion
|
|
|
|
*/
|
|
|
|
function save_repository()
|
|
|
|
{
|
2016-03-31 21:41:39 +02:00
|
|
|
$GLOBALS['egw']->acl->delete_repository("%%", 'run', $this->account_id);
|
2008-03-15 16:52:27 +01:00
|
|
|
foreach($this->data as $app => $data)
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
if(!$this->is_system_enabled($app))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
continue;
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
$GLOBALS['egw']->acl->add_repository($app,'run',$this->account_id,1);
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
return $this->data;
|
|
|
|
}
|
2001-05-02 14:40:33 +02:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
/**************************************************************************\
|
|
|
|
* These are the non-standard $this->account_id specific functions *
|
|
|
|
\**************************************************************************/
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
function app_perms()
|
|
|
|
{
|
|
|
|
if (!count($this->data))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
$this->read_repository();
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
foreach ($this->data as $app => $data)
|
|
|
|
{
|
|
|
|
$apps[] = $this->data[$app]['name'];
|
|
|
|
}
|
|
|
|
return $apps;
|
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
function read_account_specific()
|
|
|
|
{
|
|
|
|
if (!is_array($GLOBALS['egw_info']['apps']))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
$this->read_installed_apps();
|
|
|
|
}
|
2016-03-31 21:41:39 +02:00
|
|
|
if (($app_list = $GLOBALS['egw']->acl->get_app_list_for_id('run',1,$this->account_id)))
|
2008-03-15 16:52:27 +01:00
|
|
|
{
|
|
|
|
foreach($app_list as $app)
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
if ($this->is_system_enabled($app))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-08-18 11:00:19 +02:00
|
|
|
$this->data[$app] =& $GLOBALS['egw_info']['apps'][$app];
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
return $this->data;
|
|
|
|
}
|
2001-01-19 05:10:45 +01:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
/**************************************************************************\
|
|
|
|
* These are the generic functions. Not specific to $this->account_id *
|
|
|
|
\**************************************************************************/
|
2001-01-21 02:26:23 +01:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
/**
|
|
|
|
* populate array with a list of installed apps
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function read_installed_apps()
|
|
|
|
{
|
2010-01-27 06:22:41 +01:00
|
|
|
foreach($this->db->select($this->table_name,'*',false,__LINE__,__FILE__,false,'ORDER BY app_order ASC') as $row)
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
$title = $app_name = $row['app_name'];
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
if (@is_array($GLOBALS['egw_info']['user']['preferences']) && ($t = lang($app_name)) != $app_name.'*')
|
|
|
|
{
|
|
|
|
$title = $t;
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
$GLOBALS['egw_info']['apps'][$app_name] = Array(
|
|
|
|
'title' => $title,
|
|
|
|
'name' => $app_name,
|
|
|
|
'enabled' => True,
|
|
|
|
'status' => $row['app_enabled'],
|
|
|
|
'id' => (int)$row['app_id'],
|
|
|
|
'order' => (int)$row['app_order'],
|
|
|
|
'version' => $row['app_version'],
|
2013-10-15 11:36:23 +02:00
|
|
|
'index' => $row['app_index'],
|
2008-08-18 11:00:19 +02:00
|
|
|
'icon' => $row['app_icon'],
|
|
|
|
'icon_app'=> $row['app_icon_app'],
|
2008-03-15 16:52:27 +01:00
|
|
|
);
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
/**
|
|
|
|
* check if an app is enabled
|
|
|
|
*
|
|
|
|
* @param $appname name of the app to check for
|
|
|
|
*/
|
|
|
|
function is_system_enabled($appname)
|
|
|
|
{
|
|
|
|
if(!is_array($GLOBALS['egw_info']['apps']))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
$this->read_installed_apps();
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
if ($GLOBALS['egw_info']['apps'][$appname]['enabled'])
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
function id2name($id)
|
|
|
|
{
|
|
|
|
foreach($GLOBALS['egw_info']['apps'] as $appname => $app)
|
2001-10-21 12:49:29 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
if((int)$app['id'] == (int)$id)
|
2001-10-21 12:49:29 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
return $appname;
|
2001-10-21 12:49:29 +02:00
|
|
|
}
|
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
return '';
|
|
|
|
}
|
2004-02-03 07:25:36 +01:00
|
|
|
|
2008-03-15 16:52:27 +01:00
|
|
|
function name2id($appname)
|
|
|
|
{
|
|
|
|
if(is_array($GLOBALS['egw_info']['apps'][$appname]))
|
2001-10-21 12:49:29 +02:00
|
|
|
{
|
2008-03-15 16:52:27 +01:00
|
|
|
return $GLOBALS['egw_info']['apps'][$appname]['id'];
|
2001-10-21 12:49:29 +02:00
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
return 0;
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2008-03-15 16:52:27 +01:00
|
|
|
}
|