fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [9052] property: custom fields at tickets


From: Sigurd Nes
Subject: [Fmsystem-commits] [9052] property: custom fields at tickets
Date: Tue, 27 Mar 2012 19:11:15 +0000

Revision: 9052
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9052
Author:   sigurdne
Date:     2012-03-27 19:11:14 +0000 (Tue, 27 Mar 2012)
Log Message:
-----------
property: custom fields at tickets

Modified Paths:
--------------
    trunk/property/inc/class.botts.inc.php
    trunk/property/inc/class.menu.inc.php
    trunk/property/inc/class.sogeneric.inc.php
    trunk/property/inc/class.sotts.inc.php
    trunk/property/inc/class.uitts.inc.php
    trunk/property/templates/base/tts.xsl

Modified: trunk/property/inc/class.botts.inc.php
===================================================================
--- trunk/property/inc/class.botts.inc.php      2012-03-27 16:56:38 UTC (rev 
9051)
+++ trunk/property/inc/class.botts.inc.php      2012-03-27 19:11:14 UTC (rev 
9052)
@@ -64,6 +64,7 @@
                function property_botts($session=false)
                {
                        $this->so                                       = 
CreateObject('property.sotts');
+                       $this->custom                           = & 
$this->so->custom;
                        $this->bocommon                         = 
CreateObject('property.bocommon');
                        $this->historylog                       = & 
$this->so->historylog;
                        $this->config                           = 
CreateObject('phpgwapi.config','property');
@@ -454,11 +455,13 @@
                        return $tickets;
                }
 
-               function read_single($id)
+               function read_single($id, $values = array(), $view = false)
                {
                        $this->so->update_view($id);
 
-                       $ticket = $this->so->read_single($id);
+                       $values['attributes'] = $this->custom->find('property', 
'.ticket', 0, '', 'ASC', 'attrib_sort', true, true);
+                       $ticket = $this->so->read_single($id, $values);
+                       $ticket = $this->custom->prepare($ticket, 'property', 
'.ticket', $view);
 
                        $ticket['user_lid'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
                        $ticket['group_lid'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['group_id']);
@@ -775,7 +778,7 @@
                        return (int)$result['id'];      
                }
 
-               function add($ticket)
+               function add($ticket, $values_attribute = array())
                {
                        if((!isset($ticket['location_code']) || ! 
$ticket['location_code']) && isset($ticket['location']) && 
is_array($ticket['location']))
                        {
@@ -791,8 +794,13 @@
 
                        $ticket['finnish_date'] = 
$this->bocommon->date_to_timestamp($ticket['finnish_date']);
 
-                       $receipt = $this->so->add($ticket);
+                       if($values_attribute && is_array($values_attribute))
+                       {
+                               $values_attribute = 
$this->custom->convert_attribute_save($values_attribute);
+                       }
 
+                       $receipt = $this->so->add($ticket, $values_attribute);
+
                        $this->config->read();
 
                        if ( (isset($ticket['send_mail']) && 
$ticket['send_mail']) 
@@ -1147,9 +1155,14 @@
                        return $receipt;
                }
 
-               public function update_ticket($data, $id,$receipt = array())
+               public function update_ticket($data, $id,$receipt = 
array(),$values_attribute = array())
                {
-                       $receipt = $this->so->update_ticket($data, $id, 
$receipt);
+                       if($values_attribute && is_array($values_attribute))
+                       {
+                               $values_attribute = 
$this->custom->convert_attribute_save($values_attribute);
+                       }
+
+                       $receipt = $this->so->update_ticket($data, $id, 
$receipt, $values_attribute);
                        $this->fields_updated = $this->so->fields_updated;
 
                        $criteria = array
@@ -1346,4 +1359,11 @@
                                $fileuploader->upload("fmticket/{$id}");
                        }
                }
+
+               public function get_attributes($values)
+               {
+                       $values['attributes'] = $this->custom->find('property', 
'.ticket', 0, '', 'ASC', 'attrib_sort', true, true);
+                       $values = $this->custom->prepare($values, 'property', 
'.ticket', false);
+                       return $values;
+               }
        }

Modified: trunk/property/inc/class.menu.inc.php
===================================================================
--- trunk/property/inc/class.menu.inc.php       2012-03-27 16:56:38 UTC (rev 
9051)
+++ trunk/property/inc/class.menu.inc.php       2012-03-27 19:11:14 UTC (rev 
9052)
@@ -149,6 +149,31 @@
                                                        'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.ui_custom.list_attribute', 'appname' => 'property', 'location' => 
'.vendor', 'menu_selection' => 'admin::property::vendor::vendor_attribs') )
                                                )
                                        );
