phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] tts inc/class.botts.inc.php inc/class.uitts.inc...


From: Dave Hall
Subject: [Phpgroupware-cvs] tts inc/class.botts.inc.php inc/class.uitts.inc...
Date: Thu, 21 Dec 2006 00:06:14 +0000

CVSROOT:        /cvsroot/phpgroupware
Module name:    tts
Changes by:     Dave Hall <skwashd>     06/12/21 00:06:14

Modified files:
        inc            : class.botts.inc.php class.uitts.inc.php 
        js/base        : search.js 
        templates/base : search.xsl 
Added files:
        templates/base : search_results.xsl 

Log message:
        added working search functionality

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/tts/inc/class.botts.inc.php?cvsroot=phpgroupware&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/tts/inc/class.uitts.inc.php?cvsroot=phpgroupware&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/tts/js/base/search.js?cvsroot=phpgroupware&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/tts/templates/base/search.xsl?cvsroot=phpgroupware&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/tts/templates/base/search_results.xsl?cvsroot=phpgroupware&rev=1.1

Patches:
Index: inc/class.botts.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/tts/inc/class.botts.inc.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- inc/class.botts.inc.php     17 Dec 2006 23:29:29 -0000      1.4
+++ inc/class.botts.inc.php     21 Dec 2006 00:06:13 -0000      1.5
@@ -5,7 +5,7 @@
        * @copyright Copyright (C) 2000-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
        * @package tts
-       * @version $Id: class.botts.inc.php,v 1.4 2006/12/17 23:29:29 skwashd 
Exp $
+       * @version $Id: class.botts.inc.php,v 1.5 2006/12/21 00:06:13 skwashd 
Exp $
        */
 
 
@@ -417,6 +417,11 @@
                        {
                                foreach ( $fields as $id => $field )
                                {
+                                       if ( !$field['search'] )
+                                       {
+                                               continue;
+                                       }
+
                                        $values[$id] = array
                                        (
                                                'field_name'    => $field['id'],
@@ -451,7 +456,10 @@
                                (
                                        'id'            => 'ticket_id',
                                        'label'         => lang('ticket id'),
+                                       'search'        => true,
+                                       'list'          => true,
                                        'type'          => 'hidden',
+                                       'datatype'      => 'I',
                                        'nullable'      => True
                                );
        
@@ -460,6 +468,9 @@
                                        'id'            => 'ticket_type',
                                        'label'         => lang('ticket type'),
                                        'type'          => 'hidden',
+                                       'search'        => true,
+                                       'list'          => false,
+                                       'datatype'      => 'I',
                                        'change_key'=> 'T',
                                        'nullable'      => False
                                );
@@ -469,7 +480,10 @@
                                        'id'            => 'ticket_group',
                                        'label'         => lang('user group'),
                                        'options'       => $this->_get_groups(),
+                                       'search'        => true,
+                                       'list'          => false,
                                        'type'          => 'select',
+                                       'datatype'      => 'I',
                                        'nullable'      => True
                                );
                                
@@ -479,7 +493,10 @@
                                        'label'         => lang('priority'),
                                        'options'       => 
$this->_get_priorities(),
                                        'type'          => 'select',
+                                       'search'        => true,
+                                       'list'          => false,
                                        'change_key'=> 'P',
+                                       'datatype'      => 'I',
                                        'nullable'      => True
                                );
        
@@ -488,6 +505,9 @@
                                        'id'            => 'ticket_owner',
                                        'label'         => lang('ticket owner'),
                                        'type'          => 'hidden',
+                                       'search'        => true,
+                                       'list'          => true,
+                                       'datatype'      => 'I',
                                        'nullable'      => True
                                );
        
@@ -498,6 +518,9 @@
                                        'options'       => 
$this->_get_users($cat_id),
                                        'type'          => 'select',
                                        'change_key'=> 'A',
+                                       'search'        => true,
+                                       'list'          => true,
+                                       'datatype'      => 'I',
                                        'nullable'      => True
                                );
        
@@ -507,8 +530,10 @@
                                        'label'         => lang('subject'),
                                        'type'          => 'textbox',
                                        'change_key'=> 'S',
+                                       'search'        => true,
+                                       'list'          => true,
+                                       'datatype'      => 'V',
                                        'nullable'      => False
-
                                );
 
                                $fields[] = array
