fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [11206] property: more on condition survey


From: Sigurd Nes
Subject: [Fmsystem-commits] [11206] property: more on condition survey
Date: Wed, 26 Jun 2013 12:21:22 +0000

Revision: 11206
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11206
Author:   sigurdne
Date:     2013-06-26 12:21:20 +0000 (Wed, 26 Jun 2013)
Log Message:
-----------
property: more on condition survey

Modified Paths:
--------------
    trunk/property/inc/class.bocondition_survey.inc.php
    trunk/property/inc/class.custom_fields.inc.php
    trunk/property/inc/class.socommon_core.inc.php
    trunk/property/inc/class.socondition_survey.inc.php
    trunk/property/inc/class.sorequest.inc.php
    trunk/property/inc/class.uicondition_survey.inc.php

Modified: trunk/property/inc/class.bocondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.bocondition_survey.inc.php 2013-06-25 12:55:54 UTC 
(rev 11205)
+++ trunk/property/inc/class.bocondition_survey.inc.php 2013-06-26 12:21:20 UTC 
(rev 11206)
@@ -385,4 +385,20 @@
                                }
                        }
                }
+
+               public function delete_imported_records($id)
+               {
+                       try
+                       {
+                               $this->so->delete_imported_records($id);
+                       }
+
+                       catch(Exception $e)
+                       {
+                               if ( $e )
+                               {
+                                       throw $e;                               
+                               }
+                       }
+               }
        }

Modified: trunk/property/inc/class.custom_fields.inc.php
===================================================================
--- trunk/property/inc/class.custom_fields.inc.php      2013-06-25 12:55:54 UTC 
(rev 11205)
+++ trunk/property/inc/class.custom_fields.inc.php      2013-06-26 12:21:20 UTC 
(rev 11206)
@@ -51,7 +51,7 @@
                public function __construct($appname = null)
                {
                        parent::__construct($appname);
-                       $this->_db2 = clone($this->_db);                        
+                       $this->_db2 = clone($this->_db);
                        $this->contacts = CreateObject('phpgwapi.contacts');
                }
 
@@ -129,7 +129,7 @@
                                                                var 
attribute_{$i}_min = document.getElementById('values_attribute_{$i}_min');
                                                                
attribute_{$i}_date.value = '';
                                                                
attribute_{$i}_hour.value = '';
-                                                               
attribute_{$i}_min.value = '';                                                  
        
+                                                               
attribute_{$i}_min.value = '';
                                                        }
 JS;
                                                        $m++;
@@ -256,7 +256,7 @@
                                        foreach ($attributes['choice'] as 
&$_choice)
                                        {
                                                $_choice['selected'] = 
$_choice['id'] == $attributes['value'] ? 1 : 0;
-                                       }                                       
+                                       }
                                }
                                else if($attributes['datatype'] == 'custom2') 
