2001-01-19 05:10:45 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare API - Applications manager functions *
|
|
|
|
* This file written by Mark Peters <skeeter@phpgroupware.org> *
|
|
|
|
* Copyright (C) 2001 Mark Peters *
|
|
|
|
* -------------------------------------------------------------------------*
|
|
|
|
* This library is part of the phpGroupWare API *
|
|
|
|
* http://www.phpgroupware.org/api *
|
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* 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$ */
|
2001-03-13 05:58:57 +01:00
|
|
|
/*!
|
|
|
|
@class applicatons
|
|
|
|
@abstract functions for managing and installing apps
|
|
|
|
@discussion Author: skeeter
|
|
|
|
*/
|
2001-01-19 05:10:45 +01:00
|
|
|
class applications
|
|
|
|
{
|
|
|
|
var $account_id;
|
2001-02-03 11:48:41 +01:00
|
|
|
var $data = Array();
|
2001-01-28 13:07:20 +01:00
|
|
|
var $db;
|
2001-01-19 05:10:45 +01:00
|
|
|
|
2001-02-03 11:48:41 +01:00
|
|
|
/**************************************************************************\
|
|
|
|
* Standard constructor for setting $this->account_id *
|
|
|
|
\**************************************************************************/
|
2001-03-13 05:58:57 +01:00
|
|
|
/*!
|
|
|
|
@function applications
|
|
|
|
@abstract standard constructor for setting $this->account_id
|
|
|
|
@param $account_id account id
|
|
|
|
*/
|
2001-02-06 13:06:17 +01:00
|
|
|
function applications($account_id = False)
|
2001-01-27 17:32:09 +01:00
|
|
|
{
|
2001-01-26 12:58:00 +01:00
|
|
|
global $phpgw, $phpgw_info;
|
2001-01-28 13:07:20 +01:00
|
|
|
$this->db = $phpgw->db;
|
2001-02-08 07:05:39 +01:00
|
|
|
if ($account_id != False){ $this->account_id = $account_id; }
|
2001-01-26 12:58:00 +01:00
|
|
|
}
|
2001-01-21 22:34:36 +01:00
|
|
|
|
2001-02-03 11:48:41 +01:00
|
|
|
/**************************************************************************\
|
|
|
|
* These are the standard $this->account_id specific functions *
|
|
|
|
\**************************************************************************/
|
2001-03-13 05:58:57 +01:00
|
|
|
/*!
|
|
|
|
@function read_repository
|
|
|
|
@abstract read from repository
|
|
|
|
@discussion private should only be called from withing this class
|
|
|
|
*/
|
2001-02-03 11:48:41 +01:00
|
|
|
function read_repository()
|
2001-01-28 13:07:20 +01:00
|
|
|
{
|
2001-01-26 12:58:00 +01:00
|
|
|
global $phpgw, $phpgw_info;
|
2001-02-11 21:03:35 +01:00
|
|
|
if (gettype($phpgw_info['apps']) != 'array') {
|
2001-01-28 13:07:20 +01:00
|
|
|
$this->read_installed_apps();
|
2001-01-26 12:58:00 +01:00
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
$this->data = Array();
|
2001-03-11 23:38:19 +01:00
|
|
|
if($this->account_id == False) { return False; }
|
|
|
|
$apps = $phpgw->acl->get_user_applications($this->account_id);
|
2001-02-11 21:03:35 +01:00
|
|
|
reset($phpgw_info['apps']);
|
|
|
|
while ($app = each($phpgw_info['apps'])) {
|
2001-03-11 23:38:19 +01:00
|
|
|
// $check = $phpgw->acl->check('run',1,$app[0]);
|
|
|
|
$check = $apps[$app[0]];
|
2001-01-28 13:07:20 +01:00
|
|
|
if ($check) {
|
2001-02-11 21:03:35 +01:00
|
|
|
$this->data[$app[0]] = array('title' => $phpgw_info['apps'][$app[0]]['title'], 'name' => $app[0], 'enabled' => True, 'status' => $phpgw_info['apps'][$app[0]]['status']);
|
2001-01-28 13:07:20 +01:00
|
|
|
}
|
2001-01-19 05:10:45 +01:00
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
2001-03-13 05:58:57 +01:00
|
|
|
/*!
|
|
|
|
@function read()
|
|
|
|
@abstract read from the repository
|
|
|
|
@discussion pubic function that is used to determine what apps a user has rights to
|
|
|
|
*/
|
2001-02-03 11:48:41 +01:00
|
|
|
function read() {
|
|
|
|
if (count($this->data) == 0){ $this->read_repository(); }
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
2001-03-13 05:58:57 +01:00
|
|
|
/*!
|
|
|
|
@function add
|
|
|
|
@abstract add an app to a user profile
|
|
|
|
@discussion
|
|
|
|
@param $apps array containing apps to add for a user
|
|
|
|
*/
|
2001-02-03 11:48:41 +01:00
|
|
|
function add($apps) {
|
|
|
|
global $phpgw_info;
|
2001-02-11 21:03:35 +01:00
|
|
|
if(gettype($apps) == 'array') {
|
2001-02-03 11:48:41 +01:00
|
|
|
while($app = each($apps)) {
|
2001-02-11 21:03:35 +01:00
|
|
|
$this->data[$app[1]] = array('title' => $phpgw_info['apps'][$app[1]]['title'], 'name' => $app[1], 'enabled' => True, 'status' => $phpgw_info['apps'][$app[1]]['status']);
|
2001-02-03 11:48:41 +01:00
|
|
|
}
|
2001-02-08 07:05:39 +01:00
|
|
|
} elseif(gettype($apps)) {
|
2001-02-11 21:03:35 +01:00
|
|
|
$this->data[$apps] = array('title' => $phpgw_info['apps'][$apps]['title'], 'name' => $apps, 'enabled' => True, 'status' => $phpgw_info['apps'][$apps]['status']);
|
2001-02-03 11:48:41 +01:00
|
|
|
}
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
2001-03-13 05:58:57 +01:00
|
|
|
/*!
|
|
|
|
@function delete
|
|
|
|
@abstract delete an app from a user profile
|
|
|
|
@discussion
|
|
|
|
@param $appname appname to remove
|
|
|
|
*/
|
2001-02-03 11:48:41 +01:00
|
|
|
function delete($appname) {
|
|
|
|
if($this->data[$appname]) {
|
|
|
|
unset($this->data[$appname]);
|
|
|
|
}
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
2001-01-19 05:10:45 +01:00
|
|
|
}
|
2001-03-13 05:58:57 +01:00
|
|
|
/*!
|
|
|
|
@function update_data
|
|
|
|
@abstract update the array(?)
|
|
|
|
@discussion
|
|
|
|
@param $data update the repository array(?)
|
|
|
|
*/
|
2001-02-03 11:48:41 +01:00
|
|
|
function update_data($data) {
|
|
|
|
reset($data);
|
|
|
|
$this->data = Array();
|
|
|
|
$this->data = $data;
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
2001-03-13 05:58:57 +01:00
|
|
|
/*!
|
|
|
|
@function save_repository()
|
|
|
|
@abstract save the repository
|
|
|
|
@discussion
|
|
|
|
*/
|
2001-02-03 11:48:41 +01:00
|
|
|
function save_repository(){
|
|
|
|
global $phpgw;
|
2001-02-08 07:05:39 +01:00
|
|
|
$num_rows = $phpgw->acl->delete_repository("%%", 'run', $this->account_id);
|
2001-02-03 11:48:41 +01:00
|
|
|
reset($this->data);
|
|
|
|
while($app = each($this->data)) {
|
|
|
|
if(!$this->is_system_enabled($app[0])) { continue; }
|
2001-02-22 05:42:01 +01:00
|
|
|
$phpgw->acl->add_repository($app[0],'run',$this->account_id,1);
|
2001-02-03 11:48:41 +01:00
|
|
|
}
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************\
|
|
|
|
* These are the non-standard $this->account_id specific functions *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
2001-01-28 13:07:20 +01:00
|
|
|
function app_perms()
|
|
|
|
{
|
2001-01-26 12:58:00 +01:00
|
|
|
global $phpgw, $phpgw_info;
|
2001-02-03 11:48:41 +01:00
|
|
|
if (count($this->data) == 0) {
|
|
|
|
$this->read_repository();
|
2001-01-26 12:58:00 +01:00
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
@reset($this->data);
|
|
|
|
while (list ($key) = each ($this->data)) {
|
2001-02-11 21:03:35 +01:00
|
|
|
$app[] = $this->data[$key]['name'];
|
2001-01-21 02:26:23 +01:00
|
|
|
}
|
2001-01-28 13:07:20 +01:00
|
|
|
return $app;
|
2001-01-19 05:10:45 +01:00
|
|
|
}
|
|
|
|
|
2001-01-28 13:07:20 +01:00
|
|
|
function read_account_specific() {
|
|
|
|
global $phpgw, $phpgw_info;
|
2001-02-08 07:05:39 +01:00
|
|
|
if (gettype($phpgw_info['apps']) != 'array') {
|
2001-01-26 12:58:00 +01:00
|
|
|
$this->read_installed_apps();
|
|
|
|
}
|
2001-02-08 07:05:39 +01:00
|
|
|
$app_list = $phpgw->acl->get_app_list_for_id('run',1,$this->account_id);
|
2001-02-10 20:59:23 +01:00
|
|
|
if(!$app_list) {
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
2001-02-08 07:05:39 +01:00
|
|
|
@reset($app_list);
|
|
|
|
while ($app = each($app_list)) {
|
|
|
|
if ($this->is_system_enabled($app[1])) {
|
|
|
|
$this->data[$app[1]] = array('title' => $phpgw_info['apps'][$app[1]]['title'], 'name' => $app[1], 'enabled' => True, 'status' => $phpgw_info['apps'][$app[1]]['status']);
|
2001-01-28 13:07:20 +01:00
|
|
|
}
|
2001-01-21 02:26:23 +01:00
|
|
|
}
|
2001-02-03 11:48:41 +01:00
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
2001-01-21 02:26:23 +01:00
|
|
|
}
|
|
|
|
|
2001-02-03 11:48:41 +01:00
|
|
|
/**************************************************************************\
|
|
|
|
* These are the generic functions. Not specific to $this->account_id *
|
|
|
|
\**************************************************************************/
|
2001-03-13 05:58:57 +01:00
|
|
|
/*!
|
|
|
|
@function read_installed_apps()
|
|
|
|
@abstract populate array with a list of installed apps
|
|
|
|
*/
|
2001-01-28 13:07:20 +01:00
|
|
|
function read_installed_apps(){
|
2001-02-03 11:48:41 +01:00
|
|
|
global $phpgw_info;
|
2001-02-08 21:11:13 +01:00
|
|
|
$this->db->query("select * from phpgw_applications where app_enabled != '0' order by app_order asc",__LINE__,__FILE__);
|
2001-01-28 13:07:20 +01:00
|
|
|
if($this->db->num_rows()) {
|
|
|
|
while ($this->db->next_record()) {
|
2001-02-09 05:35:57 +01:00
|
|
|
$name = $this->db->f('app_name');
|
|
|
|
$title = $this->db->f('app_title');
|
|
|
|
$status = $this->db->f('app_enabled');
|
|
|
|
$phpgw_info['apps'][$name] = array('title' => $title, 'name' => $name, 'enabled' => True, 'status' => $status);
|
2001-01-21 22:34:36 +01:00
|
|
|
}
|
2001-01-19 14:16:30 +01:00
|
|
|
}
|
2001-01-19 05:10:45 +01:00
|
|
|
}
|
2001-03-13 05:58:57 +01:00
|
|
|
/*!
|
|
|
|
@function is_system_enabled
|
|
|
|
@abstract check if an app is enabled
|
|
|
|
@param $appname name of the app to check for
|
|
|
|
*/
|
2001-01-28 13:07:20 +01:00
|
|
|
function is_system_enabled($appname){
|
2001-01-30 03:13:38 +01:00
|
|
|
global $phpgw_info;
|
2001-02-09 05:35:57 +01:00
|
|
|
if(gettype($phpgw_info['apps']) != 'array') {
|
2001-01-28 13:07:20 +01:00
|
|
|
$this->read_installed_apps();
|
|
|
|
}
|
2001-02-09 05:35:57 +01:00
|
|
|
if ($phpgw_info['apps'][$appname]['enabled']) {
|
2001-01-28 13:07:20 +01:00
|
|
|
return True;
|
|
|
|
}else{
|
|
|
|
return False;
|
2001-01-19 05:10:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-08 07:05:39 +01:00
|
|
|
?>
|