fmsystem-commits
[Top][All Lists]
Advanced

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

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


From: Sigurd Nes
Subject: [Fmsystem-commits] [10537] property: more on condition survey
Date: Mon, 26 Nov 2012 11:23:09 +0000

Revision: 10537
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10537
Author:   sigurdne
Date:     2012-11-26 11:23:08 +0000 (Mon, 26 Nov 2012)
Log Message:
-----------
property: more on condition survey

Modified Paths:
--------------
    trunk/property/inc/class.bocondition_survey.inc.php
    trunk/property/inc/class.socondition_survey.inc.php
    trunk/property/inc/class.uicondition_survey.inc.php
    trunk/property/templates/base/condition_survey.xsl

Modified: trunk/property/inc/class.bocondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.bocondition_survey.inc.php 2012-11-25 21:05:36 UTC 
(rev 10536)
+++ trunk/property/inc/class.bocondition_survey.inc.php 2012-11-26 11:23:08 UTC 
(rev 10537)
@@ -139,13 +139,13 @@
                        
if($GLOBALS['phpgw']->locations->get_attrib_table('property', 
$this->acl_location))
                        {
                                $custom_fields = true;
-                               $values = array();
-                               $values['attributes'] = 
$this->custom->find('property', $this->acl_location, 0, '', 'ASC', 
'attrib_sort', true, true);
+                               $data['attributes'] = 
$this->custom->find('property', $this->acl_location, 0, '', 'ASC', 
'attrib_sort', true, true);
                        }
 
+                       $values = array();
                        if(isset($data['id']) && $data['id'])
                        {
-                               $values = $this->so->read_single($data, 
$values);
+                               $values = $this->so->read_single($data);
                        }
                        if($custom_fields)
                        {
@@ -154,6 +154,29 @@
 
                        $values['report_date']  = 
$GLOBALS['phpgw']->common->show_date($values['report_date'],$this->dateformat);
 
+                       if(isset($values['vendor_id']) && $values['vendor_id'] 
&& !$values['vendor_name'])
+                       {
+                               $contacts       = 
CreateObject('property.sogeneric');
+                               $contacts->get_location_info('vendor',false);
+
+                               $custom                 = 
createObject('property.custom_fields');
+                               $vendor_data['attributes'] = 
$custom->find('property','.vendor', 0, '', 'ASC', 'attrib_sort', true, true);
+
+                               $vendor_data    = 
$contacts->read_single(array('id' => $values['vendor_id']),$vendor_data);
+                               if(is_array($vendor_data))
+                               {
+                                       foreach($vendor_data['attributes'] as 
$attribute)
+                                       {
+                                               
if($attribute['name']=='org_name')
+                                               {
+                                                       
$values['vendor_name']=$attribute['value'];
+                                                       break;
+                                               }
+                                       }
+                               }
+                               unset($contacts);
+                       }
+
                        return $values;
                }
 
@@ -168,11 +191,11 @@
                        {
                                if (isset($data['id']) && $data['id'])
                                {
-                                       $receipt = $this->so->edit($data);
+                                       $id = $this->so->edit($data);
                                }
                                else
                                {
-                                       $receipt = $this->so->add($data);
+                                       $id = $this->so->add($data);
                                }
                        }
 
@@ -184,7 +207,7 @@
                                }
                        }
 
-                       return $receipt;
+                       return $id;
                }
 
                public function delete($id)

Modified: trunk/property/inc/class.socondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.socondition_survey.inc.php 2012-11-25 21:05:36 UTC 
(rev 10536)
+++ trunk/property/inc/class.socondition_survey.inc.php 2012-11-26 11:23:08 UTC 
(rev 10537)
@@ -158,11 +158,11 @@
                        return $values;
                }
 
