implemented loading/saving of profiles

This commit is contained in:
Roland Gruber 2004-03-15 16:34:16 +00:00
parent 62f394d10a
commit 38fbdb057d
2 changed files with 120 additions and 399 deletions

View File

@ -24,7 +24,7 @@ $Id$
*/
include_once("../../lib/status.inc");
include_once("../../lib/account.inc");
include_once("../../lib/modules.inc");
include_once("../../lib/profiles.inc");
include_once("../../lib/ldap.inc");
include_once("../../lib/config.inc");
@ -53,344 +53,65 @@ echo $_SESSION['header'];
echo "<title></title>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">\n";
echo "</head>\n<body>\n<br>\n";
// save user profile
if ($_GET['type'] == "user") {
$acct = new account();
// check input
if ($_POST['general_group'] && eregi("^[a-z]([a-z0-9_\\-])*$", $_POST['general_group'])) {
$acct->general_group = $_POST['general_group'];
}
else {
StatusMessage("ERROR", _("Primary group name is invalid!"), $_POST['general_group']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
// create option array to check and save
$options = array();
$opt_keys = array_keys($_SESSION['profile_types']);
foreach ($opt_keys as $element) {
// text fields
if ($_SESSION['profile_types'][$element] == "text") {
$options[$element] = array($_POST[$element]);
}
if ($_POST['general_groupadd']) {
$acct->general_groupadd = $_POST['general_groupadd'];
// checkboxes
elseif ($_SESSION['profile_types'][$element] == "checkbox") {
if ($_POST[$element] == "checked") $options[$element] = array(true);
else $options[$element] = array(false);
}
if ($_POST['general_homedir'] && eregi("^[/]([a-z0-9])+([/][a-z0-9_\\-\\$]+)*$", $_POST['general_homedir'])) {
$acct->general_homedir = $_POST['general_homedir'];
// dropdownbox
elseif ($_SESSION['profile_types'][$element] == "select") {
$options[$element] = array($_POST[$element]);
}
elseif ($_POST['general_homedir']) {
StatusMessage("ERROR", _("Homedir is invalid!"), $_POST['general_homedir']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
// multiselect
elseif ($_SESSION['profile_types'][$element] == "multiselect") {
$options[$element] = $_POST[$element]; // value is already an array
}
if ($_POST['general_shell'] && eregi("^[/]([a-z])+([/][a-z]+)*$", $_POST['general_shell'])) {
$acct->general_shell = $_POST['general_shell'];
}
else {
StatusMessage("ERROR", _("Shell is invalid!"), $_POST['general_shell']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (($_POST['unix_password_no'] == "1") || ($_POST['unix_password_no'] == "0")) {
$acct->unix_password_no = $_POST['unix_password_no'];
}
else {
StatusMessage("ERROR", _("Wrong parameter for login disable!"), $_POST['unix_password_no']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['unix_pwdwarn'] && is_numeric($_POST['unix_pwdwarn'])) {
$acct->unix_pwdwarn = $_POST['unix_pwdwarn'];
}
elseif ($_POST['unix_pwdwarn']) {
StatusMessage("ERROR", _("Wrong parameter for Unix password warning!"), $_POST['unix_pwdwarn']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['unix_pwdminage'] && is_numeric($_POST['unix_pwdminage'])) {
$acct->unix_pwdminage = $_POST['unix_pwdminage'];
}
elseif ($_POST['unix_pwdminage']) {
StatusMessage("ERROR", _("Password minimum age is not numeric!"), $_POST['unix_pwdminage']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['unix_pwdmaxage'] && is_numeric($_POST['unix_pwdmaxage'])) {
$acct->unix_pwdmaxage = $_POST['unix_pwdmaxage'];
}
elseif ($_POST['unix_pwdmaxage']) {
StatusMessage("ERROR", _("Password maximum age is not numeric!"), $_POST['unix_pwdmaxage']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (is_numeric($_POST['unix_pwdexpire_day']) && is_numeric($_POST['unix_pwdexpire_mon']) && is_numeric($_POST['unix_pwdexpire_yea'])) {
$acct->unix_pwdexpire = mktime(0, 0, 0, $_POST['unix_pwdexpire_mon'], $_POST['unix_pwdexpire_day'], $_POST['unix_pwdexpire_yea']);
}
else {
StatusMessage("ERROR", _("Wrong parameter for Unix password expiry!"));
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['unix_host'] && eregi("^[a-z0-9]+(,[a-z0-9]+)*$", $_POST['unix_host'])) {
$acct->unix_host = $_POST['unix_host'];
}
elseif ($_POST['unix_host']) {
StatusMessage("ERROR", _("Unix workstations are invalid!"), $_POST['unix_host']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (($_POST['unix_deactivated'] == "1") || ($_POST['unix_deactivated'] == "0")) {
$acct->unix_deactivated = $_POST['unix_deactivated'];
}
else {
StatusMessage("ERROR", _("Wrong parameter for Unix account activation!"), $_POST['unix_deactivated']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['unix_pwdallowlogin'] && is_numeric($_POST['unix_pwdallowlogin'])) {
$acct->unix_pwdallowlogin = $_POST['unix_pwdallowlogin'];
}
elseif ($_POST['unix_pwdallowlogin']) {
StatusMessage("ERROR", _("Password expiry is not numeric!"), $_POST['unix_pwdallowlogin']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (($_POST['smb_password_no'] == "1") || ($_POST['smb_password_no'] == "0")) {
$acct->smb_flags['N'] = $_POST['smb_password_no'];
}
else {
StatusMessage("ERROR", _("Wrong parameter for Samba option: Set Samba Password!"), $_POST['smb_password_no']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (($_POST['smb_useunixpwd'] == "1") || ($_POST['smb_useunixpwd'] == "0")) {
$acct->smb_useunixpwd = $_POST['smb_useunixpwd'];
}
else {
StatusMessage("ERROR", _("Wrong parameter for Samba option: Set Unix Password for Samba!"), $_POST['smb_useunixpwd']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (($_POST['smb_flagsD'] == "1") || ($_POST['smb_flagsD'] == "0")) {
$acct->smb_flags['D'] = $_POST['smb_flagsD'];
}
else {
StatusMessage("ERROR", _("Wrong parameter for Samba option: Account does not expire!"), $_POST['smb_flagsD']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (($_POST['smb_flagsX'] == "1") || ($_POST['smb_flagsX'] == "0")) {
$acct->smb_flags['X'] = $_POST['smb_flagsX'];
}
else {
StatusMessage("ERROR", _("Wrong parameter for Samba option: Account is disabled!"), $_POST['smb_flagsX']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['smb_homedrive'] && ereg("^[D-Z]:$", $_POST['smb_homedrive'])) {
$acct->smb_homedrive = $_POST['smb_homedrive'];
}
else {
StatusMessage("ERROR", _("Wrong parameter for Samba option: home drive!"), $_POST['smb_homedrive']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
// replace double \'s with \
$_POST['smb_smbhome'] = str_replace('\\\\', '\\', $_POST['smb_smbhome']);
if ($_POST['smb_smbhome'] && eregi("^[\][\]([a-z0-9])+([\][a-z0-9_\\-\\$%]+)+$", $_POST['smb_smbhome'])) {
$acct->smb_smbhome = $_POST['smb_smbhome'];
}
elseif ($_POST['smb_smbhome']) {
StatusMessage("ERROR", _("Samba home directory is invalid!"), $_POST['smb_smbhome']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
// replace double \'s with \
$_POST['smb_profilepath'] = str_replace('\\\\', '\\', $_POST['smb_profilepath']);
if ($_POST['smb_profilepath'] && eregi("^[\][\]([a-z0-9])+([\][a-z0-9_\\-\\$%]+)+$", $_POST['smb_profilepath'])) {
$acct->smb_profilePath = $_POST['smb_profilepath'];
}
elseif ($_POST['smb_profilepath']) {
StatusMessage("ERROR", _("Profile path is invalid!"), $_POST['smb_profilepath']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
// replace double \'s with \
$_POST['smb_scriptPath'] = str_replace('\\\\', '\\', $_POST['smb_scriptPath']);
if ($_POST['smb_scriptPath'] && is_string($_POST['smb_scriptPath'])) {
$acct->smb_scriptPath = $_POST['smb_scriptPath'];
}
elseif ($_POST['smb_scriptPath']) {
StatusMessage("ERROR", _("Script path is invalid!"), $_POST['smb_scriptPath']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['smb_smbuserworkstations'] && eregi("^[a-z0-9\\.\\-_]+( [a-z0-9\\.\\-_]+)*$", $_POST['smb_smbuserworkstations'])) {
$acct->smb_smbuserworkstations = $_POST['smb_smbuserworkstations'];
}
elseif ($_POST['smb_smbuserworkstations']) {
StatusMessage("ERROR", _("Samba workstations are invalid!"), $_POST['smb_smbuserworkstations']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['smb_domain'] && is_string($_POST['smb_domain'])) {
$acct->smb_domain = $_POST['smb_domain'];
}
elseif ($_POST['smb_domain']) {
StatusMessage("ERROR", _("Domain name is invalid!"), $_POST['smb_domain']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
// check quota settings if script is given
if ($_SESSION['config']->get_scriptPath()) {
if ($_POST['quotacount'] && ($_POST['quotacount'] > 0)) {
for ($i = 0; $i < $_POST['quotacount']; $i++) {
$acct->quota[$i][0] = $_POST['f_quota_'.$i.'_0'];
$acct->quota[$i][2] = $_POST['f_quota_'.$i.'_2'];
$acct->quota[$i][3] = $_POST['f_quota_'.$i.'_3'];
$acct->quota[$i][6] = $_POST['f_quota_'.$i.'_6'];
$acct->quota[$i][7] = $_POST['f_quota_'.$i.'_7'];
// Check if values are OK
if (!ereg('^([0-9])+$', $acct->quota[$i][2])) {
StatusMessage('ERROR', _('Block soft quota'), _('Block soft quota contains invalid characters. Only natural numbers are allowed'));
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (!ereg('^([0-9])+$', $acct->quota[$i][3])) {
StatusMessage('ERROR', _('Block hard quota'), _('Block hard quota contains invalid characters. Only natural numbers are allowed'));
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (!ereg('^([0-9])+$', $acct->quota[$i][6])) {
StatusMessage('ERROR', _('Inode soft quota'), _('Inode soft quota contains invalid characters. Only natural numbers are allowed'));
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (!ereg('^([0-9])+$', $acct->quota[$i][7])) {
StatusMessage('ERROR', _('Inode hard quota'), _('Inode hard quota contains invalid characters. Only natural numbers are allowed'));
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
}
}
}
if ($_POST['profname'] && eregi("^[0-9a-z_\\-]+$", $_POST['profname'])) {
$profname = $_POST['profname'];
}
else {
StatusMessage("ERROR", _("Invalid profile name!"), $_POST['profname']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
// save profile
if (saveUserProfile($acct, $profname)) {
StatusMessage("INFO", _("Profile was saved."), $profname);
}
else StatusMessage("ERROR", _("Unable to save profile!"), $profname);
echo ("<br><p><a href=\"profilemain.php\">" . _("Back to Profile Editor") . "</a></p>");
}
// save group profile
elseif ($_GET['type'] == "group") {
$acct = new account();
// check input
if ($_POST['smb_domain'] && is_string($_POST['smb_domain'])) {
$acct->smb_domain = $_POST['smb_domain'];
}
elseif ($_POST['smb_domain']) {
StatusMessage("ERROR", _("Domain name is invalid!"), $_POST['smb_domain']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
// check quota settings if script is given
if ($_SESSION['config']->get_scriptPath()) {
if ($_POST['quotacount'] && ($_POST['quotacount'] > 0)) {
for ($i = 0; $i < $_POST['quotacount']; $i++) {
$acct->quota[$i][0] = $_POST['f_quota_'.$i.'_0'];
$acct->quota[$i][2] = $_POST['f_quota_'.$i.'_2'];
$acct->quota[$i][3] = $_POST['f_quota_'.$i.'_3'];
$acct->quota[$i][6] = $_POST['f_quota_'.$i.'_6'];
$acct->quota[$i][7] = $_POST['f_quota_'.$i.'_7'];
// Check if values are OK
if (!ereg('^([0-9])+$', $acct->quota[$i][2])) {
StatusMessage('ERROR', _('Block soft quota'), _('Block soft quota contains invalid characters. Only natural numbers are allowed'));
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (!ereg('^([0-9])+$', $acct->quota[$i][3])) {
StatusMessage('ERROR', _('Block hard quota'), _('Block hard quota contains invalid characters. Only natural numbers are allowed'));
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (!ereg('^([0-9])+$', $acct->quota[$i][6])) {
StatusMessage('ERROR', _('Inode soft quota'), _('Inode soft quota contains invalid characters. Only natural numbers are allowed'));
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if (!ereg('^([0-9])+$', $acct->quota[$i][7])) {
StatusMessage('ERROR', _('Inode hard quota'), _('Inode hard quota contains invalid characters. Only natural numbers are allowed'));
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
}
// check options
$errors = checkProfileOptions($_POST['accounttype'], $options);
// print error messages if any
if (sizeof($errors) > 0) {
for ($i = 0; $i < sizeof($errors); $i++) {
if (sizeof($errors[$i]) > 3) { // messages with additional variables
StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2], $errors[$i][3]);
}
else {
StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2]);
}
}
if ($_POST['profname'] && eregi("^[0-9a-z_\\-]+$", $_POST['profname'])) {
$profname = $_POST['profname'];
}
else {
StatusMessage("ERROR", _("Invalid profile name!"), $_POST['profname']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
// save profile
if (savegroupProfile($acct, $profname)) {
StatusMessage("INFO", _("Profile was saved."), $profname);
}
else StatusMessage("ERROR", _("Unable to save profile!"), $profname);
echo ("<br><p><a href=\"profilemain.php\">" . _("Back to Profile Editor") . "</a></p>");
}
// save host profile
elseif ($_GET['type'] == "host") {
$acct = new account();
// check input
if ($_POST['general_group'] && eregi("^[a-z]([a-z0-9_\\-])*$", $_POST['general_group'])) {
$acct->general_group = $_POST['general_group'];
}
else {
StatusMessage("ERROR", _("Primary group name is invalid!"), $_POST['general_group']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['smb_domain'] && is_string($_POST['smb_domain'])) {
$acct->smb_domain = $_POST['smb_domain'];
}
elseif ($_POST['smb_domain']) {
StatusMessage("ERROR", _("Domain name is invalid!"), $_POST['smb_domain']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
if ($_POST['profname'] && eregi("^[0-9a-z_\\-]+$", $_POST['profname'])) {
$profname = $_POST['profname'];
}
else {
StatusMessage("ERROR", _("Invalid profile name!"), $_POST['profname']);
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
else { // input data is valid, save profile
// save profile
if (saveHostProfile($acct, $profname)) {
echo StatusMessage("INFO", _("Profile was saved."), $profname);
if ($_POST['accounttype'] == "user") {
if (saveUserProfile($options, $_POST['profname'])) {
echo StatusMessage("INFO", _("Profile was saved."), $profname);
}
else StatusMessage("ERROR", _("Unable to save profile!"), $profname);
}
elseif ($_POST['accounttype'] == "group") {
if (saveGroupProfile($options, $_POST['profname'])) {
echo StatusMessage("INFO", _("Profile was saved."), $profname);
}
else StatusMessage("ERROR", _("Unable to save profile!"), $profname);
}
elseif ($_POST['accounttype'] == "host") {
if (saveHostProfile($options, $_POST['profname'])) {
echo StatusMessage("INFO", _("Profile was saved."), $profname);
}
else StatusMessage("ERROR", _("Unable to save profile!"), $profname);
}
echo ("<br><p><a href=\"profilemain.php\">" . _("Back to Profile Editor") . "</a></p>");
}
// error: no or wrong type
else StatusMessage("ERROR", "", _("No type specified!"));
echo ("</body></html>\n");
?>

View File

@ -56,7 +56,7 @@ if (!(($type == 'user') || ($type == 'group') || ($type == 'host'))) meta_refres
$options = getProfileOptions($type);
// load old profile if needed
$old_profile = array();
$old_options = array();
if ($_GET['edit']) {
if ($type == "user") $old_options = loadUserProfile($_GET['edit']);
else if ($type == "group") $old_options = loadGroupProfile($_GET['edit']);
@ -78,7 +78,7 @@ for ($m = 0; $m < sizeof($modules); $m++) {
echo "<tr>\n";
for ($o = 0; $o < sizeof($options[$modules[$m]][$l]); $o++) { // line parts
echo "<td>";
print_option($options[$modules[$m]][$l][$o], $modules[$m], $old_profile);
print_option($options[$modules[$m]][$l][$o], $modules[$m], $old_options);
echo "</td>\n";
}
echo "</tr>\n";
@ -105,89 +105,89 @@ echo ("<input type=\"submit\" name=\"abort\" value=\"" . _("Abort") . "\"></td>\
echo ("<td>&nbsp</td>");
echo ("</tr>\n");
echo ("</table>\n");
echo "<input type=\"hidden\" name=\"accounttype\" value=\"$type\">\n";
echo ("</form></body></html>\n");
// prints out the row of a table including the option name, values and help
// $values: An array formated as module option
// $module_name: The name of the module the options belong to
// $old_profile: A hash array with the values from the loaded profile
function print_option($values, $modulename, $old_profile) {
switch ($values['kind']) {
// text value
case 'text':
echo $values['text'] . "\n";
break;
// help link
case 'help':
echo "<a href=../help.php?module=$modulename&amp;module=" . $values['value'] . ">" . _('Help') . "</a>\n";
break;
// input field
case 'input':
if (($values['type'] == 'text') || ($values['type'] == 'checkbox')) {
if ($values['type'] == 'text') {
$output = "<input type=\"" . $values['type'] . "\" name=\"" . $values['name'] . "\"";
if ($values['size']) $output .= " size=\"" . $values['size'] . "\"";
if ($values['maxlength']) $output .= " maxlength=\"" . $values['maxlength'] . "\"";
if (isset($old_profile[$values['name']])) $output .= " value=\"" . $old_profile[$values['name']][0] . "\"";
elseif ($values['value']) $output .= " value=\"" . $values['value'] . "\"";
if ($values['disabled']) $output .= " disabled";
$output .= ">\n";
echo $output;
$_SESSION['profile_types'][$values['name']] = "text";
}
elseif ($values['type'] == 'checkbox') {
$output = "<input type=\"" . $values['type'] . "\" name=\"" . $values['name'] . "\"";
if ($values['size']) $output .= " size=\"" . $values['size'] . "\"";
if ($values['maxlength']) $output .= " maxlength=\"" . $values['maxlength'] . "\"";
if ($values['value']) $output .= " value=\"" . $values['value'] . "\"";
if ($values['disabled']) $output .= " disabled";
if (isset($old_profile[$values['name']]) && ($old_profile[$values['name']][0] == true)) $output .= " checked";
elseif ($values['checked']) $output .= " checked";
$output .= ">\n";
echo $output;
$_SESSION['profile_types'][$values['name']] = "checkbox";
}
}
break;
// select box
case 'select':
if ($values['multiple']) {
echo "<select name=\"" . $values['name'] . "[]\" size=\"" . $values['size'] . "\" multiple>\n";
$_SESSION['profile_types'][$values['name']] = "multiselect";
// $old_options: A hash array with the values from the loaded profile
function print_option($values, $modulename, $old_options) {
switch ($values['kind']) {
// text value
case 'text':
echo $values['text'] . "\n";
break;
// help link
case 'help':
echo "<a href=../help.php?module=$modulename&amp;module=" . $values['value'] . ">" . _('Help') . "</a>\n";
break;
// input field
case 'input':
if (($values['type'] == 'text') || ($values['type'] == 'checkbox')) {
if ($values['type'] == 'text') {
$output = "<input type=\"text\" name=\"" . $values['name'] . "\"";
if ($values['size']) $output .= " size=\"" . $values['size'] . "\"";
if ($values['maxlength']) $output .= " maxlength=\"" . $values['maxlength'] . "\"";
if (isset($old_options[$values['name']])) $output .= " value=\"" . $old_options[$values['name']][0] . "\"";
elseif ($values['value']) $output .= " value=\"" . $values['value'] . "\"";
if ($values['disabled']) $output .= " disabled";
$output .= ">\n";
echo $output;
$_SESSION['profile_types'][$values['name']] = "text";
}
elseif ($values['type'] == 'checkbox') {
$output = "<input type=\"checkbox\" name=\"" . $values['name'] . "\"";
if ($values['size']) $output .= " size=\"" . $values['size'] . "\"";
if ($values['maxlength']) $output .= " maxlength=\"" . $values['maxlength'] . "\"";
if ($values['disabled']) $output .= " disabled";
if (isset($old_options[$values['name']]) && ($old_options[$values['name']][0] == true)) $output .= " checked";
elseif ($values['checked']) $output .= " checked";
$output .= ">\n";
echo $output;
$_SESSION['profile_types'][$values['name']] = "checkbox";
}
}
break;
// select box
case 'select':
if ($values['multiple']) {
echo "<select name=\"" . $values['name'] . "[]\" size=\"" . $values['size'] . "\" multiple>\n";
$_SESSION['profile_types'][$values['name']] = "multiselect";
}
else {
echo "<select name=\"" . $values['name'] . "\" size=\"" . $values['size'] . "\">\n";
$_SESSION['profile_types'][$values['name']] = "select";
}
// option values
for ($i = 0; $i < sizeof($values['options']); $i++) {
// use values from old profile if given
if (isset($old_options[$values['name']])) {
if (in_array($values['options'][$i], $old_options[$values['name']])) {
echo "<option selected>" . $values['options'][$i] . "</option>\n";
}
else {
echo "<select name=\"" . $values['name'] . "\" size=\"" . $values['size'] . "\">\n";
$_SESSION['profile_types'][$values['name']] = "select";
echo "<option>" . $values['options'][$i] . "</option>\n";
}
// option values
for ($i = 0; $i < sizeof($values['options']); $i++) {
// use values from old profile if given
if (isset($old_profile[$values['name']])) {
if (in_array($values['options'][$i], $old_profile[$values['name']])) {
echo "<option selected>" . $values['options'][$i] . "</option>\n";
}
else {
echo "<option>" . $values['options'][$i] . "</option>\n";
}
}
// use default values if not in profile
else {
if (in_array($values['options'][$i], $values['options_selected'])) {
echo "<option selected>" . $values['options'][$i] . "</option>\n";
}
else {
echo "<option>" . $values['options'][$i] . "</option>\n";
}
}
}
// use default values if not in profile
else {
if (in_array($values['options'][$i], $values['options_selected'])) {
echo "<option selected>" . $values['options'][$i] . "</option>\n";
}
echo "</select>\n";
break;
// print error message for invalid types
default:
echo _("Unrecognized type") . ": " . $values['kind'] . "\n";
break;
else {
echo "<option>" . $values['options'][$i] . "</option>\n";
}
}
}
echo "</select>\n";
break;
// print error message for invalid types
default:
echo _("Unrecognized type") . ": " . $values['kind'] . "\n";
break;
}
}
?>