+
+                               $admin_children_ticket = array
+                                       (
+                                               'ticket_cats'   => array
+                                               (
+                                                       'text'  => lang('Ticket 
Categories'),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uicategories.index', 'appname' => 'property', 'location' => '.ticket', 
'global_cats' => 'true', 'menu_selection' => 
'admin::property::ticket::ticket_cats') )
+                                               ),
+                                               'ticket_status' => array
+                                               (
+                                                       'text'  => lang('Ticket 
status'),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index', 'type' => 'ticket_status') )
+                                               ),
+                                               'ticket_config' => array
+                                               (
+                                                       'text'  => lang('ticket 
config'),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uiconfig2.index', 'location_id' => 
$GLOBALS['phpgw']->locations->get_id('property', '.ticket')) )
+                                               ),
+                                               'ticket_attribs'        => array
+                                               (
+                                                       'text'  => lang('ticket 
Attributes'),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.ui_custom.list_attribute', 'appname' => 'property', 'location' => 
'.ticket', 'menu_selection' => 'admin::property::ticket::ticket_attribs') )
+                                               )
+                                       );
+
                                $admin_children_owner = array
                                        (
                                                'owner_cats'    => array
@@ -347,21 +372,12 @@
                                                        'text'  => 
lang('Workorder Detail Categories'),
                                                        'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index', 'type' => 'wo_hours') )
                                                ),
-                                               'ticket_cats'   => array
+                                               'ticket'        => array
                                                (
-                                                       'text'  => lang('Ticket 
Categories'),
-                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uicategories.index', 'appname' => 'property', 'location' => '.ticket', 
'global_cats' => 'true', 'menu_selection' => 'admin::property::ticket_cats') )
+                                                       'text'  => 
lang('helpdesk'),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uicategories.index', 'appname' => 'property', 'location' => '.ticket', 
'global_cats' => 'true', 'menu_selection' => 
'admin::property::ticket::ticket_cats') ),
+                                                       'children' => 
$admin_children_ticket
                                                ),
-                                               'ticket_status' => array
-                                               (
-                                                       'text'  => lang('Ticket 
status'),
-                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index', 'type' => 'ticket_status') )
-                                               ),
-                                               'ticket_config' => array
-                                               (
-                                                       'text'  => lang('ticket 
config'),
-                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uiconfig2.index', 'location_id' => 
$GLOBALS['phpgw']->locations->get_id('property', '.ticket')) )
-                                               ),
                                                'tenant'        => array
                                                (
                                                        'text'  => 
lang('Tenant'),

Modified: trunk/property/inc/class.sogeneric.inc.php
===================================================================
--- trunk/property/inc/class.sogeneric.inc.php  2012-03-27 16:56:38 UTC (rev 
9051)
+++ trunk/property/inc/class.sogeneric.inc.php  2012-03-27 19:11:14 UTC (rev 
9052)
@@ -1679,7 +1679,7 @@
                                                'name'                          
=> lang('event action'),
                                                'acl_app'                       
=> 'property',
                                                'acl_location'          => 
'.admin',
-                                               'menu_selection'        => 
'admin::property::ticket_status'
+                                               'menu_selection'        => 
'admin::property::ticket::ticket_status'
                                        );
                                break;
 

