[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/inc class.boentity.inc.php, 1.12 class.soadm
From: |
sigurdne |
Subject: |
[Phpgroupware-cvs] property/inc class.boentity.inc.php, 1.12 class.soadmin_entity.inc.php, 1.10 |
Date: |
Thu, 10 Nov 2005 22:40:00 +0100 |
Update of property/inc
Modified Files:
Branch: MAIN
class.boentity.inc.php lines: +635 -647
class.soadmin_entity.inc.php lines: +1354 -1354
Log Message:
no message
====================================================
Index: property/inc/class.boentity.inc.php
diff -u property/inc/class.boentity.inc.php:1.11
property/inc/class.boentity.inc.php:1.12
--- property/inc/class.boentity.inc.php:1.11 Wed Nov 9 13:09:22 2005
+++ property/inc/class.boentity.inc.php Thu Nov 10 21:40:42 2005
@@ -1,647 +1,635 @@
-<?php
- /**
- * phpGroupWare - property: a Facilities Management System.
- *
- * @author Sigurd Nes <address@hidden>
- * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc.
http://www.fsf.org/
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
- * @internal Development of this application was funded by
http://www.bergen.kommune.no/bbb_/ekstern/
- * @package property
- * @subpackage entity
- * @version $Id$
- */
-
- /**
- * Description
- * @package property
- */
-
- class boentity
- {
- var $start;
- var $query;
- var $filter;
- var $sort;
- var $order;
- var $cat_id;
-
- var $public_functions = array
- (
- 'read' => True,
- 'read_single' => True,
- 'save' => True,
- 'delete' => True,
- 'check_perms' => True
- );
-
- var $soap_functions = array(
- 'list' => array(
- 'in' =>
array('int','int','struct','string','int'),
- 'out' => array('array')
- ),
- 'read' => array(
- 'in' => array('int','struct'),
- 'out' => array('array')
- ),
- 'save' => array(
- 'in' => array('int','struct'),
- 'out' => array()
- ),
- 'delete' => array(
- 'in' => array('int','struct'),
- 'out' => array()
- )
- );
-
- function boentity($session=False)
- {
- $this->currentapp =
$GLOBALS['phpgw_info']['flags']['currentapp'];
- $this->so =
CreateObject($this->currentapp.'.soentity');
-
- $this->solocation =
CreateObject($this->currentapp.'.solocation');
- $this->bocommon =
CreateObject($this->currentapp.'.bocommon');
- $this->vfs =
CreateObject('phpgwapi.vfs');
- $this->rootdir = $this->vfs->basedir;
- $this->fakebase = $this->vfs->fakebase;
-
- if ($session)
- {
- $this->read_sessiondata();
- $this->use_session = True;
- }
-
- $start = get_var('start',array('POST','GET'));
- $query = get_var('query',array('POST','GET'));
- $sort = get_var('sort',array('POST','GET'));
- $order = get_var('order',array('POST','GET'));
- $filter = get_var('filter',array('POST','GET'));
- $cat_id = get_var('cat_id',array('POST','GET'));
- $district_id =
get_var('district_id',array('POST','GET'));
- $entity_id =
get_var('entity_id',array('POST','GET'));
- $status = get_var('status',array('POST','GET'));
- $start_date =
get_var('start_date',array('POST','GET'));
- $end_date =
get_var('end_date',array('POST','GET'));
-
- $this->soadmin_entity =
CreateObject($this->currentapp.'.soadmin_entity',$entity_id,$cat_id);
- $this->category_name =
$this->soadmin_entity->category_name;
-
- if ($start)
- {
- $this->start=$start;
- }
- else
- {
- $this->start=0;
- }
-
- if(array_key_exists('query',$_POST) ||
array_key_exists('query',$_GET) )
- {
- $this->query = $query;
- }
- if(array_key_exists('filter',$_POST))
- {
- $this->filter = $filter;
- }
- if(array_key_exists('sort',$_POST))
- {
- $this->sort = $sort;
- }
- if(array_key_exists('order',$_POST))
- {
- $this->order = $order;
- }
- if(array_key_exists('cat_id',$_POST) ||
array_key_exists('cat_id',$_GET) )
- {
- $this->cat_id = $cat_id;
- }
- if(array_key_exists('district_id',$_POST))
- {
- $this->district_id = $district_id;
- }
- if(array_key_exists('entity_id',$_POST) ||
array_key_exists('entity_id',$_GET) )
- {
- $this->entity_id = $entity_id;
- }
- if(array_key_exists('status',$_POST))
- {
- $this->status = $status;
- }
- if(array_key_exists('start_date',$_POST))
- {
- $this->start_date = $start_date;
- }
- if(array_key_exists('end_date',$_POST))
- {
- $this->end_date = $end_date;
- }
- }
-
- function save_sessiondata($data)
- {
- if ($this->use_session)
- {
-
$GLOBALS['phpgw']->session->appsession('session_data','entity',$data);
- }
- }
-
- function read_sessiondata()
- {
- $data =
$GLOBALS['phpgw']->session->appsession('session_data','entity');
-
- //_debug_array($data);
-
- $this->start = $data['start'];
- $this->query = $data['query'];
- $this->filter = $data['filter'];
- $this->sort = $data['sort'];
- $this->order = $data['order'];
- $this->cat_id = $data['cat_id'];
- $this->district_id = $data['district_id'];
- $this->entity_id = $data['entity_id'];
- $this->status = $data['status'];
- $this->start_date = $data['start_date'];
- $this->end_date = $data['end_date'];
- }
-
- function
column_list($selected='',$entity_id='',$cat_id,$allrows='')
- {
- $soadmin_entity =
CreateObject($this->currentapp.'.soadmin_entity');
-
- if(!$selected)
- {
-
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]["entity_columns_"
. $this->entity_id . '_' . $this->cat_id];
- }
-
- $columns =
$soadmin_entity->read_attrib(array('entity_id'=>$entity_id,'cat_id'=>$cat_id,'allrows'=>$allrows));
-
-
$column_list=$this->bocommon->select_multi_list($selected,$columns);
-
- return $column_list;
- }
-
- function select_category_list($format='',$selected='')
- {
- switch($format)
- {
- case 'select':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
- break;
- case 'filter':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
- break;
- }
-
- $categories=
$this->soadmin_entity->read_category(array('allrows'=>True,'entity_id'=>$this->entity_id));
-
- while (is_array($categories) && list(,$category) =
each($categories))
- {
- $sel_category = '';
- if ($category['id']==$selected)
- {
- $sel_category = 'selected';
- }
-
- $category_list[] = array
- (
- 'cat_id' => $category['id'],
- 'name' => $category['name'],
- 'selected' => $sel_category
- );
- }
-
- for ($i=0;$i<count($category_list);$i++)
- {
- if ($category_list[$i]['selected'] !=
'selected')
- {
- unset($category_list[$i]['selected']);
- }
- }
-
- return $category_list;
- }
-
-
- function select_status_list($format='',$selected='')
- {
- switch($format)
- {
- case 'select':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
- break;
- case 'filter':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
- break;
- }
-
- $status_entries=
$this->so->select_status_list($this->entity_id,$this->cat_id);
-
- while (is_array($status_entries) && list(,$status) =
each($status_entries))
- {
- $sel_status = '';
- if ($status['id']==$selected)
- {
- $sel_status = 'selected';
- }
-
- $status_list[] = array
- (
- 'id' => $status['id'],
- 'name' => $status['name'],
- 'selected' => $sel_status
- );
- }
-
- for ($i=0;$i<count($status_list);$i++)
- {
- if ($status_list[$i]['selected'] != 'selected')
- {
- unset($status_list[$i]['selected']);
- }
- }
-
- return $status_list;
- }
-
-
- function read($data='')
- {
- $entity = $this->so->read(array('start' =>
$this->start,'query' => $this->query,'sort' => $this->sort,'order' =>
$this->order,
-
'filter' => $this->filter,'cat_id' => $this->cat_id,'district_id' =>
$this->district_id,
-
'lookup'=>$data['lookup'],'allrows'=>$data['allrows'],'entity_id'=>$this->entity_id,'cat_id'=>$this->cat_id,'status'=>$this->status,
-
'start_date'=>$this->bocommon->date_to_timestamp($data['start_date']),'end_date'=>$this->bocommon->date_to_timestamp($data['end_date']),
-
'allrows'=>$data['allrows']));
-
- $this->total_records = $this->so->total_records;
-
- $this->uicols = $this->so->uicols;
- $cols_extra = $this->so->cols_extra;
- $cols_return_lookup =
$this->so->cols_return_lookup;
-//_debug_array($entity);
-//_debug_array($cols_extra);
-//_debug_array($cols_return_lookup);
-
- if($data['lookup'])
- {
- for ($i=0;$i<count($entity);$i++)
- {
-
$location_data=$this->solocation->read_single($entity[$i]['location_code']);
- for ($j=0;$j<count($cols_extra);$j++)
- {
- $entity[$i][$cols_extra[$j]] =
$location_data[$cols_extra[$j]];
- }
-
- if($cols_return_lookup)
- {
- for
($k=0;$k<count($cols_return_lookup);$k++)
- {
-
$entity[$i][$cols_return_lookup[$k]] = $location_data[$cols_return_lookup[$k]];
- }
- }
- }
- }
-
- return $entity;
- }
-
- function read_single($data)
- {
- $soadmin_entity =
CreateObject($this->currentapp.'.soadmin_entity');
- $contacts =
CreateObject('phpgwapi.contacts');
-
- $vendor = CreateObject($this->currentapp.'.soactor');
- $vendor->role = 'vendor';
-
- $entity = $this->so->read_single($data);
- $dateformat =
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
- $entity['date'] =
$GLOBALS['phpgw']->common->show_date($entity['date'],$dateformat);
-
- if($entity['location_code'])
- {
-
$entity['location_data']=$this->solocation->read_single($entity['location_code']);
- if($entity['tenant_id'])
- {
-
$tenant_data=$this->bocommon->read_single_tenant($entity['tenant_id']);
- $entity['location_data']['tenant_id']
= $entity['tenant_id'];
-
$entity['location_data']['contact_phone']= $entity['contact_phone'];
- $entity['location_data']['last_name']
= $tenant_data['last_name'];
- $entity['location_data']['first_name']
= $tenant_data['first_name'];
- }
- }
-
- if($entity['p_num'])
- {
- $category =
$soadmin_entity->read_single_category($entity['p_entity_id'],$entity['p_cat_id']);
-
-
$entity['p'][$entity['p_entity_id']]['p_num']=$entity['p_num'];
-
$entity['p'][$entity['p_entity_id']]['p_entity_id']=$entity['p_entity_id'];
-
$entity['p'][$entity['p_entity_id']]['p_cat_id']=$entity['p_cat_id'];
-
$entity['p'][$entity['p_entity_id']]['p_cat_name'] = $category['name'];
- }
-
-
- $input_type_array = array(
- 'R' => 'radio',
- 'CH' => 'checkbox',
- 'LB' => 'listbox'
- );
-
- $sep = '/';
- $dlarr[strpos($dateformat,'Y')] = 'Y';
- $dlarr[strpos($dateformat,'m')] = 'm';
- $dlarr[strpos($dateformat,'d')] = 'd';
- ksort($dlarr);
-
- $dateformat= (implode($sep,$dlarr));
-
- $m=0;
- for ($i=0;$i<count($entity['attributes']);$i++)
- {
- if($entity['attributes'][$i]['datatype']=='D'
&& $entity['attributes'][$i]['value'])
- {
- $timestamp_date=
mktime(0,0,0,date(m,strtotime($entity['attributes'][$i]['value'])),date(d,strtotime($entity['attributes'][$i]['value'])),date(y,strtotime($entity['attributes'][$i]['value'])));
- $entity['attributes'][$i]['value']
= $GLOBALS['phpgw']->common->show_date($timestamp_date,$dateformat);
- }
- if($entity['attributes'][$i]['datatype']=='AB')
- {
- if($entity['attributes'][$i]['value'])
- {
- $contact_data
=
$contacts->read_single_entry($entity['attributes'][$i]['value'],array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
-
$entity['attributes'][$i]['contact_name'] = $contact_data[0]['n_family']
. ', ' . $contact_data[0]['n_given'];
- }
-
- $insert_record_entity[] =
$entity['attributes'][$i]['name'];
- $lookup_link =
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.addressbook&column='
. $entity['attributes'][$i]['name']);
-
- $lookup_functions[$m]['name'] =
'lookup_'. $entity['attributes'][$i]['name'] .'()';
- $lookup_functions[$m]['action'] =
'Window1=window.open('."'" . $lookup_link ."'"
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
- $m++;
- }
-
if($entity['attributes'][$i]['datatype']=='VENDOR')
- {
- if($entity['attributes'][$i]['value'])
- {
- $vendor_data =
$vendor->read_single(array('actor_id'=>$entity['attributes'][$i]['value']));
-
- for
($n=0;$n<count($vendor_data['attributes']);$n++)
- {
-
if($vendor_data['attributes'][$n]['name'] == 'org_name')
- {
-
$entity['attributes'][$i]['vendor_name']=
$vendor_data['attributes'][$n]['value'];
- $n
=count($vendor_data['attributes']);
- }
- }
- }
-
- $insert_record_entity[] =
$entity['attributes'][$i]['name'];
- $lookup_link =
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor&column='
. $entity['attributes'][$i]['name']);
-
- $lookup_functions[$m]['name'] =
'lookup_'. $entity['attributes'][$i]['name'] .'()';
- $lookup_functions[$m]['action'] =
'Window1=window.open('."'" . $lookup_link ."'"
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
- $m++;
- }
- if($entity['attributes'][$i]['datatype']=='R'
|| $entity['attributes'][$i]['datatype']=='CH' ||
$entity['attributes'][$i]['datatype']=='LB')
- {
- $entity['attributes'][$i]['choice']
=
$soadmin_entity->read_attrib_choice($data['entity_id'],$data['cat_id'],$entity['attributes'][$i]['attrib_id']);
-
$input_type=$input_type_array[$entity['attributes'][$i]['datatype']];
-
-
if($entity['attributes'][$i]['datatype']=='CH')
- {
-
$entity['attributes'][$i]['value']=unserialize($entity['attributes'][$i]['value']);
-
$entity['attributes'][$i]['choice'] =
$this->bocommon->select_multi_list_2($entity['attributes'][$i]['value'],$entity['attributes'][$i]['choice'],$input_type);
-
- }
- else
- {
- for
($j=0;$j<count($entity['attributes'][$i]['choice']);$j++)
- {
-
$entity['attributes'][$i]['choice'][$j]['input_type']=$input_type;
-
if($entity['attributes'][$i]['choice'][$j]['id']==$entity['attributes'][$i]['value'])
- {
-
$entity['attributes'][$i]['choice'][$j]['checked']='checked';
- }
- }
- }
- }
-
- $entity['attributes'][$i]['datatype_text'] =
$this->bocommon->translate_datatype($entity['attributes'][$i]['datatype']);
- $entity['attributes'][$i]['counter'] = $i;
- $entity['attributes'][$i]['type_id'] =
$data['type_id'];
- }
-
- for ($j=0;$j<count($lookup_functions);$j++)
- {
- $entity['lookup_functions'] .= 'function ' .
$lookup_functions[$j]['name'] ."\r\n";
- $entity['lookup_functions'] .= '{'."\r\n";
- $entity['lookup_functions'] .=
$lookup_functions[$j]['action'] ."\r\n";
- $entity['lookup_functions'] .= '}'."\r\n";
- }
-
- $this->vfs->override_acl = 1;
-
- $entity['files'] = $this->vfs->ls (array(
- 'string' => $this->fakebase. '/' .
$this->category_name . '/' . $entity['location_data']['loc1'] . '/' .
$data['id'],
- 'relatives' => array(RELATIVE_NONE)));
-
- $this->vfs->override_acl = 0;
-
- if(!$entity['files'][0]['file_id'])
- {
- unset($entity['files']);
- }
-
-
-
$GLOBALS['phpgw']->session->appsession('insert_record_entity',$this->currentapp,$insert_record_entity);
-
-//_debug_array($insert_record_entity);
- return $entity;
- }
-
-
- function create_home_dir($receipt='')
- {
- if(!$this->vfs->file_exists(array(
- 'string' => $this->fakebase. SEP .
$this->category_name,
- 'relatives' => Array(RELATIVE_NONE)
- )))
- {
- $this->vfs->override_acl = 1;
-
- if(!$this->vfs->mkdir (array(
- 'string' => $this->fakebase. SEP .
$this->category_name,
- 'relatives' => array(
- RELATIVE_NONE
- )
- )))
- {
-
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'.
$this->fakebase. SEP . $this->category_name);
- }
- else
- {
-
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'.
$this->fakebase. SEP . $this->category_name);
- }
- $this->vfs->override_acl = 0;
- }
-
- return $receipt;
- }
-
- function create_document_dir($loc1='',$id='')
- {
- if(!$this->vfs->file_exists(array(
- 'string' => $this->fakebase. SEP .
$this->category_name . SEP . $loc1,
- 'relatives' => Array(RELATIVE_NONE)
- )))
- {
- $this->vfs->override_acl = 1;
- if(!$this->vfs->mkdir (array(
- 'string' => $this->fakebase. SEP .
$this->category_name . SEP . $loc1,
- 'relatives' => array(
- RELATIVE_NONE
- )
- )))
- {
-
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $loc1);
- }
- else
- {
-
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $loc1);
- }
- $this->vfs->override_acl = 0;
- }
-
-
- if(!$this->vfs->file_exists(array(
- 'string' => $this->fakebase. SEP .
$this->category_name . SEP . $loc1 . SEP . $id,
- 'relatives' => Array(RELATIVE_NONE)
- )))
- {
- $this->vfs->override_acl = 1;
- if(!$this->vfs->mkdir (array(
- 'string' => $this->fakebase. SEP .
$this->category_name . SEP . $loc1 . SEP . $id,
- 'relatives' => array(
- RELATIVE_NONE
- )
- )))
- {
-
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $loc1 . SEP . $id);
- }
- else
- {
-
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $loc1 . SEP . $id);
- }
- $this->vfs->override_acl = 0;
- }
-
-//_debug_array($receipt);
- return $receipt;
- }
-
- function
save($values,$values_attribute,$action='',$entity_id,$cat_id)
- {
- while (is_array($values['location']) && list(,$value) =
each($values['location']))
- {
- if($value)
- {
- $location[] = $value;
- }
- }
-
- $values['location_code']=implode("-", $location);
-
- $values['date'] =
$this->bocommon->date_to_timestamp($values['date']);
-
- for ($i=0;$i<count($values_attribute);$i++)
- {
- if($values_attribute[$i]['datatype']=='CH' &&
$values_attribute[$i]['value'])
- {
- $values_attribute[$i]['value'] =
serialize($values_attribute[$i]['value']);
- }
- if($values_attribute[$i]['datatype']=='R' &&
$values_attribute[$i]['value'])
- {
- $values_attribute[$i]['value'] =
$values_attribute[$i]['value'][0];
- }
-
- if($values_attribute[$i]['datatype']=='N' &&
$values_attribute[$i]['value'])
- {
- $values_attribute[$i]['value'] =
str_replace(",",".",$values_attribute[$i]['value']);
- }
-
- if($values_attribute[$i]['datatype']=='D' &&
$values_attribute[$i]['value'])
- {
-
- $values_attribute[$i]['value'] =
date($this->bocommon->dateformat,$this->bocommon->date_to_timestamp($values_attribute[$i]['value']));
- }
- }
-
- if ($action=='edit')
- {
- $receipt =
$this->so->edit($values,$values_attribute,$entity_id,$cat_id);
-
- if($values['delete_file'])
- {
- for
($i=0;$i<count($values['delete_file']);$i++)
- {
- $file = $this->fakebase. SEP .
$this->category_name . SEP . $location[0] . SEP . $values['id'] . SEP .
$values['delete_file'][$i];
-
-
if($this->vfs->file_exists(array(
- 'string' =>
$file,
- 'relatives' =>
Array(RELATIVE_NONE)
- )))
- {
-
$this->vfs->override_acl = 1;
-
- if(!$this->vfs->rm
(array(
- 'string' =>
$file,
- 'relatives' =>
array(
- RELATIVE_NONE
- )
- )))
- {
-
$receipt['error'][]=array('msg'=>lang('failed to delete file') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $location[0]. SEP .
$values['id'] . SEP .$values['delete_file'][$i]);
- }
- else
- {
-
$receipt['message'][]=array('msg'=>lang('file deleted') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $location[0]. SEP .
$values['id'] . SEP . $values['delete_file'][$i]);
- }
-
$this->vfs->override_acl = 0;
- }
- }
- }
-
- }
- else
- {
- $receipt =
$this->so->add($values,$values_attribute,$entity_id,$cat_id);
- }
-
- $acl_location = '.entity.' . $entity_id . '.' . $cat_id;
- $custom_functions =
$this->soadmin_entity->read_custom_function(array('acl_location' =>
$acl_location,'allrows'=>True));
-
- if (isSet($custom_functions) AND
is_array($custom_functions))
- {
- foreach($custom_functions as $entry)
- {
- if (is_file(PHPGW_APP_INC . SEP .
'custom' . SEP . $entry['file_name']) && $entry['active'])
- include (PHPGW_APP_INC . SEP . 'custom'
. SEP . $entry['file_name']);
- }
-
- }
- return receipt;
- }
-
-
- function delete($id )
- {
- $this->so->delete($this->entity_id,$this->cat_id,$id);
- }
-
- function generate_id($data )
- {
- if($data['cat_id'])
- {
- return $this->so->generate_id($data);
- }
- }
-
- }
-?>
+<?php
+ /**
+ * phpGroupWare - property: a Facilities Management System.
+ *
+ * @author Sigurd Nes <address@hidden>
+ * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc.
http://www.fsf.org/
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/bbb_/ekstern/
+ * @package property
+ * @subpackage entity
+ * @version $Id$
+ */
+
+ /**
+ * Description
+ * @package property
+ */
+
+ class boentity
+ {
+ var $start;
+ var $query;
+ var $filter;
+ var $sort;
+ var $order;
+ var $cat_id;
+
+ var $public_functions = array
+ (
+ 'read' => True,
+ 'read_single' => True,
+ 'save' => True,
+ 'delete' => True,
+ 'check_perms' => True
+ );
+
+ var $soap_functions = array(
+ 'list' => array(
+ 'in' =>
array('int','int','struct','string','int'),
+ 'out' => array('array')
+ ),
+ 'read' => array(
+ 'in' => array('int','struct'),
+ 'out' => array('array')
+ ),
+ 'save' => array(
+ 'in' => array('int','struct'),
+ 'out' => array()
+ ),
+ 'delete' => array(
+ 'in' => array('int','struct'),
+ 'out' => array()
+ )
+ );
+
+ function boentity($session=False)
+ {
+ $this->currentapp =
$GLOBALS['phpgw_info']['flags']['currentapp'];
+ $this->so =
CreateObject($this->currentapp.'.soentity');
+
+ $this->solocation =
CreateObject($this->currentapp.'.solocation');
+ $this->bocommon =
CreateObject($this->currentapp.'.bocommon');
+ $this->vfs =
CreateObject('phpgwapi.vfs');
+ $this->rootdir = $this->vfs->basedir;
+ $this->fakebase = $this->vfs->fakebase;
+
+ if ($session)
+ {
+ $this->read_sessiondata();
+ $this->use_session = True;
+ }
+
+ $start = get_var('start',array('POST','GET'));
+ $query = get_var('query',array('POST','GET'));
+ $sort = get_var('sort',array('POST','GET'));
+ $order = get_var('order',array('POST','GET'));
+ $filter = get_var('filter',array('POST','GET'));
+ $cat_id = get_var('cat_id',array('POST','GET'));
+ $district_id =
get_var('district_id',array('POST','GET'));
+ $entity_id =
get_var('entity_id',array('POST','GET'));
+ $status = get_var('status',array('POST','GET'));
+ $start_date =
get_var('start_date',array('POST','GET'));
+ $end_date =
get_var('end_date',array('POST','GET'));
+
+ $this->soadmin_entity =
CreateObject($this->currentapp.'.soadmin_entity',$entity_id,$cat_id);
+
+ $this->category_name =
$this->soadmin_entity->category_name;
+
+ if ($start)
+ {
+ $this->start=$start;
+ }
+ else
+ {
+ $this->start=0;
+ }
+ if(array_key_exists('query',$_POST) ||
array_key_exists('query',$_GET) )
+ {
+ $this->query = $query;
+ }
+ if(array_key_exists('filter',$_POST))
+ {
+ $this->filter = $filter;
+ }
+ if(array_key_exists('sort',$_POST))
+ {
+ $this->sort = $sort;
+ }
+ if(array_key_exists('order',$_POST))
+ {
+ $this->order = $order;
+ }
+ if(array_key_exists('cat_id',$_POST) ||
array_key_exists('cat_id',$_GET) )
+ {
+ $this->cat_id = $cat_id;
+ }
+ if(array_key_exists('district_id',$_POST))
+ {
+ $this->district_id = $district_id;
+ }
+ if(array_key_exists('entity_id',$_POST) ||
array_key_exists('entity_id',$_GET) )
+ {
+ $this->entity_id = $entity_id;
+ }
+ if(array_key_exists('status',$_POST))
+ {
+ $this->status = $status;
+ }
+ if(array_key_exists('start_date',$_POST))
+ {
+ $this->start_date = $start_date;
+ }
+ if(array_key_exists('end_date',$_POST))
+ {
+ $this->end_date = $end_date;
+ }
+ }
+
+ function save_sessiondata($data)
+ {
+ if ($this->use_session)
+ {
+
$GLOBALS['phpgw']->session->appsession('session_data','entity',$data);
+ }
+ }
+
+ function read_sessiondata()
+ {
+ $data =
$GLOBALS['phpgw']->session->appsession('session_data','entity');
+ //_debug_array($data);
+ $this->start = $data['start'];
+ $this->query = $data['query'];
+ $this->filter = $data['filter'];
+ $this->sort = $data['sort'];
+ $this->order = $data['order'];
+ $this->cat_id = $data['cat_id'];
+ $this->district_id = $data['district_id'];
+ $this->entity_id = $data['entity_id'];
+ $this->status = $data['status'];
+ $this->start_date = $data['start_date'];
+ $this->end_date = $data['end_date'];
+ }
+
+ function
column_list($selected='',$entity_id='',$cat_id,$allrows='')
+ {
+ $soadmin_entity =
CreateObject($this->currentapp.'.soadmin_entity');
+
+ if(!$selected)
+ {
+
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]["entity_columns_"
. $this->entity_id . '_' . $this->cat_id];
+ }
+
+ $columns =
$soadmin_entity->read_attrib(array('entity_id'=>$entity_id,'cat_id'=>$cat_id,'allrows'=>$allrows));
+
$column_list=$this->bocommon->select_multi_list($selected,$columns);
+
+ return $column_list;
+ }
+
+ function select_category_list($format='',$selected='')
+ {
+ switch($format)
+ {
+ case 'select':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+ break;
+ case 'filter':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+ break;
+ }
+
+ $categories=
$this->soadmin_entity->read_category(array('allrows'=>True,'entity_id'=>$this->entity_id));
+
+ while (is_array($categories) && list(,$category) =
each($categories))
+ {
+ $sel_category = '';
+ if ($category['id']==$selected)
+ {
+ $sel_category = 'selected';
+ }
+
+ $category_list[] = array
+ (
+ 'cat_id' => $category['id'],
+ 'name' => $category['name'],
+ 'selected' => $sel_category
+ );
+ }
+
+ for ($i=0;$i<count($category_list);$i++)
+ {
+ if ($category_list[$i]['selected'] !=
'selected')
+ {
+ unset($category_list[$i]['selected']);
+ }
+ }
+
+ return $category_list;
+ }
+
+
+ function select_status_list($format='',$selected='')
+ {
+ switch($format)
+ {
+ case 'select':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
+ break;
+ case 'filter':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
+ break;
+ }
+
+ $status_entries=
$this->so->select_status_list($this->entity_id,$this->cat_id);
+
+ while (is_array($status_entries) && list(,$status) =
each($status_entries))
+ {
+ $sel_status = '';
+ if ($status['id']==$selected)
+ {
+ $sel_status = 'selected';
+ }
+
+ $status_list[] = array
+ (
+ 'id' => $status['id'],
+ 'name' => $status['name'],
+ 'selected' => $sel_status
+ );
+ }
+
+ for ($i=0;$i<count($status_list);$i++)
+ {
+ if ($status_list[$i]['selected'] != 'selected')
+ {
+ unset($status_list[$i]['selected']);
+ }
+ }
+
+ return $status_list;
+ }
+
+ function read($data='')
+ {
+ $entity = $this->so->read(array('start' =>
$this->start,'query' => $this->query,'sort' => $this->sort,'order' =>
$this->order,
+
'filter' => $this->filter,'cat_id' => $this->cat_id,'district_id' =>
$this->district_id,
+
'lookup'=>$data['lookup'],'allrows'=>$data['allrows'],'entity_id'=>$this->entity_id,'cat_id'=>$this->cat_id,'status'=>$this->status,
+
'start_date'=>$this->bocommon->date_to_timestamp($data['start_date']),'end_date'=>$this->bocommon->date_to_timestamp($data['end_date']),
+
'allrows'=>$data['allrows']));
+
+ $this->total_records = $this->so->total_records;
+ $this->uicols = $this->so->uicols;
+ $cols_extra = $this->so->cols_extra;
+ $cols_return_lookup =
$this->so->cols_return_lookup;
+//_debug_array($entity);
+//_debug_array($cols_extra);
+//_debug_array($cols_return_lookup);
+
+ if($data['lookup'])
+ {
+ for ($i=0;$i<count($entity);$i++)
+ {
+
$location_data=$this->solocation->read_single($entity[$i]['location_code']);
+ for ($j=0;$j<count($cols_extra);$j++)
+ {
+ $entity[$i][$cols_extra[$j]] =
$location_data[$cols_extra[$j]];
+ }
+
+ if($cols_return_lookup)
+ {
+ for
($k=0;$k<count($cols_return_lookup);$k++)
+ {
+
$entity[$i][$cols_return_lookup[$k]] = $location_data[$cols_return_lookup[$k]];
+ }
+ }
+ }
+ }
+
+ return $entity;
+ }
+
+ function read_single($data)
+ {
+ $soadmin_entity =
CreateObject($this->currentapp.'.soadmin_entity');
+ $contacts =
CreateObject('phpgwapi.contacts');
+ $vendor = CreateObject($this->currentapp.'.soactor');
+ $vendor->role = 'vendor';
+
+ $entity = $this->so->read_single($data);
+ $dateformat =
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+ $entity['date'] =
$GLOBALS['phpgw']->common->show_date($entity['date'],$dateformat);
+
+ if($entity['location_code'])
+ {
+
$entity['location_data']=$this->solocation->read_single($entity['location_code']);
+ if($entity['tenant_id'])
+ {
+
$tenant_data=$this->bocommon->read_single_tenant($entity['tenant_id']);
+ $entity['location_data']['tenant_id']
= $entity['tenant_id'];
+
$entity['location_data']['contact_phone']= $entity['contact_phone'];
+ $entity['location_data']['last_name']
= $tenant_data['last_name'];
+ $entity['location_data']['first_name']
= $tenant_data['first_name'];
+ }
+ }
+
+ if($entity['p_num'])
+ {
+ $category =
$soadmin_entity->read_single_category($entity['p_entity_id'],$entity['p_cat_id']);
+
$entity['p'][$entity['p_entity_id']]['p_num']=$entity['p_num'];
+
$entity['p'][$entity['p_entity_id']]['p_entity_id']=$entity['p_entity_id'];
+
$entity['p'][$entity['p_entity_id']]['p_cat_id']=$entity['p_cat_id'];
+
$entity['p'][$entity['p_entity_id']]['p_cat_name'] = $category['name'];
+ }
+
+ $input_type_array = array(
+ 'R' => 'radio',
+ 'CH' => 'checkbox',
+ 'LB' => 'listbox'
+ );
+
+ $sep = '/';
+
+ $dlarr[strpos($dateformat,'Y')] = 'Y';
+ $dlarr[strpos($dateformat,'m')] = 'm';
+ $dlarr[strpos($dateformat,'d')] = 'd';
+ ksort($dlarr);
+ $dateformat= (implode($sep,$dlarr));
+ $m=0;
+
+ for ($i=0;$i<count($entity['attributes']);$i++)
+ {
+ if($entity['attributes'][$i]['datatype']=='D'
&& $entity['attributes'][$i]['value'])
+ {
+ $timestamp_date=
mktime(0,0,0,date(m,strtotime($entity['attributes'][$i]['value'])),date(d,strtotime($entity['attributes'][$i]['value'])),date(y,strtotime($entity['attributes'][$i]['value'])));
+ $entity['attributes'][$i]['value']
= $GLOBALS['phpgw']->common->show_date($timestamp_date,$dateformat);
+ }
+
+ if($entity['attributes'][$i]['datatype']=='AB')
+ {
+ if($entity['attributes'][$i]['value'])
+ {
+ $contact_data
=
$contacts->read_single_entry($entity['attributes'][$i]['value'],array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
+
$entity['attributes'][$i]['contact_name'] = $contact_data[0]['n_family']
. ', ' . $contact_data[0]['n_given'];
+ }
+
+ $insert_record_entity[] =
$entity['attributes'][$i]['name'];
+ $lookup_link =
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.addressbook&column='
. $entity['attributes'][$i]['name']);
+ $lookup_functions[$m]['name'] =
'lookup_'. $entity['attributes'][$i]['name'] .'()';
+ $lookup_functions[$m]['action'] =
'Window1=window.open('."'" . $lookup_link ."'"
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+ $m++;
+ }
+
+
if($entity['attributes'][$i]['datatype']=='VENDOR')
+ {
+ if($entity['attributes'][$i]['value'])
+ {
+ $vendor_data =
$vendor->read_single(array('actor_id'=>$entity['attributes'][$i]['value']));
+ for
($n=0;$n<count($vendor_data['attributes']);$n++)
+ {
+
if($vendor_data['attributes'][$n]['name'] == 'org_name')
+ {
+
$entity['attributes'][$i]['vendor_name']=
$vendor_data['attributes'][$n]['value'];
+ $n
=count($vendor_data['attributes']);
+ }
+ }
+ }
+
+ $insert_record_entity[] =
$entity['attributes'][$i]['name'];
+ $lookup_link =
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor&column='
. $entity['attributes'][$i]['name']);
+ $lookup_functions[$m]['name'] =
'lookup_'. $entity['attributes'][$i]['name'] .'()';
+ $lookup_functions[$m]['action'] =
'Window1=window.open('."'" . $lookup_link ."'"
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+ $m++;
+ }
+
+ if($entity['attributes'][$i]['datatype']=='R'
|| $entity['attributes'][$i]['datatype']=='CH' ||
$entity['attributes'][$i]['datatype']=='LB')
+ {
+ $entity['attributes'][$i]['choice']
=
$soadmin_entity->read_attrib_choice($data['entity_id'],$data['cat_id'],$entity['attributes'][$i]['attrib_id']);
+
$input_type=$input_type_array[$entity['attributes'][$i]['datatype']];
+
+
if($entity['attributes'][$i]['datatype']=='CH')
+ {
+
$entity['attributes'][$i]['value']=unserialize($entity['attributes'][$i]['value']);
+
$entity['attributes'][$i]['choice'] =
$this->bocommon->select_multi_list_2($entity['attributes'][$i]['value'],$entity['attributes'][$i]['choice'],$input_type);
+ }
+ else
+ {
+ for
($j=0;$j<count($entity['attributes'][$i]['choice']);$j++)
+ {
+
$entity['attributes'][$i]['choice'][$j]['input_type']=$input_type;
+
if($entity['attributes'][$i]['choice'][$j]['id']==$entity['attributes'][$i]['value'])
+ {
+
$entity['attributes'][$i]['choice'][$j]['checked']='checked';
+ }
+ }
+ }
+ }
+
+ $entity['attributes'][$i]['datatype_text'] =
$this->bocommon->translate_datatype($entity['attributes'][$i]['datatype']);
+ $entity['attributes'][$i]['counter'] = $i;
+ $entity['attributes'][$i]['type_id'] =
$data['type_id'];
+ }
+
+ for ($j=0;$j<count($lookup_functions);$j++)
+ {
+ $entity['lookup_functions'] .= 'function ' .
$lookup_functions[$j]['name'] ."\r\n";
+ $entity['lookup_functions'] .= '{'."\r\n";
+ $entity['lookup_functions'] .=
$lookup_functions[$j]['action'] ."\r\n";
+ $entity['lookup_functions'] .= '}'."\r\n";
+ }
+
+ $this->vfs->override_acl = 1;
+
+ $entity['files'] = $this->vfs->ls (array(
+ 'string' => $this->fakebase. '/' .
$this->category_name . '/' . $entity['location_data']['loc1'] . '/' .
$data['id'],
+ 'relatives' => array(RELATIVE_NONE)));
+
+ $this->vfs->override_acl = 0;
+
+ if(!$entity['files'][0]['file_id'])
+ {
+ unset($entity['files']);
+ }
+
+
+
$GLOBALS['phpgw']->session->appsession('insert_record_entity',$this->currentapp,$insert_record_entity);
+
+//_debug_array($insert_record_entity);
+ return $entity;
+ }
+
+
+ function create_home_dir($receipt='')
+ {
+ if(!$this->vfs->file_exists(array(
+ 'string' => $this->fakebase. SEP .
$this->category_name,
+ 'relatives' => Array(RELATIVE_NONE)
+ )))
+ {
+ $this->vfs->override_acl = 1;
+
+ if(!$this->vfs->mkdir (array(
+ 'string' => $this->fakebase. SEP .
$this->category_name,
+ 'relatives' => array(
+ RELATIVE_NONE
+ )
+ )))
+ {
+
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'.
$this->fakebase. SEP . $this->category_name);
+ }
+ else
+ {
+
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'.
$this->fakebase. SEP . $this->category_name);
+ }
+ $this->vfs->override_acl = 0;
+ }
+
+ return $receipt;
+ }
+
+ function create_document_dir($loc1='',$id='')
+ {
+ if(!$this->vfs->file_exists(array(
+ 'string' => $this->fakebase. SEP .
$this->category_name . SEP . $loc1,
+ 'relatives' => Array(RELATIVE_NONE)
+ )))
+ {
+ $this->vfs->override_acl = 1;
+ if(!$this->vfs->mkdir (array(
+ 'string' => $this->fakebase. SEP .
$this->category_name . SEP . $loc1,
+ 'relatives' => array(
+ RELATIVE_NONE
+ )
+ )))
+ {
+
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $loc1);
+ }
+ else
+ {
+
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $loc1);
+ }
+ $this->vfs->override_acl = 0;
+ }
+
+
+ if(!$this->vfs->file_exists(array(
+ 'string' => $this->fakebase. SEP .
$this->category_name . SEP . $loc1 . SEP . $id,
+ 'relatives' => Array(RELATIVE_NONE)
+ )))
+ {
+ $this->vfs->override_acl = 1;
+ if(!$this->vfs->mkdir (array(
+ 'string' => $this->fakebase. SEP .
$this->category_name . SEP . $loc1 . SEP . $id,
+ 'relatives' => array(
+ RELATIVE_NONE
+ )
+ )))
+ {
+
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $loc1 . SEP . $id);
+ }
+ else
+ {
+
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $loc1 . SEP . $id);
+ }
+ $this->vfs->override_acl = 0;
+ }
+
+//_debug_array($receipt);
+ return $receipt;
+ }
+
+ function
save($values,$values_attribute,$action='',$entity_id,$cat_id)
+ {
+ while (is_array($values['location']) && list(,$value) =
each($values['location']))
+ {
+ if($value)
+ {
+ $location[] = $value;
+ }
+ }
+
+ $values['location_code']=implode("-", $location);
+
+ $values['date'] =
$this->bocommon->date_to_timestamp($values['date']);
+
+ for ($i=0;$i<count($values_attribute);$i++)
+ {
+ if($values_attribute[$i]['datatype']=='CH' &&
$values_attribute[$i]['value'])
+ {
+ $values_attribute[$i]['value'] =
serialize($values_attribute[$i]['value']);
+ }
+ if($values_attribute[$i]['datatype']=='R' &&
$values_attribute[$i]['value'])
+ {
+ $values_attribute[$i]['value'] =
$values_attribute[$i]['value'][0];
+ }
+
+ if($values_attribute[$i]['datatype']=='N' &&
$values_attribute[$i]['value'])
+ {
+ $values_attribute[$i]['value'] =
str_replace(",",".",$values_attribute[$i]['value']);
+ }
+
+ if($values_attribute[$i]['datatype']=='D' &&
$values_attribute[$i]['value'])
+ {
+
+ $values_attribute[$i]['value'] =
date($this->bocommon->dateformat,$this->bocommon->date_to_timestamp($values_attribute[$i]['value']));
+ }
+ }
+
+ if ($action=='edit')
+ {
+ $receipt =
$this->so->edit($values,$values_attribute,$entity_id,$cat_id);
+
+ if($values['delete_file'])
+ {
+ for
($i=0;$i<count($values['delete_file']);$i++)
+ {
+ $file = $this->fakebase. SEP .
$this->category_name . SEP . $location[0] . SEP . $values['id'] . SEP .
$values['delete_file'][$i];
+
+
if($this->vfs->file_exists(array(
+ 'string' =>
$file,
+ 'relatives' =>
Array(RELATIVE_NONE)
+ )))
+ {
+
$this->vfs->override_acl = 1;
+
+ if(!$this->vfs->rm
(array(
+ 'string' =>
$file,
+ 'relatives' =>
array(
+ RELATIVE_NONE
+ )
+ )))
+ {
+
$receipt['error'][]=array('msg'=>lang('failed to delete file') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $location[0]. SEP .
$values['id'] . SEP .$values['delete_file'][$i]);
+ }
+ else
+ {
+
$receipt['message'][]=array('msg'=>lang('file deleted') . ' :'.
$this->fakebase. SEP . $this->category_name . SEP . $location[0]. SEP .
$values['id'] . SEP . $values['delete_file'][$i]);
+ }
+
$this->vfs->override_acl = 0;
+ }
+ }
+ }
+ }
+ else
+ {
+ $receipt =
$this->so->add($values,$values_attribute,$entity_id,$cat_id);
+ }
+
+ $acl_location = '.entity.' . $entity_id . '.' . $cat_id;
+ $custom_functions =
$this->soadmin_entity->read_custom_function(array('acl_location' =>
$acl_location,'allrows'=>True));
+
+ if (isSet($custom_functions) AND
is_array($custom_functions))
+ {
+ foreach($custom_functions as $entry)
+ {
+ if (is_file(PHPGW_APP_INC . SEP .
'custom' . SEP . $entry['file_name']) && $entry['active'])
+ include (PHPGW_APP_INC . SEP . 'custom'
. SEP . $entry['file_name']);
+ }
+ }
+ return receipt;
+ }
+
+
+ function delete($id )
+ {
+ $this->so->delete($this->entity_id,$this->cat_id,$id);
+ }
+
+ function generate_id($data )
+ {
+ if($data['cat_id'])
+ {
+ return $this->so->generate_id($data);
+ }
+ }
+ }
+?>
\ No newline at end of file
====================================================
Index: property/inc/class.soadmin_entity.inc.php
diff -u property/inc/class.soadmin_entity.inc.php:1.9
property/inc/class.soadmin_entity.inc.php:1.10
--- property/inc/class.soadmin_entity.inc.php:1.9 Mon Oct 24 11:24:29 2005
+++ property/inc/class.soadmin_entity.inc.php Thu Nov 10 21:40:42 2005
@@ -1,1354 +1,1354 @@
-<?php
- /**
- * phpGroupWare - property: a Facilities Management System.
- *
- * @author Sigurd Nes <address@hidden>
- * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc.
http://www.fsf.org/
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
- * @internal Development of this application was funded by
http://www.bergen.kommune.no/bbb_/ekstern/
- * @package property
- * @subpackage admin
- * @version $Id$
- */
-
- /**
- * Description
- * @package property
- */
-
- class soadmin_entity
- {
- var $grants;
-
- function soadmin_entity($entity_id='',$cat_id='')
- {
- $this->currentapp =
$GLOBALS['phpgw_info']['flags']['currentapp'];
- $this->db = $GLOBALS['phpgw']->db;
- $this->db2 = $this->db;
- $this->account =
$GLOBALS['phpgw_info']['user']['account_id'];
- $this->bocommon =
CreateObject($this->currentapp.'.bocommon');
-
- $this->join = $this->bocommon->join;
- $this->like = $this->bocommon->like;
-
- if($entity_id && $cat_id)
- {
- $this->category_name =
$this->read_category_name($entity_id,$cat_id);
- }
- }
-
- function reset_fm_cache()
- {
- $this->db->query("DELETE FROM fm_cache
",__LINE__,__FILE__);
- }
-
- function read($data)
- {
- if(is_array($data))
- {
- if ($data['start'])
- {
- $start=$data['start'];
- }
- else
- {
- $start=0;
- }
- $query =
(isset($data['query'])?$data['query']:'');
- $sort =
(isset($data['sort'])?$data['sort']:'DESC');
- $order =
(isset($data['order'])?$data['order']:'');
- $allrows =
(isset($data['allrows'])?$data['allrows']:'');
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
-
- }
- else
- {
- $ordermethod = ' order by id asc';
- }
-
- $table = 'fm_entity';
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " where name $this->like
'%$query%' or descr $this->like '%$query%'";
- }
-
- $sql = "SELECT * FROM $table $querymethod";
-
- $this->db2->query($sql,__LINE__,__FILE__);
- $this->total_records = $this->db2->num_rows();
-
- if(!$allrows)
- {
- $this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
- }
- else
- {
- $this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
- }
-
- while ($this->db->next_record())
- {
- $entity[] = array
- (
- 'id' => $this->db->f('id'),
- 'name' => $this->db->f('name'),
- 'descr' => $this->db->f('descr'),
- 'documentation' =>
$this->db->f('documentation')
- );
- }
- return $entity;
- }
-
- function read_category($data)
- {
- if(is_array($data))
- {
- if ($data['start'])
- {
- $start=$data['start'];
- }
- else
- {
- $start=0;
- }
- $query =
(isset($data['query'])?$data['query']:'');
- $sort =
(isset($data['sort'])?$data['sort']:'DESC');
- $order =
(isset($data['order'])?$data['order']:'');
- $allrows =
(isset($data['allrows'])?$data['allrows']:'');
- $entity_id =
(isset($data['entity_id'])?$data['entity_id']:'');
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
-
- }
- else
- {
- $ordermethod = ' order by id asc';
- }
-
- $table = 'fm_entity_category';
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " AND name $this->like
'%$query%' or descr $this->like '%$query%'";
- }
-
- $sql = "SELECT * FROM $table WHERE entity_id=$entity_id
$querymethod";
-
- $this->db2->query($sql,__LINE__,__FILE__);
- $this->total_records = $this->db2->num_rows();
-
- if(!$allrows)
- {
- $this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
- }
- else
- {
- $this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
- }
-
- while ($this->db->next_record())
- {
- $standard[] = array
- (
- 'id' => $this->db->f('id'),
- 'name' => $this->db->f('name'),
- 'prefix'=> $this->db->f('prefix'),
- 'descr' => $this->db->f('descr')
- );
- }
- return $standard;
- }
-
- function read_status($data)
- {
- if(is_array($data))
- {
- if ($data['start'])
- {
- $start=$data['start'];
- }
- else
- {
- $start=0;
- }
- $query =
(isset($data['query'])?$data['query']:'');
- $sort =
(isset($data['sort'])?$data['sort']:'DESC');
- $order =
(isset($data['order'])?$data['order']:'');
- $allrows =
(isset($data['allrows'])?$data['allrows']:'');
- $entity_id =
(isset($data['entity_id'])?$data['entity_id']:'');
- $cat_id =
(isset($data['cat_id'])?$data['cat_id']:'');
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
-
- }
- else
- {
- $ordermethod = ' order by id asc';
- }
-
- $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " AND name $this->like
'%$query%' or descr $this->like '%$query%'";
- }
-
- $sql = "SELECT * FROM $table $querymethod";
-
- $this->db2->query($sql,__LINE__,__FILE__);
- $this->total_records = $this->db2->num_rows();
-
- if(!$allrows)
- {
- $this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
- }
- else
- {
- $this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
- }
-
- while ($this->db->next_record())
- {
- $status[] = array
- (
- 'id' => $this->db->f('id'),
- 'descr' => $this->db->f('descr')
- );
- }
- return $status;
- }
-
-
- function read_single($id)
- {
-
- $sql = "SELECT * FROM fm_entity where id='$id'";
-
- $this->db->query($sql,__LINE__,__FILE__);
-
- if ($this->db->next_record())
- {
- $entity['id'] =
$this->db->f('id');
- $entity['name'] =
$this->db->f('name');
- $entity['descr'] =
$this->db->f('descr');
- $entity['location_form'] =
$this->db->f('location_form');
- $entity['lookup_entity'] =
unserialize($this->db->f('lookup_entity'));
- $entity['documentation'] =
$this->db->f('documentation');
- }
-
- $sql = "SELECT location FROM fm_entity_lookup where
entity_id=$id AND type='lookup'";
-
- $this->db->query($sql,__LINE__,__FILE__);
-
- while ($this->db->next_record())
- {
- $entity['include_entity_for'][] =
$this->db->f('location');
- }
-
- $sql = "SELECT location FROM fm_entity_lookup where
entity_id=$id AND type='start'";
-
- $this->db->query($sql,__LINE__,__FILE__);
-
- while ($this->db->next_record())
- {
- $entity['start_entity_from'][] =
$this->db->f('location');
- }
-
- return $entity;
- }
-
- function read_single_category($entity_id,$cat_id)
- {
- $sql = "SELECT * FROM fm_entity_category where
entity_id=$entity_id AND id=$cat_id";
-
- $this->db->query($sql,__LINE__,__FILE__);
-
- if ($this->db->next_record())
- {
- $category['id'] =
$this->db->f('id');
- $category['name'] =
$this->db->f('name');
- $category['descr'] =
$this->db->f('descr');
- $category['prefix'] =
$this->db->f('prefix');
- $category['lookup_tenant'] =
$this->db->f('lookup_tenant');
- $category['tracking'] =
$this->db->f('tracking');
- $category['location_level'] =
$this->db->f('location_level');
- $category['fileupload'] =
$this->db->f('fileupload');
- $category['loc_link'] =
$this->db->f('loc_link');
- $category['start_project'] =
$this->db->f('start_project');
- return $category;
- }
- }
-
- function read_category_name($entity_id,$cat_id)
- {
- $sql = "SELECT * FROM fm_entity_category where
entity_id=$entity_id AND id=$cat_id";
- $this->db->query($sql,__LINE__,__FILE__);
- $this->db->next_record();
- return $this->db->f('name');
- }
-
- function read_single_status($entity_id,$cat_id,$id)
- {
-
- $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
- $sql = "SELECT * FROM $table where id='$id'";
-
- $this->db->query($sql,__LINE__,__FILE__);
-
- if ($this->db->next_record())
- {
- $status['id'] =
$this->db->f('id');
- $status['descr'] =
$this->db->f('descr');
-
- return $status;
- }
- }
-
- function add_entity($entity)
- {
- $entity['name'] =
$this->db->db_addslashes($entity['name']);
- $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
-
- $entity['id'] = $this->bocommon->next_id('fm_entity');
-
- $values= array(
- $entity['id'],
- $entity['name'],
- $entity['descr'],
- $entity['location_form'],
- $entity['documentation']
- );
-
- $values = $this->bocommon->validate_db_insert($values);
-
- $this->db->query("INSERT INTO fm_entity (id,name,
descr,location_form,documentation) "
- . "VALUES ($values)",__LINE__,__FILE__);
-
-
- $values_acl_location= array(
- '.entity.' . $entity['id'],
- $entity['name'],
- 1
- );
-
- $values_acl_location =
$this->bocommon->validate_db_insert($values_acl_location);
-
- $this->db->query("INSERT INTO fm_acl_location
(id,descr,allow_grant) "
- . "VALUES
($values_acl_location)",__LINE__,__FILE__);
-
- $receipt['id']= $entity['id'];
-
- $receipt['message'][] = array('msg'=> lang('entity has
been added'));
- return $receipt;
- }
-
-
- function add_status($values,$entity_id,$cat_id)
- {
- $values['id'] = $this->db->db_addslashes($values['id']);
- $values['descr'] =
$this->db->db_addslashes($values['descr']);
-
- $values_insert= array(
- $values['id'],
- $values['descr'],
- );
-
- $values_insert =
$this->bocommon->validate_db_insert($values_insert);
-
- $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
-
- $this->db->query("INSERT INTO $table (id,descr) VALUES
($values_insert)",__LINE__,__FILE__);
-
- $receipt['id']= $values['id'];
-
- $receipt['message'][] = array('msg'=> lang('status has
been added'));
- return $receipt;
- }
-
-
- function add_category($values)
- {
- $values['name'] =
$this->db->db_addslashes($values['name']);
- $values['descr'] =
$this->db->db_addslashes($values['descr']);
-
- $values['id'] =
$this->bocommon->next_id('fm_entity_category',array('entity_id'=>$values['entity_id']));
-
- $location_type =
$this->bocommon->next_id('fm_location_type');
-
- $values_insert= array(
- $values['entity_id'],
- $values['id'],
- $values['name'],
- $values['descr'],
- $values['prefix'],
- $values['lookup_tenant'],
- $values['tracking'],
- $values['location_level'],
- $values['fileupload'],
- $values['loc_link'],
- $values['start_project']
- );
-
- $values_insert =
$this->bocommon->validate_db_insert($values_insert);
-
-
- $this->db->transaction_begin();
-
- $this->db->query("INSERT INTO fm_entity_category
(entity_id,id,name,
descr,prefix,lookup_tenant,tracking,location_level,fileupload,loc_link,start_project)
"
- . "VALUES ($values_insert)",__LINE__,__FILE__);
-
- $values_acl_location= array(
- '.entity.' . $values['entity_id'] . '.' .
$values['id'],
- $values['name'],
- 1
- );
-
- $values_acl_location =
$this->bocommon->validate_db_insert($values_acl_location);
-
- $this->db->query("INSERT INTO fm_acl_location
(id,descr,allow_grant) "
- . "VALUES
($values_acl_location)",__LINE__,__FILE__);
-
- $receipt['id']= $values['id'];
-
- $this->init_process();
-
- $fd=array();
- $fd['id'] = array('type' => 'int', 'precision' => 4,
'nullable' => False);
- $fd['num'] = array('type' => 'varchar', 'precision' =>
16, 'nullable' => False);
- $fd['p_num'] = array('type' => 'varchar', 'precision'
=> 16, 'nullable' => True);
- $fd['p_entity_id'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
- $fd['p_cat_id'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
- $fd['location_code'] = array('type' => 'varchar',
'precision' => 25, 'nullable' => True);
-
- for ($i=1; $i<$location_type; $i++)
- {
- $fd['loc' . $i] = array('type' => 'varchar',
'precision' => 4, 'nullable' => True);
- }
-
- $fd['address'] = array('type' => 'varchar', 'precision'
=> 150, 'nullable' => True);
- $fd['tenant_id'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
- $fd['contact_phone'] = array('type' => 'varchar',
'precision' => 30, 'nullable' => True);
- $fd['status'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
- $fd['entry_date'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
- $fd['user_id'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
-
- $pk[]= 'id';
- $table = 'fm_entity_'.
$values['entity_id'] .'_'.$values['id'];
-/*
- $fd_status['id'] = array('type' => 'varchar',
'precision' => 20, 'nullable' => False);
- $fd_status['descr'] = array('type' => 'varchar',
'precision' => 255, 'nullable' => False);
- $pk_status[]= 'id';
-
- $statustable = $table . '_' .'status';
-*/
- if(($this->oProc->CreateTable($table,array('fd' =>
$fd,'pk' => $pk,'fk' => $fk,'ix' => array('location_code'),'uc' => array()))))
-// &&
($this->oProc->CreateTable($statustable,array('fd' => $fd_status,'pk' =>
$pk_status,'fk' => $fk_status,'ix' => False,'uc' => array()))))
- {
-
- $values_insert= array(
- $values['entity_id'],
- $values['id'],
- 1,
- 'status',
- 'Status',
- 'Status',
- 'LB',
- 1,
- 'True'
- );
-
- $values_insert =
$this->bocommon->validate_db_insert($values_insert);
-
- $this->db->query("INSERT INTO
fm_entity_attribute
(entity_id,cat_id,id,column_name,input_text,statustext,datatype,attrib_sort,nullable)
"
- . "VALUES
($values_insert)",__LINE__,__FILE__);
-
- $receipt['message'][] = array('msg' =>
lang('table %1 has been saved',$table));
- $this->db->transaction_commit();
- }
- else
- {
- $receipt['error'][] = array('msg' =>
lang('table could not be added') );
- if($this->db->Transaction)
- {
- $this->db->transaction_abort();
- }
- else
- {
- $this->db->query("DELETE FROM
fm_entity_category WHERE id=" . $values['id'] . " AND entity_id=" .
$values['entity_id'],__LINE__,__FILE__);
- unset($receipt['id']);
-
- }
- }
-
- return $receipt;
- }
-
- function edit_status($values,$entity_id,$cat_id)
- {
- $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
-
- $values['descr'] =
$this->db->db_addslashes($values['descr']);
-
- $value_set=array(
- 'descr' => $values['descr'],
- );
-
- $value_set =
$this->bocommon->validate_db_update($value_set);
-
- $this->db->query("UPDATE $table set $value_set WHERE
id='" . $values['id'] . "'",__LINE__,__FILE__);
-
- $receipt['message'][] = array('msg'=> lang('Status has
been edited'));
-
- return $receipt;
- }
-
- function edit_entity($entity)
- {
- if (!$entity['name'])
- {
- $receipt['error'][] = array('msg'=>lang('Name
not entered!'));
- }
-
- if (!$receipt['error'])
- {
- $table = 'fm_entity';
-
- $entity['name'] =
$this->db->db_addslashes($entity['name']);
- $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
-
- if(!$entity['location_form'])
- {
- unset($entity['lookup_entity']);
- }
-
- $value_set=array(
- 'descr' => $entity['descr'],
- 'name' => $entity['name'],
- 'location_form' => $entity['location_form'],
- 'lookup_entity' =>
serialize($entity['lookup_entity']),
- 'documentation' => $entity['documentation']
- );
-
- $value_set =
$this->bocommon->validate_db_update($value_set);
-
- $this->db->transaction_begin();
-
- $this->db->query("UPDATE $table set $value_set
WHERE id=" . $entity['id'],__LINE__,__FILE__);
-
- $value_set_acl=array(
- 'descr' =>
$entity['name']
- );
-
- $value_set_acl =
$this->bocommon->validate_db_update($value_set_acl);
-
- $this->db->query("UPDATE fm_acl_location set
$value_set_acl WHERE id='.entity." . $entity['id']. "'",__LINE__,__FILE__);
-
- $this->db->query("DELETE FROM fm_entity_lookup
WHERE type='lookup' AND entity_id=" . $entity['id'],__LINE__,__FILE__);
- if (isset($entity['include_entity_for']) AND
is_array($entity['include_entity_for']))
- {
- foreach($entity['include_entity_for']
as $location)
- {
- $this->db->query("INSERT INTO
fm_entity_lookup (entity_id,location,type)"
- . "VALUES (" .$entity['id'] .
",'$location','lookup' )",__LINE__,__FILE__);
- }
- }
-
- $this->db->query("DELETE FROM fm_entity_lookup
WHERE type='start' AND entity_id=" . $entity['id'],__LINE__,__FILE__);
-
- if (isset($entity['start_entity_from']) AND
is_array($entity['start_entity_from']))
- {
- foreach($entity['start_entity_from'] as
$location)
- {
- $this->db->query("INSERT INTO
fm_entity_lookup (entity_id,location,type)"
- . "VALUES (" .$entity['id'] .
",'$location','start' )",__LINE__,__FILE__);
- }
- }
-
- $this->db->transaction_commit();
-
- $receipt['message'][] = array('msg'=>
lang('entity has been edited'));
- }
- else
- {
- $receipt['error'][] = array('msg' =>
lang('entity has NOT been edited'));
- }
-
- return $receipt;
- }
-
- function edit_category($entity)
- {
-
- if (!$entity['name'])
- {
- $receipt['error'][] = array('msg'=>lang('Name
not entered!'));
- }
-
- if (!$receipt['error'])
- {
- $table = 'fm_entity_category';
-
- $entity['name'] =
$this->db->db_addslashes($entity['name']);
- $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
-
- $value_set=array(
- 'descr' =>
$entity['descr'],
- 'name' =>
$entity['name'],
- 'prefix' =>
$entity['prefix'],
- 'lookup_tenant' =>
$entity['lookup_tenant'],
- 'tracking' =>
$entity['tracking'],
- 'location_level'=>
$entity['location_level'],
- 'fileupload' =>
$entity['fileupload'],
- 'loc_link' =>
$entity['loc_link'],
- 'start_project' =>
$entity['start_project']
- );
-
- $value_set =
$this->bocommon->validate_db_update($value_set);
-
- $this->db->query("UPDATE $table set $value_set
WHERE entity_id=" . $entity['entity_id']. " AND id=" .
$entity['id'],__LINE__,__FILE__);
-
- $value_set_acl=array(
- 'descr' =>
$entity['name']
- );
-
- $value_set_acl =
$this->bocommon->validate_db_update($value_set_acl);
-
- $this->db->query("UPDATE fm_acl_location set
$value_set_acl WHERE id='.entity." . $entity['entity_id']. "." . $entity['id'].
"'",__LINE__,__FILE__);
-
-
- $receipt['message'][] = array('msg'=>
lang('entity has been edited'));
- }
- else
- {
- $receipt['error'][] = array('msg' =>
lang('entity has NOT been edited'));
- }
-
- return $receipt;
- }
-
- function delete_entity($id)
- {
-
$category_list=$this->read_category(array('entity_id'=>$id));
- $this->db->query("DELETE FROM fm_entity WHERE
id=$id",__LINE__,__FILE__);
- $this->db->query("DELETE FROM fm_entity_category WHERE
entity_id=$id",__LINE__,__FILE__);
- $this->db->query("DELETE FROM fm_entity_attribute WHERE
entity_id=$id",__LINE__,__FILE__);
- $this->db->query("DELETE FROM fm_acl_location WHERE id
$this->like '.entity." . $id ."%'",__LINE__,__FILE__);
- $this->db->query("DELETE FROM fm_acl2 WHERE
acl_location $this->like '.entity." . $id ."%'",__LINE__,__FILE__);
- if (isset($category_list) AND is_array($category_list))
- {
- $this->init_process();
-
- foreach($category_list as $entry)
- {
- $this->oProc->DropTable('fm_entity_' .
$id . '_' . $entry['id']);
- }
- }
-
- }
-
- function delete_category($id,$entity_id)
- {
- $this->init_process();
- $this->oProc->DropTable('fm_entity_' . $entity_id . '_'
. $id);
-// $this->oProc->DropTable('fm_entity_' . $entity_id . '_'
. $id . '_' . 'status');
- $this->db->query("DELETE FROM fm_entity_category WHERE
entity_id= $entity_id AND id= $id",__LINE__,__FILE__);
- $this->db->query("DELETE FROM fm_entity_attribute WHERE
entity_id= $entity_id AND cat_id= $id",__LINE__,__FILE__);
- $this->db->query("DELETE FROM fm_acl_location WHERE
id='.entity." . $entity_id . "." . $id ."'",__LINE__,__FILE__);
- $this->db->query("DELETE FROM fm_acl2 WHERE
acl_location='.entity." . $entity_id . "." . $id ."'",__LINE__,__FILE__);
- }
-
- function delete_attrib($cat_id,$entity_id,$attrib_id)
- {
- $this->init_process();
-
- $sql = "SELECT * FROM fm_entity_attribute WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id";
-
- $this->db->query($sql,__LINE__,__FILE__);
- $this->db->next_record();
- $ColumnName = $this->db->f('column_name');
-
- $this->oProc->DropColumn('fm_entity_' .$entity_id.'_'.
$cat_id,'', $ColumnName);
-
- $sql = "SELECT attrib_sort FROM fm_entity_attribute
where entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id";
- $this->db->query($sql,__LINE__,__FILE__);
- $this->db->next_record();
- $attrib_sort = $this->db->f('attrib_sort');
- $sql2 = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=$entity_id AND cat_id=$cat_id";
- $this->db->query($sql2,__LINE__,__FILE__);
- $this->db->next_record();
- $max_sort = $this->db->f('max_sort');
- if($max_sort>$attrib_sort)
- {
- $sql = "UPDATE fm_entity_attribute set
attrib_sort=attrib_sort-1 WHERE entity_id=$entity_id AND cat_id=$cat_id AND
attrib_sort > $attrib_sort";
- $this->db->query($sql,__LINE__,__FILE__);
- }
-
- $this->db->query("DELETE FROM fm_entity_attribute WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id",__LINE__,__FILE__);
- }
-
- function delete_status($cat_id,$entity_id,$status_id)
- {
- $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
-
- $this->db->query("DELETE FROM $table WHERE
id='$status_id'",__LINE__,__FILE__);
- }
-
- function read_attrib($data)
- {
-
-//_debug_array($data);
- if(is_array($data))
- {
- if ($data['start'])
- {
- $start=$data['start'];
- }
- else
- {
- $start=0;
- }
- $query =
(isset($data['query'])?$data['query']:'');
- $sort =
(isset($data['sort'])?$data['sort']:'DESC');
- $order =
(isset($data['order'])?$data['order']:'');
- $allrows =
(isset($data['allrows'])?$data['allrows']:'');
- $entity_id =
(isset($data['entity_id'])?$data['entity_id']:0);
- $cat_id =
(isset($data['cat_id'])?$data['cat_id']:0);
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
-
- }
- else
- {
- $ordermethod = ' order by attrib_sort asc';
- }
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " AND (fm_entity_attribute.name
$this->like '%$query%' or fm_entity_attribute.descr $this->like '%$query%')";
- }
-
- $sql = "SELECT * FROM fm_entity_attribute WHERE
entity_id=$entity_id AND cat_id = $cat_id $filtermethod $querymethod";
-
- $this->db2->query($sql,__LINE__,__FILE__);
- $this->total_records = $this->db2->num_rows();
- if(!$allrows)
- {
- $this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
- }
- else
- {
- $this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
- }
-
-
- while ($this->db->next_record())
- {
- $attrib[] = array
- (
- 'id' =>
$this->db->f('id'),
- 'entity_type' =>
$this->db->f('type_id'),
- 'attrib_sort' =>
$this->db->f('attrib_sort'),
- 'list' =>
$this->db->f('list'),
- 'lookup_form' =>
$this->db->f('lookup_form'),
- 'entity_form' =>
$this->db->f('entity_form'),
- 'column_name' =>
$this->db->f('column_name'),
- 'name' =>
$this->db->f('input_text'),
- 'size' =>
$this->db->f('size'),
- 'statustext' =>
$this->db->f('statustext'),
- 'input_text' =>
$this->db->f('input_text'),
- 'type_name' =>
$this->db->f('type'),
- 'datatype' =>
$this->db->f('datatype'),
- 'search' =>
$this->db->f('search')
- );
- }
- return $attrib;
- }
-
- function read_single_attrib($entity_id,$cat_id,$id)
- {
-
- $sql = "SELECT * FROM fm_entity_attribute where
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
-
- $this->db->query($sql,__LINE__,__FILE__);
-
- if ($this->db->next_record())
- {
- $attrib['id']
= $this->db->f('id');
- $attrib['column_name']
= $this->db->f('column_name');
- $attrib['input_text']
= $this->db->f('input_text');
- $attrib['statustext']
= $this->db->f('statustext');
- $attrib['column_info']['precision'] =
$this->db->f('precision_');
- $attrib['column_info']['scale'] =
$this->db->f('scale');
- $attrib['column_info']['default'] =
$this->db->f('default_value');
- $attrib['column_info']['nullable'] =
$this->db->f('nullable');
- $attrib['column_info']['type'] =
$this->db->f('datatype');
- $attrib['type_id']
= $this->db->f('type_id');
- $attrib['type_name']
= $this->db->f('type_name');
- $attrib['lookup_form']
= $this->db->f('lookup_form');
- $attrib['list']
= $this->db->f('list');
- $attrib['search']
= $this->db->f('search');
- if($this->db->f('datatype')=='R' ||
$this->db->f('datatype')=='CH' || $this->db->f('datatype')=='LB')
- {
- $attrib['choice'] =
$this->read_attrib_choice($entity_id,$cat_id,$id);
- }
-
- return $attrib;
- }
- }
-
- function read_attrib_choice($entity_id,$cat_id,$attrib_id)
- {
- $choice_table = 'fm_entity_choice';
- $sql = "SELECT * FROM $choice_table WHERE
entity_id=$entity_id AND cat_id=$cat_id AND attrib_id=$attrib_id";
- $this->db->query($sql,__LINE__,__FILE__);
-
- while ($this->db->next_record())
- {
- $choice[] = array
- (
- 'id' => $this->db->f('id'),
- 'value' => $this->db->f('value')
- );
- }
- return $choice;
- }
-
- function add_attrib($attrib)
- {
-
- $attrib['column_name'] =
$this->db->db_addslashes($attrib['column_name']);
- $attrib['input_text'] =
$this->db->db_addslashes($attrib['input_text']);
- $attrib['statustext'] =
$this->db->db_addslashes($attrib['statustext']);
- $attrib['default'] =
$this->db->db_addslashes($attrib['default']);
- $attrib['id'] =
$this->bocommon->next_id('fm_entity_attribute',array('entity_id'=>$attrib['entity_id'],'cat_id'=>$attrib['cat_id']));
-
- $sql = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=" . $attrib['entity_id'] . " AND cat_id=" .
$attrib['cat_id'];
- $this->db->query($sql,__LINE__,__FILE__);
- $this->db->next_record();
- $attrib_sort = $this->db->f('max_sort')+1;
-
- $values= array(
- $attrib['entity_id'],
- $attrib['cat_id'],
- $attrib['id'],
- $attrib['column_name'],
- $attrib['input_text'],
- $attrib['statustext'],
- $attrib['search'],
- $attrib['list'],
- $attrib_sort,
- $attrib['column_info']['type'],
- $attrib['column_info']['precision'],
- $attrib['column_info']['scale'],
- $attrib['column_info']['default'],
- $attrib['column_info']['nullable']
- );
-
- $values = $this->bocommon->validate_db_insert($values);
-
- $this->db->transaction_begin();
-
- $this->db->query("INSERT INTO fm_entity_attribute
(entity_id,cat_id,id,column_name, input_text,
statustext,search,list,attrib_sort,
datatype,precision_,scale,default_value,nullable) "
- . "VALUES ($values)",__LINE__,__FILE__);
-
- $receipt['id']= $attrib['id'];
-
- if($attrib['column_info']['type']=='email' &&
!$attrib['column_info']['precision'])
- {
- $attrib['column_info']['precision']=64;
- }
-
- $attrib['column_info']['type'] =
$this->bocommon->translate_datatype_insert($attrib['column_info']['type']);
-
- if($attrib['column_info']['type']=='int' &&
!$attrib['column_info']['precision'])
- {
- $attrib['column_info']['precision']=4;
- }
-
- if(!$attrib['column_info']['default'])
- {
- unset($attrib['column_info']['default']);
- }
-
- $this->init_process();
-
-
if($this->oProc->AddColumn('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'],$attrib['column_name'], $attrib['column_info']))
- {
- $receipt['message'][] = array('msg' =>
lang('Attribute has been saved') );
- $this->db->transaction_commit();
-
- }
- else
- {
- $receipt['error'][] = array('msg' =>
lang('column could not be added') );
- if($this->db->Transaction)
- {
- $this->db->transaction_abort();
- }
- else
- {
- $this->db->query("DELETE FROM
fm_entity_attribute WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['id']. " AND id='" . $receipt['id'] . "'",__LINE__,__FILE__);
- unset($receipt['id']);
-
- }
- }
-
- return $receipt;
- }
-
- function init_process()
- {
- $this->oProc
=
CreateObject('phpgwapi.schema_proc',$GLOBALS['phpgw_info']['server']['db_type']);
- $this->oProc->m_odb
= $this->db;
- $this->oProc->m_odb->Halt_On_Error = 'report';
- }
-
- function edit_attrib($attrib)
- {
-
- $choice_table = 'fm_entity_choice';
-
- $attrib['column_name'] =
$this->db->db_addslashes($attrib['column_name']);
- $attrib['input_text'] =
$this->db->db_addslashes($attrib['input_text']);
- $attrib['statustext'] =
$this->db->db_addslashes($attrib['statustext']);
- $attrib['default'] =
$this->db->db_addslashes($attrib['default']);
-
- $this->db->query("SELECT column_name FROM
fm_entity_attribute WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND id='" . $attrib['id']. "'",__LINE__,__FILE__);
- $this->db->next_record();
- $OldColumnName = $this->db->f('column_name');
-
- $this->db->transaction_begin();
-
- $value_set=array(
- 'input_text' =>
$attrib['input_text'],
- 'statustext' =>
$attrib['statustext'],
- 'search' =>
$attrib['search'],
- 'list' =>
$attrib['list'],
- );
-
- $value_set =
$this->bocommon->validate_db_update($value_set);
-
- $this->db->query("UPDATE fm_entity_attribute
set $value_set WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND id=" . $attrib['id'],__LINE__,__FILE__);
-
- if($OldColumnName !=$attrib['column_name'])
- {
-
- if($attrib['column_info']['type']!='R' &&
$attrib['column_info']['type']!='CH' && $attrib['column_info']['type']!='LB')
- {
- $this->db->query("DELETE FROM
$choice_table WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND attrib_id=" . $attrib['id'],__LINE__,__FILE__);
- }
-
- if($attrib['column_info']['type']=='email' &&
!$attrib['column_info']['precision'])
- {
- $attrib['column_info']['precision']=64;
- }
-
- if($precision =
$this->bocommon->translate_datatype_precision($attrib['column_info']['type']))
- {
-
$attrib['column_info']['precision']=$precision;
- }
-
- if(!$attrib['column_info']['default'])
- {
-
unset($attrib['column_info']['default']);
- }
-
- $value_set=array(
- 'column_name' =>
$attrib['column_name'],
- 'datatype' =>
$attrib['column_info']['type'],
- 'precision_' =>
$attrib['column_info']['precision'],
- 'scale' =>
$attrib['column_info']['scale'],
- 'default_value' =>
$attrib['column_info']['default'],
- 'nullable' =>
$attrib['column_info']['nullable']
- );
-
- $value_set =
$this->bocommon->validate_db_update($value_set);
-
- $this->db->query("UPDATE fm_entity_attribute
set $value_set WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND id=" . $attrib['id'],__LINE__,__FILE__);
-
- $attrib['column_info']['type'] =
$this->bocommon->translate_datatype_insert($attrib['column_info']['type']);
-
- $this->init_process();
-
- $mini_table_def = array(
- 'fm_entity_'.$attrib['entity_id'] . '_'
. $attrib['cat_id'] => array(
- 'fd' => array(
- $OldColumnName
=>$attrib['column_info']),
- 'pk' => array(),
- 'fk' => array(),
- 'ix' => array(),
- 'uc' => array()
- )
- );
-
- $this->oProc->GenerateScripts($mini_table_def);
-
$this->oProc->RenameColumn('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'], $OldColumnName, $attrib['column_name']);
-
$this->oProc->AlterColumn('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'],$attrib['column_name'],$attrib['column_info']);
- }
-
- $choice_table ='fm_entity_choice';
-
- if($attrib['new_choice'])
- {
- $choice_id =
$this->bocommon->next_id($choice_table
,array('entity_id'=>$attrib['entity_id'],'cat_id'=>$attrib['cat_id'],'attrib_id'=>$attrib['id']));
-
- $values= array(
- $attrib['entity_id'],
- $attrib['cat_id'],
- $attrib['id'],
- $choice_id,
- $attrib['new_choice']
- );
-
- $values =
$this->bocommon->validate_db_insert($values);
-
- $this->db->query("INSERT INTO $choice_table
(entity_id,cat_id,attrib_id,id,value) "
- . "VALUES ($values)",__LINE__,__FILE__);
- }
-
- if($attrib['delete_choice'])
- {
- for
($i=0;$i<count($attrib['delete_choice']);$i++)
- {
- $this->db->query("DELETE FROM
$choice_table WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND attrib_id=" . $attrib['id'] ." AND id=" .
$attrib['delete_choice'][$i],__LINE__,__FILE__);
- }
- }
-
- $this->db->transaction_commit();
-
- $receipt['message'][] = array('msg' =>
lang('Attribute has been edited'));
-
- return $receipt;
- }
-
- function resort_attrib($data)
- {
- if(is_array($data))
- {
- $resort =
(isset($data['resort'])?$data['resort']:'up');
- $entity_id =
(isset($data['entity_id'])?$data['entity_id']:0);
- $cat_id =
(isset($data['cat_id'])?$data['cat_id']:0);
- $id = (isset($data['id'])?$data['id']:'');
- }
-
- $sql = "SELECT attrib_sort FROM fm_entity_attribute
where entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
- $this->db->query($sql,__LINE__,__FILE__);
- $this->db->next_record();
- $attrib_sort = $this->db->f('attrib_sort');
- $sql2 = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=$entity_id AND cat_id=$cat_id";
- $this->db->query($sql2,__LINE__,__FILE__);
- $this->db->next_record();
- $max_sort = $this->db->f('max_sort');
-
- switch($resort)
- {
- case 'up':
- if($attrib_sort>1)
- {
- $sql = "UPDATE
fm_entity_attribute set attrib_sort=$attrib_sort WHERE entity_id=$entity_id AND
cat_id=$cat_id AND attrib_sort =" . ($attrib_sort-1);
-
$this->db->query($sql,__LINE__,__FILE__);
- $sql = "UPDATE
fm_entity_attribute set attrib_sort=" . ($attrib_sort-1) ." WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
-
$this->db->query($sql,__LINE__,__FILE__);
- }
- break;
- case 'down':
- if($max_sort > $attrib_sort)
- {
- $sql = "UPDATE
fm_entity_attribute set attrib_sort=$attrib_sort WHERE entity_id=$entity_id AND
cat_id=$cat_id AND attrib_sort =" . ($attrib_sort+1);
-
$this->db->query($sql,__LINE__,__FILE__);
- $sql = "UPDATE
fm_entity_attribute set attrib_sort=" . ($attrib_sort+1) ." WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
-
$this->db->query($sql,__LINE__,__FILE__);
- }
- break;
- default:
- return;
- break;
- }
- }
-
- function read_custom_function($data)
- {
- if(is_array($data))
- {
- if ($data['start'])
- {
- $start=$data['start'];
- }
- else
- {
- $start=0;
- }
- $query =
(isset($data['query'])?$data['query']:'');
- $sort =
(isset($data['sort'])?$data['sort']:'DESC');
- $order =
(isset($data['order'])?$data['order']:'');
- $allrows =
(isset($data['allrows'])?$data['allrows']:'');
- $acl_location =
(isset($data['acl_location'])?$data['acl_location']:'');
- }
-
- if(!$acl_location)
- {
- return;
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
-
- }
- else
- {
- $ordermethod = ' order by custom_sort asc';
- }
-
- $table = 'fm_custom_function';
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " AND name $this->like
'%$query%' or descr $this->like '%$query%'";
- }
-
- $sql = "SELECT * FROM $table WHERE
acl_location='$acl_location' $querymethod";
-
- $this->db2->query($sql,__LINE__,__FILE__);
- $this->total_records = $this->db2->num_rows();
-
- if(!$allrows)
- {
- $this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
- }
- else
- {
- $this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
- }
-
- while ($this->db->next_record())
- {
- $custom_function[] = array
- (
- 'id' => $this->db->f('id'),
- 'file_name' =>
$this->db->f('file_name'),
- 'sorting' =>
$this->db->f('custom_sort'),
- 'descr' =>
$this->db->f('descr'),
- 'active' =>
$this->db->f('active')
- );
- }
- return $custom_function;
- }
-
-
- function read_single_custom_function($acl_location,$id)
- {
-
- $sql = "SELECT * FROM fm_custom_function where
acl_location='$acl_location' AND id=$id";
-
- $this->db->query($sql,__LINE__,__FILE__);
-
- if ($this->db->next_record())
- {
- $custom_function['id'] =
$this->db->f('id');
- $custom_function['descr'] =
$this->db->f('descr');
- $custom_function['custom_function_file']=
$this->db->f('file_name');
- $custom_function['active'] =
$this->db->f('active');
-
- return $custom_function;
- }
-
- }
-
- function add_custom_function($custom_function)
- {
- if(!$custom_function['acl_location'] &&
$custom_function['entity_id'] && $custom_function['cat_id'])
- {
- $acl_location = '.entity.' .
$custom_function['entity_id'] . '.' . $custom_function['cat_id'];
- }
- else
- {
- $acl_location =
$custom_function['acl_location'];
- }
-
- if(!$acl_location)
- {
- return $receipt['error'][] = array('msg' =>
lang('acl_locastion is missing'));
- }
-
- $custom_function['descr'] =
$this->db->db_addslashes($custom_function['descr']);
-
-
- $this->db->query("SELECT max(id) as maximum FROM
fm_custom_function WHERE acl_location='$acl_location'",__LINE__,__FILE__);
- $this->db->next_record();
- $custom_function['id'] = $this->db->f('maximum')+1;
-
- $sql = "SELECT max(custom_sort) as max_sort FROM
fm_custom_function where acl_location='$acl_location'";
- $this->db->query($sql,__LINE__,__FILE__);
- $this->db->next_record();
- $custom_sort = $this->db->f('max_sort')+1;
-
- $values= array(
- $acl_location,
- $custom_function['id'],
- $custom_function['custom_function_file'],
- $custom_function['descr'],
- $custom_function['active'],
- $custom_sort
- );
-
- $values = $this->bocommon->validate_db_insert($values);
-
-//_debug_array($custom_function);
- $this->db->transaction_begin();
-
- $this->db->query("INSERT INTO fm_custom_function
(acl_location, id, file_name, descr, active, custom_sort) "
- . "VALUES ($values)",__LINE__,__FILE__);
-
- $receipt['id']= $custom_function['id'];
-
- $this->db->transaction_commit();
-
- return $receipt;
- }
-
- function edit_custom_function($custom_function)
- {
- if(!$custom_function['acl_location'] &&
$custom_function['entity_id'] && $custom_function['cat_id'])
- {
- $acl_location = '.entity.' .
$custom_function['entity_id'] . '.' . $custom_function['cat_id'];
- }
- else
- {
- $acl_location =
$custom_function['acl_location'];
- }
-
- if(!$acl_location)
- {
- return $receipt['error'][] = array('msg' =>
lang('acl_locastion is missing'));
- }
-
- $custom_function['descr'] =
$this->db->db_addslashes($custom_function['descr']);
-
- $this->db->transaction_begin();
-
- $value_set=array(
- 'descr' =>
$custom_function['descr'],
- 'file_name' =>
$custom_function['custom_function_file'],
- 'active' =>
$custom_function['active']
- );
-
- $value_set =
$this->bocommon->validate_db_update($value_set);
-
- $this->db->query("UPDATE fm_custom_function set
$value_set WHERE acl_location='" . $acl_location . "' AND id=" .
$custom_function['id'],__LINE__,__FILE__);
-
- $this->db->transaction_commit();
-
- $receipt['message'][] = array('msg' => lang('Custom
function has been edited'));
-
- return $receipt;
- }
-
- function resort_custom_function($data)
- {
- if(is_array($data))
- {
- $resort =
(isset($data['resort'])?$data['resort']:'up');
- $entity_id =
(isset($data['entity_id'])?$data['entity_id']:'');
- $cat_id =
(isset($data['cat_id'])?$data['cat_id']:'');
- $acl_location =
(isset($data['acl_location'])?$data['acl_location']:'');
- $id = (isset($data['id'])?$data['id']:'');
- }
-
- if(!$acl_location && $entity_id && $cat_id)
- {
- $acl_location = '.entity.' . $entity_id . '.' .
$cat_id;
- }
- else
- {
- $acl_location = $acl_location;
- }
-
- if(!$acl_location)
- {
- return $receipt['error'][] = array('msg' =>
lang('acl_locastion is missing'));
- }
-
- $sql = "SELECT custom_sort FROM fm_custom_function
where acl_location='$acl_location' AND id=$id";
- $this->db->query($sql,__LINE__,__FILE__);
- $this->db->next_record();
- $custom_sort = $this->db->f('custom_sort');
- $sql2 = "SELECT max(custom_sort) as max_sort FROM
fm_custom_function where acl_location='$acl_location'";
- $this->db->query($sql2,__LINE__,__FILE__);
- $this->db->next_record();
- $max_sort = $this->db->f('max_sort');
-
- switch($resort)
- {
- case 'up':
- if($custom_sort>1)
- {
- $sql = "UPDATE
fm_custom_function set custom_sort=$custom_sort WHERE
acl_location='$acl_location' AND custom_sort =" . ($custom_sort-1);
-
$this->db->query($sql,__LINE__,__FILE__);
- $sql = "UPDATE
fm_custom_function set custom_sort=" . ($custom_sort-1) ." WHERE
acl_location='$acl_location' AND id=$id";
-
$this->db->query($sql,__LINE__,__FILE__);
- }
- break;
- case 'down':
- if($max_sort > $custom_sort)
- {
- $sql = "UPDATE
fm_custom_function set custom_sort=$custom_sort WHERE
acl_location='$acl_location' AND custom_sort =" . ($custom_sort+1);
-
$this->db->query($sql,__LINE__,__FILE__);
- $sql = "UPDATE
fm_custom_function set custom_sort=" . ($custom_sort+1) ." WHERE
acl_location='$acl_location' AND id=$id";
-
$this->db->query($sql,__LINE__,__FILE__);
- }
- break;
- default:
- return;
- break;
- }
- }
-
- function
delete_custom_function($acl_location,$custom_function_id)
- {
- $sql = "SELECT custom_sort FROM fm_custom_function
where acl_location='$acl_location' AND id=$custom_function_id";
- $this->db->query($sql,__LINE__,__FILE__);
- $this->db->next_record();
- $custom_sort = $this->db->f('custom_sort');
- $sql2 = "SELECT max(custom_sort) as max_sort FROM
fm_custom_function where acl_location='$acl_location'";
- $this->db->query($sql2,__LINE__,__FILE__);
- $this->db->next_record();
- $max_sort = $this->db->f('max_sort');
- if($max_sort>$custom_sort)
- {
- $sql = "UPDATE fm_custom_function set
custom_sort=custom_sort-1 WHERE acl_location='$acl_location' AND custom_sort >
$custom_sort";
- $this->db->query($sql,__LINE__,__FILE__);
- }
- $this->db->query("DELETE FROM fm_custom_function WHERE
acl_location='$acl_location' AND id=$custom_function_id",__LINE__,__FILE__);
- }
- }
-?>
+<?php
+ /**
+ * phpGroupWare - property: a Facilities Management System.
+ *
+ * @author Sigurd Nes <address@hidden>
+ * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc.
http://www.fsf.org/
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/bbb_/ekstern/
+ * @package property
+ * @subpackage admin
+ * @version $Id$
+ */
+
+ /**
+ * Description
+ * @package property
+ */
+
+ class soadmin_entity
+ {
+ var $grants;
+
+ function soadmin_entity($entity_id='',$cat_id='')
+ {
+ $this->currentapp =
$GLOBALS['phpgw_info']['flags']['currentapp'];
+ $this->db = $GLOBALS['phpgw']->db;
+ $this->db2 = $this->db;
+ $this->account =
$GLOBALS['phpgw_info']['user']['account_id'];
+ $this->bocommon =
CreateObject($this->currentapp.'.bocommon');
+
+ $this->join = $this->bocommon->join;
+ $this->like = $this->bocommon->like;
+
+ if($entity_id && $cat_id)
+ {
+ $this->category_name =
$this->read_category_name($entity_id,$cat_id);
+ }
+ }
+
+ function reset_fm_cache()
+ {
+ $this->db->query("DELETE FROM fm_cache
",__LINE__,__FILE__);
+ }
+
+ function read($data)
+ {
+ if(is_array($data))
+ {
+ if ($data['start'])
+ {
+ $start=$data['start'];
+ }
+ else
+ {
+ $start=0;
+ }
+ $query =
(isset($data['query'])?$data['query']:'');
+ $sort =
(isset($data['sort'])?$data['sort']:'DESC');
+ $order =
(isset($data['order'])?$data['order']:'');
+ $allrows =
(isset($data['allrows'])?$data['allrows']:'');
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+
+ }
+ else
+ {
+ $ordermethod = ' order by id asc';
+ }
+
+ $table = 'fm_entity';
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " where name $this->like
'%$query%' or descr $this->like '%$query%'";
+ }
+
+ $sql = "SELECT * FROM $table $querymethod";
+
+ $this->db2->query($sql,__LINE__,__FILE__);
+ $this->total_records = $this->db2->num_rows();
+
+ if(!$allrows)
+ {
+ $this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
+ }
+ else
+ {
+ $this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
+ }
+
+ while ($this->db->next_record())
+ {
+ $entity[] = array
+ (
+ 'id' => $this->db->f('id'),
+ 'name' => $this->db->f('name'),
+ 'descr' => $this->db->f('descr'),
+ 'documentation' =>
$this->db->f('documentation')
+ );
+ }
+ return $entity;
+ }
+
+ function read_category($data)
+ {
+ if(is_array($data))
+ {
+ if ($data['start'])
+ {
+ $start=$data['start'];
+ }
+ else
+ {
+ $start=0;
+ }
+ $query =
(isset($data['query'])?$data['query']:'');
+ $sort =
(isset($data['sort'])?$data['sort']:'DESC');
+ $order =
(isset($data['order'])?$data['order']:'');
+ $allrows =
(isset($data['allrows'])?$data['allrows']:'');
+ $entity_id =
(isset($data['entity_id'])?$data['entity_id']:'');
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+
+ }
+ else
+ {
+ $ordermethod = ' order by id asc';
+ }
+
+ $table = 'fm_entity_category';
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " AND name $this->like
'%$query%' or descr $this->like '%$query%'";
+ }
+
+ $sql = "SELECT * FROM $table WHERE entity_id=$entity_id
$querymethod";
+
+ $this->db2->query($sql,__LINE__,__FILE__);
+ $this->total_records = $this->db2->num_rows();
+
+ if(!$allrows)
+ {
+ $this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
+ }
+ else
+ {
+ $this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
+ }
+
+ while ($this->db->next_record())
+ {
+ $standard[] = array
+ (
+ 'id' => $this->db->f('id'),
+ 'name' => $this->db->f('name'),
+ 'prefix'=> $this->db->f('prefix'),
+ 'descr' => $this->db->f('descr')
+ );
+ }
+ return $standard;
+ }
+
+ function read_status($data)
+ {
+ if(is_array($data))
+ {
+ if ($data['start'])
+ {
+ $start=$data['start'];
+ }
+ else
+ {
+ $start=0;
+ }
+ $query =
(isset($data['query'])?$data['query']:'');
+ $sort =
(isset($data['sort'])?$data['sort']:'DESC');
+ $order =
(isset($data['order'])?$data['order']:'');
+ $allrows =
(isset($data['allrows'])?$data['allrows']:'');
+ $entity_id =
(isset($data['entity_id'])?$data['entity_id']:'');
+ $cat_id =
(isset($data['cat_id'])?$data['cat_id']:'');
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+
+ }
+ else
+ {
+ $ordermethod = ' order by id asc';
+ }
+
+ $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " AND name $this->like
'%$query%' or descr $this->like '%$query%'";
+ }
+
+ $sql = "SELECT * FROM $table $querymethod";
+
+ $this->db2->query($sql,__LINE__,__FILE__);
+ $this->total_records = $this->db2->num_rows();
+
+ if(!$allrows)
+ {
+ $this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
+ }
+ else
+ {
+ $this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
+ }
+
+ while ($this->db->next_record())
+ {
+ $status[] = array
+ (
+ 'id' => $this->db->f('id'),
+ 'descr' => $this->db->f('descr')
+ );
+ }
+ return $status;
+ }
+
+
+ function read_single($id)
+ {
+
+ $sql = "SELECT * FROM fm_entity where id='$id'";
+
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ if ($this->db->next_record())
+ {
+ $entity['id'] =
$this->db->f('id');
+ $entity['name'] =
$this->db->f('name');
+ $entity['descr'] =
$this->db->f('descr');
+ $entity['location_form'] =
$this->db->f('location_form');
+ $entity['lookup_entity'] =
unserialize($this->db->f('lookup_entity'));
+ $entity['documentation'] =
$this->db->f('documentation');
+ }
+
+ $sql = "SELECT location FROM fm_entity_lookup where
entity_id=$id AND type='lookup'";
+
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ while ($this->db->next_record())
+ {
+ $entity['include_entity_for'][] =
$this->db->f('location');
+ }
+
+ $sql = "SELECT location FROM fm_entity_lookup where
entity_id=$id AND type='start'";
+
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ while ($this->db->next_record())
+ {
+ $entity['start_entity_from'][] =
$this->db->f('location');
+ }
+
+ return $entity;
+ }
+
+ function read_single_category($entity_id,$cat_id)
+ {
+ $sql = "SELECT * FROM fm_entity_category where
entity_id=$entity_id AND id=$cat_id";
+
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ if ($this->db->next_record())
+ {
+ $category['id'] =
$this->db->f('id');
+ $category['name'] =
$this->db->f('name');
+ $category['descr'] =
$this->db->f('descr');
+ $category['prefix'] =
$this->db->f('prefix');
+ $category['lookup_tenant'] =
$this->db->f('lookup_tenant');
+ $category['tracking'] =
$this->db->f('tracking');
+ $category['location_level'] =
$this->db->f('location_level');
+ $category['fileupload'] =
$this->db->f('fileupload');
+ $category['loc_link'] =
$this->db->f('loc_link');
+ $category['start_project'] =
$this->db->f('start_project');
+ return $category;
+ }
+ }
+
+ function read_category_name($entity_id,$cat_id)
+ {
+ $sql = "SELECT * FROM fm_entity_category where
entity_id=$entity_id AND id=$cat_id";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $this->db->next_record();
+ return $this->db->f('name');
+ }
+
+ function read_single_status($entity_id,$cat_id,$id)
+ {
+
+ $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
+ $sql = "SELECT * FROM $table where id='$id'";
+
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ if ($this->db->next_record())
+ {
+ $status['id'] =
$this->db->f('id');
+ $status['descr'] =
$this->db->f('descr');
+
+ return $status;
+ }
+ }
+
+ function add_entity($entity)
+ {
+ $entity['name'] =
$this->db->db_addslashes($entity['name']);
+ $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
+
+ $entity['id'] = $this->bocommon->next_id('fm_entity');
+
+ $values= array(
+ $entity['id'],
+ $entity['name'],
+ $entity['descr'],
+ $entity['location_form'],
+ $entity['documentation']
+ );
+
+ $values = $this->bocommon->validate_db_insert($values);
+
+ $this->db->query("INSERT INTO fm_entity (id,name,
descr,location_form,documentation) "
+ . "VALUES ($values)",__LINE__,__FILE__);
+
+
+ $values_acl_location= array(
+ '.entity.' . $entity['id'],
+ $entity['name'],
+ 1
+ );
+
+ $values_acl_location =
$this->bocommon->validate_db_insert($values_acl_location);
+
+ $this->db->query("INSERT INTO fm_acl_location
(id,descr,allow_grant) "
+ . "VALUES
($values_acl_location)",__LINE__,__FILE__);
+
+ $receipt['id']= $entity['id'];
+
+ $receipt['message'][] = array('msg'=> lang('entity has
been added'));
+ return $receipt;
+ }
+
+
+ function add_status($values,$entity_id,$cat_id)
+ {
+ $values['id'] = $this->db->db_addslashes($values['id']);
+ $values['descr'] =
$this->db->db_addslashes($values['descr']);
+
+ $values_insert= array(
+ $values['id'],
+ $values['descr'],
+ );
+
+ $values_insert =
$this->bocommon->validate_db_insert($values_insert);
+
+ $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
+
+ $this->db->query("INSERT INTO $table (id,descr) VALUES
($values_insert)",__LINE__,__FILE__);
+
+ $receipt['id']= $values['id'];
+
+ $receipt['message'][] = array('msg'=> lang('status has
been added'));
+ return $receipt;
+ }
+
+
+ function add_category($values)
+ {
+ $values['name'] =
$this->db->db_addslashes($values['name']);
+ $values['descr'] =
$this->db->db_addslashes($values['descr']);
+
+ $values['id'] =
$this->bocommon->next_id('fm_entity_category',array('entity_id'=>$values['entity_id']));
+
+ $location_type =
$this->bocommon->next_id('fm_location_type');
+
+ $values_insert= array(
+ $values['entity_id'],
+ $values['id'],
+ $values['name'],
+ $values['descr'],
+ $values['prefix'],
+ $values['lookup_tenant'],
+ $values['tracking'],
+ $values['location_level'],
+ $values['fileupload'],
+ $values['loc_link'],
+ $values['start_project']
+ );
+
+ $values_insert =
$this->bocommon->validate_db_insert($values_insert);
+
+
+ $this->db->transaction_begin();
+
+ $this->db->query("INSERT INTO fm_entity_category
(entity_id,id,name,
descr,prefix,lookup_tenant,tracking,location_level,fileupload,loc_link,start_project)
"
+ . "VALUES ($values_insert)",__LINE__,__FILE__);
+
+ $values_acl_location= array(
+ '.entity.' . $values['entity_id'] . '.' .
$values['id'],
+ $values['name'],
+ 1
+ );
+
+ $values_acl_location =
$this->bocommon->validate_db_insert($values_acl_location);
+
+ $this->db->query("INSERT INTO fm_acl_location
(id,descr,allow_grant) "
+ . "VALUES
($values_acl_location)",__LINE__,__FILE__);
+
+ $receipt['id']= $values['id'];
+
+ $this->init_process();
+
+ $fd=array();
+ $fd['id'] = array('type' => 'int', 'precision' => 4,
'nullable' => False);
+ $fd['num'] = array('type' => 'varchar', 'precision' =>
16, 'nullable' => False);
+ $fd['p_num'] = array('type' => 'varchar', 'precision'
=> 16, 'nullable' => True);
+ $fd['p_entity_id'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
+ $fd['p_cat_id'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
+ $fd['location_code'] = array('type' => 'varchar',
'precision' => 25, 'nullable' => True);
+
+ for ($i=1; $i<$location_type; $i++)
+ {
+ $fd['loc' . $i] = array('type' => 'varchar',
'precision' => 4, 'nullable' => True);
+ }
+
+ $fd['address'] = array('type' => 'varchar', 'precision'
=> 150, 'nullable' => True);
+ $fd['tenant_id'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
+ $fd['contact_phone'] = array('type' => 'varchar',
'precision' => 30, 'nullable' => True);
+ $fd['status'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
+ $fd['entry_date'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
+ $fd['user_id'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
+
+ $pk[]= 'id';
+ $table = 'fm_entity_'.
$values['entity_id'] .'_'.$values['id'];
+/*
+ $fd_status['id'] = array('type' => 'varchar',
'precision' => 20, 'nullable' => False);
+ $fd_status['descr'] = array('type' => 'varchar',
'precision' => 255, 'nullable' => False);
+ $pk_status[]= 'id';
+
+ $statustable = $table . '_' .'status';
+*/
+ if(($this->oProc->CreateTable($table,array('fd' =>
$fd,'pk' => $pk,'fk' => $fk,'ix' => array('location_code'),'uc' => array()))))
+// &&
($this->oProc->CreateTable($statustable,array('fd' => $fd_status,'pk' =>
$pk_status,'fk' => $fk_status,'ix' => False,'uc' => array()))))
+ {
+
+ $values_insert= array(
+ $values['entity_id'],
+ $values['id'],
+ 1,
+ 'status',
+ 'Status',
+ 'Status',
+ 'LB',
+ 1,
+ 'True'
+ );
+
+ $values_insert =
$this->bocommon->validate_db_insert($values_insert);
+
+ $this->db->query("INSERT INTO
fm_entity_attribute
(entity_id,cat_id,id,column_name,input_text,statustext,datatype,attrib_sort,nullable)
"
+ . "VALUES
($values_insert)",__LINE__,__FILE__);
+
+ $receipt['message'][] = array('msg' =>
lang('table %1 has been saved',$table));
+ $this->db->transaction_commit();
+ }
+ else
+ {
+ $receipt['error'][] = array('msg' =>
lang('table could not be added') );
+ if($this->db->Transaction)
+ {
+ $this->db->transaction_abort();
+ }
+ else
+ {
+ $this->db->query("DELETE FROM
fm_entity_category WHERE id=" . $values['id'] . " AND entity_id=" .
$values['entity_id'],__LINE__,__FILE__);
+ unset($receipt['id']);
+
+ }
+ }
+
+ return $receipt;
+ }
+
+ function edit_status($values,$entity_id,$cat_id)
+ {
+ $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
+
+ $values['descr'] =
$this->db->db_addslashes($values['descr']);
+
+ $value_set=array(
+ 'descr' => $values['descr'],
+ );
+
+ $value_set =
$this->bocommon->validate_db_update($value_set);
+
+ $this->db->query("UPDATE $table set $value_set WHERE
id='" . $values['id'] . "'",__LINE__,__FILE__);
+
+ $receipt['message'][] = array('msg'=> lang('Status has
been edited'));
+
+ return $receipt;
+ }
+
+ function edit_entity($entity)
+ {
+ if (!$entity['name'])
+ {
+ $receipt['error'][] = array('msg'=>lang('Name
not entered!'));
+ }
+
+ if (!$receipt['error'])
+ {
+ $table = 'fm_entity';
+
+ $entity['name'] =
$this->db->db_addslashes($entity['name']);
+ $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
+
+ if(!$entity['location_form'])
+ {
+ unset($entity['lookup_entity']);
+ }
+
+ $value_set=array(
+ 'descr' => $entity['descr'],
+ 'name' => $entity['name'],
+ 'location_form' => $entity['location_form'],
+ 'lookup_entity' =>
serialize($entity['lookup_entity']),
+ 'documentation' => $entity['documentation']
+ );
+
+ $value_set =
$this->bocommon->validate_db_update($value_set);
+
+ $this->db->transaction_begin();
+
+ $this->db->query("UPDATE $table set $value_set
WHERE id=" . $entity['id'],__LINE__,__FILE__);
+
+ $value_set_acl=array(
+ 'descr' =>
$entity['name']
+ );
+
+ $value_set_acl =
$this->bocommon->validate_db_update($value_set_acl);
+
+ $this->db->query("UPDATE fm_acl_location set
$value_set_acl WHERE id='.entity." . $entity['id']. "'",__LINE__,__FILE__);
+
+ $this->db->query("DELETE FROM fm_entity_lookup
WHERE type='lookup' AND entity_id=" . $entity['id'],__LINE__,__FILE__);
+ if (isset($entity['include_entity_for']) AND
is_array($entity['include_entity_for']))
+ {
+ foreach($entity['include_entity_for']
as $location)
+ {
+ $this->db->query("INSERT INTO
fm_entity_lookup (entity_id,location,type)"
+ . "VALUES (" .$entity['id'] .
",'$location','lookup' )",__LINE__,__FILE__);
+ }
+ }
+
+ $this->db->query("DELETE FROM fm_entity_lookup
WHERE type='start' AND entity_id=" . $entity['id'],__LINE__,__FILE__);
+
+ if (isset($entity['start_entity_from']) AND
is_array($entity['start_entity_from']))
+ {
+ foreach($entity['start_entity_from'] as
$location)
+ {
+ $this->db->query("INSERT INTO
fm_entity_lookup (entity_id,location,type)"
+ . "VALUES (" .$entity['id'] .
",'$location','start' )",__LINE__,__FILE__);
+ }
+ }
+
+ $this->db->transaction_commit();
+
+ $receipt['message'][] = array('msg'=>
lang('entity has been edited'));
+ }
+ else
+ {
+ $receipt['error'][] = array('msg' =>
lang('entity has NOT been edited'));
+ }
+
+ return $receipt;
+ }
+
+ function edit_category($entity)
+ {
+
+ if (!$entity['name'])
+ {
+ $receipt['error'][] = array('msg'=>lang('Name
not entered!'));
+ }
+
+ if (!$receipt['error'])
+ {
+ $table = 'fm_entity_category';
+
+ $entity['name'] =
$this->db->db_addslashes($entity['name']);
+ $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
+
+ $value_set=array(
+ 'descr' =>
$entity['descr'],
+ 'name' =>
$entity['name'],
+ 'prefix' =>
$entity['prefix'],
+ 'lookup_tenant' =>
$entity['lookup_tenant'],
+ 'tracking' =>
$entity['tracking'],
+ 'location_level'=>
$entity['location_level'],
+ 'fileupload' =>
$entity['fileupload'],
+ 'loc_link' =>
$entity['loc_link'],
+ 'start_project' =>
$entity['start_project']
+ );
+
+ $value_set =
$this->bocommon->validate_db_update($value_set);
+
+ $this->db->query("UPDATE $table set $value_set
WHERE entity_id=" . $entity['entity_id']. " AND id=" .
$entity['id'],__LINE__,__FILE__);
+
+ $value_set_acl=array(
+ 'descr' =>
$entity['name']
+ );
+
+ $value_set_acl =
$this->bocommon->validate_db_update($value_set_acl);
+
+ $this->db->query("UPDATE fm_acl_location set
$value_set_acl WHERE id='.entity." . $entity['entity_id']. "." . $entity['id'].
"'",__LINE__,__FILE__);
+
+
+ $receipt['message'][] = array('msg'=>
lang('entity has been edited'));
+ }
+ else
+ {
+ $receipt['error'][] = array('msg' =>
lang('entity has NOT been edited'));
+ }
+
+ return $receipt;
+ }
+
+ function delete_entity($id)
+ {
+
$category_list=$this->read_category(array('entity_id'=>$id));
+ $this->db->query("DELETE FROM fm_entity WHERE
id=$id",__LINE__,__FILE__);
+ $this->db->query("DELETE FROM fm_entity_category WHERE
entity_id=$id",__LINE__,__FILE__);
+ $this->db->query("DELETE FROM fm_entity_attribute WHERE
entity_id=$id",__LINE__,__FILE__);
+ $this->db->query("DELETE FROM fm_acl_location WHERE id
$this->like '.entity." . $id ."%'",__LINE__,__FILE__);
+ $this->db->query("DELETE FROM fm_acl2 WHERE
acl_location $this->like '.entity." . $id ."%'",__LINE__,__FILE__);
+ if (isset($category_list) AND is_array($category_list))
+ {
+ $this->init_process();
+
+ foreach($category_list as $entry)
+ {
+ $this->oProc->DropTable('fm_entity_' .
$id . '_' . $entry['id']);
+ }
+ }
+
+ }
+
+ function delete_category($id,$entity_id)
+ {
+ $this->init_process();
+ $this->oProc->DropTable('fm_entity_' . $entity_id . '_'
. $id);
+// $this->oProc->DropTable('fm_entity_' . $entity_id . '_'
. $id . '_' . 'status');
+ $this->db->query("DELETE FROM fm_entity_category WHERE
entity_id= $entity_id AND id= $id",__LINE__,__FILE__);
+ $this->db->query("DELETE FROM fm_entity_attribute WHERE
entity_id= $entity_id AND cat_id= $id",__LINE__,__FILE__);
+ $this->db->query("DELETE FROM fm_acl_location WHERE
id='.entity." . $entity_id . "." . $id ."'",__LINE__,__FILE__);
+ $this->db->query("DELETE FROM fm_acl2 WHERE
acl_location='.entity." . $entity_id . "." . $id ."'",__LINE__,__FILE__);
+ }
+
+ function delete_attrib($cat_id,$entity_id,$attrib_id)
+ {
+ $this->init_process();
+
+ $sql = "SELECT * FROM fm_entity_attribute WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id";
+
+ $this->db->query($sql,__LINE__,__FILE__);
+ $this->db->next_record();
+ $ColumnName = $this->db->f('column_name');
+
+ $this->oProc->DropColumn('fm_entity_' .$entity_id.'_'.
$cat_id,'', $ColumnName);
+
+ $sql = "SELECT attrib_sort FROM fm_entity_attribute
where entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $this->db->next_record();
+ $attrib_sort = $this->db->f('attrib_sort');
+ $sql2 = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=$entity_id AND cat_id=$cat_id";
+ $this->db->query($sql2,__LINE__,__FILE__);
+ $this->db->next_record();
+ $max_sort = $this->db->f('max_sort');
+ if($max_sort>$attrib_sort)
+ {
+ $sql = "UPDATE fm_entity_attribute set
attrib_sort=attrib_sort-1 WHERE entity_id=$entity_id AND cat_id=$cat_id AND
attrib_sort > $attrib_sort";
+ $this->db->query($sql,__LINE__,__FILE__);
+ }
+
+ $this->db->query("DELETE FROM fm_entity_attribute WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id",__LINE__,__FILE__);
+ }
+
+ function delete_status($cat_id,$entity_id,$status_id)
+ {
+ $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
+
+ $this->db->query("DELETE FROM $table WHERE
id='$status_id'",__LINE__,__FILE__);
+ }
+
+ function read_attrib($data)
+ {
+
+//_debug_array($data);
+ if(is_array($data))
+ {
+ if ($data['start'])
+ {
+ $start=$data['start'];
+ }
+ else
+ {
+ $start=0;
+ }
+ $query =
(isset($data['query'])?$data['query']:'');
+ $sort =
(isset($data['sort'])?$data['sort']:'DESC');
+ $order =
(isset($data['order'])?$data['order']:'');
+ $allrows =
(isset($data['allrows'])?$data['allrows']:'');
+ $entity_id =
(isset($data['entity_id'])?$data['entity_id']:0);
+ $cat_id =
(isset($data['cat_id'])?$data['cat_id']:0);
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+
+ }
+ else
+ {
+ $ordermethod = ' order by attrib_sort asc';
+ }
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " AND (fm_entity_attribute.name
$this->like '%$query%' or fm_entity_attribute.descr $this->like '%$query%')";
+ }
+
+ $sql = "SELECT * FROM fm_entity_attribute WHERE
entity_id=$entity_id AND cat_id = $cat_id $filtermethod $querymethod";
+
+ $this->db2->query($sql,__LINE__,__FILE__);
+ $this->total_records = $this->db2->num_rows();
+ if(!$allrows)
+ {
+ $this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
+ }
+ else
+ {
+ $this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
+ }
+
+
+ while ($this->db->next_record())
+ {
+ $attrib[] = array
+ (
+ 'id' =>
$this->db->f('id'),
+ 'entity_type' =>
$this->db->f('type_id'),
+ 'attrib_sort' =>
$this->db->f('attrib_sort'),
+ 'list' =>
$this->db->f('list'),
+ 'lookup_form' =>
$this->db->f('lookup_form'),
+ 'entity_form' =>
$this->db->f('entity_form'),
+ 'column_name' =>
$this->db->f('column_name'),
+ 'name' =>
$this->db->f('input_text'),
+ 'size' =>
$this->db->f('size'),
+ 'statustext' =>
$this->db->f('statustext'),
+ 'input_text' =>
$this->db->f('input_text'),
+ 'type_name' =>
$this->db->f('type'),
+ 'datatype' =>
$this->db->f('datatype'),
+ 'search' =>
$this->db->f('search')
+ );
+ }
+ return $attrib;
+ }
+
+ function read_single_attrib($entity_id,$cat_id,$id)
+ {
+
+ $sql = "SELECT * FROM fm_entity_attribute where
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
+
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ if ($this->db->next_record())
+ {
+ $attrib['id']
= $this->db->f('id');
+ $attrib['column_name']
= $this->db->f('column_name');
+ $attrib['input_text']
= $this->db->f('input_text');
+ $attrib['statustext']
= $this->db->f('statustext');
+ $attrib['column_info']['precision'] =
$this->db->f('precision_');
+ $attrib['column_info']['scale'] =
$this->db->f('scale');
+ $attrib['column_info']['default'] =
$this->db->f('default_value');
+ $attrib['column_info']['nullable'] =
$this->db->f('nullable');
+ $attrib['column_info']['type'] =
$this->db->f('datatype');
+ $attrib['type_id']
= $this->db->f('type_id');
+ $attrib['type_name']
= $this->db->f('type_name');
+ $attrib['lookup_form']
= $this->db->f('lookup_form');
+ $attrib['list']
= $this->db->f('list');
+ $attrib['search']
= $this->db->f('search');
+ if($this->db->f('datatype')=='R' ||
$this->db->f('datatype')=='CH' || $this->db->f('datatype')=='LB')
+ {
+ $attrib['choice'] =
$this->read_attrib_choice($entity_id,$cat_id,$id);
+ }
+
+ return $attrib;
+ }
+ }
+
+ function read_attrib_choice($entity_id,$cat_id,$attrib_id)
+ {
+ $choice_table = 'fm_entity_choice';
+ $sql = "SELECT * FROM $choice_table WHERE
entity_id=$entity_id AND cat_id=$cat_id AND attrib_id=$attrib_id";
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ while ($this->db->next_record())
+ {
+ $choice[] = array
+ (
+ 'id' => $this->db->f('id'),
+ 'value' => $this->db->f('value')
+ );
+ }
+ return $choice;
+ }
+
+ function add_attrib($attrib)
+ {
+
+ $attrib['column_name'] =
$this->db->db_addslashes($attrib['column_name']);
+ $attrib['input_text'] =
$this->db->db_addslashes($attrib['input_text']);
+ $attrib['statustext'] =
$this->db->db_addslashes($attrib['statustext']);
+ $attrib['default'] =
$this->db->db_addslashes($attrib['default']);
+ $attrib['id'] =
$this->bocommon->next_id('fm_entity_attribute',array('entity_id'=>$attrib['entity_id'],'cat_id'=>$attrib['cat_id']));
+
+ $sql = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=" . $attrib['entity_id'] . " AND cat_id=" .
$attrib['cat_id'];
+ $this->db->query($sql,__LINE__,__FILE__);
+ $this->db->next_record();
+ $attrib_sort = $this->db->f('max_sort')+1;
+
+ $values= array(
+ $attrib['entity_id'],
+ $attrib['cat_id'],
+ $attrib['id'],
+ $attrib['column_name'],
+ $attrib['input_text'],
+ $attrib['statustext'],
+ $attrib['search'],
+ $attrib['list'],
+ $attrib_sort,
+ $attrib['column_info']['type'],
+ $attrib['column_info']['precision'],
+ $attrib['column_info']['scale'],
+ $attrib['column_info']['default'],
+ $attrib['column_info']['nullable']
+ );
+
+ $values = $this->bocommon->validate_db_insert($values);
+
+ $this->db->transaction_begin();
+
+ $this->db->query("INSERT INTO fm_entity_attribute
(entity_id,cat_id,id,column_name, input_text,
statustext,search,list,attrib_sort,
datatype,precision_,scale,default_value,nullable) "
+ . "VALUES ($values)",__LINE__,__FILE__);
+
+ $receipt['id']= $attrib['id'];
+
+ if($attrib['column_info']['type']=='email' &&
!$attrib['column_info']['precision'])
+ {
+ $attrib['column_info']['precision']=64;
+ }
+
+ $attrib['column_info']['type'] =
$this->bocommon->translate_datatype_insert($attrib['column_info']['type']);
+
+ if($attrib['column_info']['type']=='int' &&
!$attrib['column_info']['precision'])
+ {
+ $attrib['column_info']['precision']=4;
+ }
+
+ if(!$attrib['column_info']['default'])
+ {
+ unset($attrib['column_info']['default']);
+ }
+
+ $this->init_process();
+
+
if($this->oProc->AddColumn('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'],$attrib['column_name'], $attrib['column_info']))
+ {
+ $receipt['message'][] = array('msg' =>
lang('Attribute has been saved') );
+ $this->db->transaction_commit();
+
+ }
+ else
+ {
+ $receipt['error'][] = array('msg' =>
lang('column could not be added') );
+ if($this->db->Transaction)
+ {
+ $this->db->transaction_abort();
+ }
+ else
+ {
+ $this->db->query("DELETE FROM
fm_entity_attribute WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['id']. " AND id='" . $receipt['id'] . "'",__LINE__,__FILE__);
+ unset($receipt['id']);
+
+ }
+ }
+
+ return $receipt;
+ }
+
+ function init_process()
+ {
+ $this->oProc
=
CreateObject('phpgwapi.schema_proc',$GLOBALS['phpgw_info']['server']['db_type']);
+ $this->oProc->m_odb
= $this->db;
+ $this->oProc->m_odb->Halt_On_Error = 'report';
+ }
+
+ function edit_attrib($attrib)
+ {
+
+ $choice_table = 'fm_entity_choice';
+
+ $attrib['column_name'] =
$this->db->db_addslashes($attrib['column_name']);
+ $attrib['input_text'] =
$this->db->db_addslashes($attrib['input_text']);
+ $attrib['statustext'] =
$this->db->db_addslashes($attrib['statustext']);
+ $attrib['default'] =
$this->db->db_addslashes($attrib['default']);
+
+ $this->db->query("SELECT column_name FROM
fm_entity_attribute WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND id='" . $attrib['id']. "'",__LINE__,__FILE__);
+ $this->db->next_record();
+ $OldColumnName = $this->db->f('column_name');
+
+ $this->db->transaction_begin();
+
+ $value_set=array(
+ 'input_text' =>
$attrib['input_text'],
+ 'statustext' =>
$attrib['statustext'],
+ 'search' =>
$attrib['search'],
+ 'list' =>
$attrib['list'],
+ );
+
+ $value_set =
$this->bocommon->validate_db_update($value_set);
+
+ $this->db->query("UPDATE fm_entity_attribute
set $value_set WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND id=" . $attrib['id'],__LINE__,__FILE__);
+
+ if($OldColumnName !=$attrib['column_name'])
+ {
+
+ if($attrib['column_info']['type']!='R' &&
$attrib['column_info']['type']!='CH' && $attrib['column_info']['type']!='LB')
+ {
+ $this->db->query("DELETE FROM
$choice_table WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND attrib_id=" . $attrib['id'],__LINE__,__FILE__);
+ }
+
+ if($attrib['column_info']['type']=='email' &&
!$attrib['column_info']['precision'])
+ {
+ $attrib['column_info']['precision']=64;
+ }
+
+ if($precision =
$this->bocommon->translate_datatype_precision($attrib['column_info']['type']))
+ {
+
$attrib['column_info']['precision']=$precision;
+ }
+
+ if(!$attrib['column_info']['default'])
+ {
+
unset($attrib['column_info']['default']);
+ }
+
+ $value_set=array(
+ 'column_name' =>
$attrib['column_name'],
+ 'datatype' =>
$attrib['column_info']['type'],
+ 'precision_' =>
$attrib['column_info']['precision'],
+ 'scale' =>
$attrib['column_info']['scale'],
+ 'default_value' =>
$attrib['column_info']['default'],
+ 'nullable' =>
$attrib['column_info']['nullable']
+ );
+
+ $value_set =
$this->bocommon->validate_db_update($value_set);
+
+ $this->db->query("UPDATE fm_entity_attribute
set $value_set WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND id=" . $attrib['id'],__LINE__,__FILE__);
+
+ $attrib['column_info']['type'] =
$this->bocommon->translate_datatype_insert($attrib['column_info']['type']);
+
+ $this->init_process();
+
+ $mini_table_def = array(
+ 'fm_entity_'.$attrib['entity_id'] . '_'
. $attrib['cat_id'] => array(
+ 'fd' => array(
+ $OldColumnName
=>$attrib['column_info']),
+ 'pk' => array(),
+ 'fk' => array(),
+ 'ix' => array(),
+ 'uc' => array()
+ )
+ );
+
+ $this->oProc->GenerateScripts($mini_table_def);
+
$this->oProc->RenameColumn('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'], $OldColumnName, $attrib['column_name']);
+
$this->oProc->AlterColumn('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'],$attrib['column_name'],$attrib['column_info']);
+ }
+
+ $choice_table ='fm_entity_choice';
+
+ if($attrib['new_choice'])
+ {
+ $choice_id =
$this->bocommon->next_id($choice_table
,array('entity_id'=>$attrib['entity_id'],'cat_id'=>$attrib['cat_id'],'attrib_id'=>$attrib['id']));
+
+ $values= array(
+ $attrib['entity_id'],
+ $attrib['cat_id'],
+ $attrib['id'],
+ $choice_id,
+ $attrib['new_choice']
+ );
+
+ $values =
$this->bocommon->validate_db_insert($values);
+
+ $this->db->query("INSERT INTO $choice_table
(entity_id,cat_id,attrib_id,id,value) "
+ . "VALUES ($values)",__LINE__,__FILE__);
+ }
+
+ if($attrib['delete_choice'])
+ {
+ for
($i=0;$i<count($attrib['delete_choice']);$i++)
+ {
+ $this->db->query("DELETE FROM
$choice_table WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND attrib_id=" . $attrib['id'] ." AND id=" .
$attrib['delete_choice'][$i],__LINE__,__FILE__);
+ }
+ }
+
+ $this->db->transaction_commit();
+
+ $receipt['message'][] = array('msg' =>
lang('Attribute has been edited'));
+
+ return $receipt;
+ }
+
+ function resort_attrib($data)
+ {
+ if(is_array($data))
+ {
+ $resort =
(isset($data['resort'])?$data['resort']:'up');
+ $entity_id =
(isset($data['entity_id'])?$data['entity_id']:0);
+ $cat_id =
(isset($data['cat_id'])?$data['cat_id']:0);
+ $id = (isset($data['id'])?$data['id']:'');
+ }
+
+ $sql = "SELECT attrib_sort FROM fm_entity_attribute
where entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $this->db->next_record();
+ $attrib_sort = $this->db->f('attrib_sort');
+ $sql2 = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=$entity_id AND cat_id=$cat_id";
+ $this->db->query($sql2,__LINE__,__FILE__);
+ $this->db->next_record();
+ $max_sort = $this->db->f('max_sort');
+
+ switch($resort)
+ {
+ case 'up':
+ if($attrib_sort>1)
+ {
+ $sql = "UPDATE
fm_entity_attribute set attrib_sort=$attrib_sort WHERE entity_id=$entity_id AND
cat_id=$cat_id AND attrib_sort =" . ($attrib_sort-1);
+
$this->db->query($sql,__LINE__,__FILE__);
+ $sql = "UPDATE
fm_entity_attribute set attrib_sort=" . ($attrib_sort-1) ." WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
+
$this->db->query($sql,__LINE__,__FILE__);
+ }
+ break;
+ case 'down':
+ if($max_sort > $attrib_sort)
+ {
+ $sql = "UPDATE
fm_entity_attribute set attrib_sort=$attrib_sort WHERE entity_id=$entity_id AND
cat_id=$cat_id AND attrib_sort =" . ($attrib_sort+1);
+
$this->db->query($sql,__LINE__,__FILE__);
+ $sql = "UPDATE
fm_entity_attribute set attrib_sort=" . ($attrib_sort+1) ." WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
+
$this->db->query($sql,__LINE__,__FILE__);
+ }
+ break;
+ default:
+ return;
+ break;
+ }
+ }
+
+ function read_custom_function($data)
+ {
+ if(is_array($data))
+ {
+ if ($data['start'])
+ {
+ $start=$data['start'];
+ }
+ else
+ {
+ $start=0;
+ }
+ $query =
(isset($data['query'])?$data['query']:'');
+ $sort =
(isset($data['sort'])?$data['sort']:'DESC');
+ $order =
(isset($data['order'])?$data['order']:'');
+ $allrows =
(isset($data['allrows'])?$data['allrows']:'');
+ $acl_location =
(isset($data['acl_location'])?$data['acl_location']:'');
+ }
+
+ if(!$acl_location)
+ {
+ return;
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+
+ }
+ else
+ {
+ $ordermethod = ' order by custom_sort asc';
+ }
+
+ $table = 'fm_custom_function';
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " AND name $this->like
'%$query%' or descr $this->like '%$query%'";
+ }
+
+ $sql = "SELECT * FROM $table WHERE
acl_location='$acl_location' $querymethod";
+
+ $this->db2->query($sql,__LINE__,__FILE__);
+ $this->total_records = $this->db2->num_rows();
+
+ if(!$allrows)
+ {
+ $this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
+ }
+ else
+ {
+ $this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
+ }
+
+ while ($this->db->next_record())
+ {
+ $custom_function[] = array
+ (
+ 'id' => $this->db->f('id'),
+ 'file_name' =>
$this->db->f('file_name'),
+ 'sorting' =>
$this->db->f('custom_sort'),
+ 'descr' =>
$this->db->f('descr'),
+ 'active' =>
$this->db->f('active')
+ );
+ }
+ return $custom_function;
+ }
+
+
+ function read_single_custom_function($acl_location,$id)
+ {
+
+ $sql = "SELECT * FROM fm_custom_function where
acl_location='$acl_location' AND id=$id";
+
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ if ($this->db->next_record())
+ {
+ $custom_function['id'] =
$this->db->f('id');
+ $custom_function['descr'] =
$this->db->f('descr');
+ $custom_function['custom_function_file']=
$this->db->f('file_name');
+ $custom_function['active'] =
$this->db->f('active');
+
+ return $custom_function;
+ }
+
+ }
+
+ function add_custom_function($custom_function)
+ {
+ if(!$custom_function['acl_location'] &&
$custom_function['entity_id'] && $custom_function['cat_id'])
+ {
+ $acl_location = '.entity.' .
$custom_function['entity_id'] . '.' . $custom_function['cat_id'];
+ }
+ else
+ {
+ $acl_location =
$custom_function['acl_location'];
+ }
+
+ if(!$acl_location)
+ {
+ return $receipt['error'][] = array('msg' =>
lang('acl_locastion is missing'));
+ }
+
+ $custom_function['descr'] =
$this->db->db_addslashes($custom_function['descr']);
+
+
+ $this->db->query("SELECT max(id) as maximum FROM
fm_custom_function WHERE acl_location='$acl_location'",__LINE__,__FILE__);
+ $this->db->next_record();
+ $custom_function['id'] = $this->db->f('maximum')+1;
+
+ $sql = "SELECT max(custom_sort) as max_sort FROM
fm_custom_function where acl_location='$acl_location'";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $this->db->next_record();
+ $custom_sort = $this->db->f('max_sort')+1;
+
+ $values= array(
+ $acl_location,
+ $custom_function['id'],
+ $custom_function['custom_function_file'],
+ $custom_function['descr'],
+ $custom_function['active'],
+ $custom_sort
+ );
+
+ $values = $this->bocommon->validate_db_insert($values);
+
+//_debug_array($custom_function);
+ $this->db->transaction_begin();
+
+ $this->db->query("INSERT INTO fm_custom_function
(acl_location, id, file_name, descr, active, custom_sort) "
+ . "VALUES ($values)",__LINE__,__FILE__);
+
+ $receipt['id']= $custom_function['id'];
+
+ $this->db->transaction_commit();
+
+ return $receipt;
+ }
+
+ function edit_custom_function($custom_function)
+ {
+ if(!$custom_function['acl_location'] &&
$custom_function['entity_id'] && $custom_function['cat_id'])
+ {
+ $acl_location = '.entity.' .
$custom_function['entity_id'] . '.' . $custom_function['cat_id'];
+ }
+ else
+ {
+ $acl_location =
$custom_function['acl_location'];
+ }
+
+ if(!$acl_location)
+ {
+ return $receipt['error'][] = array('msg' =>
lang('acl_locastion is missing'));
+ }
+
+ $custom_function['descr'] =
$this->db->db_addslashes($custom_function['descr']);
+
+ $this->db->transaction_begin();
+
+ $value_set=array(
+ 'descr' =>
$custom_function['descr'],
+ 'file_name' =>
$custom_function['custom_function_file'],
+ 'active' =>
$custom_function['active']
+ );
+
+ $value_set =
$this->bocommon->validate_db_update($value_set);
+
+ $this->db->query("UPDATE fm_custom_function set
$value_set WHERE acl_location='" . $acl_location . "' AND id=" .
$custom_function['id'],__LINE__,__FILE__);
+
+ $this->db->transaction_commit();
+
+ $receipt['message'][] = array('msg' => lang('Custom
function has been edited'));
+
+ return $receipt;
+ }
+
+ function resort_custom_function($data)
+ {
+ if(is_array($data))
+ {
+ $resort =
(isset($data['resort'])?$data['resort']:'up');
+ $entity_id =
(isset($data['entity_id'])?$data['entity_id']:'');
+ $cat_id =
(isset($data['cat_id'])?$data['cat_id']:'');
+ $acl_location =
(isset($data['acl_location'])?$data['acl_location']:'');
+ $id = (isset($data['id'])?$data['id']:'');
+ }
+
+ if(!$acl_location && $entity_id && $cat_id)
+ {
+ $acl_location = '.entity.' . $entity_id . '.' .
$cat_id;
+ }
+ else
+ {
+ $acl_location = $acl_location;
+ }
+
+ if(!$acl_location)
+ {
+ return $receipt['error'][] = array('msg' =>
lang('acl_locastion is missing'));
+ }
+
+ $sql = "SELECT custom_sort FROM fm_custom_function
where acl_location='$acl_location' AND id=$id";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $this->db->next_record();
+ $custom_sort = $this->db->f('custom_sort');
+ $sql2 = "SELECT max(custom_sort) as max_sort FROM
fm_custom_function where acl_location='$acl_location'";
+ $this->db->query($sql2,__LINE__,__FILE__);
+ $this->db->next_record();
+ $max_sort = $this->db->f('max_sort');
+
+ switch($resort)
+ {
+ case 'up':
+ if($custom_sort>1)
+ {
+ $sql = "UPDATE
fm_custom_function set custom_sort=$custom_sort WHERE
acl_location='$acl_location' AND custom_sort =" . ($custom_sort-1);
+
$this->db->query($sql,__LINE__,__FILE__);
+ $sql = "UPDATE
fm_custom_function set custom_sort=" . ($custom_sort-1) ." WHERE
acl_location='$acl_location' AND id=$id";
+
$this->db->query($sql,__LINE__,__FILE__);
+ }
+ break;
+ case 'down':
+ if($max_sort > $custom_sort)
+ {
+ $sql = "UPDATE
fm_custom_function set custom_sort=$custom_sort WHERE
acl_location='$acl_location' AND custom_sort =" . ($custom_sort+1);
+
$this->db->query($sql,__LINE__,__FILE__);
+ $sql = "UPDATE
fm_custom_function set custom_sort=" . ($custom_sort+1) ." WHERE
acl_location='$acl_location' AND id=$id";
+
$this->db->query($sql,__LINE__,__FILE__);
+ }
+ break;
+ default:
+ return;
+ break;
+ }
+ }
+
+ function
delete_custom_function($acl_location,$custom_function_id)
+ {
+ $sql = "SELECT custom_sort FROM fm_custom_function
where acl_location='$acl_location' AND id=$custom_function_id";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $this->db->next_record();
+ $custom_sort = $this->db->f('custom_sort');
+ $sql2 = "SELECT max(custom_sort) as max_sort FROM
fm_custom_function where acl_location='$acl_location'";
+ $this->db->query($sql2,__LINE__,__FILE__);
+ $this->db->next_record();
+ $max_sort = $this->db->f('max_sort');
+ if($max_sort>$custom_sort)
+ {
+ $sql = "UPDATE fm_custom_function set
custom_sort=custom_sort-1 WHERE acl_location='$acl_location' AND custom_sort >
$custom_sort";
+ $this->db->query($sql,__LINE__,__FILE__);
+ }
+ $this->db->query("DELETE FROM fm_custom_function WHERE
acl_location='$acl_location' AND id=$custom_function_id",__LINE__,__FILE__);
+ }
+ }
+?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/inc class.boentity.inc.php, 1.12 class.soadmin_entity.inc.php, 1.10,
sigurdne <=