- phpgw --> egw

- some php5 stuff (clone of db object)
- partialy new db-functions
This commit is contained in:
Ralf Becker 2005-06-10 20:40:57 +00:00
parent ba42b6a9da
commit ec6a4600e8
8 changed files with 313 additions and 335 deletions

View File

@ -14,7 +14,9 @@
class bo_acl
{
/*! @var $permissions Holds alls permissions for resources of user */
/**
* @var $permissions Holds alls permissions for resources of user
*/
var $permissions;
var $acl;
@ -30,14 +32,14 @@
function bo_acl($session=False)
{
define('PHPGW_ACL_CAT_ADMIN',64);
define('PHPGW_ACL_DIRECT_BOOKING',128);
// define('PHPGW_ACL_CUSTOM_3',256);
define('EGW_ACL_CAT_ADMIN',64);
define('EGW_ACL_DIRECT_BOOKING',128);
// define('EGW_ACL_CUSTOM_3',256);
$this->so = CreateObject('resources.so_acl');
$this->permissions = $this->so->get_permissions($GLOBALS['phpgw_info']['user']['account_id'],true);
$this->egw_cats = createobject('phpgwapi.categories');
$this->accounts = $GLOBALS['phpgw']->accounts->get_list();
$this->so =& CreateObject('resources.so_acl');
$this->permissions = $this->so->get_permissions($GLOBALS['egw_info']['user']['account_id'],true);
$this->egw_cats =& createobject('phpgwapi.categories');
$this->accounts = $GLOBALS['egw']->accounts->get_list();
$this->debug = False;
//all this is only needed when called from uiacl.
@ -61,14 +63,14 @@
}
}
/*!
@function get_cats
@abstract get list of cats where current user has given rights
@author Cornelius Weiß <egw@von-und-zu-weiss.de>
@param int $perm_type one of PHPGW_ACL_READ, PHPGW_ACL_ADD, PHPGW_ACL_EDIT, PHPGW_ACL_DELETE, PHPGW_ACL_DIRECT_BOOKING
@return array cat_id => cat_name
TODO mark subcats and so on!
*/
/**
* get list of cats where current user has given rights
*
* @author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param int $perm_type one of EGW_ACL_READ, EGW_ACL_ADD, EGW_ACL_EDIT, EGW_ACL_DELETE, EGW_ACL_DIRECT_BOOKING
* @return array cat_id => cat_name
* TODO mark subcats and so on!
*/
function get_cats($perm_type)
{
$cats = $this->egw_cats->return_sorted_array(0,False,'','','',!$type);
@ -80,7 +82,7 @@
{
$s .= '&nbsp;';
}
$s .= $GLOBALS['phpgw']->strip_html($cat['name']);
$s .= $GLOBALS['egw']->strip_html($cat['name']);
if ($cat['app_name'] == 'phpgw')
{
$s .= '&nbsp;&lt;' . lang('Global') . '&gt;';
@ -96,32 +98,32 @@
}
/*!
@function get_cat_name
@abstract gets name of category
@author Lukas Weiß <wnz.gh05t@users.sourceforge.net>
@param int $cat_id
@return mixed name of category
*/
/**
* gets name of category
*
* @author Lukas Wei<EFBFBD> <wnz.gh05t@users.sourceforge.net>
* @param int $cat_id
* @return mixed name of category
*/
function get_cat_name($cat_id)
{
$cat = $this->egw_cats->return_single($cat_id);
return $cat[0]['name'];
$cat = $this->egw_cats->return_single($cat_id);
return $cat[0]['name'];
}
/*!
@function get_cat_admin
@abstract gets userid of admin for given category
@author Cornelius Weiß <egw@von-und-zu-weiss.de>
@param int $cat_id
@return int userid of cat admin
*/
/**
* gets userid of admin for given category
*
* @author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param int $cat_id
* @return int userid of cat admin
*/
function get_cat_admin($cat_id)
{
$cat_rights = $this->get_rights($cat_id);
foreach ($cat_rights as $userid => $right)
{
if ($right & PHPGW_ACL_CAT_ADMIN)
if ($right & EGW_ACL_CAT_ADMIN)
{
return $userid;
}
@ -129,25 +131,26 @@
return lang('none');
}
/*!
@function is_permitted
@abstract cheks one of the following rights for current user:
@abstract PHPGW_ACL_READ, PHPGW_ACL_ADD, PHPGW_ACL_EDIT, PHPGW_ACL_DELETE, PHPGW_ACL_DIRECT_BOOKING
@param int $cat_id
@param int $right
@return bool user is permitted or not for right
*/
/**
* cheks one of the following rights for current user:
*
* EGW_ACL_READ, EGW_ACL_ADD, EGW_ACL_EDIT, EGW_ACL_DELETE, EGW_ACL_DIRECT_BOOKING
*
* @param int $cat_id
* @param int $right
* @return bool user is permitted or not for right
*/
function is_permitted($cat_id,$right)
{
return $this->permissions['L'.$cat_id] & $right;
}
/*!
@function get_rights
@abstract gets all rights from all user for given cat
@param int $cat_id
@return array userid => right
*/
/**
* gets all rights from all user for given cat
*
* @param int $cat_id
* @return array userid => right
*/
function get_rights($cat_id)
{
return $this->so->get_rights('L'.$cat_id);
@ -165,12 +168,12 @@
'limit' => $this->limit,
);
if($this->debug) { echo '<br>Read:'; _debug_array($data); }
$GLOBALS['phpgw']->session->appsession('session_data','resources_acl',$data);
$GLOBALS['egw']->session->appsession('session_data','resources_acl',$data);
}
function read_sessiondata()
{
$data = $GLOBALS['phpgw']->session->appsession('session_data','resources_acl');
$data = $GLOBALS['egw']->session->appsession('session_data','resources_acl');
if($this->debug) { echo '<br>Read:'; _debug_array($data); }
$this->start = $data['start'];
@ -194,13 +197,13 @@
$account_id = $account['account_id'];
//write implies read
$rights = in_array($account_id,$writecat) ?
(PHPGW_ACL_READ | PHPGW_ACL_ADD | PHPGW_ACL_EDIT | PHPGW_ACL_DELETE) :
(in_array($account_id,$readcat) ? PHPGW_ACL_READ : False);
$rights = in_array($account_id,$bookcat) ? ($rights | PHPGW_ACL_DIRECT_BOOKING) : $rights;
$rights = in_array($account_id,$admincat) ? ($rights | PHPGW_ACL_CAT_ADMIN) : $rights;
(EGW_ACL_READ | EGW_ACL_ADD | EGW_ACL_EDIT | EGW_ACL_DELETE) :
(in_array($account_id,$readcat) ? EGW_ACL_READ : False);
$rights = in_array($account_id,$bookcat) ? ($rights | EGW_ACL_DIRECT_BOOKING) : $rights;
$rights = in_array($account_id,$admincat) ? ($rights | EGW_ACL_CAT_ADMIN) : $rights;
if ($rights)
{
$GLOBALS['phpgw']->acl->add_repository('resources','L'.$cat_id,$account_id,$rights);
$GLOBALS['egw']->acl->add_repository('resources','L'.$cat_id,$account_id,$rights);
}
}
}

