phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] [21180] Improvements: send messages to groups, check


From: Sigurd Nes
Subject: [Phpgroupware-cvs] [21180] Improvements: send messages to groups, check for acl 4746:5203
Date: Wed, 14 Apr 2010 18:15:45 +0000

Revision: 21180
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=21180
Author:   sigurdne
Date:     2010-04-14 18:15:45 +0000 (Wed, 14 Apr 2010)
Log Message:
-----------
Improvements: send messages to groups, check for acl 4746:5203

Modified Paths:
--------------
    people/sigurdne/modules/messenger/trunk/inc/class.bomessenger.inc.php
    people/sigurdne/modules/messenger/trunk/inc/class.menu.inc.php
    people/sigurdne/modules/messenger/trunk/inc/class.uimessenger.inc.php
    people/sigurdne/modules/messenger/trunk/inc/hook_config.inc.php
    people/sigurdne/modules/messenger/trunk/setup/setup.inc.php
    people/sigurdne/modules/messenger/trunk/setup/tables_update.inc.php
    people/sigurdne/modules/messenger/trunk/templates/base/config.tpl

Added Paths:
-----------
    people/sigurdne/modules/messenger/trunk/templates/base/app_data.xsl
    people/sigurdne/modules/messenger/trunk/templates/base/messenger.xsl

Modified: people/sigurdne/modules/messenger/trunk/inc/class.bomessenger.inc.php
===================================================================
--- people/sigurdne/modules/messenger/trunk/inc/class.bomessenger.inc.php       
2010-04-14 18:10:42 UTC (rev 21179)
+++ people/sigurdne/modules/messenger/trunk/inc/class.bomessenger.inc.php       
2010-04-14 18:15:45 UTC (rev 21180)
@@ -39,23 +39,36 @@
 
                        $config = createObject('phpgwapi.config', 'messenger');
                        $config->read();
-
-                       if ( 
!isset($GLOBALS['phpgw_info']['user']['apps']['admin']) 
-                               && isset($config->data['restrict_to_group'] )
-                               && $config->data['restrict_to_group'] )
+                       if ( isset($config->config_data['restrict_to_group'] )
+                               && $config->config_data['restrict_to_group'] 
+                               && 
!isset($GLOBALS['phpgw_info']['user']['apps']['admin'])
+                       )
                        {
-                               $tmp_users = 
$GLOBALS['phpgw']->accounts->member($config->data['restrict_to_group']);
-                               foreach ( $tmp_users as $user )
+                               
+                               foreach 
($config->config_data['restrict_to_group'] as $restrict_to_group)
                                {
-                                       $users[$user->id] = 
$user['account_name'];
+                                       $tmp_users = 
$GLOBALS['phpgw']->accounts->member($restrict_to_group, true);
+
+                                       foreach ( $tmp_users as $user )
+                                       {
+                                               $users[$user['account_id']] = 
$user['account_name'];
+                                       }
                                }
+
+                               if($users)
+                               {
+                                       array_multisort($users, SORT_ASC, 
$users);
+                               }
                        }
                        else
                        {
-                               $tmp_users = 
$GLOBALS['phpgw']->accounts->get_list('accounts', -1, 'ASC', 'account_lid', '', 
-1);
+                               $tmp_users = 
$GLOBALS['phpgw']->accounts->get_list('accounts', -1, 'ASC', 
'account_lastname', '', -1);
                                foreach ( $tmp_users as $user )
                                {
-                                       $users[$user->id] = 
$GLOBALS['phpgw']->common->display_fullname($user->lid, $user->firstname, 
$user->lastname);
+                                       if($user->enabled)
+                                       {
+                                               $users[$user->id] = 
$GLOBALS['phpgw']->common->display_fullname($user->lid, $user->firstname, 
$user->lastname);
+                                       }
                                }
                        }
                        return $users;
@@ -154,6 +167,34 @@
                        return $this->so->connected;
                }
 
