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 class.uitts.inc.php


From: Dave Hall
Subject: [Phpgroupware-cvs] tts/inc class.botts.inc.php class.uitts.inc.php
Date: Wed, 29 Nov 2006 12:53:23 +0000

CVSROOT:        /cvsroot/phpgroupware
Module name:    tts
Changes by:     Dave Hall <skwashd>     06/11/29 12:53:23

Modified files:
        inc            : class.botts.inc.php class.uitts.inc.php 

Log message:
        add some basic validation, still need to be able to add error messages

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/tts/inc/class.botts.inc.php?cvsroot=phpgroupware&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/tts/inc/class.uitts.inc.php?cvsroot=phpgroupware&r1=1.3&r2=1.4

Patches:
Index: class.botts.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/tts/inc/class.botts.inc.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- class.botts.inc.php 28 Nov 2006 10:09:32 -0000      1.2
+++ class.botts.inc.php 29 Nov 2006 12:53:23 -0000      1.3
@@ -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.2 2006/11/28 10:09:32 skwashd 
Exp $
+       * @version $Id: class.botts.inc.php,v 1.3 2006/11/29 12:53:23 skwashd 
Exp $
        */
 
 
@@ -16,12 +16,45 @@
        */      
        class botts
        {
+               /**
+               * @var object $cats reference to the categories object
+               */
+               var $cats;
+               
+               /**
+               * @var object $custom reference to the custom fields object
+               */
                var $custom;
+
+               /**
+               * @var object $db reference to the global database object
+               */
                var $db;
-               var $cats;
-               var $so;
+
+               /**
+               * @var array $errors errors which have occured
+               */
+               var $errors;
+               
+               /**
+               * @var object $historylog reference to the history log object
+               */
                var $historylog;
+
+               
+               /**
+               * @var object $so does nothing as bo and so is combined
+               */
+               var $so;
+
+               /**
+               * @var int $total records - not used
+               */
                var $total_records;
+
+               /**
+               * @var array $public_methods the publicly available methods of 
this class
+               */
                var $public_methods = array
                (
                        'list_methods' => true
@@ -381,14 +414,16 @@
                                $fields[] = array
                                (
                                        'id'    => 'ticket_id',
-                                       'type'  => 'hidden'
+                                       'type'          => 'hidden',
+                                       'nullable'      => True
                                );
        
                                $fields[] = array
                                (
                                        'id'            => 'ticket_type',
                                        'type'          => 'hidden',
-                                       'change_key'=> 'T'
+                                       'change_key'=> 'T',
+                                       'nullable'      => False
                                );
                                
                                $fields[] = array
@@ -396,7 +431,8 @@
                                        'id'            => 'ticket_group',
                                        'label'         => lang('user group'),
                                        'options'       => $this->_get_groups(),
-                                       'type'          => 'select'
+                                       'type'          => 'select',
+                                       'nullable'      => True
                                );
                                
                                $fields[] = array
@@ -405,14 +441,16 @@
                                        'label'         => lang('priority'),
                                        'options'       => 
$this->_get_priorities(),
                                        'type'          => 'select',
-                                       'change_key'=> 'P'
+                                       'change_key'=> 'P',
+                                       'nullable'      => True
                                );
        
                                $fields[] = array
                                (
                                        'id'            => 'ticket_owner',
                                        'label'         => lang('ticket owner'),
-                                       'type'          => 'hidden'
+                                       'type'          => 'hidden',
+                                       'nullable'      => True
                                );
        
                                $fields[] = array
@@ -421,7 +459,8 @@
                                        'label'         => lang('assigned to'),
                                        'options'       => 
$this->_get_users($cat_id),
                                        'type'          => 'select',
-                                       'change_key'=> 'A'
+                                       'change_key'=> 'A',
+                                       'nullable'      => True
                                );
        
                                $fields[] = array
@@ -429,7 +468,9 @@
                                        'id'            => 'ticket_subject',
                                        'label'         => lang('subject'),
                                        'type'          => 'textbox',
-                                       'change_key'=> 'S'
+                                       'change_key'=> 'S',
+                                       'nullable'      => False
+
                                );
 
                                $fields[] = array
@@ -437,7 +478,8 @@
                                        'id'            => 
'ticket_billable_hours',
                                        'label'         => lang('billable 
hours'),
                                        'type'          => 'textbox',
-                                       'change_key'=> 'H'
+                                       'change_key'=> 'H',
+                                       'nullable'      => True
                                );
        
                                $fields[] = array
@@ -445,7 +487,8 @@
                                        'id'            => 
'ticket_billable_rate',
                                        'label'         => lang('hourly rate'),
                                        'type'          => 'textbox',
-                                       'change_key'=> 'B'
+                                       'change_key'=> 'B',
+                                       'nullable'      => True
                                );
                                
                                $fields[] = array
@@ -453,7 +496,8 @@
                                        'id'            => 'ticket_status',
                                        'label'         => lang('status'),
                                        'options'       => $this->_get_stati(),
-                                       'type'          => 'select'
+                                       'type'          => 'select',
+                                       'nullable'      => True
                                );
        
                                $fields[] = array
@@ -461,7 +505,8 @@
                                        'id'            => 'ticket_deadline',
                                        'label'         => lang('deadline'),
                                        'type'          => 'date',
-                                       'change_key'=> 'D'
+                                       'change_key'=> 'D',
+                                       'nullable'      => True
                                );
        
                                $fields[] = array
@@ -469,7 +514,8 @@
                                        'id'    => 'ticket_effort',
                                        'label' => lang('effort'),
                                        'type'  => 'textbox',
