phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] property/class.sostandard_entity.php, 1.1.1.3


From: nomail
Subject: [Phpgroupware-cvs] property/class.sostandard_entity.php, 1.1.1.3
Date: Fri, 21 May 2004 19:28:05 -0000

Update of /property
Modified Files:
        Branch: 
          class.sostandard_entity.php

date: 2004/04/23 21:26:33;  author: sigurdne;  state: Exp;  lines: +521 -521

Log Message:
no message
=====================================================================
Index: property/class.sostandard_entity.php
diff -u property/class.sostandard_entity.php:1.1.1.2 
property/class.sostandard_entity.php:1.1.1.3
--- property/class.sostandard_entity.php:1.1.1.2        Fri Apr 23 20:26:02 2004
+++ property/class.sostandard_entity.php        Fri Apr 23 21:26:33 2004
@@ -1,521 +1,521 @@
-<?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_sostandard_entity
-       {
-
-               function property_sostandard_entity()
-               {
-                       $this->currentapp       = 'property'; 
//$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $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;
-
-
-               }
-
-               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']:'');
-                               $type = (isset($data['type'])?$data['type']:0);
-                       }
-
-                       if ($order)
-                       {
-                               $ordermethod = " order by $order $sort";
-
-                       }
-                       else
-                       {
-                               $ordermethod = ' order by id asc';
-                       }
-
-                       $table = $this->select_table($type);
-
-                       if($query)
-                       {
-                               $query = ereg_replace("'",'',$query);
-                               $query = ereg_replace('"','',$query);
-
-                               $querymethod = " where name LIKE '%$query%' or 
descr LIKE '%$query%'";
-                       }
-
-                       $sql = "SELECT * FROM $table $querymethod";
-
-                       $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)
-                       {
-                               $standard[] = array
-                               (
-                                       'id'    => $dbresult->fields['id'],
-                                       'name'  => $dbresult->fields['name'],
-                                       'prefix'=> $dbresult->fields['prefix'],
-                                       'descr' => $dbresult->fields['descr']
-                               );
-                               $dbresult->MoveNext();
-                       }
-                       return $standard;
-               }
-
-
-               function select_table($type)
-               {
-
-                       switch($type)
-                       {
-                               case 'report':
-                                       $table='fm_report_type';
-                                       break;
-                       }
-
-                       return $table;
-               }
-
-               function select_table_attrib($type)
-               {
-
-                       switch($type)
-                       {
-                               case 'report':
-                                       $table='fm_report_type_attrib';
-                                       break;
-                       }
-
-                       return $table;
-               }
-
-               function select_table_choice($type)
-               {
-
-                       switch($type)
-                       {
-                               case 'report':
-                                       $table='fm_report_type_choice';
-                                       break;
-                       }
-
-                       return $table;
-               }
-
-
-               function read_single($id,$type)
-               {
-
-                       $table = $this->select_table($type);
-
-                       $sql = "SELECT * FROM $table  where id='$id'";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       if (!$dbresult->EOF)
-                       {
-                               $standard['id']                 = 
$dbresult->fields['id'];
-                               $standard['name']               = 
$dbresult->fields['name'];
-                               $standard['descr']              = 
$dbresult->fields['descr'];
-                               $standard['prefix']             = 
$dbresult->fields['prefix'];
-
-                               return $standard;
-                       }
-               }
-
-               function add($standard,$type)
-               {
-
-                       if (!$standard['name'])
-                       {
-                               $receipt['error'][] = array('msg'=>lang('Name 
not entered!'));
-                       }
-
-                       if (!$receipt['error'])
-                       {
-                               $table = $this->select_table($type);
-
-                               $standard['id'] = 
$this->bocommon->next_id($table);
-                               $standard['name'] = 
$this->db->db_addslashes($standard['name']);
-                               $standard['descr'] = 
$this->db->db_addslashes($standard['descr']);
-
-                       $values= array(
-                               $standard['id'],
-                               $standard['name'],
-                               $standard['descr'],
-                               $standard['prefix']
-                               );
-
-                       $values = $this->bocommon->validate_db_insert($values);
-
-
-                               $GLOBALS['phpgw']->db->Execute("INSERT INTO 
$table (id, name, descr, prefix) VALUES ($values)");
-
-                               $receipt['id']=$standard['id'];
-                               $receipt['message'][] = array('msg'     => 
lang('standard has been saved'));
-                       }
-                       else
-                       {
-                               $receipt['error'][] = array('msg'=> 
lang('Attribute has NOT been saved'));
-                       }
-
-//html_print_r($receipt);
-                       return $receipt;
-               }
-
-               function edit($standard,$type)
-               {
-
-                       if (!$standard['name'])
-                       {
-                               $receipt['error'][] = array('msg'=>lang('Name 
not entered!'));
-                       }
-
-                       if (!$receipt['error'])
-                       {
-                               $table = $this->select_table($type);
-
-                               $standard['name'] = 
$this->db->db_addslashes($standard['name']);
-                               $standard['descr'] = 
$this->db->db_addslashes($standard['descr']);
-
-                               $value_set=array(
-                                       'descr'                 => 
$standard['descr'],
-                                       'name'          => $standard['name'],
-                                       'prefix'        => $standard['prefix']
-                                       );
-
-                               $value_set      = 
$this->bocommon->validate_db_update($value_set);
-
-                               $GLOBALS['phpgw']->db->Execute("UPDATE $table 
set $value_set WHERE id=" . $standard['id']);
-
-                               $receipt['message'][] = array('msg'=> 
lang('Standard has been edited'));
-                       }
-                       else
-                       {
-                               $receipt['error'][] = array('msg'       => 
lang('Standard has NOT been edited'));
-                       }
-
-                       return $receipt;
-               }
-
-               function delete($id,$type,$attrib)
-               {
-                       if($attrib)
-                       {
-                               $table = $this->select_table_attrib($type);
-                       }
-                       else
-                       {
-
-                               $table                  = 
$this->select_table($type);
-                               $attrib_table   = 
$this->select_table_attrib($type);
-                               $GLOBALS['phpgw']->db->Execute("DELETE_ FROM 
$attrib_table WHERE type_id='" . $id . "'");
-                       }
-                       $GLOBALS['phpgw']->db->Execute("DELETE_ FROM $table 
WHERE id='" . $id . "'");
-               }
-
-               function read_attrib($data)
-               {
-
-//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']:'');
-                               $type = (isset($data['type'])?$data['type']:0);
-                               $type_id = 
(isset($data['type_id'])?$data['type_id']:0);
-                               $allrows = 
(isset($data['allrows'])?$data['allrows']:'');
-                       }
-
-                       $table          = $this->select_table_attrib($type);
-                       $type_table = $this->select_table($type);
-
-                       if ($order)
-                       {
-                               $ordermethod = " order by $order $sort";
-
-                       }
-                       else
-                       {
-                               $ordermethod = " order by $table.id asc";
-                       }
-
-
-                       if($query)
-                       {
-                               $query = ereg_replace("'",'',$query);
-                               $query = ereg_replace('"','',$query);
-
-                               $querymethod = " and ($table.name LIKE 
'%$query%' or $table.descr LIKE '%$query%')";
-                       }
-
-                       $sql = "SELECT $table.id ,$table.name ,$table.descr, 
$table.datatype ,$type_table.name as type FROM $type_table $this->join $table 
on $table.type_id = $type_table.id where $table.type_id= '$type_id' 
$querymethod";
-
-                       $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'],
-                                       'name'  => $dbresult->fields['name'],
-                                       'descr' => $dbresult->fields['descr'],
-                                       'type_name'     => 
$dbresult->fields['type'],
-                                       'datatype'      => 
$dbresult->fields['datatype']
-                               );
-                               $dbresult->MoveNext();
-                       }
-                       return $attrib;
-               }
-
-               function read_single_attrib($id,$type)
-               {
-
-                       $table          = $this->select_table_attrib($type);
-                       $type_table = $this->select_table($type);
-
-                       $sql = "SELECT $table.id ,$table.name ,$table.descr, 
$table.datatype,$type_table.id as type_id ,$type_table.name as type_name FROM 
$type_table $this->join $table on $table.type_id = $type_table.id where 
$table.id= '$id'  $querymethod";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       if (!$dbresult->EOF)
-                       {
-                               $attrib['id']           = 
$dbresult->fields['id'];
-                               $attrib['name']         = 
$dbresult->fields['name'];
-                               $attrib['descr']        = 
$dbresult->fields['descr'];
-                               $attrib['type_id']      = 
$dbresult->fields['type_id'];
-                               $attrib['type_name']    = 
$dbresult->fields['type_name'];
-                               $attrib['datatype']     = 
$dbresult->fields['datatype'];
-//                             $attrib['list'] = $dbresult->fields['list'];
-                               if($dbresult->fields['datatype']=='R' || 
$dbresult->fields['datatype']=='CH')
-                               {
-                                       $attrib['choice'] = 
$this->read_attrib_choice($attrib['id'],$type);
-                               }
-
-//html_print_r($attrib);
-                       }
-                       return $attrib;
-               }
-
-               function read_attrib_choice($attrib_id='',$type='')
-               {
-                       $choice_table = $this->select_table_choice($type);
-                       $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,$type)
-               {
-
-                       if (!$attrib['type_id'])
-                       {
-                               $receipt['error'][] = array('msg'=>lang('Entity 
type not choosen!'));
-                       }
-
-                       if (!$attrib['datatype'])
-                       {
-                               $receipt['error'][] = 
array('msg'=>lang('Datatype type not choosen!'));
-                       }
-
-                       if (!$attrib['name'])
-                       {
-                               $receipt['error'][] = array('msg'=>lang('Name 
not entered!'));
-                       }
-
-                       if (!$receipt['error'])
-                       {
-
-                               $table = $this->select_table_attrib($type);
-
-                               $attrib['id'] = 
$this->bocommon->next_id($table);
-                               $attrib['name'] = 
$this->db->db_addslashes($attrib['name']);
-                               $attrib['descr'] = 
$this->db->db_addslashes($attrib['descr']);
-
-
-                       $values= array(
-                               $attrib['id'],
-                               $attrib['type_id'],
-                               $attrib['name'],
-                               $attrib['descr'],
-                               $attrib['datatype']
-//                             $attrib['list']
-                               );
-
-                       $values = $this->bocommon->validate_db_insert($values);
-
-                               $GLOBALS['phpgw']->db->Execute("INSERT INTO 
$table (id, type_id, name, descr, datatype) "
-                                       . "VALUES ($values)");
-
-                               $receipt['id']=$attrib['id'];
-                               $receipt['message'][] = array('msg'     => 
lang('Attribute has been saved')     );
-
-                       }
-                       else
-                       {
-                               $receipt['error'][] = array('msg'       => 
lang('Attribute has NOT been saved'));
-                       }
-                       return $receipt;
-               }
-
-               function edit_attrib($attrib,$type)
-               {
-
-                       if (!$attrib['type_id'])
-                       {
-                               $receipt['error'][] = array('msg'=>lang('Entity 
type not choosen!'));
-                       }
-
-                       if (!$attrib['datatype'])
-                       {
-                               $receipt['error'][] = 
array('msg'=>lang('Datatype type not choosen!'));
-                       }
-
-                       if (!$attrib['name'])
-                       {
-                               $receipt['error'][] = array('msg'=>lang('Name 
not entered!'));
-                       }
-
-                       if (!$receipt['error'])
-                       {
-                               $table = $this->select_table_attrib($type);
-                               $choice_table = 
$this->select_table_choice($type);
-
-                               $attrib['name'] = 
$this->db->db_addslashes($attrib['name']);
-                               $attrib['descr'] = 
$this->db->db_addslashes($attrib['descr']);
-
-                               $value_set=array(
-                                       'descr'         => $attrib['descr'],
-                                       'name'          => $attrib['name'],
-                                       'type_id'       => $attrib['type_id'],
-                                       'datatype'      => $attrib['datatype']
-//                                     'list'          => $attrib['list']
-                                       );
-
-                               $value_set      = 
$this->bocommon->validate_db_update($value_set);
-
-                               $GLOBALS['phpgw']->db->Execute("UPDATE $table 
set $value_set WHERE id=" . $attrib['id']);
-
-                               if($attrib['new_choice'])
-                               {
-                                       $GLOBALS['phpgw']->db->Execute("INSERT 
INTO $choice_table (attrib_id, value) "
-                                       . "VALUES ('" . $attrib['id'] . "','" . 
$attrib['new_choice']. "')");
-
-                               }
-
-                               if($attrib['delete_choice'])
-                               {
-                                       for 
($i=0;$i<count($attrib['delete_choice']);$i++)
-                                       {
-
-                                               
$GLOBALS['phpgw']->db->Execute("DELETE FROM $choice_table WHERE id='" . 
$attrib['delete_choice'][$i] . "'");
-                                       }
-                               }
-
-                               if($attrib['datatype']!='R' && 
$attrib['datatype']!='CH')
-                               {
-                                       $GLOBALS['phpgw']->db->Execute("DELETE 
FROM $choice_table WHERE attrib_id='" . $attrib['id'] . "'");
-                               }
-
-                               $receipt['message'][] = array('msg'     => 
lang('Attribute has been edited'));
-                       }
-                       else
-                       {
-                               $receipt['error'][] = array('msg'       => 
lang('Attribute has NOT been edited'));
-                       }
-                       return $receipt;
-               }
-
-
-               function select_entity_type($type='')
-               {
-                       $table = $this->select_table($type);
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT * 
FROM $table ORDER BY name ");
-
-                       $i = 0;
-                       while (!$dbresult->EOF)
-                       {
-                               $entity_type[$i]['id']          = 
$dbresult->fields['id'];
-                               $entity_type[$i]['name']                = 
stripslashes($dbresult->fields['name']);
-                               $entity_type[$i]['descr']       = 
stripslashes($dbresult->fields['descr']);
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-//html_print_r($entity_type);
-
-                       return $entity_type;
-               }
-
-       }
-?>
+<?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_sostandard_entity
+       {
+
+               function property_sostandard_entity()
+               {
+                       $this->currentapp       = 'property'; 
//$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $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;
+
+
+               }
+
+               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']:'');
+                               $type = (isset($data['type'])?$data['type']:0);
+                       }
+
+                       if ($order)
+                       {
+                               $ordermethod = " order by $order $sort";
+
+                       }
+                       else
+                       {
+                               $ordermethod = ' order by id asc';
+                       }
+
+                       $table = $this->select_table($type);
+
+                       if($query)
+                       {
+                               $query = ereg_replace("'",'',$query);
+                               $query = ereg_replace('"','',$query);
+
+                               $querymethod = " where name LIKE '%$query%' or 
descr LIKE '%$query%'";
+                       }
+
+                       $sql = "SELECT * FROM $table $querymethod";
+
+                       $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)
+                       {
+                               $standard[] = array
+                               (
+                                       'id'    => $dbresult->fields['id'],
+                                       'name'  => $dbresult->fields['name'],
+                                       'prefix'=> $dbresult->fields['prefix'],
+                                       'descr' => $dbresult->fields['descr']
+                               );
+                               $dbresult->MoveNext();
+                       }
+                       return $standard;
+               }
+
+
+               function select_table($type)
+               {
+
+                       switch($type)
+                       {
+                               case 'report':
+                                       $table='fm_report_type';
+                                       break;
+                       }
+
+                       return $table;
+               }
+
+               function select_table_attrib($type)
+               {
+
+                       switch($type)
+                       {
+                               case 'report':
+                                       $table='fm_report_type_attrib';
+                                       break;
+                       }
+
+                       return $table;
+               }
+
+               function select_table_choice($type)
+               {
+
+                       switch($type)
+                       {
+                               case 'report':
+                                       $table='fm_report_type_choice';
+                                       break;
+                       }
+
+                       return $table;
+               }
+
+
+               function read_single($id,$type)
+               {
+
+                       $table = $this->select_table($type);
+
+                       $sql = "SELECT * FROM $table  where id='$id'";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       if (!$dbresult->EOF)
+                       {
+                               $standard['id']                 = 
$dbresult->fields['id'];
+                               $standard['name']               = 
$dbresult->fields['name'];
+                               $standard['descr']              = 
$dbresult->fields['descr'];
+                               $standard['prefix']             = 
$dbresult->fields['prefix'];
+
+                               return $standard;
+                       }
+               }
+
+               function add($standard,$type)
+               {
+
+                       if (!$standard['name'])
+                       {
+                               $receipt['error'][] = array('msg'=>lang('Name 
not entered!'));
+                       }
+
+                       if (!$receipt['error'])
+                       {
+                               $table = $this->select_table($type);
+
+                               $standard['id'] = 
$this->bocommon->next_id($table);
+                               $standard['name'] = 
$this->db->db_addslashes($standard['name']);
+                               $standard['descr'] = 
$this->db->db_addslashes($standard['descr']);
+
+                       $values= array(
+                               $standard['id'],
+                               $standard['name'],
+                               $standard['descr'],
+                               $standard['prefix']
+                               );
+
+                       $values = $this->bocommon->validate_db_insert($values);
+
+
+                               $GLOBALS['phpgw']->db->Execute("INSERT INTO 
$table (id, name, descr, prefix) VALUES ($values)");
+
+                               $receipt['id']=$standard['id'];
+                               $receipt['message'][] = array('msg'     => 
lang('standard has been saved'));
+                       }
+                       else
+                       {
+                               $receipt['error'][] = array('msg'=> 
lang('Attribute has NOT been saved'));
+                       }
+
+//html_print_r($receipt);
+                       return $receipt;
+               }
+
+               function edit($standard,$type)
+               {
+
+                       if (!$standard['name'])
+                       {
+                               $receipt['error'][] = array('msg'=>lang('Name 
not entered!'));
+                       }
+
+                       if (!$receipt['error'])
+                       {
+                               $table = $this->select_table($type);
+
+                               $standard['name'] = 
$this->db->db_addslashes($standard['name']);
+                               $standard['descr'] = 
$this->db->db_addslashes($standard['descr']);
+
+                               $value_set=array(
+                                       'descr'                 => 
$standard['descr'],
+                                       'name'          => $standard['name'],
+                                       'prefix'        => $standard['prefix']
+                                       );
+
+                               $value_set      = 
$this->bocommon->validate_db_update($value_set);
+
+                               $GLOBALS['phpgw']->db->Execute("UPDATE $table 
set $value_set WHERE id=" . $standard['id']);
+
+                               $receipt['message'][] = array('msg'=> 
lang('Standard has been edited'));
+                       }
+                       else
+                       {
+                               $receipt['error'][] = array('msg'       => 
lang('Standard has NOT been edited'));
+                       }
+
+                       return $receipt;
+               }
+
+               function delete($id,$type,$attrib)
+               {
+                       if($attrib)
+                       {
+                               $table = $this->select_table_attrib($type);
+                       }
+                       else
+                       {
+
+                               $table                  = 
$this->select_table($type);
+                               $attrib_table   = 
$this->select_table_attrib($type);
+                               $GLOBALS['phpgw']->db->Execute("DELETE_ FROM 
$attrib_table WHERE type_id='" . $id . "'");
+                       }
+                       $GLOBALS['phpgw']->db->Execute("DELETE_ FROM $table 
WHERE id='" . $id . "'");
+               }
+
+               function read_attrib($data)
+               {
+
+//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']:'');
+                               $type = (isset($data['type'])?$data['type']:0);
+                               $type_id = 
(isset($data['type_id'])?$data['type_id']:0);
+                               $allrows = 
(isset($data['allrows'])?$data['allrows']:'');
+                       }
+
+                       $table          = $this->select_table_attrib($type);
+                       $type_table = $this->select_table($type);
+
+                       if ($order)
+                       {
+                               $ordermethod = " order by $order $sort";
+
+                       }
+                       else
+                       {
+                               $ordermethod = " order by $table.id asc";
+                       }
+
+
+                       if($query)
+                       {
+                               $query = ereg_replace("'",'',$query);
+                               $query = ereg_replace('"','',$query);
+
+                               $querymethod = " and ($table.name LIKE 
'%$query%' or $table.descr LIKE '%$query%')";
+                       }
+
+                       $sql = "SELECT $table.id ,$table.name ,$table.descr, 
$table.datatype ,$type_table.name as type FROM $type_table $this->join $table 
on $table.type_id = $type_table.id where $table.type_id= '$type_id' 
$querymethod";
+
+                       $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'],
+                                       'name'  => $dbresult->fields['name'],
+                                       'descr' => $dbresult->fields['descr'],
+                                       'type_name'     => 
$dbresult->fields['type'],
+                                       'datatype'      => 
$dbresult->fields['datatype']
+                               );
+                               $dbresult->MoveNext();
+                       }
+                       return $attrib;
+               }
+
+               function read_single_attrib($id,$type)
+               {
+
+                       $table          = $this->select_table_attrib($type);
+                       $type_table = $this->select_table($type);
+
+                       $sql = "SELECT $table.id ,$table.name ,$table.descr, 
$table.datatype,$type_table.id as type_id ,$type_table.name as type_name FROM 
$type_table $this->join $table on $table.type_id = $type_table.id where 
$table.id= '$id'  $querymethod";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       if (!$dbresult->EOF)
+                       {
+                               $attrib['id']           = 
$dbresult->fields['id'];
+                               $attrib['name']         = 
$dbresult->fields['name'];
+                               $attrib['descr']        = 
$dbresult->fields['descr'];
+                               $attrib['type_id']      = 
$dbresult->fields['type_id'];
+                               $attrib['type_name']    = 
$dbresult->fields['type_name'];
+                               $attrib['datatype']     = 
$dbresult->fields['datatype'];
+//                             $attrib['list'] = $dbresult->fields['list'];
+                               if($dbresult->fields['datatype']=='R' || 
$dbresult->fields['datatype']=='CH')
+                               {
+                                       $attrib['choice'] = 
$this->read_attrib_choice($attrib['id'],$type);
+                               }
+
+//html_print_r($attrib);
+                       }
+                       return $attrib;
+               }
+
+               function read_attrib_choice($attrib_id='',$type='')
+               {
+                       $choice_table = $this->select_table_choice($type);
+                       $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,$type)
+               {
+
+                       if (!$attrib['type_id'])
+                       {
+                               $receipt['error'][] = array('msg'=>lang('Entity 
type not choosen!'));
+                       }
+
+                       if (!$attrib['datatype'])
+                       {
+                               $receipt['error'][] = 
array('msg'=>lang('Datatype type not choosen!'));
+                       }
+
+                       if (!$attrib['name'])
+                       {
+                               $receipt['error'][] = array('msg'=>lang('Name 
not entered!'));
+                       }
+
+                       if (!$receipt['error'])
+                       {
+
+                               $table = $this->select_table_attrib($type);
+
+                               $attrib['id'] = 
$this->bocommon->next_id($table);
+                               $attrib['name'] = 
$this->db->db_addslashes($attrib['name']);
+                               $attrib['descr'] = 
$this->db->db_addslashes($attrib['descr']);
+
+
+                       $values= array(
+                               $attrib['id'],
+                               $attrib['type_id'],
+                               $attrib['name'],
+                               $attrib['descr'],
+                               $attrib['datatype']
+//                             $attrib['list']
+                               );
+
+                       $values = $this->bocommon->validate_db_insert($values);
+
+                               $GLOBALS['phpgw']->db->Execute("INSERT INTO 
$table (id, type_id, name, descr, datatype) "
+                                       . "VALUES ($values)");
+
+                               $receipt['id']=$attrib['id'];
+                               $receipt['message'][] = array('msg'     => 
lang('Attribute has been saved')     );
+
+                       }
+                       else
+                       {
+                               $receipt['error'][] = array('msg'       => 
lang('Attribute has NOT been saved'));
+                       }
+                       return $receipt;
+               }
+
+               function edit_attrib($attrib,$type)
+               {
+
+                       if (!$attrib['type_id'])
+                       {
+                               $receipt['error'][] = array('msg'=>lang('Entity 
type not choosen!'));
+                       }
+
+                       if (!$attrib['datatype'])
+                       {
+                               $receipt['error'][] = 
array('msg'=>lang('Datatype type not choosen!'));
+                       }
+
+                       if (!$attrib['name'])
+                       {
+                               $receipt['error'][] = array('msg'=>lang('Name 
not entered!'));
+                       }
+
+                       if (!$receipt['error'])
+                       {
+                               $table = $this->select_table_attrib($type);
+                               $choice_table = 
$this->select_table_choice($type);
+
+                               $attrib['name'] = 
$this->db->db_addslashes($attrib['name']);
+                               $attrib['descr'] = 
$this->db->db_addslashes($attrib['descr']);
+
+                               $value_set=array(
+                                       'descr'         => $attrib['descr'],
+                                       'name'          => $attrib['name'],
+                                       'type_id'       => $attrib['type_id'],
+                                       'datatype'      => $attrib['datatype']
+//                                     'list'          => $attrib['list']
+                                       );
+
+                               $value_set      = 
$this->bocommon->validate_db_update($value_set);
+
+                               $GLOBALS['phpgw']->db->Execute("UPDATE $table 
set $value_set WHERE id=" . $attrib['id']);
+
+                               if($attrib['new_choice'])
+                               {
+                                       $GLOBALS['phpgw']->db->Execute("INSERT 
INTO $choice_table (attrib_id, value) "
+                                       . "VALUES ('" . $attrib['id'] . "','" . 
$attrib['new_choice']. "')");
+
+                               }
+
+                               if($attrib['delete_choice'])
+                               {
+                                       for 
($i=0;$i<count($attrib['delete_choice']);$i++)
+                                       {
+
+                                               
$GLOBALS['phpgw']->db->Execute("DELETE FROM $choice_table WHERE id='" . 
$attrib['delete_choice'][$i] . "'");
+                                       }
+                               }
+
+                               if($attrib['datatype']!='R' && 
$attrib['datatype']!='CH')
+                               {
+                                       $GLOBALS['phpgw']->db->Execute("DELETE 
FROM $choice_table WHERE attrib_id='" . $attrib['id'] . "'");
+                               }
+
+                               $receipt['message'][] = array('msg'     => 
lang('Attribute has been edited'));
+                       }
+                       else
+                       {
+                               $receipt['error'][] = array('msg'       => 
lang('Attribute has NOT been edited'));
+                       }
+                       return $receipt;
+               }
+
+
+               function select_entity_type($type='')
+               {
+                       $table = $this->select_table($type);
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT * 
FROM $table ORDER BY name ");
+
+                       $i = 0;
+                       while (!$dbresult->EOF)
+                       {
+                               $entity_type[$i]['id']          = 
$dbresult->fields['id'];
+                               $entity_type[$i]['name']                = 
stripslashes($dbresult->fields['name']);
+                               $entity_type[$i]['descr']       = 
stripslashes($dbresult->fields['descr']);
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+//html_print_r($entity_type);
+
+                       return $entity_type;
+               }
+
+       }
+?>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]