allow to selected modules for file upload

This commit is contained in:
Roland Gruber 2010-02-15 20:21:44 +00:00
parent efc47ad218
commit 4f84924055
29 changed files with 299 additions and 143 deletions

View File

@ -1,5 +1,6 @@
March 2010 3.0.0
- support to remove extension from an existing account: shadowAccount, sambaSamAccount, eduPerson
- file upload: allow to select account modules for upload
- removed frames
- Unix: automatic user name generation from first and last name (2492675)
- fixed bugs:

View File

@ -105,12 +105,13 @@ objectClass which is added to all accounts.<br>
&nbsp;&nbsp;&nbsp; * @param array $partialAccounts list of hash arrays
(name =&gt; value) which are later added to LDAP<br>
&nbsp;&nbsp;&nbsp; * @param array $ids list of IDs for column position
(e.g. "posixAccount_uid" =&gt; 5)<br>
(e.g. "posixAccount_uid" =&gt; 5)<br> 
  * @param array $selectedModules list of selected account modules<br>
&nbsp;&nbsp;&nbsp; * @return array list of error messages if any<br>
&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">function</span> <span
style="color: rgb(255, 0, 0);">build_uploadAccounts</span>($rawAccounts,
$ids, &amp;$partialAccounts) {<br>
$ids, &amp;$partialAccounts, $selectedModules) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $messages = array();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for ($i = 0; $i &lt;
sizeof($rawAccounts); $i++) {<br>

View File

@ -23,7 +23,14 @@ This is a list of API changes for all LAM releases.
You can now integrate JavaScript libraries by simply putting the files
into templates/lib. All files with the name *.js are automatically
included on all pages.<br>
There is a new log level LOG_DEBUG available for logNewMessage().<br>
There is a new log level LOG_DEBUG available for logNewMessage().
<br>
<h3>Module interface:</h3>
The function
<span style="font-weight: bold;">build_uploadAccounts()</span>
has a new parameter
<span style="font-weight: bold;">$selectedModules</span>
.<br>
<br>
<br>

View File

@ -824,11 +824,12 @@ abstract class baseModule {
* <br> boolean: unique // true if all values of this column must be different values (optional, default: "false")
* <br> )
*
* @param array $selectedModules list of selected account modules
* @return array column list
*
* @see baseModule::get_metaData()
*/
public function get_uploadColumns() {
public function get_uploadColumns($selectedModules) {
if (isset($this->meta['upload_columns'])) return $this->meta['upload_columns'];
else return array();
}
@ -859,9 +860,10 @@ abstract class baseModule {
* @param array $rawAccounts the user input data, contains one subarray for each account.
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
public function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
public function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
// must be implemented in sub modules
return array();
}

View File

@ -115,10 +115,14 @@ function get_ldap_filter($scope) {
* The list is already sorted by the priority given by the nodules.
*
* @param string $scope account type (user, group, host)
* @param array $selectedModules return only RDN attributes of these modules
* @return array list of LDAP attributes
*/
function getRDNAttributes($scope) {
function getRDNAttributes($scope, $selectedModules=null) {
$mods = $_SESSION['config']->get_AccountModules($scope);
if ($selectedModules != null) {
$mods = $selectedModules;
}
$return = array();
$attrs_low = array();
$attrs_normal = array();
@ -380,14 +384,14 @@ function getAvailablePDFFields($scope) {
* <br> )
*
* @param string $scope account type
* @param array $selectedModules selected account modules
* @return array column list
*/
function getUploadColumns($scope) {
$mods = $_SESSION['config']->get_AccountModules($scope);
function getUploadColumns($scope, $selectedModules) {
$return = array();
for ($i = 0; $i < sizeof($mods); $i++) {
$module = new $mods[$i]($scope);
$return[$mods[$i]] = $module->get_uploadColumns();
for ($i = 0; $i < sizeof($selectedModules); $i++) {
$module = new $selectedModules[$i]($scope);
$return[$selectedModules[$i]] = $module->get_uploadColumns($selectedModules);
}
return $return;
}
@ -400,11 +404,12 @@ function getUploadColumns($scope) {
* @param string $scope account type
* @param array $data array containing one account in each element
* @param array $ids array(<column_name> => <column number>)
* @param array $selectedModules selected account modules
* @return mixed array including accounts or false if there were errors
*/
function buildUploadAccounts($scope, $data, $ids) {
function buildUploadAccounts($scope, $data, $ids, $selectedModules) {
// build module order
$unOrdered = $_SESSION['config']->get_AccountModules($scope);
$unOrdered = $selectedModules;
$ordered = array();
$predepends = array();
// get dependencies
@ -453,7 +458,7 @@ function buildUploadAccounts($scope, $data, $ids) {
for ($i = 0; $i < sizeof($data); $i++) $partialAccounts[$i]['objectClass'] = array();
for ($i = 0; $i < sizeof($ordered); $i++) {
$module = new $ordered[$i]($scope);
$errors = $module->build_uploadAccounts($data, $ids, $partialAccounts);
$errors = $module->build_uploadAccounts($data, $ids, $partialAccounts, $selectedModules);
if (sizeof($errors) > 0) {
array_unshift($errors, array("INFO", _("Displayed account numbers start at \"0\". Add 2 to get the row in your spreadsheet."), ""));
$errors[] = array("ERROR", _("Upload was stopped after errors in %s module!"), "", array($module->get_alias()));

View File

@ -4,7 +4,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
2005 - 2007 Roland Gruber
2005 - 2010 Roland Gruber
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
@ -101,30 +101,18 @@ class account extends baseModule {
)
);
// upload columns
if (isset($_SESSION['loggedIn']) && ($_SESSION['loggedIn'] === true)) {
if ($this->get_scope() == 'user') {
$return['upload_columns'][] = array(
'name' => 'account_hosts',
'description' => _('Host list'),
'help' => 'host'
);
}
if (!in_array('posixAccount', $modules)) {
$return['upload_columns'][] = array(
'name' => 'account_uid',
'description' => _('User name'),
'help' => 'uid',
'required' => true
);
$return['upload_columns'] = array(
array(
'name' => 'account_description',
'description' => _('Description'),
'help' => 'description'
)
);
}
if ($this->get_scope() == 'user') {
$return['upload_columns'][] = array(
'name' => 'account_hosts',
'description' => _('Host list'),
'help' => 'host'
);
}
$return['upload_columns'][] = array(
'name' => 'account_description',
'description' => _('Description'),
'help' => 'description'
);
return $return;
}
@ -217,16 +205,17 @@ class account extends baseModule {
$modules = $_SESSION['config']->get_AccountModules($this->get_scope());
if (!in_array('posixAccount', $modules)) {
$return[] = array (
0 => array('kind' => 'text', 'text' => _("User name").'*'),
1 => array('kind' => 'input', 'name' => 'uid', 'type' => 'text', 'size' => '30', 'maxlength' => '20',
array('kind' => 'text', 'text' => _("User name").'*'),
array('kind' => 'input', 'name' => 'uid', 'type' => 'text', 'size' => '30', 'maxlength' => '20',
'value' => $this->attributes['uid'][0]),
2 => array('kind' => 'help', 'value' => 'uid'));
array('kind' => 'help', 'value' => 'uid'));
}
// description
$return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Description') ),
1 => array ( 'kind' => 'input', 'name' => 'description', 'type' => 'text', 'size' => '30',
'maxlength' => '255', 'value' => $this->attributes['description'][0] ),
2 => array ('kind' => 'help', 'value' => 'description'));
$return[] = array(
array('kind' => 'text', 'text' => _('Description')),
array('kind' => 'input', 'name' => 'description', 'type' => 'text', 'size' => '30',
'maxlength' => '255', 'value' => $this->attributes['description'][0]),
array('kind' => 'help', 'value' => 'description'));
return $return;
}
@ -242,28 +231,59 @@ class account extends baseModule {
return $return;
}
/**
* Returns an array containing all input columns for the file upload.
*
* Syntax:
* <br> array(
* <br> string: name, // fixed non-translated name which is used as column name (should be of format: <module name>_<column name>)
* <br> string: description, // short descriptive name
* <br> string: help, // help ID
* <br> string: example, // example value
* <br> boolean: required // true, if user must set a value for this column
* <br> )
*
* @param array $selectedModules list of selected account modules
* @return array column list
*/
function get_uploadColumns($selectedModules) {
$return = parent::get_uploadColumns($selectedModules);
if (!in_array('posixAccount', $selectedModules)) {
$return[] = array(
'name' => 'account_uid',
'description' => _('User name'),
'help' => 'uid',
'required' => true
);
}
return $return;
}
/**
* In this function the LDAP account is built up.
*
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class
if (!in_array("account", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "account";
$modules = $_SESSION['config']->get_AccountModules($this->get_scope());
if (!in_array('posixAccount', $modules)) {
// description
if ($rawAccounts[$i][$ids['account_description']] && ($rawAccounts[$i][$ids['account_description']] != '')) {
$partialAccounts[$i]['description'] = $rawAccounts[$i][$ids['account_description']];
}
else {
$partialAccounts[$i]['description'] = $rawAccounts[$i][$ids['account_uid']];
}
// description
if ($rawAccounts[$i][$ids['account_description']] && ($rawAccounts[$i][$ids['account_description']] != '')) {
$partialAccounts[$i]['description'] = $rawAccounts[$i][$ids['account_description']];
}
elseif (isset($rawAccounts[$i][$ids['account_uid']])) {
$partialAccounts[$i]['description'] = $rawAccounts[$i][$ids['account_uid']];
}
elseif (isset($partialAccounts[$i]['uid'])) {
$partialAccounts[$i]['description'] = $partialAccounts[$i]['uid'];
}
if (!in_array('posixAccount', $selectedModules)) {
// user name
if (get_preg($rawAccounts[$i][$ids['account_uid']], 'username')) {
$partialAccounts[$i]['uid'] = $rawAccounts[$i][$ids['account_uid']];

View File

@ -280,9 +280,10 @@ class asteriskAccount extends baseModule implements passwordService {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class

View File

@ -421,9 +421,10 @@ class asteriskExtension extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class

View File

@ -620,9 +620,10 @@ class ddns extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
if (!$this->check_if_ddns_is_enable()) {
return $messages;

View File

@ -801,9 +801,10 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class

View File

@ -542,9 +542,10 @@ class eduPerson extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class

View File

@ -160,9 +160,10 @@ class ieee802Device extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class

View File

@ -252,9 +252,10 @@ class inetLocalMailRecipient extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class

View File

@ -4,7 +4,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
2005 - 2009 Roland Gruber
2005 - 2010 Roland Gruber
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
@ -472,27 +472,6 @@ class inetOrgPerson extends baseModule implements passwordService {
'example' => _('YourCompany, Human Resources')
);
}
// cn and uid for upload (only if posixAccount is not loaded)
if (isset($_SESSION['loggedIn']) && ($_SESSION['loggedIn'] === true)) {
$modules = $_SESSION['config']->get_AccountModules($this->get_scope());
if (!in_array('posixAccount', $modules)) {
$return['upload_columns'][] = array(
'name' => 'inetOrgPerson_cn',
'description' => _('Common name'),
'help' => 'cn',
'example' => _('Steve Miller'),
'default' => '<i>&lt;inetOrgPerson_firstName&gt; &lt;inetOrgPerson_lastName&gt;</i>'
);
$return['upload_columns'][] = array(
'name' => 'inetOrgPerson_userName',
'description' => _('User name'),
'help' => 'uid',
'example' => _('smiller'),
'unique' => true,
'required' => true
);
}
}
// Unix workstations for upload
if (isset($_SESSION['loggedIn']) && ($_SESSION['loggedIn'] === true)) {
if ($this->supportUnixHosts()) {
@ -1287,15 +1266,54 @@ class inetOrgPerson extends baseModule implements passwordService {
}
}
/**
* Returns an array containing all input columns for the file upload.
*
* Syntax:
* <br> array(
* <br> string: name, // fixed non-translated name which is used as column name (should be of format: <module name>_<column name>)
* <br> string: description, // short descriptive name
* <br> string: help, // help ID
* <br> string: example, // example value
* <br> boolean: required // true, if user must set a value for this column
* <br> )
*
* @param array $selectedModules list of selected account modules
* @return array column list
*/
function get_uploadColumns($selectedModules) {
$return = parent::get_uploadColumns($selectedModules);
// cn and uid for upload (only if posixAccount is not selected)
if (!in_array('posixAccount', $selectedModules)) {
$return[] = array(
'name' => 'inetOrgPerson_cn',
'description' => _('Common name'),
'help' => 'cn',
'example' => _('Steve Miller'),
'default' => '<i>&lt;inetOrgPerson_firstName&gt; &lt;inetOrgPerson_lastName&gt;</i>'
);
$return[] = array(
'name' => 'inetOrgPerson_userName',
'description' => _('User name'),
'help' => 'uid',
'example' => _('smiller'),
'unique' => true,
'required' => true
);
}
return $return;
}
/**
* In this function the LDAP account is built up.
*
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$errors = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
if (!in_array("inetOrgPerson", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "inetOrgPerson";
@ -1504,8 +1522,7 @@ class inetOrgPerson extends baseModule implements passwordService {
$errors[] = $errMsg;
}
}
$modules = $_SESSION['config']->get_AccountModules($this->get_scope());
if (!in_array('posixAccount', $modules)) {
if (!in_array('posixAccount', $selectedModules)) {
// cn
if ($rawAccounts[$i][$ids['inetOrgPerson_cn']] != "") {
if (get_preg($rawAccounts[$i][$ids['inetOrgPerson_cn']], 'cn')) {

View File

@ -609,9 +609,10 @@ class kolabUser extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class

View File

@ -139,9 +139,10 @@ class ldapPublicKey extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class

View File

@ -230,9 +230,10 @@ class nisMailAlias extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class

View File

@ -497,9 +497,10 @@ class nisnetgroup extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
// get list of existing groups
$dnGroups = $_SESSION['cache']->get_cache('cn', 'nisNetgroup', 'netgroup');

View File

@ -171,9 +171,10 @@ class phpGroupwareGroup extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
if (isset($rawAccounts[$i][$ids['phpGroupwareGroup_extension']])
&& (strtolower($rawAccounts[$i][$ids['phpGroupwareGroup_extension']]) == "true")) {

View File

@ -373,9 +373,10 @@ class phpGroupwareUser extends baseModule implements passwordService {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
if (!isset($rawAccounts[$i][$ids['phpGroupwareUser_extension']])

View File

@ -1250,9 +1250,10 @@ class posixAccount extends baseModule implements passwordService {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$errors = array();
$needAutoUID = array();
// get list of existing users

View File

@ -54,9 +54,10 @@ class posixGroup extends baseModule implements passwordService {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$error_messages = array();
$needAutoGID = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {

View File

@ -4,7 +4,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
2007 - 2009 Roland Gruber
2007 - 2010 Roland Gruber
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
@ -611,9 +611,10 @@ class quota extends baseModule {
* <br> boolean: required // true, if user must set a value for this column
* <br> )
*
* @param array $selectedModules list of selected account modules
* @return array column list
*/
function get_uploadColumns() {
function get_uploadColumns($selectedModules) {
$this->initQuotas();
if (!isset($this->quota) || !is_array($this->quota)) return array();
$return = array();

View File

@ -546,9 +546,10 @@ class sambaDomain extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class

View File

@ -134,9 +134,10 @@ class sambaGroupMapping extends baseModule {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
// search existing Samba 3 domains
$domains = search_domains();
$nameToSID = array();

View File

@ -1855,9 +1855,10 @@ class sambaSamAccount extends baseModule implements passwordService {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$errors = array();
// get list of Samba 3 domains
$domains = search_domains();

View File

@ -425,9 +425,10 @@ class shadowAccount extends baseModule implements passwordService {
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class

View File

@ -86,11 +86,12 @@ if (isset($_GET['showldif'])) {
include 'main_header.php';
if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
$selectedModules = explode(',', $_POST['selectedModules']);
// check if input file is well formated
$data = array(); // input values without first row
$ids = array(); // <column name> => <column number for $data>
// get input fields from modules
$columns = getUploadColumns($_POST['scope']);
$columns = getUploadColumns($_POST['scope'], $selectedModules);
// read input file
$handle = fopen ($_FILES['inputfile']['tmp_name'], "r");
if (($head = fgetcsv($handle, 2000)) !== false ) { // head row
@ -157,9 +158,9 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
// let modules build accounts
else {
$accounts = buildUploadAccounts($_POST['scope'], $data, $ids);
$accounts = buildUploadAccounts($_POST['scope'], $data, $ids, $selectedModules);
if ($accounts != false) {
$rdnList = getRDNAttributes($_POST['scope']);
$rdnList = getRDNAttributes($_POST['scope'], $selectedModules);
$suffix = $_SESSION['config']->get_Suffix($_POST['scope']);
// set DN
for ($i = 0; $i < sizeof($accounts); $i++) {

View File

@ -72,51 +72,129 @@ $types = $_SESSION['config']->get_ActiveTypes();
include 'main_header.php';
// check if account specific page should be shown
if (isset($_POST['type'])) showMainPage($_POST['type']);
if (isset($_POST['type'])) {
// get selected type
$scope = $_POST['type'];
// get selected modules
$selectedModules = array();
$checkedBoxes = array_keys($_POST, 'on');
for ($i = 0; $i < sizeof($checkedBoxes); $i++) {
if (strpos($checkedBoxes[$i], $scope . '_') === 0) {
$selectedModules[] = substr($checkedBoxes[$i], strlen($scope) + 1);
}
}
$deps = getModulesDependencies($scope);
$depErrors = check_module_depends($selectedModules, $deps);
if (is_array($depErrors) && (sizeof($depErrors) > 0)) {
for ($i = 0; $i < sizeof($depErrors); $i++) {
StatusMessage('ERROR', _("Unsolved dependency:") . ' ' .
getModuleAlias($depErrors[$i][0], $scope) . " (" .
getModuleAlias($depErrors[$i][1], $scope) . ")");
}
}
else {
showMainPage($scope, $selectedModules);
exit;
}
}
// show start page
else {
echo "<h1>" . _("Account creation via file upload") . "</h1>\n";
echo "<p>&nbsp;</p>\n";
echo "<p>\n";
echo _("Here you can create multiple accounts by providing a CSV file.");
echo "</p>\n";
echo "<p>&nbsp;</p>\n";
echo "<p><b>\n";
echo _("Please select your account type:");
echo "</b></p>\n";
echo "<form enctype=\"multipart/form-data\" action=\"masscreate.php\" method=\"post\">\n";
echo "<table style=\"border-color: grey\" cellpadding=\"10\" border=\"0\" cellspacing=\"0\">\n";
echo "<tr><td>\n";
echo "<select class=\"user\" name=\"type\">\n";
for ($i = 0; $i < sizeof($types); $i++) {
echo "<option value=\"" . $types[$i] . "\">\n";
echo getTypeAlias($types[$i]);
echo "</option>\n";
echo "<h1>" . _("Account creation via file upload") . "</h1>\n";
echo "<p>&nbsp;</p>\n";
echo "<p>\n";
echo _("Here you can create multiple accounts by providing a CSV file.");
echo "</p>\n";
echo "<p>&nbsp;</p>\n";
echo '<script type="text/javascript">';
echo 'function changeVisibleModules(element) {';
echo 'jQuery(\'div.typeOptions\').toggle(false);';
echo 'jQuery(\'div#\' + element.options[element.selectedIndex].value).toggle();';
echo '}';
echo '</script>';
echo "<form enctype=\"multipart/form-data\" action=\"masscreate.php\" method=\"post\">\n";
echo "<table style=\"border-color: grey\" cellpadding=\"10\" border=\"0\" cellspacing=\"0\">\n";
echo "<tr><td>\n";
echo '<b>' . _("Account type") . ':</b>';
echo "</td>\n";
echo "<td>\n";
echo "<select class=\"user\" name=\"type\" onChange=\"changeVisibleModules(this);\">\n";
for ($i = 0; $i < sizeof($types); $i++) {
$selected = '';
if (isset($_POST['type']) && ($_POST['type'] == $types[$i])) {
$selected = 'selected';
}
echo "</select>\n";
echo "</td>\n";
echo "<td>\n";
echo "<input class=\"user\" type=\"submit\" name=\"submit\" value=\"". _("Ok") . "\">\n";
echo "</td></tr>\n";
echo "</table>\n";
echo "</form>\n";
echo "</body>\n";
echo "</html>\n";
}
echo "<option value=\"" . $types[$i] . "\" $selected>\n";
echo getTypeAlias($types[$i]);
echo "</option>\n";
}
echo "</select>\n";
echo "</td></tr>\n";
echo "<tr><td valign=\"top\">\n";
echo '<b>' . _('Selected modules') . ':</b>';
echo "</td>\n";
echo "<td>\n";
// generate one DIV for each account type
for ($i = 0; $i < sizeof($types); $i++) {
$style = 'style="display:none;"';
if ((!isset($_POST['type']) && ($i == 0)) || ($_POST['type'] == $types[$i])) {
// show first account type or last selected one
$style = '';
}
echo "<div $style id=\"" . $types[$i] . "\" class=\"typeOptions\">\n";
echo "<table border=0>";
$modules = $_SESSION['config']->get_AccountModules($types[$i]);
for ($m = 0; $m < sizeof($modules); $m++) {
if ($m%3 == 0) {
echo "<tr>\n";
}
echo "<td>";
$module = new $modules[$m]($types[$i]);
$iconImage = $module->getIcon();
echo '<img align="middle" src="../graphics/' . $iconImage . '" alt="' . $iconImage . '">';
echo "</td><td>\n";
if (is_base_module($modules[$m], $types[$i])) {
echo "<input type=\"hidden\" name=\"" . $types[$i] . '_' . $modules[$m] . "\" value=\"on\"><input type=\"checkbox\" checked disabled>";
}
else {
$checked = 'checked';
if (isset($_POST['submit']) && !isset($_POST[$types[$i] . '_' . $modules[$m]])) {
$checked = '';
}
echo "<input type=\"checkbox\" name=\"" . $types[$i] . '_' . $modules[$m] . "\" $checked>";
}
echo getModuleAlias($modules[$m], $types[$i]);
echo "</td>";
if (($m%3 == 2) && ($m != (sizeof($modules) - 1))) {
echo "</tr>\n";
}
}
echo "</tr>";
echo "</table>\n";
echo "</div>\n";
}
echo "</td></tr>\n";
echo "<tr><td>\n";
echo "<input class=\"user\" type=\"submit\" name=\"submit\" value=\"". _("Ok") . "\">\n";
echo "</td></tr>\n";
echo "</table>\n";
echo "</form>\n";
echo "</body>\n";
echo "</html>\n";
/**
* Displays the acount type specific main page of the upload.
*
* @param string $scope account type
* @param array $selectedModules list of selected account modules
*/
function showMainPage($scope) {
function showMainPage($scope, $selectedModules) {
echo "<h1>" . _("File upload") . "</h1>";
echo "<p>\n";
echo _("Please provide a CSV formated file with your account data. The cells in the first row must be filled with the column identifiers. The following rows represent one account for each row.");
@ -133,6 +211,7 @@ function showMainPage($scope) {
echo "<b>" . _("CSV file:") . "</b> <input class=\"$scope\" name=\"inputfile\" type=\"file\">&nbsp;&nbsp;";
echo "<input class=\"$scope\" name=\"submitfile\" type=\"submit\" value=\"" . _('Upload file and create accounts') . "\">\n";
echo "<input type=\"hidden\" name=\"scope\" value=\"$scope\">\n";
echo "<input type=\"hidden\" name=\"selectedModules\" value=\"" . implode(',', $selectedModules) . "\">\n";
echo "</p>\n";
echo "</form>\n";
@ -166,7 +245,7 @@ function showMainPage($scope) {
echo "<br>\n";
echo "<ul>\n";
echo "<li><b>" . _("Identifier") . ":</b> " . "dn_rdn</li>\n";
echo "<li><b>" . _("Possible values") . ":</b> " . implode(", ", getRDNAttributes($scope)) . "</li>\n";
echo "<li><b>" . _("Possible values") . ":</b> " . implode(", ", getRDNAttributes($scope, $selectedModules)) . "</li>\n";
echo "</ul>\n";
echo "</td>\n";
echo "</tr>\n";
@ -174,12 +253,15 @@ function showMainPage($scope) {
echo "</fieldset><br>\n";
// get input fields from modules
$columns = getUploadColumns($scope);
$columns = getUploadColumns($scope, $selectedModules);
// print input fields
$modules = array_keys($columns);
for ($m = 0; $m < sizeof($modules); $m++) {
if (sizeof($columns[$modules[$m]]) < 1) continue;
// skip modules without upload columns
if (sizeof($columns[$modules[$m]]) < 1) {
continue;
}
$icon = '';
$module = new $modules[$m]($scope);
$iconImage = $module->getIcon();
@ -243,7 +325,7 @@ function showMainPage($scope) {
}
echo "</tr>\n";
echo "<tr>\n";
$RDNs = getRDNAttributes($scope);
$RDNs = getRDNAttributes($scope, $selectedModules);
// DN attributes
$sampleCSV_row[] = "\"" . $_SESSION['config']->get_Suffix($scope) . "\"";
$sampleCSV_row[] = "\"" . $RDNs[0] . "\"";