[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/inc/class.bocommon.inc.php, 1.4
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/inc/class.bocommon.inc.php, 1.4 |
Date: |
Fri, 11 Jun 2004 19:13:13 +0200 |
Update of /property/inc
Modified Files:
Branch:
class.bocommon.inc.php
date: 2004/06/11 17:13:13; author: sigurdne; state: Exp; lines: +1231 -1223
Log Message:
no message
=====================================================================
Index: property/inc/class.bocommon.inc.php
diff -u property/inc/class.bocommon.inc.php:1.3
property/inc/class.bocommon.inc.php:1.4
--- property/inc/class.bocommon.inc.php:1.3 Sun Jun 6 20:18:39 2004
+++ property/inc/class.bocommon.inc.php Fri Jun 11 17:13:13 2004
@@ -1,1223 +1,1231 @@
-<?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 bocommon
- {
- var $start;
- var $query;
- var $filter;
- var $sort;
- var $order;
- var $cat_id;
- var $district_id;
-
-
- var $public_functions = array
- (
- 'select_part_of_town' => True,
- 'menu' => True,
- );
-
- var $soap_functions = array(
- 'list' => array(
- 'in' =>
array('int','int','struct','string','int'),
- 'out' => array('array')
- ),
- 'read' => array(
- 'in' => array('int','struct'),
- 'out' => array('array')
- ),
- 'save' => array(
- 'in' => array('int','struct'),
- 'out' => array()
- ),
- 'delete' => array(
- 'in' => array('int','struct'),
- 'out' => array()
- )
- );
-
- function bocommon()
- {
-
- $this->currentapp =
$GLOBALS['phpgw_info']['flags']['currentapp'];
- $this->socommon =
CreateObject($this->currentapp.'.socommon');
-
- $this->join = $this->socommon->join;
- $this->left_join = $this->socommon->left_join;
-
- switch($GLOBALS['phpgw_info']['server']['db_type'])
- {
- case 'mssql':
- $this->dateformat = "M d
Y";
- $this->datetimeformat = "M d Y g:iA";
- break;
- case 'mysql':
- $this->dateformat =
"Y-m-d";
- $this->datetimeformat = "Y-m-d G:i:s";
- break;
- case 'pgsql':
- $this->dateformat =
"Y-m-d";
- $this->datetimeformat = "Y-m-d G:i:s";
-// $this->dateformat = "F j,
Y";
-// $this->datetimeformat = "F j, Y g:iA";
- break;
- }
-
- /* if
($GLOBALS['phpgw_info']['server']['db_type']=='mssql')
- {
- $this->dateformat = "M d Y";
- $this->datetimeformat = "M d Y g:iA";
- }
- else
- {
- $this->dateformat = "Y-m-d";
- $this->datetimeformat = "Y-m-d G:i:s";
- }
- */
-
- }
-
- function jscalendar()
- {
- $phpgw_js_url =
$GLOBALS['phpgw_info']['server']['webserver_url'].'/phpgwapi/js';
- $img = $phpgw_js_url.'/jscalendar/img.gif';
- $dateformat =
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
- $jsDateFormat = str_replace(array('d', 'm', 'M', 'Y'),
array('%d', '%m', '%b', '%Y'), $dateformat);
-
- $GLOBALS['phpgw_info']['flags']['java_script']
.='</script>
- <link rel="stylesheet" type="text/css" media="all"
href="'.$phpgw_js_url.'/jscalendar/calendar-win2k-cold-1.css"
title="win2k-cold-1" >
- <script type="text/javascript"
src="'.$phpgw_js_url.'/jscalendar/calendar.js"></script>
- <script type="text/javascript"
src="'.$phpgw_js_url.'/jscalendar/calendar-setup.js"></script>
- <script type="text/javascript"
src="'.$phpgw_js_url.'/jscalendar/lang/calendar-'.substr($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'],0,2)
.'.js"></script>
- ';
-
-
-// <script type="text/javascript"
src="'.ereg_replace('[?&]*click_history=[0-9a-f]*','',$GLOBALS['phpgw']->link('/phpgwapi/js/jscalendar/jscalendar-setup.php')).'"></script>
-
- $cal_info=array(
-// 'stylesheet'
=> $phpgw_js_url.'/jscalendar/calendar-win2k-cold-1.css',
-// 'calendar_source'
=> $phpgw_js_url.'/jscalendar/calendar.js',
-// 'calendar_setup_source' =>
$phpgw_js_url.'/jscalendar/calendar-setup.js',
-// 'calendar_lang'
=>
$phpgw_js_url.'/jscalendar/lang/calendar-'.substr($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'],0,2)
.'.js',
- 'jsDateFormat'
=> $jsDateFormat,
- 'img'
=> $img,
- );
- return $cal_info;
- }
-
- function check_perms($rights, $required)
- {
- // return (!!($rights & $required) == True);
- return ($rights & $required);
- }
-
- function create_preferences($app='',$user_id='')
- {
- return
$this->socommon->create_preferences($app,$user_id);
- }
-
- function get_lookup_entity($location='')
- {
- return $this->socommon->get_lookup_entity($location);
- }
-
- function get_start_entity($location='')
- {
- return $this->socommon->get_start_entity($location);
- }
-
- function msgbox_data($receipt)
- {
- $msgbox_data_error=array();
- if (isSet($receipt['error']) AND
is_array($receipt['error']))
- {
- foreach($receipt['error'] as $errors)
- {
- $msgbox_data_error +=
array($errors['msg']=> False);
- }
- }
-
- $msgbox_data_message=array();
-
- if (isSet($receipt['message']) AND
is_array($receipt['message']))
- {
- foreach($receipt['message'] as $messages)
- {
- $msgbox_data_message +=
array($messages['msg']=> True);
- }
- }
-
- $msgbox_data = $msgbox_data_error +
$msgbox_data_message;
-
- return $msgbox_data;
- }
-
- function moneyformat($amount)
- {
- if
($GLOBALS['phpgw_info']['server']['db_type']=='mssql')
- {
- $moneyformat =
"CONVERT(MONEY,"."'$amount'".",0)";
- }
- else
- {
- $moneyformat = "'" . $amount . "'";
- }
-
- return $moneyformat;
- }
-
-
- function date_array($date)
- {
- $dateformat =
strtolower($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
- $dateformat = str_replace(".","",$dateformat);
- $dateformat = str_replace("-","",$dateformat);
- $dateformat = str_replace("/","",$dateformat);
- $y=strpos($dateformat,'y');
- $d=strpos($dateformat,'d');
- $m=strpos($dateformat,'m');
-
- $dateparts = explode('/', $date);
- $date_array['day'] = $dateparts[$d];
- $date_array['month'] = $dateparts[$m];
- $date_array['year'] = $dateparts[$y];
-
- return $date_array;
- }
-
- function date_to_timestamp($date)
- {
- if($date)
- {
- $date_array = $this->date_array($date);
- $date = mktime
(2,0,0,$date_array['month'],$date_array['day'],$date_array['year']);
- }
- return $date;
- }
-
-
- function
column_list($selected='',$entity_type='',$cat_id,$allrows='')
- {
- $bostandard_entity =
CreateObject($this->currentapp.'.bostandard_entity',True);
-
- if(!$selected)
- {
-
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp][$entity_type.'_columns_'.$cat_id];
- }
-
- $columns =
$bostandard_entity->read_attrib($entity_type,$cat_id,$allrows);
-//_debug_array($columns);
-
-
$column_list=$this->select_multi_list($selected,$columns);
-
- return $column_list;
-
- }
-
- function select_multi_list($selected='',$input_list)
- {
- $j=0;
- if (isset($input_list) AND is_array($input_list))
- {
- foreach($input_list as $entry)
- {
- $output_list[$j]['id'] = $entry['id'];
- $output_list[$j]['name'] =
$entry['name'];
-
- for ($i=0;$i<count($selected);$i++)
- {
- if($selected[$i] ==
$entry['id'])
- {
-
$output_list[$j]['selected'] = 'selected';
- }
- }
- $j++;
- }
- }
-
- for ($i=0;$i<count($output_list);$i++)
- {
- if ($output_list[$i]['selected'] != 'selected')
- {
- unset($output_list[$i]['selected']);
- }
- }
-
- return $output_list;
- }
-
-
-
- function select_list($selected='',$input_list='')
- {
- if (isset($input_list) AND is_array($input_list))
- {
- foreach($input_list as $entry)
- {
- $sel_entry = '';
- if ($entry['id']==$selected)
- {
- $sel_entry = 'selected';
- }
- $entry_list[] = array
- (
- 'id' => $entry['id'],
- 'name' =>
$entry['name'],
- 'selected' => $sel_entry
- );
- }
- for ($i=0;$i<count($entry_list);$i++)
- {
- if ($entry_list[$i]['selected'] !=
'selected')
- {
-
unset($entry_list[$i]['selected']);
- }
- }
- }
- return $entry_list;
- }
-
-
- function
get_user_list($format='',$selected='',$extra='',$default='')
- {
- switch($format)
- {
- case 'select':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_select'));
- break;
- case 'filter':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_filter'));
- break;
- }
-
- if(!$selected && $default)
- {
- $selected = $default;
- }
-
- if (is_array($extra))
- {
- foreach($extra as $extra_user)
- {
- $users_extra[]=array
- (
- 'account_id' => $extra_user,
- 'account_firstname' =>
lang($extra_user)
- );
- }
- }
-
- $accounts = CreateObject('phpgwapi.accounts');
- $users = $accounts->get_list('accounts', $start, $sort,
$order, $query);
- unset($accounts);
- if (is_array($users_extra) && is_array($users))
- {
- $users = $users_extra + $users;
- }
-
- if (isSet($users) AND is_array($users))
- {
- foreach($users as $user)
- {
- $sel_user = '';
- if ($user['account_id']==$selected)
- {
- $sel_user = 'selected';
- }
-
- $user_list[] = array
- (
- 'user_id' =>
$user['account_id'],
- 'name' =>
$user['account_lastname'].' '.$user['account_firstname'],
- 'selected' => $sel_user
- );
- }
- }
-
- $user_count= count($user_list);
- for ($i=0;$i<$user_count;$i++)
- {
- if ($user_list[$i]['selected'] != 'selected')
- {
- unset($user_list[$i]['selected']);
- }
- }
-
-//_debug_array($user_list);
- return $user_list;
- }
-
- function get_group_list($format='',$selected='')
- {
- switch($format)
- {
- case 'select':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('group_select'));
- break;
- case 'filter':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('group_filter'));
- break;
- }
-
- $accounts = CreateObject('phpgwapi.accounts');
- $users = $accounts->get_list('groups', $start, $sort,
$order, $query);
- unset($accounts);
- if (isSet($users) AND is_array($users))
- {
- foreach($users as $user)
- {
- $sel_user = '';
- if ($user['account_id']==$selected)
- {
- $sel_user = 'selected';
- }
-
- $user_list[] = array
- (
- 'id' => $user['account_id'],
- 'name' =>
$user['account_firstname'],
- 'selected' => $sel_user
- );
- }
- }
-
- $user_count= count($user_list);
- for ($i=0;$i<$user_count;$i++)
- {
- if ($user_list[$i]['selected'] != 'selected')
- {
- unset($user_list[$i]['selected']);
- }
- }
-
-//_debug_array($user_list);
- return $user_list;
- }
-
-
- function
get_user_list_right($right='',$selected='',$acl_location='')
- {
-
$employees=$this->socommon->get_user_list_right($right,$acl_location);
- while (is_array($employees) && list(,$user) =
each($employees))
- {
- $sel_user = '';
- if ($user['account_lid']==$selected)
- {
- $sel_user = 'selected';
- }
-
- $user_list[] = array
- (
- 'lid' =>
$user['account_lid'],
- 'firstname' =>
$user['account_firstname'],
- 'lastname' =>
$user['account_lastname'],
- 'selected' => $sel_user
- );
- }
-
- for ($i=0;$i<count($user_list);$i++)
- {
- if ($user_list[$i]['selected'] != 'selected')
- {
- unset($user_list[$i]['selected']);
- }
- }
-
- return $user_list;
- }
-
- function
get_user_list_right2($format='',$right='',$selected='',$acl_location='',$extra='',$default='')
- {
- switch($format)
- {
- case 'select':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_select'));
- break;
- case 'filter':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_filter'));
- break;
- }
-
- if(!$selected && $default)
- {
- $selected = $default;
- }
-
- if (isset($extra) AND is_array($extra))
- {
- foreach($extra as $extra_user)
- {
- $users_extra[]=array
- (
- 'account_id' => $extra_user,
- 'account_firstname' =>
lang($extra_user)
- );
- }
- }
-
-
$users=$this->socommon->get_user_list_right($right,$acl_location);
-
- if (is_array($users_extra) && is_array($users))
- {
- foreach($users as $users_entry)
- {
- array_push($users_extra,$users_entry);
- }
- $users=$users_extra;
- }
-
- while (is_array($users) && list(,$user) = each($users))
- {
- $sel_user = '';
- if ($user['account_id']==$selected)
- {
- $sel_user = 'selected';
- }
-
- $user_list[] = array
- (
- 'user_id' =>
$user['account_id'],
- 'name' =>
$user['account_lastname'].' '.$user['account_firstname'],
- 'selected' => $sel_user
- );
- }
-
- for ($i=0;$i<count($user_list);$i++)
- {
- if ($user_list[$i]['selected'] != 'selected')
- {
- unset($user_list[$i]['selected']);
- }
- }
-
- return $user_list;
- }
-
-
- function initiate_ui_vendorlookup($data)
- {
-//_debug_array($data);
-
- $contacts =
CreateObject($this->currentapp.'.soactor');
- $contacts->role='vendor';
-
- if($data['type']=='view')
- {
-
$GLOBALS['phpgw']->xslttpl->add_file(array('vendor_view'));
- }
- else
- {
-
$GLOBALS['phpgw']->xslttpl->add_file(array('vendor_form'));
- }
-
- $vendor['value_vendor_id']
= $data['vendor_id'];
- $vendor['value_vendor_name'] =
$data['vendor_name'];
-
- if($data['vendor_id'] && !$data['vendor_name'])
- {
- $vendor_data
= $contacts->read_single(array('actor_id'=>$data['vendor_id']));
- if(is_array($vendor_data))
- {
- foreach($vendor_data['attributes'] as
$attribute)
- {
-
if($attribute['name']=='org_name')
- {
-
$vendor['value_vendor_name']=$attribute['value'];
- break;
- }
- }
- }
- }
-
- $vendor['vendor_link']
=
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor');
- $vendor['lang_vendor']
= lang('Vendor');
- $vendor['lang_select_vendor_help'] =
lang('Klick this link to select vendor');
- $vendor['lang_vendor_name']
= lang('Vendor Name');
-
- unset($contacts);
-//_debug_array($vendor);
- return $vendor;
- }
-
-
- function initiate_ui_budget_account_lookup($data)
- {
-//_debug_array($data);
-
-
$GLOBALS['phpgw']->xslttpl->add_file(array('b_account_form'));
- $b_account['value_b_account_id']
= $data['b_account_id'];
- $b_account['value_b_account_name']
= $data['b_account_name'];
- $b_account['b_account_link']
=
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.b_account');
- $b_account['lang_b_account']
= lang('b_account');
- $b_account['lang_select_b_account_help'] =
lang('Klick this link to select budget account');
- $b_account['lang_b_account']
= lang('Budget account');
- if($data['b_account_id'] && !$data['b_account_name'])
- {
- $b_account_object =
CreateObject($this->currentapp.'.sob_account');
- $b_account_data =
$b_account_object->read_single($data['b_account_id']);
- $b_account['value_b_account_name'] =
$b_account_data['descr'];
- }
-
-//_debug_array($b_account);
- return $b_account;
- }
-
- function
select_multi_list_2($selected='',$input_list,$input_type='')
- {
- $j=0;
- if (isset($input_list) AND is_array($input_list))
- {
- foreach($input_list as $entry)
- {
- $output_list[$j]['id'] = $entry['id'];
- $output_list[$j]['value'] =
$entry['value'];
- $output_list[$j]['input_type'] =
$input_type;
-
- for ($i=0;$i<count($selected);$i++)
- {
- if($selected[$i] ==
$entry['id'])
- {
-
$output_list[$j]['checked'] = 'checked';
- }
- }
- $j++;
- }
- }
-
- for ($i=0;$i<count($output_list);$i++)
- {
- if ($output_list[$i]['checked'] != 'checked')
- {
- unset($output_list[$i]['checked']);
- }
- }
-
- return $output_list;
- }
-
- function translate_datatype($datatype)
- {
- $datatype_text = array(
- 'V' => 'Varchar',
- 'I' => 'Integer',
- 'C' => 'char',
- 'N' => 'Float',
- 'D' => 'Date',
- 'T' => 'Memo',
- 'R' => 'Muliple radio',
- 'CH' => 'Muliple checkbox',
- 'LB' => 'Listbox',
- 'AB' => 'Contact',
- 'email' => 'Email'
- );
-
- $datatype = lang($datatype_text[$datatype]);
-
- return $datatype;
- }
-
- function translate_datatype_insert($datatype)
- {
- $datatype_text = array(
- 'V' => 'varchar',
- 'I' => 'int',
- 'C' => 'char',
- 'N' => 'decimal',
- 'D' => 'timestamp',
- 'T' => 'text',
- 'R' => 'int',
- 'CH' => 'text',
- 'LB' => 'int',
- 'AB' => 'int',
- 'email' => 'varchar'
- );
-
- return $datatype_text[$datatype];
- }
-
-
- function save_attributes($values_attribute,$type)
- {
-
- 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'])
- {
- $dateformat=
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
- $dateformat =
str_replace(".","",$dateformat);
- $dateformat =
str_replace("-","",$dateformat);
- $dateformat =
str_replace("/","",$dateformat);
- $y=strpos($dateformat,'Y');
- $d=strpos($dateformat,'d');
- $m=strpos($dateformat,'m');
-
- $dateparts = explode('/',
$values_attribute[$i]['value']);
- $day = $dateparts[$d];
- $month = $dateparts[$m];
- $year = $dateparts[$y];
- $values_attribute[$i]['value'] =
date($this->dateformat,mktime(2,0,0,$month,$day,$year));
- }
- }
-
-
$this->socommon->save_attributes($values_attribute,$type);
- }
-
- function list_methods($_type='xmlrpc')
- {
- /*
- This handles introspection or discovery by the logged
in client,
- in which case the input might be an array. The
server always calls
- this function to fill the server dispatch map using a
string.
- */
- if (is_array($_type))
- {
- $_type = $_type['type'] ? $_type['type'] :
$_type[0];
- }
- switch($_type)
- {
- case 'xmlrpc':
- $xml_functions = array(
- 'read' => array(
- 'function' => 'read',
- 'signature' =>
array(array(xmlrpcInt,xmlrpcStruct)),
- 'docstring' =>
lang('Read a single entry by passing the id and fieldlist.')
- ),
- 'save' => array(
- 'function' => 'save',
- 'signature' =>
array(array(xmlrpcStruct,xmlrpcStruct)),
- 'docstring' =>
lang('Update a single entry by passing the fields.')
- ),
- 'delete' => array(
- 'function' => 'delete',
- 'signature' =>
array(array(xmlrpcBoolean,xmlrpcInt)),
- 'docstring' =>
lang('Delete a single entry by passing the id.')
- ),
- 'list' => array(
- 'function' => '_list',
- 'signature' =>
array(array(xmlrpcStruct,xmlrpcStruct)),
- 'docstring' =>
lang('Read a list of entries.')
- ),
- 'list_methods' => array(
- 'function' =>
'list_methods',
- 'signature' =>
array(array(xmlrpcStruct,xmlrpcString)),
- 'docstring' =>
lang('Read this list of methods.')
- )
- );
- return $xml_functions;
- break;
- case 'soap':
- return $this->soap_functions;
- break;
- default:
- return array();
- break;
- }
- }
-
- function add_leading_zero($num)
- {
-
- if ($id_type == "hex")
- {
- $num = hexdec($num);
- $num++;
- $num = dechex($num);
- }
- else
- {
- $num++;
- }
-
- if (strlen($num) == 4)
- $return = $num;
- if (strlen($num) == 3)
- $return = "0$num";
- if (strlen($num) == 2)
- $return = "00$num";
- if (strlen($num) == 1)
- $return = "000$num";
- if (strlen($num) == 0)
- $return = "0001";
-
- return strtoupper($return);
- }
-
-
- function read_location_data($location_code)
- {
- $soadmin_location =
CreateObject($this->currentapp.'.soadmin_location');
-
- $location_types =
$soadmin_location->select_location_type();
- unset($soadmin_location);
-
- return
$this->socommon->read_location_data($location_code,$location_types);
- }
-
- function read_single_tenant($tenant_id)
- {
- return $this->socommon->read_single_tenant($tenant_id);
- }
-
- function check_location($location_code='',$type_id='')
- {
- return
$this->socommon->check_location($location_code,$type_id);
- }
-
- function generate_sql($data)
- {
-//_debug_array($data);
-
- $cols =
(isset($data['cols'])?$data['cols']:'');
- $entity_table =
(isset($data['entity_table'])?$data['entity_table']:'');
- $cols_return =
(isset($data['cols_return'])?$data['cols_return']:'');
- $uicols =
(isset($data['uicols'])?$data['uicols']:'');
- $joinmethod =
(isset($data['joinmethod'])?$data['joinmethod']:'');
- $paranthesis =
(isset($data['paranthesis'])?$data['paranthesis']:'');
- $lookup =
(isset($data['lookup'])?$data['lookup']:'');
- $location_level =
(isset($data['location_level'])?$data['location_level']:'');
- $no_address =
(isset($data['no_address'])?$data['no_address']:'');
-
- $this->join = $this->socommon->join;
-
- $joinmethod .= " $this->join fm_location1 ON
($entity_table.loc1 = fm_location1.loc1))";
- $paranthesis .='(';
- $joinmethod .= " $this->join fm_part_of_town ON
(fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id))";
- $paranthesis .='(';
- $joinmethod .= " $this->join fm_owner ON
(fm_location1.owner_id = fm_owner.id))";
- $paranthesis .='(';
-
- $soadmin_location =
CreateObject($this->currentapp.'.soadmin_location');
- $location_types =
$soadmin_location->select_location_type();
- $config = $soadmin_location->read_config('');
-
- if($location_level)
- {
- $type_id=$location_level;
- }
- else
- {
- $type_id = count($location_types);
- }
- $this->type_id = $type_id;
-
- for ($i=0; $i<$type_id; $i++)
- {
-
- $uicols['input_type'][] = 'text';
- $uicols['name'][] = 'loc'
. $location_types[$i]['id'];
- $uicols['descr'][] =
$location_types[$i]['name'];
- $uicols['statustext'][] =
$location_types[$i]['descr'];
- }
-/*
- $fm_location_cols =
$soadmin_location->read_attrib(array('type_id'=>$type_id,'lookup_type'=>$type_id));
- $location_cols_count = count($fm_location_cols);
-
- for ($i=0;$i<$location_cols_count;$i++)
- {
- if($fm_location_cols[$i]['list']==1)
- {
- $cols_extra[]
= $fm_location_cols[$i]['column_name']; // only for lookup
- $cols_return[]
= $fm_location_cols[$i]['column_name'];
- $uicols['input_type'][] =
'text';
- $uicols['name'][]
= $fm_location_cols[$i]['column_name'];
- $uicols['descr'][]
= $fm_location_cols[$i]['input_text'];
- $uicols['statustext'][] =
$fm_location_cols[$i]['statustext'];
- }
- }
-
-*/
- unset($soadmin_location);
-
- for ($i=0; $i< $this->type_id; $i++)
- {
- $cols_return[] = 'loc' .
$location_types[$i]['id'];
- }
-
- if($lookup)
- {
- $cols_return[] =
'loc1_name';
- $cols_extra[] =
'loc1_name';
- $uicols['input_type'][] = 'text';
- $uicols['name'][] =
'loc1_name';
- $uicols['descr'][] =
lang('Property Name');
- $uicols['statustext'][] =
lang('Property Name');
-
- for ($i=2;$i<($type_id+1);$i++)
- {
- $cols_return_lookup[] = 'loc'
. $i . '_name';
- $uicols['input_type'][] =
'hidden';
- $uicols['name'][]
= 'loc' . $i . '_name';
- $uicols['descr'][]
= '';
- $uicols['statustext'][] = '';
- }
- }
-
- if(!$no_address)
- {
- $cols.= ",$entity_table.address";
- $cols_return[] =
'address';
- $uicols['input_type'][] = 'text';
- $uicols['name'][] =
'address';
- $uicols['descr'][] =
lang('address');
- $uicols['statustext'][] =
lang('address');
- }
-
-
- $config_count = count($config);
- for ($i=0;$i<$config_count;$i++)
- {
-
- if (($config[$i]['location_type'] <= $type_id)
&& ($config[$i]['query_value'] ==1))
- {
-
-
if($config[$i]['column_name']=='street_id')
- {
-
- $cols_return[]
= 'street_name';
- $uicols['input_type'][]
= 'hidden';
- $uicols['name'][]
= 'street_name';
- $uicols['descr'][]
= lang('street name');
- $uicols['statustext'][]
= lang('street name');
-
- $cols_return[]
= 'street_number';
- $uicols['input_type'][]
= 'hidden';
- $uicols['name'][]
= 'street_number';
- $uicols['descr'][]
= lang('street number');
- $uicols['statustext'][]
= lang('street number');
-
- $cols_return[]
= $config[$i]['column_name'];
- $uicols['input_type'][]
= 'hidden';
- $uicols['name'][]
= $config[$i]['column_name'];
- $uicols['descr'][]
= lang($config[$i]['input_text']);
- $uicols['statustext'][]
= lang($config[$i]['input_text']);
- if($lookup)
- {
- $cols_extra[]
= 'street_name';
- $cols_extra[]
= 'street_number';
- $cols_extra[]
= $config[$i]['column_name'];
- }
-
- }
- else
- {
- $cols_return[]
= $config[$i]['column_name'];
- $uicols['input_type'][]
= 'text';
- $uicols['name'][]
= $config[$i]['column_name'];
- $uicols['descr'][]
= $config[$i]['input_text'];
- $uicols['statustext'][]
= $config[$i]['input_text'];
-
- if($lookup)
- {
- $cols_extra[]
= $config[$i]['column_name'];
- }
- }
- }
- }
-
- $this->uicols = $uicols;
- $this->cols_return = $cols_return;
- $this->cols_extra = $cols_extra;
- $this->cols_return_lookup = $cols_return_lookup;
-
- $from .= " FROM $paranthesis $entity_table ";
-
- $sql = "SELECT $cols $from $joinmethod";
-
- return $sql;
-
- }
-
- function select_part_of_town($format='',$selected='')
- {
- switch($format)
- {
- case 'select':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('select_part_of_town'));
- break;
- case 'filter':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_part_of_town'));
- break;
- }
-
- $parts= $this->socommon->select_part_of_town();
-
- while (is_array($parts) && list(,$part) = each($parts))
- {
- $sel_part = '';
- if ($part['id']==$selected)
- {
- $sel_part = 'selected';
- }
-
- $part_of_town_list[] = array
- (
- 'id' => $part['id'],
- 'name' => $part['name'],
- 'selected' => $sel_part
- );
- }
-
- for ($i=0;$i<count($part_of_town_list);$i++)
- {
- if ($part_of_town_list[$i]['selected'] !=
'selected')
- {
-
unset($part_of_town_list[$i]['selected']);
- }
- }
-
- return $part_of_town_list;
- }
-
- function select_category_property_list($format='',$selected='')
- {
- switch($format)
- {
- case 'select':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
- break;
- case 'filter':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
- break;
- }
-
- $categories=
$this->socommon->select_category_property_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 select_district_list($format='',$selected='')
- {
- switch($format)
- {
- case 'select':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('select_district'));
- break;
- case 'filter':
-
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_district'));
- break;
- }
-
- $districts= $this->socommon->select_district_list();
-
- while (is_array($districts) && list(,$district) =
each($districts))
- {
- $sel_district = '';
- if ($district['id']==$selected)
- {
- $sel_district = 'selected';
- }
-
- $district_list[] = array
- (
- 'id' => $district['id'],
- 'name' => $district['name'],
- 'selected' => $sel_district
- );
- }
-
- for ($i=0;$i<count($district_list);$i++)
- {
- if ($district_list[$i]['selected'] !=
'selected')
- {
- unset($district_list[$i]['selected']);
- }
- }
-
- return $district_list;
- }
-
-
- function validate_db_insert($values)
- {
- foreach($values as $value)
- {
- if($value)
- {
- $insert_value[] = "'".$value."'";
- }
- else
- {
- $insert_value[] = 'NULL';
- }
- }
-
- $values = implode(",", $insert_value);
- return $values;
- }
-
- function validate_db_update($value_set)
- {
- while (is_array($value_set) && list($field,$value) =
each($value_set))
- {
- if($value)
- {
- $value_entry[]= "$field='$value'";
- }
- else
- {
- $value_entry[]= "$field=NULL";
- }
- }
-
- $value_set = implode(",", $value_entry);
- return $value_set;
- }
-
- function fm_cache($name='',$value='')
- {
- return $this->socommon->fm_cache($name,$value);
- }
-
- function next_id($table,$key='')
- {
- return $this->socommon->next_id($table,$key);
- }
-
- function select_datatype($selected='')
- {
- $datatypes[0]['id']= 'V';
- $datatypes[0]['name']= lang('varchar');
- $datatypes[1]['id']= 'C';
- $datatypes[1]['name']= lang('Character');
- $datatypes[2]['id']= 'I';
- $datatypes[2]['name']= lang('Integer');
- $datatypes[3]['id']= 'N';
- $datatypes[3]['name']= lang('Decimal');
- $datatypes[4]['id']= 'D';
- $datatypes[4]['name']= lang('Date');
- $datatypes[5]['id']= 'T';
- $datatypes[5]['name']= lang('Memo');
- $datatypes[6]['id']= 'R';
- $datatypes[6]['name']= lang('Multiple radio');
- $datatypes[7]['id']= 'CH';
- $datatypes[7]['name']= lang('Multiple Checkbox');
- $datatypes[8]['id']= 'LB';
- $datatypes[8]['name']= lang('ListBox');
- $datatypes[9]['id']= 'AB';
- $datatypes[9]['name']= lang('Contact');
- $datatypes[10]['id']= 'email';
- $datatypes[10]['name']= lang('Email');
-
- return $this->select_list($selected,$datatypes);
-
- }
-
- function select_nullable($selected='')
- {
- $nullable[0]['id']= 'True';
- $nullable[0]['name']= lang('True');
- $nullable[1]['id']= 'False';
- $nullable[1]['name']= lang('False');
-
- return $this->select_list($selected,$nullable);
- }
-
-
- function excel($list,$name,$descr)
- {
- $GLOBALS['phpgw_info']['flags']['noframework'] = True;
- require('PEAR.php');
- $xls =
CreateObject($this->currentapp.'.excel');
-
- $count_uicols_name=count($name);
-
- $j=0;
- if (isset($list) AND is_array($list))
- {
- $str=$xls->Begin();
- foreach($list as $entry)
- {
- $m=0;
- for ($k=0;$k<$count_uicols_name;$k++)
- {
-
if($uicols['input_type'][$k]!='hidden')
- {
- $content[$j][$m]
= str_replace("\r\n"," ",$entry[$name[$k]]);
-
$str.=$xls->WriteLabel(0,$m,$descr[$k]);
- $m++;
- }
- }
-
- $j++;
- }
-
- foreach($content as $row)
- {
- $line++;
- for ($i=0; $i<count($row); $i++)
- {
-
$str.=$xls->WriteLabel($line,$i,$row[$i]);
- }
- }
-
- $filename=
$GLOBALS['phpgw_info']['user']['account_lid'].'.xls';
-
- $str.=$xls->EOF();
- $size=strlen($str);
-
- $browser = CreateObject('phpgwapi.browser');
-
$browser->content_header($filename,'application/vnd.ms-excel',$size);
-
- echo $str;
- }
-
- }
-
-
-
- }
-?>
+<?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 bocommon
+ {
+ var $start;
+ var $query;
+ var $filter;
+ var $sort;
+ var $order;
+ var $cat_id;
+ var $district_id;
+
+
+ var $public_functions = array
+ (
+ 'select_part_of_town' => True,
+ 'menu' => True,
+ );
+
+ var $soap_functions = array(
+ 'list' => array(
+ 'in' =>
array('int','int','struct','string','int'),
+ 'out' => array('array')
+ ),
+ 'read' => array(
+ 'in' => array('int','struct'),
+ 'out' => array('array')
+ ),
+ 'save' => array(
+ 'in' => array('int','struct'),
+ 'out' => array()
+ ),
+ 'delete' => array(
+ 'in' => array('int','struct'),
+ 'out' => array()
+ )
+ );
+
+ function bocommon()
+ {
+
+ $this->currentapp =
$GLOBALS['phpgw_info']['flags']['currentapp'];
+ $this->socommon =
CreateObject($this->currentapp.'.socommon');
+
+ $this->join = $this->socommon->join;
+ $this->left_join = $this->socommon->left_join;
+
+ switch($GLOBALS['phpgw_info']['server']['db_type'])
+ {
+ case 'mssql':
+ $this->dateformat = "M d
Y";
+ $this->datetimeformat = "M d Y g:iA";
+ break;
+ case 'mysql':
+ $this->dateformat =
"Y-m-d";
+ $this->datetimeformat = "Y-m-d G:i:s";
+ break;
+ case 'pgsql':
+ $this->dateformat =
"Y-m-d";
+ $this->datetimeformat = "Y-m-d G:i:s";
+// $this->dateformat = "F j,
Y";
+// $this->datetimeformat = "F j, Y g:iA";
+ break;
+ }
+
+ /* if
($GLOBALS['phpgw_info']['server']['db_type']=='mssql')
+ {
+ $this->dateformat = "M d Y";
+ $this->datetimeformat = "M d Y g:iA";
+ }
+ else
+ {
+ $this->dateformat = "Y-m-d";
+ $this->datetimeformat = "Y-m-d G:i:s";
+ }
+ */
+
+ }
+
+ function jscalendar()
+ {
+ $phpgw_js_url =
$GLOBALS['phpgw_info']['server']['webserver_url'].'/phpgwapi/js';
+ $img = $phpgw_js_url.'/jscalendar/img.gif';
+ $dateformat =
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+ $jsDateFormat = str_replace(array('d', 'm', 'M', 'Y'),
array('%d', '%m', '%b', '%Y'), $dateformat);
+
+ $GLOBALS['phpgw_info']['flags']['java_script']
.='</script>
+ <link rel="stylesheet" type="text/css" media="all"
href="'.$phpgw_js_url.'/jscalendar/calendar-win2k-cold-1.css"
title="win2k-cold-1" >
+ <script type="text/javascript"
src="'.$phpgw_js_url.'/jscalendar/calendar.js"></script>
+ <script type="text/javascript"
src="'.$phpgw_js_url.'/jscalendar/calendar-setup.js"></script>
+ <script type="text/javascript"
src="'.$phpgw_js_url.'/jscalendar/lang/calendar-'.substr($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'],0,2)
.'.js"></script>
+ ';
+
+
+// <script type="text/javascript"
src="'.ereg_replace('[?&]*click_history=[0-9a-f]*','',$GLOBALS['phpgw']->link('/phpgwapi/js/jscalendar/jscalendar-setup.php')).'"></script>
+
+ $cal_info=array(
+// 'stylesheet'
=> $phpgw_js_url.'/jscalendar/calendar-win2k-cold-1.css',
+// 'calendar_source'
=> $phpgw_js_url.'/jscalendar/calendar.js',
+// 'calendar_setup_source' =>
$phpgw_js_url.'/jscalendar/calendar-setup.js',
+// 'calendar_lang'
=>
$phpgw_js_url.'/jscalendar/lang/calendar-'.substr($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'],0,2)
.'.js',
+ 'jsDateFormat'
=> $jsDateFormat,
+ 'img'
=> $img,
+ );
+ return $cal_info;
+ }
+
+ function check_perms($rights, $required)
+ {
+ // return (!!($rights & $required) == True);
+ return ($rights & $required);
+ }
+
+ function create_preferences($app='',$user_id='')
+ {
+ return
$this->socommon->create_preferences($app,$user_id);
+ }
+
+ function get_lookup_entity($location='')
+ {
+ return $this->socommon->get_lookup_entity($location);
+ }
+
+ function get_start_entity($location='')
+ {
+ return $this->socommon->get_start_entity($location);
+ }
+
+ function msgbox_data($receipt)
+ {
+ $msgbox_data_error=array();
+ if (isSet($receipt['error']) AND
is_array($receipt['error']))
+ {
+ foreach($receipt['error'] as $errors)
+ {
+ $msgbox_data_error +=
array($errors['msg']=> False);
+ }
+ }
+
+ $msgbox_data_message=array();
+
+ if (isSet($receipt['message']) AND
is_array($receipt['message']))
+ {
+ foreach($receipt['message'] as $messages)
+ {
+ $msgbox_data_message +=
array($messages['msg']=> True);
+ }
+ }
+
+ $msgbox_data = $msgbox_data_error +
$msgbox_data_message;
+
+ return $msgbox_data;
+ }
+
+ function moneyformat($amount)
+ {
+ if
($GLOBALS['phpgw_info']['server']['db_type']=='mssql')
+ {
+ $moneyformat =
"CONVERT(MONEY,"."'$amount'".",0)";
+ }
+ else
+ {
+ $moneyformat = "'" . $amount . "'";
+ }
+
+ return $moneyformat;
+ }
+
+
+ function date_array($date)
+ {
+ $dateformat =
strtolower($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+ $dateformat = str_replace(".","",$dateformat);
+ $dateformat = str_replace("-","",$dateformat);
+ $dateformat = str_replace("/","",$dateformat);
+ $y=strpos($dateformat,'y');
+ $d=strpos($dateformat,'d');
+ $m=strpos($dateformat,'m');
+
+ $dateparts = explode('/', $date);
+ $date_array['day'] = $dateparts[$d];
+ $date_array['month'] = $dateparts[$m];
+ $date_array['year'] = $dateparts[$y];
+
+ return $date_array;
+ }
+
+ function date_to_timestamp($date)
+ {
+ if($date)
+ {
+ $date_array = $this->date_array($date);
+ $date = mktime
(2,0,0,$date_array['month'],$date_array['day'],$date_array['year']);
+ }
+ return $date;
+ }
+
+
+ function
column_list($selected='',$entity_type='',$cat_id,$allrows='')
+ {
+ $bostandard_entity =
CreateObject($this->currentapp.'.bostandard_entity',True);
+
+ if(!$selected)
+ {
+
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp][$entity_type.'_columns_'.$cat_id];
+ }
+
+ $columns =
$bostandard_entity->read_attrib($entity_type,$cat_id,$allrows);
+//_debug_array($columns);
+
+
$column_list=$this->select_multi_list($selected,$columns);
+
+ return $column_list;
+
+ }
+
+ function select_multi_list($selected='',$input_list)
+ {
+ $j=0;
+ if (isset($input_list) AND is_array($input_list))
+ {
+ foreach($input_list as $entry)
+ {
+ $output_list[$j]['id'] = $entry['id'];
+ $output_list[$j]['name'] =
$entry['name'];
+
+ for ($i=0;$i<count($selected);$i++)
+ {
+ if($selected[$i] ==
$entry['id'])
+ {
+
$output_list[$j]['selected'] = 'selected';
+ }
+ }
+ $j++;
+ }
+ }
+
+ for ($i=0;$i<count($output_list);$i++)
+ {
+ if ($output_list[$i]['selected'] != 'selected')
+ {
+ unset($output_list[$i]['selected']);
+ }
+ }
+
+ return $output_list;
+ }
+
+
+
+ function select_list($selected='',$input_list='')
+ {
+ if (isset($input_list) AND is_array($input_list))
+ {
+ foreach($input_list as $entry)
+ {
+ $sel_entry = '';
+ if ($entry['id']==$selected)
+ {
+ $sel_entry = 'selected';
+ }
+ $entry_list[] = array
+ (
+ 'id' => $entry['id'],
+ 'name' =>
$entry['name'],
+ 'selected' => $sel_entry
+ );
+ }
+ for ($i=0;$i<count($entry_list);$i++)
+ {
+ if ($entry_list[$i]['selected'] !=
'selected')
+ {
+
unset($entry_list[$i]['selected']);
+ }
+ }
+ }
+ return $entry_list;
+ }
+
+
+ function
get_user_list($format='',$selected='',$extra='',$default='')
+ {
+ switch($format)
+ {
+ case 'select':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_select'));
+ break;
+ case 'filter':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_filter'));
+ break;
+ }
+
+ if(!$selected && $default)
+ {
+ $selected = $default;
+ }
+
+ if (is_array($extra))
+ {
+ foreach($extra as $extra_user)
+ {
+ $users_extra[]=array
+ (
+ 'account_id' => $extra_user,
+ 'account_firstname' =>
lang($extra_user)
+ );
+ }
+ }
+
+ $accounts = CreateObject('phpgwapi.accounts');
+ $users = $accounts->get_list('accounts', $start, $sort,
$order, $query);
+ unset($accounts);
+ if (is_array($users_extra) && is_array($users))
+ {
+ $users = $users_extra + $users;
+ }
+
+ if (isSet($users) AND is_array($users))
+ {
+ foreach($users as $user)
+ {
+ $sel_user = '';
+ if ($user['account_id']==$selected)
+ {
+ $sel_user = 'selected';
+ }
+
+ $user_list[] = array
+ (
+ 'user_id' =>
$user['account_id'],
+ 'name' =>
$user['account_lastname'].' '.$user['account_firstname'],
+ 'selected' => $sel_user
+ );
+ }
+ }
+
+ $user_count= count($user_list);
+ for ($i=0;$i<$user_count;$i++)
+ {
+ if ($user_list[$i]['selected'] != 'selected')
+ {
+ unset($user_list[$i]['selected']);
+ }
+ }
+
+//_debug_array($user_list);
+ return $user_list;
+ }
+
+ function get_group_list($format='',$selected='')
+ {
+ switch($format)
+ {
+ case 'select':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('group_select'));
+ break;
+ case 'filter':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('group_filter'));
+ break;
+ }
+
+ $accounts = CreateObject('phpgwapi.accounts');
+ $users = $accounts->get_list('groups', $start, $sort,
$order, $query);
+ unset($accounts);
+ if (isSet($users) AND is_array($users))
+ {
+ foreach($users as $user)
+ {
+ $sel_user = '';
+ if ($user['account_id']==$selected)
+ {
+ $sel_user = 'selected';
+ }
+
+ $user_list[] = array
+ (
+ 'id' => $user['account_id'],
+ 'name' =>
$user['account_firstname'],
+ 'selected' => $sel_user
+ );
+ }
+ }
+
+ $user_count= count($user_list);
+ for ($i=0;$i<$user_count;$i++)
+ {
+ if ($user_list[$i]['selected'] != 'selected')
+ {
+ unset($user_list[$i]['selected']);
+ }
+ }
+
+//_debug_array($user_list);
+ return $user_list;
+ }
+
+
+ function
get_user_list_right($right='',$selected='',$acl_location='')
+ {
+
$employees=$this->socommon->get_user_list_right($right,$acl_location);
+ while (is_array($employees) && list(,$user) =
each($employees))
+ {
+ $sel_user = '';
+ if ($user['account_lid']==$selected)
+ {
+ $sel_user = 'selected';
+ }
+
+ $user_list[] = array
+ (
+ 'lid' =>
$user['account_lid'],
+ 'firstname' =>
$user['account_firstname'],
+ 'lastname' =>
$user['account_lastname'],
+ 'selected' => $sel_user
+ );
+ }
+
+ for ($i=0;$i<count($user_list);$i++)
+ {
+ if ($user_list[$i]['selected'] != 'selected')
+ {
+ unset($user_list[$i]['selected']);
+ }
+ }
+
+ return $user_list;
+ }
+
+ function
get_user_list_right2($format='',$right='',$selected='',$acl_location='',$extra='',$default='')
+ {
+ switch($format)
+ {
+ case 'select':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_select'));
+ break;
+ case 'filter':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_filter'));
+ break;
+ }
+
+ if(!$selected && $default)
+ {
+ $selected = $default;
+ }
+
+ if (isset($extra) AND is_array($extra))
+ {
+ foreach($extra as $extra_user)
+ {
+ $users_extra[]=array
+ (
+ 'account_id' => $extra_user,
+ 'account_firstname' =>
lang($extra_user)
+ );
+ }
+ }
+
+
$users=$this->socommon->get_user_list_right($right,$acl_location);
+
+ if (is_array($users_extra) && is_array($users))
+ {
+ foreach($users as $users_entry)
+ {
+ array_push($users_extra,$users_entry);
+ }
+ $users=$users_extra;
+ }
+
+ while (is_array($users) && list(,$user) = each($users))
+ {
+ $sel_user = '';
+ if ($user['account_id']==$selected)
+ {
+ $sel_user = 'selected';
+ }
+
+ $user_list[] = array
+ (
+ 'user_id' =>
$user['account_id'],
+ 'name' =>
$user['account_lastname'].' '.$user['account_firstname'],
+ 'selected' => $sel_user
+ );
+ }
+
+ for ($i=0;$i<count($user_list);$i++)
+ {
+ if ($user_list[$i]['selected'] != 'selected')
+ {
+ unset($user_list[$i]['selected']);
+ }
+ }
+
+ return $user_list;
+ }
+
+
+ function initiate_ui_vendorlookup($data)
+ {
+//_debug_array($data);
+
+ $contacts =
CreateObject($this->currentapp.'.soactor');
+ $contacts->role='vendor';
+
+ if($data['type']=='view')
+ {
+
$GLOBALS['phpgw']->xslttpl->add_file(array('vendor_view'));
+ }
+ else
+ {
+
$GLOBALS['phpgw']->xslttpl->add_file(array('vendor_form'));
+ }
+
+ $vendor['value_vendor_id']
= $data['vendor_id'];
+ $vendor['value_vendor_name'] =
$data['vendor_name'];
+
+ if($data['vendor_id'] && !$data['vendor_name'])
+ {
+ $vendor_data
= $contacts->read_single(array('actor_id'=>$data['vendor_id']));
+ if(is_array($vendor_data))
+ {
+ foreach($vendor_data['attributes'] as
$attribute)
+ {
+
if($attribute['name']=='org_name')
+ {
+
$vendor['value_vendor_name']=$attribute['value'];
+ break;
+ }
+ }
+ }
+ }
+
+ $vendor['vendor_link']
=
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor');
+ $vendor['lang_vendor']
= lang('Vendor');
+ $vendor['lang_select_vendor_help'] =
lang('Klick this link to select vendor');
+ $vendor['lang_vendor_name']
= lang('Vendor Name');
+
+ unset($contacts);
+//_debug_array($vendor);
+ return $vendor;
+ }
+
+
+ function initiate_ui_budget_account_lookup($data)
+ {
+ if($data['type']=='view')
+ {
+
$GLOBALS['phpgw']->xslttpl->add_file(array('b_account_view'));
+ }
+ else
+ {
+
$GLOBALS['phpgw']->xslttpl->add_file(array('b_account_form'));
+ }
+
+ $b_account['value_b_account_id']
= $data['b_account_id'];
+ $b_account['value_b_account_name']
= $data['b_account_name'];
+ $b_account['b_account_link']
=
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.b_account');
+ $b_account['lang_b_account']
= lang('b_account');
+ $b_account['lang_select_b_account_help'] =
lang('Klick this link to select budget account');
+ $b_account['lang_b_account']
= lang('Budget account');
+ if($data['b_account_id'] && !$data['b_account_name'])
+ {
+ $b_account_object =
CreateObject($this->currentapp.'.sob_account');
+ $b_account_data =
$b_account_object->read_single($data['b_account_id']);
+ $b_account['value_b_account_name'] =
$b_account_data['descr'];
+ }
+
+//_debug_array($b_account);
+ return $b_account;
+ }
+
+ function
select_multi_list_2($selected='',$input_list,$input_type='')
+ {
+ $j=0;
+ if (isset($input_list) AND is_array($input_list))
+ {
+ foreach($input_list as $entry)
+ {
+ $output_list[$j]['id'] = $entry['id'];
+ $output_list[$j]['value'] =
$entry['value'];
+ $output_list[$j]['input_type'] =
$input_type;
+
+ for ($i=0;$i<count($selected);$i++)
+ {
+ if($selected[$i] ==
$entry['id'])
+ {
+
$output_list[$j]['checked'] = 'checked';
+ }
+ }
+ $j++;
+ }
+ }
+
+ for ($i=0;$i<count($output_list);$i++)
+ {
+ if ($output_list[$i]['checked'] != 'checked')
+ {
+ unset($output_list[$i]['checked']);
+ }
+ }
+
+ return $output_list;
+ }
+
+ function translate_datatype($datatype)
+ {
+ $datatype_text = array(
+ 'V' => 'Varchar',
+ 'I' => 'Integer',
+ 'C' => 'char',
+ 'N' => 'Float',
+ 'D' => 'Date',
+ 'T' => 'Memo',
+ 'R' => 'Muliple radio',
+ 'CH' => 'Muliple checkbox',
+ 'LB' => 'Listbox',
+ 'AB' => 'Contact',
+ 'email' => 'Email'
+ );
+
+ $datatype = lang($datatype_text[$datatype]);
+
+ return $datatype;
+ }
+
+ function translate_datatype_insert($datatype)
+ {
+ $datatype_text = array(
+ 'V' => 'varchar',
+ 'I' => 'int',
+ 'C' => 'char',
+ 'N' => 'decimal',
+ 'D' => 'timestamp',
+ 'T' => 'text',
+ 'R' => 'int',
+ 'CH' => 'text',
+ 'LB' => 'int',
+ 'AB' => 'int',
+ 'email' => 'varchar'
+ );
+
+ return $datatype_text[$datatype];
+ }
+
+
+ function save_attributes($values_attribute,$type)
+ {
+
+ 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'])
+ {
+ $dateformat=
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+ $dateformat =
str_replace(".","",$dateformat);
+ $dateformat =
str_replace("-","",$dateformat);
+ $dateformat =
str_replace("/","",$dateformat);
+ $y=strpos($dateformat,'Y');
+ $d=strpos($dateformat,'d');
+ $m=strpos($dateformat,'m');
+
+ $dateparts = explode('/',
$values_attribute[$i]['value']);
+ $day = $dateparts[$d];
+ $month = $dateparts[$m];
+ $year = $dateparts[$y];
+ $values_attribute[$i]['value'] =
date($this->dateformat,mktime(2,0,0,$month,$day,$year));
+ }
+ }
+
+
$this->socommon->save_attributes($values_attribute,$type);
+ }
+
+ function list_methods($_type='xmlrpc')
+ {
+ /*
+ This handles introspection or discovery by the logged
in client,
+ in which case the input might be an array. The
server always calls
+ this function to fill the server dispatch map using a
string.
+ */
+ if (is_array($_type))
+ {
+ $_type = $_type['type'] ? $_type['type'] :
$_type[0];
+ }
+ switch($_type)
+ {
+ case 'xmlrpc':
+ $xml_functions = array(
+ 'read' => array(
+ 'function' => 'read',
+ 'signature' =>
array(array(xmlrpcInt,xmlrpcStruct)),
+ 'docstring' =>
lang('Read a single entry by passing the id and fieldlist.')
+ ),
+ 'save' => array(
+ 'function' => 'save',
+ 'signature' =>
array(array(xmlrpcStruct,xmlrpcStruct)),
+ 'docstring' =>
lang('Update a single entry by passing the fields.')
+ ),
+ 'delete' => array(
+ 'function' => 'delete',
+ 'signature' =>
array(array(xmlrpcBoolean,xmlrpcInt)),
+ 'docstring' =>
lang('Delete a single entry by passing the id.')
+ ),
+ 'list' => array(
+ 'function' => '_list',
+ 'signature' =>
array(array(xmlrpcStruct,xmlrpcStruct)),
+ 'docstring' =>
lang('Read a list of entries.')
+ ),
+ 'list_methods' => array(
+ 'function' =>
'list_methods',
+ 'signature' =>
array(array(xmlrpcStruct,xmlrpcString)),
+ 'docstring' =>
lang('Read this list of methods.')
+ )
+ );
+ return $xml_functions;
+ break;
+ case 'soap':
+ return $this->soap_functions;
+ break;
+ default:
+ return array();
+ break;
+ }
+ }
+
+ function add_leading_zero($num)
+ {
+
+ if ($id_type == "hex")
+ {
+ $num = hexdec($num);
+ $num++;
+ $num = dechex($num);
+ }
+ else
+ {
+ $num++;
+ }
+
+ if (strlen($num) == 4)
+ $return = $num;
+ if (strlen($num) == 3)
+ $return = "0$num";
+ if (strlen($num) == 2)
+ $return = "00$num";
+ if (strlen($num) == 1)
+ $return = "000$num";
+ if (strlen($num) == 0)
+ $return = "0001";
+
+ return strtoupper($return);
+ }
+
+
+ function read_location_data($location_code)
+ {
+ $soadmin_location =
CreateObject($this->currentapp.'.soadmin_location');
+
+ $location_types =
$soadmin_location->select_location_type();
+ unset($soadmin_location);
+
+ return
$this->socommon->read_location_data($location_code,$location_types);
+ }
+
+ function read_single_tenant($tenant_id)
+ {
+ return $this->socommon->read_single_tenant($tenant_id);
+ }
+
+ function check_location($location_code='',$type_id='')
+ {
+ return
$this->socommon->check_location($location_code,$type_id);
+ }
+
+ function generate_sql($data)
+ {
+//_debug_array($data);
+
+ $cols =
(isset($data['cols'])?$data['cols']:'');
+ $entity_table =
(isset($data['entity_table'])?$data['entity_table']:'');
+ $cols_return =
(isset($data['cols_return'])?$data['cols_return']:'');
+ $uicols =
(isset($data['uicols'])?$data['uicols']:'');
+ $joinmethod =
(isset($data['joinmethod'])?$data['joinmethod']:'');
+ $paranthesis =
(isset($data['paranthesis'])?$data['paranthesis']:'');
+ $lookup =
(isset($data['lookup'])?$data['lookup']:'');
+ $location_level =
(isset($data['location_level'])?$data['location_level']:'');
+ $no_address =
(isset($data['no_address'])?$data['no_address']:'');
+
+ $this->join = $this->socommon->join;
+
+ $joinmethod .= " $this->join fm_location1 ON
($entity_table.loc1 = fm_location1.loc1))";
+ $paranthesis .='(';
+ $joinmethod .= " $this->join fm_part_of_town ON
(fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id))";
+ $paranthesis .='(';
+ $joinmethod .= " $this->join fm_owner ON
(fm_location1.owner_id = fm_owner.id))";
+ $paranthesis .='(';
+
+ $soadmin_location =
CreateObject($this->currentapp.'.soadmin_location');
+ $location_types =
$soadmin_location->select_location_type();
+ $config = $soadmin_location->read_config('');
+
+ if($location_level)
+ {
+ $type_id=$location_level;
+ }
+ else
+ {
+ $type_id = count($location_types);
+ }
+ $this->type_id = $type_id;
+
+ for ($i=0; $i<$type_id; $i++)
+ {
+
+ $uicols['input_type'][] = 'text';
+ $uicols['name'][] = 'loc'
. $location_types[$i]['id'];
+ $uicols['descr'][] =
$location_types[$i]['name'];
+ $uicols['statustext'][] =
$location_types[$i]['descr'];
+ }
+/*
+ $fm_location_cols =
$soadmin_location->read_attrib(array('type_id'=>$type_id,'lookup_type'=>$type_id));
+ $location_cols_count = count($fm_location_cols);
+
+ for ($i=0;$i<$location_cols_count;$i++)
+ {
+ if($fm_location_cols[$i]['list']==1)
+ {
+ $cols_extra[]
= $fm_location_cols[$i]['column_name']; // only for lookup
+ $cols_return[]
= $fm_location_cols[$i]['column_name'];
+ $uicols['input_type'][] =
'text';
+ $uicols['name'][]
= $fm_location_cols[$i]['column_name'];
+ $uicols['descr'][]
= $fm_location_cols[$i]['input_text'];
+ $uicols['statustext'][] =
$fm_location_cols[$i]['statustext'];
+ }
+ }
+
+*/
+ unset($soadmin_location);
+
+ for ($i=0; $i< $this->type_id; $i++)
+ {
+ $cols_return[] = 'loc' .
$location_types[$i]['id'];
+ }
+
+ if($lookup)
+ {
+ $cols_return[] =
'loc1_name';
+ $cols_extra[] =
'loc1_name';
+ $uicols['input_type'][] = 'text';
+ $uicols['name'][] =
'loc1_name';
+ $uicols['descr'][] =
lang('Property Name');
+ $uicols['statustext'][] =
lang('Property Name');
+
+ for ($i=2;$i<($type_id+1);$i++)
+ {
+ $cols_return_lookup[] = 'loc'
. $i . '_name';
+ $uicols['input_type'][] =
'hidden';
+ $uicols['name'][]
= 'loc' . $i . '_name';
+ $uicols['descr'][]
= '';
+ $uicols['statustext'][] = '';
+ }
+ }
+
+ if(!$no_address)
+ {
+ $cols.= ",$entity_table.address";
+ $cols_return[] =
'address';
+ $uicols['input_type'][] = 'text';
+ $uicols['name'][] =
'address';
+ $uicols['descr'][] =
lang('address');
+ $uicols['statustext'][] =
lang('address');
+ }
+
+
+ $config_count = count($config);
+ for ($i=0;$i<$config_count;$i++)
+ {
+
+ if (($config[$i]['location_type'] <= $type_id)
&& ($config[$i]['query_value'] ==1))
+ {
+
+
if($config[$i]['column_name']=='street_id')
+ {
+
+ $cols_return[]
= 'street_name';
+ $uicols['input_type'][]
= 'hidden';
+ $uicols['name'][]
= 'street_name';
+ $uicols['descr'][]
= lang('street name');
+ $uicols['statustext'][]
= lang('street name');
+
+ $cols_return[]
= 'street_number';
+ $uicols['input_type'][]
= 'hidden';
+ $uicols['name'][]
= 'street_number';
+ $uicols['descr'][]
= lang('street number');
+ $uicols['statustext'][]
= lang('street number');
+
+ $cols_return[]
= $config[$i]['column_name'];
+ $uicols['input_type'][]
= 'hidden';
+ $uicols['name'][]
= $config[$i]['column_name'];
+ $uicols['descr'][]
= lang($config[$i]['input_text']);
+ $uicols['statustext'][]
= lang($config[$i]['input_text']);
+ if($lookup)
+ {
+ $cols_extra[]
= 'street_name';
+ $cols_extra[]
= 'street_number';
+ $cols_extra[]
= $config[$i]['column_name'];
+ }
+
+ }
+ else
+ {
+ $cols_return[]
= $config[$i]['column_name'];
+ $uicols['input_type'][]
= 'text';
+ $uicols['name'][]
= $config[$i]['column_name'];
+ $uicols['descr'][]
= $config[$i]['input_text'];
+ $uicols['statustext'][]
= $config[$i]['input_text'];
+
+ if($lookup)
+ {
+ $cols_extra[]
= $config[$i]['column_name'];
+ }
+ }
+ }
+ }
+
+ $this->uicols = $uicols;
+ $this->cols_return = $cols_return;
+ $this->cols_extra = $cols_extra;
+ $this->cols_return_lookup = $cols_return_lookup;
+
+ $from .= " FROM $paranthesis $entity_table ";
+
+ $sql = "SELECT $cols $from $joinmethod";
+
+ return $sql;
+
+ }
+
+ function select_part_of_town($format='',$selected='')
+ {
+ switch($format)
+ {
+ case 'select':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('select_part_of_town'));
+ break;
+ case 'filter':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_part_of_town'));
+ break;
+ }
+
+ $parts= $this->socommon->select_part_of_town();
+
+ while (is_array($parts) && list(,$part) = each($parts))
+ {
+ $sel_part = '';
+ if ($part['id']==$selected)
+ {
+ $sel_part = 'selected';
+ }
+
+ $part_of_town_list[] = array
+ (
+ 'id' => $part['id'],
+ 'name' => $part['name'],
+ 'selected' => $sel_part
+ );
+ }
+
+ for ($i=0;$i<count($part_of_town_list);$i++)
+ {
+ if ($part_of_town_list[$i]['selected'] !=
'selected')
+ {
+
unset($part_of_town_list[$i]['selected']);
+ }
+ }
+
+ return $part_of_town_list;
+ }
+
+ function select_category_property_list($format='',$selected='')
+ {
+ switch($format)
+ {
+ case 'select':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+ break;
+ case 'filter':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+ break;
+ }
+
+ $categories=
$this->socommon->select_category_property_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 select_district_list($format='',$selected='')
+ {
+ switch($format)
+ {
+ case 'select':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('select_district'));
+ break;
+ case 'filter':
+
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_district'));
+ break;
+ }
+
+ $districts= $this->socommon->select_district_list();
+
+ while (is_array($districts) && list(,$district) =
each($districts))
+ {
+ $sel_district = '';
+ if ($district['id']==$selected)
+ {
+ $sel_district = 'selected';
+ }
+
+ $district_list[] = array
+ (
+ 'id' => $district['id'],
+ 'name' => $district['name'],
+ 'selected' => $sel_district
+ );
+ }
+
+ for ($i=0;$i<count($district_list);$i++)
+ {
+ if ($district_list[$i]['selected'] !=
'selected')
+ {
+ unset($district_list[$i]['selected']);
+ }
+ }
+
+ return $district_list;
+ }
+
+
+ function validate_db_insert($values)
+ {
+ foreach($values as $value)
+ {
+ if($value)
+ {
+ $insert_value[] = "'".$value."'";
+ }
+ else
+ {
+ $insert_value[] = 'NULL';
+ }
+ }
+
+ $values = implode(",", $insert_value);
+ return $values;
+ }
+
+ function validate_db_update($value_set)
+ {
+ while (is_array($value_set) && list($field,$value) =
each($value_set))
+ {
+ if($value)
+ {
+ $value_entry[]= "$field='$value'";
+ }
+ else
+ {
+ $value_entry[]= "$field=NULL";
+ }
+ }
+
+ $value_set = implode(",", $value_entry);
+ return $value_set;
+ }
+
+ function fm_cache($name='',$value='')
+ {
+ return $this->socommon->fm_cache($name,$value);
+ }
+
+ function next_id($table,$key='')
+ {
+ return $this->socommon->next_id($table,$key);
+ }
+
+ function select_datatype($selected='')
+ {
+ $datatypes[0]['id']= 'V';
+ $datatypes[0]['name']= lang('varchar');
+ $datatypes[1]['id']= 'C';
+ $datatypes[1]['name']= lang('Character');
+ $datatypes[2]['id']= 'I';
+ $datatypes[2]['name']= lang('Integer');
+ $datatypes[3]['id']= 'N';
+ $datatypes[3]['name']= lang('Decimal');
+ $datatypes[4]['id']= 'D';
+ $datatypes[4]['name']= lang('Date');
+ $datatypes[5]['id']= 'T';
+ $datatypes[5]['name']= lang('Memo');
+ $datatypes[6]['id']= 'R';
+ $datatypes[6]['name']= lang('Multiple radio');
+ $datatypes[7]['id']= 'CH';
+ $datatypes[7]['name']= lang('Multiple Checkbox');
+ $datatypes[8]['id']= 'LB';
+ $datatypes[8]['name']= lang('ListBox');
+ $datatypes[9]['id']= 'AB';
+ $datatypes[9]['name']= lang('Contact');
+ $datatypes[10]['id']= 'email';
+ $datatypes[10]['name']= lang('Email');
+
+ return $this->select_list($selected,$datatypes);
+
+ }
+
+ function select_nullable($selected='')
+ {
+ $nullable[0]['id']= 'True';
+ $nullable[0]['name']= lang('True');
+ $nullable[1]['id']= 'False';
+ $nullable[1]['name']= lang('False');
+
+ return $this->select_list($selected,$nullable);
+ }
+
+
+ function excel($list,$name,$descr)
+ {
+ $GLOBALS['phpgw_info']['flags']['noframework'] = True;
+ require('PEAR.php');
+ $xls =
CreateObject($this->currentapp.'.excel');
+
+ $count_uicols_name=count($name);
+
+ $j=0;
+ if (isset($list) AND is_array($list))
+ {
+ $str=$xls->Begin();
+ foreach($list as $entry)
+ {
+ $m=0;
+ for ($k=0;$k<$count_uicols_name;$k++)
+ {
+
if($uicols['input_type'][$k]!='hidden')
+ {
+ $content[$j][$m]
= str_replace("\r\n"," ",$entry[$name[$k]]);
+
$str.=$xls->WriteLabel(0,$m,$descr[$k]);
+ $m++;
+ }
+ }
+
+ $j++;
+ }
+
+ foreach($content as $row)
+ {
+ $line++;
+ for ($i=0; $i<count($row); $i++)
+ {
+
$str.=$xls->WriteLabel($line,$i,$row[$i]);
+ }
+ }
+
+ $filename=
$GLOBALS['phpgw_info']['user']['account_lid'].'.xls';
+
+ $str.=$xls->EOF();
+ $size=strlen($str);
+
+ $browser = CreateObject('phpgwapi.browser');
+
$browser->content_header($filename,'application/vnd.ms-excel',$size);
+
+ echo $str;
+ }
+
+ }
+
+ function increment_id($name)
+ {
+ return $this->socommon->increment_id($name);
+ }
+ }
+?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/inc/class.bocommon.inc.php, 1.4,
nomail <=