2001-01-19 05:10:45 +01:00
|
|
|
<?php
|
2003-09-22 12:58:57 +02:00
|
|
|
/**************************************************************************\
|
2004-05-05 14:06:13 +02:00
|
|
|
* eGroupWare API - Applications manager functions *
|
2003-09-22 12:58:57 +02:00
|
|
|
* This file written by Mark Peters <skeeter@phpgroupware.org> *
|
|
|
|
* Copyright (C) 2001 Mark Peters *
|
2004-02-03 07:25:36 +01:00
|
|
|
* ------------------------------------------------------------------------ *
|
2004-05-05 14:06:13 +02:00
|
|
|
* This library is part of the eGroupWare API *
|
|
|
|
* http://www.egroupware.org/api *
|
2003-09-22 12:58:57 +02:00
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* 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 *
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, *
|
|
|
|
* or any later version. *
|
|
|
|
* This library is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU Lesser General Public License for more details. *
|
|
|
|
* 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, *
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
2003-03-22 13:29:42 +01:00
|
|
|
|
2005-11-02 12:45:52 +01:00
|
|
|
/**
|
|
|
|
* functions for managing and installing apps
|
|
|
|
*
|
|
|
|
* Author: skeeter
|
|
|
|
*/
|
2001-05-02 14:40:33 +02:00
|
|
|
class applications
|
|
|
|
{
|
|
|
|
var $account_id;
|
|
|
|
var $data = Array();
|
|
|
|
var $db;
|
2005-11-02 12:45:52 +01:00
|
|
|
var $table_name = 'egw_applications';
|
2001-11-19 06:50:08 +01:00
|
|
|
var $public_functions = array(
|
|
|
|
'list_methods' => True,
|
|
|
|
'read' => True
|
|
|
|
);
|
2003-08-28 16:31:11 +02:00
|
|
|
var $xmlrpc_methods = array();
|
2001-01-19 05:10:45 +01:00
|
|
|
|
2001-05-02 14:40:33 +02:00
|
|
|
/**************************************************************************\
|
|
|
|
* Standard constructor for setting $this->account_id *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
2005-11-02 12:45:52 +01:00
|
|
|
/**
|
|
|
|
* standard constructor for setting $this->account_id
|
|
|
|
*
|
|
|
|
* @param $account_id account id
|
|
|
|
*/
|
2001-05-02 14:40:33 +02:00
|
|
|
function applications($account_id = '')
|
|
|
|
{
|
2005-11-20 09:03:06 +01:00
|
|
|
if (is_object($GLOBALS['egw_setup']))
|
|
|
|
{
|
|
|
|
$this->db = clone($GLOBALS['egw_setup']->db);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->db = clone($GLOBALS['egw']->db);
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
$this->db->set_app('phpgwapi');
|
|
|
|
|
2001-05-02 14:40:33 +02:00
|
|
|
$this->account_id = get_account_id($account_id);
|
2003-08-28 16:31:11 +02:00
|
|
|
|
|
|
|
$this->xmlrpc_methods[] = array(
|
|
|
|
'name' => 'read',
|
|
|
|
'description' => 'Return a list of applications the current user has access to'
|
|
|
|
);
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
|
|
|
|
2004-02-03 07:25:36 +01:00
|
|
|
function NOT_list_methods($_type='xmlrpc')
|
2001-11-19 06:50:08 +01:00
|
|
|
{
|
|
|
|
/*
|
2005-11-02 12:45:52 +01:00
|
|
|
This handles introspection or discovery by the logged in client,
|
|
|
|
in which case the input might be an array. The server always calls
|
|
|
|
this function to fill the server dispatch map using a string.
|
2001-11-19 06:50:08 +01:00
|
|
|
*/
|
|
|
|
if (is_array($_type))
|
|
|
|
{
|
|
|
|
$_type = $_type['type'] ? $_type['type'] : $_type[0];
|
|
|
|
}
|
|
|
|
switch($_type)
|
|
|
|
{
|
|
|
|
case 'xmlrpc':
|
|
|
|
$xml_functions = array(
|
|
|
|
'read' => array(
|
|
|
|
'function' => 'read',
|
|
|
|
'signature' => array(array(xmlrpcStruct)),
|
|
|
|
'docstring' => lang('Returns struct of users application access')
|
|
|
|
),
|
|
|
|
'list_methods' => array(
|
|
|
|
'function' => 'list_methods',
|
|
|
|
'signature' => array(array(xmlrpcStruct,xmlrpcString)),
|
|
|
|
'docstring' => lang('Read this list of methods.')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return $xml_functions;
|
|
|
|
break;
|
|
|
|
case 'soap':
|
|
|
|
return $this->soap_functions;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return array();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-02 14:40:33 +02:00
|
|
|
/**************************************************************************\
|
|
|
|
* These are the standard $this->account_id specific functions *
|
|
|
|
\**************************************************************************/
|
2001-01-21 22:34:36 +01:00
|
|
|
|
2005-11-02 12:45:52 +01:00
|
|
|
/**
|
|
|
|
* read from repository
|
|
|
|
*
|
|
|
|
* private should only be called from withing this class
|
|
|
|
*/
|
2001-05-02 14:40:33 +02:00
|
|
|
function read_repository()
|
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
if (!isset($GLOBALS['egw_info']['apps']) || !is_array($GLOBALS['egw_info']['apps']))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
|
|
|
$this->read_installed_apps();
|
|
|
|
}
|
|
|
|
$this->data = Array();
|
2003-09-22 12:58:57 +02:00
|
|
|
if(!$this->account_id)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
$apps = $GLOBALS['egw']->acl->get_user_applications($this->account_id);
|
|
|
|
foreach($GLOBALS['egw_info']['apps'] as $app => $data)
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2003-09-22 12:58:57 +02:00
|
|
|
if (isset($apps[$app]) && $apps[$app])
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2003-09-22 12:58:57 +02:00
|
|
|
$this->data[$app] = array(
|
2005-11-02 12:45:52 +01:00
|
|
|
'title' => $GLOBALS['egw_info']['apps'][$app]['title'],
|
2003-09-22 12:58:57 +02:00
|
|
|
'name' => $app,
|
2003-08-28 16:31:11 +02:00
|
|
|
'enabled' => True,
|
2005-11-02 12:45:52 +01:00
|
|
|
'status' => $GLOBALS['egw_info']['apps'][$app]['status'],
|
|
|
|
'id' => $GLOBALS['egw_info']['apps'][$app]['id']
|
2001-05-02 14:40:33 +02:00
|
|
|
);
|
2004-02-03 07:25:36 +01:00
|
|
|
}
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
|
|
|
return $this->data;
|
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2005-11-02 12:45:52 +01:00
|
|
|
/**
|
|
|
|
* read from the repository
|
|
|
|
*
|
|
|
|
* pubic function that is used to determine what apps a user has rights to
|
|
|
|
*/
|
2001-05-02 14:40:33 +02:00
|
|
|
function read()
|
|
|
|
{
|
2003-09-22 12:58:57 +02:00
|
|
|
if (!count($this->data))
|
2001-11-23 18:56:51 +01:00
|
|
|
{
|
|
|
|
$this->read_repository();
|
|
|
|
}
|
2001-05-02 14:40:33 +02:00
|
|
|
return $this->data;
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
/**
|
|
|
|
* add an app to a user profile
|
|
|
|
*
|
|
|
|
* @discussion
|
|
|
|
* @param $apps array containing apps to add for a user
|
|
|
|
*/
|
2001-05-02 14:40:33 +02:00
|
|
|
function add($apps)
|
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
if(is_array($apps))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2003-09-22 12:58:57 +02:00
|
|
|
foreach($apps as $app)
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2003-09-22 12:58:57 +02:00
|
|
|
$this->data[$app] = array(
|
2005-11-02 12:45:52 +01:00
|
|
|
'title' => $GLOBALS['egw_info']['apps'][$app]['title'],
|
2003-09-22 12:58:57 +02:00
|
|
|
'name' => $app,
|
2003-08-28 16:31:11 +02:00
|
|
|
'enabled' => True,
|
2005-11-02 12:45:52 +01:00
|
|
|
'status' => $GLOBALS['egw_info']['apps'][$app]['status'],
|
|
|
|
'id' => $GLOBALS['egw_info']['apps'][$app]['id']
|
2001-05-02 14:40:33 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif(gettype($apps))
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->data[$apps] = array(
|
2005-11-02 12:45:52 +01:00
|
|
|
'title' => $GLOBALS['egw_info']['apps'][$apps]['title'],
|
2003-08-28 16:31:11 +02:00
|
|
|
'name' => $apps,
|
|
|
|
'enabled' => True,
|
2005-11-02 12:45:52 +01:00
|
|
|
'status' => $GLOBALS['egw_info']['apps'][$apps]['status'],
|
|
|
|
'id' => $GLOBALS['egw_info']['apps'][$apps]['id']
|
2001-05-02 14:40:33 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $this->data;
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
/**
|
|
|
|
* delete an app from a user profile
|
|
|
|
*
|
|
|
|
* @discussion
|
|
|
|
* @param $appname appname to remove
|
|
|
|
*/
|
2001-05-02 14:40:33 +02:00
|
|
|
function delete($appname)
|
|
|
|
{
|
|
|
|
if($this->data[$appname])
|
|
|
|
{
|
|
|
|
unset($this->data[$appname]);
|
|
|
|
}
|
|
|
|
return $this->data;
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
/**
|
|
|
|
* update the array(?)
|
|
|
|
*
|
|
|
|
* @discussion
|
|
|
|
* @param $data update the repository array(?)
|
|
|
|
*/
|
2001-05-02 14:40:33 +02:00
|
|
|
function update_data($data)
|
|
|
|
{
|
|
|
|
$this->data = $data;
|
|
|
|
return $this->data;
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
/**
|
|
|
|
* save the repository
|
|
|
|
*
|
|
|
|
* @discussion
|
|
|
|
*/
|
2001-05-02 14:40:33 +02:00
|
|
|
function save_repository()
|
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
$num_rows = $GLOBALS['egw']->acl->delete_repository("%%", 'run', $this->account_id);
|
2003-09-22 12:58:57 +02:00
|
|
|
foreach($this->data as $app => $data)
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2003-09-22 12:58:57 +02:00
|
|
|
if(!$this->is_system_enabled($app))
|
2001-11-23 18:56:51 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
$GLOBALS['egw']->acl->add_repository($app,'run',$this->account_id,1);
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************\
|
|
|
|
* These are the non-standard $this->account_id specific functions *
|
|
|
|
\**************************************************************************/
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2001-05-02 14:40:33 +02:00
|
|
|
function app_perms()
|
|
|
|
{
|
2003-09-22 12:58:57 +02:00
|
|
|
if (!count($this->data))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
|
|
|
$this->read_repository();
|
|
|
|
}
|
2003-09-22 12:58:57 +02:00
|
|
|
foreach ($this->data as $app => $data)
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2003-09-22 12:58:57 +02:00
|
|
|
$apps[] = $this->data[$app]['name'];
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2003-09-22 12:58:57 +02:00
|
|
|
return $apps;
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
|
2001-05-02 14:40:33 +02:00
|
|
|
function read_account_specific()
|
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
if (!is_array($GLOBALS['egw_info']['apps']))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
|
|
|
$this->read_installed_apps();
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
if ($app_list = $GLOBALS['egw']->acl->get_app_list_for_id('run',1,$this->account_id))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2003-09-22 12:58:57 +02:00
|
|
|
foreach($app_list as $app)
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2003-09-22 12:58:57 +02:00
|
|
|
if ($this->is_system_enabled($app))
|
|
|
|
{
|
|
|
|
$this->data[$app] = array(
|
2005-11-02 12:45:52 +01:00
|
|
|
'title' => $GLOBALS['egw_info']['apps'][$app]['title'],
|
2003-09-22 12:58:57 +02:00
|
|
|
'name' => $app,
|
|
|
|
'enabled' => True,
|
2005-11-02 12:45:52 +01:00
|
|
|
'status' => $GLOBALS['egw_info']['apps'][$app]['status'],
|
|
|
|
'id' => $GLOBALS['egw_info']['apps'][$app]['id']
|
2003-09-22 12:58:57 +02:00
|
|
|
);
|
|
|
|
}
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->data;
|
|
|
|
}
|
2001-01-19 05:10:45 +01:00
|
|
|
|
2001-05-02 14:40:33 +02:00
|
|
|
/**************************************************************************\
|
|
|
|
* These are the generic functions. Not specific to $this->account_id *
|
|
|
|
\**************************************************************************/
|
2001-01-21 02:26:23 +01:00
|
|
|
|
2005-11-02 12:45:52 +01:00
|
|
|
/**
|
|
|
|
* populate array with a list of installed apps
|
|
|
|
*
|
|
|
|
*/
|
2001-05-02 14:40:33 +02:00
|
|
|
function read_installed_apps()
|
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
$this->db->select($this->table_name,'*','app_enabled != 0',__LINE__,__FILE__,false,'ORDER BY app_order ASC');
|
|
|
|
while ($this->db->next_record())
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
$title = $app_name = $this->db->f('app_name');
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2005-11-02 12:45:52 +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
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
$GLOBALS['egw_info']['apps'][$this->db->f('app_name')] = Array(
|
|
|
|
'title' => $title,
|
|
|
|
'name' => $this->db->f('app_name'),
|
|
|
|
'enabled' => True,
|
|
|
|
'status' => $this->db->f('app_enabled'),
|
|
|
|
'id' => (int)$this->db->f('app_id'),
|
|
|
|
'order' => (int)$this->db->f('app_order'),
|
|
|
|
'version' => $this->db->f('app_version')
|
|
|
|
);
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* check if an app is enabled
|
|
|
|
*
|
|
|
|
* @param $appname name of the app to check for
|
|
|
|
*/
|
2001-05-02 14:40:33 +02:00
|
|
|
function is_system_enabled($appname)
|
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
if(!is_array($GLOBALS['egw_info']['apps']))
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
|
|
|
$this->read_installed_apps();
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
if ($GLOBALS['egw_info']['apps'][$appname]['enabled'])
|
2001-05-02 14:40:33 +02:00
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2001-10-21 12:49:29 +02:00
|
|
|
function id2name($id)
|
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
foreach($GLOBALS['egw_info']['apps'] as $appname => $app)
|
2001-10-21 12:49:29 +02:00
|
|
|
{
|
2003-12-20 19:26:24 +01:00
|
|
|
if((int)$app['id'] == (int)$id)
|
2001-10-21 12:49:29 +02:00
|
|
|
{
|
|
|
|
return $appname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
2004-02-03 07:25:36 +01:00
|
|
|
|
2001-10-21 12:49:29 +02:00
|
|
|
function name2id($appname)
|
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
if(is_array($GLOBALS['egw_info']['apps'][$appname]))
|
2001-10-21 12:49:29 +02:00
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
return $GLOBALS['egw_info']['apps'][$appname]['id'];
|
2001-10-21 12:49:29 +02:00
|
|
|
}
|
2003-09-22 12:58:57 +02:00
|
|
|
return 0;
|
2001-10-21 12:49:29 +02:00
|
|
|
}
|
2001-05-02 14:40:33 +02:00
|
|
|
}
|