2003-07-09 16:20:34 +00:00
< ? php
/*
$Id $
This code is part of LDAP Account Manager ( http :// www . sourceforge . net / projects / lam )
Copyright ( C ) 2003 Tilo Lutz
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
LDAP Account Manager displays table for creating or modifying accounts in LDAP
*/
2003-09-20 07:59:19 +00:00
include_once ( '../lib/account.inc' ); // File with all account-funtions
2003-07-09 16:20:34 +00:00
include_once ( '../lib/config.inc' ); // File with configure-functions
2003-09-20 07:59:19 +00:00
include_once ( '../lib/profiles.inc' ); // functions to load and save profiles
include_once ( '../lib/status.inc' ); // Return error-message
include_once ( '../lib/pdf.inc' ); // Return a pdf-file
include_once ( '../lib/ldap.inc' ); // LDAP-functions
2003-07-09 16:20:34 +00:00
session_save_path ( '../sess' );
@ session_start ();
2003-08-10 19:46:21 +00:00
echo '<html><head><title>' ;
2003-08-14 14:56:36 +00:00
echo _ ( 'Create new accounts' );
2003-07-24 16:44:21 +00:00
echo '</title>' .
2003-09-28 13:30:31 +00:00
'<link rel="stylesheet" type="text/css" href="' . $_SESSION [ 'lamurl' ] . 'style/layout.css">' .
2003-07-24 16:44:21 +00:00
'<meta http-equiv="pragma" content="no-cache">' .
'<meta http-equiv="cache-control" content="no-cache">' .
'</head><body>' .
'<form enctype="multipart/form-data" action="massdetail.php" method="post">' .
2003-09-19 10:03:00 +00:00
'<table class="massdetail" width="100%">' ;
2003-07-09 16:20:34 +00:00
if ( $_GET ) {
$row = $_GET [ 'row' ];
$select = $_GET [ 'type' ];
}
if ( $_POST ) {
$row = $_POST [ 'row' ];
$select = $_POST [ 'type' ];
}
if ( $_POST [ 'apply' ]) {
2003-09-19 10:03:00 +00:00
// Check if surname is valid
2003-09-29 16:20:30 +00:00
if ( ! ereg ( '^([a-z]|[A-Z]|[-]|[ ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])+$' , $_POST [ 'f_general_surname' ])) $errors2 [] = array ( 'ERROR' , _ ( 'Surname' ), _ ( 'Surname contains invalid characters' ));
2003-09-19 10:03:00 +00:00
else $_SESSION [ 'accounts' ][ $row ] -> general_surname = $_POST [ 'f_general_surname' ];
// Check if givenname is valid
2003-09-29 16:20:30 +00:00
if ( ! ereg ( '^([a-z]|[A-Z]|[-]|[ ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])+$' , $_POST [ 'f_general_givenname' ])) $errors2 [] = array ( 'ERROR' , _ ( 'Given name' ), _ ( 'Given name contains invalid characters' ));
2003-09-19 10:03:00 +00:00
else $_SESSION [ 'accounts' ][ $row ] -> general_givenname = $_POST [ 'f_general_givenname' ];
// Check if username is valid
if ( ! ereg ( '^([a-z]|[0-9]|[.]|[-]|[_])*$' , $_POST [ 'f_general_username' ]))
2003-09-29 16:20:30 +00:00
$errors2 [] = array ( 'ERROR' , _ ( 'Username' ), _ ( 'Username contains invalid characters. Valid characters are: a-z, 0-9 and .-_ !' ));
2003-09-20 07:59:19 +00:00
else if ( ! ereg ( '^([a-z]|[A-Z]).*$' , $_POST [ 'f_general_username' ]))
2003-09-29 16:20:30 +00:00
$errors2 [] = array ( 'ERROR' , _ ( 'Name' ), _ ( 'Name contains invalid characters. First character must be a letter' ));
2003-09-19 10:03:00 +00:00
else {
$_SESSION [ 'accounts' ][ $row ] -> general_username = $_POST [ 'f_general_username' ];
// Check if user already exists
2003-09-20 07:59:19 +00:00
if ( isset ( $_SESSION [ 'accounts' ][ $row ] -> general_groupadd ) && in_array ( $_SESSION [ 'accounts' ][ $row ] -> general_group , $_SESSION [ 'accounts' ][ $row ] -> general_groupadd )) {
for ( $i = 0 ; $i < count ( $_SESSION [ 'accounts' ][ $row ] -> general_groupadd ); $i ++ )
if ( $_SESSION [ 'accounts' ][ $row ] -> general_groupadd [ $i ] == $_SESSION [ 'accounts' ][ $row ] -> general_group ) {
unset ( $_SESSION [ 'accounts' ][ $row ] -> general_groupadd [ $i ]);
$_SESSION [ 'accounts' ][ $row ] -> general_groupadd = array_values ( $_SESSION [ 'accounts' ][ $row ] -> general_groupadd );
2003-09-19 10:03:00 +00:00
}
}
// Create automatic useraccount with number if original user already exists
// Reset name to original name if new name is in use
2003-10-19 17:06:16 +00:00
while ( $temp = ldapexists ( $_SESSION [ 'accounts' ][ $row ])) {
2003-09-19 10:03:00 +00:00
// get last character of username
2003-09-20 07:59:19 +00:00
$lastchar = substr ( $_SESSION [ 'accounts' ][ $row ] -> general_username , strlen ( $_SESSION [ 'accounts' ][ $row ] -> general_username ) - 1 , 1 );
2003-09-19 10:03:00 +00:00
// Last character is no number
if ( ! ereg ( '^([0-9])+$' , $lastchar ))
2003-09-20 07:59:19 +00:00
$_SESSION [ 'accounts' ][ $row ] -> general_username = $_SESSION [ 'accounts' ][ $row ] -> general_username . '2' ;
2003-09-19 10:03:00 +00:00
else {
2003-09-20 07:59:19 +00:00
$i = strlen ( $_SESSION [ 'accounts' ][ $row ] -> general_username ) - 1 ;
2003-09-19 10:03:00 +00:00
$mark = false ;
while ( ! $mark ) {
2003-09-20 07:59:19 +00:00
if ( ereg ( '^([0-9])+$' , substr ( $_SESSION [ 'accounts' ][ $row ] -> general_username , $i , strlen ( $_SESSION [ 'accounts' ][ $row ] -> general_username ) - $i ))) $i -- ;
2003-09-19 10:03:00 +00:00
else $mark = true ;
}
// increase last number with one
2003-09-20 07:59:19 +00:00
$firstchars = substr ( $_SESSION [ 'accounts' ][ $row ] -> general_username , 0 , $i + 1 );
$lastchars = substr ( $_SESSION [ 'accounts' ][ $row ] -> general_username , $i + 1 , strlen ( $_SESSION [ 'accounts' ][ $row ] -> general_username ) - $i );
$_SESSION [ 'accounts' ][ $row ] -> general_username = $firstchars . ( intval ( $lastchars ) + 1 );
2003-09-19 10:03:00 +00:00
}
}
}
// check if group is valid
if ( $_POST [ 'f_general_group' ] != '' ) $_SESSION [ 'accounts' ][ $row ] -> general_group = $_POST [ 'f_general_group' ];
2003-09-29 16:20:30 +00:00
else $errors2 [] = array ( 'ERROR' , _ ( 'Primary group' ), _ ( 'No primary group defined.' ));
2003-09-20 07:59:19 +00:00
if ( in_array ( $_POST [ 'f_general_group' ], findgroups ())) $_SESSION [ 'accounts' ][ $row ] -> general_group = $_POST [ 'f_general_group' ];
2003-09-29 16:20:30 +00:00
else $errors2 [] = array ( 'WARN' , _ ( 'Primary group' ), _ ( 'Primary group does not exist. Will create group automaticly.' ));
if ( ! ereg ( '^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])*$' , $_POST [ 'f_personal_title' ])) $errors2 [] = array ( 'ERROR' , _ ( 'Title' ), _ ( 'Please enter a valid title!' ));
2003-09-19 10:03:00 +00:00
else $_SESSION [ 'accounts' ][ $row ] -> personal_title = $_POST [ 'f_personal_title' ];
2003-09-29 16:20:30 +00:00
if ( ! ereg ( '^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])*$' , $_POST [ 'f_personal_employeeType' ])) $errors2 [] = array ( 'ERROR' , _ ( 'Employee type' ), _ ( 'Please enter a valid employee type!' ));
2003-09-19 10:03:00 +00:00
else $_SESSION [ 'accounts' ][ $row ] -> personal_employeeType = $_POST [ 'f_personal_employeeType' ];
2003-09-29 16:20:30 +00:00
if ( ! ereg ( '^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])*$' , $_POST [ 'f_personal_street' ])) $errors2 [] = array ( 'ERROR' , _ ( 'Street' ), _ ( 'Please enter a valid street name!' ));
2003-09-19 10:03:00 +00:00
else $_SESSION [ 'accounts' ][ $row ] -> personal_street = $_POST [ 'f_personal_street' ];
2003-09-29 16:20:30 +00:00
if ( ! ereg ( '^([0-9]|[A-Z]|[a-z])*$' , $_POST [ 'f_personal_postalCode' ])) $errors2 [] = array ( 'ERROR' , _ ( 'Postal code' ), _ ( 'Please enter a valid postal code!' ));
2003-09-19 10:03:00 +00:00
else $_SESSION [ 'accounts' ][ $row ] -> personal_postalCode = $_POST [ 'f_personal_postalCode' ];
2003-09-29 16:20:30 +00:00
if ( ! ereg ( '^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])*$' , $_POST [ 'f_personal_postalAddress' ])) $errors2 [] = array ( 'ERROR' , _ ( 'Postal address' ), _ ( 'Please enter a valid postal address!' ));
2003-09-19 10:03:00 +00:00
else $_SESSION [ 'accounts' ][ $row ] -> personal_postalAddress = $_POST [ 'f_personal_postalAddress' ];
2003-09-29 16:20:30 +00:00
if ( ! ereg ( '^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$' , $_POST [ 'f_personal_telephoneNumber' ])) $errors2 [] = array ( 'ERROR' , _ ( 'Telephone number' ), _ ( 'Please enter a valid telephone number!' ));
2003-09-19 10:03:00 +00:00
else $_SESSION [ 'accounts' ][ $row ] -> personal_telephoneNumber = $_POST [ 'f_personal_telephoneNumber' ];
2003-09-29 16:20:30 +00:00
if ( ! ereg ( '^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$' , $_POST [ 'f_personal_mobileTelephoneNumber' ])) $errors2 [] = array ( 'ERROR' , _ ( 'Mobile number' ), _ ( 'Please enter a valid mobile number!' ));
2003-09-19 10:03:00 +00:00
else $_SESSION [ 'accounts' ][ $row ] -> personal_mobileTelephoneNumber = $_POST [ 'f_personal_mobileTelephoneNumber' ];
2003-09-29 16:20:30 +00:00
if ( ! ereg ( '^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$' , $_POST [ 'f_personal_facsimileTelephoneNumber' ])) $errors2 [] = array ( 'ERROR' , _ ( 'Fax number' ), _ ( 'Please enter a valid fax number!' ));
2003-09-19 10:03:00 +00:00
else $_SESSION [ 'accounts' ][ $row ] -> personal_facsimileTelephoneNumber = $_POST [ 'f_personal_facsimileTelephoneNumber' ];
2003-09-29 16:20:30 +00:00
if ( ! ereg ( '^(([0-9]|[A-Z]|[a-z]|[.]|[-]|[_])+[@]([0-9]|[A-Z]|[a-z]|[-])+([.]([0-9]|[A-Z]|[a-z]|[-])+)*)*$' , $_POST [ 'f_personal_mail' ])) $errors2 [] = array ( 'ERROR' , _ ( 'eMail address' ), _ ( 'Please enter a valid eMail address!' ));
2003-09-19 10:03:00 +00:00
else $_SESSION [ 'accounts' ][ $row ] -> personal_mail = $_POST [ 'f_personal_mail' ];
2003-07-09 16:20:34 +00:00
}
2003-09-19 10:03:00 +00:00
echo '<tr><td><input name="type" type="hidden" value="' . $select . '"></td></tr>' ;
echo '<tr><td><input name="row" type="hidden" value="' . $row . '"></td></tr>' ;
2003-09-29 16:20:30 +00:00
if ( is_array ( $errors2 )) {
for ( $i = 0 ; $i < sizeof ( $errors2 ); $i ++ ) {
StatusMessage ( $errors2 [ $i ][ 0 ], $errors2 [ $i ][ 1 ], $errors2 [ $i ][ 2 ]);
2003-09-19 10:03:00 +00:00
}
}
2003-07-09 16:20:34 +00:00
switch ( $select ) {
case 'error' :
for ( $i = 0 ; $i < sizeof ( $_SESSION [ 'errors' ][ $row ]); $i ++ )
2003-09-19 10:03:00 +00:00
if ( $_SESSION [ 'errors' ][ $row ][ $i ][ 0 ] == 'ERROR' ) {
2003-07-09 16:20:34 +00:00
StatusMessage ( 'ERROR' , _ ( 'Invalid Value!' ), $_SESSION [ 'errors' ][ $row ][ $i ][ 2 ]);
2003-09-19 10:03:00 +00:00
}
2003-07-09 16:20:34 +00:00
break ;
2003-08-28 18:37:27 +00:00
case 'info' :
2003-07-09 16:20:34 +00:00
for ( $i = 0 ; $i < sizeof ( $_SESSION [ 'errors' ][ $row ]); $i ++ )
2003-09-19 10:03:00 +00:00
if ( $_SESSION [ 'errors' ][ $row ][ $i ][ 0 ] == 'INFO' ) {
2003-08-20 16:16:52 +00:00
StatusMessage ( 'INFO' , _ ( 'Check values.' ), $_SESSION [ 'errors' ][ $row ][ $i ][ 2 ]);
2003-09-19 10:03:00 +00:00
}
2003-07-09 16:20:34 +00:00
break ;
2003-08-28 18:37:27 +00:00
case 'warn' :
for ( $i = 0 ; $i < sizeof ( $_SESSION [ 'errors' ][ $row ]); $i ++ )
2003-09-19 10:03:00 +00:00
if ( $_SESSION [ 'errors' ][ $row ][ $i ][ 0 ] == 'WARN' ) {
2003-08-28 18:37:27 +00:00
StatusMessage ( 'WARN' , _ ( 'Check values.' ), $_SESSION [ 'errors' ][ $row ][ $i ][ 2 ]);
2003-09-19 10:03:00 +00:00
}
2003-08-28 18:37:27 +00:00
break ;
2003-07-09 16:20:34 +00:00
case 'detail' :
echo '<tr><td>' ;
2003-08-14 14:56:36 +00:00
echo _ ( 'Surname' ) . '*' ;
2003-07-24 16:44:21 +00:00
echo '</td>' . " \n " . '<td>' .
'<input name="f_general_surname" type="text" size="20" maxlength="20" value="' . $_SESSION [ 'accounts' ][ $row ] -> general_surname . '">' .
'</td><td>' .
'<a href="help.php?HelpNumber=424" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr>' . " \n " . '<tr><td>' ;
2003-08-14 14:56:36 +00:00
echo _ ( 'Given name' ) . '*' ;
2003-07-24 16:44:21 +00:00
echo '</td>' . " \n " . '<td>' .
'<input name="f_general_givenname" type="text" size="20" maxlength="20" value="' . $_SESSION [ 'accounts' ][ $row ] -> general_givenname . '">' .
'</td>' . " \n " . '<td>' .
'<a href="help.php?HelpNumber=425" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr>' . " \n " . '<tr><td>' ;
2003-08-14 14:56:36 +00:00
echo _ ( 'Username' ) . '*' ;
2003-07-09 16:20:34 +00:00
echo " </td> \n <td> " .
2003-07-24 16:44:21 +00:00
'<input name="f_general_username" type="text" size="20" maxlength="20" value="' . $_SESSION [ 'accounts' ][ $row ] -> general_username . '">' .
'</td><td>' .
'<a href="help.php?HelpNumber=400" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr>' . " \n " . '<tr><td>' ;
2003-07-09 16:20:34 +00:00
echo _ ( 'Title' );
2003-07-24 16:44:21 +00:00
echo '</td>' . " \n " . '<td>' .
'<input name="f_personal_title" type="text" size="10" maxlength="10" value="' . $_SESSION [ 'accounts' ][ $row ] -> personal_title . '"> ' ;
2003-09-20 07:59:19 +00:00
echo $_SESSION [ 'accounts' ] -> general_surname . ' ' . $_SESSION [ 'accounts' ] -> general_givenname . '</td><td>' .
2003-07-24 16:44:21 +00:00
'<a href="help.php?HelpNumber=448" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr>' . " \n " . '<tr><td>' ;
2003-08-14 14:56:36 +00:00
echo _ ( 'Employee type' );
2003-07-24 16:44:21 +00:00
echo '</td>' . " \n " . '<td>' .
'<input name="f_personal_employeeType" type="text" size="30" maxlength="30" value="' . $_SESSION [ 'accounts' ][ $row ] -> personal_employeeType . '">' .
'</td><td>' .
'<a href="help.php?HelpNumber=449" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr>' . " \n " . '<tr><td>' ;
2003-07-09 16:20:34 +00:00
echo _ ( 'Street' );
2003-07-24 16:44:21 +00:00
echo '</td>' . " \n " . '<td>' .
'<input name="f_personal_street" type="text" size="30" maxlength="30" value="' . $_SESSION [ 'accounts' ][ $row ] -> personal_street . '">' .
'</td><td>' .
'<a href="help.php?HelpNumber=450" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr>' . " \n " . '<tr><td>' ;
2003-07-09 16:20:34 +00:00
echo _ ( 'Postal code' );
2003-07-24 16:44:21 +00:00
echo '</td>' . " \n " . '<td>' .
'<input name="f_personal_postalCode" type="text" size="5" maxlength="5" value="' . $_SESSION [ 'accounts' ][ $row ] -> personal_postalCode . '">' .
'</td><td>' .
'<a href="help.php?HelpNumber=451" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr>' . " \n " . '<tr><td>' ;
2003-07-09 16:20:34 +00:00
echo _ ( 'Postal address' );
2003-07-24 16:44:21 +00:00
echo '</td>' . " \n " . '<td>' .
'<input name="f_personal_postalAddress" type="text" size="30" maxlength="30" value="' . $_SESSION [ 'accounts' ][ $row ] -> personal_postalAddress . '">' .
'</td><td>' .
'<a href="help.php?HelpNumber=452" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr>' . " \n " . '<tr><td>' ;
2003-08-14 14:56:36 +00:00
echo _ ( 'Telephone number' );
2003-07-24 16:44:21 +00:00
echo '</td>' . " \n " . '<td>' .
'<input name="f_personal_telephoneNumber" type="text" size="30" maxlength="30" value="' . $_SESSION [ 'accounts' ][ $row ] -> personal_telephoneNumber . '">' .
'</td><td>' .
'<a href="help.php?HelpNumber=453" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr>' . " \n " . '<tr><td>' ;
2003-08-14 14:56:36 +00:00
echo _ ( 'Mobile number' );
2003-07-24 16:44:21 +00:00
echo '</td>' . " \n " . '<td>' .
'<input name="f_personal_mobileTelephoneNumber" type="text" size="30" maxlength="30" value="' . $_SESSION [ 'accounts' ][ $row ] -> personal_mobileTelephoneNumber . '">' .
'</td><td>' .
'<a href="help.php?HelpNumber=454" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr>' . " \n " . '<tr><td>' ;
2003-08-14 14:56:36 +00:00
echo _ ( 'Fax number' );
2003-07-24 16:44:21 +00:00
echo '</td>' . " \n " . '<td>' .
'<input name="f_personal_facsimileTelephoneNumber" type="text" size="30" maxlength="30" value="' . $_SESSION [ 'accounts' ][ $row ] -> personal_facsimileTelephoneNumber . '">' .
'</td><td>' .
'<a href="help.php?HelpNumber=455" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr>' . " \n " . '<tr><td>' ;
2003-08-14 14:56:36 +00:00
echo _ ( 'eMail address' );
2003-07-24 16:44:21 +00:00
echo '</td>' . " \n " . '<td>' .
'<input name="f_personal_mail" type="text" size="30" maxlength="30" value="' . $_SESSION [ 'accounts' ][ $row ] -> personal_mail . '">' .
'</td><td>' .
'<a href="help.php?HelpNumber=456" target="lamhelp">' . _ ( 'Help' ) . '</a>' .
'</td></tr><br>' ;
2003-08-03 13:22:12 +00:00
echo '<tr><td><input name="apply" type="submit" value="' ; echo _ ( 'Apply' ); echo '"></td><td></td><td>' ;
echo '<input name="undo" type="submit" value="' ; echo _ ( 'Undo' ); echo '"></td></tr>' ;
2003-07-09 16:20:34 +00:00
break ;
}
echo '</table></form></body></html>' ;
?>