+               public function send_to_groups($values)
+               {
+                       foreach ($values['account_groups'] as $group)
+                       {
+                               $members = 
$GLOBALS['phpgw']->accounts->member($group);
+
+                               if (isset($members) AND is_array($members))
+                               {
+                                       foreach($members as $user)
+                                       {
+                                               $accounts[$user['account_id']] 
= array
+                                               (
+                                                       'account_id' => 
$user['account_id'],
+                                                       'account_name' => 
$user['account_name']
+                                               );
+                                       }
+                                       unset($members);
+                               }
+                       }
+                       $receipt = array();
+                       foreach ($accounts as $account)
+                       {
+                               $this->so->send_message(array('to' => 
$account['account_id'], 'subject' => $values['subject'], 'content' => 
$values['content']));
+                               
$receipt['message'][]=array('msg'=>lang('message sent to' . " 
{$account['account_name']}" ));
+                       }
+                       return $receipt;
+               }
+
                function send_message($data='')
                {
                        if(is_array($data))

Modified: people/sigurdne/modules/messenger/trunk/inc/class.menu.inc.php
===================================================================
--- people/sigurdne/modules/messenger/trunk/inc/class.menu.inc.php      
2010-04-14 18:10:42 UTC (rev 21179)
+++ people/sigurdne/modules/messenger/trunk/inc/class.menu.inc.php      
2010-04-14 18:15:45 UTC (rev 21180)
@@ -66,6 +66,11 @@
                                        (
                                                'text'  => 
lang('Configuration'),
                                                'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uiconfig.index', 'appname' => 'messenger') )
+                                       ),
+                                       'acl'   => array
+                                       (
+                                               'text'  => lang('Configure 
Access Permissions'),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'preferences.uiadmin_acl.list_acl', 'acl_app' => 'messenger') )
                                        )
                                );
                        }
@@ -101,19 +106,32 @@
                                        'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'messenger.uimessenger.inbox')),
                                        'text'  => 
$GLOBALS['phpgw']->translation->translate('inbox', array(), true),
                                        'image' => array('messenger', 'navbar')
-                               ),
-                               'compose' => array
+                               )
+                       );
+                       if ($GLOBALS['phpgw']->acl->check('.compose', 
PHPGW_ACL_ADD, 'messenger'))
+                       {
+                               $menus['navigation']['compose'] = array
                                (
                                        'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'messenger.uimessenger.compose')),
                                        'text'  => 
$GLOBALS['phpgw']->translation->translate('compose', array(), true),
-                               ),
-                               'compose_global' => array
+                               );
+                       }
+                       if ($GLOBALS['phpgw']->acl->check('.compose_groups', 
PHPGW_ACL_ADD, 'messenger'))
+                       {
+                               $menus['navigation']['compose_groups'] = array
                                (
+                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'messenger.uimessenger.compose_groups')),
+                                       'text'  => 
$GLOBALS['phpgw']->translation->translate('compose groups', array(), true),
+                               );
+                       }
+                       if ($GLOBALS['phpgw']->acl->check('.compose_global', 
PHPGW_ACL_ADD, 'messenger'))
+                       {       
+                               $menus['navigation']['compose_global'] = array
+                               (
                                        'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'messenger.uimessenger.compose_global')),
                                        'text'  => 
$GLOBALS['phpgw']->translation->translate('compose global', array(), true),
-                               )
-                       );
-
+                               );
+                       }
                        $GLOBALS['phpgw_info']['flags']['currentapp'] = 
$incoming_app;
                        return $menus;
                }