//lookup
                                {
@@ -412,8 +412,8 @@
                                        $lookup_functions[$m]['action'] = "var 
oArgs = {menuaction:'{$this->_appname}.uievent.edit',"
                                                ."location:'{$location}',"
                                                
."attrib_id:'{$attributes['id']}'";
-                                       $lookup_functions[$m]['action'] .=      
isset($attributes['item_id']) && $attributes['item_id'] ? 
",item_id:{$attributes['item_id']}" : '';             
-                                       $lookup_functions[$m]['action'] .=      
isset($attributes['value']) && $attributes['value'] ? 
",id:{$attributes['value']}" : '';                
+                                       $lookup_functions[$m]['action'] .=      
isset($attributes['item_id']) && $attributes['item_id'] ? 
",item_id:{$attributes['item_id']}" : '';
+                                       $lookup_functions[$m]['action'] .=      
isset($attributes['value']) && $attributes['value'] ? 
",id:{$attributes['value']}" : '';
                                        $lookup_functions[$m]['action'] .= 
"};\n";
                                        $lookup_functions[$m]['action'] .= 
"if(document.form.{$attributes['name']}.value)\n";
                                        $lookup_functions[$m]['action'] .= 
"{\n";
@@ -488,40 +488,85 @@
 
 
                function prepare_for_db($table, $values_attribute, $id = 0)
-               {       
+               {
                        $id = (int)$id;
                        $data = array();
-                       if (isset($values_attribute) AND 
is_array($values_attribute))
+                       if (isset($values_attribute) && 
is_array($values_attribute))
                        {
                                foreach($values_attribute as $entry)
                                {
-                                       if($entry['datatype']!='AB' && 
$entry['datatype']!='ABO' && $entry['datatype']!='VENDOR' && 
$entry['datatype']!='event')
+                                       switch ($entry['datatype'])
                                        {
-                                               if($entry['datatype'] == 'C' || 
$entry['datatype'] == 'T' || $entry['datatype'] == 'V' || $entry['datatype'] == 
'link')
-                                               {
-                                                       $entry['value'] = 
$this->_db2->db_addslashes($entry['value']);
-                                               }
-
-                                               if($entry['datatype'] == 'pwd' 
&& $entry['value'] && $entry['value2'])
-                                               {
-                                                       if($entry['value'] || 
$entry['value2'])
+                                               case 'C':
+                                               case 'T':
+                                               case 'V':
+                                               case 'link':
+                                               case 'email':
+                                               case 'link':
+                                                       
$data['value_set'][$entry['name']]      = isset($entry['value']) && 
$entry['value'] ? 
$this->_db2->db_addslashes(phpgw::clean_value($entry['value'], 'string')) : '';
+                                                       $entry['value'] = 
$this->_db2->db_addslashes($entry['value']); // in case of history entries
+                                                       break;
+                                               case 'LB':
+                                               case 'R':
+                                               case 'AB':
+                                               case 'ABO':
+                                               case 'AB':
+                                               case 'ABO':
+                                               case 'VENDOR':
+                                               case 'event':
+                                               case 'I':
+                                               case 'custom3':
+                                               case 'user':
+                                                       
$data['value_set'][$entry['name']]      = isset($entry['value']) && 
$entry['value'] ? phpgw::clean_value($entry['value'], 'int') : '';
+                                                       break;
+                                               case 'bolean':
+                                                       
$data['value_set'][$entry['name']]      = isset($entry['value']) && 
$entry['value'] ? phpgw::clean_value($entry['value'], 'bool') : '';
+                                                       break;
+                                               case 'N':
+                                                       
$data['value_set'][$entry['name']]      = isset($entry['value']) && 
$entry['value'] ? phpgw::clean_value($entry['value'], 'float') : '';
+                                                       break;
+                                               case 'CH':
+                                                       $_value = ',' . 
implode(',', phpgw::clean_value($entry['value'])) . ',';
+                                                       
$data['value_set'][$entry['name']]      = isset($entry['value']) && 
$entry['value'] ? $_value : '';
+                                               break;
+                                               case 'D':
+                                                       $ts = 
phpgwapi_datetime::date_to_timestamp($entry['value']) - 
phpgwapi_datetime::user_timezone();
+                                                       $_value = 
date($this->_dateformat, $ts);
+                                                       
$data['value_set'][$entry['name']]      = isset($entry['value']) && 
$entry['value'] ? $_value : '';
+                                                       break;
+                                               case 'DT':
+                                                       $date_array     = 
phpgwapi_datetime::date_array($attrib['value']['date']);
+                                                       $ts = mktime 
((int)$attrib['value']['hour'], (int)$attrib['value']['min'], 0, 
$date_array['month'], $date_array['day'], $date_array['year']) - 
phpgwapi_datetime::user_timezone();
+                                                       $_value = 
date($this->_datetimeformat, $ts);
+                                                       
$data['value_set'][$entry['name']]      = isset($entry['value']) && 
$entry['value'] ? $_value : '';
+                                                       break;
+                                               case 'pwd':
+                                                       if($entry['value'] && 
$entry['value2'])
                                                        {
-                                                               
if($entry['value'] == $entry['value2'])
+                                                               
if($entry['value'] || $entry['value2'])
                                                                {
-                                                                       
$data['value_set'][$entry['name']]      = md5($entry['value']);
+                                                                       
if($entry['value'] == $entry['value2'])
+                                                                       {
+                                                                               
$data['value_set'][$entry['name']]      = md5($entry['value']);
+                                                                       }
+                                                                       else
+                                                                       {
+                                                                               
throw new Exception(lang('Passwords do not match!'));
+                                                                       }
                                                                }
-                                                               else
-                                                               {
-                                                                       
$data['receipt']['error'][]=array('msg'=>lang('Passwords do not match!'));
-                                                               }
                                                        }
-                                               }
-                                               else
-                                               {
-                                                       
$data['value_set'][$entry['name']]      = 
isset($entry['value'])?$entry['value']:'';
-                                               }
+                                                       else
+                                                       {
+                                                               
$data['value_set'][$entry['name']]      = 
isset($entry['value'])?$entry['value']:'';
+                                                       }
+
+                                                       break;
+
+                                               default:
+                                                       
$data['value_set'][$entry['name']]      = isset($entry['value']) && 
$entry['value'] ? 
$this->_db2->db_addslashes(phpgw::clean_value($entry['value'], 'string')) : '';
                                        }
 
+
                                        if($entry['history'] == 1)
                                        {
                                                if($id)
@@ -532,7 +577,7 @@
                                                        if($entry['value'] != 
$old_value)
                                                        {
                                                                
$data['history_set'][$entry['attrib_id']] = array
-                                                                       ('
+                                                               ('
                                                                        value'  
=> $entry['value'],
                                                                        'date'  
=> phpgwapi_datetime::date_to_timestamp($entry['date'])
                                                                );
@@ -659,7 +704,7 @@
                                        $ret =   lang('yes');
                                        break;
                                case 'custom1':
-                                       
+
                                        $ret = '';
                                        if($data['value'] && 
$data['get_single_function'])
                                        {
@@ -717,7 +762,7 @@
                                default:
                                        if(is_array($data['value']))
                                        {
-                                               $ret =  $data['value'];         
                                                
+                                               $ret =  $data['value'];
                                        }
                                        else
                                        {

Modified: trunk/property/inc/class.socommon_core.inc.php
===================================================================
--- trunk/property/inc/class.socommon_core.inc.php      2013-06-25 12:55:54 UTC 
(rev 11205)
+++ trunk/property/inc/class.socommon_core.inc.php      2013-06-26 12:21:20 UTC 
(rev 11206)
@@ -69,6 +69,7 @@
                 */
                protected $_like;
 
+               protected $_global_lock = false;
 
                public function __construct()
                {
@@ -108,7 +109,14 @@
 
                        $value_set      = 
$this->_db->validate_update($value_set);
 
-                       $this->_db->transaction_begin();
+                       if ( $this->_db->get_transaction() )
+                       {
+                               $this->_global_lock = true;
+                       }
+                       else
+                       {
+                               $this->_db->transaction_begin();
+                       }
 
                        $sql = "UPDATE {$table} SET $value_set WHERE id= {$id}";
 
@@ -127,7 +135,11 @@
                                }
                        }
 
-                       $this->_db->transaction_commit();
+                       if ( !$this->_global_lock )
+                       {
+                               $this->_db->transaction_commit();
+                       }
+
                        return $id;
                }
 
@@ -173,9 +185,9 @@
                                }
                        }
 
-                       if(isset($values['attributes']) && 
is_array($values['attributes']))
+                       if(isset($data['attributes']) && 
is_array($data['attributes']))
                        {
-                               $data_attribute = 
$this->custom->prepare_for_db($table, $values['attributes']);
+                               $data_attribute = 
$this->custom->prepare_for_db($table, $data['attributes']);
                                if(isset($data_attribute['value_set']))
                                {
                                        foreach($data_attribute['value_set'] as 
$input_name => $value)

Modified: trunk/property/inc/class.socondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.socondition_survey.inc.php 2013-06-25 12:55:54 UTC 
(rev 11205)
+++ trunk/property/inc/class.socondition_survey.inc.php 2013-06-26 12:21:20 UTC 
(rev 11206)
@@ -234,22 +234,43 @@
                        $value_set['user_id']                   = 
$this->account;
                        $value_set['modified_date']             = time();
 
+
+
+                       $this->_db->query("SELECT coordinator_id FROM 
fm_condition_survey WHERE id = {$id}",__LINE__,__FILE__);
+                       $this->_db->next_record();
+                       $old_coordinator_id             = 
(int)$this->_db->f('coordinator_id');
+
+
+                       $this->_db->transaction_begin();
                        try
                        {
+                               $sql = "UPDATE {$table} SET $value_set WHERE 
id= {$id}";
+
+                               $this->_db->Exception_On_Error = true;
+
+                               if($old_coordinator_id != 
$value_set['coordinator_id'])
+                               {
+                                       $this->_db->query("UPDATE fm_request 
SET coordinator = {$value_set['coordinator_id']} WHERE condition_survey_id = 
{$id}",__LINE__,__FILE__);
+                               }
+
                                $this->_edit($id, $value_set, 
'fm_condition_survey');
+                               $this->_db->Exception_On_Error = false;
                        }
 
                        catch(Exception $e)
                        {
                                if ( $e )
                                {
+                                       $this->_db->transaction_abort();
                                        throw $e;
                                }
                        }
 
+                       $this->_db->transaction_commit();
                        return $id;
                }
 
+
                public function edit_title($data)
                {
                        $id = (int)$data['id'];
@@ -386,6 +407,11 @@
 
                        unset($entry);
 
+                       $custom = createObject('phpgwapi.custom_fields');
+                       $attributes = 
$custom->find('property','.project.request', 0, '','','',true, true);
+
+
+
                        $origin_id = 
$GLOBALS['phpgw']->locations->get_id('property', '.project.condition_survey');
                        foreach ($import_data as $entry)
                        {
@@ -432,8 +458,8 @@
                                        $request['origin_id']                   
        = $origin_id;
                                        $request['origin_item_id']              
        = (int)$survey['id'];
                                        $request['title']                       
                = substr($entry['title'], 0, 255);
-                                       $request['descr']                       
                = $entry['descr'];
-                                       $request['building_part']               
        = $entry['building_part'];
+                                       $request['descr']                       
                = phpgw::clean_value($entry['descr'], 'string');
+                                       $request['building_part']               
        = phpgw::clean_value($entry['building_part'], 'string');
                                        $request['coordinator']                 
        = $survey['coordinator_id'];
 
                                        if($entry['import_type'] == 1)
@@ -466,8 +492,23 @@
                                                )
                                        );
 
-//_debug_array($request);
-                                       $sorequest->add($request, 
$values_attribute = array());
+                                       $values_attribute = array();
+                                       foreach($entry as $_field => $_value)
+                                       {
+                                               
if(preg_match('/^custom_attribute_/', $_field) && $_value)
+                                               {
+                                                       $attribute_id = 
(int)ltrim($_field, 'custom_attribute_');
+                                                       
+                                                       $values_attribute[] = 
array
+                                                       (
+                                                               'name'          
=> $attributes[$attribute_id]['column_name'],
+                                                               'value'         
=> $_value,
+                                                               'datatype'      
=> $attributes[$attribute_id]['datatype'],
+                                                       );
+                                               }
+                                       }
+
+                                       $sorequest->add($request, 
$values_attribute);
                                }
                        }
 
@@ -551,9 +592,42 @@
 
                public function delete($id)
                {
+
+                       $this->_db->transaction_begin();
+
+                       try
+                       {
+                               $this->_db->Exception_On_Error = true;
+                               $this->delete_imported_records($id);
+                               $this->_db->query("DELETE FROM 
fm_condition_survey WHERE id = {$id}",__LINE__,__FILE__);
+                               $this->_db->Exception_On_Error = false;
+                       }
+
+                       catch(Exception $e)
+                       {
+                               if ( $e )
+                               {
+                                       $this->_db->transaction_abort();
+                                       throw $e;
+                               }
+                       }
+
+                       $this->_db->transaction_commit();
+               }
+
+               public function delete_imported_records($id)
+               {
                        $id = (int) $id;
                        $interlink      = CreateObject('property.interlink');
-                       $this->_db->transaction_begin();
+
+                       if ( $this->_db->get_transaction() )
+                       {
+                               $this->_global_lock = true;
+                       }
+                       else
+                       {
+                               $this->_db->transaction_begin();
+                       }
                        
                        $requests = array();
                        $this->_db->query("SELECT id AS request_id FROM 
fm_request WHERE condition_survey_id={$id}",__LINE__,__FILE__);
@@ -573,7 +647,6 @@
                                        $this->_db->query('DELETE FROM 
fm_request_history  WHERE  history_record_id IN (' . implode(',', $requests) . 
')',__LINE__,__FILE__);
                                }
                                $this->_db->query("DELETE FROM fm_request WHERE 
condition_survey_id = {$id}",__LINE__,__FILE__);
-                               $this->_db->query("DELETE FROM 
fm_condition_survey WHERE id = {$id}",__LINE__,__FILE__);
                        
                                foreach ($requests as $request_id)
                                {
@@ -587,11 +660,18 @@
                        {
                                if ( $e )
                                {
-                                       $this->_db->transaction_abort();
+                                       if ( !$this->_global_lock )
+                                       {
+                                               $this->_db->transaction_abort();
+                                       }
+
                                        throw $e;
                                }
                        }
 
-                       $this->_db->transaction_commit();
+                       if ( !$this->_global_lock )
+                       {
+                               $this->_db->transaction_commit();
+                       }
                }
        }

Modified: trunk/property/inc/class.sorequest.inc.php
===================================================================
--- trunk/property/inc/class.sorequest.inc.php  2013-06-25 12:55:54 UTC (rev 
11205)
+++ trunk/property/inc/class.sorequest.inc.php  2013-06-26 12:21:20 UTC (rev 
11206)
@@ -997,9 +997,8 @@
                        $data = $request;
                        $data['attributes'] = $values_attribute;
                        
-                       $value_set                                              
= $this->_get_value_set( $data );
+                       $value_set                      = 
$this->_get_value_set( $data );
 
-
                        if ( $this->_db->get_transaction() )
                        {
                                $this->global_lock = true;

Modified: trunk/property/inc/class.uicondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.uicondition_survey.inc.php 2013-06-25 12:55:54 UTC 
(rev 11205)
+++ trunk/property/inc/class.uicondition_survey.inc.php 2013-06-26 12:21:20 UTC 
(rev 11206)
@@ -37,22 +37,23 @@
                private $receipt = array();
                public $public_functions = array
                (
-                       'query'                         => true,
-                       'index'                         => true,
-                       'view'                          => true,
-                       'add'                           => true,
-                       'edit'                          => true,
-                       'save'                          => true,
-                       'delete'                        => true,
-                       'get_vendors'           => true,
-                       'get_users'                     => true,
-                       'edit_survey_title'     => true,
-                       'get_files'                     => true,
-                       'get_request'   => true,
-                       'get_summation'         => true,
-                       'view_file'                     => true,
-                       'import'                        => true,
-                       'download'                      => true
+                       'query'                                         => true,
+                       'index'                                         => true,
+                       'view'                                          => true,
+                       'add'                                           => true,
+                       'edit'                                          => true,
+                       'save'                                          => true,
+                       'delete'                                        => true,
+                       'delete_imported_records'       => true,
+                       'get_vendors'                           => true,
+                       'get_users'                                     => true,
+                       'edit_survey_title'                     => true,
+                       'get_files'                                     => true,
+                       'get_request'                           => true,
+                       'get_summation'                         => true,
+                       'view_file'                                     => true,
+                       'import'                                        => true,
+                       'download'                                      => true
                );
 
                public function __construct()
@@ -256,6 +257,21 @@
                        {
                                $data['datatable']['actions'][] = array
                                        (
+                                               'my_name'               => 
'delete_imported_records',
+                                               'text'                  => 
lang('delete imported records'),
+                                               'confirm_msg'   => lang('do you 
really want to delete this entry') . '?',
+                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                                               (
+                                                       'menuaction'    => 
'property.uicondition_survey.delete_imported_records'
+                                               )),
+                                               'parameters'    => 
json_encode($parameters)
+                                       );
+                       }
+
+                       if($GLOBALS['phpgw']->acl->check('.admin', 
PHPGW_ACL_DELETE, 'property'))
+                       {
+                               $data['datatable']['actions'][] = array
+                                       (
                                                'my_name'               => 
'delete_survey',
                                                'text'                  => 
lang('delete'),
                                                'confirm_msg'   => lang('do you 
really want to delete this entry') . '?',
@@ -561,7 +577,7 @@
                                else
                                {
                                        phpgwapi_cache::message_set('ok!', 
'message'); 
-                                       
$GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 
'property.uicondition_survey.view', 'id' => $id));
+                                       
$GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 
'property.uicondition_survey.edit', 'id' => $id));
                                }
                        }
                }
@@ -1018,7 +1034,6 @@
                                        'building_part'                         
=> 'bygningsdels kode',
                                        'descr'                                 
        => 'Tilstandbeskrivelse',
                                        'title'                                 
        => 'Tiltak/overskrift',
-                                       'hjemmel'                               
        => 'Hjemmel/ krav',
                                        'condition_degree'                      
=> 'Tilstandsgrad',
                                        'condition_type'                        
=> 'Konsekvenstype',
                                        'consequence'                           
=> 'Konsekvensgrad',
@@ -1029,6 +1044,14 @@
                                        'amount_potential_grants'       => 
'Potensial for offentlig støtte',
                                );
 
+                               $custom = 
createObject('phpgwapi.custom_fields');
+                               $attributes = 
$custom->find('property','.project.request', 0, '','','',true, true);
+
+                               foreach($attributes as $attribute)
+                               {
+                                       
$_options["custom_attribute_{$attribute['id']}"] = $attribute['input_text'];
+                               }
+
                                phpgw::import_class('phpgwapi.sbox');
 
                                foreach($data[$start_line] as $_column => 
$_value)
@@ -1255,6 +1278,36 @@
                        return 'Deleted';
                }
 
+               /**
+               * Delete related requests only
+               *
+               * @param int  $id  id of entity
+               *
+               * @return string text to appear in ui as receipt on action
+               */
+
+               public function delete_imported_records()
+               {
+                       if(!$GLOBALS['phpgw']->acl->check('.admin', 
PHPGW_ACL_DELETE, 'property'))
+                       {
+                               return 'No access';
+                       }
+                       $id = phpgw::get_var('id', 'int', 'GET');
+
+                       try
+                       {
+                               $this->bo->delete_imported_records($id);
+                       }
+                       catch(Exception $e)
+                       {
+                               if ( $e )
+                               {
+                                       return $e->getMessage(); 
+                               }
+                       }
+                       return 'Deleted';
+               }
+
                /*
                * Overrides with incoming data from POST
                */




reply via email to

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