-               function read_single($id, $data = array())
+               function read_single($data = array())
                {
                        $table = 'fm_condition_survey';
 
-                       $id = (int) $id;
+                       $id             = (int)$data['id'];
                        $this->_db->query("SELECT * FROM {$table} WHERE 
id={$id}",__LINE__,__FILE__);
 
                        $values = array();
@@ -200,16 +200,81 @@
 
                function add($data)
                {
-
                        $table = 'fm_condition_survey';
 
                        $this->_db->transaction_begin();
 
                        $id = $this->_db->next_id($table);
 
+                       $value_set                      = 
$this->_get_value_set( $data );
+                       $value_set['id']        = $id;
+
+                       $cols = implode(',', array_keys($value_set));
+                       $values = 
$this->_db->validate_insert(array_values($value_set));
+                       $sql = "INSERT INTO {$table} ({$cols}) VALUES 
({$values})";
+
+                       try
+                       {
+                               $this->_db->Exception_On_Error = true;
+                               $this->_db->query($sql,__LINE__,__FILE__);
+                               $this->_db->Exception_On_Error = false;
+                       }
+
+                       catch(Exception $e)
+                       {
+                               if ( $e )
+                               {
+                                       throw $e;                               
+                               }
+                               return 0;
+                       }
+
+                       if($this->_db->transaction_commit())
+                       {
+                               return $id;
+                       }
+                       else
+                       {
+                               return 0;
+                       }
+               }
+
+               function edit($data)
+               {
+                       $table = 'fm_condition_survey';
+                       $id = (int)$data['id'];
+
+                       $value_set      = $this->_get_value_set( $data );
+                       $value_set      = 
$this->_db->validate_update($value_set);
+
+                       $this->_db->transaction_begin();
+
+                       $sql = "UPDATE {$table} SET $value_set WHERE id= {$id}";
+
+                       try
+                       {
+                               $this->_db->Exception_On_Error = true;
+                               $this->_db->query($sql,__LINE__,__FILE__);
+                               $this->_db->Exception_On_Error = false;
+                       }
+
+                       catch(Exception $e)
+                       {
+                               if ( $e )
+                               {
+                                       throw $e;                               
+                               }
+                       }
+
+                       $this->_db->transaction_commit();
+                       return $id;
+               }
+
+
+               private function _get_value_set($data)
+               {
                        $value_set = array
                        (
-                               'id'                            => $id,
                                'title'                         => 
$this->_db->db_addslashes($data['title']),
                                'descr'                         => 
$this->_db->db_addslashes($data['descr']),
                                'status_id'                     => 
(int)$data['status_id'],
@@ -298,51 +363,9 @@
        //              $value_set['address'] = $address;
 
                        unset($_address);
-
-                       $cols = implode(',', array_keys($value_set));
-                       $values = 
$this->_db->validate_insert(array_values($value_set));
-
-                       try
-                       {
-                               $this->_db->Exception_On_Error = true;
-                               $this->_db->query("INSERT INTO {$table} 
({$cols}) VALUES ({$values})",__LINE__,__FILE__);
-                               $this->_db->Exception_On_Error = false;
-                       }
-
-                       catch(Exception $e)
-                       {
-                               if ( $e )
-                               {
-                                       throw $e;                               
-                               }
-                       }
-
-                       if($this->_db->transaction_commit())
-                       {
-                               return $id;
-                       }
-
-                       return 0;
+                       return $value_set;
                }
 
-               function edit($data)
-               {
-                       $table = 'fm_condition_survey';
-                       $id = (int)$data['id'];
-
-                       $value_set      = 
$this->db->validate_update($value_set);
-
-                       $this->db->transaction_begin();
-
-                       $this->db->query("UPDATE {$table} SET $value_set WHERE 
id= {$id}",__LINE__,__FILE__);
-
-                       if($this->_db->transaction_commit())
-                       {
-                               $this->_receipt['message'][] = 
array('msg'=>lang('survey %1 has been saved',$id));
-                       }
-                       return $id;
-               }
-
                function delete($id)
                {
                        $id = (int) $id;

Modified: trunk/property/inc/class.uicondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.uicondition_survey.inc.php 2012-11-25 21:05:36 UTC 
(rev 10536)
+++ trunk/property/inc/class.uicondition_survey.inc.php 2012-11-26 11:23:08 UTC 
(rev 10537)
@@ -82,8 +82,8 @@
                        phpgwapi_yui::load_widget('paginator');
 
                        $categories = $this->_get_categories();
-                       
 
+
                        $data = array(
                                'datatable_name'        => lang('condition 
survey'),
                                'form' => array(
@@ -243,10 +243,6 @@
 
                public function edit($values = array(), $mode = 'edit')
                {
-/*
-_debug_array($_POST);
-die();
-*/
                        $id     = phpgw::get_var('id', 'int');
 
                        if(!$this->acl_add && !$this->acl_edit)
@@ -278,13 +274,15 @@
                        $tabs['documents']      = array('label' => 
lang('documents'), 'link' => null);
                        $tabs['import'] = array('label' => lang('import'), 
'link' => null);
 
+                       if ($id)
+                       {
                                $tabs['documents']['link'] = '#documents';
                                $tabs['import']['link'] = '#import';
 
-                       if ($id)
-                       {
-
-                               $values = $this->bo->read_single( array('id' => 
$id,  'view' => $mode == 'view') );
+                               if (!$values)
+                               {
+                                       $values = $this->bo->read_single( 
array('id' => $id,  'view' => $mode == 'view') );
+                               }
                        }
 
                        if(isset($values['location_code']) && 
$values['location_code'])
@@ -305,10 +303,12 @@
                                        'lookup_entity' => array(),
                                        'entity_data'   => 
isset($values['p'])?$values['p']:''
                                ));
-//_debug_array($values);die();
 
+                       $msgbox_data = 
$this->bocommon->msgbox_data($this->receipt);
+
                        $data = array
                        (
+                               'msgbox_data'           => 
$GLOBALS['phpgw']->common->msgbox($msgbox_data),
                                'survey'                        => $values,
                                'location_data'         => $location_data,
                                'categories'            => array('options' => 
$categories),
@@ -319,7 +319,7 @@
 //_debug_array($data);die();
                        $GLOBALS['phpgw']->jqcal->add_listener('report_date');
                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('property') . '::' . lang('condition survey');
-                       
+
                        phpgwapi_jquery::load_widget('core');
                        self::add_javascript('property', 'portico', 
'condition_survey_edit.js');
                        self::add_javascript('phpgwapi', 'yui3', 
'yui/yui-min.js');
@@ -327,28 +327,32 @@
                        
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yui3/gallery-formvalidator/validatorCss.css');
                        self::render_template_xsl(array('condition_survey'), 
$data);
                }
-               
+
                public function save()
                {
                        $id = phpgw::get_var('id');
-                       
+
                        if ($id )
                        {
-                               $values = $this->bo->read_single(array('id' => 
$id));
+                               $values = $this->bo->read_single( array('id' => 
$id,  'view' => true) );
                        }
                        else
                        {
                                $values = array();
                        }
-                       
+
                        /*
                        * Overrides with incoming data from POST
                        */
                        $values = $this->_populate($values);
 
-//_debug_array($values);die();                 
-                       if( !$this->receipt['error'] )
+                       if( $this->receipt['error'] )
                        {
+                               $this->edit( $values );
+                       }
+                       else
+                       {
+
                                try
                                {
                                        $id = $this->bo->save($values);
@@ -364,12 +368,9 @@
                                        }
                                }
 
-                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'property.uicondition_survey.view', 'id' => $id)); 
+                               phpgwapi_cache::message_set('ok!', 'message'); 
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'property.uicondition_survey.view', 'id' => $id));
                        }
-                       else
-                       {
-                               $this->edit( $values );
-                       }
                }
 
                public function get_vendors()
@@ -394,7 +395,7 @@
                        $insert_record = 
phpgwapi_cache::session_get('property', 'insert_record');
 
                        $values = phpgw::get_var('values');
-                       
+
                        $_fields = array
                        (
                                array
@@ -441,7 +442,7 @@
                                ),
                        );
 
-                       
+
                        foreach ($_fields as $_field)
                        {
                                if($data[$_field['name']] = 
$_POST['values'][$_field['name']])
@@ -453,11 +454,16 @@
                                        
$this->receipt['error'][]=array('msg'=>lang('Please enter value for attribute 
%1', $_field['name']));
                                }
                        }
-//_debug_array($_POST);
-//_debug_array($data);
 
+//_debug_array($data);die();
+
                        $values = 
$this->bocommon->collect_locationdata($data,$insert_record);
-                       
+
+                       if(!isset($values['location_code']) || ! 
$values['location_code'])
+                       {
+                               
$this->receipt['error'][]=array('msg'=>lang('Please select a location !'));
+                       }
+
                        /*
                        * Extra data from custom fields
                        */
@@ -476,17 +482,17 @@
 
                        if(!isset($values['cat_id']) || !$values['cat_id'])
                        {
-                               $receipt['error'][]=array('msg'=>lang('Please 
select a category !'));
+                               
$this->receipt['error'][]=array('msg'=>lang('Please select a category !'));
                        }
 
-                       if(isset($values['title']) || !$values['title'])
+                       if(!isset($values['title']) || !$values['title'])
                        {
-                               $receipt['error'][]=array('msg'=>lang('Please 
give a title !'));
+                               
$this->receipt['error'][]=array('msg'=>lang('Please give a title !'));
                        }
 
                        if(!isset($values['report_date']) || 
!$values['report_date'])
                        {
-                               $receipt['error'][]=array('msg'=>lang('Please 
select a date!'));
+                               
$this->receipt['error'][]=array('msg'=>lang('Please select a date!'));
                        }
 
                        return $values;
@@ -504,7 +510,7 @@
                        {
                                $_category['id'] = $_category['cat_id'];
                        }
-                       
+
                        return $categories['cat_list'];
                }
        }

Modified: trunk/property/templates/base/condition_survey.xsl
===================================================================
--- trunk/property/templates/base/condition_survey.xsl  2012-11-25 21:05:36 UTC 
(rev 10536)
+++ trunk/property/templates/base/condition_survey.xsl  2012-11-26 11:23:08 UTC 
(rev 10537)
@@ -67,7 +67,7 @@
                                                                </td>
                                                                <td>
                                                                        
<xsl:value-of select="survey/id"/>
-                                                                       <input 
type="hidden" name="values[id]" value="{survey/id}"/>
+                                                                       <input 
type="hidden" name="id" value="{survey/id}"/>
                                                                </td>
                                                        </tr>
                                                </xsl:when>




reply via email to

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