Modified: people/sigurdne/modules/messenger/trunk/inc/class.uimessenger.inc.php
===================================================================
--- people/sigurdne/modules/messenger/trunk/inc/class.uimessenger.inc.php       
2010-04-14 18:10:42 UTC (rev 21179)
+++ people/sigurdne/modules/messenger/trunk/inc/class.uimessenger.inc.php       
2010-04-14 18:15:45 UTC (rev 21180)
@@ -18,16 +18,17 @@
                var $template;
                var $public_functions = array
                (
-                       'inbox'          => true,
-                       'compose'        => true,
-                       'compose_global' => true,
-                       'read_message'   => true,
-                       'reply'          => true,
-                       'forward'        => true,
-                       'delete'         => true
+                       'inbox'                         => true,
+                       'compose'                       => true,
+                       'compose_groups'        => true,
+                       'compose_global'        => true,
+                       'read_message'          => true,
+                       'reply'                         => true,
+                       'forward'                       => true,
+                       'delete'                        => true
                );
 
-               function uimessenger()
+               function __construct()
                {
                        $this->template   = $GLOBALS['phpgw']->template;
                        $this->bo         = 
CreateObject('messenger.bomessenger');
@@ -40,6 +41,13 @@
 
                function compose($errors = '')
                {
+                       if (!$GLOBALS['phpgw']->acl->check('.compose', 
PHPGW_ACL_ADD, 'messenger'))
+                       {
+                               $this->_no_access('compose');
+                       }
+
+                       $GLOBALS['phpgw_info']['flags']['menu_selection'] = 
'messenger::compose';
+
                        $message = isset($_POST['message']) ? $_POST['message'] 
: array('subject' => '', 'content' => '');
 
                        $this->_display_headers();
@@ -77,16 +85,106 @@
                        $this->template->pfp('out','form');
                }
 
-               function compose_global($errors = '')
+               function compose_groups()
                {
-                       global $message;
+                       if (!$GLOBALS['phpgw']->acl->check('.compose_groups', 
PHPGW_ACL_ADD, 'messenger'))
+                       {
+                               $this->_no_access('compose_groups');
+                       }
 
-                       if (! $GLOBALS['phpgw']->acl->check('run',1,'admin'))
+                       $GLOBALS['phpgw_info']['flags']['xslt_app'] = true;
+                       $GLOBALS['phpgw_info']['flags']['menu_selection'] = 
'messenger::compose_groups';
+
+                       $values = phpgw::get_var('values');
+                       $values['account_groups'] = (array) 
phpgw::get_var('account_groups', 'int', 'POST');
+                       $receipt = array();
+
+                       if (isset($values['save']))
                        {
-                               $this->inbox();
-                               return false;
+                               if(!$values['account_groups'])
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('Missing groups'));
+                               }
+
+                               if($GLOBALS['phpgw']->session->is_repost())
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('repost'));
+                               }
+
+                               if(!isset($values['subject']) || 
!$values['subject'])
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('Missing subject'));
+                               }
+
+                               if(!isset($values['content']) || 
!$values['content'])
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('Missing content'));
+                               }
+
+                               if(isset($values['save']) && 
$values['account_groups'] && !$receipt['error'])
+                               {
+                                       $receipt = 
$this->bo->send_to_groups($values);
+                               }
                        }
+                       $group_list = array();
 
