diff --git a/lam/templates/masscreate.php b/lam/templates/masscreate.php index 3c2a6b2b..d8973256 100644 --- a/lam/templates/masscreate.php +++ b/lam/templates/masscreate.php @@ -19,26 +19,21 @@ $Id$ 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 */ -// include all needed files -include_once('../lib/account.inc'); // File with all account-funtions -include_once('../lib/config.inc'); // File with configure-functions -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 - -/* We have to include all modules -* before start session -* *** fixme I would prefer loading them dynamic but -* i don't know how to to this +/** +* Start page of file upload +* +* @author Roland Gruber +* @package tools */ -$dir = opendir('../lib/modules'); -while ($entry = readdir($dir)) - if (is_file('../lib/modules/'.$entry)) include_once ('../lib/modules/'.$entry); + +/** access to configuration */ +include_once('../lib/config.inc'); +/** status messages */ +include_once('../lib/status.inc'); +/** account modules */ +include_once('../lib/modules.inc'); // Start session session_save_path('../sess'); @@ -53,561 +48,175 @@ if (!isset($_SESSION['loggedIn'])) { // Set correct language, codepages, .... setlanguage(); -if (!isset($_SESSION['cache'])) { - $_SESSION['cache'] = new cache(); - } - -/* Save current time in $time. We need $time to check out how -* long masscreate.php is running. To avoid max. execution time -* set in php.ini masscreate.php will create a redirect to -* itself. -*/ -$time=time(); -/* Startcondition massdetail.php was called from outside or -* from masscreate.php itself via meta refresh -*/ -if (count($_POST)==0) { - // Register new account_container - $_SESSION['account'] = new accountContainer('user', 'account'); - // load profile - - // Find out list of attribtues which must be set put not allready covered by profile - - // Print first HTML-Page - echo $_SESSION['header']; - echo "" . _('Create new Accounts') . "\n"; - echo "\n"; - - } -else { - /* Check loaded attributed in $_SESSION['accounts'] if file was loaded and - * filesize is bigger as 0. - */ - if ($_POST['tolist'] && ($_FILES['userfile']['size']>0)) $select = 'list'; - // Go the corresponding page if button was pressed - else if ($_POST['list2']) $select = 'list2'; - else if ($_POST['back']) $select = 'main'; - else if ($_POST['cancel']) $select = 'cancel'; - else if ($_POST['create']) $select = 'create'; - else if ($_POST['pdf']) { - // Create PDF-File - createUserPDF($_SESSION['accounts']); - // Stop script - die; - } - } - -switch ($select) { - /* Select which part of page should be loaded - * cacnel = Go back to listusers.php - * list = Load csv-file. Refresh to list2 - */ - case 'cancel' : - // go back to user list page - metaRefresh("lists/listusers.php"); - // Stop script - die; - break; - case 'list' : - if (loadfile()) { - // Do Refresh to masscreate.php itself if csv-file was loaded successfully - $_SESSION['group_suffix'] = $_POST['f_group_suffix']; - $_SESSION['group_selectprofile'] = $_POST['f_selectgroupprofile']; - metaRefresh("masscreate.php?list2=true"); - // Stop script - die; - } - else { - /* Loadfile has returned an error because masscreate.php can only - * handle max 400 new users. - * lam will show an error-page with a notice everything after line - * 400 in csv-file will be ignored - */ - echo $_SESSION['header']; - echo ''; - echo _('Create new Accounts'); - echo ''."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n". - '
'."\n". - ''. - ''."\n"; - echo '
'; - echo _('Max 400 users allowed. Ignored additional users.'); - echo '
'; - echo _('Cancel'); - echo ''; - echo _('Contiune'); - echo "
\n"; - // Stop script - die; - } - break; - } - -// Write HTML-Header echo $_SESSION['header']; -echo ''; -echo _('Create new Accounts'); -echo ''."\n". - ''."\n". - ''."\n". - ''."\n"; +echo "account upload\n"; +echo "\n"; +echo "\n"; +echo "\n"; + +// check if account specific page should be shown +if ($_POST['user']) showMainPage('user'); +elseif ($_POST['group']) showMainPage('group'); +elseif ($_POST['host']) showMainPage('host'); +// show start page +else { + echo "

" . _("Account creation via file upload") . "

\n"; + echo "

 

\n"; + echo "

 

\n"; + + echo "