-                                       'change_key'=> 'E'
+                                       'change_key'=> 'E',
+                                       'nullable'      => True
                                );
        
                                $fields[] = array
@@ -477,7 +523,8 @@
                                        'id'            => 'ticket_details',
                                        'label'         => lang('details'),
                                        'type'          => 'memo',
-                                       'change_key'=> 'C'
+                                       'change_key'=> 'C',
+                                       'nullable'      => False
                                );
                        }
 
@@ -493,7 +540,8 @@
                                                //'help'        => 
lang($cust_field['status_text']),
                                                'label'         => 
lang($cust_field['name']),
                                                'type'          => 
$this->_translate_cust_type($cust_field['datatype']),
-                                               'change_key'=> 'F'
+                                               'change_key'=> 'F',
+                                               'nullable'      => 
$cust_field['nullable']
                                        );
                                        if ( isset($cust_field['choice']) )
                                        {
@@ -531,14 +579,20 @@
                /**
                * Validate a ticket before it is submitted
                *
-               * @param string $ttype the ticket type to be validated
                * @param array $values the ticket values as an associative array
-               * @return array any errors, count(0) == valid
+               * @return bool any errors?
                */
-               function validate($ttype, $values)
+               function validate($values)
+               {
+                       $ticket_fields = 
$this->get_fields($values['ticket_type']);
+                       foreach ( $ticket_fields as $field )
+                       {
+                               if ( !$field['nullable'] && 
!$values[$field['id']] )
                {
-                       $errors = array();
-                       return $errors;
+                                       $this->errors[$field['id']] = lang('%1 
must not be empty', $field['label']);
+                               }
+                       }
+                       return !count($this->errors);
                }
                
                function _read($params = '')
@@ -677,13 +731,10 @@
                                return $ticket['ticket_id'];
                        }
                        
-                       if ( count($this->validate($ticket) ) ) // we don't 
really care what is invalid
-                       {
                                if ( $id = $this->save($ticket) )
                                {
                                        return $id; 
                                }
-                       }
                        return 0;
                }
 
@@ -692,6 +743,11 @@
                 */
                function save($ticket, $dohistorylog = true)
                {
+                       if ( !$this->validate($ticket) )
+                       {
+                               return 0;
+                       }
+
                        $ticket_id = 0;
                        $lastmod = isset($ticket['ticket_lastmod']) ? (int) 
$ticket['ticket_lastmod'] : time();
                        $sql = $this->db->adodb->Prepare('INSERT INTO 
phpgw_tts_tickets('
@@ -767,6 +823,11 @@
                */
                function update($ticket_id, $params)
                {
+                       if ( !$this->validate($ticket) )
+                       {
+                               return 0;
+                       }
+                       
                        $ticket_id = (int) $ticket_id;
                        if ( $ticket_id <= 0 )
                        {

Index: class.uitts.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/tts/inc/class.uitts.inc.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- class.uitts.inc.php 28 Nov 2006 10:31:08 -0000      1.3
+++ class.uitts.inc.php 29 Nov 2006 12:53:23 -0000      1.4
@@ -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.3 2006/11/28 10:31:08 skwashd 
Exp $
+       * @version $Id: class.uitts.inc.php,v 1.4 2006/11/29 12:53:23 skwashd 
Exp $
        */
        
        class uitts
@@ -58,7 +58,6 @@
                {
                        if ( $_SERVER['REQUEST_METHOD'] == 'GET' )
                        {
-                               //FIXME switch to XSLT here
                                $GLOBALS['phpgw_info']['flags']['xslt_app'] = 
true;
                                
$GLOBALS['phpgw']->xslttpl->add_file('select_ticket');
                                
@@ -99,31 +98,32 @@
                                        $this->_access_denied();
                                }
 
-                               if ( isset($_POST['next']) && $_POST['next'] )
-                               {
+
                                        $ticket = array
                                        (
                                                'ticket_id'             => 0,
                                                'ticket_type'   => (int) 
$_REQUEST['ticket_type']
                                        );
                                        
-                                       $this->_render_add_form($ticket);
-                                       
$GLOBALS['phpgw']->common->phpgw_footer();
-                                       exit;
-                               }
-                               elseif ( isset($_POST['submit']) && 
$_POST['submit'] )
+                               if ( isset($_POST['submit']) && 
$_POST['submit'] )
                                {
                                        $id = $this->bo->save($_POST);
                                        if ($id > 0)
                                        {
                                                
$GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 
'tts.uitts.view', 'ticket_id' => $id));
+                                               exit;
                                        }
-                                       die('oh shit!');
                                }
-                               elseif ( isset($_POST['cancel']) && 
$_POST['cancel'] )
+
+                               if ( isset($_POST['cancel']) && 
$_POST['cancel'] )
                                {
                                        
$GLOBALS['phpgw']->redirect_link('/tts/index.php');
+                                       exit;
                                }
+                               
+                               $this->_render_add_form($ticket);
+                               $GLOBALS['phpgw']->common->phpgw_footer();
+                               exit;
                        }
                        die('invalid request');
                }
@@ -414,6 +414,15 @@
 
                        //echo '<pre>' . print_r($fields, true) . '</pre>';
                        
+                       $invalids =& $this->bo->errors;
+                       foreach ( $fields as $key => $field )
+                       {
+                               if ( isset($invalids[$field['id']]) )
+                               {
+                                       $fields[$key]['class'] = 'error';
+                               }
+                       }
+                       
                        return array('form_elm' => $fields);
                }
 




reply via email to

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