phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] property/class.bos_agreement.php, 1.1.2.1


From: nomail
Subject: [Phpgroupware-cvs] property/class.bos_agreement.php, 1.1.2.1
Date: Sun, 20 Jun 2004 11:04:46 +0200

Update of /property
Added Files:
        Branch: proposal-branch
          class.bos_agreement.php

date: 2004/06/20 09:04:46;  author: sigurdne;  state: Exp;  lines: +636 -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.                                            
   *
        
\**************************************************************************/
        /* $Id: class.bos_agreement.php,v 1.1.2.1 2004/06/20 09:04:46 sigurdne 
Exp $ */

        class property_bos_agreement
        {
                var $start;
                var $query;
                var $filter;
                var $sort;
                var $order;
                var $cat_id;
                var $role;
                var $member_id;

                var $public_functions = array
                (
                        'read'                          => True,
                        'read_single'           => True,
                        'save'                          => True,
                        'delete'                        => True,
                        'check_perms'           => True
                );

                function property_bos_agreement($session=False)
                {
                        $this->currentapp                       = 'property'; 
//$GLOBALS['phpgw_data']['flags']['req_app'];
                        $this->so = 
CreateObject($this->currentapp.'_sos_agreement');
                        $this->bocommon = 
CreateObject($this->currentapp.'_bocommon');
                        $this->fm_session       = 
CreateObject($this->currentapp.'_session');
                        $this->vfs                      = 
CreateObject($this->currentapp.'_vfs');
                        $this->rootdir          = $this->vfs->basedir;
                        $this->fakebase         = $this->vfs->fakebase;

                        if ($session)
                        {
                                $this->read_sessiondata();
                                $this->use_session = True;
                        }

                        $start  = 
$this->bocommon->get_var2('start',array('POST','GET'));
                        $query  = 
$this->bocommon->get_var2('query',array('POST','GET'));
                        $sort   = 
$this->bocommon->get_var2('sort',array('POST','GET'));
                        $order  = 
$this->bocommon->get_var2('order',array('POST','GET'));
                        $filter = 
$this->bocommon->get_var2('filter',array('POST','GET'));
                        $cat_id = 
$this->bocommon->get_var2('cat_id',array('POST','GET'));
                        $allrows        = 
$this->bocommon->get_var2('allrows',array('POST','GET'));
                        $role   = 
$this->bocommon->get_var2('role',array('POST','GET'));
                        $member_id      = 
$this->bocommon->get_var2('member_id',array('POST','GET'));


                        $this->role     = $role;
                        $this->so->role = $role;

                        if ($start)
                        {
                                $this->start=$start;
                        }
                        else
                        {
                                $this->start=0;
                        }

                        if(isset($query))
                        {
                                $this->query = $query;
                        }
                        if(!empty($filter))
                        {
                                $this->filter = $filter;
                        }
                        if(isset($sort))
                        {
                                $this->sort = $sort;
                        }
                        if(isset($order))
                        {
                                $this->order = $order;
                        }
                        if(isset($cat_id) && !empty($cat_id))
                        {
                                $this->cat_id = $cat_id;
                        }
                        else
                        {
                                unset($this->cat_id);
                        }
                        if(isset($allrows))
                        {
                                $this->allrows = $allrows;
                        }
                        if(isset($member_id))
                        {
                                $this->member_id = $member_id;
                        }
                }

                function save_sessiondata($data)
                {
                        if ($this->use_session)
                        {
                                
$this->fm_session->appsession('session_data','s_agreement',$data);
                        }
                }

                function read_sessiondata()
                {
                        $data = 
$this->fm_session->appsession('session_data','s_agreement');

                        //html_print_r($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->member_id= $data['member_id'];
                        $this->allrows  = $data['allrows'];
                }

                function check_perms($has, $needed)
                {
                        return (!!($has & $needed) == True);
                }


                function select_category_list($format='',$selected='')
                {
                        switch($format)
                        {
                                case 'select':
                                        
$this->bocommon->xsl_add_file(array('cat_select'));
                                        break;
                                case 'filter':
                                        
$this->bocommon->xsl_add_file(array('cat_filter'));
                                        break;
                        }

                        $categories= $this->so->select_category_list();

                        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 read()
                {
                        $s_agreement = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
                                                                                
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'member_id'=>$this->member_id));
                        $this->total_records = $this->so->total_records;

                        $this->uicols   = $this->so->uicols;

                        for ($i=0; $i<count($s_agreement); $i++)
                        {
                                $s_agreement[$i]['entry_date']  = 
$this->bocommon->show_date($s_agreement[$i]['entry_date'],$GLOBALS['phpgw_data']['prefs'][$this->currentapp
 . '.dateformat']);
                        }
                        return $s_agreement;
                }

                function read_details($id)
                {
                        $list = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
                                                                                
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'member_id'=>$this->member_id,
                                                                                
        's_agreement_id'=>$id,'detail'=>True));
                        $this->total_records = $this->so->total_records;

                        $this->uicols   = $this->so->uicols;

                        for ($i=0; $i<count($list); $i++)
                        {
                                $list[$i]['date']  = 
$this->bocommon->show_date($list[$i]['date'],$GLOBALS['phpgw_data']['prefs'][$this->currentapp
 . '.dateformat']);
                        }

                        return $list;
                }

                function read_prizing($data)
                {
                        $list = $this->so->read_prizing($data);
                        $this->total_records = $this->so->total_records;

                        $this->uicols   = $this->so->uicols;

                        for ($i=0; $i<count($list); $i++)
                        {
                                $list[$i]['date']  = 
$this->bocommon->show_date($list[$i]['date'],$GLOBALS['phpgw_data']['prefs'][$this->currentapp
 . '.dateformat']);
                        }

                        return $list;
                }

                function read_single($data)
                {
                        $s_agreement    = $this->so->read_single($data);
                        $dateformat = 
$GLOBALS['phpgw_data']['prefs'][$this->currentapp . '.dateformat'];
                        $s_agreement['start_date']              = 
$this->bocommon->show_date($s_agreement['start_date'],$dateformat);
                        $s_agreement['end_date']                = 
$this->bocommon->show_date($s_agreement['end_date'],$dateformat);

                        $s_agreement = $this->convert_attribute($s_agreement);

                        $this->vfs->override_acl = 1;

                        $s_agreement['files'] = $this->vfs->ls (array(
                             'string' => $this->fakebase. '/' . 
'service_agreement' .  '/' . $data['s_agreement_id'],
                             'relatives' => array(RELATIVE_NONE)));

                        $this->vfs->override_acl = 0;

                        if(!$s_agreement['files'][0]['file_id'])
                        {
                                unset($s_agreement['files']);
                        }

                        return $s_agreement;

                }

                function read_single_item($data)
                {
                        $item   = $this->so->read_single_item($data);
//html_print_r($item);
                        $item   = $this->convert_attribute($item,True);

                        if($item['location_code'])
                        {
                                $solocation     = 
CreateObject($this->currentapp.'_solocation');
                                $item['location_data'] 
=$solocation->read_single($item['location_code']);
                        }

                        if($item['p_num'])
                        {
                                $soadmin_entity = 
CreateObject($this->currentapp.'_soadmin_entity');
                                $category = 
$soadmin_entity->read_single_category($item['p_entity_id'],$item['p_cat_id']);

                                
$item['p'][$item['p_entity_id']]['p_num']=$item['p_num'];
                                
$item['p'][$item['p_entity_id']]['p_entity_id']=$item['p_entity_id'];
                                
$item['p'][$item['p_entity_id']]['p_cat_id']=$item['p_cat_id'];
                                $item['p'][$item['p_entity_id']]['p_cat_name'] 
= $category['name'];
                        }

                        return $item;
                }

                function convert_attribute($list,$detail='')
                {
                        if($detail)
                        {
                                $this->so->role = 'detail';
                        }
                        $contacts                       = 
CreateObject($this->currentapp.'_contacts');
                        $dateformat = 
$GLOBALS['phpgw_data']['prefs'][$this->currentapp . '.dateformat'];

                        $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));

