phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] phpgroupware/notes/class.base.php, 1.1.2.1


From: nomail
Subject: [Phpgroupware-cvs] phpgroupware/notes/class.base.php, 1.1.2.1
Date: Thu, 20 May 2004 20:56:26 -0000

Update of /phpgroupware/notes
Added Files:
        Branch: proposal-branch
          class.base.php

date: 2004/04/16 21:22:00;  author: seek3r;  state: Exp;  lines: +466 -0

Log Message:
bringing savannah cvs back up to date with what we were doing on our private 
cvs server. We will not be doing dev from this cvs tree
=====================================================================
No syntax errors detected in -
=====================================================================
<?php
        
/**************************************************************************\
        * phpGroupWare                                                          
   *
        * http://www.phpgroupware.org                                           
   *
        * This file written by Joseph Engo <address@hidden>                *
        * Copyright (C) 2003-2004 Joseph Engo                                   
   *
        * 
-------------------------------------------------------------------------*
        * This program is free software; you can redistribute it and/or modify 
it  *
        * under the terms of the GNU General Public License as published by the 
   *
        * Free Software Foundation; either version 2 of the License, or (at 
your   *
        * option) any later version.                                            
   *
        
\**************************************************************************/

        /* $Id: class.base.php,v 1.1.2.1 2004/04/16 21:22:00 seek3r Exp $ */
        /* $Source: 
/cvsroot/phpgroupware/phpgroupware/notes/Attic/class.base.php,v $ */

        $functions             = array();
        $functions['notes_base'] = array
        (
                'type'         => 'public',
                'abstract'     => 'base class for notes',
                'discussion'   => 'base class for notes'
        );
        
        $functions['start']    = array
        (
                'type'         => 'public',
                'title'        => 'Notes',
                'abstract'     => 'Show list of notes',
                'discussion'   => 'This will show a list of notes the user owns 
or has access to'
        );

        $functions['create']   = array
        (
                'type'         => 'public',
                'title'        => 'Create note',
                'abstract'     => 'Create note',
                'params'       => array
                (
                        'form_submit'       => array('type' => 'enum',   
'default' => array('false','true'),     'desc' => 'form_submit'),
                        'category'          => array('type' => 'number', 
'default' => 0,                         'desc' => 'Category ID number'),
                        'access'            => array('type' => 'enum',   
'default' => array('private','public'), 'desc' => 'Access type'),
                        'content'           => array('type' => 'any',    
'default' => NOTSET,                    'desc' => 'Note content'),
                        'dm_type'           => array('type' => 'enum',   
'default' => array('N','D'),            'desc' => 'Datamine type'),
                        'datamine_location' => array('type' => 'any',    
'default' => NOTSET,                    'desc' => 'Datamine location')
                )
        );

        $functions['view']   = array
        (
                'type'         => 'public',
                'title'        => 'View note',
                'abstract'     => 'View note',
                'params'       => array
                (
                        'note_id'    => array('type' => 'number', 'default' => 
REQUIRED, 'desc' => 'Note ID number')
                )
        );

        $functions['edit']   = array
        (
                'type'         => 'public',
                'title'        => 'Edit note',
                'abstract'     => 'Edit note',
                'params'       => array
                (
                        'form_submit' => array('type' => 'enum',   'default' => 
array('false','true'),     'desc' => 'form_submit'),
                        'note_id'     => array('type' => 'number', 'default' => 
REQUIRED,                  'desc' => 'Note ID number'),
                        'category'    => array('type' => 'number', 'default' => 
0,                         'desc' => 'Category ID number'),
                        'access'      => array('type' => 'enum',   'default' => 
array('private','public'), 'desc' => 'Access type'),
                        'content'     => array('type' => 'any',    'default' => 
NOTSET,                    'desc' => 'Note content')
                )
        );

        $functions['delete']   = array
        (
                'type'         => 'public',
                'title'        => 'Delete note',
                'abstract'     => 'Delete note',
                'params'       => array
                (
                        'note_id'    => array('type' => 'number', 'default' => 
REQUIRED, 'desc' => 'Note ID number'),
                        'answer'     => array('type' => 'any',    'default' => 
NOVAR,    'desc' => 'Answer to yes no dialog')
                )
        );

        $GLOBALS['docs']['notes']['classes']['notes_base'] = array
        (
                'abstract'  => 'Default class for notes',
                'functions' => $functions
        );

        class notes_base
        {
                function notes_base()
                {
                        $GLOBALS['phpgw']->add_xsl('notes.base');
                        $GLOBALS['phpgw']->add_xsl('api.widgets');

                        // The no_app_menu is *ONLY* a temp workaround for not 
showing the app menu
                        // durring _datamine_get(), I am currently working on 
another solution to it
                        if (! $GLOBALS['notes_menus_loaded'] && ! 
$GLOBALS['no_app_menu'])
                        {
                                $GLOBALS['phpgw']->add_appmenu('Notes 
menu','Add note','notes.base.create');
                                //$GLOBALS['phpgw']->add_appmenu('Notes 
menu','Preferences','api.base.prefs&appname=notes');

                                $GLOBALS['notes_menus_loaded'] = true;
                        }
                }

                // This is only until categorys is done
                function _temp_cat()
                {
                        return '-';
                }

                function __get_record(&$db)
                {
                        // Belive it or not, some browsers don't have strlen or 
substr support in XSLT,
                        // this is a work around
                        // FIXME: This should be a preference option for the 
cut off point
                        if (strlen($db->fields['note_content']) > 55)
                        {
                                $content_title = 
substr($db->fields['note_content'],0,55) . ' ...';
                        }
                        else
                        {
                                $content_title = $db->fields['note_content'];
                        }

                        return array
                        (
                                'id'          => $db->fields['note_id'],
                                // FIXME: Need to create a function to handle 
displaying loginids in the proper format.
                                // Based on preference and the system settings
                                'owner'         => 
$GLOBALS['phpgw']->accounts->cross_reference((int)$db->fields['note_owner']),
                                'owner_id'      => $db->fields['note_owner'],
                                'access'        => $db->fields['note_access'],
                                'category'      => 
$this->_temp_cat($db->fields['note_category']),
                                'category_id'   => $db->fields['note_category'],
                                'content'       => $db->fields['note_content'],
                                'content_title' => $content_title,
                                'created'       => 
strftime('%x',$db->unixtimestamp($db->fields['note_created'])) . date(' h:i:s 
a',$db->unixtimestamp($db->fields['note_created'])),
                                'modified'      => 
strftime('%x',$db->unixtimestamp($db->fields['note_modified'])) . date(' h:i:s 
a',$db->unixtimestamp($db->fields['note_modified']))
                        );
                }

                function start()
                {
                        $args = new safe_args();
                        $args->set('start',0,'number');
                        $args->set('search',NOTSET,'any');
                        $args->set('sort','desc','any');
                        $args->set('order','note_created','string');
                        $args = $args->get(func_get_args());

                        $result['action_type'] = 'note_start';
                        $result['notes']       = array();

                        if 
($GLOBALS['phpgw']->acl->check('notes.base.edit',1,1))
                        {
                                $result['edit_allowed']   = true;
                        }

                        if 
($GLOBALS['phpgw']->acl->check('notes.base.delete',1,1))
                        {
                                $result['delete_allowed'] = true;
                        }

                        $db = $GLOBALS['phpgw']->db->execute("SELECT * FROM 
phpgw_notes WHERE note_owner="
                                . $GLOBALS['phpgw_data']['user']['id'] . " AND 
note_dm_type='N' order by "
                                . $args['order'] . " " . $args['sort']);

                        while (! $db->EOF)
                        {
                                $result['notes'][] = $this->__get_record(&$db);

                                $db->MoveNext();
                        }

                        return $result;
                }

                // FIXME: When the note_content is one *really* large string, 
it totally screaws up the display
                // Create a way to split oversized strings so they wrap
                function view()
                {
                        $args = new safe_args();
                        $args->set('note_id',REQUIRED,'number');
                        $args = $args->get(func_get_args());

                        $result['action_type'] = 'note_view';
                        $db = $GLOBALS['phpgw']->db->execute("SELECT * FROM 
phpgw_notes WHERE note_id='"
                                . $args['note_id'] . "' AND note_dm_type='N'");

                        if (! $GLOBALS['phpgw']->acl->check('notes.' . 
$args['note_id'],PHPGW_ACL_READ))
                        {
                                
$GLOBALS['phpgw']->interface->access_denied('this record');
                                return array();
                        }
                        else if ($db->EOF)
                        {
                                $GLOBALS['msgbox']->add(lang('Record not 
found'),'notice');
                                return array();
                        }
                        else
                        {
                                $GLOBALS['phpgw']->add_appmenu('Notes 
menu','Edit note','notes.base.edit&note_id=' . $args['note_id']);
                                $GLOBALS['phpgw']->add_appmenu('Notes 
menu','Delete note','notes.base.delete&note_id=' . $args['note_id']);

                                $result['note'] = $this->__get_record(&$db);
                                $obj                    = 
createObject('api_history');
                                $obj->field_desc        = array
                                (
                                        'access'   => lang('Access'),
                                        'category' => lang('Category'),
                                        'content'  => lang('Content')
                                );
                                $obj->field_execMethod['category'] = 
'notes.base._temp_cat';
                                $result['history_data'] = $obj->get('notes.' . 
$args['note_id']);
                                $result['datamine']     = 
execMethod('api.datamine._get','notes.base.' . $args['note_id']);
                        }

                        return $result;
                }

                function create()
                {
                        $args = new safe_args();
                        $args->set('form_submit',array('false','true'),'enum');
                        $args->set('access',array('public','private'),'enum');
                        $args->set('dm_type',array('N','D'),'enum');
                        $args->set('dm_redirect',NOTSET,'any');
                        $args->set('datamine_location',NOTSET,'any');
                        $args->set('content',NOTSET,'any');
                        $args->set('category',0,'number');
                        $args = $args->get(func_get_args());

                        $result['note'] = array
                        (
                                'access'            => $args['access'],
                                'content'           => $args['content'],
                                'category'          => $args['category'],
                                'dm_type'           => $args['dm_type'],
                                'dm_redirect'       => $args['dm_redirect'],
                                'datamine_location' => 
$args['datamine_location']
                        );
                        $result['action_type'] = 'note_create';

                        if ($args['form_submit'] == 'true')
                        {
                                if (! strlen($args['content']))
                                {
                                        $result['missing_fields']['content'] = 
true;
                                        $GLOBALS['msgbox']->add(lang('You 
forgot to enter some of the required fields. The missing fields have been 
marked'),'notice');
                                        //$GLOBALS['phpgw']->form_lock();
                                }
                                else
                                {
                                        $GLOBALS['phpgw']->db->execute("INSERT 
INTO phpgw_notes (note_owner,"
                                                . 
"note_access,note_category,note_content,note_dm_type,note_modified,"
                                                . "note_created) values ('" . 
$GLOBALS['phpgw_data']['user']['id']
                                                . "','" . $args['access'] . 
"','" . $args['category']
                                                . "','" . $args['content'] . 
"','" . $args['dm_type']
                                                . "',now(),now())");

                                        // This is done like this on purpose, 
just in case they add a duplicate
                                        // or submit the form 2+ times
                                        $dbresult = 
$GLOBALS['phpgw']->db->selectlimit("SELECT note_id FROM phpgw_notes where 
note_owner="
                                                . 
$GLOBALS['phpgw_data']['user']['id'] . " AND note_content='"
                                                . $args['content'] . "' order 
by note_created desc",1);

                                        $note_id = $dbresult->fields['note_id'];

                                        // If insert works, show this message 
then forward them to view the new note
                                        if ($note_id)
                                        {
                                                $history_data = array
                                                (
                                                        'access'   => 
$args['access'],
                                                        'category' => 
$args['category'],
                                                        'content'  => 
$args['content']
                                                );

                                                $obj = 
createObject('api_history');
                                                $obj->set('notes.' . 
$note_id,$history_data,array());
                                                
$GLOBALS['msgbox']->add(lang('Note has been successfully created'),'notice');

                                                if ($args['dm_type'] == 'D')
                                                {
                                                        
execMethod('api.datamine._set',array('location_from' => 
$args['datamine_location'], 'location_to' => 'notes.base.' . $note_id));
                                                        return 
execMethod($_SESSION['phpgw_session']['phpgw_data']['op_history'][$args['dm_redirect']]['op'],$_SESSION['phpgw_session']['phpgw_data']['op_history'][$args['dm_redirect']]['data']);
                                                }
                                                else
                                                {
                                                        return 
$this->view($note_id);
                                                }
                                        }
                                        else
                                        {
                                                
$GLOBALS['msgbox']->add(lang('There was a problem creating this 
record'),'warning');
                                                $GLOBALS['phpgw']->form_lock();
                                        }
                                }
                        }
                        else
                        {
                                $GLOBALS['phpgw']->form_lock();
                        }

                        return $result;
                }

                function edit()
                {
                        $args = new safe_args();
                        $args->set('form_submit',array('false','true'),'enum');
                        $args->set('note_id',REQUIRED,'number');
                        $args->set('access',array('public','private'),'enum');
                        $args->set('content', NOTSET, 'any');
                        $args->set('category',0,'number');
                        $args = $args->get(func_get_args());

                        $result['action_type'] = 'note_edit';
                        $db = $GLOBALS['phpgw']->db->execute("SELECT * from 
phpgw_notes where note_id='"
                                . $args['note_id'] . "'");

                        if (! $GLOBALS['phpgw']->acl->check('notes.' . 
$args['note_id'],PHPGW_ACL_READ))
                        {
                                
$GLOBALS['phpgw']->interface->access_denied('this record');
                                return array();
                        }
                        else if ($db->EOF)
                        {
                                $GLOBALS['msgbox']->add(lang('Record not 
found'),'notice');
                                return array();
                        }
                        else
                        {
                                $note_values = $this->__get_record(&$db);
                                if ($args['form_submit'] == 'true')
                                {
                                        $GLOBALS['phpgw']->add_appmenu('Notes 
menu','Edit note','notes.base.edit&note_id=' . $args['note_id']);
                                        $GLOBALS['phpgw']->add_appmenu('Notes 
menu','Delete note','notes.base.delete&note_id=' . $args['note_id']);

                                        $GLOBALS['phpgw']->db->execute("
                                                UPDATE
                                                        phpgw_notes
                                                SET
                                                        note_content='" . 
$args['content'] . "',
                                                        note_access='" . 
$args['access'] . "',
                                                        note_category='" . 
$args['category'] . "'
                                                WHERE
                                                        note_id=" . 
$args['note_id']);

                                                $old_values   = array
                                                (
                                                        'access'   => 
$note_values['access'],
                                                        'category' => 
($note_values['category'] == '-' ? '0' : $note_values['category']),
                                                        'content'  => 
$note_values['content']
                                                );

                                                $history_data = array
                                                (
                                                        'access'   => 
$args['access'],
                                                        'category' => 
$args['category'],
                                                        'content'  => 
$args['content']
                                                );

                                                $obj = 
createObject('api_history');
                                                $obj->field_desc = array
                                                (
                                                        'access'   => 
lang('Access'),
                                                        'category' => 
lang('Category'),
                                                        'content'  => 
lang('Content')
                                                );
                                                $obj->set('notes.' . 
$args['note_id'],$history_data,$old_values);

                                                
$GLOBALS['msgbox']->add(lang('Note has been successfully updated'),'notice');
                                                return array();
                                }
                                else
                                {
                                        $result['note'] = $note_values;
                                }
                        }

                        return $result;
                }

                function delete()
                {
                        $args = new safe_args();
                        $args->set('note_id',REQUIRED,'number');
                        $args->set('answer',NOVAR,'any');
                        $args = $args->get(func_get_args());

                        if (! $GLOBALS['phpgw']->acl->check('notes.' . 
$args['note_id'],PHPGW_ACL_DELETE))
                        {
                                
$GLOBALS['phpgw']->interface->access_denied('this record');
                                return array();
                        }

                        if ($args['answer'] == NOVAR)
                        {
                                $db = $GLOBALS['phpgw']->db->execute("SELECT * 
from phpgw_notes WHERE note_id='"
                                        . $args['note_id'] . "'");

                                if ($db->EOF)
                                {
                                        $GLOBALS['msgbox']->add(lang('Record 
not found'),'notice');
                                        return array();
                                }
                                $result['note'] = $this->__get_record(&$db);

                                $result['dialog'] = array(
                                        'question' => lang('Are you sure you 
want to delete this note ?'),
                                        'yes_op'   => 'notes.base.delete',
                                        'no_op'    => 'api.statecache.cancel',
                                        'current_inputs' => array(
                                                0 => array(
                                                        'name'  => 'note_id',
                                                        'value' => 
$args['note_id']
                                                )
                                        )
                                );

                                $result['action_type'] = 'note_delete';
                        }
                        else if ($args['answer'] == 'Yes')
                        {
                                $db = $GLOBALS['phpgw']->db->execute("DELETE 
FROM phpgw_notes WHERE note_id='"
                                        . $args['note_id'] . "'");

                                if ($GLOBALS['phpgw']->db->affected_rows())
                                {
                                        execMethod('api.history.clear','notes.' 
. $args['note_id']);
                                        $GLOBALS['msgbox']->add(lang('Note has 
been deleted successfully'),'notice');
                                }
                                else
                                {
                                        $GLOBALS['msgbox']->add(lang('There was 
a problem deleting this note'),'warning');
                                }
                        }

                        return $result;
                        
                }

                function _datamine_get()
                {
                        $args = new safe_args();
                        $args->set('note_id',REQUIRED,'number');
                        $args = $args->get(func_get_args());

                        $GLOBALS['phpgw']->add_xsl('notes.widgets');

                        // FIXME: This needs ACL check and it needs to check 
for note_dm_type of D
                        $dbresult = $GLOBALS['phpgw']->db->execute("SELECT * 
FROM phpgw_notes WHERE note_id='"
                                . $args['note_id'] . "' AND note_dm_type='D'");

                        return $this->__get_record(&$dbresult);
                }

        }





reply via email to

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