+                       $all_groups = 
$GLOBALS['phpgw']->accounts->get_list('groups');
+
+                       if(!$GLOBALS['phpgw']->acl->check('run', 
phpgwapi_acl::READ, 'admin'))
+                       {
+                               $available_apps = 
$GLOBALS['phpgw_info']['apps'];
+                               $valid_groups = array();
+                               foreach($available_apps as $_app => $dummy)
+                               {
+                                       
if($GLOBALS['phpgw']->acl->check('admin', phpgwapi_acl::ADD, $_app))
+                                       {
+                                               $valid_groups   = 
array_merge($valid_groups,$GLOBALS['phpgw']->acl->get_ids_for_location('run', 
phpgwapi_acl::READ, $_app));
+                                       }
+                               }
+
+                               $valid_groups = array_unique($valid_groups);
+                       }
+                       else
+                       {
+                               $valid_groups = array_keys($all_groups);
+                       }
+
+                       foreach ( $all_groups as $group )
+                       {
+                               $group_list[$group->id] = array
+                               (
+                                       'account_id'    => $group->id,
+                                       'account_lid'   => $group->__toString(),
+                                       'i_am_admin'    => in_array($group->id, 
$valid_groups),
+                                       'selected'              => 
in_array($group->id, $values['account_groups'])
+                               );
+                       }
+
+                       $data = array
+                       (
+                               'msgbox_data'   => 
$GLOBALS['phpgw']->common->msgbox($GLOBALS['phpgw']->common->msgbox_data($receipt)),
+                               'form_action'   => 
$GLOBALS['phpgw']->link('/index.php',array('menuaction' => 
'messenger.uimessenger.compose_groups')),
+                               'group_list'    => $group_list,
+                               'value_subject' => isset($values['subject']) ? 
$values['subject'] : '',
+                               'value_content' => isset($values['content']) ? 
$values['content'] : ''
+                       );
+
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array('messenger'));
+                       $GLOBALS['phpgw']->xslttpl->set_var('phpgw', 
array('compose_groups' => $data));
+
+               }
+
+               function compose_global($errors = '')
+               {
+                       if (!$GLOBALS['phpgw']->acl->check('.compose_global', 
PHPGW_ACL_ADD, 'messenger'))
+                       {
+                               $this->_no_access('compose_global');
+                       }
+
+                       $GLOBALS['phpgw_info']['flags']['menu_selection'] = 
'messenger::compose_global';
+
+                       global $message;
+
                        $this->_display_headers();
                        $this->_set_compose_read_blocks();
 
@@ -375,4 +473,24 @@
                        $this->template->set_block('_form','form_read_buttons');
                        
$this->template->set_block('_form','form_read_buttons_for_global');
                }
+
+               function _no_access($location)
+               {
+                       $GLOBALS['phpgw']->common->phpgw_header(true);
+
+                       $log_args = array
+                       (
+                               'severity'      => 'W',
+                               'text'          => 'W-Permissions, Attempted to 
access %1',
+                               'p1'            => 
"{$GLOBALS['phpgw_info']['flags']['currentapp']}::{$location}"
+                       );
+
+                       $GLOBALS['phpgw']->log->warn($log_args);
+
+                       $lang_denied = lang('Access not permitted');
+                       echo <<<HTML
+                       <div class="error">$lang_denied</div>
+HTML;
+                       $GLOBALS['phpgw']->common->phpgw_exit(True);
+               }
        }

Modified: people/sigurdne/modules/messenger/trunk/inc/hook_config.inc.php
===================================================================
--- people/sigurdne/modules/messenger/trunk/inc/hook_config.inc.php     
2010-04-14 18:10:42 UTC (rev 21179)
+++ people/sigurdne/modules/messenger/trunk/inc/hook_config.inc.php     
2010-04-14 18:15:45 UTC (rev 21180)
@@ -3,7 +3,7 @@
 * phpGroupWare - KnowledgeBase                                             *
 * http://www.phpgroupware.org                                              *
 *                                                                          *
-* Copyright (c) 2003-2006 Free Sofware Foundation Inc                      *
+* Copyright (c) 2003-2010 Free Sofware Foundation Inc                      *
 * Written by Dave Hall skwashd at phpgropware.org                          *
 * ------------------------------------------------------------------------ *
 *  Started off as a port of phpBrain - http://vrotvrot.com/phpBrain/      *
@@ -19,15 +19,23 @@
 
        function restrict_to_group($config)
        {
-               $str = '';
                $groups = $GLOBALS['phpgw']->accounts->get_list('groups', -1, 
'ASC', 'account_lid', '', -1);
+
+               $restrict_to_group = isset($config['restrict_to_group']) && 
$config['restrict_to_group'] ? $config['restrict_to_group'] : array();
+               $out = '';
                foreach ( $groups as $group )
                {
-                       $str .= '<option value="' . $group->id . '"' . 
($config['restrict_to_group'] == $group->id ? ' selected="selected"' : '' ) .'>'
-                               . 
$GLOBALS['phpgw']->common->display_fullname($group->lid, $group->firstname, 
$group->lastname)
-                       ."</option>\n";
+                       $checked = in_array($group->id, $restrict_to_group) ? 
'checked = "checked"' : '';
+                       $out .=  <<<HTML
+                               <tr>
+                                       <td>
+                                               {$group->__toString()}
+                                       </td>
+                                       <td>
+                                               <input type="checkbox" 
name="newsettings[restrict_to_group][]" value="{$group->id}" {$checked}>
+                                       </td>
+                               </tr>
+HTML;
                }
-               return $str;
-               
$sbox->getAccount('newsettings[restrict_to_group]',$config['restrict_to_group'],
 true, 'groups', 1);
+               return $out;
        }
