2003-06-01 11:39:23 +00:00
< ? php
/*
$Id $
This code is part of LDAP Account Manager ( http :// www . sourceforge . net / projects / lam )
2004-09-21 18:37:55 +00:00
Copyright ( C ) 2004 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
/** 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
2003-06-01 11:39:23 +00:00
session_save_path ( '../sess' );
@ session_start ();
2003-10-22 17:51:44 +00:00
// Redirect to startpage if user is not loged in
if ( ! isset ( $_SESSION [ 'loggedIn' ])) {
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 ;
}
2003-10-22 13:57:32 +00:00
echo $_SESSION [ 'header' ];
2004-08-31 19:13:32 +00:00
echo " <title>account upload</title> \n " ;
echo " <link rel= \" stylesheet \" type= \" text/css \" href= \" ../style/layout.css \" > \n " ;
echo " </head> \n " ;
echo " <body> \n " ;
// check if account specific page should be shown
2004-09-21 18:37:55 +00:00
if ( isset ( $_POST [ 'user' ])) showMainPage ( 'user' );
elseif ( isset ( $_POST [ 'group' ])) showMainPage ( 'group' );
elseif ( isset ( $_POST [ 'host' ])) showMainPage ( 'host' );
2004-08-31 19:13:32 +00:00
// show start page
else {
echo " <h1 align= \" center \" > " . _ ( " Account creation via file upload " ) . " </h1> \n " ;
echo " <p> </p> \n " ;
echo " <p> </p> \n " ;
echo " <p> \n " ;
2004-11-07 13:25:48 +00:00
echo _ ( " Here you can create multiple accounts by providing a CSV file. " );
2004-08-31 19:13:32 +00:00
echo " </p> \n " ;
echo " <p> </p> \n " ;
echo " <p><b> \n " ;
echo _ ( " Please select your account type: " );
echo " </b></p> \n " ;
2004-09-21 18:37:55 +00:00
echo " <form enctype= \" multipart/form-data \" action= \" masscreate.php \" method= \" post \" > \n " ;
2004-08-31 19:13:32 +00:00
echo " <table style= \" border-color: grey \" cellpadding= \" 10 \" border= \" 2 \" cellspacing= \" 0 \" > \n " ;
echo " <tr> \n " ;
echo " <th class= \" userlist-sort \" > \n " ;
echo " <input type= \" submit \" name= \" user \" value= \" " . _ ( " Create user accounts " ) . " \" > \n " ;
echo " </th> \n " ;
echo " <th class= \" grouplist-sort \" > \n " ;
echo " <input type= \" submit \" name= \" group \" value= \" " . _ ( " Create group accounts " ) . " \" > \n " ;
echo " </th> \n " ;
echo " <th class= \" hostlist-sort \" > \n " ;
echo " <input type= \" submit \" name= \" host \" value= \" " . _ ( " Create host accounts " ) . " \" > \n " ;
echo " </th> \n " ;
echo " </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
*/
function showMainPage ( $scope ) {
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. " );
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 " ;
2004-09-21 18:37:55 +00:00
echo " <b> " . _ ( " CSV file: " ) . " </b> <input name= \" inputfile \" type= \" file \" > " ;
echo " <input name= \" submitfile \" type= \" submit \" value= \" " . _ ( 'Upload file and create accounts' ) . " \" > \n " ;
echo " <input type= \" hidden \" name= \" scope \" value= \" $scope\ " > \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 " ;
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
2005-04-24 10:31:07 +00:00
echo " <fieldset class= \" " . $scope . " edit \" > \n <legend><b> " . _ ( " DN settings " ) . " </b></legend> \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
echo " <a href= \" help.php?HelpNumber=361 \" target= \" lamhelp \" > " ;
echo " <img src= \" ../graphics/help.png \" alt= \" " . _ ( 'Help' ) . " \" title= \" " . _ ( 'Help' ) . " \" > " ;
echo " </a> \n " ;
2004-09-21 18:37:55 +00:00
echo " <br> \n " ;
echo " <ul> \n " ;
echo " <li><b> " . _ ( " Identifier " ) . " :</b> " . " dn_suffix</li> \n " ;
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
echo " <a href= \" help.php?HelpNumber=301 \" target= \" lamhelp \" > " ;
echo " <img src= \" ../graphics/help.png \" alt= \" " . _ ( 'Help' ) . " \" title= \" " . _ ( 'Help' ) . " \" > " ;
echo " </a> \n " ;
2004-09-21 18:37:55 +00:00
echo " <br> \n " ;
echo " <ul> \n " ;
echo " <li><b> " . _ ( " Identifier " ) . " :</b> " . " dn_rdn</li> \n " ;
2004-10-14 20:16:23 +00:00
echo " <li><b> " . _ ( " Possible values " ) . " :</b> " . implode ( " , " , getRDNAttributes ( $scope )) . " </li> \n " ;
2004-09-21 18:37:55 +00:00
echo " <li><b> " . _ ( " Example value " ) . " :</b> " . " uid</li> \n " ;
echo " </ul> \n " ;
echo " </td> \n " ;
echo " </tr> \n " ;
echo " </table> \n " ;
echo " </fieldset> \n " ;
2004-08-31 19:13:32 +00:00
// get input fields from modules
$columns = getUploadColumns ( $scope );
// print input fields
$modules = array_keys ( $columns );
for ( $m = 0 ; $m < sizeof ( $modules ); $m ++ ) {
if ( sizeof ( $columns [ $modules [ $m ]]) < 1 ) continue ;
2005-04-24 10:31:07 +00:00
echo " <fieldset class= \" " . $scope . " edit \" > \n <legend><b> " . getModuleAlias ( $modules [ $m ], $scope ) . " </b></legend> \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 " ;
2004-08-31 19:13:32 +00:00
echo " </fieldset> " ;
2003-08-28 18:37:27 +00:00
}
2004-08-31 19:13:32 +00:00
echo " <p> </p> \n " ;
2004-10-12 13:12:16 +00:00
// print table example and build sample CSV
$sampleCSV = " " ;
$sampleCSV_head = array ();
$sampleCSV_row = array ();
2005-04-24 10:31:07 +00:00
echo " <big><b> " . _ ( " This is an example how it would look in your spreadsheet program before you convert to CSV: " ) . " </b></big><br><br> \n " ;
2004-08-31 19:13:32 +00:00
echo " <table style= \" border-color: grey \" cellpadding= \" 10 \" border= \" 2 \" cellspacing= \" 0 \" > \n " ;
echo " <tr> \n " ;
2004-10-16 11:29:15 +00:00
// DN attributes
$sampleCSV_head [] = " \" dn_suffix \" " ;
$sampleCSV_head [] = " \" dn_rdn \" " ;
echo " <td> \n " ;
echo " dn_suffix " ;
echo " </td> \n " ;
echo " <td> \n " ;
echo " dn_rdn " ;
echo " </td> \n " ;
// module attributes
2004-08-31 19:13:32 +00:00
for ( $m = 0 ; $m < sizeof ( $modules ); $m ++ ) {
if ( sizeof ( $columns [ $modules [ $m ]]) < 1 ) continue ;
for ( $i = 0 ; $i < sizeof ( $columns [ $modules [ $m ]]); $i ++ ) {
2004-10-12 13:12:16 +00:00
$sampleCSV_head [] = " \" " . $columns [ $modules [ $m ]][ $i ][ 'name' ] . " \" " ;
2004-08-31 19:13:32 +00:00
echo " <td> \n " ;
echo $columns [ $modules [ $m ]][ $i ][ 'name' ];
echo " </td> \n " ;
2003-09-28 13:30:31 +00:00
}
2003-09-28 16:00:13 +00:00
}
2004-08-31 19:13:32 +00:00
echo " </tr> \n " ;
echo " <tr> \n " ;
2004-10-16 11:29:15 +00:00
// DN attributes
2005-03-10 20:20:00 +00:00
$sampleCSV_row [] = " \" " . $_SESSION [ 'config' ] -> get_Suffix ( $scope ) . " \" " ;
2004-10-16 11:29:15 +00:00
$sampleCSV_row [] = " \" " . array_shift ( getRDNAttributes ( $scope )) . " \" " ;
echo " <td> \n " ;
2005-03-10 20:20:00 +00:00
echo $_SESSION [ 'config' ] -> get_Suffix ( $scope );
2004-10-16 11:29:15 +00:00
echo " </td> \n " ;
echo " <td> \n " ;
echo array_shift ( getRDNAttributes ( $scope ));
echo " </td> \n " ;
// module attributes
2004-08-31 19:13:32 +00:00
for ( $m = 0 ; $m < sizeof ( $modules ); $m ++ ) {
if ( sizeof ( $columns [ $modules [ $m ]]) < 1 ) continue ;
for ( $i = 0 ; $i < sizeof ( $columns [ $modules [ $m ]]); $i ++ ) {
2004-10-12 13:12:16 +00:00
$sampleCSV_row [] = " \" " . $columns [ $modules [ $m ]][ $i ][ 'example' ] . " \" " ;
2004-08-31 19:13:32 +00:00
echo " <td> \n " ;
echo $columns [ $modules [ $m ]][ $i ][ 'example' ];
echo " </td> \n " ;
2003-10-22 13:57:32 +00:00
}
2003-06-01 15:14:16 +00:00
}
2004-08-31 19:13:32 +00:00
echo " </tr> \n " ;
echo " </table> \n " ;
2004-10-12 13:12:16 +00:00
$sampleCSV = implode ( " , " , $sampleCSV_head ) . " \n " . implode ( " , " , $sampleCSV_row ) . " \n " ;
$_SESSION [ 'mass_csv' ] = $sampleCSV ;
// link to CSV sample
echo " <p> \n " ;
echo " <br><br> \n " ;
echo " <a href= \" masscreate.php?getCSV=1 \" ><b> " . _ ( " Download sample CSV file " ) . " </b></a> \n " ;
echo " <br><br> \n " ;
echo " <p> \n " ;
2004-08-31 19:13:32 +00:00
echo " </body> \n " ;
echo " </html> \n " ;
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
2005-06-02 19:31:35 +00:00
echo " <a href= \" help.php?module= $module &HelpNumber= " . $data [ 'help' ] . " &scope= " . $scope . " \" target= \" lamhelp \" > " ;
2005-04-24 10:31:07 +00:00
echo " <img src= \" ../graphics/help.png \" alt= \" " . _ ( 'Help' ) . " \" title= \" " . _ ( 'Help' ) . " \" > " ;
echo " </a> \n " ;
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
?>