fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [17202] more on helpdesk


From: sigurdne
Subject: [Fmsystem-commits] [17202] more on helpdesk
Date: Sun, 29 Oct 2017 08:15:09 -0400 (EDT)

Revision: 17202
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=17202
Author:   sigurdne
Date:     2017-10-29 08:15:09 -0400 (Sun, 29 Oct 2017)
Log Message:
-----------
more on helpdesk

Modified Paths:
--------------
    trunk/helpdesk/inc/hook_config.inc.php
    trunk/helpdesk/setup/phpgw_no.lang
    trunk/helpdesk/setup/setup.inc.php
    trunk/helpdesk/templates/base/config.tpl
    trunk/phpgwapi/inc/class.login.inc.php

Added Paths:
-----------
    trunk/helpdesk/inc/class.hook_helper.inc.php

Added: trunk/helpdesk/inc/class.hook_helper.inc.php
===================================================================
--- trunk/helpdesk/inc/class.hook_helper.inc.php                                
(rev 0)
+++ trunk/helpdesk/inc/class.hook_helper.inc.php        2017-10-29 12:15:09 UTC 
(rev 17202)
@@ -0,0 +1,190 @@
+<?php
+       /**
+        * Helpdesk - Hook helper
+        *
+        * @author Sigurd Nes <address@hidden>
+        * @copyright Copyright (C) 2017 Free Software Foundation, Inc. 
http://www.fsf.org/
+        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+        * @package Helpdesk
+        * @version $Id: class.hook_helper.inc.php 14728 2016-02-11 22:28:46Z 
sigurdne $
+        */
+       /*
+         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.
+
+         This program is distributed in the hope that it will be useful,
+         but WITHOUT ANY WARRANTY; without even the implied warranty of
+         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+         GNU General Public License for more details.
+
+         You should have received a copy of the GNU General Public License
+         along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
+
+       phpgw::import_class('frontend.bofellesdata');
+
+       /**
+        * Hook helper
+        *
+        * @package rental
+        */
+       class frontend_hook_helper
+       {
+
+               /**
+                * Create useraccount on login for SSO/ntlm
+                *
+                * @return void
+                */
+               public function auto_addaccount()
+               {
+                       $account_lid = $GLOBALS['hook_values']['account_lid'];
+
+                       if (!$GLOBALS['phpgw']->accounts->exists($account_lid))
+                       {
+                               $config = CreateObject('phpgwapi.config', 
'helpdesk')->read();
+
+                               $autocreate_user = 
isset($config['autocreate_user']) && $config['autocreate_user'] ? 
$config['autocreate_user'] : 0;
+
+                               if ($autocreate_user)
+                               {
+                                       $fellesdata_user = 
frontend_bofellesdata::get_instance()->get_user($account_lid);
+                                       if ($fellesdata_user)
+                                       {
+                                               // Read default assign-to-group 
from config
+                                               $default_group_id = 
isset($config['autocreate_default_group']) && 
$config['autocreate_default_group'] ? $config['autocreate_default_group'] : 0;
+                                               $group_lid = 
$GLOBALS['phpgw']->accounts->name2id($default_group_id);
+                                               $group_lid = $group_lid ? 
$group_lid : 'frontend_delegates';
+
+                                               $password = 'PEre' . 
mt_rand(100, mt_getrandmax()) . '&';
+                                               $account_id = 
self::create_phpgw_account($account_lid, $fellesdata_user['firstname'], 
$fellesdata_user['lastname'], $password, $group_lid);
+                                               if ($account_id)
+                                               {
+                                                       
$GLOBALS['phpgw']->redirect_link('/login.php', array());
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               /**
+                * Try to create a phpgw user
+                *
+                * @param string $username      the username
+                * @param string $firstname     the user's first name
+                * @param string $lastname the user's last name
+                * @param string $password      the user's password
+                */
+               public static function create_phpgw_account( string $username, 
string $firstname, string $lastname, string $password, $group_lid = 
'frontend_delegates' )
+               {
+
+                       // Create group account if needed
+                       if (!$GLOBALS['phpgw']->accounts->exists($group_lid)) 
// No group account exist
+                       {
+                               $account = new phpgwapi_group();
+                               $account->lid = $group_lid;
+                               $account->firstname = 'Frontend';
+                               $account->lastname = 'Delegates';
+                               $frontend_delegates = 
$GLOBALS['phpgw']->accounts->create($account, array(), array(), $modules);
+
+                               $aclobj = & $GLOBALS['phpgw']->acl;
+                               $aclobj->set_account_id($frontend_delegates, 
true);
+                               $aclobj->add('frontend', '.', 1);
+                               $aclobj->add('frontend', 'run', 1);
+                               $aclobj->add('manual', '.', 1);
+                               $aclobj->add('manual', 'run', 1);
+                               $aclobj->add('preferences', 'changepassword', 
1);
+                               $aclobj->add('preferences', '.', 1);
+                               $aclobj->add('preferences', 'run', 1);
+                               $aclobj->add('helpdesk', '.ticket', 1);
+
+                               $aclobj->add('frontend', '.ticket', 1);
+                               $aclobj->add('frontend', '.rental.contract', 1);
+                               $aclobj->add('frontend', '.rental.contract_in', 
1);
+                               $aclobj->save_repository();
+                       }
+                       else
+                       {
+                               $frontend_delegates = 
$GLOBALS['phpgw']->accounts->name2id($group_lid);
+                       }
+
+                       if (isset($username) && isset($firstname) && 
isset($lastname) && isset($password))
+                       {
+                               if 
(!$GLOBALS['phpgw']->accounts->exists($username))
+                               {
+                                       $account = new phpgwapi_user();
+                                       $account->lid = $username;
+                                       $account->firstname = $firstname;
+                                       $account->lastname = $lastname;
+                                       $account->passwd = $password;
+                                       $account->enabled = true;
+                                       $account->expires = -1;
+                                       $result = 
$GLOBALS['phpgw']->accounts->create($account, array($frontend_delegates), 
array(), array(
+                                               'helpdesk'));
+                                       if ($result)
+                                       {
+                                               $fellesdata_user = 
frontend_bofellesdata::get_instance()->get_user($username);
+                                               if ($fellesdata_user)
+                                               {
+                                                       $email = 
$fellesdata_user['email'];
+                                                       if (!empty($email))
+                                                       {
+                                                               $title = 
lang('email_create_account_title');
+                                                               $message = 
lang('email_create_account_message', $fellesdata_user['firstname'], 
$fellesdata_user['lastname']);
+                                                               
self::send_system_message($email, $title, $message);
+                                                       }
+                                               }
+
+                                               $preferences = 
createObject('phpgwapi.preferences', $result);
+                                               $preferences->add('common', 
'default_app', 'helpdesk');
+                                               if (!empty($email))
+                                               {
+                                                       
$preferences->add('helpdesk', 'email', $email);
+                                               }
+                                               $preferences->save_repository();
+
+                                               
$GLOBALS['phpgw']->log->write(array('text' => 'I-Notification, user created %1',
+                                                       'p1' => $username));
+                                       }
+
+                                       return $result;
+                               }
+                       }
+                       return false;
+               }
+
+               /**
+                *
+                * @param unknown_type $to
+                * @param unknown_type $title
+                * @param unknown_type $contract_message
+                * @param unknown_type $from
+                */
+               public static function send_system_message( $to, $title, 
$contract_message, $from = 'address@hidden' )
+               {
+                       if 
(isset($GLOBALS['phpgw_info']['server']['smtp_server']) && 
$GLOBALS['phpgw_info']['server']['smtp_server'])
+                       {
+                               if (!is_object($GLOBALS['phpgw']->send))
+                               {
+                                       $GLOBALS['phpgw']->send = 
CreateObject('phpgwapi.send');
+                               }
+
+                               try
+                               {
+                                       $rcpt = 
$GLOBALS['phpgw']->send->msg('email', $to, $title, 
stripslashes(nl2br($contract_message)), '', '', '', $from, 'System message', 
'html', '', array(), false);
+                               }
+                               catch (Exception $e)
+                               {
+
+                               }
+
+                               return !!$rcpt;
+
+                       }
+                       return false;
+               }
+
+       }
\ No newline at end of file

Modified: trunk/helpdesk/inc/hook_config.inc.php
===================================================================
--- trunk/helpdesk/inc/hook_config.inc.php      2017-10-28 19:57:58 UTC (rev 
17201)
+++ trunk/helpdesk/inc/hook_config.inc.php      2017-10-29 12:15:09 UTC (rev 
17202)
@@ -226,3 +226,31 @@
                return $out;
        }
 
+
+               /**
+        * Get HTML selectbox with user groups - which group to add autocreated 
users
+        *
+        * @param $config
+        * @return string options for selectbox
+        */
+       function autocreate_default_group( $config )
+       {
+               $groups = $GLOBALS['phpgw']->accounts->get_list('groups');
+               $group_assigned = isset($config['autocreate_default_group']) ? 
$config['autocreate_default_group'] : '';
+
+               $out = '<option value="">' . lang('none selected') . 
'</option>' . "\n";
+
+               foreach ($groups as $group => $label)
+               {
+                       $selected = '';
+                       if ($group_assigned == $group)
+                       {
+                               $selected = ' selected';
+                       }
+
+                       $out .= <<<HTML
+                               <option 
value="{$group}"{$selected}>{$label}</option>
+HTML;
+               }
+               return $out;
+       }

Modified: trunk/helpdesk/setup/phpgw_no.lang
===================================================================
--- trunk/helpdesk/setup/phpgw_no.lang  2017-10-28 19:57:58 UTC (rev 17201)
+++ trunk/helpdesk/setup/phpgw_no.lang  2017-10-29 12:15:09 UTC (rev 17202)
@@ -217,4 +217,6 @@
 ticket status  helpdesk        no      Meldingsstatus
 url    helpdesk        no      Url
 forward        helpdesk        no      Videresend
-ticket is forwarded    helpdesk        no      Melding er videresendt
\ No newline at end of file
+ticket is forwarded    helpdesk        no      Melding er videresendt
+email_create_account_title     helpdesk        no      LRS systemtilgang
+email_create_account_message   helpdesk        no      Systemmelding fra LRS 
til %1 %2:<br/>Det er opprettet en tilgang for deg i LRS<br/><br/>Du får 
tilgang til systemet via kommunens intranett.<br/>Under verktøy i høyre 
kolonne, velg fra LRS listen.<br/>Brukerveiledning finner du i systemet, ved å 
velge "Hjelp" i toppmenyen.<br/>Har du spørsmål send en e-post til LRS 
brukerstøtte.<br/>

Modified: trunk/helpdesk/setup/setup.inc.php
===================================================================
--- trunk/helpdesk/setup/setup.inc.php  2017-10-28 19:57:58 UTC (rev 17201)
+++ trunk/helpdesk/setup/setup.inc.php  2017-10-29 12:15:09 UTC (rev 17202)
@@ -66,6 +66,7 @@
                'cat_add'               => 'helpdesk.cat_hooks.cat_add',
                'cat_delete'    => 'helpdesk.cat_hooks.cat_delete',
                'cat_edit'              => 'helpdesk.cat_hooks.cat_edit',
+               'auto_addaccount' => 'helpdesk.hook_helper.auto_addaccount',
                'config',
                'home',
        );

Modified: trunk/helpdesk/templates/base/config.tpl
===================================================================
--- trunk/helpdesk/templates/base/config.tpl    2017-10-28 19:57:58 UTC (rev 
17201)
+++ trunk/helpdesk/templates/base/config.tpl    2017-10-29 12:15:09 UTC (rev 
17202)
@@ -215,6 +215,23 @@
                                </select>
                        </td>
                </tr>
+               <tr class="row_on">
+                       <td>{lang_activate_autocreate_user}:</td>
+                       <td>
+                               <select name="newsettings[autocreate_user]">
+                                       <option value="" 
{selected_autocreate_user_}>NO</option>
+                                       <option value="1" 
{selected_autocreate_user_1}>YES</option>
+                               </select>
+                       </td>
+               </tr>
+               <tr class="row_off">
+                       <td>{lang_autocreate_default_group}:</td>
+                       <td>
+                               <select 
name="newsettings[autocreate_default_group]">
+                                       {hook_autocreate_default_group}
+                               </select>
+                       </td>
+               </tr>
 
                <!-- END body -->
                <!-- BEGIN footer -->

Modified: trunk/phpgwapi/inc/class.login.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.login.inc.php      2017-10-28 19:57:58 UTC (rev 
17201)
+++ trunk/phpgwapi/inc/class.login.inc.php      2017-10-29 12:15:09 UTC (rev 
17202)
@@ -168,7 +168,7 @@
                                        'account_lid' => $login
                                );
 
-                               
$GLOBALS['phpgw']->hooks->process('auto_addaccount', array('frontend'));
+                               
$GLOBALS['phpgw']->hooks->process('auto_addaccount', array('frontend', 
'helpdesk'));
 
                        //------------------Start login ntlm
 
@@ -270,7 +270,7 @@
                                        (
                                                'account_lid' => $login
                                        );
-                                       
$GLOBALS['phpgw']->hooks->process('auto_addaccount', array('frontend'));
+                                       
$GLOBALS['phpgw']->hooks->process('auto_addaccount', array('frontend', 
'helpdesk'));
                                        $GLOBALS['sessionid'] = 
$GLOBALS['phpgw']->session->create($login, '');
                                }
 




reply via email to

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