-?>

Modified: people/sigurdne/modules/messenger/trunk/setup/setup.inc.php
===================================================================
--- people/sigurdne/modules/messenger/trunk/setup/setup.inc.php 2010-04-14 
18:10:42 UTC (rev 21179)
+++ people/sigurdne/modules/messenger/trunk/setup/setup.inc.php 2010-04-14 
18:15:45 UTC (rev 21180)
@@ -16,7 +16,7 @@
 
        /* Basic information about this app */
        $setup_info['messenger']['name']      = 'messenger';
-       $setup_info['messenger']['version']   = '0.9.0';
+       $setup_info['messenger']['version']   = '0.9.17.500';
        $setup_info['messenger']['app_order'] = '10';
        $setup_info['messenger']['enable']    = 1;
        $setup_info['messenger']['app_group']   = 'office';

Modified: people/sigurdne/modules/messenger/trunk/setup/tables_update.inc.php
===================================================================
--- people/sigurdne/modules/messenger/trunk/setup/tables_update.inc.php 
2010-04-14 18:10:42 UTC (rev 21179)
+++ people/sigurdne/modules/messenger/trunk/setup/tables_update.inc.php 
2010-04-14 18:15:45 UTC (rev 21180)
@@ -4,4 +4,18 @@
        {
                return $GLOBALS['setup_info']['messenger']['currentver'] = 
'0.9.0';
        }