Modified: trunk/property/inc/class.sotts.inc.php
===================================================================
--- trunk/property/inc/class.sotts.inc.php      2012-03-27 16:56:38 UTC (rev 
9051)
+++ trunk/property/inc/class.sotts.inc.php      2012-03-27 19:11:14 UTC (rev 
9052)
@@ -65,6 +65,7 @@
                {
                        $this->account          = 
(int)$GLOBALS['phpgw_info']['user']['account_id'];
                        $this->historylog       = 
CreateObject('property.historylog','tts');
+                       $this->custom           = 
createObject('property.custom_fields');
                        $this->db                       = & 
$GLOBALS['phpgw']->db;
                        $this->like             = & $this->db->like;
                        $this->join             = & $this->db->join;
@@ -566,7 +567,7 @@
                        return $entity;
                }
 
-               function read_single($id)
+               function read_single($id, $values = array())
                {
                        $id = (int) $id;
                        $sql = "SELECT * FROM fm_tts_tickets WHERE id = {$id}";
@@ -615,6 +616,15 @@
                                {
                                        $ticket['assignedto_name']      = 
$GLOBALS['phpgw']->accounts->get($ticket['assignedto'])->__toString();
                                }
+
+                               if ( isset($values['attributes']) && 
is_array($values['attributes']) )
+                               {
+                                       $ticket['attributes'] = 
$values['attributes'];
+                                       foreach ( $ticket['attributes'] as 
&$attr )
+                                       {
+                                               $attr['value']  = 
$this->db->f($attr['column_name']);
+                                       }
+                               }
                        }
 
                        return $ticket;
@@ -635,8 +645,10 @@
                        }
                }
 
-               function add(&$ticket)
+               function add(&$ticket , $values_attribute = array())
                {
+                       $table = 'fm_tts_tickets';
+
                        if(isset($ticket['location']) && 
is_array($ticket['location']))
                        {
                                foreach ($ticket['location'] as $input_name => 
$value)
@@ -648,6 +660,18 @@
                                }
                        }
 
+                       $data_attribute = $this->custom->prepare_for_db($table, 
$values_attribute);
+                       if(isset($data_attribute['value_set']))
+                       {
+                               foreach($data_attribute['value_set'] as 
$input_name => $value)
+                               {
+                                       if(isset($value) && $value)
+                                       {
+                                               $value_set[$input_name] = 
$value;
+                                       }
+                               }
+                       }
+
                        if(isset($ticket['extra']) && 
is_array($ticket['extra']))
                        {
                                foreach ($ticket['extra'] as $input_name => 
$value)
@@ -716,7 +740,6 @@
                        $values = 
$this->db->validate_insert(array_values($value_set));
                        $this->db->transaction_begin();
 
-                       $table = 'fm_tts_tickets';
                        $this->db->query("INSERT INTO {$table} ({$cols}) VALUES 
({$values})",__LINE__,__FILE__);
 
                        $id = $this->db->get_last_insert_id($table,'id');
@@ -887,7 +910,7 @@
                        return $receipt;
                }
 
-               function update_ticket(&$ticket,$id = 0, $receipt = array())
+               function update_ticket(&$ticket,$id = 0, $receipt = array(), 
$values_attribute = array())
                {
                        $this->fields_updated = array();
                        $id = (int) $id;
@@ -1267,6 +1290,19 @@
                        }
 
                        $value_set                                      = 
array();
+
+                       $data_attribute = 
$this->custom->prepare_for_db('fm_tts_tickets', $values_attribute);
+                       if(isset($data_attribute['value_set']))
+                       {
+                               foreach($data_attribute['value_set'] as 
$input_name => $value)
+                               {
+                                       if(isset($value) && $value)
+                                       {
+                                               $value_set[$input_name] = 
$value;
+                                       }
+                               }
+                       }
+
                        $value_set['vendor_id']         = $ticket['vendor_id'];
                        $value_set['b_account_id']      = 
$ticket['b_account_id'];
                        $value_set['order_descr']       = 
$this->db->db_addslashes($ticket['order_descr']);

Modified: trunk/property/inc/class.uitts.inc.php
===================================================================
--- trunk/property/inc/class.uitts.inc.php      2012-03-27 16:56:38 UTC (rev 
9051)
+++ trunk/property/inc/class.uitts.inc.php      2012-03-27 19:11:14 UTC (rev 
9052)
@@ -1767,6 +1767,8 @@
                                
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'property.uitts.index'));
                        }
 