\n"; + echo "Here you can create multiple accounts by providing a CSV file."; + echo "

\n"; + + echo "

 

\n"; + + echo "

\n"; + echo _("Please select your account type:"); + echo "

\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo "
\n"; + + echo "\n"; + echo "\n"; +} -switch ($select) { - /* Select which part of page should be loaded - * create = Create new users - * list2 = Show page with all users who should be created. - * main = Show startpegae where settings and file can be selected - */ - case 'create': - /* Set Metarefresh to max_execution_time - 5sec - * 5 sec. should be enough to create the current - * user - */ - if ($_SESSION['pointer'] < sizeof($_SESSION['accounts'])) { - $refresh = get_cfg_var('max_execution_time')-5; - echo ''."\n"; - } - // Display start of body - echo ''."\n". - '
'."\n". - "
"; - echo _('Creating users. Please stand by ....'); - echo "\n\n"; - // Keys needed to encrypt passwords from session - $stay=true; - // Stay in loop as long there are still users to create and no error did ocour - while (($_SESSION['pointer'] < sizeof($_SESSION['accounts'])) && $stay) { - if (getgid($_SESSION['accounts'][$_SESSION['pointer']]->general_group)==-1) { - // Create group if it doesn't exist yet - $group = LoadGroupProfile($_SESSION['group_selectprofile']); - $group->type = 'group'; - // load quotas from profile and check if they are valid - if ($config_intern->scriptServer) { - // load quotas and check if quotas from profile are valid - $quotas = getquotas(array($group)); - for ($i=0; $iquota); $i++) $profile_quotas[] = $group->quota[$i][0]; - for ($i=0; $iquota); $i++) { - $real_quotas[] = $quotas[0]->quota[$i][0]; - if (is_array($profile_quotas)) { - if (!in_array($quotas[0]->quota[$i][0], $profile_quotas)) $group->quota[]=$quotas[0]->quota[$i]; - } - else $group->quota[]=$quotas[0]->quota[$i]; - } - $j=0; - // delete not existing quotas - while (isset($group->quota[$j][0])) { - // remove invalid quotas - if (!in_array($group->quota[$j][0], $real_quotas)) unset($group->quota[$j]); - else $j++; - } - // Beautify array, repair index - $group->quota = array_values($group->quota); - } - // Get groupname from current user - $group->general_username=$_SESSION['accounts'][$_SESSION['pointer']]->general_group; - // gid Number - $temp = explode(':', checkid($group)); - $group->general_uidNumber = $temp[0]; - // Set Gecos to groupname - $group->general_gecos=$_SESSION['accounts'][$_SESSION['pointer']]->general_group; - // Set DN - $group->general_dn=$_SESSION['group_suffix']; - // Create group - $error = creategroup($group); - // Show success or failure-message about group creation - if ($error==1) { - echo ''."\n"; - } - else { - $stay = false; - StatusMessage('ERROR', _('Could not create group!'), sprintf (_('Was unable to create %s.'), $_SESSION['accounts'][$row]->general_group)); - } - } - // Check if Homedir is valid - $_SESSION['accounts'][$_SESSION['pointer']]->general_homedir = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->general_homedir); - if ($_SESSION['accounts'][$_SESSION['pointer']]->general_username != '') - $_SESSION['accounts'][$_SESSION['pointer']]->general_homedir = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->general_homedir); - // Set uid number - $temp = explode(':', checkid($_SESSION['accounts'][$_SESSION['pointer']])); - $_SESSION['accounts'][$_SESSION['pointer']]->general_uidNumber = $temp[0]; - $_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath); - $_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath); - $_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath); - $_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath); - $_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome); - $_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome); - $_SESSION['accounts'][$_SESSION['pointer']]->unix_password = base64_encode($_SESSION['ldap']->encrypt(genpasswd())); - $_SESSION['accounts'][$_SESSION['pointer']]->smb_password = $_SESSION['accounts'][$_SESSION['pointer']]->unix_password; - // Only create user if we have at least 5sec time to create the user - if ( (time()-$time)<(get_cfg_var('max_execution_time')-10)) { - $error = createuser($_SESSION['accounts'][$_SESSION['pointer']], false); - // Show error or success message - if ($error==1) { - $_SESSION['pointer']++; - echo ''."\n"; - } - else { - $stay = false; - StatusMessage('ERROR', _('Could not create user!'), sprintf (_('Was unable to create %s.'), $_SESSION['accounts'][$row]->general_username)); - } - } - // End loop if we don't have enough time to create user - else $stay=false; - } - if (!$stay) { - // Display rest of meta-refreh page if there are still users to create - echo ''."\n"; - echo '
'; - sprintf (_('Created group %s.'), $_SESSION['accounts'][$_SESSION['pointer']]->general_group); - echo '
'; - sprintf (_('Created user %s.'), $_SESSION['accounts'][$_SESSION['pointer']]->general_username); - echo '
'; - echo _('Click here if you are not directed to the next page.'); - echo '
'; - echo "
\n"; - } - else { - // Write homedirs and quotas if needed - if ($_SESSION['config']->scriptServer) { - setquotas ($_SESSION['accounts']); - // Get array with new usernames - foreach ($_SESSION['accounts'] as $account) $users[] = $account->general_username; - addhomedir($users); - } - // Show success-page - echo ''; - echo _('All Users have been created'); - echo ''."\n".''; - echo ''; - echo ''; - echo ''."\n\n"; - // unset variables - if ( isset($_SESSION['pointer'])) unset($_SESSION['pointer']); - if ( isset($_SESSION['mass_errors'])) unset($_SESSION['mass_errors']); - if ( isset($_SESSION['group_suffix'])) unset($_SESSION['group_suffix']); - if ( isset($_SESSION['group_selectprofile'])) unset($_SESSION['group_selectprofile']); - } - break; - case 'list2': - // Show table with all users - echo ''."\n". - ''."\n". - ''; - for ($i=0; $igeneral_group!='') - StatusMessage('INFO', _('Group').' '. $_SESSION['accounts'][$i]->general_group.' '._('not found!'), _('It will be created.')); - echo "
\n"; - echo "
"; - echo _('Confirm List'); - echo "\n\n"; - echo ''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n"; - $end = sizeof($_SESSION['accounts']); - for ($row=0; $row<$end; $row++) { // loops for every row - echo ''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n"; - } - $noerrors=true; - for ($i=0; $i'; - if (!$noerrors) { echo ''."\n"; } - if (!$nowarn) { echo ''."\n"; } - echo '
'._('row').''. _('Surname'). ''. _('Given name'). ''. _('User name'). ''. _('Primary group'). ''. - _('Details'). '' . _('Infos'). '' . _('Warnings'). '' . _('Errors') . '
'.$row.''. - $_SESSION['accounts'][$row]->general_surname.''. - $_SESSION['accounts'][$row]->general_givenname.''. - $_SESSION['accounts'][$row]->general_username.''. - $_SESSION['accounts'][$row]->general_group.''. - ''._('Show Details.').''; - $found=false; - // Show infos - for ($i=0; $i'._('Show Infos.').''; - echo ''; - $found=false; - // Show warnings - for ($i=0; $i'._('Show Warnings.').''; - echo ''; - $found=false; - // Show errors - for ($i=0; $i'._('Show Errors.').''; - echo '
'. _('There are some errors.') . '
'. _('There are some warnings.') . '
'; - echo "
"; - echo _('Please select page:'); - echo "\n\n". - ''."\n"."
'; - if ($noerrors) { echo ''; } - echo '
\n
"; - break; - case 'main': - // Unset old variables - if ( isset($_SESSION['accounts'])) unset($_SESSION['accounts']); - if ( isset($_SESSION['pointer'])) unset($_SESSION['pointer']); - if ( isset($_SESSION['mass_errors'])) unset($_SESSION['mass_errors']); - if ( isset($_SESSION['group_suffix'])) unset($_SESSION['group_suffix']); - if ( isset($_SESSION['group_selectprofile'])) unset($_SESSION['group_selectprofile']); - // Set pointer to 0, first user - $_SESSION['pointer']=0; - echo ''."\n". - ''."\n". - "
"; - echo _('Mass Creation'); - echo "\n\n\n
"; - echo _('Please provide a csv-file with the following syntax. Values with * are required:'); - echo '
'. - ''. - ''."\n".''."\n".'\n'."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".'
'."\n"; - echo _('Surname').'*,'; - echo ''; - echo _('Given name').'*,'; - echo ''; - echo _('Username').'*,'; - echo ""; - echo _('Primary group').','; - echo ''; - echo _('Title').','; - echo ''; - echo _('eMail address').','; - echo ''; - echo _('Telephone number').','; - echo '
'; - echo _('Mobile number').','; - echo ''; - echo _('Fax number').','; - echo ''; - echo _('Street').','; - echo ''; - echo _('Postal code').','; - echo ''; - echo _('Postal address').','; - echo ''; - echo _('Employee type'); - echo '<CR>'; - echo '
'; - echo "
"; - echo _('If Primary group is not given it\'ll used from profile.'); - echo "
"; - echo _('If Primary group does not exist it will be created.'); - echo "
\n"; - echo "
"; - echo _('Select settings'); - echo "\n". - '\n\n\n'."\n".''."\n".'\n\n\n'."\n".'\n\n\n'."\n". - ''."\n"."
'."\n"; - echo _('Select user profile:'); - echo ''; - echo ""; - echo _('Help')."
"; - echo _('User suffix'); echo ''._('Help').''. - '
'."\n"; - echo _("Expand suffix with primary groupname"); - echo ''; - echo ""; - echo _('Help')."
"; - echo _('Group suffix'); echo ''._('Help').''. - '
'."\n"; - echo _('Select group profile'); - echo ''; - echo ""; - echo _('Help')."
"; - echo ''; - echo _('Select file:'); - echo '
'."\n". - '
\n
\n"; - break; - } - -echo '
'; - - -/* Whis function will load a csv-file and -* load all attributes into $_SESSION['accounts'][$row] which -* is an array of account objects -* The csv file is using the following syntax: +/** +* Displays the acount type specific main page of the upload. +* +* @param string $scope account type */ -function loadfile() { - if ($_FILES['userfile']['size']>0) { - // Array with all OUs from users - $OUs = $_SESSION['ldap']->search_units($_SESSION['config']->get_UserSuffix()); - // fixme **** load all existing OUs in Array - // open csv-file - $handle = fopen($_FILES['userfile']['tmp_name'], 'r'); - // Load profile which should be used for all users - $profile = loadUserProfile($_POST['f_selectprofile']) ; - // Set type to user - $profile->type = 'user'; - if ($config_intern->scriptServer) { - // load quotas and check if quotas from profile are valid - $quotas = getquotas(array($profile)); - for ($i=0; $iquota); $i++) $profile_quotas[] = $profile->quota[$i][0]; - for ($i=0; $iquota); $i++) { - $real_quotas[] = $quotas[0]->quota[$i][0]; - if (is_array($profile_quotas)) { - if (!in_array($quotas[0]->quota[$i][0], $profile_quotas)) $profile->quota[]=$quotas[0]->quota[$i]; - } - else $profile->quota[]=$quotas[0]->quota[$i]; - } - $j=0; - // delete not existing quotas - while (isset($profile->quota[$j][0])) { - // remove invalid quotas - if (!in_array($profile->quota[$j][0], $real_quotas)) unset($profile->quota[$j]); - else $j++; - } - // Beautify array, repair index - $profile->quota = array_values($profile->quota); - } - // Get keys to en/decrypt passwords - for ($row=0; $line_array=fgetcsv($handle,2048); $row++) { - // loops for every row - // Set corrent user to profile - $_SESSION['accounts'][$row] = $profile; - // Load values from file into array - if (isset($line_array[0])) $_SESSION['accounts'][$row]->general_surname = $line_array[0]; - if (isset($line_array[1])) $_SESSION['accounts'][$row]->general_givenname = $line_array[1]; - if (isset($line_array[2])) $_SESSION['accounts'][$row]->general_username = $line_array[2]; - if (isset($line_array[3])) $_SESSION['accounts'][$row]->general_group = $line_array[3]; - if (isset($line_array[4])) $_SESSION['accounts'][$row]->personal_title = $line_array[4]; - if (isset($line_array[5])) $_SESSION['accounts'][$row]->personal_mail = $line_array[5]; - if (isset($line_array[6])) $_SESSION['accounts'][$row]->personal_telephoneNumber = $line_array[6]; - if (isset($line_array[7])) $_SESSION['accounts'][$row]->personal_mobileTelephoneNumber = $line_array[7]; - if (isset($line_array[8])) $_SESSION['accounts'][$row]->personal_facsimileTelephoneNumber = $line_array[8]; - if (isset($line_array[9])) $_SESSION['accounts'][$row]->personal_street = $line_array[9]; - if (isset($line_array[10])) $_SESSION['accounts'][$row]->personal_postalCode = $line_array[10]; - if (isset($line_array[11])) $_SESSION['accounts'][$row]->personal_postalAddress = $line_array[11]; - if (isset($line_array[12])) $_SESSION['accounts'][$row]->personal_employeeType = $line_array[12]; - if ($_POST['f_ou_expand']) { - // Expand DN of user with ou=$group - $_SESSION['accounts'][$row]->general_dn = "ou=".$_SESSION['accounts'][$row]->general_group .','. $_POST['f_general_suffix']; - // Create OUs if needed - if (!in_array("ou=".$_SESSION['accounts'][$row]->general_group.",".$_POST['f_general_suffix'], $OUs)) { - $attr['objectClass']= 'organizationalUnit'; - $attr['ou'] = $_SESSION['accounts'][$row]->general_group; - $success = ldap_add($_SESSION['ldap']->server(), $_SESSION['accounts'][$row]->general_dn, $attr); - if ($success) $OUs[] = "ou=".$_SESSION['accounts'][$row]->general_group.",".$_POST['f_general_suffix']; - } - } - // Set DN without uid=$username - else $_SESSION['accounts'][$row]->general_dn = $_POST['f_general_suffix']; - // Create Random Password - $_SESSION['accounts'][$row]->unix_password = base64_encode($_SESSION['ldap']->encrypt(genpasswd())); - $_SESSION['accounts'][$row]->smb_password=$_SESSION['accounts'][$row]->unix_password; - } - } - // Validate cache-array - ldapreload('user'); - // Get List with all existing usernames - foreach ($_SESSION['userDN'] as $user_array) $users[] = $user_array['cn']; - for ($row2=0; $row2general_username, $users)) { - // get last character of username - $lastchar = substr($_SESSION['accounts'][$row2]->general_username, strlen($_SESSION['accounts'][$row2]->general_username)-1, 1); - // Last character is no number - if ( !ereg('^([0-9])+$', $lastchar)) - /* Last character is no number. Therefore we only have to - * add "2" to it. - */ - $_SESSION['accounts'][$row2]->general_username = $_SESSION['accounts'][$row2]->general_username . '2'; - else { - /* Last character is a number -> we have to increase the number until we've - * found a groupname with trailing number which is not in use. - * - * $i will show us were we have to split groupname so we get a part - * with the groupname and a part with the trailing number - */ - $i=strlen($_SESSION['accounts'][$row2]->general_username)-1; - $mark = false; - // Set $i to the last character which is a number in $account_new->general_username - while (!$mark) { - if (ereg('^([0-9])+$',substr($_SESSION['accounts'][$row2]->general_username, $i, strlen($_SESSION['accounts'][$row2]->general_username)-$i))) $i--; - else $mark=true; - } - // increase last number with one - $firstchars = substr($_SESSION['accounts'][$row2]->general_username, 0, $i+1); - $lastchars = substr($_SESSION['accounts'][$row2]->general_username, $i+1, strlen($_SESSION['accounts'][$row2]->general_username)-$i); - // Put username together - $_SESSION['accounts'][$row2]->general_username = $firstchars . (intval($lastchars)+1); - } - } - // Add uername to array so it's not used again for another user in masscreate - $users[] = $_SESSION['accounts'][$row2]->general_username; - if ($_SESSION['accounts'][$row2]->general_username != $username) $_SESSION['mass_errors'][$row2][] = array('WARN', _('Username'), _('Username in use. Selected next free username.')); - // Check if givenname is valid - if ( !ereg('^([a-z]|[A-Z]|[-]|[ ]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])+$', $_SESSION['accounts'][$row2]->general_givenname)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Given name'), _('Given name contains invalid characters')); - // Check if surname is valid - if ( !ereg('^([a-z]|[A-Z]|[-]|[ ]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])+$', $_SESSION['accounts'][$row2]->general_surname)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Surname'), _('Surname contains invalid characters')); - if ( ($_SESSION['accounts'][$row2]->general_gecos=='') || ($_SESSION['accounts'][$row2]->general_gecos==' ')) { - $_SESSION['accounts'][$row2]->general_gecos = $_SESSION['accounts'][$row2]->general_givenname . " " . $_SESSION['accounts'][$row2]->general_surname ; - $_SESSION['mass_errors'][$row2][] = array('INFO', _('Gecos'), _('Inserted sur- and given name in gecos-field.')); - } - $_SESSION['accounts'][$row2]->smb_displayName = $_SESSION['accounts'][$row2]->general_gecos; - if ($_SESSION['accounts'][$row2]->general_group=='') $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Primary group'), _('No primary group defined!')); - // Check if Username contains only valid characters - if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $_SESSION['accounts'][$row2]->general_username)) - $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Username'), _('Username contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')); - // Check if Name-length is OK. minLength=3, maxLength=20 - if ( !ereg('.{3,20}', $_SESSION['accounts'][$row2]->general_username)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Name'), _('Name must contain between 3 and 20 characters.')); - // Check if Name starts with letter - if ( !ereg('^([a-z]|[A-Z]).*$', $_SESSION['accounts'][$row2]->general_username)) - $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Name'), _('Name contains invalid characters. First character must be a letter.')); - // Personal Settings - if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['accounts'][$row2]->personal_telephoneNumber)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Telephone number'), _('Please enter a valid telephone number!')); - if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['accounts'][$row2]->personal_mobileTelephoneNumber)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Mobile number'), _('Please enter a valid mobile number!')); - if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['accounts'][$row2]->personal_facsimileTelephoneNumber)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Fax number'), _('Please enter a valid fax number!')); - if ( !ereg('^(([0-9]|[A-Z]|[a-z]|[.]|[-]|[_])+[@]([0-9]|[A-Z]|[a-z]|[-])+([.]([0-9]|[A-Z]|[a-z]|[-])+)*)*$', $_SESSION['accounts'][$row2]->personal_mail)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('eMail address'), _('Please enter a valid eMail address!')); - if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_street)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Street'), _('Please enter a valid street name!')); - if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_postalAddress)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Postal address'), _('Please enter a valid postal address!')); - if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_title)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Title'), _('Please enter a valid title!')); - if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_employeeType)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Employee type'), _('Please enter a valid employee type!')); - if ( !ereg('^([0-9]|[A-Z]|[a-z])*$', $_SESSION['accounts']->personal_postalCode)) $_SESSION['mass_errors'][$row2][] = array('ERROR', _('Postal code'), _('Please enter a valid postal code!')); - } - } - // Close file if it was opened - if ($_FILES['userfile']['size']>0) { - fclose($handle); - unlink($_FILES['userfile']['tmp_name']); - } - // Return false if more than 400 users were found - if ($row2>400) return false; - else return true; - } +function showMainPage($scope) { + echo "

\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 "

\n"; + + echo "

 

\n"; + echo "

\n"; + echo "" . _("CSV file:") . " "; + echo "

\n"; + + echo "

 

\n"; + + echo "" . _("Columns:") . "\n"; + echo "

\n"; + + // 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; + echo "

\n" . getModuleAlias($modules[$m], $scope) . "\n"; + echo "\n"; + for ($i = 0; $i < sizeof($columns[$modules[$m]]); $i++) { + echo "\n"; + echo "\n"; + $i++; + if ($i < sizeof($columns[$modules[$m]])) { + echo "\n"; + $i++; + if ($i < sizeof($columns[$modules[$m]])) { + echo "\n"; + } + else echo ""; // empty cell if no more fields + } + else echo ""; // empty cell if no more fields + echo "\n"; + } + echo "
\n"; + showColumnData($scope, $modules[$m], $columns[$modules[$m]][$i]); + echo "\n"; + showColumnData($scope, $modules[$m], $columns[$modules[$m]][$i]); + echo "\n"; + showColumnData($scope, $modules[$m], $columns[$modules[$m]][$i]); + echo "
\n"; + echo "
"; + } + echo "

\n"; + + echo "

 

\n"; + + // print table example + echo "" . _("This is an example how it would look in your spreadsheet program before you convert to CSV:") . "\n"; + + echo "

\n"; + echo "\n"; + echo "\n"; + for ($m = 0; $m < sizeof($modules); $m++) { + if (sizeof($columns[$modules[$m]]) < 1) continue; + for ($i = 0; $i < sizeof($columns[$modules[$m]]); $i++) { + echo "\n"; + } + } + echo "\n"; + echo "\n"; + for ($m = 0; $m < sizeof($modules); $m++) { + if (sizeof($columns[$modules[$m]]) < 1) continue; + for ($i = 0; $i < sizeof($columns[$modules[$m]]); $i++) { + echo "\n"; + } + } + echo "\n"; + echo "
\n"; + echo $columns[$modules[$m]][$i]['name']; + echo "
\n"; + echo $columns[$modules[$m]][$i]['example']; + echo "
\n"; + echo "

\n"; + + echo "\n"; + echo "\n"; + die; +} + +/** +* Prints the properties of one input field. +* +* @param string $scope account type +* @param string $module account module name +* @param array $data field data from modules +*/ +function showColumnData($scope, $module, $data) { + if ($data['required']) { + echo "\n"; + echo $data['description']; + echo "\n"; + } + else { + echo "\n"; + echo $data['description']; + echo "\n"; + } + echo "
\n"; + echo "
    \n"; + echo "
  • \n"; + echo "" . _("Identifier:") . " " . $data['name'] . "\n"; + echo "
  • \n"; + echo "
  • \n"; + echo "" . _("Example value:") . " " . $data['example'] . "\n"; + echo "
  • \n"; + echo "
  • \n"; + echo "" . _("Help") . "\n"; + echo "
  • \n"; + + echo "
\n"; +} ?> diff --git a/lam/templates/massdetail.php b/lam/templates/massdetail.php deleted file mode 100644 index 481792a2..00000000 --- a/lam/templates/massdetail.php +++ /dev/null @@ -1,289 +0,0 @@ -general_surname = $_POST['f_general_surname']; - // Check if givenname is valid - if ( !ereg('^([a-z]|[A-Z]|[-]|[ ]|[�|[�|[�|[�|[]|[�|[�)+$', $_POST['f_general_givenname'])) $errors2[] = array('ERROR', _('Given name'), _('Given name contains invalid characters')); - 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'])) - $errors2[] = array('ERROR', _('Username'), _('Username contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')); - else if ( !ereg('^([a-z]|[A-Z]).*$', $_POST['f_general_username'])) - $errors2[] = array('ERROR', _('Name'), _('Name contains invalid characters. First character must be a letter.')); - else { - // Create Array with all users in ldap and in array - // Validate cache-array - ldapreload('user'); - // Get List with all existing usernames - foreach ($_SESSION['userDN'] as $user_array) $users[] = $user_array['cn']; - // Get List with all users in array - foreach ($_SESSION['accounts'] as $user_array) $users[] = $user_array->general_username; - // unset old username in user-array - $users = @array_flip($users); - unset ($users[$_SESSION['accounts'][$row]->general_username]); - $users = array_flip($users); - // Store new username - $_SESSION['accounts'][$row]->general_username = $_POST['f_general_username']; - // Set all usernames to unique usernames - while (in_array($_SESSION['accounts'][$row2]->general_username, $users)) { - // get last character of username - $lastchar = substr($_SESSION['accounts'][$row2]->general_username, strlen($_SESSION['accounts'][$row2]->general_username)-1, 1); - // Last character is no number - if ( !ereg('^([0-9])+$', $lastchar)) - /* Last character is no number. Therefore we only have to - * add "2" to it. - */ - $_SESSION['accounts'][$row2]->general_username = $_SESSION['accounts'][$row2]->general_username . '2'; - else { - /* Last character is a number -> we have to increase the number until we've - * found a groupname with trailing number which is not in use. - * - * $i will show us were we have to split groupname so we get a part - * with the groupname and a part with the trailing number - */ - $i=strlen($_SESSION['accounts'][$row2]->general_username)-1; - $mark = false; - // Set $i to the last character which is a number in $account_new->general_username - while (!$mark) { - if (ereg('^([0-9])+$',substr($_SESSION['accounts'][$row2]->general_username, $i, strlen($_SESSION['accounts'][$row2]->general_username)-$i))) $i--; - else $mark=true; - } - // increase last number with one - $firstchars = substr($_SESSION['accounts'][$row2]->general_username, 0, $i+1); - $lastchars = substr($_SESSION['accounts'][$row2]->general_username, $i+1, strlen($_SESSION['accounts'][$row2]->general_username)-$i); - // Put username together - $_SESSION['accounts'][$row2]->general_username = $firstchars . (intval($lastchars)+1); - } - } - // Show warning if lam has changed username - if ($_SESSION['accounts'][$row2]->general_username != $_POST['f_general_username']) $errors2[] = array('WARN', _('Username'), _('Username in use. Selected next free username.')); - } - // Check personal settings - if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[�|[�|[�|[�|[�|[]|[�)*$', $_POST['f_personal_title'])) $errors2[] = array('ERROR', _('Title'), _('Please enter a valid title!')); - else $_SESSION['accounts'][$row]->personal_title = $_POST['f_personal_title']; - if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[�|[�|[�|[�|[�|[]|[�)*$', $_POST['f_personal_employeeType'])) $errors2[] = array('ERROR', _('Employee type'), _('Please enter a valid employee type!')); - else $_SESSION['accounts'][$row]->personal_employeeType = $_POST['f_personal_employeeType']; - if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[�|[�|[�|[�|[�|[]|[�)*$', $_POST['f_personal_street'])) $errors2[] = array('ERROR', _('Street'), _('Please enter a valid street name!')); - else $_SESSION['accounts'][$row]->personal_street = $_POST['f_personal_street']; - if ( !ereg('^([0-9]|[A-Z]|[a-z])*$', $_POST['f_personal_postalCode'])) $errors2[] = array('ERROR', _('Postal code'), _('Please enter a valid postal code!')); - else $_SESSION['accounts'][$row]->personal_postalCode = $_POST['f_personal_postalCode']; - if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[�|[�|[�|[�|[�|[]|[�)*$', $_POST['f_personal_postalAddress'])) $errors2[] = array('ERROR', _('Postal address'), _('Please enter a valid postal address!')); - else $_SESSION['accounts'][$row]->personal_postalAddress = $_POST['f_personal_postalAddress']; - if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_POST['f_personal_telephoneNumber'])) $errors2[] = array('ERROR', _('Telephone number'), _('Please enter a valid telephone number!')); - else $_SESSION['accounts'][$row]->personal_telephoneNumber = $_POST['f_personal_telephoneNumber']; - if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_POST['f_personal_mobileTelephoneNumber'])) $errors2[] = array('ERROR', _('Mobile number'), _('Please enter a valid mobile number!')); - else $_SESSION['accounts'][$row]->personal_mobileTelephoneNumber = $_POST['f_personal_mobileTelephoneNumber']; - if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_POST['f_personal_facsimileTelephoneNumber'])) $errors2[] = array('ERROR', _('Fax number'), _('Please enter a valid fax number!')); - else $_SESSION['accounts'][$row]->personal_facsimileTelephoneNumber = $_POST['f_personal_facsimileTelephoneNumber']; - 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!')); - else $_SESSION['accounts'][$row]->personal_mail = $_POST['f_personal_mail']; - } - -// Print header and part of body -echo ''; -echo _('Create new accounts'); -echo ''. - ''. - ''. - ''. - ''. - '
'; -// Display errir-messages -if (is_array($errors2)) - for ($i=0; $i'; - // Store variabled in $_POST - echo ''; - echo ''; - echo ''; - echo _('Surname').'*'; - echo ''."\n".''. - ''. - ''. - ''._('Help').''. - ''."\n".''; - echo _('Given name').'*'; - echo ''."\n".''. - ''. - ''."\n".''. - ''._('Help').''. - ''."\n".''; - echo _('Username').'*'; - echo "\n". - ''. - ''. - ''._('Help').''. - ''."\n".''; - echo _('Title'); - echo ''."\n".''. - ' '; - echo $_SESSION['accounts']->general_surname . ' ' . $_SESSION['accounts']->general_givenname . ''. - ''._('Help').''. - ''."\n".''; - echo _('Employee type'); - echo ''."\n".''. - ''. - ''. - ''._('Help').''. - ''."\n".''; - echo _('Street'); - echo ''."\n".''. - ''. - ''. - ''._('Help').''. - ''."\n".''; - echo _('Postal code'); - echo ''."\n".''. - ''. - ''. - ''._('Help').''. - ''."\n".''; - echo _('Postal address'); - echo ''."\n".''. - ''. - ''. - ''._('Help').''. - ''."\n".''; - echo _('Telephone number'); - echo ''."\n".''. - ''. - ''. - ''._('Help').''. - ''."\n".''; - echo _('Mobile number'); - echo ''."\n".''. - ''. - ''. - ''._('Help').''. - ''."\n".''; - echo _('Fax number'); - echo ''."\n".''. - ''. - ''. - ''._('Help').''. - ''."\n".''; - echo _('eMail address'); - echo ''."\n".''. - ''. - ''. - ''._('Help').''. - '
'; - echo ''; - echo ''; - break; - } - -// Print end of HTML-Page -echo ''; -?>