<?PHP
/******************************************************************************
 @Author:     Björn Brockmann, Paul Eppner (paul@twomoons.de)
			      Sven Bräutigam, Jürgen Brändle
 @Homepage    http://www.der-dirigent.de
******************************************************************************/

/******************************************************************************
 1. Benötigte Funktionen und Klassen includieren
******************************************************************************/

include('inc/fnc.user.php');

/******************************************************************************
 2. Eventuelle Actions/ Funktionen abarbeiten
******************************************************************************/

$perm->check('area_user');
switch($action) {
	case 'save':
		$errno = user_save();
		if (!$errno) {
			header ('Status: 302 Moved Temporarily');
			header ('Location:'.$sess->url("main.php?area=user&idgroup=$idgroup&order=$order&ascdesc=$ascdesc"));
			exit;
		}
		break;
}
/******************************************************************************
 3. Eventuelle Dateien zur Darstellung includieren
******************************************************************************/

include('inc/inc.header.php');

/******************************************************************************
 4. Bildschirmausgabe aufbereiten und ausgeben
******************************************************************************/

// Templatedatei laden
$tpl->loadTemplatefile('user_edit.tpl');
$tmp['AREA'] = $dedi_lang['area_user_edit'];
if (!empty($errno)) {
	$tpl -> setCurrentBlock('ERROR');
	$tpl_error['ERRORMESSAGE'] = $dedi_lang['err_'.$errno];
	$tpl->setVariable($tpl_error);
	$tpl->parseCurrentBlock();
}
// Tabellenformatierung
$tmp['CELLPADDING'] = $cellpadding;
$tmp['CELLSPACING'] = $cellspacing;
$tmp['BORDER'] = $border;
$tmp['LANG_USERNAME'] = $dedi_lang['user_loginname'];
$tmp['LANG_NAME'] = $dedi_lang['user_name'];
$tmp['LANG_SURNAME'] = $dedi_lang['user_surname'];
$tmp['LANG_NEWPASSWORD'] = $dedi_lang['user_newpassword'];
$tmp['LANG_NEWPASSWORDAGAIN'] = $dedi_lang['user_newpasswordagain'];
$tmp['LANG_EMAIL'] = $dedi_lang['user_email'];
$tmp['LANG_GROUP'] = $dedi_lang['user_group'];

// RF/symap: block start
$tmp['LANG_SALUTATION'] = $dedi_lang['user_salutation'];
$tmp['LANG_STREET'] = $dedi_lang['user_street'];
$tmp['LANG_STREET_ALT'] = $dedi_lang['user_street_alt'];
$tmp['LANG_ZIP'] = $dedi_lang['user_zip'];
$tmp['LANG_LOCATION'] = $dedi_lang['user_location'];
$tmp['LANG_STATE'] = $dedi_lang['user_state'];
$tmp['LANG_COUNTRY'] = $dedi_lang['user_country'];
$tmp['LANG_PHONE'] = $dedi_lang['user_phone'];
$tmp['LANG_FAX'] = $dedi_lang['user_fax'];
$tmp['LANG_MOBILE'] = $dedi_lang['user_mobile'];
$tmp['LANG_PAGER'] = $dedi_lang['user_pager'];
$tmp['LANG_HOMEPAGE'] = $dedi_lang['user_homepage'];
$tmp['LANG_BIRTHDAY'] = $dedi_lang['user_birthday'];