@@ -517,6 +542,9 @@
                                        'label'         => lang('billable 
hours'),
                                        'type'          => 'textbox',
                                        'change_key'=> 'H',
+                                       'search'        => true,
+                                       'list'          => false,
+                                       'datatype'      => 'N',
                                        'nullable'      => True
                                );
        
@@ -526,6 +554,9 @@
                                        'label'         => lang('hourly rate'),
                                        'type'          => 'textbox',
                                        'change_key'=> 'B',
+                                       'search'        => true,
+                                       'list'          => false,
+                                       'datatype'      => 'N',
                                        'nullable'      => True
                                );
                                
@@ -535,6 +566,9 @@
                                        'label'         => lang('status'),
                                        'options'       => $this->_get_stati(),
                                        'type'          => 'select',
+                                       'search'        => true,
+                                       'list'          => true,
+                                       'datatype'      => 'C',
                                        'nullable'      => True
                                );
        
@@ -544,6 +578,9 @@
                                        'label'         => lang('deadline'),
                                        'type'          => 'date',
                                        'change_key'=> 'D',
+                                       'search'        => true,
+                                       'list'          => true,
+                                       'datatype'      => 'D',
                                        'nullable'      => True
                                );
        
@@ -553,6 +590,9 @@
                                        'label' => lang('effort'),
                                        'type'  => 'textbox',
                                        'change_key'=> 'E',
+                                       'search'        => true,
+                                       'list'          => false,
+                                       'datatype'      => 'V',
                                        'nullable'      => True
                                );
        
@@ -562,6 +602,9 @@
                                        'label'         => lang('details'),
                                        'type'          => 'memo',
                                        'change_key'=> 'C',
+                                       'search'        => true,
+                                       'list'          => false,
+                                       'datatype'      => 'M',
                                        'nullable'      => False
                                );
                        }
@@ -577,8 +620,11 @@
                                                'id'            => 
$cust_field['column_name'],
                                                //'help'        => 
lang($cust_field['status_text']),
                                                'label'         => 
lang($cust_field['name']),
-                                               'type'          => 
$this->_translate_cust_type($cust_field['datatype']),
+                                               'datatype'      => 
$cust_field['datatype'],
                                                'change_key'=> 'F',
+                                               'search'        => 
$cust_field['search'],
+                                               'list'          => 
$cust_field['list'],
+                                               'type'          => 
$this->_translate_cust_type($cust_field['datatype']),
                                                'nullable'      => 
$cust_field['nullable']
                                        );
                                        if ( isset($cust_field['choice']) )
@@ -850,29 +896,91 @@
                /**
                * Search for tickets
                *
-               * @param bool $caled_from_ui is the script being called from 
the UI layer or directly?
+               * @param array $args the search arguments
                * @return array the search results, empty array for nothing 
found
                */