+                       $values_attribute                       = 
phpgw::get_var('values_attribute');
+
                        //------------------- start ticket from other location
                        $bypass                 = phpgw::get_var('bypass', 
'bool');
 //                     if(isset($_POST) && $_POST && isset($bypass) && $bypass)
@@ -1883,9 +1885,20 @@
                                        unset($_priority);
                                }
 
+                               if(isset($values_attribute) && 
is_array($values_attribute))
+                               {
+                                       foreach ($values_attribute as 
$attribute )
+                                       {
+                                               if($attribute['nullable'] != 1 
&& (!$attribute['value'] && !$values['extra'][$attribute['name']]))
+                                               {
+                                                       
$receipt['error'][]=array('msg'=>lang('Please enter value for attribute %1', 
$attribute['input_text']));
+                                               }
+                                       }
+                               }
+
                                if(!isset($receipt['error']))
                                {
-                                       $receipt = $this->bo->add($values);
+                                       $receipt = $this->bo->add($values, 
$values_attribute);
 
                                        //------------ files
                                        $values['file_name'] = @str_replace(' 
','_',$_FILES['file']['name']);
@@ -1948,6 +1961,33 @@
                                }
                        }
 
+                       /* Preserve attribute values from post */
+                       if(isset($receipt['error']) && (isset( 
$values_attribute) && is_array( $values_attribute)))
+                       {
+                               $values = 
$this->bocommon->preserve_attribute_values($values,$values_attribute);
+                       }
+
+                       $values = $this->bo->get_attributes($values);
+
+                       if (isset($values['attributes']) && 
is_array($values['attributes']))
+                       {
+                               foreach ($values['attributes'] as & $attribute)
+                               {
+                                       if($attribute['history'] == true)
+                                       {
+                                               $link_history_data = array
+                                                       (
+                                                               'menuaction'    
=> 'property.uiproject.attrib_history',
+                                                               'attrib_id'     
=> $attribute['id'],
+                                                               'id'            
=> $id,
+                                                               'edit'          
=> true
+                                                       );
+
+                                               $attribute['link_history'] = 
$GLOBALS['phpgw']->link('/index.php',$link_history_data);
+                                       }
+                               }
+                       }
+
                        $location_data=$bolocation->initiate_ui_location(array(
                                'values'        => 
isset($values['location_data'])?$values['location_data']:'',
                                'type_id'       => -1, // calculated from 
location_types
@@ -2001,6 +2041,7 @@
 
                        $data = array
                                (
+                                       'custom_attributes'                     
        => array('attributes' => $values['attributes']),
                                        'contact_data'                          
        => $contact_data,
                                        'simple'                                
                => $this->_simple,
                                        'show_finnish_date'                     
        => $this->_show_finnish_date,
@@ -2058,7 +2099,7 @@
 
                        $GLOBALS['phpgw']->js->validate_file( 'yahoo', 
'tts.add', 'property' );
                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('property') . ' - ' . $appname . ': ' . $function_msg;
-                       
$GLOBALS['phpgw']->xslttpl->add_file(array('tts','files'));
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array('tts','files','attributes_form'));
                        $GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('add' 
=> $data));
                        //      $GLOBALS['phpgw']->xslttpl->pp();
                }
@@ -2304,6 +2345,8 @@
                        $values['b_account_id']         = 
phpgw::get_var('b_account_id', 'int', 'POST');
                        $values['b_account_name']       = 
phpgw::get_var('b_account_name', 'string', 'POST');
 
+                       $values_attribute                       = 
phpgw::get_var('values_attribute');
+
                        $receipt = 
$GLOBALS['phpgw']->session->appsession('receipt','property');
                        
$GLOBALS['phpgw']->session->appsession('receipt','property','');
                        if(!$receipt)
@@ -2311,7 +2354,7 @@
                                $receipt = array();
                        }
 
-                       $GLOBALS['phpgw']->xslttpl->add_file(array('tts', 
'files'));
+                       $GLOBALS['phpgw']->xslttpl->add_file(array('tts', 
'files', 'attributes_form'));
 
                        $historylog     = 
