2003-06-01 11:39:23 +00:00
< ? php
/*
$Id $
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager ( http :// www . ldap - account - manager . org / )
2010-01-01 17:21:46 +00:00
Copyright ( C ) 2004 - 2010 Roland Gruber
2003-06-01 11:39:23 +00: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 .
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 , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
2004-08-31 19:13:32 +00:00
/**
* Start page of file upload
*
* @ author Roland Gruber
* @ package tools
2004-01-10 11:47:48 +00:00
*/
2004-08-31 19:13:32 +00:00
2006-03-26 17:51:25 +00:00
/** security functions */
include_once ( " ../lib/security.inc " );
2004-08-31 19:13:32 +00:00
/** access to configuration */
include_once ( '../lib/config.inc' );
/** status messages */
include_once ( '../lib/status.inc' );
/** account modules */
include_once ( '../lib/modules.inc' );
2004-01-10 11:47:48 +00:00
2004-09-21 18:37:55 +00:00
2004-01-10 11:47:48 +00:00
// Start session
2006-03-26 17:51:25 +00:00
startSecureSession ();
2003-10-22 17:51:44 +00:00
2007-12-30 13:15:39 +00:00
// die if no write access
if ( ! checkIfWriteAccessIsAllowed ()) die ();
2003-10-22 17:51:44 +00:00
// Redirect to startpage if user is not loged in
2008-05-15 17:32:59 +00:00
if ( ! isset ( $_SESSION [ 'loggedIn' ]) || ( $_SESSION [ 'loggedIn' ] !== true )) {
2003-10-22 17:51:44 +00:00
metaRefresh ( " login.php " );
2004-01-10 11:47:48 +00:00
exit ;
2004-09-21 18:37:55 +00:00
}
2003-10-22 17:51:44 +00:00
2003-10-22 13:57:32 +00:00
// Set correct language, codepages, ....
2003-08-10 19:46:21 +00:00
setlanguage ();
2003-06-01 11:39:23 +00:00
2004-10-12 13:12:16 +00:00
// show CSV if requested
if ( isset ( $_GET [ 'getCSV' ])) {
//download file
if ( isset ( $HTTP_SERVER_VARS [ 'HTTP_USER_AGENT' ]) and strpos ( $HTTP_SERVER_VARS [ 'HTTP_USER_AGENT' ], 'MSIE' )) {
Header ( 'Content-Type: application/force-download' );
}
else {
2004-10-12 13:29:06 +00:00
Header ( 'Content-Type: application/msexcel' );
2004-10-12 13:12:16 +00:00
}
Header ( 'Content-disposition: attachment; filename=lam.csv' );
echo $_SESSION [ 'mass_csv' ];
exit ;
}
2010-01-01 17:21:46 +00:00
include 'main_header.php' ;
2004-08-31 19:13:32 +00:00
2010-02-27 19:14:15 +00:00
// get possible types and remove those which do not support file upload
$types = $_SESSION [ 'config' ] -> get_ActiveTypes ();
for ( $i = 0 ; $i < sizeof ( $types ); $i ++ ) {
$myType = new $types [ $i ]();
if ( ! $myType -> supportsFileUpload ()) {
unset ( $types [ $i ]);
}
}
$types = array_values ( $types );
2004-08-31 19:13:32 +00:00
// check if account specific page should be shown
2010-02-15 20:21:44 +00:00
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 ;
}
}
2006-01-01 16:30:05 +00:00
2004-08-31 19:13:32 +00:00
// show start page
2010-02-15 20:21:44 +00:00
echo " <h1> " . _ ( " Account creation via file upload " ) . " </h1> \n " ;
echo " <p> </p> \n " ;
echo " <p> \n " ;
echo _ ( " Here you can create multiple accounts by providing a CSV file. " );
echo " </p> \n " ;
echo " <p> </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 " ;
2010-04-04 14:54:58 +00:00
$sortedTypes = array ();
2010-02-15 20:21:44 +00:00
for ( $i = 0 ; $i < sizeof ( $types ); $i ++ ) {
2010-04-04 14:54:58 +00:00
$sortedTypes [ $types [ $i ]] = getTypeAlias ( $types [ $i ]);
}
natcasesort ( $sortedTypes );
foreach ( $sortedTypes as $key => $value ) {
2010-02-15 20:21:44 +00:00
$selected = '' ;
2010-04-04 14:54:58 +00:00
if ( isset ( $_POST [ 'type' ]) && ( $_POST [ 'type' ] == $key )) {
2010-02-15 20:21:44 +00:00
$selected = 'selected' ;
2008-12-27 13:47:41 +00:00
}
2010-04-04 14:54:58 +00:00
echo " <option value= \" " . $key . " \" $selected > " . $value . " </option> \n " ;
2010-02-15 20:21:44 +00:00
}
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
2010-04-04 14:54:58 +00:00
$counter = 0 ;
foreach ( $sortedTypes as $type => $label ) {
2010-02-15 20:21:44 +00:00
$style = 'style="display:none;"' ;
2010-05-19 19:22:29 +00:00
if (( ! isset ( $_POST [ 'type' ]) && ( $counter == 0 )) || ( isset ( $_POST [ 'type' ]) && ( $_POST [ 'type' ] == $type ))) {
2010-02-15 20:21:44 +00:00
// show first account type or last selected one
$style = '' ;
}
2010-04-04 14:54:58 +00:00
echo " <div $style id= \" " . $type . " \" class= \" typeOptions \" > \n " ;
2010-02-15 20:21:44 +00:00
echo " <table border=0> " ;
2010-04-04 14:54:58 +00:00
$modules = $_SESSION [ 'config' ] -> get_AccountModules ( $type );
2010-02-15 20:21:44 +00:00
for ( $m = 0 ; $m < sizeof ( $modules ); $m ++ ) {
if ( $m % 3 == 0 ) {
echo " <tr> \n " ;
}
echo " <td> " ;
2010-04-04 14:54:58 +00:00
$module = new $modules [ $m ]( $type );
2010-02-15 20:21:44 +00:00
$iconImage = $module -> getIcon ();
echo '<img align="middle" src="../graphics/' . $iconImage . '" alt="' . $iconImage . '">' ;
echo " </td><td> \n " ;
2010-04-04 14:54:58 +00:00
if ( is_base_module ( $modules [ $m ], $type )) {
echo " <input type= \" hidden \" name= \" " . $type . '_' . $modules [ $m ] . " \" value= \" on \" ><input type= \" checkbox \" checked disabled> " ;
2010-02-15 20:21:44 +00:00
}
else {
$checked = 'checked' ;
2010-04-04 14:54:58 +00:00
if ( isset ( $_POST [ 'submit' ]) && ! isset ( $_POST [ $type . '_' . $modules [ $m ]])) {
2010-02-15 20:21:44 +00:00
$checked = '' ;
}
2010-04-04 14:54:58 +00:00
echo " <input type= \" checkbox \" name= \" " . $type . '_' . $modules [ $m ] . " \" $checked > " ;
2010-02-15 20:21:44 +00:00
}
2010-04-04 14:54:58 +00:00
echo getModuleAlias ( $modules [ $m ], $type );
2010-02-15 20:21:44 +00:00
echo " </td> " ;
if (( $m % 3 == 2 ) && ( $m != ( sizeof ( $modules ) - 1 ))) {
echo " </tr> \n " ;
}
}
echo " </tr> " ;
echo " </table> \n " ;
echo " </div> \n " ;
2010-04-04 14:54:58 +00:00
$counter ++ ;
2010-02-15 20:21:44 +00:00
}
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 " ;
2010-08-21 09:43:52 +00:00
include 'main_footer.php' ;
2004-08-31 19:13:32 +00:00
/**
* Displays the acount type specific main page of the upload .
*
* @ param string $scope account type
2010-02-15 20:21:44 +00:00
* @ param array $selectedModules list of selected account modules
2004-08-31 19:13:32 +00:00
*/
2010-02-15 20:21:44 +00:00
function showMainPage ( $scope , $selectedModules ) {
2010-01-01 17:21:46 +00:00
echo " <h1> " . _ ( " File upload " ) . " </h1> " ;
2004-08-31 19:13:32 +00:00
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. " );
2006-03-03 17:01:57 +00:00
echo " <br> " ;
echo _ ( " Check your input carefully. LAM will only do some basic checks on the upload data. " );
echo " <br><br> " ;
2006-03-06 15:28:08 +00:00
echo _ ( " Hint: Format all cells as text in your spreadsheet program and turn off auto correction. " );
2004-08-31 19:13:32 +00:00
echo " </p> \n " ;
echo " <p> </p> \n " ;
2004-09-21 18:37:55 +00:00
echo " <form enctype= \" multipart/form-data \" action= \" massBuildAccounts.php \" method= \" post \" > \n " ;
2004-08-31 19:13:32 +00:00
echo " <p> \n " ;
2010-01-30 17:40:24 +00:00
echo " <b> " . _ ( " CSV file: " ) . " </b> <input class= \" $scope\ " name = \ " inputfile \" type= \" file \" > " ;
echo " <input class= \" $scope\ " name = \ " submitfile \" type= \" submit \" value= \" " . _ ( 'Upload file and create accounts' ) . " \" > \n " ;
2004-09-21 18:37:55 +00:00
echo " <input type= \" hidden \" name= \" scope \" value= \" $scope\ " > \n " ;
2010-02-15 20:21:44 +00:00
echo " <input type= \" hidden \" name= \" selectedModules \" value= \" " . implode ( ',' , $selectedModules ) . " \" > \n " ;
2010-09-04 12:39:32 +00:00
echo " <a href= \" masscreate.php?getCSV=1 \" ><b> " . _ ( " Download sample CSV file " ) . " </b></a> \n " ;
2004-08-31 19:13:32 +00:00
echo " </p> \n " ;
2004-09-21 18:37:55 +00:00
echo " </form> \n " ;
2004-08-31 19:13:32 +00:00
echo " <p> </p> \n " ;
2006-03-03 17:01:57 +00:00
echo _ ( " Here is a list of possible columns. The red columns must be included in the CSV file and filled with data for all accounts. " );
2004-08-31 19:13:32 +00:00
2004-11-18 16:46:41 +00:00
echo " <p><big><b> " . _ ( " Columns: " ) . " </b></big></p> \n " ;
2004-08-31 19:13:32 +00:00
2004-09-21 18:37:55 +00:00
// DN options
2007-12-31 12:25:13 +00:00
echo " <fieldset class= \" " . $scope . " edit \" > \n <legend><b> " . _ ( " DN settings " ) . " </b></legend><br> \n " ;
2004-10-12 13:12:16 +00:00
echo " <table width= \" 100% \" > \n " ;
2004-11-18 16:46:41 +00:00
echo " <tr valign= \" top \" > \n " ;
2004-10-12 13:12:16 +00:00
echo " <td width= \" 50% \" > \n " ;
2004-09-21 18:37:55 +00:00
echo " <b> " . _ ( " DN suffix " ) . " </b> \n " ;
2005-04-24 10:31:07 +00:00
// help link
2009-02-07 22:56:36 +00:00
echo " " ;
printHelpLink ( getHelp ( '' , '361' ), '361' );
2004-09-21 18:37:55 +00:00
echo " <br> \n " ;
echo " <ul> \n " ;
echo " <li><b> " . _ ( " Identifier " ) . " :</b> " . " dn_suffix</li> \n " ;
2007-06-10 14:51:35 +00:00
echo " <li><b> " . _ ( " Example value " ) . " :</b> " . _ ( " ou=accounts,dc=yourdomain,dc=org " ) . " </li> \n " ;
2005-03-10 20:20:00 +00:00
echo " <li><b> " . _ ( " Default value " ) . " :</b> " . $_SESSION [ 'config' ] -> get_Suffix ( $scope ) . " </li> \n " ;
2004-09-21 18:37:55 +00:00
echo " </ul> \n " ;
echo " </td> \n " ;
2004-10-12 13:12:16 +00:00
echo " <td width= \" 50% \" > \n " ;
2004-09-21 18:37:55 +00:00
echo " <b><font color= \" red \" > " . _ ( " RDN identifier " ) . " </font></b> \n " ;
2005-04-24 10:31:07 +00:00
// help link
2009-02-07 22:56:36 +00:00
echo " " ;
printHelpLink ( getHelp ( '' , '301' ), '301' );
2004-09-21 18:37:55 +00:00
echo " <br> \n " ;
echo " <ul> \n " ;
echo " <li><b> " . _ ( " Identifier " ) . " :</b> " . " dn_rdn</li> \n " ;
2010-02-15 20:21:44 +00:00
echo " <li><b> " . _ ( " Possible values " ) . " :</b> " . implode ( " , " , getRDNAttributes ( $scope , $selectedModules )) . " </li> \n " ;
2004-09-21 18:37:55 +00:00
echo " </ul> \n " ;
echo " </td> \n " ;
echo " </tr> \n " ;
echo " </table> \n " ;
2007-11-19 19:16:08 +00:00
echo " </fieldset><br> \n " ;
2004-09-21 18:37:55 +00:00
2004-08-31 19:13:32 +00:00
// get input fields from modules
2010-02-15 20:21:44 +00:00
$columns = getUploadColumns ( $scope , $selectedModules );
2004-08-31 19:13:32 +00:00
// print input fields
$modules = array_keys ( $columns );
for ( $m = 0 ; $m < sizeof ( $modules ); $m ++ ) {
2010-02-15 20:21:44 +00:00
// skip modules without upload columns
if ( sizeof ( $columns [ $modules [ $m ]]) < 1 ) {
continue ;
}
2007-11-19 19:16:08 +00:00
$icon = '' ;
$module = new $modules [ $m ]( $scope );
$iconImage = $module -> getIcon ();
if ( $iconImage != null ) {
2007-12-01 12:34:52 +00:00
$icon = '<img align="middle" src="../graphics/' . $iconImage . '" alt="' . $iconImage . '"> ' ;
2007-11-19 19:16:08 +00:00
}
2007-12-31 12:25:13 +00:00
echo " <fieldset class= \" " . $scope . " edit \" > \n <legend> $icon <b> " . getModuleAlias ( $modules [ $m ], $scope ) . " </b></legend><br> \n " ;
2004-10-12 13:12:16 +00:00
echo " <table width= \" 100% \" > \n " ;
2004-08-31 19:13:32 +00:00
for ( $i = 0 ; $i < sizeof ( $columns [ $modules [ $m ]]); $i ++ ) {
2004-11-18 16:46:41 +00:00
echo " <tr valign= \" top \" > \n " ;
2004-10-12 13:12:16 +00:00
echo " <td width= \" 33% \" > \n " ;
2005-06-02 19:31:35 +00:00
showColumnData ( $modules [ $m ], $columns [ $modules [ $m ]][ $i ], $scope );
2004-08-31 19:13:32 +00:00
echo " </td> \n " ;
$i ++ ;
if ( $i < sizeof ( $columns [ $modules [ $m ]])) {
2004-10-12 13:12:16 +00:00
echo " <td width= \" 33% \" > \n " ;
2005-06-02 19:31:35 +00:00
showColumnData ( $modules [ $m ], $columns [ $modules [ $m ]][ $i ], $scope );
2004-08-31 19:13:32 +00:00
echo " </td> \n " ;
$i ++ ;
if ( $i < sizeof ( $columns [ $modules [ $m ]])) {
2004-10-12 13:12:16 +00:00
echo " <td width= \" 33% \" > \n " ;
2005-06-02 19:31:35 +00:00
showColumnData ( $modules [ $m ], $columns [ $modules [ $m ]][ $i ], $scope );
2004-08-31 19:13:32 +00:00
echo " </td> \n " ;
2003-10-22 13:57:32 +00:00
}
2004-10-12 13:12:16 +00:00
else echo " <td width= \" 33% \" ></td> " ; // empty cell if no more fields
2003-11-06 10:58:21 +00:00
}
2004-10-12 13:12:16 +00:00
else echo " <td width= \" 33% \" ></td><td width= \" 33% \" ></td> " ; // empty cell if no more fields
2004-08-31 19:13:32 +00:00
echo " </tr> \n " ;
}
2003-10-22 13:57:32 +00:00
echo " </table> \n " ;
2007-11-19 19:16:08 +00:00
echo " </fieldset><br> " ;
2003-08-28 18:37:27 +00:00
}
2004-08-31 19:13:32 +00:00
2010-09-04 12:39:32 +00:00
// build sample CSV
2004-10-12 13:12:16 +00:00
$sampleCSV_head = array ();
$sampleCSV_row = array ();
2010-09-04 12:39:32 +00:00
// DN attributes
$sampleCSV_head [] = " \" dn_suffix \" " ;
$sampleCSV_head [] = " \" dn_rdn \" " ;
// module attributes
for ( $m = 0 ; $m < sizeof ( $modules ); $m ++ ) {
if ( sizeof ( $columns [ $modules [ $m ]]) < 1 ) continue ;
for ( $i = 0 ; $i < sizeof ( $columns [ $modules [ $m ]]); $i ++ ) {
$sampleCSV_head [] = " \" " . $columns [ $modules [ $m ]][ $i ][ 'name' ] . " \" " ;
2003-09-28 16:00:13 +00:00
}
2010-09-04 12:39:32 +00:00
}
$RDNs = getRDNAttributes ( $scope , $selectedModules );
// DN attributes
$sampleCSV_row [] = " \" " . $_SESSION [ 'config' ] -> get_Suffix ( $scope ) . " \" " ;
$sampleCSV_row [] = " \" " . $RDNs [ 0 ] . " \" " ;
// module attributes
for ( $m = 0 ; $m < sizeof ( $modules ); $m ++ ) {
if ( sizeof ( $columns [ $modules [ $m ]]) < 1 ) continue ;
for ( $i = 0 ; $i < sizeof ( $columns [ $modules [ $m ]]); $i ++ ) {
$sampleCSV_row [] = " \" " . $columns [ $modules [ $m ]][ $i ][ 'example' ] . " \" " ;
2003-06-01 15:14:16 +00:00
}
2010-09-04 12:39:32 +00:00
}
2004-10-12 13:12:16 +00:00
$sampleCSV = implode ( " , " , $sampleCSV_head ) . " \n " . implode ( " , " , $sampleCSV_row ) . " \n " ;
$_SESSION [ 'mass_csv' ] = $sampleCSV ;
2010-08-21 09:43:52 +00:00
include 'main_footer.php' ;
2004-08-31 19:13:32 +00:00
die ;
}
/**
* Prints the properties of one input field .
*
* @ param string $module account module name
* @ param array $data field data from modules
2005-06-02 19:31:35 +00:00
* @ param string $scope account type
2004-08-31 19:13:32 +00:00
*/
2005-06-02 19:31:35 +00:00
function showColumnData ( $module , $data , $scope ) {
2004-10-10 11:16:34 +00:00
if ( isset ( $data [ 'required' ]) && ( $data [ 'required' ] == true )) {
2004-08-31 19:13:32 +00:00
echo " <font color= \" red \" ><b> \n " ;
echo $data [ 'description' ];
echo " </b></font> \n " ;
2003-06-01 11:39:23 +00:00
}
2004-08-31 19:13:32 +00:00
else {
echo " <b> \n " ;
echo $data [ 'description' ];
echo " </b> \n " ;
}
2005-04-24 10:31:07 +00:00
// help link
2009-02-07 22:56:36 +00:00
echo " " ;
printHelpLink ( getHelp ( $module , $data [ 'help' ], $scope ), $data [ 'help' ], $module , $scope );
2004-08-31 19:13:32 +00:00
echo " <br> \n " ;
echo " <ul> \n " ;
echo " <li> \n " ;
2004-10-09 11:07:05 +00:00
echo " <b> " . _ ( " Identifier " ) . " :</b> " . $data [ 'name' ] . " \n " ;
2004-08-31 19:13:32 +00:00
echo " </li> \n " ;
2004-10-12 13:12:16 +00:00
if ( isset ( $data [ 'values' ])) {
echo " <li> \n " ;
echo " <b> " . _ ( " Possible values " ) . " :</b> " . $data [ 'values' ] . " \n " ;
echo " </li> \n " ;
}
2004-08-31 19:13:32 +00:00
echo " <li> \n " ;
2004-10-09 11:07:05 +00:00
echo " <b> " . _ ( " Example value " ) . " :</b> " . $data [ 'example' ] . " \n " ;
2004-08-31 19:13:32 +00:00
echo " </li> \n " ;
2004-10-14 20:16:23 +00:00
if ( isset ( $data [ 'default' ])) {
echo " <li> \n " ;
echo " <b> " . _ ( " Default value " ) . " :</b> " . $data [ 'default' ] . " \n " ;
echo " </li> \n " ;
}
2004-08-31 19:13:32 +00:00
echo " </ul> \n " ;
}
2003-06-01 11:39:23 +00:00
?>