$tmp['LANG_FIRM'] = $dedi_lang['user_firm'];
$tmp['LANG_POSITION'] = $dedi_lang['user_position'];
$tmp['LANG_FIRM_STREET'] = $dedi_lang['user_firm_street'];
$tmp['LANG_FIRM_STREET_ALT'] = $dedi_lang['user_firm_street_alt'];
$tmp['LANG_FIRM_ZIP'] = $dedi_lang['user_firm_zip'];
$tmp['LANG_FIRM_LOCATION'] = $dedi_lang['user_firm_location'];
$tmp['LANG_FIRM_STATE'] = $dedi_lang['user_firm_state'];
$tmp['LANG_FIRM_COUNTRY'] = $dedi_lang['user_firm_country'];
$tmp['LANG_FIRM_EMAIL'] = $dedi_lang['user_firm_email'];
$tmp['LANG_FIRM_PHONE'] = $dedi_lang['user_firm_phone'];
$tmp['LANG_FIRM_FAX'] = $dedi_lang['user_firm_fax'];
$tmp['LANG_FIRM_MOBILE'] = $dedi_lang['user_firm_mobile'];
$tmp['LANG_FIRM_PAGER'] = $dedi_lang['user_firm_pager'];
$tmp['LANG_FIRM_HOMEPAGE'] = $dedi_lang['user_firm_homepage'];
// RF/symap: block end
$tmp['LANG_COMMENT'] = $dedi_lang['user_comment'];

