fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [6607] Property: more on generic code


From: Sigurd Nes
Subject: [Fmsystem-commits] [6607] Property: more on generic code
Date: Wed, 17 Nov 2010 10:34:08 +0000

Revision: 6607
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=6607
Author:   sigurdne
Date:     2010-11-17 10:34:08 +0000 (Wed, 17 Nov 2010)
Log Message:
-----------
Property: more on generic code

Modified Paths:
--------------
    trunk/property/inc/class.bocategory.inc.php
    trunk/property/inc/class.bocommon.inc.php
    trunk/property/inc/class.socategory.inc.php
    trunk/property/inc/class.uicategory.inc.php
    trunk/property/templates/base/category.xsl

Modified: trunk/property/inc/class.bocategory.inc.php
===================================================================
--- trunk/property/inc/class.bocategory.inc.php 2010-11-17 10:33:13 UTC (rev 
6606)
+++ trunk/property/inc/class.bocategory.inc.php 2010-11-17 10:34:08 UTC (rev 
6607)
@@ -65,6 +65,7 @@
                {
                        $this->so                       = 
CreateObject('property.socategory');
                        $this->custom           = & $this->so->custom;
+                       $this->bocommon         = 
CreateObject('property.bocommon');
 
                        $start                          = 
phpgw::get_var('start', 'int', 'REQUEST', 0);
                        $query                          = 
phpgw::get_var('query');
@@ -76,6 +77,9 @@
                        $type                           = 
phpgw::get_var('type');
                        $type_id                        = 
phpgw::get_var('type_id', 'int');
 
+                       $this->type_id          = $type;
+                       $this->type_id          = $type_id;
+
                        if ($session)
                        {
                                $this->read_sessiondata($type);
@@ -122,9 +126,21 @@
                        return $this->so->get_location_info($type,$type_id);
                }
 
+               function column_list($selected='',$allrows='')
+               {
+                       if(!$selected)
+                       {
+                               $selected = 
$GLOBALS['phpgw_info']['user']['preferences']['property']["generic_columns_{$this->type}_{$this->type_id}"];
+                       }
+                       $filter = array('list' => ''); // translates to "list 
IS NULL"
+                       $columns = 
$this->custom->find('property',$this->location_info['acl_location'], 0, 
'','','',true, false, $filter);
+                       
$column_list=$this->bocommon->select_multi_list($selected,$columns);
+
+                       return $column_list;
+               }
+
                public function read($filter = array())
                {
-
                        if (! $filter )
                        {
                                foreach ( $this->location_info['fields'] as 
$field )
@@ -202,7 +218,7 @@
                        $values = $this->so->get_list($data);
                        foreach ($values as &$entry)
                        {
-                               $entry['selected'] = isset($data['selected']) 
&& $data['selected'] == $entry['id'] ? 1 : 0;
+                               $entry['selected'] = isset($data['selected']) 
&& trim($data['selected']) == trim($entry['id']) ? 1 : 0;
                        }
                        return $values;
                }

Modified: trunk/property/inc/class.bocommon.inc.php
===================================================================
--- trunk/property/inc/class.bocommon.inc.php   2010-11-17 10:33:13 UTC (rev 
6606)
+++ trunk/property/inc/class.bocommon.inc.php   2010-11-17 10:34:08 UTC (rev 
6607)
@@ -2221,4 +2221,22 @@
                {
                        return 
$this->socommon->set_pending_action($action_params);
                }
+
+               public function get_categories($data)
+               {
+                       $cats   = CreateObject('phpgwapi.categories', -1,  
'property', $data['acl_location']);
+                       $cats->supress_info = true;
+                       $values = $cats->formatted_xslt_list(array('selected' 
=> $data['selected'], 'globals' => true, 'link_data' =>array()));
+                       $ret = array();
+                       foreach ($values['cat_list'] as $category)
+                       {
+                               $ret[] = array
+                               (
+                                       'id'            => $category['cat_id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => 
$category['selected'] ? 1 : 0
+                               );
+                       }
+                       return $ret;
+               }
        }

Modified: trunk/property/inc/class.socategory.inc.php
===================================================================
--- trunk/property/inc/class.socategory.inc.php 2010-11-17 10:33:13 UTC (rev 
6606)
+++ trunk/property/inc/class.socategory.inc.php 2010-11-17 10:34:08 UTC (rev 
6607)
@@ -34,6 +34,8 @@
 
        class property_socategory
        {
+               var $type;
+               var $type_id;
                var $location_info = array();
 
                function __construct()
@@ -59,6 +61,7 @@
                                return $values;
                        }
 
+/*
                        $valid_order = false;
 
                        if($order)
@@ -82,20 +85,24 @@
 
                                if(!$valid_order)
                                {
-                                       $order = '';
+//                                     $order = '';
                                }                       
                        }
-
+*/
                        $_filter_array = array();
                        $get_single = array();
                        foreach ( $this->location_info['fields'] as $field )
                        {
                                if (isset($field['filter']) && $field['filter'])
                                {
-                                       if(isset($filter[$field['name']]) && 
$filter[$field['name']])
+                                       if(isset($filter[$field['name']]) && 
$filter[$field['name']] && $field['type'] == 'multiple_select')
                                        {
-                                               $_filter_array[] = 
"{$field['name']} = '{$filter[$field['name']]}'";
+                                               $_filter_array[] = 
"{$field['name']} {$this->_like} '%,{$filter[$field['name']]},%'";
                                        }
+                                       else if(isset($filter[$field['name']]) 
&& $filter[$field['name']])
+                                       {
+                                               $_filter_array[] = 
"{$field['name']} = '{$filter[$field['name']]}'";                               
     
+                                       }
                                }
                                if (isset($field['get_single']) && 
$field['get_single'])
                                {
@@ -112,7 +119,7 @@
 
                        foreach($this->location_info['fields'] as $field)
                        {
-                               $uicols['input_type'][]         = 'text';
+                               $uicols['input_type'][]         = 
isset($field['hidden']) && $field['hidden'] ? 'hidden' : 'text';
                                $uicols['name'][]                       = 
$field['name'];
                                $uicols['descr'][]                      = 
$field['descr'];
                                $uicols['datatype'][]           = 'V';
@@ -121,14 +128,21 @@
 
                        
if($GLOBALS['phpgw']->locations->get_attrib_table('property', 
$this->location_info['acl_location']))
                        {
-
                                $choice_table = 'phpgw_cust_choice';
                                $attribute_table = 'phpgw_cust_attribute';
                                $location_id = 
$GLOBALS['phpgw']->locations->get_id('property', 
$this->location_info['acl_location']);
                                $attribute_filter = " location_id = 
{$location_id}";
 
-                               $this->_db->query("SELECT * FROM 
$attribute_table WHERE list=1 AND $attribute_filter ORDER BY attrib_sort ASC");
+                               $user_columns = 
isset($GLOBALS['phpgw_info']['user']['preferences']['property']["generic_columns_{$this->type}_{$this->type_id}"])?$GLOBALS['phpgw_info']['user']['preferences']['property']["generic_columns_{$this->type}_{$this->type_id}"]:'';
 
+                               $user_column_filter = '';
+                               if (isset($user_columns) AND 
is_array($user_columns) AND $user_columns[0])
+                               {
+                                       $user_column_filter = " OR 
($attribute_filter AND id IN (" . implode(',',$user_columns) .'))';
+                               }
+
+                               $this->_db->query("SELECT * FROM 
$attribute_table WHERE list=1 AND $attribute_filter $user_column_filter ORDER 
BY attrib_sort ASC");
+
                                $i      = count($uicols['name']);
                                while ($this->_db->next_record())
                                {
@@ -147,6 +161,7 @@
                                        $i++;
                                }
                        }
+
                        $where = 'WHERE';
                        $filtermethod = '';
                        if(isset($this->location_info['check_grant']) && 
$this->location_info['check_grant'])
@@ -182,23 +197,57 @@
                                {
                                        $id_query = "'{$query}'";
                                }
-
                                $query = $this->_db->db_addslashes($query);
                                $querymethod = " {$where } 
({$table}.{$this->location_info['id']['name']} = {$id_query}";
+//_debug_array($filtermethod);
+//_debug_array($where);die();
+
                                foreach($this->location_info['fields'] as 
$field)
                                {
                                        if($field['type'] == 'varchar')
                                        {
                                                $querymethod .= " OR 
{$table}.{$field['name']} $this->_like '%$query%'";
                                        }
+                                       $where = 'OR';
                                }
                                $querymethod .= ')';
+
+                               $_querymethod = array();
+
+                               $this->_db->query("SELECT * FROM 
$attribute_table WHERE $attribute_filter AND search='1'",__LINE__,__FILE__);
+
+                               while ($this->_db->next_record())
+                               {
+                                       if($this->_db->f('datatype')=='V' || 
$this->_db->f('datatype')=='email' || $this->_db->f('datatype')=='CH'):
+                                       {
+                                               $_querymethod[]= "$table." . 
$this->_db->f('column_name') . " {$this->_like} '%{$query}%'";
+                                       }
+                                       elseif($this->_db->f('datatype')=='I'):
+                                       {
+                                               if(ctype_digit($query))
+                                               {
+                                                       $_querymethod[]= 
"$table." . $this->_db->f('column_name') . '=' . (int)$query;
+                                               }
+                                       }
+                                       else:
+                                       {
+                                               $_querymethod[]= "$table." . 
$this->_db->f('column_name') . " = '$query'";
+                                       }
+                                       endif;
+                               }
+
+                               if (isset($_querymethod) AND 
is_array($_querymethod))
+                               {
+                                       $querymethod .= " $where (" . implode 
(' OR ',$_querymethod) . ')';
+                               }
+
                        }
 
                        $sql = "SELECT * FROM $table $filtermethod 
$querymethod";
 
-                       $this->_db->query($sql,__LINE__,__FILE__);
-                       $this->total_records = $this->_db->num_rows();
+                       $this->_db->query('SELECT count(*) as cnt ' . 
substr($sql,strripos($sql,'from')),__LINE__,__FILE__);
+                       $this->_db->next_record();
+                       $this->total_records = $this->_db->f('cnt');
 
                        if(!$allrows)
                        {
@@ -261,7 +310,10 @@
 
                function get_location_info($type,$type_id)
                {
-                       $type_id = (int)$type_id;
+                       $type_id                = (int)$type_id;
+                       $this->type             = $type;
+                       $this->type_id  = $type_id;
+
                        $info = array();
                        switch($type)
                        {
@@ -558,7 +610,7 @@
                                case 'vendor':
                                        $info = array
                                        (
-                                               'table' => 'fm_vendor',
+                                               'table'                         
=> 'fm_vendor',
                                                'id'                            
=> array('name' => 'id', 'type' => 'int'),
                                                'fields'                        
=> array
                                                (
@@ -588,22 +640,19 @@
                                                                //FIXME
                                                                'name'          
        => 'member_of',
                                                                'descr'         
        => lang('member'),
-                                                               'type'          
        => 'select', // multiple_select
+                                                               'type'          
        => 'multiple_select',
                                                                'nullable'      
        => false,
                                                                'filter'        
        => true,
-                                                               'sortable'      
=> true,
+                                                               'sortable'      
        => false,
+                                                               'hidden'        
        => true,
                                                                'values_def'    
=> array
                                                                (
                                                                        
'valueset'              => false,
-                                                                       
'method'                => 'phpgwapi.categories.formatted_xslt_list',
-                                                                       
'method_input'  => array('type' => 'vendor_cats',       'selected' => 
'##member_of##')
+                                                                       
'method'                => 'property.bocommon.get_categories',
+                                                                       
'method_input'  => array('app' => 'property', 'acl_location' => '.vendor',      
'selected' => '##member_of##')
                                                                )
                                                        ),
                                                ),
-
-//                             $values_combo_box[0]  = 
$this->cats->formatted_xslt_list(array('selected' => $this->member_id,'globals' 
=> true));
-
-
                                                'edit_msg'      => lang('edit'),
                                                'add_msg'       => lang('add'),
                                                'name'          => 
lang('vendor'),
@@ -1532,6 +1581,18 @@
                        {
                                unset($data['apply']);
                        }
+
+                       foreach ( $this->location_info['fields'] as $field )
+                       {
+                               if (isset($field['filter']) && $field['filter'])
+                               {
+                                       if(isset($data[$field['name']]) && 
$data[$field['name']] && $field['type'] == 'multiple_select')
+                                       {
+                                               $data[$field['name']] = ',' . 
implode(',',$data[$field['name']]) . ',';
+                                       }
+                               }
+                       }
+
                        $cols = array();
                        $vals = array();
 
@@ -1654,6 +1715,14 @@
                        }
                        foreach($this->location_info['fields'] as $field)
                        {
+                               if (isset($field['filter']) && $field['filter'])
+                               {
+                                       if(isset($data[$field['name']]) && 
$data[$field['name']] && $field['type'] == 'multiple_select')
+                                       {
+                                               $data[$field['name']] = ',' . 
implode(',',$data[$field['name']]) . ',';
+                                       }
+                               }
+
                                $value_set[$field['name']] = 
$this->_db->db_addslashes($data[$field['name']]);
                        }
 

Modified: trunk/property/inc/class.uicategory.inc.php
===================================================================
--- trunk/property/inc/class.uicategory.inc.php 2010-11-17 10:33:13 UTC (rev 
6606)
+++ trunk/property/inc/class.uicategory.inc.php 2010-11-17 10:34:08 UTC (rev 
6607)
@@ -50,7 +50,8 @@
                        'view'   => true,
                        'edit'   => true,
                        'delete' => true,
-                       'download'      => true
+                       'download'      => true,
+                       'columns'       => true,
                );
 
                function __construct()
@@ -58,7 +59,7 @@
                        $GLOBALS['phpgw_info']['flags']['xslt_app'] = true;
                        $this->account                          = 
$GLOBALS['phpgw_info']['user']['account_id'];
                        $this->bo                                       = 
CreateObject('property.bocategory',true);
-                       $this->bocommon                         = 
CreateObject('property.bocommon');
+                       $this->bocommon                         = & 
$this->bo->bocommon;
                        $this->custom                           = & 
$this->bo->custom;
 
                        $this->location_info            = 
$this->bo->location_info;
@@ -99,6 +100,59 @@
                        
$this->bocommon->download($list,$uicols['name'],$uicols['descr'],$uicols['input_type']);
                }
 
+               function columns()
+               {
+
+                       //cramirez: necesary for windows.open . Avoid error JS
+                       phpgwapi_yui::load_widget('tabview');
+
+                       $GLOBALS['phpgw']->xslttpl->add_file(array('columns'));
+                       $GLOBALS['phpgw_info']['flags']['noframework'] = true;
+                       $values = phpgw::get_var('values');
+
+                       $type           = phpgw::get_var('type');
+                       $type_id        = phpgw::get_var('type_id', 'int');
+
+                       if ($values['save'])
+                       {
+                               $GLOBALS['phpgw']->preferences->account_id = 
$this->account;
+                               $GLOBALS['phpgw']->preferences->read();
+                               
$GLOBALS['phpgw']->preferences->add('property',"generic_columns_{$type}_{$type_id}",$values['columns'],'user');
+                               
$GLOBALS['phpgw']->preferences->save_repository();
+
+                               $receipt['message'][] = array('msg' => 
lang('columns is updated'));
+                       }
+
+                       $function_msg   = lang('Select Column');
+
+                       $link_data = array
+                       (
+                       'menuaction'    => 'property.uicategory.columns',
+                               'type'                  => $type,
+                               'type_id'               => $type_id
+
+                       );
+
+                       $msgbox_data = $this->bocommon->msgbox_data($receipt);
+
+                       $data = array
+                       (
+                               'msgbox_data'   => 
$GLOBALS['phpgw']->common->msgbox($msgbox_data),
+                               'column_list'   => 
$this->bo->column_list($values['columns'],$allrows=true),
+                               'function_msg'  => $function_msg,
+                               'form_action'   => 
$GLOBALS['phpgw']->link('/index.php',$link_data),
+                               'lang_columns'  => lang('columns'),
+                               'lang_none'             => lang('None'),
+                               'lang_save'             => lang('save'),
+                               'select_name'   => 'period'
+                       );
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
$function_msg;
+                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('columns' => $data));
+               }
+
+
+
                function index()
                {
                        if(!$this->acl_read)
@@ -199,6 +253,23 @@
                                        )
                                );
 
+
+                               
if($GLOBALS['phpgw']->locations->get_attrib_table('property', 
$this->location_info['acl_location']))
+                               {
+                                       
$datatable['actions']['form'][0]['fields']['field'][] =  array(
+                                                                               
                                'type'=> 'link',
+                                                                               
                                'id'  => 'btn_columns',
+                                                                               
                                'url' => 
"Javascript:window.open('".$GLOBALS['phpgw']->link('/index.php',
+                                                                               
                                array(
+                                                                               
                                        'menuaction' => 
'property.uicategory.columns',
+                                                                               
                                        'type'                  => $type,
+                                                                               
                                        'type_id'               => $type_id
+                                                                               
                                        ))."','','width=350,height=370')",
+                                                                               
                                'value' => lang('columns'),
+                                                                               
                                'tab_index' => 7
+                                                                               
            );
+                               }
+
                                $values_combo_box = array();
                                $i = 0;
                                $button_def = array();
@@ -252,7 +323,6 @@
                                        $GLOBALS['phpgw']->js->add_code('', 
$code);
                                }
 
-
                                if($values_combo_box)
                                {
                                        $i = 0;
@@ -607,12 +677,19 @@
                        }
 
                        /* Preserve attribute values from post */
-                       if(isset($receipt['error']) && (isset( 
$values_attribute) && is_array( $values_attribute)))
+                       if(isset($receipt['error']))
                        {
-                               $values = 
$this->custom->preserve_attribute_values($values,$values_attribute);
+                               foreach ( $this->location_info['fields'] as 
$field )
+                               {
+                                       $values[$field['name']] = 
phpgw::clean_value($_POST['values'][$field['name']]);
+                               }
+
+                               if(isset( $values_attribute) && is_array( 
$values_attribute))
+                               {
+                                       $values = 
$this->custom->preserve_attribute_values($values,$values_attribute);
+                               }
                        }
 
-
                        $link_data = array
                        (
                                'menuaction'    => 'property.uicategory.edit',
@@ -620,7 +697,6 @@
                                'type'                  => $type,
                                'type_id'               => $type_id
                        );
-//_debug_array($link_data);
 
                        $tabs = array();
 

Modified: trunk/property/templates/base/category.xsl
===================================================================
--- trunk/property/templates/base/category.xsl  2010-11-17 10:33:13 UTC (rev 
6606)
+++ trunk/property/templates/base/category.xsl  2010-11-17 10:34:08 UTC (rev 
6607)
@@ -121,6 +121,18 @@
                                                                </xsl:for-each>
                                                        </select>
                                                </xsl:when>
+                                               <xsl:when 
test="type='multiple_select'">
+                                                       <select 
name="values[{name}][]" multiple="multiple">
+                                                               <xsl:for-each 
select="valueset" >
+                                                                       <option 
value="{id}">
+                                                                               
<xsl:if test="selected != 0">
+                                                                               
        <xsl:attribute name="selected" value="selected" />
+                                                                               
</xsl:if>
+                                                                               
<xsl:value-of select="name"/>
+                                                                       
</option>                                               
+                                                               </xsl:for-each>
+                                                       </select>
+                                               </xsl:when>
                                        </xsl:choose>
                                </td>
                        </tr>




reply via email to

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