//html_print_r($list);
                        $m=0;
                        for ($i=0;$i<count($list['attributes']);$i++)
                        {
                                if($list['attributes'][$i]['datatype']=='D' && 
$list['attributes'][$i]['value'])
                                {
                                        $timestamp_date= 
mktime(0,0,0,date(m,strtotime($list['attributes'][$i]['value'])),date(d,strtotime($list['attributes'][$i]['value'])),date(y,strtotime($list['attributes'][$i]['value'])));
                                        $list['attributes'][$i]['value']        
= $this->bocommon->show_date($timestamp_date,$dateformat);
                                }
                                if($list['attributes'][$i]['datatype']=='AB')
                                {
                                        if($list['attributes'][$i]['value'])
                                        {
                                                $contact_data   = 
$contacts->read_single_entry($list['attributes'][$i]['value'],array('org_name'=>'org_name','email'=>'email'));
                                                
$list['attributes'][$i]['org_name']     = $contact_data[0]['org_name'];
                                        }

                                        $insert_record_list[]   = 
$list['attributes'][$i]['name'];
                                        $lookup_link            = 
$this->bocommon->link('/index.php','sid=cookie&op='.$this->currentapp.'_uilookup.addressbook&column='
 . $list['attributes'][$i]['name']);

                                        $lookup_functions[$m]['name'] = 
'lookup_'. $list['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($list['attributes'][$i]['datatype']=='R' || 
$list['attributes'][$i]['datatype']=='CH' || 
$list['attributes'][$i]['datatype']=='LB')
                                {
                                        $list['attributes'][$i]['choice']       
= $this->so->read_attrib_choice($list['attributes'][$i]['attrib_id']);
                                        
$input_type=$input_type_array[$list['attributes'][$i]['datatype']];

                                        
if($list['attributes'][$i]['datatype']=='CH')
                                        {
                                                
$list['attributes'][$i]['value']=unserialize($list['attributes'][$i]['value']);
                                                
$list['attributes'][$i]['choice'] = 
$this->bocommon->select_multi_list_2($list['attributes'][$i]['value'],$list['attributes'][$i]['choice'],$input_type);

                                        }
                                        else
                                        {
                                                for 
($j=0;$j<count($list['attributes'][$i]['choice']);$j++)
                                                {
                                                        
$list['attributes'][$i]['choice'][$j]['input_type']=$input_type;
                                                        
if($list['attributes'][$i]['choice'][$j]['id']==$list['attributes'][$i]['value'])
                                                        {
                                                                
$list['attributes'][$i]['choice'][$j]['checked']='checked';
                                                        }
                                                }
                                        }
                                }

                                $list['attributes'][$i]['datatype_text'] = 
$this->bocommon->translate_datatype($list['attributes'][$i]['datatype']);
                                $list['attributes'][$i]['counter']      = $i;
                                $list['attributes'][$i]['type_id']      = 
$data['type_id'];
                        }

                        for ($j=0;$j<count($lookup_functions);$j++)
                        {
                                $list['lookup_functions'] .= 'function ' . 
$lookup_functions[$j]['name'] ."\r\n";
                                $list['lookup_functions'] .= '{'."\r\n";
                                $list['lookup_functions'] .= 
$lookup_functions[$j]['action'] ."\r\n";
                                $list['lookup_functions'] .= '}'."\r\n";
                        }

                        
$this->fm_session->appsession('insert_record_s_agreement' . 
!!$detail,$this->currentapp,$insert_record_list);

//html_print_r($list);
                        return $list;

                }

                function convert_attribute_save($values_attribute='')
                {

                        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']));
                                }
                        }

                        return $values_attribute;
                }

                function save($values,$values_attribute='',$action='')
                {

                        $values['start_date']   = 
$this->bocommon->date_to_timestamp($values['start_date']);
                        $values['end_date']     = 
$this->bocommon->date_to_timestamp($values['end_date']);

                        $values_attribute = 
$this->convert_attribute_save($values_attribute);

                        if ($action=='edit')
//                      if ($values['s_agreement_id'])
                        {
                                if ($values['s_agreement_id'] != 0)
                                {
                                        
$receipt=$this->so->edit($values,$values_attribute);

                                        if($values['delete_file'])
                                        {
                                                for 
($i=0;$i<count($values['delete_file']);$i++)
                                                {
                                                        $file = 
$this->fakebase. SEP . 'service_agreement' . SEP . $values['s_agreement_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 . 'service_agreement'. SEP . $values['s_agreement_id'] . 
SEP .$values['delete_file'][$i]);
                                                                }
                                                                else
                                                                {
                                                                        
$receipt['message'][]=array('msg'=>lang('file deleted') . ' :'. 
$this->fakebase. SEP . 'service_agreement'. SEP . $values['id'] . SEP . 
$values['delete_file'][$i]);
                                                                }
                                                                
$this->vfs->override_acl = 0;
                                                        }
                                                }
                                        }
                                }
                        }
                        else
                        {
                                $receipt = 
$this->so->add($values,$values_attribute);
                        }
                        return $receipt;
                }

                function save_item($values,$values_attribute='')
                {

                        while (is_array($values['location']) && list(,$value) = 
each($values['location']))
                        {
                                if($value)
                                {
                                        $location[] = $value;
                                }
                        }

                        $values['location_code'address@hidden("-", $location);

                        $values_attribute = 
$this->convert_attribute_save($values_attribute);

                        if ($values['id'])
                        {
                                if ($values['id'] != 0)
                                {
                                        
$receipt=$this->so->edit_item($values,$values_attribute);
                                }
                        }
                        else
                        {
                                $receipt = 
$this->so->add_item($values,$values_attribute);
                        }
                        return $receipt;
                }


                function update($values)
                {
                        $values['date'] = 
$this->bocommon->date_to_timestamp($values['date']);

                        return $this->so->update($values);
                }

                function delete_last_index($s_agreement_id,$id)
                {
                        $this->so->delete_last_index($s_agreement_id,$id);
                }


                function delete_item($s_agreement_id,$item_id)
                {
                        $this->so->delete_item($s_agreement_id,$item_id);
                }

                function delete($s_agreement_id='',$id='',$attrib='')
                {
                        if ($attrib)
                        {
                                $this->so->delete_attrib($id);
                        }
                        else
                        {
                                $this->so->delete($s_agreement_id);
                        }
                }

                function read_attrib($type_id='')
                {
                        $attrib = $this->so->read_attrib(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
                                                                                
        'allrows'=>$this->allrows));

                        for ($i=0; $i<count($attrib); $i++)
                        {
                                $attrib[$i]['datatype'] = 
$this->bocommon->translate_datatype($attrib[$i]['datatype']);
                        }

                        $this->total_records = $this->so->total_records;

                        return $attrib;
                }

                function read_single_attrib($id)
                {
                        return $this->so->read_single_attrib($id);
                }

                function resort_attrib($data)
                {
                        $this->so->resort_attrib($data);
                }

                function save_attrib($attrib,$action='')
                {
                        if ($action=='edit')
                        {
                                if ($attrib['id'] != '')
                                {

                                        $receipt = 
$this->so->edit_attrib($attrib);
                                }
                        }
                        else
                        {
                                $receipt = $this->so->add_attrib($attrib);
                        }
                        return $receipt;
                }

                function column_list($selected='',$allrows='')
                {
                        if(!$selected)
                        {
                                $selected = 
unserialize($GLOBALS['phpgw_data']['prefs'][$this->currentapp . 
".entity_columns_" . $this->entity_id . '_' . $this->cat_id]);
                        }

                        $columns = 
$this->so->read_attrib(array('allrows'=>$allrows,'column_list'=>True));

                        
$column_list=$this->bocommon->select_multi_list($selected,$columns);

                        return $column_list;
                }

                function request_next_id()
                {
                                return $this->so->request_next_id();
                }

                function create_home_dir($receipt='')
                {
//html_print_r($this->fakebase. '/' . 'service_agreement');
                        if(!$this->vfs->file_exists(array(
                                        'string' => $this->fakebase. '/' . 
'service_agreement',
                                        'relatives' => Array(RELATIVE_NONE)
                                )))
                        {
                                $this->vfs->override_acl = 1;

                                if(!$this->vfs->mkdir (array(
                                     'string' => $this->fakebase. '/' . 
'service_agreement',
                                     'relatives' => array(
                                          RELATIVE_NONE
                                     )
                                )))
                                {
                                        
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. '/' . 'service_agreement');
                                }
                                else
                                {
                                        
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. '/' . 'service_agreement');
                                }
                                $this->vfs->override_acl = 0;
                        }

                        return $receipt;
                }

                function create_document_dir($id='')
                {

                        if(!$this->vfs->file_exists(array(
                                        'string' => $this->fakebase. '/' . 
'service_agreement' .  '/' . $id,
                                        'relatives' => Array(RELATIVE_NONE)
                                )))
                        {
                                $this->vfs->override_acl = 1;
                                if(!$this->vfs->mkdir (array(
                                     'string' => $this->fakebase. '/' . 
'service_agreement' .  '/' . $id,
                                     'relatives' => array(
                                          RELATIVE_NONE
                                     )
                                )))
                                {
                                        
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. '/'  . 'service_agreement' .  '/' . $id);
                                }
                                else
                                {
                                        
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. '/' . 'service_agreement' .  '/' . $id);
                                }
                                $this->vfs->override_acl = 0;
                        }

//html_print_r($receipt);
                        return $receipt;
                }


        }
?>




reply via email to

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