[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/class.soactor.php, 1.1.2.1
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/class.soactor.php, 1.1.2.1 |
Date: |
Sun, 20 Jun 2004 11:04:46 +0200 |
Update of /property
Added Files:
Branch: proposal-branch
class.soactor.php
date: 2004/06/20 09:04:46; author: sigurdne; state: Exp; lines: +858 -0
Log Message:
no message
=====================================================================
<?php
/**************************************************************************\
* phpGroupWare - property
*
* http://www.phpgroupware.org
*
*
*
* Facilities Management
*
* Written by Sigurd Nes [sigurdne at online.no]
*
*
------------------------------------------------------------------------ *
* Copyright 2000 - 2003 Free Software Foundation, Inc
*
* This program is part of the GNU project, see http://www.gnu.org/
*
*
------------------------------------------------------------------------ *
* This program is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU General Public License as published by the
*
* Free Software Foundation; either version 2 of the License, or (at
your *
* option) any later version.
*
\**************************************************************************/
class property_soactor
{
var $role;
function property_soactor()
{
$this->currentapp = 'property';
//$GLOBALS['phpgw_data']['flags']['req_app'];
$this->functions =
CreateObject($this->currentapp.'_functions');
// $this->db = $GLOBALS['phpgw']->db;
// $this->db2 = $this->db;
$this->account = $GLOBALS['phpgw_data']['user']['id'];
$this->bocommon =
CreateObject($this->currentapp.'_bocommon');
$this->join = $this->bocommon->join;
$this->left_join = $this->bocommon->left_join;
}
function select_category_list()
{
$table = 'fm_' . $this->role . '_category';
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
id,descr FROM $table ORDER BY descr ");
$i = 0;
while (!$dbresult->EOF)
{
$categories[$i]['id']
= $dbresult->fields['id'];
$categories[$i]['name']
= stripslashes($dbresult->fields['descr']);
$i++;
$dbresult->MoveNext();
}
return $categories;
}
function read($data)
{
if(is_array($data))
{
$start =
(isset($data['start'])?$data['start']:0);
$filter =
(isset($data['filter'])?$data['filter']:'none');
$query =
(isset($data['query'])?$data['query']:'');
$sort =
(isset($data['sort'])?$data['sort']:'DESC');
$order =
(isset($data['order'])?$data['order']:'');
$cat_id =
(isset($data['cat_id'])?$data['cat_id']:'');
$allrows =
(isset($data['allrows'])?$data['allrows']:'');
$member_id =
(isset($data['member_id'])?$data['member_id']:0);
}
$sql = $this->bocommon->fm_cache('sql_actor_' .
$this->role . $lookup);
$entity_table = 'fm_' . $this->role;
$category_table = 'fm_' . $this->role . '_category';
$choice_table = 'fm_' . $this->role . '_choice';
$attribute_table = 'fm_' . $this->role . '_attribute';
if(!$sql)
{
$cols = $entity_table .
".*,$category_table.descr as category";
$cols_return[] = 'id';
$uicols['input_type'][] = 'text';
$uicols['name'][] = 'id';
$uicols['descr'][] =
lang('ID');
$uicols['statustext'][] = lang('ID');
$cols_return[] = 'id';
$uicols['input_type'][] = 'hidden';
$uicols['name'][] = 'id';
$uicols['descr'][] = false;
$uicols['statustext'][] = false;
$cols_return[] =
'category';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'category';
$uicols['descr'][] =
lang('category');
$uicols['statustext'][] =
lang('category');
$paranthesis .='(';
$joinmethod .= " $this->join " . $entity_table
. "_category ON ( $entity_table" . ".category =" .$entity_table .
"_category.id))";
$from .= " FROM $paranthesis $entity_table ";
$sql = "SELECT $cols $from $joinmethod";
$this->bocommon->fm_cache('sql_actor_' .
$this->role . $lookup,$sql);
$this->bocommon->fm_cache('uicols_actor_' .
$this->role . $lookup,$uicols);
$this->bocommon->fm_cache('cols_return_actor_'
. $this->role . $lookup,$cols_return);
}
else
{
$uicols
= $this->bocommon->fm_cache('uicols_actor_'. $this->role . $lookup);
$cols_return
= $this->bocommon->fm_cache('cols_return_actor_' . $this->role . $lookup);
if($lookup)
{
$admin_entity =
CreateObject($this->currentapp.'_soadmin_entity');
$category =
$admin_entity->read_single_category($entity_id,$cat_id);
}
}
$i = count($uicols['name']);
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT *
FROM $attribute_table WHERE list=1");
while (!$dbresult->EOF)
{
$uicols['input_type'][] = 'text';
$uicols['name'][] =
$dbresult->fields['column_name'];
$uicols['descr'][] =
$dbresult->fields['input_text'];
$uicols['statustext'][] =
$dbresult->fields['statustext'];
$uicols['datatype'][$i] =
$dbresult->fields['datatype'];
$cols_return_extra[]= array(
'name' =>
$dbresult->fields['column_name'],
'datatype' =>
$dbresult->fields['datatype'],
'attrib_id' =>
$dbresult->fields['id']
);
$i++;
$dbresult->MoveNext();
}
$user_columns=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['actor_columns_'
. $this->role];
//_debug_array($user_columns);
if (isset($user_columns) AND is_array($user_columns)
AND $user_columns[0])
{
foreach($user_columns as $column_id)
{
$dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT * FROM $attribute_table WHERE id=
$column_id");
$this->db->next_record();
$uicols['input_type'][] =
'text';
$uicols['name'][]
= $dbresult->fields['column_name'];
$uicols['descr'][]
= $dbresult->fields['input_text'];
$uicols['statustext'][] =
$dbresult->fields['statustext'];
$uicols['datatype'][$i] =
$dbresult->fields['datatype'];
$cols_return_extra[]= array(
'name' =>
$dbresult->fields['column_name'],
'datatype' =>
$dbresult->fields['datatype'],
'attrib_id' =>
$dbresult->fields['id']
);
$i++;
}
}
$this->uicols = $uicols;
//_debug_array($cols_return_extra);
if ($order)
{
$ordermethod = " order by $entity_table.$order
$sort";
}
else
{
$ordermethod = " order by $entity_table.id
DESC";
}
$where= 'WHERE';
/* if ($filter=='all')
{
if (is_array($grants))
{
while (list($user) = each($grants))
{
$public_user_list[] = $user;
}
reset($public_user_list);
$filtermethod .= " $where (
$entity_table.user_id IN(" . implode(',',$public_user_list) . "))";
$where= 'AND';
}
}
else
{
$filtermethod = " $where
$entity_table.user_id=$filter ";
$where= 'AND';
}
*/
if ($cat_id)
{
$filtermethod .= " $where
$entity_table.category='$cat_id' ";
$where= 'AND';
}
if ($member_id>0)
{
$filtermethod .= " $where
$entity_table.member_of LIKE '%,$member_id,%' ";
$where= 'AND';
}
if ($status)
{
$filtermethod .= " $where
$entity_table.status='$status' ";
$where= 'AND';
}
if($query)
{
$query = ereg_replace("'",'',$query);
$query = ereg_replace('"','',$query);
$dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT * FROM $attribute_table where
search='1'");
while (!$dbresult->EOF)
{
$querymethod[]= "$entity_table." .
$dbresult->fields['column_name'] . " LIKE '%$query%'";
$dbresult->MoveNext();
}
if (isset($querymethod) AND
is_array($querymethod))
{
$querymethod = " $where (" . implode ('
OR ',$querymethod) . ')';
$where = 'AND';
}
}
$sql .= " $filtermethod $querymethod";
//echo $sql;
$dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
$this->total_records = $dbresult2->_numOfRows;
$maxmatchs = 15;
if(!$allrows)
{
$dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
}
else
{
$dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
}
$j=0;
$n=count($cols_return);
//_debug_array($cols_return);
while (!$dbresult->EOF)
{
for ($i=0;$i<$n;$i++)
{
$actor_list[$j][$cols_return[$i]] =
$dbresult->fields[$cols_return[$i]];
$actor_list[$j]['grants'] =
(int)$grants[$dbresult->fields['user_id']];
}
for ($i=0;$i<count($cols_return_extra);$i++)
{
$value='';
$value=$dbresult->fields[$cols_return_extra[$i]['name']];
if(($cols_return_extra[$i]['datatype']=='R' ||
$cols_return_extra[$i]['datatype']=='LB') && $value):
{
$sql="SELECT value FROM
$choice_table where attrib_id=" .$cols_return_extra[$i]['attrib_id']. " AND
id=" . $value;
$dbresult2 =
$GLOBALS['phpgw']->db->Execute($sql);
$actor_list[$j][$cols_return_extra[$i]['name']] = $dbresult2->fields['value'];
}
elseif($cols_return_extra[$i]['datatype']=='AB' && $value):
{
$sql="SELECT org_name FROM
phpgw_addressbook where id=$value";
$dbresult2 =
$GLOBALS['phpgw']->db->Execute($sql);
$actor_list[$j][$cols_return_extra[$i]['name']] =
$dbresult2->fields['org_name'];
}
elseif($cols_return_extra[$i]['datatype']=='CH' && $value):
{
$ch= unserialize($value);
if (isset($ch) AND
is_array($ch))
{
for
($k=0;$k<count($ch);$k++)
{
$sql="SELECT
value FROM $choice_table where attrib_id="
.$cols_return_extra[$i]['attrib_id']. " AND id=" . $ch[$k];
$dbresult2 =
$GLOBALS['phpgw']->db->Execute($sql);
while
(!$dbresult2->EOF)
{
$ch_value[]=$dbresult2->fields['value'];
$dbresult2->MoveNext();
}
}
$actor_list[$j][$cols_return_extra[$i]['name']] = @implode(",", $ch_value);
unset($ch_value);
}
}
elseif($cols_return_extra[$i]['datatype']=='D' && $value):
{
//html_print_r($value);
$actor_list[$j][$cols_return_extra[$i]['name']]=date($GLOBALS['phpgw_data']['prefs'][$this->currentapp
. '.dateformat'],strtotime($value));
}
else:
{
$actor_list[$j][$cols_return_extra[$i]['name']]=$value;
}
endif;
}
$j++;
$dbresult->MoveNext();
}
//html_print_r($actor_list);
return $actor_list;
}
function read_single($data)
{
$attribute_table = 'fm_' . $this->role . '_attribute';
$table = 'fm_' . $this->role;
$actor_id =$data['actor_id'];
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT *
FROM $attribute_table ORDER BY attrib_sort");
while (!$dbresult->EOF)
{
$actor['attributes'][] = array
(
'attrib_id' =>
$dbresult->fields['id'],
'name' =>
$dbresult->fields['column_name'],
'input_text' =>
stripslashes($dbresult->fields['input_text']),
'statustext' =>
stripslashes($dbresult->fields['statustext']),
'datatype' =>
$dbresult->fields['datatype']
);
$dbresult->MoveNext();
}
if($actor_id)
{
$dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT * from $table where id='$actor_id'");
if($dbresult->fields[0])
{
$actor['id'] =
(int)$dbresult->fields['id'];
$actor['entry_date'] =
$dbresult->fields['entry_date'];
$actor['cat_id']
= $dbresult->fields['category'];
$actor['member_of']
= explode(',',$dbresult->fields['member_of']);
for
($i=0;$i<count($actor['attributes']);$i++)
{
$actor['attributes'][$i]['value'] =
$dbresult->fields[$actor['attributes'][$i]['name']];
$actor['attributes'][$i]['datatype_text'] =
$this->bocommon->translate_datatype($actor['attributes'][$i]['datatype']);
}
}
}
return $actor;
}
function add($actor,$values_attribute='')
{
$table = 'fm_' . $this->role;
$actor['member_of']=',' .
implode(',',$actor['member_of']) . ',';
while (is_array($actor['extra']) &&
list($input_name,$value) = each($actor['extra']))
{
if($value)
{
$cols[] = $input_name;
$vals[] = $value;
}
}
if (isset($values_attribute) AND
is_array($values_attribute))
{
foreach($values_attribute as $entry)
{
if($entry['value'])
{
$cols[] = $entry['name'];
$vals[] = $entry['value'];
}
}
}
if($cols)
{
$cols = "," . implode(",", $cols);
$vals = "," .
$this->bocommon->validate_db_insert($vals);
}
$GLOBALS['phpgw']->db->begintrans();
$id = $this->bocommon->next_id($table);
$GLOBALS['phpgw']->db->Execute("INSERT INTO $table
(id,entry_date,category,member_of $cols) "
. "VALUES ($id,'" . time() . "','" .
$actor['cat_id'] . "','" . $actor['member_of'] . "' $vals)");
$receipt['actor_id']=
$id;//$this->db->get_last_insert_id($table,'id');
$receipt['message'][] = array('msg'=>lang('actor %1 has
been saved',$receipt['actor_id']));
$GLOBALS['phpgw']->db->committrans();
return $receipt;
}
function edit($actor,$values_attribute='')
{
//_debug_array($actor);
//_debug_array($values_attribute);
$table = 'fm_' . $this->role;
$actor['member_of']=',' .
implode(',',$actor['member_of']) . ',';
while (is_array($actor['extra']) &&
list($column,$value) = each($actor['extra']))
{
$value_set[$column] = $value;
}
if (isset($values_attribute) AND
is_array($values_attribute))
{
foreach($values_attribute as $entry)
{
if($entry['datatype']!='AB')
{
$value_set[$entry['name']]
= $entry['value'];
}
}
}
if($value_set)
{
$value_set = ',' .
$this->bocommon->validate_db_update($value_set);
}
$GLOBALS['phpgw']->db->Execute("UPDATE $table set
entry_date='" . time() . "', category='"
. $actor['cat_id'] .
"', member_of='" . $actor['member_of'] . "'$value_set WHERE id=" .
intval($actor['actor_id']));
$receipt['actor_id']= $actor['actor_id'];
$receipt['message'][] = array('msg'=>lang('actor %1 has
been edited',$actor['actor_id']));
return $receipt;
}
function delete($actor_id)
{
$table = 'fm_' . $this->role;
$GLOBALS['phpgw']->db->Execute('DELETE FROM $table
WHERE id=' . intval($actor_id));
}
function read_attrib($data)
{
$attribute_table = 'fm_' . $this->role . '_attribute';
//html_print_r($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']:'');
$column_list =
(isset($data['column_list'])?$data['column_list']:'');
}
$where = 'WHERE';
if ($column_list)
{
$filtermethod = " $where list !=1 or list is
null";
$where = 'AND';
}
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 = " $where
($attribute_table.input_text LIKE '%$query%' or $attribute_table.column_name
LIKE '%$query%')";
}
$sql = "SELECT * FROM $attribute_table $filtermethod
$querymethod";
//echo $sql;
$dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
$this->total_records = $dbresult2->_numOfRows;
$maxmatchs = 15;
if(!$allrows)
{
$dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
}
else
{
$dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
}
while (!$dbresult->EOF)
{
$attrib[] = array
(
'id' =>
$dbresult->fields['id'],
'attrib_sort' =>
$dbresult->fields['attrib_sort'],
'list' =>
$dbresult->fields['list'],
'lookup_form' =>
$dbresult->fields['lookup_form'],
'column_name' =>
$dbresult->fields['column_name'],
'name' =>
$dbresult->fields['input_text'],
'size' =>
$dbresult->fields['size'],
'statustext' =>
$dbresult->fields['statustext'],
'input_text' =>
$dbresult->fields['input_text'],
'type_name' =>
$dbresult->fields['type'],
'datatype' =>
$dbresult->fields['datatype'],
'search' =>
$dbresult->fields['search']
);
$dbresult->MoveNext();
}
return $attrib;
}
function read_single_attrib($id)
{
$attribute_table = 'fm_' . $this->role . '_attribute';
$sql = "SELECT * FROM $attribute_table where id=$id";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
if($dbresult->fields[0])
{
$attrib['id']
= $dbresult->fields['id'];
$attrib['column_name']
= $dbresult->fields['column_name'];
$attrib['input_text']
= $dbresult->fields['input_text'];
$attrib['statustext']
= $dbresult->fields['statustext'];
$attrib['column_info']['precision'] =
$dbresult->fields['precision_'];
$attrib['column_info']['scale'] =
$dbresult->fields['scale'];
$attrib['column_info']['default'] =
$dbresult->fields['default_value'];
$attrib['column_info']['nullable'] =
$dbresult->fields['nullable'];
$attrib['column_info']['type'] =
$dbresult->fields['datatype'];
$attrib['type_name']
= $dbresult->fields['type_name'];
$attrib['lookup_form']
= $dbresult->fields['lookup_form'];
$attrib['list']
= $dbresult->fields['list'];
$attrib['search']
= $dbresult->fields['search'];
if($dbresult->fields['datatype']=='R' ||
$dbresult->fields['datatype']=='CH' || $dbresult->fields['datatype']=='LB')
{
$attrib['choice'] =
$this->read_attrib_choice($id);
}
return $attrib;
}
}
function read_attrib_choice($attrib_id)
{
$choice_table = 'fm_' . $this->role . '_choice';
$sql = "SELECT * FROM $choice_table WHERE
attrib_id=$attrib_id";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
while (!$dbresult->EOF)
{
$choice[] = array
(
'id' => $dbresult->fields['id'],
'value' => $dbresult->fields['value']
);
$dbresult->MoveNext();
}
return $choice;
}
function add_attrib($attrib)
{
$table = 'fm_' . $this->role;
$attribute_table = 'fm_' . $this->role . '_attribute';
$attrib['column_name'] =
$this->functions->db_addslashes($attrib['column_name']);
$attrib['input_text'] =
$this->functions->db_addslashes($attrib['input_text']);
$attrib['statustext'] =
$this->functions->db_addslashes($attrib['statustext']);
$attrib['default'] =
$this->functions->db_addslashes($attrib['default']);
$attrib['id'] =
$this->bocommon->next_id($attribute_table);
$sql = "SELECT max(attrib_sort) as max_sort FROM
$attribute_table";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
$attrib_sort = $dbresult->fields['max_sort']+1;
$values= array(
$attrib['id'],
$attrib['column_name'],
$attrib['input_text'],
$attrib['statustext'],
$attrib['lookup_form'],
$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);
$GLOBALS['phpgw']->db->begintrans();
$GLOBALS['phpgw']->db->Execute("INSERT INTO
$attribute_table (id,column_name, input_text,
statustext,lookup_form,search,list,attrib_sort,datatype,precision_,scale,default_value,nullable)
"
. "VALUES ($values)");
$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($table,$attrib['column_name'],
$attrib['column_info']))
{
$receipt['message'][] = array('msg' =>
lang('Attribute has been saved') );
$GLOBALS['phpgw']->db->committrans();
}
else
{
$receipt['error'][] = array('msg' =>
lang('column could not be added') );
if($this->db->Transaction)
{
$GLOBALS['phpgw']->db->rollbacktrans();
}
else
{
$GLOBALS['phpgw']->db->Execute("DELETE
FROM $attribute_table WHERE id='" . $receipt['id'] . "'");
unset($receipt['id']);
}
}
return $receipt;
}
function init_process()
{
$this->oProc =
CreateObject($this->currentapp.'_oproc');
}
function edit_attrib($attrib)
{
$attribute_table = 'fm_' . $this->role . '_attribute';
$table = 'fm_' . $this->role;
$attrib['column_name'] =
$this->functions->db_addslashes($attrib['column_name']);
$attrib['input_text'] =
$this->functions->db_addslashes($attrib['input_text']);
$attrib['statustext'] =
$this->functions->db_addslashes($attrib['statustext']);
$attrib['default'] =
$this->functions->db_addslashes($attrib['default']);
$choice_table = 'fm_' . $this->role . '_choice';
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
column_name FROM $attribute_table WHERE id='" . $attrib['id']. "'");
$OldColumnName =
$dbresult->fields['column_name'];
$GLOBALS['phpgw']->db->begintrans();
$attrib_type=$attrib['column_info']['type'];
if(($OldColumnName !=$attrib['column_name']) ||
($attrib['column_info']['type'] != $dbresult->fields['datatype']))
{
$value_set=array(
'column_name' =>
$attrib['column_name'],
'input_text' =>
$attrib['input_text'],
'statustext' =>
$attrib['statustext'],
'lookup_form' =>
$attrib['lookup_form'],
'search' =>
$attrib['search'],
'list' =>
$attrib['list'],
'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);
$GLOBALS['phpgw']->db->Execute("UPDATE
$attribute_table set $value_set WHERE 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();
$this->oProc->AlterColumn($table,$OldColumnName,$attrib['column_name'],$attrib['column_info']);
}
if($attrib['new_choice'])
{
$choice_id =
$this->bocommon->next_id($choice_table ,array('attrib_id'=>$attrib['id']));
$values= array(
$attrib['id'],
$choice_id,
$attrib['new_choice']
);
$values =
$this->bocommon->validate_db_insert($values);
$GLOBALS['phpgw']->db->Execute("INSERT INTO
$choice_table (attrib_id,id,value) "
. "VALUES ($values)");
}
if($attrib['delete_choice'])
{
for
($i=0;$i<count($attrib['delete_choice']);$i++)
{
$GLOBALS['phpgw']->db->Execute("DELETE
FROM $choice_table WHERE attrib_id=" . $attrib['id'] ." AND id=" .
$attrib['delete_choice'][$i]);
}
}
//html_print_r($attrib_type);
if($attrib_type!='R' && $attrib_type!='CH' &&
$attrib_type!='LB')
{
$GLOBALS['phpgw']->db->Execute("DELETE FROM
$choice_table WHERE attrib_id=" . $attrib['id']);
}
$GLOBALS['phpgw']->db->committrans();
$receipt['message'][] = array('msg' =>
lang('Attribute has been edited'));
return $receipt;
}
function resort_attrib($data)
{
//html_print_r($data);
$attribute_table = 'fm_' . $this->role . '_attribute';
if(is_array($data))
{
$resort =
(isset($data['resort'])?$data['resort']:'up');
$id = (isset($data['id'])?$data['id']:'');
}
$sql = "SELECT attrib_sort FROM $attribute_table where
id=$id";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
$attrib_sort = $dbresult->fields['attrib_sort'];
$sql = "SELECT max(attrib_sort) as max_sort FROM
$attribute_table";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
$max_sort = $dbresult->fields['max_sort'];
switch($resort)
{
case 'up':
if($attrib_sort>1)
{
$sql = "UPDATE $attribute_table
set attrib_sort=$attrib_sort WHERE attrib_sort =" . ($attrib_sort-1);
$GLOBALS['phpgw']->db->Execute($sql);
$sql = "UPDATE $attribute_table
set attrib_sort=" . ($attrib_sort-1) ." WHERE id=$id";
$GLOBALS['phpgw']->db->Execute($sql);
}
break;
case 'down':
if($max_sort > $attrib_sort)
{
$sql = "UPDATE $attribute_table
set attrib_sort=$attrib_sort WHERE attrib_sort =" . ($attrib_sort+1);
$GLOBALS['phpgw']->db->Execute($sql);
$sql = "UPDATE $attribute_table
set attrib_sort=" . ($attrib_sort+1) ." WHERE id=$id";
$GLOBALS['phpgw']->db->Execute($sql);
}
break;
default:
return;
break;
}
}
function delete_attrib($attrib_id)
{
$table = 'fm_' . $this->role;
$attribute_table = 'fm_' . $this->role . '_attribute';
$this->init_process();
$sql = "SELECT * FROM $attribute_table WHERE
id=$attrib_id";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
$ColumnName =
$dbresult->fields['column_name'];
if($this->oProc->DropColumn($table,'', $ColumnName))
{
$sql = "SELECT attrib_sort FROM
$attribute_table where id=$attrib_id";
$dbresult =
$GLOBALS['phpgw']->db->Execute($sql);
$attrib_sort =
$dbresult->fields['attrib_sort'];
$sql2 = "SELECT max(attrib_sort) as max_sort
FROM $attribute_table";
$dbresult =
$GLOBALS['phpgw']->db->Execute($sql2);
$max_sort = $dbresult->fields['max_sort'];
if($max_sort>$attrib_sort)
{
$sql = "UPDATE $attribute_table set
attrib_sort=attrib_sort-1 WHERE attrib_sort > $attrib_sort";
$GLOBALS['phpgw']->db->Execute($sql);
}
$GLOBALS['phpgw']->db->Execute("DELETE FROM
$attribute_table WHERE id=$attrib_id");
}
else
{
$receipt['error'][] = array('msg' =>
lang('Attribute has NOT been deleted'));
}
return $receipt;
}
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/class.soactor.php, 1.1.2.1,
nomail <=