phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] notes/inc class.uinotes.inc.php, 1.32 class.sonotes.i


From: uid65887
Subject: [Phpgroupware-cvs] notes/inc class.uinotes.inc.php, 1.32 class.sonotes.inc.php, 1.12 class.bonotes.inc.php, 1.24 class.ipc_notes.inc.php, 1.1
Date: Wed, 27 Apr 2005 07:33:03 -0000

Update of notes/inc

Modified Files:
     Branch: MAIN
            class.uinotes.inc.php lines: +5 -17
            class.sonotes.inc.php lines: +19 -13
            class.bonotes.inc.php lines: +220 -35
Added Files:
     Branch: MAIN
            class.ipc_notes.inc.php 

Log Message:
added ipc layer class for notes plus cat fixes

====================================================
Index: notes/inc/class.uinotes.inc.php
diff -u notes/inc/class.uinotes.inc.php:1.31 
notes/inc/class.uinotes.inc.php:1.32
--- notes/inc/class.uinotes.inc.php:1.31        Wed Nov 12 16:45:41 2003
+++ notes/inc/class.uinotes.inc.php     Tue Dec 23 16:17:35 2003
@@ -68,7 +68,6 @@

                function index()
                {
-                       //$GLOBALS['phpgw']->xslttpl->add_file('app_data');
                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('notes') . ': ' . lang('list notes');

                        $notes_list = $this->bonotes->read();
@@ -144,11 +143,7 @@
                        $data = array
                        (
                                'nm_data'                               => 
$this->nextmatchs->xslt_nm($nm),
-                               'lang_no_cat'                   => lang('no 
category'),
-                               'lang_cat_statustext'   => lang('Select the 
category the notes belongs to. To do not use a category select NO CATEGORY'),
-                               'select_name'                   => 'cat_id',
-                               'cat_list'                              => 
$this->cats->formatted_xslt_list(array('selected' => $this->cat_id,'globals' => 
True)),
-                               'select_url'                    => 
$GLOBALS['phpgw']->link('/index.php','menuaction=notes.uinotes.index'),
+                               'cat_filter'                    => 
$this->cats->formatted_xslt_list(array('select_name' => 'cat_id','selected' => 
$this->cat_id,'globals' => True,'link_data' => $link_data)),
                                'filter_data'                   => 
$this->nextmatchs->xslt_filter(array('filter' => $this->filter,'link_data' => 
$link_data)),
                                'search_data'                   => 
$this->nextmatchs->xslt_search(array('query' => $this->query,'link_data' => 
$link_data)),
                                'table_header'                  => 
$table_header,
@@ -186,8 +181,6 @@
                                }
                        }

-                       $GLOBALS['phpgw']->xslttpl->add_file('app_data');
-
                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('notes') . ': ' . ($note_id?lang('edit note'):lang('add note'));

                        if ($note_id)
@@ -214,7 +207,6 @@
                                'lang_apply'                                    
=> lang('apply'),
                                'value_content'                                 
=> $note['content'],
                                'value_access'                                  
=> $note['access'],
-                               'value_cat'                                     
        => $note['cat'],
                                'lang_content_statustext'               => 
lang('Enter the content of the note'),
                                'lang_apply_statustext'                 => 
lang('Apply the values'),
                                'lang_cancel_statustext'                => 
lang('Leave the note untouched and return back to the list'),
@@ -222,9 +214,7 @@
                                'lang_access_off_statustext'    => lang('The 
note is public. If the note should be private, check this box'),
                                'lang_access_on_statustext'             => 
lang('The note is private. If the note should be public, uncheck this box'),
                                'lang_no_cat'                                   
=> lang('no category'),
-                               'lang_cat_statustext'                   => 
lang('Select the category the notes belongs to. To do not use a category select 
NO CATEGORY'),
-                               'select_name'                                   
=> 'values[cat_id]',
-                               'cat_list'                                      
        => $this->cats->formatted_xslt_list(array('format' => 
'select','selected' => $this->cat_id,'globals' => True))
+                               'cat_select'                                    
=> $this->cats->formatted_xslt_list(array('select_name' => 
'values[cat_id]','selected' => $note['cat_id']))
                        );
                        
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('edit' => $data));
                }
@@ -237,7 +227,7 @@

                        $link_data = array
                        (
-                               'menuaction' => 'notes.ui.index'
+                               'menuaction' => 'notes.uinotes.index'
                        );

                        if ($_POST['delete'])
@@ -258,7 +248,7 @@
                        $data = array
                        (
                                'delete_url'                            => 
$GLOBALS['phpgw']->link('/index.php','menuaction=notes.uinotes.delete&note_id=' 
. $note_id),
-                               'lang_delete_msg'                       => 
lang('do you really want to delete this note ?'),
+                               'lang_confirm_msg'                      => 
lang('do you really want to delete this note ?'),
                                'lang_delete'                           => 
lang('delete'),
                                'lang_delete_statustext'        => lang('Delete 
the note'),
                                'lang_cancel_statustext'        => lang('Leave 
the note untouched and return back to the list'),
@@ -275,8 +265,6 @@

                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('notes') . ': ' . lang('view note');

-                       $GLOBALS['phpgw']->xslttpl->add_file('app_data');
-
                        $note = $this->bonotes->read_single($note_id);

                        $data = array

====================================================
Index: notes/inc/class.sonotes.inc.php
diff -u notes/inc/class.sonotes.inc.php:1.11 
notes/inc/class.sonotes.inc.php:1.12
--- notes/inc/class.sonotes.inc.php:1.11        Tue Nov 11 12:45:30 2003
+++ notes/inc/class.sonotes.inc.php     Tue Dec 23 16:17:35 2003
@@ -18,6 +18,9 @@
        class sonotes
        {
                var $grants;
+               var $db;
+               var $db2;
+               var $account;

                function sonotes()
                {
@@ -39,6 +42,9 @@
                                $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:0);
                        }

+                       $start  = intval($start);
+                       $cat_id = intval($cat_id);
+
                        if ($order)
                        {
                                $ordermethod = " order by $order $sort";
@@ -96,15 +102,15 @@

                        while ($this->db->next_record())
                        {
-                               $ngrants = 
(int)$this->grants[$this->db->f('note_owner')];
+                               $ngrants = 
$this->grants[$this->db->f('note_owner')];
                                $notes[] = array
                                (
-                                       'note_id'       => 
(int)$this->db->f('note_id'),
+                                       'note_id'       => 
$this->db->f('note_id'),
                                        'owner'         => 
$this->db->f('note_owner'),
-                                       'owner_id'      => 
(int)$this->db->f('note_owner'),
+                                       'owner_id'      => 
$this->db->f('note_owner'),
                                        'access'        => 
$this->db->f('note_access'),
                                        'date'          => 
$this->db->f('note_date'),
-                                       'cat_id'        => 
(int)$this->db->f('note_category'),
+                                       'cat_id'        => 
$this->db->f('note_category'),
                                        'content'       => 
stripslashes($this->db->f('note_content')),
                                        'grants'        => $ngrants
                                );
@@ -114,16 +120,16 @@

                function read_single($note_id)
                {
-                       $this->db->query("select * from phpgw_notes where 
note_id='$note_id'",__LINE__,__FILE__);
+                       $this->db->query('select * from phpgw_notes where 
note_id=' . intval($note_id),__LINE__,__FILE__);

                        if ($this->db->next_record())
                        {
-                               $note['id']                     = 
(int)$this->db->f('note_id');
+                               $note['id']                     = 
$this->db->f('note_id');
                                $note['owner']          = 
$this->db->f('note_owner');
                                $note['content']        = 
stripslashes($this->db->f('note_content'));
                                $note['access']         = 
$this->db->f('note_access');
                                $note['date']           = 
$this->db->f('note_date');
-                               $note['cat_id']         = 
(int)$this->db->f('note_category');
+                               $note['cat_id']         = 
$this->db->f('note_category');

                                return $note;
                        }
@@ -133,9 +139,9 @@
                {
                        $note['content'] = 
$this->db->db_addslashes($note['content']);

-                       $this->db->query("INSERT INTO phpgw_notes 
(note_owner,note_access,note_date,note_content,note_category) "
-                               . "VALUES ('" . $this->account . "','" . 
$note['access'] . "','" . time() . "','" . $note['content']
-                               . "','" . $note['cat_id'] . 
"')",__LINE__,__FILE__);
+                       $this->db->query('INSERT INTO phpgw_notes 
(note_owner,note_access,note_date,note_content,note_category) '
+                               . 'VALUES (' . $this->account . ",'" . 
$note['access'] . "'," . time() . ",'" . $note['content']
+                               . "'," . intval($note['cat_id']) . 
')',__LINE__,__FILE__);
                        return 
$this->db->get_last_insert_id('phpgw_notes','note_id');
                }

@@ -143,8 +149,8 @@
                {
                        $note['content'] = 
$this->db->db_addslashes($note['content']);

-                       $this->db->query("UPDATE phpgw_notes set 
note_content='" . $note['content'] . "', note_date='" . time() . "', 
note_category='"
-                                                       . $note['cat_id'] . "', 
note_access='" . $note['access'] . "' WHERE note_id=" . 
intval($note['note_id']),__LINE__,__FILE__);
+                       $this->db->query("UPDATE phpgw_notes set 
note_content='" . $note['content'] . "', note_date=" . time() . ', 
note_category='
+                                                       . 
intval($note['cat_id']) . ", note_access='" . $note['access'] . "' WHERE 
note_id=" . intval($note['note_id']),__LINE__,__FILE__);
                }

                function delete($note_id)

====================================================
Index: notes/inc/class.bonotes.inc.php
diff -u notes/inc/class.bonotes.inc.php:1.23 
notes/inc/class.bonotes.inc.php:1.24
--- notes/inc/class.bonotes.inc.php:1.23        Wed Nov 12 16:45:41 2003
+++ notes/inc/class.bonotes.inc.php     Tue Dec 23 16:17:35 2003
@@ -23,6 +23,7 @@
                var $sort;
                var $order;
                var $cat_id;
+               var $map;

                var $public_functions = array
                (
@@ -52,44 +53,70 @@
                        )
                );

-               function bonotes($session=False)
+               function bonotes($is_active=False)
                {
-                       $this->sonotes = CreateObject('notes.sonotes');
+                       $this->sonotes  = CreateObject('notes.sonotes');
+                       $this->start    = 0;
+                       $this->query    = '';
+                       $this->sort             = 'DESC';
+                       $this->order    = '';
+                       $this->cat_id   = 0;

-                       if ($session)
+                       $this->map = array();
+
+                       if ($is_active)
                        {
                                $this->read_sessiondata();
                                $this->use_session = True;
-                       }

-                       $start          = get_var('start',array('POST','GET'));
-                       $query          = get_var('query',array('POST','GET'));
-                       $sort           = get_var('sort',array('POST','GET'));
-                       $order          = get_var('order',array('POST','GET'));
-                       $filter         = get_var('filter',array('POST','GET'));
-                       $_cat_id        = get_var('cat_id',array('POST','GET'));
+                               $start          = 
get_var('start',array('POST','GET'));
+                               $query          = 
get_var('query',array('POST','GET'));
+                               $sort           = 
get_var('sort',array('POST','GET'));
+                               $order          = 
get_var('order',array('POST','GET'));
+                               $filter         = 
get_var('filter',array('POST','GET'));
+                               $_cat_id        = 
get_var('cat_id',array('POST','GET'));

-                       $this->start = (isset($start)?$start:0);
+                               $this->start = (isset($start)?$start:0);

-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
+                               if(isset($query))
+                               {
+                                       $this->query = $query;
+                               }
+                               if(!empty($filter))
+                               {
+                                       $this->filter = $filter;
+                               }
+                               if(isset($sort))
+                               {
+                                       $this->sort = $sort;
+                               }
+                               if(isset($order))
+                               {
+                                       $this->order = $order;
+                               }
+                               if(isset($_cat_id) && !empty($_cat_id))
+                               {
+                                       $this->cat_id = $_cat_id;
+                               }
                        }
-                       if(isset($_cat_id) && !empty($_cat_id))
+                       else
                        {
-                               $this->cat_id = $_cat_id;
+                               // define the map
+                               $this->map = array
+                               (
+                                       'application/x-phpgw-notes' => array
+                                       (
+                                               // extern           <> intern
+                                               'note_id'                       
=> 'id',
+                                               'note_owner'            => 
'owner',
+                                               'note_access'           => 
'access',
+                                               'note_createdate'       => 
'date',
+                                               'note_category'         => 
'category',
+                                               'note_description'      => 
'content'
+                                       ),
+                                       'text/plain' => array('content'),
+                                       'text/xml' => array()
+                               );
                        }
                }

@@ -202,13 +229,10 @@
                                $note['access'] = 'public';
                        }

-                       if ($note['note_id'])
+                       if (intval($note['note_id']) > 0)
                        {
-                               if ($note['note_id'] != 0)
-                               {
-                                       $note_id = $note['note_id'];
-                                       $this->sonotes->edit($note);
-                               }
+                               $note_id = $note['note_id'];
+                               $this->sonotes->edit($note);
                        }
                        else
                        {
@@ -228,5 +252,166 @@
                                $this->sonotes->delete($params);
                        }
                }
+
+               /**
+               * Convert data from a certain mime type format to the internal 
application data structure.
+               *
+               * @access  public
+               * @param   mixed    $dataExtern  data to convert, the datatype 
depends on the passed mime type
+               * @param   string   $type        specifies the mime type of the 
passed data
+               * @return  array                 data as application internal 
array
+               */
+               function importData($dataExtern, $type)
+               {
+                       $dataIntern = array();
+
+                       switch ($type)
+                       {
+                               case 'application/x-phpgw-notes':
+                                       if (is_array($dataExtern) == false)
+                                       {
+                                               return false;
+                                       }
+
+                                       foreach($this->map[$type] as $keyExtern 
=> $keyIntern)
+                                       {
+                                               if 
(isset($dataExtern[$keyExtern]) == true)
+                                               {
+                                                       $dataIntern[$keyIntern] 
= $dataExtern[$keyExtern];
+                                               }
+                                               else
+                                               {
+                                                       $dataIntern[$keyIntern] 
= null;
+                                               }
+                                       }
+                                       break;
+                               case 'text/plain':
+                                       if (is_string($dataExtern) == false)
+                                       {
+                                               return false;
+                                       }
+                                       $keyIntern = $this->map[$type][0];
+                                       $dataIntern[$keyIntern] = $dataExtern;
+                                       break;
+                               case 'text/xml':
+                                       return false;
+                                       break;
+                               default:
+                                       return false;
+                                       break;
+                       }
+                       return $dataIntern;
+               }
+
+
+               /**
+               * Convert data from internal application data structure to a 
certain mime type format.
+               *
+               * @access  public
+               * @param   array    $dataIntern  data as application internal 
array
+               * @param   string   $type        specifies the mime type of the 
returned data
+               * @return  mixed                 data in certain mime type 
format, the datatype depends on the passed mime type
+               */
+               function exportData($dataIntern, $type)
+               {
+                       if (is_array($dataIntern) == false)
+                       {
+                               return false;
+                       }
+
+                       $dataExtern = null;
+
+                       switch ($type)
+                       {
+                               case 'application/x-phpgw-notes':
+                                       $dataExtern = array();
+                                       foreach($this->map[$type] as $keyExtern 
=> $keyIntern)
+                                       {
+                                               if 
(isset($dataIntern[$keyIntern]) == true)
+                                               {
+                                                       $dataExtern[$keyExtern] 
= $dataIntern[$keyIntern];
+                                               }
+                                               else
+                                               {
+                                                       $dataExtern[$keyExtern] 
= null;
+                                               }
+                                       }
+
+                                       // extend the internal data with link 
informtion
+                                       $keyExtern_note_id = 
$this->getKeyExtern('id', $type);
+                                       $id = $dataExtern[$keyExtern_note_id];
+                                       // info needed to generate a view link
+                                       $dataExtern['link_view'] = 
array('menuaction'   => 'notes.uinotes.view',
+                                                                               
                                'note_id'       => $id);
+                                       // info needed to generate a edit link
+                                       $dataExtern['link_edit'] = 
array('menuaction'   => 'notes.uinotes.edit',
+                                                                               
                                'note_id'       => $id);
+                                       break;
+                               case 'text/plain':
+                                       $keyIntern = $this->map[$type][0];
+                                       $dataExtern = $dataIntern[$keyIntern];
+                                       break;
+                               case 'text/xml':
+                                       return false;
+                                       break;
+                               default:
+                                       return false;
+                                       break;
+                       }
+                       return $dataExtern;
+               }
+
+               function getKeyExtern($keyIntern, $type)
+               {
+                       $keyExtern = false;
+                       switch ($type)
+                       {
+                               case 'application/x-phpgw-notes':
+                                       foreach($this->map[$type] as $keyEx => 
$keyIn)
+                                       {
+                                               if ($keyIn == $keyIntern)
+                                               {
+                                                       $keyExtern = $keyEx;
+                                                       break;
+                                               }
+                                       }
+                                       break;
+                               case 'text/plain':
+                                       $keyIntern = $this->map[$type][0];
+                                       $dataExtern = $dataIntern[$keyIntern];
+                                       break;
+                               case 'text/xml':
+                                       return false;
+                                       break;
+                               default:
+                                       return false;
+                                       break;
+                       }
+                       return $keyExtern;
+               }
+
+               function getKeyIntern($keyExtern, $type)
+               {
+                       $keyIntern = false;
+                       switch ($type)
+                       {
+                               case 'application/x-phpgw-notes':
+                                       if 
(isset($this->map[$type][$keyExtern]) == true)
+                                       {
+                                               $keyIntern = 
$this->map[$type][$keyExtern];
+                                       }
+                                       break;
+                               case 'text/plain':
+                                       $keyIntern = $this->map[$type][0];
+                                       break;
+                               case 'text/xml':
+                                       return false;
+                                       break;
+                               default:
+                                       return false;
+                                       break;
+                       }
+                       return $keyExtern;
+               }
        }
 ?>

====================================================
Index: class.ipc_notes.inc.php
<?php
/**
 * IPC Layer
 *
 * @author      Dirk Schaller <address@hidden>
 * @copyright   Copyright (C) 2003 Free Software Foundation http://www.fsf.org/
 * @license     http://www.fsf.org/licenses/gpl.html GNU General Public License
 * @package     phpgwapi
 * @subpackage  ipc
 * @version     $Id: class.ipc_notes.inc.php,v 1.1 2003/12/23 16:17:35 uid65887 
Exp $
 */

/**
 * Fassade of the notes application.
 *
 * @package  notes
 */
class ipc_notes extends ipc_
{
        /**
         * Constructor
         *
         * @access  public
         */
        function ipc_notes()
        {
                $this->bonotes = CreateObject('notes.bonotes');
        }

        /**
         * Add data in a certain mime type format to the application.
         *
         * @access  public
         * @param   mixed    $data  data for adding to the application, the 
datatype depends on the mime type
         * @param   string   $type  specifies the mime type of the passed data
         * @return  integer         id of the added data
         */
        function addData($data, $type)
        {
                // 1: mapping the mime type to application data
                $dataIntern = $this->bonotes->importData($data, $type);
                if ($dataIntern == false)
                {
                        return false;
                }

                // 2: add data to application
                return $this->bonotes->save($dataIntern);
        }


        /**
         * Convert data from a mime type to another.
         *
         * @access  public
         * @param   mixed    $data     data for converting, the datatype 
depends on the input mime type
         * @param   string   $typeIn   specifies the input mime type of the 
passed data
         * @param   string   $typeOut  specifies the output mime type of the 
passed data
         * @return  mixed              converted data from application, the 
datatype depends on the passed output mime type
         */
        function convertData($data, $typeIn, $typeOut)
        {
                // 1: mapping the passed input data to application internal data
                $dataIntern = $this->bonotes->importData($data, $typeIn);
                if ($dataIntern == false)
                {
                        return false;
                }

                // 2: mapping internal data to the output mime type
                return $this->bonotes->exportData($dataIntern, $typeOut);
        }


        /**
         * Get data from the application in a certain mime type format.
         *
         * @param   integer  $id    id of data to get from the application
         * @param   string   $type  specifies the mime type of the returned data
         * @return  mixed           data from application, the datatype depends 
on the passed mime type, false if no data exists for the passed id
         */
        function getData($id, $type)
        {
                // 1: get data
                $dataIntern = $this->bonotes->read_single($id);
                if ($dataIntern == false)
                {
                        return false;
                }

                // 2: mapping internal data to the output mime type
                return $this->bonotes->exportData($dataIntern, $type);
        }


        /**
         * Remove data of the passed id.
         *
         * @param   integer  $id  id of data to remove from the application
         * @return  boolean       true if the data is removed, otherwise false
         */
        function removeData($id)
        {
                $this->bonotes->delete($id);
                // return status workaround: delete() : void  --> check if sql 
error
                if ($GLOBALS['phpgw']->db->Error)
                {
                        return false;
                }
                else
                {
                        return true;
                }
        }

        /**
         * Replace the existing data of the passed id with the passed data in a 
certain mime type format.
         *
         * @param   integer  $id    id of data to replace
         * @param   mixed    $data  the new data, the datatype depends on the 
passed mime type
         * @param   string   $type  specifies the mime type of the passed data
         * @return  boolean         true if the data is replaced, otherwise 
false
         */
        function replaceData($id, $data, $type)
        {
                // 1: mapping the passed input data to application internal data
                $dataIntern = $this->bonotes->importData($data, $type);
                if ($dataIntern == false)
                {
                        return false;
                }

                $dataIntern['id'] = (int) $id;

                // 2: replace data
                $this->bonotes->save($dataIntern);
                // return status workaround: save() : void  --> check if sql 
error
                if ($GLOBALS['phpgw']->db->Error)
                {
                        return false;
                }
                else
                {
                        return true;
                }
        }


        /**
         * Checks if data for the passed id exists.
         *
         * @param   integer  $id  id to check
         * @return  boolean       true if the data with id exist, otherwise 
false
         */
        function existData($id)
        {
                // i dont know what we need to check? you want to ckeck for a 
note with identically content? (ceb)
                // workaround: sonotes doesn't support a method for check
                // --> sql query
                $sql = "SELECT * FROM phpgw_notes WHERE note_id=".intval($id);
                $this->so->db->query($sql,__LINE__,__FILE__);
                if ($GLOBALS['phpgw']->db->Error)
                {
                        return false;
                }

                if ($this->so->db->num_rows() == 1)
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }
}
?>






reply via email to

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