[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [11197] Added logic for delegating on all organizatio
From: |
Erik Holm-Larsen |
Subject: |
[Fmsystem-commits] [11197] Added logic for delegating on all organization-levels |
Date: |
Mon, 24 Jun 2013 11:02:45 +0000 |
Revision: 11197
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11197
Author: erikhl
Date: 2013-06-24 11:02:44 +0000 (Mon, 24 Jun 2013)
Log Message:
-----------
Added logic for delegating on all organization-levels
Added optional level-parameter to fellesdata organization calls
Added logic to ensure fellesdata-queries works on postgres and oracle
Modified Paths:
--------------
trunk/frontend/inc/class.bofellesdata.inc.php
trunk/frontend/inc/class.borental.inc.php
trunk/frontend/inc/class.uifrontend.inc.php
trunk/rental/inc/class.bofellesdata.inc.php
trunk/rental/inc/class.soparty.inc.php
trunk/rental/inc/class.uiresultunit.inc.php
Modified: trunk/frontend/inc/class.bofellesdata.inc.php
===================================================================
--- trunk/frontend/inc/class.bofellesdata.inc.php 2013-06-24 07:08:16 UTC
(rev 11196)
+++ trunk/frontend/inc/class.bofellesdata.inc.php 2013-06-24 11:02:44 UTC
(rev 11197)
@@ -3,10 +3,10 @@
// Instance variable
protected static $bo;
-
+
/**
* Get a static reference to the storage object associated with
this model object
- *
+ *
* @return the storage object
*/
public static function get_instance()
@@ -23,7 +23,7 @@
exec(sprintf('ping -c 1 -W 5 %s', escapeshellarg($host)), $res,
$rval);
return $rval === 0;
}
-
+
public function get_db()
{
if($this->db && is_object($this->db))
@@ -52,45 +52,46 @@
$db->Password =
$config->config_data['external_db_password'];
$db->Halt_On_Error = 'no';
-
+
try
{
$db->connect();
}
catch(Exception $e)
{
- phpgwapi_cache::message_set('Could not connect
to backend-server ' . $config->config_data['external_db_host'], 'error');
+ phpgwapi_cache::message_set('Could not connect
to backend-server ' . $config->config_data['external_db_host'], 'error');
$GLOBALS['phpgw']->redirect_link('/home.php');
}
$this->db = $db;
return $db;
}
-
+
public function populate_result_units(array $unit_ids)
{
$this->log(__class__, __function__);
$columns = "V_ORG_ENHET.ORG_ENHET_ID,
V_ORG_ENHET.ORG_NAVN, V_ORG_ENHET.RESULTATENHET";
$table = "V_ORG_ENHET";
-
+
if(!$db = $this->get_db())
{
return;
}
-
+
$result_units = array();
-
+
$unit_ids_string = implode(',',$unit_ids);
-
-
- $sql = "SELECT $columns FROM $table WHERE
V_ORG_ENHET.ORG_ENHET_ID IN ($unit_ids_string) AND V_ORG_ENHET.ORG_NIVAA = 4";
+
+
+ $sql = "SELECT $columns FROM $table WHERE
V_ORG_ENHET.ORG_ENHET_ID IN ($unit_ids_string)";
+ //var_dump($sql);
if($db->Type == 'postgres')
{
$sql = strtolower($sql);
}
$db->query($sql,__LINE__,__FILE__);
-
+
while ($db->next_record())
{
if($db->Type == 'postgres')
@@ -100,7 +101,7 @@
"ORG_NAME" => $db->f('org_navn'),
"UNIT_ID" => $db->f('resultatenhet'),
"LEADER" => false
- );
+ );
}
else
{
@@ -112,13 +113,13 @@
);
}
}
-
+
return $result_units;
}
-
+
/**
* Method for retrieving the result units this user has access to
- *
+ *
* @param string $username the username
* @return an array of (result unit number => result unit name)
*/
@@ -132,14 +133,15 @@
*/
$result_units = array();
$org_unit_ids = array();
-
+
$columns = "V_ORG_ENHET.ORG_ENHET_ID, V_ORG_ENHET.ORG_NIVAA,
V_ORG_ENHET.ORG_NAVN, V_ORG_ENHET.ENHET_ID, V_ORG_ENHET.RESULTATENHET";
$table = "V_ORG_ENHET";
$joins = "LEFT JOIN V_ORG_PERSON_ENHET ON
(V_ORG_PERSON_ENHET.ORG_ENHET_ID = V_ORG_ENHET.ORG_ENHET_ID) ".
"LEFT JOIN V_ORG_PERSON ON
(V_ORG_PERSON.ORG_PERSON_ID = V_ORG_PERSON_ENHET.ORG_PERSON_ID)";
-
+
$sql = "SELECT $columns FROM $table $joins WHERE
V_ORG_PERSON.BRUKERNAVN = '$username'";
-
+ //var_dump($sql);
+
if(!$db = $this->get_db())
{
return;
@@ -153,14 +155,14 @@
}
//var_dump($sql);
$db->query($sql,__LINE__,__FILE__);
-
-
-
+
+
+
while ($db->next_record())
{
if($db->Type == "postgres")
{
- $identifier = (int)$db->f('org_enhet_id');
+ $identifier = (int)$db->f('org_enhet_id');
$level = (int)$db->f('org_nivaa','int');
$name = $db->f('org_navn');
$unit_id = $db->f('resultatenhet');
@@ -172,17 +174,17 @@
$name = $db->f('ORG_NAVN');
$unit_id = $db->f('RESULTATENHET');
}
-
+
switch($level)
{
case 1: break; // TODO: Access to all
result units
- case 2: // LEVEL:
Byrådsavdeling
+ case 2: // LEVEL:
Byrådsavdeling
//Must traverse down the
hierarchy
$columns =
"V_ORG_ENHET.ORG_ENHET_ID, V_ORG_ENHET.ORG_NIVAA, V_ORG_ENHET.ORG_NAVN,
V_ORG_ENHET.ENHET_ID, V_ORG_ENHET.RESULTATENHET";
$tables = "V_ORG_ENHET";
$joins = "LEFT JOIN
V_ORG_KNYTNING ON (V_ORG_KNYTNING.ORG_ENHET_ID = V_ORG_ENHET.ORG_ENHET_ID)";
$sql = "SELECT $columns FROM
$tables $joins WHERE V_ORG_ENHET.ORG_NIVAA = 4 AND
V_ORG_KNYTNING.ORG_ENHET_ID_KNYTNING = {$identifier}";
-
+
if($db1->Type == "postgres")
{
$sql = strtolower($sql);
@@ -200,7 +202,7 @@
"UNIT_ID" => $db1->f('resultatenhet'),
"LEADER" => true
);
-
+
$org_unit_ids[(int)$db1->f('org_enhet_id')] = true;
}
}
@@ -214,7 +216,7 @@
"UNIT_ID" => $db1->f('RESULTATENHET'),
"LEADER" => true
);
-
+
$org_unit_ids[(int)$db1->f('ORG_ENHET_ID')] = true;
}
}
@@ -224,7 +226,7 @@
case 4: // LEVEL:
Resultatenhet
//Insert in result array
if(!isset($org_unit_ids[$identifier]))
- {
+ {
$result_units[] = array(
"ORG_UNIT_ID"
=> $identifier,
"ORG_NAME" =>
$name,
@@ -233,10 +235,10 @@
);
$org_unit_ids[$identifier] = true;
}
- break;
+ break;
}
}
-
+
return $result_units;
/*
return array(
@@ -253,12 +255,12 @@
);
*/
}
-
+
/**
- *
+ *
* @param int $number the result unit number
*/
- public function get_organisational_unit_name($number)
+ public function get_organisational_unit_name($number)
{
$this->log(__class__, __function__);
@@ -286,7 +288,7 @@
{
return $db->f('ORG_NAVN', true);
}
- }
+ }
}
else
{
@@ -294,8 +296,8 @@
}
//return "No name";
}
-
- public function get_organisational_unit_info($number)
+
+ public function get_organisational_unit_info($number)
{
$this->log(__class__, __function__);
@@ -328,16 +330,16 @@
);
}
}
- }
+ }
else
{
return lang('no_name_organisational_unit');
}
}
-
+
/**
* Get user info from Fellesdata based on a username
- *
+ *
* @param $username the username in question
* @return an array containing username, firstname, lastname and email
if user exist, false otherwise
*/
@@ -377,11 +379,11 @@
'email' => $db->f('EPOST', true)
);
}
- }
+ }
else
{
return false;
- }
+ }
}
protected function log($class, $function)
Modified: trunk/frontend/inc/class.borental.inc.php
===================================================================
--- trunk/frontend/inc/class.borental.inc.php 2013-06-24 07:08:16 UTC (rev
11196)
+++ trunk/frontend/inc/class.borental.inc.php 2013-06-24 11:02:44 UTC (rev
11197)
@@ -6,7 +6,7 @@
include_class('rental', 'contract', 'inc/model/');
class frontend_borental {
-
+
public static function contract_exist_per_location($contract_id,
$location_code, $contract_state_identifier)
{
$contracts_per_location =
phpgwapi_cache::session_get('frontend', $contract_state_identifier);
@@ -20,20 +20,20 @@
}
return $exist;
}
-
+
public static function send_contract_message(int $contract_id, string
$contract_message, string $from_address)
{
$contract =
rental_socontract::get_instance()->get_single($contract_id);
if(isset($contract) && isset($contract_message) &&
$contract_message != '')
{
- $title = lang('title_contract_message');
+ $title = lang('title_contract_message');
$title .= " ".$contract->get_old_contract_id();
$title .=
"(".lang($contract->get_contract_type_title()).")";
-
+
$config = CreateObject('phpgwapi.config','frontend');
$config->read();
$to = $config->config_data['email_contract_messages'];
-
+
if (isset($contract_message) && isset($to) &&
isset($from_address))
{
if
(isset($GLOBALS['phpgw_info']['server']['smtp_server']) &&
$GLOBALS['phpgw_info']['server']['smtp_server'] )
@@ -42,15 +42,15 @@
{
$GLOBALS['phpgw']->send
= CreateObject('phpgwapi.send');
}
-
+
$from =
"{$GLOBALS['phpgw_info']['user']['fullname']}<{$from_address}>";
-
+
$receive_notification = false;
$rcpt =
$GLOBALS['phpgw']->send->msg('email',$to,$title,
stripslashes(nl2br($contract_message)), '', $from, '',
$from ,
$GLOBALS['phpgw_info']['user']['fullname'],
'html', '', array() ,
$receive_notification);
-
+
if($rcpt)
{
return true;
@@ -58,40 +58,40 @@
}
}
}
-
- return false;
+
+ return false;
}
-
+
public static function get_first_contract_per_location($location_code)
{
$contracts_per_location =
phpgwapi_cache::session_get('frontend', 'contracts_per_location');
return $contracts_per_location[$location_code][0];
}
-
+
public static function
get_first_contract_in_per_location($location_code)
{
$contracts_in_per_location =
phpgwapi_cache::session_get('frontend', 'contracts_in_per_location');
return $contracts_in_per_location[$location_code][0];
}
-
+
/**
*
* @param integer $org_unit_ids
*/
public static function get_property_locations($array)
{
-
+
$property_locations = array();
$property_locations_active = array();
-
+
$total_price_all_buildings = 0;
$total_rented_area_all_builings = 0;
-
+
$types =
rental_socontract::get_instance()->get_fields_of_responsibility();
$location_id_internal =
array_search('contract_type_internleie', $types);
$location_id_in = array_search('contract_type_innleie', $types);
$location_id_ex = array_search('contract_type_eksternleie',
$types);
-
+
foreach($array as $row){
/*
* 1. hent alle kontraktsparter som har org unit id (foreløpig
bruker vi result_unit_number i rentalparty)
@@ -111,49 +111,49 @@
{
$parties =
rental_soparty::get_instance()->get(null, null, null, null, null, null,
array('email' => $row));
}
-
+
$contracts = array();
$composites = array();
-
-
+
+
//For all parties connected to the internal
organization unit
foreach($parties as $party)
{
//... get the contracts
$contracts =
rental_socontract::get_instance()->get(null, null, null, null, null, null,
array('party_id' => $party->get_id()));
-
+
//... and for each contract connected to this
contract part
foreach($contracts as $id => $contract)
{
//... get the composites
$composites =
rental_socomposite::get_instance()->get(null, null, null, null, null, null,
array('contract_id' => $contracts[$id]->get_id()));
-
+
//...and for each composite in the
contract in which this contract part is connected
foreach($composites as $composite)
{
//... get the units
$units =
$composite->get_units();
-
+
//... and for each unit
retrieve the property locations we are after
foreach($units as $unit)
{
$property_location =
$unit->get_location();
$property_locations[$property_location->get_location_code()] =
$property_location;
-
+
// Contract holders:
contracts_per_location (internal) and contracts_in_per_location (in)
-
+
// Internal contract
should have impact on total price
if($contract->get_location_id() == $location_id_internal)
{
$total_price =
rental_socontract_price_item::get_instance()->get_total_price($contract->get_id());
$contract->set_total_price($total_price);
-
+
if(!is_array($contracts_per_location[$property_location->get_location_code()]))
{
-
$contracts_per_location[$property_location->get_location_code()] = array();
+
$contracts_per_location[$property_location->get_location_code()] = array();
}
array_push($contracts_per_location[$property_location->get_location_code()],
$contract);
-
+
if($contract->is_active())
{
$property_locations_active[$property_location->get_location_code()] = true;
@@ -165,15 +165,15 @@
{
$total_price =
rental_socontract_price_item::get_instance()->get_total_price($contract->get_id());
$contract->set_total_price($total_price);
-
+
if($contract->is_active())
{
$property_locations_active[$property_location->get_location_code()] = true;
}
-
+
if(!is_array($contracts_in_per_location[$property_location->get_location_code()]))
{
-
$contracts_in_per_location[$property_location->get_location_code()] = array();
+
$contracts_in_per_location[$property_location->get_location_code()] = array();
}
array_push($contracts_in_per_location[$property_location->get_location_code()],
$contract);
}
@@ -181,13 +181,13 @@
{
$total_price =
rental_socontract_price_item::get_instance()->get_total_price($contract->get_id());
$contract->set_total_price($total_price);
-
+
if(!is_array($contracts_ex_per_location[$property_location->get_location_code()]))
{
-
$contracts_ex_per_location[$property_location->get_location_code()] = array();
+
$contracts_ex_per_location[$property_location->get_location_code()] = array();
}
array_push($contracts_ex_per_location[$property_location->get_location_code()],
$contract);
-
+
if($contract->is_active())
{
$property_locations_active[$property_location->get_location_code()] = true;
@@ -195,19 +195,19 @@
$rented_price_per_location[$property_location->get_location_code()] +=
$total_price;
}
}
- }
+ }
}
}
}
}
-
+
phpgwapi_cache::session_set('frontend',
'contracts_per_location', $contracts_per_location);
phpgwapi_cache::session_set('frontend',
'contracts_in_per_location', $contracts_in_per_location);
phpgwapi_cache::session_set('frontend',
'contracts_ex_per_location', $contracts_ex_per_location);
phpgwapi_cache::session_set('frontend',
'rented_area_per_location', $rented_area_per_location);
phpgwapi_cache::session_set('frontend',
'total_price_per_location', $rented_price_per_location);
-
-
+
+
//Serialize the properties
$serialized_properties = array();
foreach($property_locations as $key => $property_location)
Modified: trunk/frontend/inc/class.uifrontend.inc.php
===================================================================
--- trunk/frontend/inc/class.uifrontend.inc.php 2013-06-24 07:08:16 UTC (rev
11196)
+++ trunk/frontend/inc/class.uifrontend.inc.php 2013-06-24 11:02:44 UTC (rev
11197)
@@ -27,8 +27,8 @@
phpgw::import_class('frontend.bofrontend');
phpgw::import_class('frontend.bofellesdata');
phpgw::import_class('frontend.borental');
-
-
+
+
/**
* Frontend main class
*
@@ -41,7 +41,7 @@
* Used to save state of header (select box, ++) between
requests
* @var array
*/
- public $header_state;
+ public $header_state;
public $public_functions = array
(
@@ -53,7 +53,7 @@
{
// This module uses XSLT templates
$GLOBALS['phpgw_info']['flags']['xslt_app'] = true;
-
+
$this->config =
CreateObject('phpgwapi.config','frontend');
$this->config->read();
$use_fellesdata =
$this->config->config_data['use_fellesdata'];
@@ -62,7 +62,7 @@
// Get the mode: in frame or full screen
$mode = phpgwapi_cache::session_get('frontend',
'noframework');
$noframework = isset($mode) ? $mode : true;
-
+
/* Get the tabs and check to see whether the user has
specified a tab or has a selected tab on session */
$tabs = $this->get_tabs();
$location_id = phpgw::get_var('location_id', 'int',
'REQUEST');
@@ -70,23 +70,23 @@
$selected = isset($tab) && $tab ? $tab :
array_shift(array_keys($tabs));
$this->tabs =
$GLOBALS['phpgw']->common->create_tabs($tabs, $selected);
phpgwapi_cache::session_set('frontend','tab',$selected);
-
+
// Get header state
$this->header_state =
phpgwapi_cache::session_get('frontend', 'header_state');
$this->header_state['use_fellesdata'] = $use_fellesdata;
$this->header_state['logo_path'] = $logo_path;
$this->header_state['form_action'] =
$tabs[$selected]['link'];
-
+
// Get navigation parameters
$param_selected_location = phpgw::get_var('location');
// New location selected from locations list
$param_selected_org_unit =
phpgw::get_var('org_unit_id'); // New organisational unit
selected from organisational units list
$param_only_org_unit = phpgw::get_var('org_enhet_id');
// Frontend access from rental module regarding specific organisational unit
-
+
//Refresh organisation list
- $refresh = phpgw::get_var('refresh','bool');
+ $refresh = phpgw::get_var('refresh','bool');
$property_locations_update = false;
-
+
/* If the user has selected an organisational unit or
all units */
if(isset($param_selected_org_unit))
{
@@ -120,15 +120,15 @@
//Update locations according to organisational
unit specification
$property_locations =
frontend_borental::get_property_locations($org_unit_ids);
$property_locations_update = true;
-
+
}
/* If the user selects a organisational unit in rental
module */
- else if(isset($param_only_org_unit))
+ else if(isset($param_only_org_unit))
{
//TODO: check permissions
if($use_fellesdata){
$name_and_result_number =
frontend_bofellesdata::get_instance()->get_organisational_unit_info($param_only_org_unit);
-
+
//Specify unit
$org_unit_ids = array(
array(
@@ -137,23 +137,23 @@
"UNIT_ID" =>
$name_and_result_number['UNIT_NUMBER']
)
);
-
+
//Update header state
$this->header_state['org_unit'] =
$org_unit_ids;
$this->header_state['number_of_org_units'] = '1';
//$this->header_state['selected_org_unit'] =
$name_and_result_number['UNIT_NUMBER'];
$this->header_state['selected_org_unit'] = $param_only_org_unit;
-
+
//Update locations
$property_locations =
frontend_borental::get_property_locations($org_unit_ids);
$property_locations_update = true;
-
+
$noframework = false; // In regular
frames
phpgwapi_cache::session_set('frontend',
'noframework', $noframework); // Store mode on session
$GLOBALS['phpgw_info']['flags']['menu_selection'] = "frontend::{$selected}";
$this->insert_links_on_header_state();
}
- }
+ }
/* No state, first visit after login, or refresh
request*/
else if(!isset($this->header_state) || isset($refresh)
|| !isset($this->header_state['locations']))
{
@@ -161,7 +161,7 @@
{
//Specify organisational units
$org_units =
frontend_bofellesdata::get_instance()->get_result_units($GLOBALS['phpgw_info']['user']['account_lid']);
-
+
//Merge with delegation units
$delegation_org_ids =
frontend_bofrontend::get_delegations($GLOBALS['phpgw_info']['user']['account_id']);
if(count($delegation_org_ids) > 0)
@@ -169,30 +169,30 @@
$delegation_units =
frontend_bofellesdata::get_instance()->populate_result_units($delegation_org_ids);
$org_units =
array_merge($org_units,$delegation_units);
}
-
+
//Update org units on header state
$this->header_state['org_unit'] =
$org_units;
$this->header_state['number_of_org_units'] = count($org_units);
$this->header_state['selected_org_unit'] = 'all';
-
+
//Update locations
$property_locations =
frontend_borental::get_property_locations($org_units);
}
- else
+ else
{
//If no organisational database is in
use: get rented properties based on username
$usernames[] =
$GLOBALS['phpgw_info']['user']['account_lid'];
$property_locations =
frontend_borental::get_property_locations($usernames);
}
-
+
$property_locations_update = true;
$this->insert_links_on_header_state();
-
+
}
-
-
+
+
if($property_locations_update)
- {
+ {
if(count($property_locations) > 0)
{
$this->header_state['selected_location'] =
$property_locations[0]['location_code'];
@@ -203,13 +203,13 @@
$this->header_state['selected_location'] = '';
$param_selected_location = '';
}
-
+
$this->header_state['locations'] =
$property_locations;
$this->header_state['number_of_locations'] =
count($property_locations);
$this->calculate_totals($property_locations);
}
-
-
+
+
/* If the user has selected a location or as a
side-effect from selecting organisational unit */
if(isset($param_selected_location))
{
@@ -254,15 +254,15 @@
}
else
{
- $this->header_state['new_messages'] =
lang('no_new_messages');
+ $this->header_state['new_messages'] =
lang('no_new_messages');
}
-
+
phpgwapi_cache::session_set('frontend', 'header_state',
$this->header_state);
$GLOBALS['phpgw']->css->add_external_file('frontend/templates/base/base.css');
$GLOBALS['phpgw_info']['flags']['noframework'] = true;
}
-
+
function get_tabs()
{
// Get tabs from location hierarchy
@@ -284,8 +284,8 @@
}
unset($location);
}
-
+
// this one is for generic entitysupport from the app
'property'
$entity_frontend =
isset($this->config->config_data['entity_frontend']) &&
$this->config->config_data['entity_frontend'] ?
$this->config->config_data['entity_frontend'] : array();
@@ -300,7 +300,7 @@
{
$location_id =
$GLOBALS['phpgw']->locations->get_id('property', $location);
$location_arr = explode('.', $location);
-
+
$category =
$entity->read_single_category($location_arr[2], $location_arr[3]);
$tabs[$location_id] = array(
'label' => $category['name'],
@@ -310,17 +310,17 @@
}
$extra_tabs = phpgwapi_cache::session_get('frontend',
'extra_tabs');
-
+
if(isset($extra_tabs))
{
$tabs = array_merge($extra_tabs,$tabs);
}
-
+
phpgwapi_cache::session_clear('frontend', 'extra_tabs');
-
+
return $tabs;
}
-
+
function insert_links_on_header_state()
{
$help_url = "";
@@ -329,12 +329,12 @@
$fileName = '/frontend/help/NO/helpdesk.index.pdf';
$vfs = CreateObject('phpgwapi.vfs');
$vfs->override_acl = 1;
-
+
$file = array('string' => $fileName, RELATIVE_NONE);
if($vfs->file_exists($file)){
$help_in_vfs = true;
}
-
+
if($help_in_vfs)
{
$help_url = "javascript:openwindow('"
@@ -343,7 +343,7 @@
'menuaction'=>
'frontend.uidocumentupload.read_helpfile_from_vfs',
'app' => 'frontend'
)) . "','700','600')";
- }else{
+ }else{
$help_url = "javascript:openwindow('"
.
$GLOBALS['phpgw']->link('/index.php', array
(
@@ -353,7 +353,7 @@
'referer' =>
phpgw::get_var('menuaction')
)) . "','700','600')";
}
-
+
$contact_url = "javascript:openwindow('"
. $GLOBALS['phpgw']->link('/index.php', array
(
@@ -361,7 +361,7 @@
'app' =>
$GLOBALS['phpgw_info']['flags']['currentapp'],
'section' => 'contact'
)) . "','700','600')";
-
+
$folder_url = "javascript:openwindow('"
. $GLOBALS['phpgw']->link('/index.php', array
(
@@ -369,9 +369,9 @@
'app' =>
$GLOBALS['phpgw_info']['flags']['currentapp'],
'section' => 'folder'
)) . "','700','600')";
-
+
$name_of_user =
$GLOBALS['phpgw_info']['user']['firstname']."
".$GLOBALS['phpgw_info']['user']['lastname'];
-
+
if(count($GLOBALS['phpgw_info']['user']['apps']) > 1)
{
$home_url =
$GLOBALS['phpgw']->link('/home.php');
@@ -390,23 +390,23 @@
$this->header_state['folder_url'] = $folder_url;
$this->header_state['name_of_user'] = $name_of_user;
}
-
+
function calculate_totals($property_locations)
{
-
+
// Calculate
$total_area = 0;
// $rented_area_per_location =
phpgwapi_cache::user_get('frontend','rented_area_per_location',
$GLOBALS['phpgw_info']['user']['account_id']);
$rented_area_per_location =
phpgwapi_cache::session_get('frontend','rented_area_per_location');
foreach($rented_area_per_location as $location_code =>
$area_per_location)
{
-
+
if($this->location_in_selection($location_code,$property_locations))
{
$total_area += $area_per_location;
}
}
-
+
$total_price = 0;
// $total_price_per_location =
phpgwapi_cache::user_get('frontend','total_price_per_location',
$GLOBALS['phpgw_info']['user']['account_id']);
$total_price_per_location =
phpgwapi_cache::session_get('frontend','total_price_per_location');
@@ -420,7 +420,7 @@
$this->header_state['total_price'] =
number_format($total_price, 0, ","," ")." kr";
$this->header_state['total_area'] =
number_format($total_area, 0, ",", " ")." kvm";
}
-
+
function location_in_selection($location_code,
$property_locations)
{
foreach($property_locations as $property_location)
@@ -432,7 +432,7 @@
}
return false;
}
-
+
function org_unit_in_selection($unit_id, $org_units)
{
foreach($org_units as $org_unit)
@@ -444,7 +444,7 @@
}
return false;
}
-
+
public function get_org_enhet_id($result_unit_number,
$org_units)
{
foreach($org_units as $org_unit)
Modified: trunk/rental/inc/class.bofellesdata.inc.php
===================================================================
--- trunk/rental/inc/class.bofellesdata.inc.php 2013-06-24 07:08:16 UTC (rev
11196)
+++ trunk/rental/inc/class.bofellesdata.inc.php 2013-06-24 11:02:44 UTC (rev
11197)
@@ -11,10 +11,10 @@
(
'get_all_org_units_autocomplete'
=> true,
);
-
+
/**
* Get a static reference to the storage object associated with
this model object
- *
+ *
* @return the storage object
*/
public static function get_instance()
@@ -24,8 +24,8 @@
}
return self::$bo;
}
-
+
/* our simple php ping function */
function ping($host)
{
@@ -39,17 +39,17 @@
{
return $this->db;
}
-
+
$config = CreateObject('phpgwapi.config','rental');
$config->read();
-
+
if(! $config->config_data['external_db_host'] ||
!$this->ping($config->config_data['external_db_host']))
{
$message ="Database server
{$config->config_data['external_db_host']} is not accessible";
phpgwapi_cache::message_set($message, 'error');
return false;
}
-
+
$db = createObject('phpgwapi.db', null, null, true);
$db->debug =
!!$config->config_data['external_db_debug'];
@@ -73,7 +73,7 @@
$this->db = $db;
return $db;
}
-
+
public function responsibility_id_exist($responsibility_id)
{
$this->log(__class__, __function__);
@@ -89,20 +89,34 @@
}
$sql = "SELECT $column FROM $table $joins WHERE
V_ANSVAR.ANSVAR = '$responsibility_id' AND V_ORG_ENHET.ORG_NIVAA = 4";
+ if($db->Type == "postgres")
+ {
+ $sql = strtolower($sql);
+ }
$db->query($sql,__LINE__,__FILE__);
if($db->next_record())
- {
- return array(
- 'UNIT_ID' =>
$db->f('ORG_ENHET_ID'),
- 'UNIT_NAME' =>
$db->f('ORG_NAVN')
- );
+ {
+ if($db->Type == "postgres")
+ {
+ return array(
+ 'UNIT_ID' =>
$db->f('org_enhet_id'),
+ 'UNIT_NAME' =>
$db->f('org_navn')
+ );
+ }
+ else
+ {
+ return array(
+ 'UNIT_ID' =>
$db->f('ORG_ENHET_ID'),
+ 'UNIT_NAME' =>
$db->f('ORG_NAVN')
+ );
+ }
}
}
return false;
}
-
-
-
+
+
+
public function result_unit_exist($result_unit, $level)
{
$this->log(__class__, __function__);
@@ -118,18 +132,32 @@
$sql = "SELECT $column FROM $table WHERE
V_ORG_ENHET.RESULTATENHET = $result_unit";
if($level) $sql = "$sql AND
V_ORG_ENHET.ORG_NIVAA = $level";
+ if($db->Type == "postgres")
+ {
+ $sql = strtolower($sql);
+ }
$db->query($sql,__LINE__,__FILE__);
if($db->next_record())
{
- return array(
- 'UNIT_ID' =>
$db->f('ORG_ENHET_ID'),
- 'UNIT_NAME' =>
$db->f('ORG_NAVN')
- );
+ if($db->Type == "postgres")
+ {
+ return array(
+ 'UNIT_ID' =>
$db->f('org_enhet_id'),
+ 'UNIT_NAME' =>
$db->f('org_navn')
+ );
+ }
+ else
+ {
+ return array(
+ 'UNIT_ID' =>
$db->f('ORG_ENHET_ID'),
+ 'UNIT_NAME' =>
$db->f('ORG_NAVN')
+ );
+ }
}
}
return false;
}
-
+
public function org_unit_exist($org_unit_id, $level)
{
$this->log(__class__, __function__);
@@ -145,40 +173,68 @@
$sql = "SELECT $column FROM $table WHERE
V_ORG_ENHET.ORG_ENHET_ID = $org_unit_id";
if($level) $sql = "$sql AND
V_ORG_ENHET.ORG_NIVAA = $level";
+
+ if($db->Type == "postgres")
+ {
+ $sql = strtolower($sql);
+ }
$db->query($sql,__LINE__,__FILE__);
if($db->next_record())
{
- return array(
- 'UNIT_ID' =>
$db->f('ORG_ENHET_ID'),
- 'UNIT_NAME' =>
$db->f('ORG_NAVN')
- );
+ if($db->Type == "postgres")
+ {
+ return array(
+ 'UNIT_ID' =>
$db->f('org_enhet_id'),
+ 'UNIT_NAME' =>
$db->f('org_navn')
+ );
+ }
+ else
+ {
+ return array(
+ 'UNIT_ID' =>
$db->f('ORG_ENHET_ID'),
+ 'UNIT_NAME' =>
$db->f('ORG_NAVN')
+ );
+ }
}
}
return false;
}
-
- public function get_result_unit($org_unit_id)
- {
+
+ public function get_result_unit($org_unit_id, $org_level = 4)
+ {
$this->log(__class__, __function__);
//Must traverse down u hierarchy
$columns = "V_ORG_ENHET.ORG_ENHET_ID,
V_ORG_ENHET.ORG_NIVAA, V_ORG_ENHET.ORG_NAVN, V_ORG_ENHET.ENHET_ID,
V_ORG_ENHET.RESULTATENHET";
$tables = "V_ORG_ENHET";
$joins = "LEFT JOIN V_ORG_KNYTNING ON
(V_ORG_KNYTNING.ORG_ENHET_ID = V_ORG_ENHET.ORG_ENHET_ID)";
- $sql = "SELECT $columns FROM $tables $joins WHERE
V_ORG_ENHET.ORG_NIVAA = 4 AND V_ORG_KNYTNING.ORG_ENHET_ID = {$org_unit_id}";
+ //$sql = "SELECT $columns FROM $tables $joins WHERE
V_ORG_KNYTNING.ORG_ENHET_ID = {$org_unit_id}";
+ $sql = "SELECT $columns FROM $tables $joins WHERE
V_ORG_ENHET.ORG_NIVAA = {$org_level} AND V_ORG_KNYTNING.ORG_ENHET_ID =
{$org_unit_id}";
if(!$db = $this->get_db())
{
return;
}
- $db->query($sql,__LINE__,__FILE__);
-
+ if($db->Type == "postgres")
+ {
+ $sql = strtolower($sql);
+ }
+
+ $db->query($sql,__LINE__,__FILE__);
+
if($db->next_record())
{
- $level = (int)$db->f('ORG_NIVAA');
- if($level == 4)
+ if($db->Type == "postgres")
{
return array(
+ "ORG_UNIT_ID" =>
(int)$db->f('org_enhet_id'),
+ "ORG_NAME" =>
$db->f('org_navn'),
+ "UNIT_ID" =>
$db->f('resultatenhet')
+ );
+ }
+ else
+ {
+ return array(
"ORG_UNIT_ID" =>
(int)$db->f('ORG_ENHET_ID'),
"ORG_NAME" =>
$db->f('ORG_NAVN'),
"UNIT_ID" =>
$db->f('RESULTATENHET')
@@ -186,8 +242,8 @@
}
}
}
-
-
+
+
public function get_all_org_units_autocomplete()
{
$query = strtoupper(phpgw::get_var('query'));
@@ -200,20 +256,35 @@
return;
}
+ if($db->Type == "postgres")
+ {
+ $sql = strtolower($sql);
+ }
+ $db->query($sql,__LINE__,__FILE__);
- $db->query($sql,__LINE__,__FILE__);
-
$result_units = array();
while($db->next_record())
{
- $result[] = array
+ if($db->Type == "postgres")
+ {
+ $result[] = array
+ (
+ 'id' =>
(int)$db->f('org_enhet_id'),
+ 'name' =>
$db->f('org_navn',true),
+ 'unit_id' =>
$db->f('resultatenhet')
+ );
+ }
+ else
+ {
+ $result[] = array
(
'id' =>
(int)$db->f('ORG_ENHET_ID'),
'name' =>
$db->f('ORG_NAVN',true),
'unit_id' =>
$db->f('RESULTATENHET')
);
+ }
}
-
+
return array('ResultSet'=> array('Result'=>$result));
}
@@ -225,15 +296,25 @@
{
return;
}
-
- $db->query($sql,__LINE__,__FILE__);
+ if($db->Type == "postgres")
+ {
+ $sql = strtolower($sql);
+ }
+ $db->query($sql,__LINE__,__FILE__);
$db->next_record();
- return $db->f('ORG_NAVN',true);
+ if($db->Type == "postgres")
+ {
+ return $db->f('org_navn',true);
+ }
+ else
+ {
+ return $db->f('ORG_NAVN',true);
+ }
}
public function get_result_units()
{
- $this->log(__class__, __function__);
+ $this->log(__class__, __function__);
$columns = "V_ORG_ENHET.ORG_ENHET_ID,
V_ORG_ENHET.ORG_NAVN, V_ORG_ENHET.RESULTATENHET";
$tables = "V_ORG_ENHET";
@@ -243,24 +324,39 @@
return;
}
- $db->query($sql,__LINE__,__FILE__);
-
+ if($db->Type == "postgres")
+ {
+ $sql = strtolower($sql);
+ }
+ $db->query($sql,__LINE__,__FILE__);
+
$result_units = array();
while($db->next_record())
{
- $result_units[] = array(
+ if($db->Type == "postgres")
+ {
+ $result_units[] = array(
+ "ORG_UNIT_ID" =>
(int)$db->f('org_enhet_id'),
+ "ORG_UNIT_NAME" =>
$db->f('org_navn'),
+ "UNIT_ID" =>
$db->f('resultatenhet')
+ );
+ }
+ else
+ {
+ $result_units[] = array(
"ORG_UNIT_ID" =>
(int)$db->f('ORG_ENHET_ID'),
"ORG_UNIT_NAME" =>
$db->f('ORG_NAVN'),
"UNIT_ID" =>
$db->f('RESULTATENHET')
);
+ }
}
-
+
return $result_units;
}
/**
* Get id/name for result unit
- *
+ *
* @return array values prepared for standardized select/filter
*/
public function get_result_units_wrapper()
@@ -282,12 +378,12 @@
/**
* Get id/name for org unit
* @param integer $level level in organization hierarchy
- *
+ *
* @return array values prepared for standardized select/filter
*/
public function get_org_units($level = 1)
{
- $this->log(__class__, __function__);
+ $this->log(__class__, __function__);
$level = (int) $level;
$columns = "V_ORG_ENHET.ORG_ENHET_ID,
V_ORG_ENHET.ORG_NAVN";
@@ -297,23 +393,39 @@
{
return;
}
- $db->query($sql,__LINE__,__FILE__);
-
+
+ if($db->Type == "postgres")
+ {
+ $sql = strtolower($sql);
+ }
+ $db->query($sql,__LINE__,__FILE__);
+
$values = array();
while($db->next_record())
{
- $values[] = array
- (
- 'id' => (int)$db->f('ORG_ENHET_ID'),
- 'name' => $db->f('ORG_NAVN'),
- );
+ if($db->Type == "postgres")
+ {
+ $values[] = array
+ (
+ 'id' =>
(int)$db->f('org_enhet_id'),
+ 'name' => $db->f('org_navn'),
+ );
+ }
+ else
+ {
+ $values[] = array
+ (
+ 'id' =>
(int)$db->f('ORG_ENHET_ID'),
+ 'name' => $db->f('ORG_NAVN'),
+ );
+ }
}
-
+
return $values;
}
-
- public function get_result_unit_with_leader($org_unit_id)
+
+ public function get_result_unit_with_leader($org_unit_id,
$org_level = 4)
{
$this->log(__class__, __function__);
@@ -321,20 +433,41 @@
$tables = "V_ORG_ENHET";
$joins = "LEFT JOIN V_ORG_PERSON_ENHET ON
(V_ORG_ENHET.ORG_ENHET_ID = V_ORG_PERSON_ENHET.ORG_ENHET_ID AND
V_ORG_PERSON_ENHET.prioritet = 1) ".
"LEFT JOIN V_ORG_PERSON ON
(V_ORG_PERSON.ORG_PERSON_ID = V_ORG_PERSON_ENHET.ORG_PERSON_ID)";
-
- $sql = "SELECT $columns FROM $tables $joins WHERE
V_ORG_ENHET.ORG_NIVAA = 4 AND V_ORG_ENHET.ORG_ENHET_ID = {$org_unit_id}";
+
+ $sql = "SELECT $columns FROM $tables $joins WHERE
V_ORG_ENHET.ORG_NIVAA = {$org_level} AND V_ORG_ENHET.ORG_ENHET_ID =
{$org_unit_id}";
+ //$sql = "SELECT $columns FROM $tables $joins WHERE
V_ORG_ENHET.ORG_ENHET_ID = {$org_unit_id}";
if(!$db = $this->get_db())
{
return;
}
+ if($db->Type == "postgres")
+ {
+ $sql = strtolower($sql);
+ }
+
$db->query($sql,__LINE__,__FILE__);
-
+
if($db->next_record())
{
-
- $full_name = $db->f('FORNAVN')."
".$db->f('ETTERNAVN');
-
+ if($db->Type == "postgres")
+ {
+ $full_name = $db->f('fornavn')."
".$db->f('etternavn');
+
+ return array(
+ "ORG_UNIT_ID" =>
(int)$db->f('org_enhet_id'),
+ "ORG_UNIT_NAME" =>
$db->f('org_navn'),
+ "ORG_EMAIL" =>
$db->f('epost'),
+ "LEADER_FIRSTNAME" =>
$db->f('fornavn'),
+ "LEADER_LASTNAME" =>
$db->f('etternavn'),
+ "LEADER_FULLNAME" =>
$full_name,
+ "LEADER_USERNAME" =>
$db->f('brukernavn')
+ );
+ }
+ else
+ {
+ $full_name = $db->f('FORNAVN')."
".$db->f('ETTERNAVN');
+
return array(
"ORG_UNIT_ID" =>
(int)$db->f('ORG_ENHET_ID'),
"ORG_UNIT_NAME" =>
$db->f('ORG_NAVN'),
@@ -344,9 +477,10 @@
"LEADER_FULLNAME" => $full_name,
"LEADER_USERNAME" =>
$db->f('BRUKERNAVN')
);
+ }
}
}
-
+
public function get_department_for_org_unit($org_unit_id)
{
$this->log(__class__, __function__);
@@ -354,33 +488,47 @@
$columns = "DEP_ORG_ENHET.ORG_ENHET_ID,
DEP_ORG_ENHET.ORG_NAVN";
$tables = "V_ORG_ENHET";
$joins = "LEFT JOIN V_ORG_KNYTNING ON
(V_ORG_ENHET.ORG_ENHET_ID = V_ORG_KNYTNING.ORG_ENHET_ID) " .
- "LEFT JOIN V_ORG_ENHET
DEP_ORG_ENHET ON (V_ORG_KNYTNING.ORG_ENHET_ID_KNYTNING =
DEP_ORG_ENHET.ORG_ENHET_ID) ";
-
+ "LEFT JOIN V_ORG_ENHET
DEP_ORG_ENHET ON (V_ORG_KNYTNING.ORG_ENHET_ID_KNYTNING =
DEP_ORG_ENHET.ORG_ENHET_ID) ";
+
$sql = "SELECT $columns FROM $tables $joins WHERE
V_ORG_ENHET.ORG_NIVAA = 4 AND V_ORG_ENHET.ORG_ENHET_ID = {$org_unit_id}";
-
+
if(!$db = $this->get_db())
{
return;
}
+ if($db->Type == "postgres")
+ {
+ $sql = strtolower($str);
+ }
+
$db->query($sql,__LINE__,__FILE__);
-
+
if($db->next_record())
{
-
- return array(
+ if($db->Type == "postgres")
+ {
+ return array(
+ "DEP_ORG_ID" =>
(int)$db->f('org_enhet_id'),
+ "DEP_ORG_NAME" =>
$db->f('org_navn')
+ );
+ }
+ else
+ {
+ return array(
"DEP_ORG_ID" =>
(int)$db->f('ORG_ENHET_ID'),
"DEP_ORG_NAME" =>
$db->f('ORG_NAVN')
);
+ }
}
}
-
-
+
+
public function get_result_units_with_leader($start_index,
$num_of_objects, $sort_field, $sort_ascending,$search_for, $search_type)
{
- $this->log(__class__, __function__);
+ $this->log(__class__, __function__);
- $columns = "V_ORG_ENHET.ORG_ENHET_ID,
V_ORG_ENHET.ORG_NAVN, V_ORG_PERSON.FORNAVN, V_ORG_PERSON.ETTERNAVN,
V_ORG_PERSON.BRUKERNAVN";
+ $columns = "V_ORG_ENHET.ORG_ENHET_ID,
V_ORG_ENHET.ORG_NIVAA, V_ORG_ENHET.ORG_NAVN, V_ORG_PERSON.FORNAVN,
V_ORG_PERSON.ETTERNAVN, V_ORG_PERSON.BRUKERNAVN";
$tables = "V_ORG_ENHET";
$joins = "LEFT JOIN V_ORG_PERSON_ENHET ON
(V_ORG_ENHET.ORG_ENHET_ID = V_ORG_PERSON_ENHET.ORG_ENHET_ID AND
V_ORG_PERSON_ENHET.prioritet = 1) ".
"LEFT JOIN V_ORG_PERSON ON
(V_ORG_PERSON.ORG_PERSON_ID = V_ORG_PERSON_ENHET.ORG_PERSON_ID)";
@@ -395,66 +543,127 @@
$count = 0;
$selector = "(";
foreach($search_words
as $search_word){
- $selector =
$selector." (upper(FORNAVN) LIKE '%$search_word%' OR ".
+ if($db->Type ==
"postgres")
+ {
+
$selector = $selector." (upper(fornavn) LIKE '%$search_word%' OR ".
+
"upper(etternavn) LIKE '%$search_word%' OR ".
+
"upper(brukernavn) LIKE '%$search_word%')";
+ }
+ else
+ {
+
$selector = $selector." (upper(FORNAVN) LIKE '%$search_word%' OR ".
"upper(ETTERNAVN) LIKE '%$search_word%' OR ".
"upper(BRUKERNAVN) LIKE '%$search_word%')";
+ }
if($count <
(count($search_words)-1)) $selector = $selector." OR ";
$count =
($count + 1);
}
$selector =
$selector.")";
-
+
break;
default:
- $selector =
"upper(ORG_NAVN) LIKE '%".$search_for."%'";
- break;
+ if($db->Type ==
"postgres")
+ {
+ $selector =
"upper(org_navn) LIKE '%".$search_for."%'";
+ }
+ else
+ {
+ $selector =
"upper(ORG_NAVN) LIKE '%".$search_for."%'";
+ }
+ break;
}
$sql = "$sql AND $selector";
}
-
+
$dir = $sort_ascending ? 'ASC' : 'DESC';
-
+
switch($sort_field){
case "ORG_UNIT_ID":
- $order_by = "ORDER BY
V_ORG_ENHET.ORG_ENHET_ID $dir";
+ if($db->Type == "postgres")
+ {
+ $order_by = "ORDER BY
V_ORG_ENHET.org_enhet_id $dir";
+ }
+ else
+ {
+ $order_by = "ORDER BY
V_ORG_ENHET.ORG_ENHET_ID $dir";
+ }
break;
case "ORG_UNIT_NAME":
- $order_by = "ORDER BY
V_ORG_ENHET.ORG_NAVN $dir";
+ if($db->Type == "postgres")
+ {
+ $order_by = "ORDER BY
V_ORG_ENHET.org_navn $dir";
+ }
+ else
+ {
+ $order_by = "ORDER BY
V_ORG_ENHET.ORG_NAVN $dir";
+ }
break;
case "LEADER_FULLNAME":
- $order_by = "ORDER BY
V_ORG_PERSON.FORNAVN $dir, V_ORG_PERSON.ETTERNAVN $dir";
+ if($db->Type == "postgres")
+ {
+ $order_by = "ORDER BY
V_ORG_PERSON.fornavn $dir, V_ORG_PERSON.etternavn $dir";
+ }
+ else
+ {
+ $order_by = "ORDER BY
V_ORG_PERSON.FORNAVN $dir, V_ORG_PERSON.ETTERNAVN $dir";
+ }
break;
default:
- $order_by = "ORDER BY
V_ORG_ENHET.ORG_ENHET_ID $dir";
+ if($db->Type == "postgres")
+ {
+ $order_by = "ORDER BY
V_ORG_ENHET.org_enhet_id $dir";
+ }
+ else
+ {
+ $order_by = "ORDER BY
V_ORG_ENHET.ORG_ENHET_ID $dir";
+ }
break;
}
$sql = "$sql $order_by";
-
-
+
+
if(!$db = $this->get_db())
{
return;
}
$db->limit_query($sql,$start_index,__LINE__,__FILE__,$num_of_objects);
-
+
$result_units = array();
while($db->next_record())
{
-
- $full_name = $db->f('FORNAVN')."
".$db->f('ETTERNAVN');
-
+ if($db->Type == "postgres")
+ {
+ $full_name = $db->f('fornavn')."
".$db->f('etternavn');
+
+ $result_units[] = array(
+ "ORG_UNIT_ID" =>
(int)$db->f('org_enhet_id'),
+ "ORG_UNIT_LEVEL" =>
(int)$db->f('org_nivaa'),
+ "ORG_UNIT_NAME" =>
$db->f('org_navn'),
+ "LEADER_FIRSTNAME" =>
$db->f('fornavn'),
+ "LEADER_LASTNAME" =>
$db->f('etternavn'),
+ "LEADER_FULLNAME" =>
$full_name,
+ "LEADER_USERNAME" =>
$db->f('brukernavn')
+ );
+ }
+ else
+ {
+ $full_name = $db->f('FORNAVN')."
".$db->f('ETTERNAVN');
+
$result_units[] = array(
"ORG_UNIT_ID" =>
(int)$db->f('ORG_ENHET_ID'),
+ "ORG_UNIT_LEVEL" =>
(int)$db->f('ORG_NIVAA'),
"ORG_UNIT_NAME" =>
$db->f('ORG_NAVN'),
"LEADER_FIRSTNAME" =>
$db->f('FORNAVN'),
"LEADER_LASTNAME" =>
$db->f('ETTERNAVN'),
"LEADER_FULLNAME" => $full_name,
"LEADER_USERNAME" =>
$db->f('BRUKERNAVN')
);
+ }
}
return $result_units;
}
-
+
public function get_result_units_count($search_for,
$search_type)
{
$this->log(__class__, __function__);
@@ -475,29 +684,45 @@
$selector = "(";
foreach($search_words
as $search_word)
{
- $selector =
$selector." (upper(FORNAVN) LIKE '%$search_word%' OR ".
+ if($db->Type ==
"postgres")
+ {
+
$selector = $selector." (upper(fornavn) LIKE '%$search_word%' OR ".
+
"upper(etternavn) LIKE '%$search_word%' OR ".
+
"upper(brukernavn) LIKE '%$search_word%')";
+ }
+ else
+ {
+
$selector = $selector." (upper(FORNAVN) LIKE '%$search_word%' OR ".
"upper(ETTERNAVN) LIKE '%$search_word%' OR ".
"upper(BRUKERNAVN) LIKE '%$search_word%')";
+ }
if($count <
(count($search_words)-1)) $selector = $selector." OR ";
$count =
($count + 1);
}
$selector =
$selector.")";
-
+
break;
default:
- $selector =
"upper(ORG_NAVN) LIKE '%".$search_for."%'";
- break;
+ if($db->Type ==
"postgres")
+ {
+ $selector =
"upper(org_navn) LIKE '%".$search_for."%'";
+ }
+ else
+ {
+ $selector =
"upper(ORG_NAVN) LIKE '%".$search_for."%'";
+ }
+ break;
}
$sql = "$sql AND $selector";
}
-
+
if(!$db = $this->get_db())
{
return;
}
$db->query($sql);
-
+
if($db->next_record())
{
return $db->f('COUNT');
@@ -519,7 +744,7 @@
));
unset($bt);
}
- }
+ }
public function is_connected()
{
Modified: trunk/rental/inc/class.soparty.inc.php
===================================================================
--- trunk/rental/inc/class.soparty.inc.php 2013-06-24 07:08:16 UTC (rev
11196)
+++ trunk/rental/inc/class.soparty.inc.php 2013-06-24 11:02:44 UTC (rev
11197)
@@ -16,6 +16,7 @@
const LOCATION_INTERNAL = '.RESPONSIBILITY.INTERNAL';
protected static $so;
+ protected $external_db = null;
/**
* Get a static reference to the storage object associated with this
model object
@@ -30,6 +31,54 @@
return self::$so;
}
+ /* our simple php ping function */
+ function ping($host)
+ {
+ exec(sprintf('ping -c 1 -W 5 %s',
escapeshellarg($host)), $res, $rval);
+ return $rval === 0;
+ }
+
+ public function get_external_db()
+ {
+ if($this->external_db && is_object($this->external_db))
+ {
+ return $this->external_db;
+ }
+
+ $config = CreateObject('phpgwapi.config','rental');
+ $config->read();
+
+ if(! $config->config_data['external_db_host'] ||
!$this->ping($config->config_data['external_db_host']))
+ {
+ $message ="Database server
{$config->config_data['external_db_host']} is not accessible";
+ phpgwapi_cache::message_set($message, 'error');
+ return false;
+ }
+
+ $db = createObject('phpgwapi.db', null, null, true);
+
+ $db->debug =
!!$config->config_data['external_db_debug'];
+ $db->Host = $config->config_data['external_db_host'];
+ $db->Port = $config->config_data['external_db_port'];
+ $db->Type = $config->config_data['external_db_type'];
+ $db->Database =
$config->config_data['external_db_name'];
+ $db->User = $config->config_data['external_db_user'];
+ $db->Password =
$config->config_data['external_db_password'];
+
+ try
+ {
+ $db->connect();
+ $connected = true;
+ }
+ catch(Exception $e)
+ {
+ $status = lang('unable_to_connect_to_database');
+ }
+
+ $this->external_db = $db;
+ return $db;
+ }
+
/**
* Generate SQL query
*
@@ -129,17 +178,17 @@
$filter_clauses[] = "contract.location_id =
{$party_type}";
}
}
-
+
if(isset($filters['active']))
{
if($filters['active'] == 'active')
{
$filter_clauses[] = "NOT party.is_inactive";
- }
+ }
else if($filters['active'] == 'inactive')
{
$filter_clauses[] = "party.is_inactive = TRUE";
- }
+ }
}
if(isset($filters['contract_id'])){
@@ -162,10 +211,19 @@
$org_unit_id =
$this->marshal($filters['org_unit_id'],'string');
if(isset($org_unit_id))
{
- $filter_clauses[] = "party.org_enhet_id =
{$org_unit_id}";
+ //check if org_unit is on top level
+ if($this->org_unit_is_top_level($org_unit_id)){
+ //get connected units on level 4
+ $org_unit_ids_tmp =
$this->get_org_unit_ids_from_top($org_unit_id);
+ $org_unit_ids =
implode(',',$org_unit_ids_tmp);
+ $filter_clauses[] = "party.org_enhet_id
IN ({$org_unit_ids})";
+ }
+ else{
+ $filter_clauses[] = "party.org_enhet_id
= {$org_unit_id}";
+ }
}
}
-
+
if(isset($filters['email'])){
$email = $this->marshal($filters['email'],'string');
if(isset($email))
@@ -177,7 +235,7 @@
if(isset($filters['sync']))
{
$filter_clauses[] = "NOT party.is_inactive";
-
+
if($filters['sync'] == 'sync_parties')
{
// involved in contract with service- and
responsibility identifiers
@@ -209,7 +267,7 @@
$filter_clauses[] = "party.result_unit_number
IS NULL";
}
}
-
+
if(count($filter_clauses))
{
$clauses[] = join(' AND ', $filter_clauses);
@@ -261,8 +319,42 @@
return "SELECT {$cols} FROM {$tables} {$joins} WHERE
{$condition} {$order}";
}
+ function org_unit_is_top_level($org_unit_id)
+ {
+ $q = "select * from V_ORG_ENHET where org_enhet_id=$org_unit_id
and org_nivaa < 4";
+ if(!$external_db = $this->get_external_db())
+ {
+ return;
+ }
+ $result = $this->external_db->query($q);
+ if($this->external_db->next_record()) {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ function get_org_unit_ids_from_top($org_unit_id){
+ $unit_ids = array();
+ $q="select * from v_org_knytning where
org_enhet_id_knytning=$org_unit_id";
+
+ if(!$external_db = $this->get_external_db())
+ {
+ return;
+ }
+ $result = $this->external_db->query($q);
+
+ while($this->external_db->next_record()){
+ $unit_id = $this->external_db->f('org_enhet_id');
+ $unit_ids[] = $unit_id;
+ }
+ return $unit_ids;
+ }
+
/**
* Function for adding a new party to the database. Updates the party
object.
*
@@ -296,19 +388,19 @@
function update($party)
{
$id = intval($party->get_id());
-
-
+
+
$location_id = $this->marshal($party->get_location_id(), 'int');
-
+
if($location_id)
{
$loc =
$GLOBALS['phpgw']->locations->get_name($location_id);
$name = $loc['location'];
$level_identifier =
result_unit::get_identifier_from_name($name);
}
-
+
$result_unit_number = $this->marshal($level_identifier,
'string');
-
+
$values = array(
'identifier = ' .
$this->marshal($party->get_identifier(), 'string'),
'first_name = ' .
$this->marshal($party->get_first_name(), 'string'),
@@ -334,9 +426,9 @@
'location_id = ' . $location_id,
'result_unit_number = ' . $result_unit_number
);
-
+
$result = $this->db->query('UPDATE rental_party SET ' .
join(',', $values) . " WHERE id=$id", __LINE__,__FILE__);
-
+
return isset($result);
}
@@ -399,14 +491,14 @@
}
return $party;
}
-
+
public function get_export_data()
{
$parties = rental_soparty::get_instance()->get(null, null,
null, null, null, null, null);
$exportable = new rental_agresso_cs15($parties);
return $exportable->get_contents();
}
-
+
public function get_number_of_parties()
{
$q ="SELECT COUNT(id) FROM rental_party";
@@ -415,7 +507,7 @@
$this->db->next_record();
return (int) $this->db->f('count',true);
}
-
+
public function has_contract($party_id)
{
$sql = "SELECT * FROM rental_contract_party WHERE
party_id={$party_id}";
@@ -429,7 +521,7 @@
return false;
}
}
-
+
public function delete_party($party_id)
{
if($party_id)
@@ -440,10 +532,10 @@
}
}
-
+
/**
* Check to see if this user is an administrator
- *
+ *
* @return true if private permission on root, false otherwise
*/
@@ -451,10 +543,10 @@
{
return
$GLOBALS['phpgw']->acl->check(self::LOCATION_ROOT,PHPGW_ACL_PRIVATE,'rental');
}
-
+
/**
* Check to see if the user is an executive officer
- *
+ *
* @return true if at least add permission on fields of
responsibilities (locations: .RESPONSIBIITY.*)
*/
protected function isExecutiveOfficer()
@@ -468,7 +560,7 @@
/**
* Synchronization job to update company name on contract parties which
are connected to Fellesdata.
- *
+ *
* Uses property org_enhet_id on party to link party with unit from
Fellesdata.
* To be run as a scheduled job
*/
@@ -477,7 +569,7 @@
$config = CreateObject('phpgwapi.config','rental');
$config->read();
- $use_fellesdata = $config->config_data['use_fellesdata'];
+ $use_fellesdata = $config->config_data['use_fellesdata'];
if(!$use_fellesdata){
return;
}
@@ -486,9 +578,9 @@
$parties = rental_soparty::get_instance()->get();
$result_count = rental_soparty::get_instance()->get_count();
$updated_parties;
-
+
$updated_parties[] = "Total number of parties: {$result_count}";
-
+
if(($this->isExecutiveOfficer() || $this->isAdministrator()))
{
$count = 0;
@@ -529,21 +621,21 @@
$this->log_sync_messages($updated_parties);
}
}
-
+
private function log_sync_messages($messages)
{
$msgs = array_merge(
array('---------------Messages-------------------'),
$messages
);
-
+
//use PHPGW tmp-catalog to store log-file
$path = $GLOBALS['phpgw_info']['server']['temp_dir'];
-
+
//Write to the log-file
$date_now = date('Y-m-d');
file_put_contents("{$path}/FD_name_sync_{$date_now}.log",
implode(PHP_EOL, $msgs));
}
-
+
}
Modified: trunk/rental/inc/class.uiresultunit.inc.php
===================================================================
--- trunk/rental/inc/class.uiresultunit.inc.php 2013-06-24 07:08:16 UTC (rev
11196)
+++ trunk/rental/inc/class.uiresultunit.inc.php 2013-06-24 11:02:44 UTC (rev
11197)
@@ -3,7 +3,7 @@
phpgw::import_class('rental.bofellesdata');
phpgw::import_class('frontend.bofrontend');
phpgw::import_class('frontend.bofellesdata');
-
+
class rental_uiresultunit extends rental_uicommon
{
public $public_functions = array
@@ -13,7 +13,7 @@
'query' => true,
'remove_delegate' => true
);
-
+
public function __construct()
{
parent::__construct();
@@ -21,7 +21,7 @@
self::set_active_menu('rental::resultunit');
$GLOBALS['phpgw_info']['flags']['app_header'] .=
'::'.lang('delegates');
}
-
+
public function query()
{
$config = CreateObject('phpgwapi.config','rental');
@@ -43,32 +43,32 @@
// Form variables
$search_for = phpgw::get_var('query');
$search_type = phpgw::get_var('search_option');
-
+
phpgwapi_cache::session_set('rental',
'resultunit_query', $search_for);
phpgwapi_cache::session_set('rental',
'resultunit_search_type', $search_type);
-
+
// Create an empty result set
$result_count = 0;
// get all result unit from fellesdata
$bofelles = rental_bofellesdata::get_instance();
$result_units =
$bofelles->get_result_units_with_leader($start_index,$num_of_objects,$sort_field,
$sort_ascending, $search_for, $search_type);
-
+
$result_count =
$bofelles->get_result_units_count($search_for, $search_type);
-
+
foreach($result_units as &$unit){
$unit['UNIT_NO_OF_DELEGATES'] =
count(frontend_bofrontend::get_delegates($unit['ORG_UNIT_ID']));
}
-
+
$resultunit_data = array('results' => $result_units,
'total_records' => $result_count);
-
+
$editable = phpgw::get_var('editable') == 'true' ? true
: false;
-
+
array_walk($resultunit_data['results'], array($this,
'add_actions'));
-
+
return $this->yui_results($resultunit_data,
'total_records', 'results');
}
-
+
/**
* View a list of all resultunits
*/
@@ -81,18 +81,18 @@
}
$this->render('resultunit_list.php');
}
-
-
+
+
public function add_actions(&$value)
{
if(($this->isExecutiveOfficer() ||
$this->isAdministrator()))
{
$value['ajax'][] = false;
- $value['actions'][] =
html_entity_decode(self::link(array('menuaction' => 'rental.uiresultunit.edit',
'id' => $value['ORG_UNIT_ID'])));
+ $value['actions'][] =
html_entity_decode(self::link(array('menuaction' => 'rental.uiresultunit.edit',
'id' => $value['ORG_UNIT_ID'], 'level' => $value['ORG_UNIT_LEVEL'])));
$value['labels'][] = lang('edit');
}
}
-
+
public function edit()
{
$GLOBALS['phpgw_info']['flags']['app_header'] .=
'::'.lang('edit');
@@ -101,12 +101,13 @@
$use_fellesdata =
$config->config_data['use_fellesdata'];
$unit_id = (int)phpgw::get_var('id');
-
+ $unit_level = (int)phpgw::get_var('level');
+
if (isset($unit_id) && $unit_id > 0 && $use_fellesdata)
{
-
+
$msglog['error']['msg'] =
phpgw::get_var('error');
$msglog['message']['msg'] =
phpgw::get_var('message');
-
+
if(isset($_POST['search']))
{
$username = phpgw::get_var('username');
@@ -140,12 +141,14 @@
else if(isset($_POST['add']))
{
$account_id =
phpgw::get_var('account_id');
-
-
+ //var_dump($account_id);
+
$bofelles =
rental_bofellesdata::get_instance();
- $unit =
$bofelles->get_result_unit($unit_id);
+ $unit =
$bofelles->get_result_unit($unit_id, $unit_level);
+ //var_dump($unit);
if($account_id){
$res =
$this->add_delegate($account_id,$unit['ORG_UNIT_ID'],$unit['ORG_NAME']);
+ //var_dump($res);
if(!$res)
{
$msglog['error']['msg']
= lang('delegation_error');
@@ -156,26 +159,26 @@
}
}
else{
- $msglog['error']['msg'] =
lang('unknown_user');
+ $msglog['error']['msg'] =
lang('unknown_user');
}
}
-
+
$bofelles = rental_bofellesdata::get_instance();
- $unit =
$bofelles->get_result_unit_with_leader($unit_id);
-
+ $unit =
$bofelles->get_result_unit_with_leader($unit_id, $unit_level);
+
$delegates_per_org_unit =
frontend_bofrontend::get_delegates($unit_id);
$unit['UNIT_NO_OF_DELEGATES'] =
count($delegates_per_org_unit);
-
- $form_action =
$GLOBALS['phpgw']->link('/index.php',array('menuaction' =>
'rental.uiresultunit.edit', 'id' => $unit_id));
-
- $this->render('resultunit.php', array ('unit'
=> $unit,
+
+ $form_action =
$GLOBALS['phpgw']->link('/index.php',array('menuaction' =>
'rental.uiresultunit.edit', 'id' => $unit_id, 'level' => $unit_level));
+
+ $this->render('resultunit.php', array ('unit'
=> $unit,
'form_action' => $form_action,
'search_result' => isset($search_result) ?
$search_result : array(),
'msglog' => $msglog,
'cancel_link' => self::link(array('menuaction'
=> 'rental.uiresultunit.index', 'populate_form' => 'yes'))));
}
}
-
+
public function add_delegate(int $account_id, $org_unit_id,
$org_name)
{
$config = CreateObject('phpgwapi.config','rental');
@@ -184,18 +187,18 @@
if(!isset($account_id) || $account_id == '' &&
$use_fellesdata)
{
//User is only registered in Fellesdata
- $username = phpgw::get_var('username');
- $firstname = phpgw::get_var('firstname');
- $lastname = phpgw::get_var('lastname');
+ $username = phpgw::get_var('username');
+ $firstname = phpgw::get_var('firstname');
+ $lastname = phpgw::get_var('lastname');
$password = 'TEst1234';
-
+
$account_id =
frontend_bofrontend::create_delegate_account($username, $firstname, $lastname,
$password);
-
+
if(isset($account_id) &&
!is_numeric($account_id))
{
return false;
}
- }
+ }
$success =
frontend_bofrontend::add_delegate($account_id, null, $org_unit_id, $org_name);
if($success)
@@ -212,34 +215,34 @@
{
$fellesdata_user =
frontend_bofellesdata::get_instance()->get_user($user_name);
$fellesdata_owner =
frontend_bofellesdata::get_instance()->get_user($owner_name);
-
+
if($fellesdata_user &&
$fellesdata_owner)
- {
+ {
//Send email notification to
delegate
$email =
$fellesdata_user['email'];
if(isset($email) && $email !=
'')
{
-
+
$title =
lang('email_add_delegate_title');
$message =
lang('email_add_delegate_message',$fellesdata_user['firstname'],$fellesdata_user['lastname'],$fellesdata_owner['firstname'],$fellesdata_owner['lastname'],$org_name_string);
frontend_bofrontend::send_system_message($email,$title,$message);
- return true;
+ return true;
}
}
}
- }
+ }
return false;
}
-
+
public function remove_delegate()
{
- $unit_id = phpgw::get_var('id');
- $account_id = phpgw::get_var('account_id');
-
+ $unit_id = phpgw::get_var('id');
+ $account_id = phpgw::get_var('account_id');
+
$result =
frontend_bofrontend::remove_delegate($account_id,null,$unit_id);
-
+
$args = array('menuaction' =>
'rental.uiresultunit.edit', 'id' => $unit_id);
-
+
if($result){
$args['message'] = lang('delegate_removed');
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [11197] Added logic for delegating on all organization-levels,
Erik Holm-Larsen <=