-               function search($called_from_ui = false, $args = array() )
+               function search($args = array() )
                {
-                       if ( !$called_from_ui )
+                       $from_tbls = 'phpgw_tts_tickets';
+                       if ( $ttype_key = array_search('ttype', $args) )
                        {
-                               $args = (array) $_POST;
+                               $ttype = (int) $args['value'][$ttype_key];
+                               $from_tbls .= " phpgw_tts_c{$ttype}";
+                               $ttype_filter = $this->acl->check("C{$ttype}", 
PHPGW_ACL_READ, 'tts') ? "phpgw_tts_c{$ttype}.ticket_id = 
phpgw_tts_tickets.ticket_id" : '1 = 0';
+                               unset($args['value'][$ttype_key]);
+                       }
+                       else
+                       {
+                               $ttype = 0;
+                               $ttype_filter = 'phpgw_tts_tickets.ticket_type 
IN(\'' . implode('\',\'', $GLOBALS['phpgw']->acl->get_location_list('tts', 
PHPGW_ACL_READ)) . '\')';
                        }
 
-                       error_log(print_r($_POST, true));
+                       $fields = $this->get_fields($ttype);
 
                        $where = array();
                        foreach ( $args['value'] as $key => $val )
                        {
-                               $where[] = 
$this->_criteria2sql($args['field'][$key], $args['stype'][$key], $val);
+                               $where[] = 
$this->_criteria2sql($args['field'][$key], $args['stype'][$key], $val, $fields);
+                       }
+
+                       $show_fields = array();
+                       $headings = array();
+                       foreach ( $fields as $id => $field )
+                       {
+                               if ( $field['list'] )
+                               {
+                                       $show_fields[$id] = $field['id'];
+                                       $headings[$id] = $field['label'];
+                               }
                        }
 
-                       return '';
+                       $defaults = array('date' => lang('not specified'), 
'lookup' => lang('invalid') );
+
+                       $concat = ($args['search_type'] == 'AND' ? ' AND ' : ' 
OR ');
+
+                       $sql = 'SELECT ' . implode(',', $show_fields) . " FROM 
{$from_tbls} WHERE (" . implode($concat, $where) . ") AND {$ttype_filter}";
+                       trigger_error("SQL: $sql", E_USER_NOTICE);
+                       $this->db->query($sql, __LINE__, __FILE__);
 
-                       $concat = ($_POST['search_type'] == 'AND' ? ' AND ' : ' 
OR ');
 
-                       $sql = 'SELECT * FROM phpgw_tts_tickets WHERE ' . 
implode($concat, $where);
+                       $results = array();
+                       while ( $this->db->next_record() )
+                       {
+                               $id = (int) $this->db->f('ticket_id');
+                               foreach ( $show_fields as $key => $field )
+                               {
+                                       $results[$id][$field] = 
$this->db->f($field, true);
+                                       if ( isset($fields[$key]['options']) 
+                                               && 
is_array($fields[$key]['options']) )
+                                       {
+                                               $found = false;
+                                               foreach ( 
$fields[$key]['options'] as $option )
+                                               {
+                                                       if ( $option['id'] == 
$results[$id][$field] )
+                                                       {
+                                                               
$results[$id][$field] = $option['value'];
+                                                               $found = true;
+                                                       }
+                                               }
+                                               if ( !$found )
+                                               {
+                                                       $results[$id][$field] = 
$defaults['lookup'];
+                                               }
+                                       }
+                                       else if ( $fields[$key]['datatype'] == 
'D' )
+                                       {
+                                               if ( $results[$id][$field] == 0 
)
+                                               {
+                                                       $results[$id][$field] = 
$defaults['date'];
+                                               }
+                                               else
+                                               {
+                                                       $results[$id][$field] = 
date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'], 
$results[$id][$field]);
+                                               }
+                                       }
+                               }
+                       }
+                       return array('results' => $results, 'headings' => 
$headings);
                }
 
                /**
@@ -1001,15 +1109,78 @@
                /**
                * Convert a search criteria entry to a snippet of SQL
                */
-               function _criteria2sql($field, $stype, $val)
+               function _criteria2sql($field_name, $stype, $val, $field_list)
                {
-                       error_log("field $field, stype $stype, val $val");
-                       $ftype = $this->_get_field_type($field);
-               }
-
-               function _get_field_type($field)
+                       $sql = '1 = 1';
+                       foreach ( $field_list as $entry )
                {
-                       
+                               if ( $entry['id'] == $field_name 
+                                       && $entry['search'] )
+                               {
+                                       $is_string = '';
+                                       $sql = 
$this->db->db_addslashes($field_name) . ' ';
+                                       switch ( strtolower($entry['datatype']) 
)
+                                       {
+                                               case 'i': //int
+                                               case 'r': //radio boxes
+                                               case 'lb': //select
+                                               case 'ch': //checkboxes
+                                               case 'ab': //addressbook
+                                               case 'vendor':
+                                                       $val = (int) $val;
+                                                       break;
+                                               case 'f': //float
+                                                       $val = (float) $val;
+                                                       break;
+                                               case 'c': //char
+                                               case 'v': //varchar
+                                               case 'email':
+                                               case 'link':
+                                               default: //anything else
+                                                       $val = 
$this->db->db_addslashes($val);
+                                                       $is_string = true;
+                                       }
+
+                                       switch ( $stype )
+                                       {
+                                               case 'is_not':
+                                               case 'not_equals':
+                                                       $sql = $is_string ? 
"$field_name != '$val'" : "$field_name != $val";
+                                                       break;
+                                               case 'before':
+                                               case 'less_than':
+                                                       $sql = "$field_name < 
$val";
+                                                       break;
+                                               case 'after':
+                                               case 'greater_than':
+                                                       $sql = "$field_name > 
$val";
+                                                       break;
+                                               case 'contains':
+                                                       $sql = "$field_name 
LIKE '%$val%'";
+                                                       break;
+                                               case 'not_contains':
+                                                       $sql = "$field_name NOT 
LIKE '%$val%'";
+                                                       break;
+                                               case 'starts':
+                                                       $sql = "$field_name 
LIKE '$val%'";
+                                                       break;
+                                               case 'not_starts':
+                                                       $sql = "$field_name NOT 
LIKE '$val%'";
+                                                       break;
+                                               case 'ends':
+                                                       $sql = "$field_name 
LIKE '%$val'";
+                                                       break;
+                                               case 'not_ends':
+                                                       $sql = "$field_name NOT 
LIKE '%$val'";
+                                                       break;
+                                               case 'is':
+                                               case 'equals':
+                                               default:
+                                                       $sql = $is_string ? 
"$field_name = '$val'" : "$field_name = $val";
+                                       }
+                               }
+                       }
+                       return $sql;
                }
                
                /**
@@ -1077,8 +1248,17 @@
                 */
                function _get_users($cat_id)
                {
+                       if ( $cat_id == 0 )
+                       {
+                               $loc = '.';
+                       }
+                       else
+                       {
+                               $loc = "C{$cat_id}";
+                       }
+
                        $users = array();
-                       $grants = 
$GLOBALS['phpgw']->acl->get_ids_for_location("C{$cat_id}", PHPGW_ACL_EDIT, 
'tts');
+                       $grants = 
$GLOBALS['phpgw']->acl->get_ids_for_location($loc, PHPGW_ACL_EDIT, 'tts');
                        if ( is_array($grants ) && count($grants) )
                        {
                                foreach ( $grants as $uid )

Index: inc/class.uitts.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/tts/inc/class.uitts.inc.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- inc/class.uitts.inc.php     17 Dec 2006 23:29:29 -0000      1.5
+++ inc/class.uitts.inc.php     21 Dec 2006 00:06:13 -0000      1.6
@@ -5,7 +5,7 @@
        * @copyright Copyright (C) 2000-2006 Free Software Foundation, Inc. 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
        * @package tts
-       * @version $Id: class.uitts.inc.php,v 1.5 2006/12/17 23:29:29 skwashd 
Exp $
+       * @version $Id: class.uitts.inc.php,v 1.6 2006/12/21 00:06:13 skwashd 
Exp $
        */
        
        class uitts
@@ -361,9 +361,29 @@
                */
                function search()
                {
-                       $GLOBALS['phpgw']->common->phpgw_header(true);
-                       echo 'coming soon! :)';
-                       $GLOBALS['phpgw']->common->phpgw_exit();
+                       if ( isset($_GET['search_mode']) )
+                       {
+                               if ( $_GET['search_mode'] == 'adv' )
+                               {
+                                       $results = $this->bo->search((array) 
$_GET);
+                               }
+                               else
+                               {
+                                       $results = array();
+                               }
+
+                               $GLOBALS['phpgw_info']['flags']['xslt_app'] = 
true;
+                               
$GLOBALS['phpgw']->xslttpl->add_file('search_results');
+
+                               $results['lang'] = array
+                               (
+                                       'search_results'        => lang('search 
results')
+                               );
+
+                               $GLOBALS['phpgw']->xslttpl->set_var('phpgw', 
array('search_results' => $results) );
+                               $GLOBALS['phpgw']->common->phpgw_exit(true);
+                       }
+
                        $GLOBALS['phpgw_info']['flags']['xslt_app'] = true;
                        $GLOBALS['phpgw']->xslttpl->add_file('search');
                        if ( !isset($GLOBALS['phpgw']->js) || 
!is_object($GLOBALS['phpgw']->js) )

Index: js/base/search.js
===================================================================
RCS file: /cvsroot/phpgroupware/tts/js/base/search.js,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- js/base/search.js   17 Dec 2006 23:29:29 -0000      1.1
+++ js/base/search.js   21 Dec 2006 00:06:13 -0000      1.2
@@ -343,6 +343,12 @@
                return false; //ignore it
        }
 
+       if ( xhr.status != 200 )
+       {
+               alert('ERROR');
+               return false;
+       }
+
        var responseData = eval(xhr.responseText);
        if ( typeof(responseData) != 'object'
                || !responseData.length )
@@ -390,8 +396,6 @@
                
arSelects[i].parentNode.appendChild(addFieldLookup(arFields[arSelects[i].options.selectedIndex],
 arSelects[i].id.substr(9) ) );
                
arSelects[i].parentNode.appendChild(addSearchValue(arFields[arSelects[i].options.selectedIndex],
 arSelects[i].id.substr(9) ) );
        }
-       //unset the xhr obj
-       xhr = null;
 }
 
 function hideLoading()
@@ -474,7 +478,7 @@
 }
 
 // TODO Move me
-function form2POST()
+function form2String()
 {
        var strForm = '';
        
@@ -506,7 +510,10 @@
                return !alert('You must specify at least one field');
        }
        
-       var strPOST = form2POST() + 'search_type=' + 
encodeURI(document.getElementById('tts_search_type'));
+       var strForm = form2String() + 'search_type=' + 
encodeURI(document.getElementById('tts_search_type').options[document.getElementById('tts_search_type').selectedIndex].value);
+
+       window.location = phpGWLink('/index.php', {menuaction : 
'tts.uitts.search'}) + '&' + strForm + '&search_mode=adv';
+       return false;
 
        displayLoading();
 
@@ -516,11 +523,30 @@
        xhr.setRequestHeader("Content-length", strPOST.length);
        xhr.onreadystatechange = function()
        {
-               
-               if ( xhr.readyState == 4 )
+               if ( xhr.readyState != 4 )
                {
+                       return false;
+               }
+
                        hideLoading();
+               if ( xhr.status != 200 )
+               {
+                       alert('ERROR');
+                       return false;
                }
+               arEntries = eval(xhr.responseText);
+               
+               var elmTarget = document.getElementById('tts_search_results');
+               elmTarget.innerHTML = '';
+
+               alert('# == ' + arEntries.length);
+               
+               if ( !arEntries.length )
+               {
+                       elmTarget.innerHTML = '<strong>Nothing found, try 
again</strong>';
+                       return false;
+               }
+
        }
        xhr.send(strPOST);
        return false;

Index: templates/base/search.xsl
===================================================================
RCS file: /cvsroot/phpgroupware/tts/templates/base/search.xsl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- templates/base/search.xsl   17 Dec 2006 23:29:29 -0000      1.1
+++ templates/base/search.xsl   21 Dec 2006 00:06:13 -0000      1.2
@@ -65,6 +65,10 @@
                                        <input type="submit" 
name="tts_search_cancel" id="tts_search_cancel" value="Cancel" 
onclick="window.location='http://google.com';"/>
                                        <input type="submit" 
name="tts_search_ok" id="tts_search_ok" value="{lang/search}" 
onclick="submitAdvSearch(); return false;"/>
                                </fieldset>
+
+                               <div id="tts_search_results">
+                               </div>
+
                        </form>
                </div>
        </xsl:template>

Index: templates/base/search_results.xsl
===================================================================
RCS file: templates/base/search_results.xsl
diff -N templates/base/search_results.xsl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ templates/base/search_results.xsl   21 Dec 2006 00:06:14 -0000      1.1
@@ -0,0 +1,33 @@
+       <xsl:template match="search_results">
+               <div id="tts_search_results">
+                       <h1><xsl:value-of select="lang/search_results" /></h1>
+                       <table>
+                               <thead>
+                                       <tr>
+                                               <xsl:for-each select="headings">
+                                                       <th><xsl:value-of 
select="." /></th>
+                                               </xsl:for-each>
+                                       </tr>
+                               </thead>
+                               <tbody>
+                                       <xsl:for-each select="results">
+                                               <tr id="record_{ticket_id}">
+                                                       <xsl:attribute 
name="class">
+                                                                       
<xsl:choose>
+                                                                               
        <xsl:when test="position() mod 2 = 0">
+                                                                               
                        <xsl:text>row_off</xsl:text>
+                                                                               
        </xsl:when>
+                                                                               
        <xsl:otherwise>
+                                                                               
                        <xsl:text>row_on</xsl:text>
+                                                                               
        </xsl:otherwise>
+                                                                       
</xsl:choose>
+                                                       </xsl:attribute>
+                                                       <xsl:for-each 
select="*">
+                                                               
<td><xsl:value-of select="." /></td>
+                                                       </xsl:for-each>
+                                               </tr>
+                                       </xsl:for-each>
+                               </tbody>
+                       </table>
+               </div>
+       </xsl:template>




reply via email to

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