// Formulareinstellungen
$tmp['FORM_URL'] = $sess->url('main.php');
if (!isset($username) && !empty($iduser)) {
// RF/symap: block start
	$sql = "SELECT username, name, surname, email, is_deletable, salutation, street, street_alt, zip, location, state, country, phone, fax, mobile, pager, homepage, birthday, firm, position, firm_street, firm_street_alt, firm_zip, firm_location, firm_state, firm_country, firm_email, firm_phone, firm_fax, firm_mobile, firm_pager, firm_homepage, comment FROM ".$dedi_db['users']." WHERE user_id='$iduser' LIMIT 0, 1";
// RF/symap: block end
	$db->query($sql);
	$db->next_record();
	$tmp['FORM_OLDUSERNAME'] = htmlspecialchars($db->f('username'));
	$tmp['FORM_USERNAME'] = htmlspecialchars($db->f('username'));
	$tmp['FORM_NAME'] = htmlspecialchars($db->f('name'));
	$tmp['FORM_SURNAME'] = htmlspecialchars($db->f('surname'));
	$tmp['FORM_EMAIL'] = htmlspecialchars($db->f('email'));
// RF/symap: block start
	$tmp['FORM_SALUTATION'] = htmlspecialchars($db->f('salutation'));
	$tmp['FORM_STREET'] = htmlspecialchars($db->f('street'));
	$tmp['FORM_STREET_ALT'] = htmlspecialchars($db->f('street_alt'));
	$tmp['FORM_ZIP'] = htmlspecialchars($db->f('zip'));
	$tmp['FORM_LOCATION'] = htmlspecialchars($db->f('location'));
	$tmp['FORM_STATE'] = htmlspecialchars($db->f('state'));
	$tmp['FORM_COUNTRY'] = htmlspecialchars($db->f('country'));
	$tmp['FORM_PHONE'] = htmlspecialchars($db->f('phone'));
	$tmp['FORM_FAX'] = htmlspecialchars($db->f('fax'));
	$tmp['FORM_MOBILE'] = htmlspecialchars($db->f('mobile'));
	$tmp['FORM_PAGER'] = htmlspecialchars($db->f('pager'));
	$tmp['FORM_HOMEPAGE'] = htmlspecialchars($db->f('homepage'));
	$tmp['FORM_BIRTHDAY'] = htmlspecialchars($db->f('birthday'));
	$tmp['FORM_FIRM'] = htmlspecialchars($db->f('firm'));
	$tmp['FORM_POSITION'] = htmlspecialchars($db->f('position'));
	$tmp['FORM_FIRM_STREET'] = htmlspecialchars($db->f('firm_street'));
	$tmp['FORM_FIRM_STREET_ALT'] = htmlspecialchars($db->f('firm_street_alt'));
	$tmp['FORM_FIRM_ZIP'] = htmlspecialchars($db->f('firm_zip'));
	$tmp['FORM_FIRM_LOCATION'] = htmlspecialchars($db->f('firm_location'));
	$tmp['FORM_FIRM_STATE'] = htmlspecialchars($db->f('firm_state'));
	$tmp['FORM_FIRM_COUNTRY'] = htmlspecialchars($db->f('firm_country'));
	$tmp['FORM_FIRM_EMAIL'] = htmlspecialchars($db->f('firm_email'));
	$tmp['FORM_FIRM_PHONE'] = htmlspecialchars($db->f('firm_phone'));
	$tmp['FORM_FIRM_FAX'] = htmlspecialchars($db->f('firm_fax'));
	$tmp['FORM_FIRM_MOBILE'] = htmlspecialchars($db->f('firm_mobile'));
	$tmp['FORM_FIRM_PAGER'] = htmlspecialchars($db->f('firm_pager'));
	$tmp['FORM_FIRM_HOMEPAGE'] = htmlspecialchars($db->f('firm_homepage'));
// RF/symap: block end
	$tmp['FORM_COMMENT'] = htmlspecialchars($db->f('comment'));
	$deletable = $db->f('is_deletable');
	$tmp['FORM_DELETABLE'] = $deletable;

	// zugehörige Gruppen suchen
	$sql = "SELECT idgroup FROM ".$dedi_db['users_groups']." WHERE user_id='$iduser'";
	$db->query($sql);
	while ($db->next_record()) $group[] = $db->f('idgroup');
} else {
	remove_magic_quotes_gpc($username);
	remove_magic_quotes_gpc($name);
	remove_magic_quotes_gpc($surname);
	remove_magic_quotes_gpc($email);
	remove_magic_quotes_gpc($password);
// RF/symap: block start
	remove_magic_quotes_gpc($salutation);
	remove_magic_quotes_gpc($street);
	remove_magic_quotes_gpc($street_alt);
	remove_magic_quotes_gpc($zip);
	remove_magic_quotes_gpc($location);
	remove_magic_quotes_gpc($state);
	remove_magic_quotes_gpc($country);
	remove_magic_quotes_gpc($phone);
	remove_magic_quotes_gpc($fax);
	remove_magic_quotes_gpc($mobile);
	remove_magic_quotes_gpc($pager);
	remove_magic_quotes_gpc($homepage);
	remove_magic_quotes_gpc($birthday);
	remove_magic_quotes_gpc($firm);
	remove_magic_quotes_gpc($position);
	remove_magic_quotes_gpc($firm_street);
	remove_magic_quotes_gpc($firm_street_alt);
	remove_magic_quotes_gpc($firm_zip);
	remove_magic_quotes_gpc($firm_location);
	remove_magic_quotes_gpc($firm_state);
	remove_magic_quotes_gpc($firm_country);
	remove_magic_quotes_gpc($firm_email);
	remove_magic_quotes_gpc($firm_phone);
	remove_magic_quotes_gpc($firm_fax);
	remove_magic_quotes_gpc($firm_mobile);
	remove_magic_quotes_gpc($firm_pager);
	remove_magic_quotes_gpc($firm_homepage);
// RF/symap: block end

	remove_magic_quotes_gpc($comment);
	$tmp['FORM_OLDUSERNAME'] = htmlspecialchars($oldusername);
	$tmp['FORM_USERNAME'] = htmlspecialchars($username);
	$tmp['FORM_PASSWORD'] = htmlspecialchars($password);
	$tmp['FORM_PASSWORDVALIDATE'] = htmlspecialchars($password_validate);
	$tmp['FORM_NAME'] = htmlspecialchars($name);
	$tmp['FORM_SURNAME'] = htmlspecialchars($surname);
	$tmp['FORM_EMAIL'] = htmlspecialchars($email);
	$tmp['FORM_DELETABLE'] = $deletable;
// RF/symap: block start
	$tmp['FORM_SALUTATION'] = $salutation;
	$tmp['FORM_STREET'] = $street;
	$tmp['FORM_STREET_ALT'] = $street_alt;
	$tmp['FORM_ZIP'] = $zip;
	$tmp['FORM_LOCATION'] = $location;
	$tmp['FORM_STATE'] = $state;
	$tmp['FORM_COUNTRY'] = $country;
	$tmp['FORM_PHONE'] = $phone;
	$tmp['FORM_FAX'] = $fax;
	$tmp['FORM_MOBILE'] = $mobile;
	$tmp['FORM_PAGER'] = $pager;
	$tmp['FORM_HOMEPAGE'] = $homepage;
	$tmp['FORM_BIRTHDAY'] = $birthday;
	$tmp['FORM_FIRM'] = $firm;
	$tmp['FORM_POSITION'] = $position;
	$tmp['FORM_FIRM_STREET'] = $firm_street;
	$tmp['FORM_FIRM_STREET_ALT'] = $firm_street_alt;
	$tmp['FORM_FIRM_ZIP'] = $firm_zip;
	$tmp['FORM_FIRM_LOCATION'] = $firm_location;
	$tmp['FORM_FIRM_STATE'] = $firm_state;
	$tmp['FORM_FIRM_COUNTRY'] = $firm_country;
	$tmp['FORM_FIRM_EMAIL'] = $firm_phone;
	$tmp['FORM_FIRM_PHONE'] = $firm_phone;
	$tmp['FORM_FIRM_FAX'] = $firm_fax;
	$tmp['FORM_FIRM_MOBILE'] = $firm_mobile;
	$tmp['FORM_FIRM_PAGER'] = $firm_pager;
	$tmp['FORM_FIRM_HOMEPAGE'] = $firm_homepage;
// RF/symap: block end

	$tmp['FORM_COMMENT'] = $comment;
}
if (!is_array($group)) $group['0'] = $idgroup;
$tmp['FORM_ABORT'] = '<a href="'.$sess->url("main.php?area=user&idgroup=$idgroup&order=$order&ascdesc=$ascdesc").'" onMouseOver="on(\''.$dedi_lang['gen_abort'].'\');return true;" onMouseOut="off()" ;return true;"><img src="tpl/'.$cfg_dedi['skin'].'/img/but_cancel.gif" alt="'.$dedi_lang['gen_abort'].'" title="'.$dedi_lang['gen_abort'].'" width="21" height="21" border="0"></a>';
$tmp['IMGPATH'] = 'tpl/'.$cfg_dedi['skin'].'/img/';
$tmp['IDUSER'] = $iduser;
$tmp['IDGROUP'] = $idgroup;
$tmp['ORDER'] = $order;
$tmp['ASCDESC'] = $ascdesc;
$tpl->setVariable($tmp);
unset($tmp);

// Usergruppen auflisten
$tpl->setCurrentBlock('SELECT_SHOWLIST');
$sql = "SELECT idgroup, name, is_active, is_sys_admin FROM ".$dedi_db['groups']." ORDER BY name";
$db->query($sql);
while ($db->next_record()) {
	// Standardusergruppe ausblenden
	if ($db->f('idgroup') != '1' && $deletable != '0' || ($deletable == '0' && $db->f('idgroup') == $idgroup) || ($idgroup == '1' && $db->f('idgroup') != '3')) {
		$tmp['SHOWLIST_VALUE'] = $db->f('idgroup');
		$tmp['SHOWLIST_ENTRY'] = $db->f('name');
		if (in_array($db->f('idgroup'), $group)) $tmp['SHOWLIST_SELECTED'] = ' selected';
		$tmp['SHOWLIST_STYLE'] = ($db->f('is_sys_admin') == '1') ? ' style="color:darkgreen;"' : '';
		if (empty($tmp['SHOWLIST_STYLE']) && $db->f('is_active') == '0') $tmp['SHOWLIST_STYLE'] = ' style="color:red;"';
		$tpl->setVariable($tmp);
		$tpl->parseCurrentBlock();
		unset($tmp);
	}
}
?>