2001-09-02 01:32:40 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-01-27 00:26:19 +01:00
|
|
|
* eGroupWare - account administration *
|
|
|
|
* http://www.egroupware.org *
|
2003-08-28 16:16:30 +02:00
|
|
|
* -------------------------------------------- *
|
2001-09-02 01:32:40 +02:00
|
|
|
* 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. *
|
|
|
|
\**************************************************************************/
|
2003-08-28 16:16:30 +02:00
|
|
|
|
2001-09-04 05:29:36 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2001-09-02 01:32:40 +02:00
|
|
|
class boaccounts
|
|
|
|
{
|
2001-09-04 06:26:51 +02:00
|
|
|
var $so;
|
2003-08-28 16:16:30 +02:00
|
|
|
var $public_functions = array(
|
|
|
|
'add_group' => True,
|
|
|
|
'add_user' => True,
|
|
|
|
'delete_group' => True,
|
|
|
|
'delete_user' => True,
|
|
|
|
'edit_group' => True,
|
2007-03-09 13:07:15 +01:00
|
|
|
'edit_user' => True
|
2001-09-02 01:32:40 +02:00
|
|
|
);
|
|
|
|
|
2001-10-10 17:10:15 +02:00
|
|
|
var $xml_functions = array();
|
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
var $soap_functions = array(
|
|
|
|
'add_user' => array(
|
|
|
|
'in' => array('int', 'struct'),
|
|
|
|
'out' => array()
|
2001-10-10 17:10:15 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
function delete_group($account_id='')
|
2006-03-08 17:53:16 +01:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
if(!$account_id || $GLOBALS['egw']->acl->check('group_access',32,'admin'))
|
2006-03-08 17:53:16 +01:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
return False;
|
2003-04-23 23:52:22 +02:00
|
|
|
}
|
2007-03-09 13:07:15 +01:00
|
|
|
|
|
|
|
$account_id = (int)$account_id;
|
2003-08-28 16:16:30 +02:00
|
|
|
|
2006-06-07 01:42:56 +02:00
|
|
|
// delete all acl (and memberships) of group
|
|
|
|
$GLOBALS['egw']->acl->delete_account($account_id);
|
2003-08-28 16:16:30 +02:00
|
|
|
|
2010-03-08 22:08:16 +01:00
|
|
|
// make this information also available in the hook
|
2007-04-29 14:07:43 +02:00
|
|
|
$lid = $GLOBALS['egw']->accounts->id2name($account_id);
|
|
|
|
|
|
|
|
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values'] = array(
|
|
|
|
'account_id' => $account_id,
|
|
|
|
'account_name' => $lid,
|
|
|
|
'location' => 'deletegroup'
|
|
|
|
),False,True); // called for every app now, not only enabled ones)
|
2003-08-28 16:16:30 +02:00
|
|
|
|
2005-10-14 19:03:16 +02:00
|
|
|
$GLOBALS['egw']->accounts->delete($account_id);
|
2003-08-28 16:16:30 +02:00
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
return True;
|
2003-04-23 23:52:22 +02:00
|
|
|
}
|
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
function delete_user($account_id='',$new_owner='')
|
2003-08-28 16:16:30 +02:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
if(!$account_id || $GLOBALS['egw']->acl->check('account_access',32,'admin'))
|
2003-08-28 16:16:30 +02:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
$accountid = (int)$account_id;
|
|
|
|
$account_id = get_account_id($accountid);
|
2010-03-08 22:08:16 +01:00
|
|
|
// make this information also available in the hook
|
2007-03-09 13:07:15 +01:00
|
|
|
$lid = $GLOBALS['egw']->accounts->id2name($account_id);
|
2003-08-28 16:16:30 +02:00
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
$GLOBALS['hook_values'] = array(
|
|
|
|
'account_id' => $account_id,
|
|
|
|
'account_lid' => $lid,
|
|
|
|
'new_owner' => (int)$new_owner,
|
|
|
|
'location' => 'deleteaccount'
|
|
|
|
);
|
|
|
|
// first all other apps, then preferences and admin
|
|
|
|
foreach(array_merge(array_diff(array_keys($GLOBALS['egw_info']['apps']),array('preferences','admin')),array('preferences','admin')) as $app)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->hooks->single($GLOBALS['hook_values'],$app);
|
|
|
|
}
|
|
|
|
return True;
|
2003-08-28 16:16:30 +02:00
|
|
|
}
|
2001-09-02 01:32:40 +02:00
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
function add_group($group_info)
|
2001-09-03 04:58:25 +02:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
if($GLOBALS['egw']->acl->check('group_access',4,'admin'))
|
2003-08-28 16:16:30 +02:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
$errors = $this->validate_group($group_info);
|
|
|
|
if(count($errors))
|
2001-09-03 04:58:25 +02:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
return $errors;
|
2001-09-03 04:58:25 +02:00
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
|
2005-10-14 19:03:16 +02:00
|
|
|
$group =& CreateObject('phpgwapi.accounts',$group_info['account_id'],'g');
|
2001-09-04 05:13:28 +02:00
|
|
|
$group->acct_type = 'g';
|
2003-08-28 16:16:30 +02:00
|
|
|
$account_info = array(
|
2001-09-03 04:58:25 +02:00
|
|
|
'account_type' => 'g',
|
|
|
|
'account_lid' => $group_info['account_name'],
|
|
|
|
'account_passwd' => '',
|
|
|
|
'account_firstname' => $group_info['account_name'],
|
|
|
|
'account_lastname' => 'Group',
|
|
|
|
'account_status' => 'A',
|
2006-10-11 23:58:58 +02:00
|
|
|
'account_expires' => -1,
|
2001-09-03 04:58:25 +02:00
|
|
|
// 'account_file_space' => $account_file_space_number . "-" . $account_file_space_type,
|
2007-03-09 13:07:15 +01:00
|
|
|
'account_email' => $group_info['account_email'],
|
|
|
|
'account_members' => $group_info['account_user']
|
2001-09-03 04:58:25 +02:00
|
|
|
);
|
2004-07-13 00:06:13 +02:00
|
|
|
$group_info['account_id'] = $group->create($account_info);
|
2007-03-09 13:07:15 +01:00
|
|
|
|
|
|
|
// do the following only if we got an id - the create succeeded
|
|
|
|
if($group_info['account_id'])
|
2001-09-03 04:58:25 +02:00
|
|
|
{
|
2006-06-07 01:42:56 +02:00
|
|
|
$group->set_members($group_info['account_user'],$group_info['account_id']);
|
|
|
|
|
2005-10-14 19:03:16 +02:00
|
|
|
$apps =& CreateObject('phpgwapi.applications',$group_info['account_id']);
|
2004-07-13 00:06:13 +02:00
|
|
|
$apps->update_data(Array());
|
|
|
|
reset($group_info['account_apps']);
|
|
|
|
while(list($app,$value) = each($group_info['account_apps']))
|
2001-09-04 05:13:28 +02:00
|
|
|
{
|
2004-07-13 00:06:13 +02:00
|
|
|
$apps->add($app);
|
|
|
|
$new_apps[] = $app;
|
2001-09-04 05:13:28 +02:00
|
|
|
}
|
2004-07-13 00:06:13 +02:00
|
|
|
$apps->save_repository();
|
2007-03-09 13:07:15 +01:00
|
|
|
|
2007-04-29 14:07:43 +02:00
|
|
|
$GLOBALS['hook_values'] = $group_info;
|
|
|
|
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
|
|
|
|
'location' => 'addgroup'
|
|
|
|
),False,True); // called for every app now, not only enabled ones)
|
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
return True;
|
2001-09-03 04:58:25 +02:00
|
|
|
}
|
2007-03-09 13:07:15 +01:00
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
return False;
|
2001-09-03 04:58:25 +02:00
|
|
|
}
|
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
function edit_group($group_info)
|
2001-09-02 09:30:25 +02:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
if($GLOBALS['egw']->acl->check('group_access',16,'admin'))
|
2001-09-04 06:26:51 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
return False;
|
2001-09-04 06:26:51 +02:00
|
|
|
}
|
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
$errors = $this->validate_group($group_info);
|
|
|
|
if(count($errors))
|
2001-09-02 09:30:25 +02:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
return $errors;
|
2001-09-02 09:30:25 +02:00
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
|
2005-10-14 19:03:16 +02:00
|
|
|
$group =& CreateObject('phpgwapi.accounts',$group_info['account_id'],'g');
|
2001-09-03 04:58:25 +02:00
|
|
|
$old_group_info = $group->read_repository();
|
2001-12-18 07:10:32 +01:00
|
|
|
|
2001-09-02 09:30:25 +02:00
|
|
|
// Set group apps
|
2005-10-14 19:03:16 +02:00
|
|
|
$apps =& CreateObject('phpgwapi.applications',$group_info['account_id']);
|
2001-09-02 09:30:25 +02:00
|
|
|
$apps_before = $apps->read_account_specific();
|
|
|
|
$apps->update_data(Array());
|
|
|
|
$new_apps = Array();
|
2001-09-03 04:58:25 +02:00
|
|
|
if(count($group_info['account_apps']))
|
2001-09-02 09:30:25 +02:00
|
|
|
{
|
2001-09-03 04:58:25 +02:00
|
|
|
reset($group_info['account_apps']);
|
|
|
|
while(list($app,$value) = each($group_info['account_apps']))
|
2001-09-02 09:30:25 +02:00
|
|
|
{
|
2001-09-03 04:58:25 +02:00
|
|
|
$apps->add($app);
|
|
|
|
if(!@$apps_before[$app] || @$apps_before == False)
|
2001-09-02 09:30:25 +02:00
|
|
|
{
|
2001-09-03 04:58:25 +02:00
|
|
|
$new_apps[] = $app;
|
2001-09-02 09:30:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$apps->save_repository();
|
|
|
|
|
2006-06-07 01:42:56 +02:00
|
|
|
$group->set_members($group_info['account_user'],$group_info['account_id']);
|
2001-09-02 09:30:25 +02:00
|
|
|
|
2007-04-29 14:07:43 +02:00
|
|
|
$GLOBALS['hook_values'] = $group_info;
|
|
|
|
$GLOBALS['hook_values']['old_name'] = $group->id2name($group_info['account_id']);
|
|
|
|
|
2004-06-23 15:19:38 +02:00
|
|
|
// This is down here so we are sure to catch the acl changes
|
|
|
|
// for LDAP to update the memberuid attribute
|
2007-03-09 13:07:15 +01:00
|
|
|
$group->data['account_email'] = $group_info['account_email'];
|
2007-05-04 16:18:47 +02:00
|
|
|
$group->data['account_lid'] = $group_info['account_name'];
|
2001-09-02 09:30:25 +02:00
|
|
|
$group->save_repository();
|
2007-03-09 13:07:15 +01:00
|
|
|
|
2006-01-04 20:19:11 +01:00
|
|
|
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
|
|
|
|
'location' => 'editgroup'
|
|
|
|
),False,True); // called for every app now, not only enabled ones)
|
2001-09-02 09:30:25 +02:00
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
return True;
|
2001-09-02 09:30:25 +02:00
|
|
|
}
|
|
|
|
|
2013-06-25 18:37:44 +02:00
|
|
|
/**
|
|
|
|
* Process a user edit
|
|
|
|
*
|
|
|
|
* @param array $userData
|
|
|
|
* @param int $required_account_access=16 can be set to 4 for add user
|
|
|
|
* @return boolean|array with errors or true on success, false on acl failure
|
|
|
|
*/
|
|
|
|
function edit_user(&$userData, $required_account_access=16)
|
2001-09-02 01:32:40 +02:00
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
if($GLOBALS['egw']->acl->check('account_access',$required_account_access,'admin'))
|
2001-09-04 06:26:51 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
return False;
|
|
|
|
}
|
2010-09-22 11:48:27 +02:00
|
|
|
//error_log(array2string($userData));
|
2004-01-12 07:22:20 +01:00
|
|
|
$accountPrefix = '';
|
2005-10-14 19:03:16 +02:00
|
|
|
if(isset($GLOBALS['egw_info']['server']['account_prefix']))
|
2004-01-12 07:22:20 +01:00
|
|
|
{
|
2005-10-14 19:03:16 +02:00
|
|
|
$accountPrefix = $GLOBALS['egw_info']['server']['account_prefix'];
|
2004-01-12 07:22:20 +01:00
|
|
|
}
|
2013-07-14 15:05:24 +02:00
|
|
|
if($accountPrefix && strpos($userData['account_lid'], $accountPrefix) !== 0)
|
2009-02-16 09:22:22 +01:00
|
|
|
{
|
|
|
|
$userData['account_lid'] = $accountPrefix . $userData['account_lid'];
|
|
|
|
}
|
2001-09-04 06:26:51 +02:00
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
$errors = $this->validate_user($userData);
|
2013-06-25 18:37:44 +02:00
|
|
|
|
|
|
|
if(!$errors)
|
2002-01-10 19:18:44 +01:00
|
|
|
{
|
2013-06-26 21:55:20 +02:00
|
|
|
$new_user = !$userData['account_id'];
|
|
|
|
$passwd = $userData['account_passwd'];
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors = $this->save_user($userData);
|
2013-06-26 21:55:20 +02:00
|
|
|
$GLOBALS['hook_values'] = $userData + ($new_user ? array(
|
|
|
|
'new_password' => $passwd,
|
|
|
|
) : array());
|
2007-03-09 13:07:15 +01:00
|
|
|
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
|
2013-06-26 21:55:20 +02:00
|
|
|
'location' => $new_user ? 'addaccount' : 'editaccount',
|
2007-03-09 13:07:15 +01:00
|
|
|
),False,True); // called for every app now, not only enabled ones)
|
2002-01-10 19:18:44 +01:00
|
|
|
}
|
2013-06-26 21:55:20 +02:00
|
|
|
//error_log(__METHOD__."(".array2string($userData).") returning ".array2string($errors ? $errors : true));
|
2013-06-25 18:37:44 +02:00
|
|
|
return $errors ? $errors : true;
|
2002-01-10 19:18:44 +01:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
function validate_group($group_info)
|
2001-09-03 04:58:25 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
$errors = Array();
|
2007-03-09 13:07:15 +01:00
|
|
|
|
2005-10-14 19:03:16 +02:00
|
|
|
$group =& CreateObject('phpgwapi.accounts',$group_info['account_id'],'g');
|
2001-09-03 04:58:25 +02:00
|
|
|
$group->read_repository();
|
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
if(!$group_info['account_name'])
|
2001-09-03 04:58:25 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
$errors[] = lang('You must enter a group name.');
|
2003-04-23 03:08:32 +02:00
|
|
|
}
|
2007-03-09 13:07:15 +01:00
|
|
|
/* For LDAP */
|
|
|
|
if(!$group_info['account_user'])
|
|
|
|
{
|
|
|
|
$errors[] = lang('You must select at least one group member.');
|
|
|
|
}
|
2003-04-23 03:08:32 +02:00
|
|
|
|
2003-08-28 16:16:30 +02:00
|
|
|
if($group_info['account_name'] != $group->id2name($group_info['account_id']))
|
2003-04-23 03:08:32 +02:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
if($group->exists($group_info['account_name']))
|
2001-09-03 04:58:25 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
$errors[] = lang('Sorry, that group name has already been taken.');
|
2001-09-03 04:58:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-03-09 13:07:15 +01:00
|
|
|
if(preg_match("/\D/", $account_file_space_number))
|
2001-09-03 04:58:25 +02:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
$errors[] = lang('File space must be an integer');
|
2001-09-03 04:58:25 +02:00
|
|
|
}
|
|
|
|
*/
|
2003-08-28 16:16:30 +02:00
|
|
|
if(count($errors))
|
2001-09-03 04:58:25 +02:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
return $errors;
|
2001-09-03 04:58:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 18:37:44 +02:00
|
|
|
/**
|
|
|
|
* checks if the userdata are valid
|
|
|
|
*
|
|
|
|
* @return array with errors or empty array if there are none
|
|
|
|
*/
|
2003-08-28 16:16:30 +02:00
|
|
|
function validate_user(&$_userData)
|
2001-09-02 01:32:40 +02:00
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors = array();
|
2001-09-02 01:32:40 +02:00
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
if($GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
|
2003-09-01 00:09:12 +02:00
|
|
|
(!$_userData['account_lastname'] && !$_userData['lastname']))
|
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors[] = lang('You must enter a lastname');
|
2003-09-01 00:09:12 +02:00
|
|
|
}
|
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
if(!$_userData['account_lid'])
|
2001-09-02 01:32:40 +02:00
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors[] = lang('You must enter a loginid');
|
2001-09-02 01:32:40 +02:00
|
|
|
}
|
2007-03-09 13:07:15 +01:00
|
|
|
|
2003-09-13 19:14:30 +02:00
|
|
|
if(!in_array($_userData['account_primary_group'],$_userData['account_groups']))
|
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors[] = lang('The groups must include the primary group');
|
2003-09-13 19:14:30 +02:00
|
|
|
}
|
2010-03-16 17:33:28 +01:00
|
|
|
// Check if an account already exists as system user, and if it does deny creation
|
|
|
|
// (increase the totalerrors counter and the message thereof)
|
|
|
|
if ($GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
|
2013-05-27 16:30:22 +02:00
|
|
|
!$GLOBALS['egw_info']['server']['ldap_allow_systemusernames'] && !$_userData['account_id'] &&
|
2010-03-16 17:33:28 +01:00
|
|
|
function_exists('posix_getpwnam') && posix_getpwnam($_userData['account_lid']))
|
2009-12-16 15:10:15 +01:00
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors[] = lang('There already is a system-user with this name. User\'s should not have the same name as a systemuser');
|
2009-12-16 15:10:15 +01:00
|
|
|
}
|
2007-03-09 13:07:15 +01:00
|
|
|
if($_userData['old_loginid'] != $_userData['account_lid'])
|
2001-09-02 01:32:40 +02:00
|
|
|
{
|
2009-12-16 15:10:15 +01:00
|
|
|
if($GLOBALS['egw']->accounts->exists($_userData['account_lid']))
|
2001-09-02 01:32:40 +02:00
|
|
|
{
|
2009-12-16 15:10:15 +01:00
|
|
|
if($GLOBALS['egw']->accounts->exists($_userData['account_lid']) && $GLOBALS['egw']->accounts->get_type($_userData['account_lid'])=='g')
|
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors[] = lang('There already is a group with this name. Userid\'s can not have the same name as a groupid');
|
2009-12-16 15:10:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors[] = lang('That loginid has already been taken');
|
2009-12-16 15:10:15 +01:00
|
|
|
}
|
2001-09-02 01:32:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
if($_userData['account_passwd'] || $_userData['account_passwd_2'])
|
2001-09-02 01:32:40 +02:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
if($_userData['account_passwd'] != $_userData['account_passwd_2'])
|
2002-05-26 10:50:40 +02:00
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors[] = lang('The two passwords are not the same');
|
2002-05-26 10:50:40 +02:00
|
|
|
}
|
2001-09-02 01:32:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
if(!count($_userData['account_permissions']) && !count($_userData['account_groups']))
|
2001-09-02 01:32:40 +02:00
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors[] = lang('You must add at least 1 permission or group to this account');
|
2001-09-02 01:32:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-09 13:07:15 +01:00
|
|
|
if($_userData['account_expires_month'] || $_userData['account_expires_day'] || $_userData['account_expires_year'] || $_userData['account_expires_never'])
|
2001-09-02 01:32:40 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
if($_userData['account_expires_never'])
|
2001-09-02 01:32:40 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
$_userData['expires'] = -1;
|
|
|
|
$_userData['account_expires'] = $_userData['expires'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
if(! checkdate($_userData['account_expires_month'],$_userData['account_expires_day'],$_userData['account_expires_year']))
|
2003-08-28 16:16:30 +02:00
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors[] = lang('You have entered an invalid expiration date');
|
2003-08-28 16:16:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$_userData['expires'] = mktime(2,0,0,$_userData['account_expires_month'],$_userData['account_expires_day'],$_userData['account_expires_year']);
|
|
|
|
$_userData['account_expires'] = $_userData['expires'];
|
|
|
|
}
|
2001-09-02 01:32:40 +02:00
|
|
|
}
|
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$_userData['expires'] = -1;
|
|
|
|
$_userData['account_expires'] = $_userData['expires'];
|
|
|
|
}
|
2001-09-02 01:32:40 +02:00
|
|
|
|
|
|
|
/*
|
2007-03-09 13:07:15 +01:00
|
|
|
$check_account_file_space = explode('-', $_userData['file_space']);
|
|
|
|
if(preg_match("/\D/", $check_account_file_space[0]))
|
2001-09-02 01:32:40 +02:00
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors[] = lang('File space must be an integer');
|
2001-09-02 01:32:40 +02:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2013-06-25 18:37:44 +02:00
|
|
|
return $errors;
|
2001-09-02 01:32:40 +02:00
|
|
|
}
|
2001-12-18 07:10:32 +01:00
|
|
|
|
2013-06-25 18:37:44 +02:00
|
|
|
/**
|
|
|
|
* stores the userdata
|
|
|
|
*
|
|
|
|
* @param array &$_userData "account_id" got set for new accounts
|
|
|
|
* @return array with error-messages
|
|
|
|
*/
|
|
|
|
function save_user(array &$_userData)
|
2001-09-02 01:32:40 +02:00
|
|
|
{
|
2013-06-26 12:48:37 +02:00
|
|
|
//error_log(__METHOD__."(".array2string($_userData).")");
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors = array();
|
2007-03-09 13:07:15 +01:00
|
|
|
|
2013-06-25 18:37:44 +02:00
|
|
|
// do NOT save password via accounts::save, as pw policy violation can happen and we cant/dont report that way
|
|
|
|
$passwd = $_userData['account_passwd'];
|
2013-07-16 16:58:38 +02:00
|
|
|
$new_account = !$_userData['account_id'];
|
2013-06-25 18:37:44 +02:00
|
|
|
unset($_userData['account_passwd']);
|
|
|
|
unset($_userData['account_passwd_2']);
|
2013-07-16 16:58:38 +02:00
|
|
|
|
|
|
|
if ($new_account && !$GLOBALS['egw']->accounts->save($_userData))
|
2001-12-18 07:10:32 +01:00
|
|
|
{
|
2013-06-25 18:37:44 +02:00
|
|
|
$errors[] = lang('Failed to save user!');
|
|
|
|
return $errors;
|
|
|
|
}
|
2003-10-07 19:06:53 +02:00
|
|
|
|
2013-06-25 18:37:44 +02:00
|
|
|
if ($passwd)
|
|
|
|
{
|
2013-07-30 20:13:22 +02:00
|
|
|
$_userData['account_passwd'] = $passwd;
|
2013-06-25 18:37:44 +02:00
|
|
|
try {
|
|
|
|
$auth = new auth();
|
|
|
|
if ($auth->change_password('', $passwd, $_userData['account_id']))
|
|
|
|
{
|
|
|
|
$GLOBALS['hook_values']['account_id'] = $_userData['account_id'];
|
|
|
|
$GLOBALS['hook_values']['old_passwd'] = '';
|
2013-07-30 20:13:22 +02:00
|
|
|
$GLOBALS['hook_values']['new_passwd'] = $passwd;
|
2013-06-25 18:37:44 +02:00
|
|
|
|
|
|
|
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
|
|
|
|
'location' => 'changepassword'
|
|
|
|
),False,True); // called for every app now, not only enabled ones)
|
2013-07-16 16:58:38 +02:00
|
|
|
|
|
|
|
if ($_userData['account_lastpwd_change']==0 || // AD requires to activate account AFTER setting pw
|
|
|
|
$new_account && $_userData['account_status'] == 'A' && $GLOBALS['egw']->accounts->require_password_for_enable())
|
2013-06-25 18:37:44 +02:00
|
|
|
{
|
|
|
|
// change password sets the shadow_timestamp/account_lastpwd_change timestamp
|
|
|
|
// so we need to reset that to 0 as Admin required the change of password upon next login
|
2013-07-16 16:58:38 +02:00
|
|
|
$GLOBALS['egw']->accounts->save($_userData);
|
2013-06-25 18:37:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-16 16:58:38 +02:00
|
|
|
$errors[] = lang('Failed to change password.');
|
2013-06-25 18:37:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception $e) {
|
|
|
|
$errors[] = $e->getMessage();
|
2010-09-22 11:48:27 +02:00
|
|
|
}
|
2001-09-02 01:32:40 +02:00
|
|
|
}
|
2013-07-16 16:58:38 +02:00
|
|
|
$GLOBALS['egw']->accounts->set_memberships($_userData['account_groups'],$_userData['account_id']);
|
|
|
|
|
|
|
|
if (!$new_account && !$GLOBALS['egw']->accounts->save($_userData))
|
|
|
|
{
|
|
|
|
$errors[] = lang('Failed to save user!');
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
2011-03-16 13:44:42 +01:00
|
|
|
if ($_userData['account_lastpwd_change']==0)
|
|
|
|
{
|
2011-03-16 14:26:17 +01:00
|
|
|
if (!isset($auth)) $auth =& CreateObject('phpgwapi.auth');
|
2011-03-16 13:44:42 +01:00
|
|
|
// we call that with NULL for 2nd Parameter as we are doing an admin action.
|
|
|
|
$auth->setLastPwdChange($_userData['account_id'],NULL, $_userData['account_lastpwd_change']);
|
|
|
|
}
|
2001-09-02 01:32:40 +02:00
|
|
|
|
2013-06-25 18:37:44 +02:00
|
|
|
$apps = new applications((int)$_userData['account_id']);
|
2007-03-09 13:07:15 +01:00
|
|
|
if($_userData['account_permissions'])
|
2003-04-28 01:16:15 +02:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
foreach($_userData['account_permissions'] as $app => $enabled)
|
2003-08-28 16:16:30 +02:00
|
|
|
{
|
2007-03-09 13:07:15 +01:00
|
|
|
if($enabled)
|
2003-08-28 16:16:30 +02:00
|
|
|
{
|
2005-03-30 16:46:37 +02:00
|
|
|
$apps->add($app);
|
2003-08-28 16:16:30 +02:00
|
|
|
}
|
|
|
|
}
|
2001-09-02 01:32:40 +02:00
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
$apps->save_repository();
|
2001-09-02 01:32:40 +02:00
|
|
|
|
2013-06-25 18:37:44 +02:00
|
|
|
$acl = new acl($_userData['account_id']);
|
2007-03-09 13:07:15 +01:00
|
|
|
if($_userData['anonymous'])
|
2003-08-28 16:16:30 +02:00
|
|
|
{
|
|
|
|
$acl->add_repository('phpgwapi','anonymous',$_userData['account_id'],1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$acl->delete_repository('phpgwapi','anonymous',$_userData['account_id']);
|
|
|
|
}
|
2007-03-09 13:07:15 +01:00
|
|
|
if(!$_userData['changepassword'])
|
2003-08-28 16:16:30 +02:00
|
|
|
{
|
2006-06-23 03:28:47 +02:00
|
|
|
$GLOBALS['egw']->acl->add_repository('preferences','nopasswordchange',$_userData['account_id'],1);
|
2003-08-28 16:16:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-23 03:28:47 +02:00
|
|
|
$GLOBALS['egw']->acl->delete_repository('preferences','nopasswordchange',$_userData['account_id']);
|
2003-08-28 16:16:30 +02:00
|
|
|
}
|
2005-10-14 19:03:16 +02:00
|
|
|
$GLOBALS['egw']->session->delete_cache((int)$_userData['account_id']);
|
2013-06-25 18:37:44 +02:00
|
|
|
|
2013-06-26 12:48:37 +02:00
|
|
|
//error_log(__METHOD__."(".array2string($_userData).") returning ".array2string($errors));
|
2013-06-25 18:37:44 +02:00
|
|
|
return $errors;
|
2001-09-02 01:32:40 +02:00
|
|
|
}
|
2001-09-03 04:58:25 +02:00
|
|
|
|
2002-01-10 19:18:44 +01:00
|
|
|
function load_group_managers($account_id)
|
|
|
|
{
|
2005-10-14 19:03:16 +02:00
|
|
|
$temp_user = $GLOBALS['egw']->acl->get_ids_for_location($account_id,EGW_ACL_GROUP_MANAGERS,'phpgw_group');
|
2002-01-10 19:18:44 +01:00
|
|
|
if(!$temp_user)
|
|
|
|
{
|
|
|
|
return Array();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$group_user = $temp_user;
|
|
|
|
}
|
|
|
|
$account_user = Array();
|
2007-03-09 13:07:15 +01:00
|
|
|
while(list($key,$user) = each($group_user))
|
2002-01-10 19:18:44 +01:00
|
|
|
{
|
|
|
|
$account_user[$user] = ' selected';
|
|
|
|
}
|
|
|
|
@reset($account_user);
|
|
|
|
return $account_user;
|
|
|
|
}
|
|
|
|
|
2001-09-03 04:58:25 +02:00
|
|
|
function load_group_apps($account_id)
|
|
|
|
{
|
2005-10-14 19:03:16 +02:00
|
|
|
$apps =& CreateObject('phpgwapi.applications',(int)$account_id);
|
2001-09-03 04:58:25 +02:00
|
|
|
$app_list = $apps->read_account_specific();
|
|
|
|
$account_apps = Array();
|
|
|
|
while(list($key,$app) = each($app_list))
|
|
|
|
{
|
|
|
|
$account_apps[$app['name']] = True;
|
|
|
|
}
|
|
|
|
@reset($account_apps);
|
|
|
|
return $account_apps;
|
|
|
|
}
|
2001-09-02 01:32:40 +02:00
|
|
|
}
|