fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [6559] Property: More on roles


From: Sigurd Nes
Subject: [Fmsystem-commits] [6559] Property: More on roles
Date: Tue, 09 Nov 2010 14:13:24 +0000

Revision: 6559
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=6559
Author:   sigurdne
Date:     2010-11-09 14:13:23 +0000 (Tue, 09 Nov 2010)
Log Message:
-----------
Property: More on roles

Modified Paths:
--------------
    trunk/property/inc/class.bolocation.inc.php
    trunk/property/inc/class.boresponsible.inc.php
    trunk/property/inc/class.socategory.inc.php
    trunk/property/inc/class.soresponsible.inc.php
    trunk/property/inc/class.uilocation.inc.php
    trunk/property/js/yahoo/location.responsiblility_role.js
    trunk/property/setup/setup.inc.php
    trunk/property/setup/tables_current.inc.php
    trunk/property/setup/tables_update.inc.php

Modified: trunk/property/inc/class.bolocation.inc.php
===================================================================
--- trunk/property/inc/class.bolocation.inc.php 2010-11-09 12:40:48 UTC (rev 
6558)
+++ trunk/property/inc/class.bolocation.inc.php 2010-11-09 14:13:23 UTC (rev 
6559)
@@ -662,11 +662,52 @@
 
                function get_responsible($data = array())
                {
+                       $soresponsible          = 
CreateObject('property.soresponsible');
+                       $contacts = createObject('phpgwapi.contacts');
+
                        $locations = $this->read($data);
                        foreach ($locations as & $location)
                        {
-                               
+                               $responsible_item = 
$soresponsible->get_active_responsible_at_location($location['location_code'], 
$data['role_id']);
+                               $location['responsible_item'] = 
$responsible_item['id'];
+                               $location['responsible_contact'] = 
$contacts->get_name_of_person_id($responsible_item['contact_id']);
+                               $location['responsible_contact_id'] = 
$responsible_item['contact_id'];
                        }
+
+                       $this->uicols['name'][]                 = 
'responsible_contact';
+                       $this->uicols['descr'][]                = 
lang('responsible');
+                       $this->uicols['sortable'][]             = false;
+                       $this->uicols['sort_field'][]   = '';
+                       $this->uicols['format'][]               = '';
+                       $this->uicols['formatter'][]    = '';
+                       $this->uicols['input_type'][]   = '';
+
+                       $this->uicols['name'][]                 = 
'responsible_contact_id';
+                       $this->uicols['descr'][]                = 'dummy';
+                       $this->uicols['sortable'][]             = false;
+                       $this->uicols['sort_field'][]   = '';
+                       $this->uicols['format'][]               = '';
+                       $this->uicols['formatter'][]    = '';
+                       $this->uicols['input_type'][]   = 'hidden';
+
+                       $this->uicols['name'][]                 = 
'responsible_item';
+                       $this->uicols['descr'][]                = 'dummy';
+                       $this->uicols['sortable'][]             = false;
+                       $this->uicols['sort_field'][]   = '';
+                       $this->uicols['format'][]               = '';
+                       $this->uicols['formatter'][]    = '';
+                       $this->uicols['input_type'][]   = 'hidden';
+
+                       $this->uicols['name'][]                 = 'select';
+                       $this->uicols['descr'][]                = 
lang('select');
+                       $this->uicols['sortable'][]             = false;
+                       $this->uicols['sort_field'][]   = '';
+                       $this->uicols['format'][]               = '';
+                       $this->uicols['formatter'][]    = 'myFormatterCheck';
+                       $this->uicols['input_type'][]   = '';
+
+//_debug_array($locations);
+
                        return $locations;
                }
 