View File

@ -22,21 +22,21 @@ class bo_resources
function bo_resources()
{
$this->so = CreateObject('resources.so_resources');
$this->acl = CreateObject('resources.bo_acl');
$this->so =& CreateObject('resources.so_resources');
$this->acl =& CreateObject('resources.bo_acl');
$this->cats = $this->acl->egw_cats;
$this->vfs = CreateObject('phpgwapi.vfs');
$this->link = CreateObject('infolog.bolink');
$this->conf = CreateObject('phpgwapi.config');
$this->vfs =& CreateObject('phpgwapi.vfs');
$this->link =& CreateObject('infolog.bolink');
$this->conf =& CreateObject('phpgwapi.config');
$this->conf->read_repository();
}
/*!
@function get_rows
@abstract get rows for resources list
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
*/
/**
* get rows for resources list
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
*/
function get_rows($query,&$rows,&$readonlys)
{
$query['search'] = $query['search'] ? $query['search'] : '*';
@ -44,7 +44,7 @@ class bo_resources
$criteria = array( 'name' => $query['search'],
'short_description' => $query['search']
);
$cats = $query['filter'] ? array($query['filter'] => '') : $this->acl->get_cats(PHPGW_ACL_READ);
$cats = $query['filter'] ? array($query['filter'] => '') : $this->acl->get_cats(EGW_ACL_READ);
$accessory_of = $query['view_accs_of'] ? $query['view_accs_of'] : -1;
$rows = array( 0 => array( 'id' => '',
@ -60,19 +60,19 @@ class bo_resources
$order_by = $query['order'] ? $query['order'].' '. $query['sort'] : '';
$nr = $this->so->search($criteria,$cats,&$rows,$accessory_of,$order_by,$offset=$query['start'],$num_rows=0);
$nr = $this->so->search($criteria,$cats,$rows,$accessory_of,$order_by,$offset=$query['start'],$num_rows=0);
foreach($rows as $num => $resource)
{
if (!$this->acl->is_permitted($resource['cat_id'],PHPGW_ACL_EDIT))
if (!$this->acl->is_permitted($resource['cat_id'],EGW_ACL_EDIT))
{
$readonlys["edit[$resource[id]]"] = true;
}
if (!$this->acl->is_permitted($resource['cat_id'],PHPGW_ACL_DELETE))
if (!$this->acl->is_permitted($resource['cat_id'],EGW_ACL_DELETE))
{
$readonlys["delete[$resource[id]]"] = true;
}
if ((!$this->acl->is_permitted($resource['cat_id'],PHPGW_ACL_ADD)) || $accessory_of != -1)
if ((!$this->acl->is_permitted($resource['cat_id'],EGW_ACL_ADD)) || $accessory_of != -1)
{
$readonlys["new_acc[$resource[id]]"] = true;
}
@ -106,16 +106,16 @@ class bo_resources
return $nr;
}
/*!
@function read
@abstract reads a resource exept binary datas
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@param int $id resource id
@return array with key => value or false if not found or allowed
*/
/**
* reads a resource exept binary datas
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param int $id resource id
* @return array with key => value or false if not found or allowed
*/
function read($id)
{
if(!$this->acl->is_permitted($this->so->get_value('cat_id',$id),PHPGW_ACL_READ))
if(!$this->acl->is_permitted($this->so->get_value('cat_id',$id),EGW_ACL_READ))
{
echo lang('You are not permitted to get information about this resource!') . '<br>';
echo lang('Notify your administrator to correct this situation') . '<br>';
@ -124,16 +124,16 @@ class bo_resources
return $this->so->read($id);
}
/*!
@function save
@abstract saves a resource. pictures are saved in vfs
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@param array $resource array with key => value of all needed datas
@return string msg if somthing went wrong; nothing if all right
*/
/**
* saves a resource. pictures are saved in vfs
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param array $resource array with key => value of all needed datas
* @return string msg if somthing went wrong; nothing if all right
*/
function save($resource)
{
if(!$this->acl->is_permitted($resource['cat_id'],PHPGW_ACL_EDIT))
if(!$this->acl->is_permitted($resource['cat_id'],EGW_ACL_EDIT))
{
return lang('You are not permitted to edit this reource!');
}
@ -199,12 +199,12 @@ class bo_resources
return $this->so->save($resource) ? false : lang('Something went wrong by saving resource');
}
/*!
@function delete
@abstract deletes resource including pictures and links
@autor Lukas Weiss <wnz_gh05t@users.sourceforge.net>
@param int $id id of resource
*/
/**
* deletes resource including pictures and links
*
* @author Lukas Weiss <wnz_gh05t@users.sourceforge.net>
* @param int $id id of resource
*/
function delete($id)
{
$this->remove_picture($id);
@ -212,19 +212,19 @@ class bo_resources
return $this->so->delete(array('id'=>$id)) ? false : lang('Something went wrong by deleting resource');
}
/*!
@function get_acc_list
@abstract gets list of accessories for resource
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@param int $id id of resource
@return array
*/
/**
* gets list of accessories for resource
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param int $id id of resource
* @return array
*/
function get_acc_list($id)
{
if($id < 1){return;}
$cat_id = $this->so->get_value('cat_id',$id);
$data[0] = array('id' => '', 'name' => '');
$this->so->search(array('name' => '*'),array($cat_id => ''),&$data,$accessory_of=$id,$order_by='',$offset=false,$num_rows=-1);
$this->so->search(array('name' => '*'),array($cat_id => ''),$data,$accessory_of=$id,$order_by='',$offset=false,$num_rows=-1);
foreach($data as $num => $resource)
{
$acc_list[$resource['id']] = $resource['name'];
@ -232,18 +232,17 @@ class bo_resources
return $acc_list;
}
/*!
@function link_query
@syntax link_query( $pattern )
@author Cornelius Weiß <egw@von-und-zu-weiss.de>
@abstract query infolog for entries matching $pattern
*/
/**
* @author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* query infolog for entries matching $pattern
*
*/
function link_query( $pattern )
{
$criteria = array('name' => $pattern,'short_description' => $pattern);
$cats = $this->acl->get_cats(PHPGW_ACL_READ);
$cats = $this->acl->get_cats(EGW_ACL_READ);
$data[0] = array('id' => '','name' => '', 'short_description' => '');
$this->so->search($criteria,$cats,&$data,$accessory_of=-1,$order_by='',$offset=false,$num_rows=-1);
$this->so->search($criteria,$cats,$data,$accessory_of=-1,$order_by='',$offset=false,$num_rows=-1);
foreach($data as $num => $resource)
{
@ -255,12 +254,11 @@ class bo_resources
return $list;
}
/*!
@function link_title
@syntax link_title( $id )
@author Cornelius Weiß <egw@von-und-zu-weiss.de>
@abstract get title for an infolog entry identified by $id
*/
/**
* @author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* get title for an infolog entry identified by $id
*
*/
function link_title( $resource )
{
if (!is_array($resource) && $resource > 0)
@ -271,15 +269,15 @@ class bo_resources
return $title ? $title : false;
}
/*!
@function save_picture
@abstract resizes and saves an pictures in vfs
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@param array $file array with key => value
@param int $resource_id
@return mixed string with msg if somthing went wrong; nothing if all right
TODO make thumb an picture sizes choosable by preferences
*/
/**
* resizes and saves an pictures in vfs
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param array $file array with key => value
* @param int $resource_id
* @return mixed string with msg if somthing went wrong; nothing if all right
* TODO make thumb an picture sizes choosable by preferences
*/
function save_picture($file,$resouce_id)
{
// test upload dir
@ -316,7 +314,7 @@ class bo_resources
$dst_img_size = array( 0 => 320, 1 => 240);
$thumb_size = array( 0 => 64, 1 => 48);
$tmp_dir = $GLOBALS['phpgw_info']['server']['temp_dir'].'/';
$tmp_dir = $GLOBALS['egw_info']['server']['temp_dir'].'/';
if($src_img_size[0] > 64 || $src_img_size[1] > 48)
{
$f = $thumb_size[0] / $src_img_size[0];
@ -357,7 +355,7 @@ class bo_resources
'attributes' => array (
'mime_type' => 'image/jpeg',
'comment' => 'picture of resource no.'.$resouce_id,
'app' => $GLOBALS['phpgw_info']['flags']['currentapp']
'app' => $GLOBALS['egw_info']['flags']['currentapp']
)));
$this->vfs->mv(array(
'from' => $tmp_dir.$resouce_id.'.thumb.jpg',
@ -370,20 +368,19 @@ class bo_resources
'attributes' => array (
'mime_type' => 'image/jpeg',
'comment' => 'thumbnail of resource no.'.$resouce_id,
'app' => $GLOBALS['phpgw_info']['flags']['currentapp']
'app' => $GLOBALS['egw_info']['flags']['currentapp']
)));
$this->vfs->override_acl = 0;
return;
}
/*!
@function get_picture
@abstact get resource picture either from vfs or from symlink
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@param int $id id of resource
@param bool $size false = thumb, true = full pic
@return string url of picture
*/
/**
* get resource picture either from vfs or from symlink
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param int $id id of resource
* @param bool $size false = thumb, true = full pic
* @return string url of picture
*/
function get_picture($id=0,$size=false)
{
if ($id > 0)
@ -394,7 +391,7 @@ class bo_resources
switch($src)
{
case 'own_src':
$picture = $this->conf->config_data['dont_use_vfs'] ? $GLOBALS['phpgw_info']['server']['webserver_url'] : 'vfs:';
$picture = $this->conf->config_data['dont_use_vfs'] ? $GLOBALS['egw_info']['server']['webserver_url'] : 'vfs:';
$picture .= $size ? $this->pictures_dir.$id.'.jpg' : $this->thumbs_dir.$id.'.jpg';
break;
case 'cat_src':
@ -402,24 +399,25 @@ class bo_resources
$picture = unserialize($picture['data']);
if($picture['icon'])
{
$picture = $GLOBALS['phpgw_info']['server']['webserver_url'].'/phpgwapi/images/'.$picture['icon'];
$picture = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/images/'.$picture['icon'];
break;
}
case 'gen_src':
default :
$picture = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->resource_icons;
$picture = $GLOBALS['egw_info']['server']['webserver_url'].$this->resource_icons;
$picture .= strstr($src,'.') ? $src : 'generic.png';
}
return $picture;
}
/*!
@fuction remove_picture
@abstract removes picture from vfs
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@param int $id id of resource
@return bool succsess or not
*/
/**
* remove_picture
* removes picture from vfs
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param int $id id of resource
* @return bool succsess or not
*/
function remove_picture($id)
{
$vfs_data = array('string' => $this->pictures_dir.$id.'.jpg','relatives' => array(RELATIVE_ROOT));
@ -433,16 +431,17 @@ class bo_resources
$this->vfs->override_acl = 0;
}
/*!
@fuction get_genpicturelist
@abstract gets all pictures from 'generic picutres dir' in selectbox style for eTemplate
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@return array directory contens in eTemplates selectbox style
*/
/**
* get_genpicturelist
* gets all pictures from 'generic picutres dir' in selectbox style for eTemplate
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @return array directory contens in eTemplates selectbox style
*/
function get_genpicturelist()
{
$icons['generic.png'] = lang('gernal resource');
$dir = dir(PHPGW_SERVER_ROOT.$this->resource_icons);
$dir = dir(EGW_SERVER_ROOT.$this->resource_icons);
while($file = $dir->read())
{
if (preg_match('/\\.(png|gif|jpe?g)$/i',$file) && $file != 'generic.png')

View File

@ -24,20 +24,20 @@ class resources_hooks
if ($location == 'sidebox_menu')
{
$file = array(
'resources list' => $GLOBALS['phpgw']->link('/index.php',array(
'resources list' => $GLOBALS['egw']->link('/index.php',array(
'menuaction' => 'resources.ui_resources.index' )),
/*'add' => $GLOBALS['phpgw']->link('/index.php',array(
/*'add' => $GLOBALS['egw']->link('/index.php',array(
'menuaction' => 'resources.ui_resources.edit' ))*/
);
display_sidebox($appname,$GLOBALS['phpgw_info']['apps']['resources']['title'].' '.lang('Menu'),$file);
display_sidebox($appname,$GLOBALS['egw_info']['apps']['resources']['title'].' '.lang('Menu'),$file);
}
/* if ($GLOBALS['phpgw_info']['user']['apps']['preferences'] && $location != 'admin')
/* if ($GLOBALS['egw_info']['user']['apps']['preferences'] && $location != 'admin')
{
$file = array(
'Preferences' => $GLOBALS['phpgw']->link('/preferences/preferences.php','appname='.$appname),
'Grant Access' => $GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app='.$appname),
'Edit Categories' => $GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uicategories.index&cats_app=' . $appname . '&cats_level=True&global_cats=True')
'Preferences' => $GLOBALS['egw']->link('/preferences/preferences.php','appname='.$appname),
'Grant Access' => $GLOBALS['egw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app='.$appname),
'Edit Categories' => $GLOBALS['egw']->link('/index.php','menuaction=preferences.uicategories.index&cats_app=' . $appname . '&cats_level=True&global_cats=True')
);
if ($location == 'preferences')
{
@ -49,20 +49,20 @@ class resources_hooks
}
}
*/
if ($GLOBALS['phpgw_info']['user']['apps']['admin'] && $location != 'preferences')
if ($GLOBALS['egw_info']['user']['apps']['admin'] && $location != 'preferences')
{
$file = Array(
'Site configuration' => $GLOBALS['phpgw']->link('/index.php',array(
'Site configuration' => $GLOBALS['egw']->link('/index.php',array(
'menuaction' => 'resources.ui_resources.admin' )),
'Global Categories' => $GLOBALS['phpgw']->link('/index.php',array(
'Global Categories' => $GLOBALS['egw']->link('/index.php',array(
'menuaction' => 'admin.uicategories.index',
'appname' => $appname,
'global_cats'=> True)),
'Configure Access Permissions' => $GLOBALS['phpgw']->link('/index.php',
'Configure Access Permissions' => $GLOBALS['egw']->link('/index.php',
'menuaction=resources.ui_acl.acllist')
// 'Custom fields, typ and status' => $GLOBALS['phpgw']->link('/index.php',array(
// 'Custom fields, typ and status' => $GLOBALS['egw']->link('/index.php',array(
// 'menuaction' => 'infolog.uicustomfields.edit')),
// 'CSV-Import' => $GLOBALS['phpgw']->link('/infolog/csv_import.php')
// 'CSV-Import' => $GLOBALS['egw']->link('/infolog/csv_import.php')
);
if ($location == 'admin')
{

View File

@ -18,7 +18,8 @@
function so_acl()
{
copyobj($GLOBALS['phpgw']->db,$this->db);
$this->db = clone($GLOBALS['egw']->db);
$this->db->set_app('resources');
}
function get_rights($location)
@ -39,20 +40,20 @@
$this->db->query($sql,__LINE__,__FILE__);
}
/*!
@function get_permission
@abstract gets permissions for resources of user
@discussion This function is needed, cause eGW api dosn't provide a usefull function for that topic!
@discussion Using api-functions for that, would resault bad performace :-(
@autor autor of news_admin ?
@param int $user user_id we want to get perms for
@param bool $inc_groups get rights due to groupmembership of user
*/
/**
* gets permissions for resources of user
*
* This function is needed, cause eGW api dosn't provide a usefull function for that topic!
* Using api-functions for that, would resault bad performace :-(
* autor of news_admin ?
*
* @param int $user user_id we want to get perms for
* @param bool $inc_groups get rights due to groupmembership of user
*
*/
function get_permissions($user, $inc_groups)
{
$groups = $GLOBALS['phpgw']->acl->get_location_list_for_id('phpgw_group', 1, $user);
$groups = $GLOBALS['egw']->acl->get_location_list_for_id('phpgw_group', 1, $user);
$result = array();
$sql = 'SELECT acl_location, acl_rights FROM phpgw_acl ';
$sql .= "WHERE acl_appname = 'resources' ";

View File

@ -17,25 +17,26 @@ class so_resources
{
function so_resources()
{
$this->db = $GLOBALS['phpgw']->db;
$this->db = clone($GLOBALS['egw']->db);
$this->db->set_app('resources');
$this->rs_table = 'egw_resources';
}
/*!
@function search
@abstract searches db for rows matching searchcriteria and categories
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@discussion '*' is replaced with sql-wildcard '%'
@param array $criteria array of key => value for search. (or'ed together)
@param array $cats array of cat_id => cat_name to be searched
@param &array $data reference of data array with cols to return in first row ( key => '')
@param int $accessory_of find accessories of id, default -1 = show all exept accessories
@param string $order_by fieldnames + {ASC|DESC} separated by colons ','
@param int $offset row to start from, default 0
@param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
@return int number of matching rows
*/
/**
* searches db for rows matching searchcriteria and categories
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* '*' is replaced with sql-wildcard '%'
* @param array $criteria array of key => value for search. (or'ed together)
* @param array $cats array of cat_id => cat_name to be searched
* @param &array $data reference of data array with cols to return in first row ( key => '')
* @param int $accessory_of find accessories of id, default -1 = show all exept accessories
* @param string $order_by fieldnames + {ASC|DESC} separated by colons ','
* @param int $offset row to start from, default 0
* @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']
*
* @return int number of matching rows
*/
function search($criteria,$cats,&$data,$accessory_of=-1,$order_by='',$offset=false,$num_rows=-1)
{
$select = implode(',',array_keys($data[0]));
@ -48,7 +49,7 @@ class so_resources
$where .= " ) ";
foreach ((array)$cats as $cat_id => $cat_name)
{
$wherecats .= ($wherecats ? " OR " : " AND ( " ) .'cat_id' . "='".$cat_id."'";
$wherecats .= ($wherecats ? " OR " : " AND ( " ) .'cat_id' . "=".(int)$cat_id;
}
$wherecats .= $wherecats ? " ) " : "";
$whereacc = " AND (accessory_of ='".$accessory_of."')";
@ -63,7 +64,7 @@ class so_resources
}
if($num_rows==0)
{
$num_rows = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
$num_rows = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
}
for ($n = 1; $this->db->next_record() && $n!=$num_rows+1; ++$n)
{
@ -73,81 +74,56 @@ class so_resources
return $nr;
}
/*!
@function get_value
@abstract gets the value of $key from resource of $id
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@param string $key key of value to get
@param int $id resource id
@return mixed value of key and resource, false if key or id not found.
*/
/**
* gets the value of $key from resource of $id
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param string $key key of value to get
* @param int $id resource id
* @return mixed value of key and resource, false if key or id not found.
*/
function get_value($key,$id)
{
if($this->db->query( "SELECT ". $key . " FROM ".$this->rs_table." WHERE id = ".$id,__LINE__,__FILE__))
if($this->db->select($this->rs_table,$key,array('id' => $id),__LINE__,__FILE__))
{
$this->db->next_record();
(array)$value = $this->db->row();
$value = $this->db->row(row);
return $value[$key];
}
return false;
}
function delete($id)
{
$this->db->delete($this->rs_table,$id,__LINE__,__FILE__);
return true;
}
{
$this->db->delete($this->rs_table,$id,__LINE__,__FILE__);
return true;
}
/*!
@function read
@abstract reads a resource exept binary datas
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@param int $id resource id
@return array with key => value or false if not found
*/
/**
* reads a resource exept binary datas
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param int $id resource id
* @return array with key => value or false if not found
*/
function read($id)
{
$tabledef = $this->db->metadata($table=$this->rs_table,$full=false);
foreach($tabledef as $n => $fielddef)
if($this->db->select($this->rs_table,'*',array('id' => $id),__LINE__,__FILE__))
{
if(!$fielddef['binary'])
{
$readfields[$n] = $fielddef['name'];
}
}
if($this->db->query( "SELECT ". implode(',',$readfields) . " FROM ".$this->rs_table." WHERE id = ".$id,__LINE__,__FILE__))
{
$this->db->next_record();
return $this->db->row();
return $this->db->row(true);
}
return false;
}
/*!
@function save
@abstract saves a resource including binary datas
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@param array $resource key => value
@return mixed id of resource if all right, false if fale
*/
/**
* saves a resource including binary datas
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param array $resource key => value
* @return mixed id of resource if all right, false if fale
*/
function save($resource)
{
$where = array('id' => $resource['id']);
$tabledef = $this->db->metadata($table=$this->rs_table,$full=false);
foreach($tabledef as $n => $fielddef)
{
if(isset($resource[$fielddef['name']]))
{
$data[$fielddef['name']] = $resource[$fielddef['name']];
}
elseif($resource['id'] > 0) //we need to reload old data! bug in db::update?
{
$data[$fielddef['name']] = $this->get_value($fielddef['name'],$resource['id']);
}
}
return $this->db->insert($this->rs_table,$data,$where,__LINE__,__FILE__) ? $this->db->get_last_insert_id($this->rs_table, 'id') : false;
return $this->db->insert($this->rs_table,$resource,array('id' => $resource['id']),__LINE__,__FILE__) ? $this->db->get_last_insert_id($this->rs_table, 'id') : false;
}
}

View File

@ -28,9 +28,9 @@
function ui_acl()
{
$this->bo = createobject('resources.bo_acl',True);
$this->accounts = $GLOBALS['phpgw']->accounts->get_list();
$this->nextmatchs = createobject('phpgwapi.nextmatchs');
$this->bo =& createobject('resources.bo_acl',True);
$this->accounts = $GLOBALS['egw']->accounts->get_list();
$this->nextmatchs =& createobject('phpgwapi.nextmatchs');
$this->start = $this->bo->start;
$this->query = $this->bo->query;
$this->order = $this->bo->order;
@ -40,17 +40,17 @@
function acllist()
{
if (!$GLOBALS['phpgw']->acl->check('run',1,'admin'))
if (!$GLOBALS['egw']->acl->check('run',1,'admin'))
{
$this->deny();
}
if ($_POST['btnDone'])
{
$GLOBALS['phpgw']->redirect_link('/admin/index.php');
$GLOBALS['egw']->redirect_link('/admin/index.php');
}
$GLOBALS['phpgw']->common->phpgw_header();
$GLOBALS['egw']->common->egw_header();
echo parse_navbar();
if ($_POST['btnSave'])
@ -61,10 +61,10 @@
}
}
$GLOBALS['phpgw']->template->set_file('acl', 'acl.tpl');
$GLOBALS['phpgw']->template->set_block('acl','cat_list','Cblock');
$GLOBALS['phpgw']->template->set_var(array(
'title' => $GLOBALS['phpgw_info']['apps']['resources']['title'] . ' - ' . lang('Configure Access Permissions'),
$GLOBALS['egw']->template->set_file('acl', 'acl.tpl');
$GLOBALS['egw']->template->set_block('acl','cat_list','Cblock');
$GLOBALS['egw']->template->set_var(array(
'title' => $GLOBALS['egw_info']['apps']['resources']['title'] . ' - ' . lang('Configure Access Permissions'),
'lang_search' => lang('Search'),
'lang_save' => lang('Save'),
'lang_done' => lang('Done'),
@ -78,11 +78,11 @@
$left = $this->nextmatchs->left('/index.php',$this->start,$this->bo->catbo->total_records,'menuaction=resources.uiacl.acllist');
$right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->catbo->total_records,'menuaction=resources.uiacl.acllist');
$GLOBALS['phpgw']->template->set_var(array(
$GLOBALS['egw']->template->set_var(array(
'left' => $left,
'right' => $right,
'lang_showing' => $this->nextmatchs->show_hits($this->bo->catbo->total_records,$this->start),
'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
'th_bg' => $GLOBALS['egw_info']['theme']['th_bg'],
'sort_cat' => $this->nextmatchs->show_sort_order(
$this->sort,'cat_name','cat_name','/index.php',lang('Category'),'&menuaction=resources.uiacl.acllist'
),
@ -95,18 +95,18 @@
$this->rights = $this->bo->get_rights($cat['id']);
$tr_color = $this->nextmatchs->alternate_row_color($tr_color);
$GLOBALS['phpgw']->template->set_var(array(
$GLOBALS['egw']->template->set_var(array(
'tr_color' => $tr_color,
'catname' => $cat['name'],
'catid' => $cat['id'],
'read' => $this->selectlist(PHPGW_ACL_READ),
'write' => $this->selectlist(PHPGW_ACL_ADD),
'book' =>$this->selectlist(PHPGW_ACL_DIRECT_BOOKING),
'admin' => '<option value="" selected="1">'.lang('choose categories admin').'</option>'.$this->selectlist(PHPGW_ACL_CAT_ADMIN,true)
'read' => $this->selectlist(EGW_ACL_READ),
'write' => $this->selectlist(EGW_ACL_ADD),
'book' =>$this->selectlist(EGW_ACL_DIRECT_BOOKING),
'admin' => '<option value="" selected="1">'.lang('choose categories admin').'</option>'.$this->selectlist(EGW_ACL_CAT_ADMIN,true)
));
$GLOBALS['phpgw']->template->parse('Cblock','cat_list',True);
$GLOBALS['egw']->template->parse('Cblock','cat_list',True);
}
$GLOBALS['phpgw']->template->pfp('out','acl',True);
$GLOBALS['egw']->template->pfp('out','acl',True);
}
function selectlist($right,$users_only=false)
@ -117,7 +117,7 @@
if(!($users_only && $account['account_lastname'] == 'Group'))
{
$selectlist .= '<option value="' . $account['account_id'] . '"';
if($this->rights[$account['account_id']] & $right)
if($this->rights[$account['account_id']] & $right)
{
$selectlist .= ' selected="selected"';
}
@ -131,7 +131,7 @@
function deny()
{
echo '<p><center><b>'.lang('Access not permitted').'</b></center>';
$GLOBALS['phpgw']->common->phpgw_exit(True);
$GLOBALS['egw']->common->egw_exit(True);
}
}
?>

View File

@ -23,30 +23,30 @@ class ui_resources
'writeLangFile' => True
);
/*!
@function ui_resources
@abstract constructor of class ui_resources
*/
/**
* constructor of class ui_resources
*
*/
function ui_resources()
{
// print_r($GLOBALS['phpgw_info']); die();
$this->tmpl = CreateObject('etemplate.etemplate','resources.show');
$this->bo = CreateObject('resources.bo_resources');
// print_r($GLOBALS['egw_info']); die();
$this->tmpl =& CreateObject('etemplate.etemplate','resources.show');
$this->bo =& CreateObject('resources.bo_resources');
if(!@is_object($GLOBALS['phpgw']->js))
if(!@is_object($GLOBALS['egw']->js))
{
$GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
$GLOBALS['egw']->js =& CreateObject('phpgwapi.javascript');
}
}
/*!
@function index
@abstract main resources list.
@autor Cornelius Weiß <egw@von-und-zu-weiss.de>
@param array $content content from eTemplate callback
FIXME don't translate cats in nextmach
*/
/**
* main resources list.
*
* Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* @param array $content content from eTemplate callback
*
* FIXME don't translate cats in nextmach
*/
function index($content='')
{
if (is_array($content))
@ -56,7 +56,7 @@ class ui_resources
if (isset($content['nm']['rows']))
{
unset($sessiondata['rows']);
$GLOBALS['phpgw']->session->appsession('session_data','resources_index_nm',$sessiondata);
$GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$sessiondata);
unset($content['nm']['rows']['checkbox']);
switch (key($content['nm']['rows']))
@ -73,7 +73,7 @@ class ui_resources
case 'view_acc':
list($id) = each($content['nm']['rows']['view_acc']);
$sessiondata['view_accs_of'] = $id;
$GLOBALS['phpgw']->session->appsession('session_data','resources_index_nm',$sessiondata);
$GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$sessiondata);
return $this->index();
case 'view':
list($id) = each($content['nm']['rows']['view']);
@ -84,39 +84,39 @@ class ui_resources
}
if (isset($content['add'])) // note: this isn't used as add is a popup now!
{
$GLOBALS['phpgw']->session->appsession('session_data','resources_index_nm',$sessiondata);
$GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$sessiondata);
return $content['nm']['view_accs_of'] ? $this->edit(array('id' => 0, 'accessory_of' => $content['nm']['view_accs_of'])) : $this->edit(0);
}
if (isset($content['back']))
{
unset($sessiondata['view_accs_of']);
$GLOBALS['phpgw']->session->appsession('session_data','resources_index_nm',$sessiondata);
$GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$sessiondata);
return $this->index();
}
}
else
{
$content = array();
$content['nm'] = $GLOBALS['phpgw']->session->appsession('session_data','resources_index_nm');
$content['nm'] = $GLOBALS['egw']->session->appsession('session_data','resources_index_nm');
}
$content['nm']['get_rows'] = 'resources.bo_resources.get_rows';
$content['nm']['no_filter'] = False;
$content['nm']['filter_label'] = 'Category';
$content['nm']['filter_help'] = lang('Select a category'); // is this used???
$content['nm']['options-filter']= array('0'=>lang('all categories'))+(array)$this->bo->acl->get_cats(PHPGW_ACL_READ);
$content['nm']['options-filter']= array('0'=>lang('all categories'))+(array)$this->bo->acl->get_cats(EGW_ACL_READ);
$content['nm']['no_filter2'] = true;
$content['nm']['filter_no_lang'] = true;
$content['nm']['no_cat'] = true;
// check if user is permitted to add resources
if(!$this->bo->acl->get_cats(PHPGW_ACL_ADD))
if(!$this->bo->acl->get_cats(EGW_ACL_ADD))
{
$no_button['add'] = true;
}
$no_button['back'] = true;
$no_button['add_sub'] = true;
$GLOBALS['phpgw_info']['flags']['app_header'] = lang('resources');
$GLOBALS['egw_info']['flags']['app_header'] = lang('resources');
if($content['nm']['view_accs_of'])
{
@ -128,22 +128,21 @@ class ui_resources
$no_button['back'] = false;
$no_button['add'] = true;
$no_button['add_sub'] = false;
$GLOBALS['phpgw_info']['flags']['app_header'] = lang('resources') . ' - ' . lang('accessories of ') . $master['name'] .
$GLOBALS['egw_info']['flags']['app_header'] = lang('resources') . ' - ' . lang('accessories of ') . $master['name'] .
($master['short_description'] ? ' [' . $master['short_description'] . ']' : '');
}
$preserv = $content;
$GLOBALS['phpgw']->session->appsession('session_data','resources_index_nm',$content['nm']);
$GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$content['nm']);
$this->tmpl->read('resources.show');
$this->tmpl->exec('resources.ui_resources.index',$content,$sel_options,$no_button,$preserv);
}
/*!
@function edit
@syntax edit($content=0)
@author Cornelius Weiß <egw@von-und-zu-weiss.de>
@abstract invokes add or edit dialog for resources
@param $content Content from the eTemplate Exec call or id on inital call
*/
/**
* @author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
* invokes add or edit dialog for resources
*
* @param $content Content from the eTemplate Exec call or id on inital call
*/
function edit($content=0,$accessory_of = -1)
{
if (is_array($content))
@ -170,17 +169,17 @@ class ui_resources
{
return $this->edit($content);
}
$js = "opener.location.href='".$GLOBALS['phpgw']->link('/index.php',
$js = "opener.location.href='".$GLOBALS['egw']->link('/index.php',
array('menuaction' => 'resources.ui_resources.index'))."';";
$js .= 'window.close();';
echo "<html><body><script>$js</script></body></html>\n";
$GLOBALS['phpgw']->common->phpgw_exit();
$GLOBALS['egw']->common->egw_exit();
}
elseif($content['cancel'])
{
$js .= 'window.close();';
echo "<html><body><script>$js</script></body></html>\n";
$GLOBALS['phpgw']->common->phpgw_exit();
$GLOBALS['egw']->common->egw_exit();
}
}
else
@ -208,7 +207,7 @@ class ui_resources
$content['useable'] = $content['useable'] ? $content['useable'] : 1;
$sel_options['gen_src_list'] = $this->bo->get_genpicturelist();
$sel_options['cat_id'] = $this->bo->acl->get_cats(PHPGW_ACL_ADD);
$sel_options['cat_id'] = $this->bo->acl->get_cats(EGW_ACL_ADD);
$sel_options['cat_id'] = count($sel_options['cat_id']) == 1 ? $sel_options['cat_id'] : array('' => lang('select one')) + $sel_options['cat_id'];
if($accessory_of > 0 || $content['accessory_of'] > 0)
@ -226,11 +225,11 @@ class ui_resources
}
/*!
@function admin
@abstract adminsection of resources
@author Cornelius Weiß <egw@von-und-zu-weiss.de>
*/
/**
* adminsection of resources
*
* @author Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
*/
function admin($content='')
{
if(is_array($content))
@ -242,7 +241,7 @@ class ui_resources
}
else
{
return $GLOBALS['phpgw']->redirect_link('/admin/index.php');
return $GLOBALS['egw']->redirect_link('/admin/index.php');
}
}
$content = $this->bo->conf->read_repository();
@ -250,12 +249,12 @@ class ui_resources
$this->tmpl->exec('resources.ui_resources.admin',$content,$sel_options,$no_button,$preserv);
}
/*!
@function show
@abstract showes a single resource
@param int $id resource id
@author Lukas Weiss <wnz.gh05t@users.sourceforge.net>
*/
/**
* showes a single resource
*
* @param int $id resource id
* @author Lukas Weiss <wnz.gh05t@users.sourceforge.net>
*/
function show($id=0)
{
if (isset($_GET['id'])) $id = $_GET['id'];
@ -265,9 +264,9 @@ class ui_resources
$content['gen_src_list'] = strstr($content['picture_src'],'.') ? $content['picture_src'] : false;
$content['picture_src'] = strstr($content['picture_src'],'.') ? 'gen_src' : $content['picture_src'];
$content['link_to'] = array(
'to_id' => $id,
'to_app' => 'resources'
);
'to_id' => $id,
'to_app' => 'resources'
);
$content['resource_picture'] = $this->bo->get_picture($content['id'],$content['picture_src'],$size=true);
$content['quantity'] = $content['quantity'] ? $content['quantity'] : 1;
@ -275,8 +274,8 @@ class ui_resources
$content['quantity'] = ($content['useable'] == $content['quantity']) ? $content['quantity'] : $content['quantity'].' ('.lang('useable ').$content['useable'].')';
//$sel_options['gen_src_list'] = $this->bo->get_genpicturelist();
//$sel_options['gen_src_list'] = $this->bo->get_genpicturelist();
$content['cat_name'] = $this->bo->acl->get_cat_name($content['cat_id']);
$content['cat_admin'] = $this->bo->acl->get_cat_admin($content['cat_id']);
@ -297,12 +296,12 @@ class ui_resources
}
/*!
@function delete
@abstract deletes a resource
@param int $id resource id
@author Lukas Weiss <wnz.gh05t@users.sourceforge.net>
*/
/**
* deletes a resource
*
* @param int $id resource id
* @author Lukas Weiss <wnz.gh05t@users.sourceforge.net>
*/
function delete($id)
{
$this->bo->delete($id);

View File

@ -12,12 +12,12 @@
\**************************************************************************/
$GLOBALS['phpgw_info']['flags'] = array(
$GLOBALS['egw_info']['flags'] = array(
'currentapp' => 'resources',
'noheader' => True,
'nonavbar' => True
);
include('../header.inc.php');
$GLOBALS['phpgw']->redirect_link('/index.php','menuaction=resources.ui_resources.index');
$GLOBALS['egw']->redirect_link('/index.php','menuaction=resources.ui_resources.index');