-?>
+
+       $test[] = '0.9.0';
+       function messenger_upgrade0_9_0()
+       {
+               $GLOBALS['phpgw']->locations->add('.', 'top', 'messenger', 
false);
+               $GLOBALS['phpgw']->locations->add('.compose', 'compose messages 
to users', 'messenger', false);
+               $GLOBALS['phpgw']->locations->add('.compose_groups', 'compose 
messages to groups', 'messenger', false);
+               $GLOBALS['phpgw']->locations->add('.compose_global', 'compose 
global message', 'messenger', false);
+
+               $GLOBALS['setup_info']['messenger']['currentver'] = 
'0.9.17.500';
+               return $GLOBALS['setup_info']['messenger']['currentver'];
+
+       }
+
+

Added: people/sigurdne/modules/messenger/trunk/templates/base/app_data.xsl
===================================================================
--- people/sigurdne/modules/messenger/trunk/templates/base/app_data.xsl         
                (rev 0)
+++ people/sigurdne/modules/messenger/trunk/templates/base/app_data.xsl 
2010-04-14 18:15:45 UTC (rev 21180)
@@ -0,0 +1,3 @@
+       <xsl:template name="dummy">
+       </xsl:template>
+

Modified: people/sigurdne/modules/messenger/trunk/templates/base/config.tpl
===================================================================
--- people/sigurdne/modules/messenger/trunk/templates/base/config.tpl   
2010-04-14 18:10:42 UTC (rev 21179)
+++ people/sigurdne/modules/messenger/trunk/templates/base/config.tpl   
2010-04-14 18:15:45 UTC (rev 21180)
@@ -31,10 +31,9 @@
                <tr class="row_off">
                        
<td>{lang_Restrict_users_to_only_sending_to_the_follow_group}:</td>
                        <td>
-                               <select name="newsettings[restrict_to_group]">
-                                       <option 
value="0">{lang_no_restriction}</a>
+                               <table>
                                        {hook_restrict_to_group}
-                               </select>
+                               </table>
                        </td>
                </tr>
 <!-- END body -->

Added: people/sigurdne/modules/messenger/trunk/templates/base/messenger.xsl
===================================================================
--- people/sigurdne/modules/messenger/trunk/templates/base/messenger.xsl        
                        (rev 0)
+++ people/sigurdne/modules/messenger/trunk/templates/base/messenger.xsl        
2010-04-14 18:15:45 UTC (rev 21180)
@@ -0,0 +1,101 @@
+<!-- $Id: support.xsl 4904 2010-02-24 13:32:35Z sigurd $ -->
+
+       <xsl:template match="compose_groups" xmlns:php="http://php.net/xsl";>
+               <form ENCTYPE="multipart/form-data" name="form" method="post" 
action="{form_action}">
+               <table cellpadding="0" cellspacing="0" width="100%">
+                       <xsl:choose>
+                               <xsl:when test="msgbox_data != ''">
+                                       <tr>
+                                               <td align="left" colspan="2">
+                                                       <xsl:call-template 
name="msgbox"/>
+                                               </td>
+                                       </tr>
+                               </xsl:when>
+                       </xsl:choose>
+               </table>
+               
+                       <div id="groups">
+                       <h2><xsl:value-of select="php:function('lang', 
'groups')" /></h2>
+                               <ul class="group_list">
+                                       <xsl:apply-templates 
select="group_list" />
+                               </ul>
+                       </div>
+
+                       <h2><xsl:value-of select="php:function('lang', 'Compose 
message')" /></h2>
+
+
+               <table>
+                       <tr class="th">
+                               <td class="th_text" valign="top">
+                                       <xsl:value-of 
select="php:function('lang', 'subject')" />
+                               </td>
+                               <td>
+                                       <input type="text" 
name="values[subject]" value='{value_subject}'>
+                                               <xsl:attribute name="size">
+                                                       <xsl:text>60</xsl:text>
+                                               </xsl:attribute>
+                                               <xsl:attribute name="title">
+                                                       <xsl:value-of 
select="php:function('lang', 'subject')" />
+                                               </xsl:attribute>
+                                       </input>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td valign="top">
+                                       <xsl:value-of 
select="php:function('lang', 'content')" />
+                               </td>
+                               <td>
+                                       <textarea cols="60" rows="10" 
name="values[content]" wrap="virtual" onMouseout="window.status='';return 
true;">
+                                               <xsl:attribute name="title">
+                                                       <xsl:value-of 
select="php:function('lang', 'content')" />
+                                               </xsl:attribute>
+                                               <xsl:value-of 
select="value_content"/>          
+                                       </textarea>
+                               </td>
+                       </tr>
+
+                       <tr height="50">
+                               <td>
+                                       <xsl:variable 
name="lang_send"><xsl:value-of select="php:function('lang', 'send')" 
/></xsl:variable>                                    
+                                       <input type="submit" 
name="values[save]" value="{$lang_send}" title='{$lang_send}'>
+                                       </input>
+                               </td>
+                       </tr>
+
+               </table>
+               </form>
+       </xsl:template>
+
+<!-- BEGIN group_list -->
+       <xsl:template match="group_list">
+               <li>
+                       <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:choose>
+                               <xsl:when test="i_am_admin = 1">
+                                       <input type="checkbox" 
id="account_groups{account_id}" name="account_groups[]" value="{account_id}">
+                                               <xsl:choose>
+                                                       <xsl:when 
test="selected = '1'">
+                                                               <xsl:attribute 
name="checked" value="checked" />
+                                                       </xsl:when>
+                                               </xsl:choose>
+                                       </input>
+                               </xsl:when>
+                               <xsl:otherwise>
+                                       <input type="checkbox" readonly='true'>
+                                       </input>
+                               </xsl:otherwise>
+                       </xsl:choose>
+
+                       <xsl:value-of select="account_lid"/>
+               </li>
+       </xsl:template>
+





reply via email to

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