Modified: trunk/property/inc/class.boresponsible.inc.php
===================================================================
--- trunk/property/inc/class.boresponsible.inc.php      2010-11-09 12:40:48 UTC 
(rev 6558)
+++ trunk/property/inc/class.boresponsible.inc.php      2010-11-09 14:13:23 UTC 
(rev 6559)
@@ -204,7 +204,7 @@
                        $responsibilities = array();
                        foreach($values as  $value)
                        {
-                               $responsibilities = array
+                               $responsibilities[] = array
                                (
                                        'id'            => $value['id'],
                                        'name'          => $value['name'],
@@ -289,20 +289,79 @@
 
                public function update_role_assignment($values)
                {
+                       if(!isset($values['assign']))
+                       {
+                               $values['assign'] = array();
+                       }
+                       $to_expire = array();
+                       $to_edit = array();
+                       $dont_add = array();
+                       if( isset($values['assign_orig']) && 
is_array($values['assign_orig']) )
+                       {
+                               foreach( $values['assign_orig'] as $assign_orig 
=> $location_code )
+                               {
+                                       $assign_arr                     = 
explode('_', $assign_orig);
+                                       $contact_id                     = 
$assign_arr[0];
+                                       $responsible_item       = 
$assign_arr[1];
+                                       $dont_add[]             = 
$location_code;                               
+       
+                                       if( !in_array($location_code, 
$values['assign']) )
+                                       {
+                                               $to_expire[] = 
$responsible_item;
+                                       }
+
+                                       if( in_array($location_code, 
$values['assign']) &&  $values['contact_id'] && !$values['contact_id'] == 
$contact_id )
+                                       {
+                                               $to_edit[] = array
+                                               (
+                                                       'id'                    
        => $responsible_item,
+                                                       'active_from'           
=> time(),
+                                                       'contact_id'            
=> $values['contact_id'],
+                                                       'location_code'         
=> $location_code,
+                                                       'responsibility_id'     
=> $values['responsibility_id'],
+                                                       'remark'                
        => 'from role assignment'
+                                               );
+                                       }
+                               }
+                       }
+
                        foreach ($values['assign'] as $location_code)
                        {
+                               if(in_array($location_code, $dont_add))
+                               {
+                                       continue;
+                               }
+
+                               if(!$values['contact_id'])
+                               {
+                                       $receipt['error'][] = array('msg'=> 
lang('missing contact'));
+                                       return $receipt;
+                               }
+
                                $data = array
                                (
                                        'location'                      => 
explode('-', $location_code),
                                        'active_from'           => time(),
                                        'responsibility_id'     => 
$values['responsibility_id'],
                                        'contact_id'            => 
$values['contact_id'],
-                                       'ecodimb'                       => '',
                                        'remark'                        => 
'from role assignment'
                                );
 
+//_debug_array($data);
                                $this->so->add_contact($data);
                        }
+
+                       foreach ( $to_edit as $edit_data)
+                       {
+                               $receipt = $this->so->edit_contact($edit_data); 
                
+                       }
+
+                       foreach ( $to_expire as $expire_id)
+                       {
+                               $this->so->expire_contact($expire_id);
+                       }
+
+                       return $receipt;
                }
                /**
                * Save responsibility contact

Modified: trunk/property/inc/class.socategory.inc.php
===================================================================
--- trunk/property/inc/class.socategory.inc.php 2010-11-09 12:40:48 UTC (rev 
6558)
+++ trunk/property/inc/class.socategory.inc.php 2010-11-09 14:13:23 UTC (rev 
6559)
@@ -1115,14 +1115,14 @@
                                                        ),
                                                        array
                                                        (
-                                                               'name'          
        => 'responsibility',
+                                                               'name'          
        => 'responsibility_id',
                                                                'descr'         
        => lang('responsibility'),
                                                                'type'          
        => 'select',
                                                                'values_def'    
=> array
                                                                (
                                                                        
'valueset'              => false,
                                                                        
'method'                => 'property.boresponsible.get_responsibilities',
-                                                                       
'method_input'  => array('acl_app' => 'property',       'selected' => 
'##responsibility##')
+                                                                       
'method_input'  => array('acl_app' => 'property',       'selected' => 
'##responsibility_id##')
                                                                )
                                                        )
                                                ),

Modified: trunk/property/inc/class.soresponsible.inc.php
===================================================================
--- trunk/property/inc/class.soresponsible.inc.php      2010-11-09 12:40:48 UTC 
(rev 6558)
+++ trunk/property/inc/class.soresponsible.inc.php      2010-11-09 14:13:23 UTC 
(rev 6559)
@@ -379,8 +379,8 @@
                                (int) $values['responsibility_id'],
                                (int) $values['contact_id'],
                                @implode('-', $values['location']),
-                               $values['active_from'],
-                               $values['active_to'],
+                               (int) $values['active_from'],
+                               (int) $values['active_to'],
                                isset($values['extra']['p_num']) ? 
$values['extra']['p_num'] : '',
                                isset($values['extra']['p_entity_id']) ? 
$values['extra']['p_entity_id'] : '',
                                isset($values['extra']['p_cat_id']) ? 
$values['extra']['p_cat_id'] : '',
@@ -426,6 +426,7 @@
                        $orig = $this->read_single_contact($values['id']);
 
                        if(isset($values['location']) &&(@implode('-', 
$values['location']) != $orig['location_code'])
+                               || $values['contact_id'] != $orig['contact_id']
                                || $values['active_from'] != 
$orig['active_from']
                                || $values['active_to'] != $orig['active_to']
                                || $values['extra']['p_num'] != $orig['p_num']
@@ -527,7 +528,61 @@
                        $this->db->query('DELETE FROM fm_responsibility_contact 
WHERE id='  . (int) $id, __LINE__, __FILE__);
                }
 
+
                /**
+               * Deactivate a responsibility type contact - leaving the 
information as history
+               *
+               * @param integer $id ID of responsibility type
+               *
+               * @return void
+               */
+
+               function expire_contact($id)
+               {
+                       $value_set['expired_by']        = $this->account;
+                       $value_set['expired_on']        = time();
+                       $value_set      = 
$this->db->validate_update($value_set);
+                       $this->db->transaction_begin();
+                       $this->db->query("UPDATE fm_responsibility_contact set 
$value_set WHERE id = " . (int) $id, __LINE__, __FILE__);
+                       $this->db->transaction_commit();
+               }
+
+               /**
+               * Get the contact and relation id for a particular role at a 
given location
+               *
+               * @param array $location_code location_code
+               * @param array $role_id  role_id
+               *
+               * @return array
+               */
+
+               public function 
get_active_responsible_at_location($location_code, $role_id)
+               {
+                       $role_id = (int)$role_id;
+                       $time = time() +1;
+                       
+                       $sql = "SELECT fm_responsibility_contact.id, contact_id 
FROM fm_responsibility_contact"
+                        . " $this->join fm_responsibility ON 
fm_responsibility_contact.responsibility_id = fm_responsibility.id"
+                        . " $this->join fm_responsibility_role ON 
fm_responsibility.id = fm_responsibility_role.responsibility_id"
+                        . " WHERE fm_responsibility_role.id ={$role_id}"
+                        . " AND fm_responsibility_contact.location_code 
='{$location_code}'"
+                        . " AND active_from < {$time} AND (active_to > {$time} 
OR active_to = 0) AND expired_on IS NULL";
+               
+                       $values = array();
+                       $this->db->query($sql, __LINE__, __FILE__);
+
+                       if($this->db->next_record())
+                       {
+                               $values = array
+                               (
+                                       'id'                    =>  
$this->db->f('id'),
+                                       'contact_id'    => 
$this->db->f('contact_id')
+                               );
+                       }
+                       return $values;
+
+               }
+               /**
                * Get the responsibility for a particular category conserning a 
given location or item
                * Locations are checked bottom up at the deepest level - before 
checkin on it's parent if it is a miss.
                *

Modified: trunk/property/inc/class.uilocation.inc.php
===================================================================
--- trunk/property/inc/class.uilocation.inc.php 2010-11-09 12:40:48 UTC (rev 
6558)
+++ trunk/property/inc/class.uilocation.inc.php 2010-11-09 14:13:23 UTC (rev 
6559)
@@ -865,6 +865,7 @@
                                $datatable['pagination']['records_returned']= 
count($location_list);
 
 
+
                        }
 
                        $datatable['pagination']['records_total']       = 
$this->bo->total_records;
@@ -1037,7 +1038,7 @@
                        }
 
                        $values = phpgw::get_var('values');
-
+                       $role_id = phpgw::get_var('role_id', 'int');
                        $receipt = array();
                $_role = CreateObject('property.socategory');
                        $_role->get_location_info('responsibility_role','');
@@ -1045,30 +1046,20 @@
                        if($values && $this->acl_edit)
                        {
                                $user_id = phpgw::get_var('user_id', 'int');
-                               $role_id = phpgw::get_var('role_id', 'int');
                                $account = 
$GLOBALS['phpgw']->accounts->get($user_id);
                                $contact_id = $account->person_id;
-
-                               if(!$contact_id)
+                               if(!$role_id)
                                {
-                                       $receipt['message'][] = array('msg'=> 
lang('missing contact'));                         
+                                       $receipt['error'][] = array('msg'=> 
lang('missing role'));                              
                                }
-                               else if(!$role_id)
-                               {
-                                       $receipt['message'][] = array('msg'=> 
lang('missing role'));                            
-                               }
                                else
                                {
                                        $role = 
$_role->read_single($data=array('id' => $role_id));
                                        $values['contact_id']                   
= $contact_id;
-                                       $values['responsibility_id']    = 
$role['responsibility'];
+                                       $values['responsibility_id']    = 
$role['responsibility_id'];
 
                                        $boresponsible = 
CreateObject('property.boresponsible');
                                        $receipt = 
$boresponsible->update_role_assignment($values);
-                                       foreach($values['assign'] as $_assign 
=> $_location_code)
-                                       {
-                                               $receipt['message'][] = 
array('msg'=>"{$_assign} => {$_location_code}");
-                                       }
                                }
                        }
 
@@ -1123,7 +1114,8 @@
                                                                                
."block_query:'{$block_query}'";
 
 
-                               $values_combo_box[0]  = 
execMethod('property.soadmin_location.read',array());
+                               //$values_combo_box[0]  = 
execMethod('property.soadmin_location.read',array());
+                               $values_combo_box[0]  = 
array(array('id'=>'1','name'=> 'Eiendom'));
 
                                $values_combo_box[1]  = 
$this->bocommon->select_category_list(array('format'=>'filter',
                                                                                
'selected' => $this->cat_id,
@@ -1148,8 +1140,7 @@
                                $default_value = 
array('id'=>'','name'=>lang('no user'));
                                array_unshift 
($values_combo_box[4],$default_value);
 
-
-
+/*
                        $_role_criteria = array
                        (
                                'allrows'       => true,
@@ -1170,10 +1161,21 @@
                                                 );
                                        }
                                }
-                       
+
                                $default_value = array 
('id'=>'','name'=>lang('no role'));
                                array_unshift 
($values_combo_box[5],$default_value);
+*/
+                       $_role_criteria = array
+                       (
+                               'type'          => 'responsibility_role',
+                               'filter'        => array('location' => 
".location.{$type_id}"),
+                               'order'         => 'name'
+                       );
 
+                       $values_combo_box[5] =   
execMethod('property.socategory.get_list',$_role_criteria);
+                               $default_value = array 
('id'=>'','name'=>lang('no role'));
+                               array_unshift 
($values_combo_box[5],$default_value);
+
                                $datatable['actions']['form'] = array(
                                        array(
                                                'action'        => 
$GLOBALS['phpgw']->link('/index.php',
@@ -1298,18 +1300,10 @@
 
                        $location_list = array();
 
-                       $location_list = 
$this->bo->get_responsible(array('type_id'=>$type_id,'lookup_tenant'=>$lookup_tenant,'lookup'=>$lookup,'allrows'=>$this->allrows,'dry_run'
 =>$dry_run));
+                       $location_list = 
$this->bo->get_responsible(array('role_id' =>$role_id, 
'type_id'=>$type_id,'lookup_tenant'=>$lookup_tenant,'lookup'=>$lookup,'allrows'=>$this->allrows,'dry_run'
 =>$dry_run));
 
                        $uicols = $this->bo->uicols;
 
-                       $uicols['name'][]               = 'select';
-                       $uicols['descr'][]              = lang('select');
-                       $uicols['sortable'][]   = false;
-                       $uicols['sort_field'][] = '';
-                       $uicols['format'][]             = '';
-                       $uicols['formatter'][]  = 'myFormatterCheck';
-                       $uicols['input_type'][] = '';
-
                        $content = array();
                        $j=0;
                        if (isset($location_list) && is_array($location_list))

Modified: trunk/property/js/yahoo/location.responsiblility_role.js
===================================================================
--- trunk/property/js/yahoo/location.responsiblility_role.js    2010-11-09 
12:40:48 UTC (rev 6558)
+++ trunk/property/js/yahoo/location.responsiblility_role.js    2010-11-09 
14:13:23 UTC (rev 6559)
@@ -180,16 +180,13 @@
        {
                var checked = '';
                var hidden = '';
-               if(!oRecord.getData('exception'))
+               if(oRecord.getData('responsible_item'))
                {
-                       if(oRecord.getData('responsibility_id'))
-                       {
-                               checked = "checked = 'checked'";
-                               hidden = "<input type=\"hidden\" 
class=\"orig_check\"  
name=\"values[assign_orig]["+oRecord.getData('responsibility_id')+"_"+oRecord.getData('location_code')+"]\"
 value=\""+oRecord.getData('location_code')+"\"/>";
-                       }
-                       
-                       elCell.innerHTML = hidden + "<center><input 
type=\"checkbox\" "+checked+" class=\"mychecks\"  name=\"values[assign][]\" 
value=\""+oRecord.getData('location_code')+"\"/></center>";
+                       checked = "checked = 'checked'";
+                       hidden = "<input type=\"hidden\" class=\"orig_check\"  
name=\"values[assign_orig]["+oRecord.getData('responsible_contact_id')+"_"+oRecord.getData('responsible_item')+"]\"
 value=\""+oRecord.getData('location_code')+"\"/>";
                }
+                       
+               elCell.innerHTML = hidden + "<center><input type=\"checkbox\" 
"+checked+" class=\"mychecks\"  name=\"values[assign][]\" 
value=\""+oRecord.getData('location_code')+"\"/></center>";
        }
 
        var FormatterCenter = function(elCell, oRecord, oColumn, oData)

Modified: trunk/property/setup/setup.inc.php
===================================================================
--- trunk/property/setup/setup.inc.php  2010-11-09 12:40:48 UTC (rev 6558)
+++ trunk/property/setup/setup.inc.php  2010-11-09 14:13:23 UTC (rev 6559)
@@ -12,7 +12,7 @@
        */
 
        $setup_info['property']['name']                 = 'property';
-       $setup_info['property']['version']              = '0.9.17.597';
+       $setup_info['property']['version']              = '0.9.17.598';
        $setup_info['property']['app_order']    = 8;
        $setup_info['property']['enable']               = 1;
        $setup_info['property']['app_group']    = 'office';

Modified: trunk/property/setup/tables_current.inc.php
===================================================================
--- trunk/property/setup/tables_current.inc.php 2010-11-09 12:40:48 UTC (rev 
6558)
+++ trunk/property/setup/tables_current.inc.php 2010-11-09 14:13:23 UTC (rev 
6559)
@@ -2122,13 +2122,13 @@
                                'name' => array('type' => 'varchar', 
'precision' => 200,'nullable' => False),
                                'remark' => array('type' => 'text','nullable' 
=> True),
                                'location' => array('type' => 'varchar', 
'precision' => 200,'nullable' => False),
-                               'responsibility' => array('type' => 'int', 
'precision' => 4,'nullable' => True),
+                               'responsibility_id' => array('type' => 'int', 
'precision' => 4,'nullable' => True),
                                'user_id' => array('type' => 'int', 'precision' 
=> 4,'nullable' => True),
                                'entry_date' => array('type' => 'int', 
'precision' => 4,'nullable' => True),
                                'modified_date' => array('type' => 'int', 
'precision' => 4,'nullable' => True),
                        ),
                        'pk' => array('id'),
-                       'fk' => array('fm_responsibility' => 
array('responsibility' => 'id')),
+                       'fk' => array('fm_responsibility' => 
array('responsibility_id' => 'id')),
                        'ix' => array(),
                        'uc' => array()
                ),

Modified: trunk/property/setup/tables_update.inc.php
===================================================================
--- trunk/property/setup/tables_update.inc.php  2010-11-09 12:40:48 UTC (rev 
6558)
+++ trunk/property/setup/tables_update.inc.php  2010-11-09 14:13:23 UTC (rev 
6559)
@@ -4645,3 +4645,22 @@
                }
        }
 
+       /**
+       * Update property version from 0.9.17.597 to 0.9.17.598
+       * Rename column
+       * 
+       */
+
+       $test[] = '0.9.17.597';
+       function property_upgrade0_9_17_597()
+       {
+               $GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
+
+               
$GLOBALS['phpgw_setup']->oProc->RenameColumn('fm_responsibility_role','responsibility','responsibility_id');
+
+               if($GLOBALS['phpgw_setup']->oProc->m_odb->transaction_commit())
+               {
+                       $GLOBALS['setup_info']['property']['currentver'] = 
'0.9.17.598';
+                       return $GLOBALS['setup_info']['property']['currentver'];
+               }
+       }




reply via email to

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