CreateObject('property.historylog','tts');
 
@@ -2379,8 +2422,20 @@
                                {
                                        $values['assignedto'] = $this->account;
                                }
-                               $receipt = 
$this->bo->update_ticket($values,$id, $receipt);
 
+                               if(isset($values_attribute) && 
is_array($values_attribute))
+                               {
+                                       foreach ($values_attribute as 
$attribute )
+                                       {
+                                               if($attribute['nullable'] != 1 
&& (!$attribute['value'] && !$values['extra'][$attribute['name']]))
+                                               {
+                                                       
$receipt['error'][]=array('msg'=>lang('Please enter value for attribute %1', 
$attribute['input_text']));
+                                               }
+                                       }
+                               }
+
+                               $receipt = 
$this->bo->update_ticket($values,$id, $receipt, $values_attribute);
+
                                if ( (isset($values['send_mail']) && 
$values['send_mail']) 
                                        || 
(isset($this->bo->config->config_data['mailnotification'])
                                        && 
$this->bo->config->config_data['mailnotification']
@@ -2443,9 +2498,35 @@
 
 
                        }
+
+                       /* Preserve attribute values from post */
+                       if(isset($receipt['error']) && (isset( 
$values_attribute) && is_array( $values_attribute)))
+                       {
+                               $values = 
$this->bocommon->preserve_attribute_values($values,$values_attribute);
+                       }
+
                        //---------end files
-                       $ticket = $this->bo->read_single($id);
+                       $ticket = $this->bo->read_single($id, $values);
 
+                       if (isset($ticket['attributes']) && 
is_array($ticket['attributes']))
+                       {
+                               foreach ($ticket['attributes'] as & $attribute)
+                               {
+                                       if($attribute['history'] == true)
+                                       {
+                                               $link_history_data = array
+                                                       (
+                                                               'menuaction'    
=> 'property.uiproject.attrib_history',
+                                                               'attrib_id'     
=> $attribute['id'],
+                                                               'id'            
=> $id,
+                                                               'edit'          
=> true
+                                                       );
+
+                                               $attribute['link_history'] = 
$GLOBALS['phpgw']->link('/index.php',$link_history_data);
+                                       }
+                               }
+                       }
+
                        $order_link                             = '';
                        $add_to_project_link    = '';
                        $request_link                   ='';
@@ -3085,6 +3166,7 @@
                        $order_catetory = 
$this->cats->formatted_xslt_list(array('select_name' => 
'values[cat_id]','selected' => $ticket['order_cat_id']));
                        $data = array
                                (
+                                       'custom_attributes'                     
        => array('attributes' => $ticket['attributes']),
                                        'send_response'                         
        => isset($this->bo->config->config_data['tts_send_response']) ? 
$this->bo->config->config_data['tts_send_response'] : '',
                                        'value_sms_phone'                       
        => $ticket['contact_phone'],
                                        'access_order'                          
        => $access_order,

Modified: trunk/property/templates/base/tts.xsl
===================================================================
--- trunk/property/templates/base/tts.xsl       2012-03-27 16:56:38 UTC (rev 
9051)
+++ trunk/property/templates/base/tts.xsl       2012-03-27 19:11:14 UTC (rev 
9052)
@@ -641,6 +641,7 @@
                                                                </xsl:choose>
                                                        </xsl:when>
                                                </xsl:choose>
+                                               <xsl:apply-templates 
select="custom_attributes/attributes"/>
                                                <tr>
                                                        <td valign="top">
                                                                <xsl:value-of 
select="php:function('lang', 'subject')"/>
@@ -1103,6 +1104,7 @@
                                                                        <input 
type="hidden" name="values[billable_hour]" value="{value_billable_hours}"/>
                                                                </xsl:otherwise>
                                                        </xsl:choose>
+                                                       <xsl:apply-templates 
select="custom_attributes/attributes"/>
                                                        <tr>
                                                                <td 
valign="top">
                                                                        
<xsl:value-of select="php:function('lang', 'new note')"/>




reply via email to

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