Location: PHPKode > projects > Redaxscript > includes/admin/users.php
<?php

/* admin users list */

function admin_users_list()
{
	hook(__FUNCTION__ . '_start');

	/* query users */

	$query = 'SELECT id, name, user, language, first, last, status FROM ' . PREFIX . 'users ORDER BY last DESC';
	$result = mysql_query($query);
	$num_rows = mysql_num_rows($result);

	/* collect listing output */

	$output = '<h2 class="title_content">' . l('users') . '</h2>';
	if (USERS_NEW == 1)
	{
		$output .= '<a class="field_button field_button_plus" href="' . REWRITE_STRING . 'admin/new/users"><span><span>' . l('user_new') . '</span></span></a>';
	}
	$output .= '<div class="wrapper_full"><table class="table_default table_admin">';
	$output .= '<thead><tr><th class="s2o3 column_first">' . l('name') . '</th><th class="s1o6 column_second">' . l('user') . '</th><th class="s1o6 column_last">' . l('session') . '</th></tr></thead>';
	$output .= '<tfoot><tr><td class="column_first">' . l('name') . '</td><td class="column_second">' . l('user') . '</td><td class="column_last">' . l('session') . '</td></tr></tfoot>';
	if ($result == '' || $num_rows == '')
	{
		$error = l('user_no') . l('point');
	}
	else if ($result)
	{
		$output .= '<tbody>';
		while ($r = mysql_fetch_assoc($result))
		{
			if ($r)
			{
				foreach ($r as $key => $value)
				{
					$$key = stripslashes($value);
				}
			}
			if ($status == 1)
			{
				$class_status = '';
			}
			else
			{
				$class_status = 'disabled';
			}

			/* collect table row */

			$output .= '<tr';
			if ($class_status)
			{
				$output .= ' class="' . $class_status . '"';
			}
			$output .= '><td class="column_first">';
			if ($language)
			{
				$output .= '<span class="icon_flag language_' . $language . '" title="' . l($language) . '">' . $language . '</span>';
			}
			$output .= $name;

			/* collect control output */

			if (USERS_EDIT == 1 || (USERS_DELETE == 1 && $id > 1))
			{
				$output .= '<ul class="list_admin_control">';
			}
			if (USERS_EDIT == 1)
			{
				if ($id > 1)
				{
					if ($status == 1)
					{
						$output .= '<li class="item_disable">' . anchor_element('internal', '', '', l('disable'), 'admin/disable/users/' . $id . '/' . TOKEN) . '</li>';
					}
					else if ($status == 0)
					{
						$output .= '<li class="item_enable">' . anchor_element('internal', '', '', l('enable'), 'admin/enable/users/' . $id . '/' . TOKEN) . '</li>';
					}
				}
				$output .= '<li class="item_edit">' . anchor_element('internal', '', '', l('edit'), 'admin/edit/users/' . $id) . '</li>';
			}
			if (USERS_DELETE == 1 && $id > 1)
			{
				$output .= '<li class="item_delete">' . anchor_element('internal', '', 'js_confirm', l('delete'), 'admin/delete/users/' . $id . '/' . TOKEN) . '</li>';
			}
			if (USERS_EDIT == 1 || (USERS_DELETE == 1 && $id > 1))
			{
				$output .= '</ul>';
			}

			/* collect premature output */

			$output .= '</td><td class="column_second">' . $user . '</td><td class="column_last">';
			if ($first == $last)
			{
				$output .= l('none');
			}
			else
			{
				$minute_ago = date('Y-m-d H:i:s', strtotime('-1 minute'));
				$day_ago = date('Y-m-d H:i:s', strtotime('-1 day'));
				if ($last > $minute_ago)
				{
					$output .= l('online');
				}
				else if ($last > $day_ago)
				{
					$time = date(s('time'), strtotime($last));
					$output .= l('today') . ' ' . l('at') . ' ' . $time;
				}
				else
				{
					$date = date(s('date'), strtotime($last));
					$output .= $date;
				}
			}
			$output .= '</td></tr>';
		}
		$output .= '</tbody>';
	}

	/* handle error */

	if ($error)
	{
		$output .= '<tbody><tr><td colspan="3">' . $error . '</td></tr></tbody>';
	}
	$output .= '</table></div>';
	echo $output;
	hook(__FUNCTION__ . '_end');
}

/* admin users form */

function admin_users_form()
{
	hook(__FUNCTION__ . '_start');

	/* define fields for existing user */

	if (ADMIN_PARAMETER == 'edit' && ID_PARAMETER)
	{
		/* query user */

		$query = 'SELECT * FROM ' . PREFIX . 'users WHERE id = ' . ID_PARAMETER;
		$result = mysql_query($query);
		$r = mysql_fetch_assoc($result);
		if ($r)
		{
			foreach ($r as $key => $value)
			{
				$$key = stripslashes($value);
			}
		}
		$wording_headline = $name;
		$wording_submit = l('save');
		$string = 'admin/process/users/' . $id;
	}

	/* else define fields for new user */

	else if (ADMIN_PARAMETER == 'new')
	{
		$status = 1;
		$groups = 0;
		$wording_headline = l('user_new');
		$wording_submit = l('create');
		$string = 'admin/process/users';
		$class_required = ' js_required field_required';
		$code_required = ' required="required"';
	}

	/* collect output */

	$output = '<h2 class="title_content">' . $wording_headline . '</h2>';

	/* collect tab menue output */

	$output .= '<ul class="js_list_tab_menue list_tab_menue">';
	$output .= '<li class="js_list_tab_menue_active list_tab_menue_active item_first">' . anchor_element('internal', '', '', l('user'), FULL_STRING . '#tab-1') . '</li>';
	$output .= '<li class="item_second">' . anchor_element('internal', '', '', l('customize'), FULL_STRING . '#tab-2') . '</li></ul>';

	/* collect tab box output */

	$output .= form_element('form', 'admin_form_users', 'js_check_required js_note_required form_admin hidden_legend', '', '', '', 'action="' . REWRITE_STRING . $string . '" method="post"');
	$output .= '<div class="js_box_tab_menue box_tab_menue">';

	/* collect user set */

	$output .= form_element('fieldset', 'tab-1', 'js_box_tab_menue_inner box_tab_menue_inner', '', '', l('user')) . '<ul>';
	$output .= '<li>' . form_element('text', 'name', 'js_required field_text field_required', 'name', $name, l('name'), 'maxlength="50" required="required" autofocus="autofocus"') . '</li>';
	if ($id == '')
	{
		$output .= '<li>' . form_element('text', 'user', 'js_required field_text field_required', 'user', $user, l('user'), 'maxlength="10" required="required"') . '</li>';
	}
	$output .= '<li>' . form_element('text', 'password', 'field_text' . $class_required, 'password', '', l('password'), 'maxlength="10"' . $code_required) . '</li>';
	$output .= '<li>' . form_element('text', 'password_confirm', 'field_text' . $class_required, 'password_confirm', '', l('password_confirm'), 'maxlength="10"' . $code_required) . '</li>';
	$output .= '<li>' . form_element('email', 'email', 'js_required field_text field_required', 'email', $email, l('email'), 'maxlength="50" required="required"') . '</li>';
	$output .= '<li>' . form_element('textarea', 'description', 'js_auto_resize field_textarea_small', 'description', $description, l('description'), 'rows="1" cols="15"') . '</li>';
	$output .= '</ul></fieldset>';

	/* collect customize set */

	$output .= form_element('fieldset', 'tab-2', 'js_box_tab_menue_inner box_tab_menue_inner', '', '', l('customize')) . '<ul>';

	/* build languages select */

	$language_array[l('select')] = '';
	$languages_directory = read_directory('languages', 'misc.php');
	foreach ($languages_directory as $value)
	{
		$value = substr($value, 0, 2);
		$language_array[l($value)] = $value;
	}
	$output .= '<li>' . select_element('language', 'field_select', 'language', $language_array, $language, l('language')) . '</li>';
	if ($id == '' || $id > 1)
	{
		$output .= '<li>' . select_element('status', 'field_select', 'status', array(
			l('enable') => 1,
			l('disable') => 0
		), $status, l('status')) . '</li>';

		/* build groups select */

		if (GROUPS_EDIT == 1 && USERS_EDIT == 1)
		{
			$groups_query = 'SELECT * FROM ' . PREFIX . 'groups ORDER BY name ASC';
			$groups_result = mysql_query($groups_query);
			if ($groups_result)
			{
				while ($g = mysql_fetch_assoc($groups_result))
				{
					$groups_array[$g['name']] = $g['id'];
				}
			}
			$output .= '<li>' . select_element('groups', 'field_select field_multiple', 'groups', $groups_array, $groups, l('groups'), 'multiple="multiple"') . '</li>';
		}
	}
	$output .= '</ul></fieldset></div>';

	/* collect premature output */

	if ($id)
	{
		$output .= form_element('hidden', '', '', 'user', $user);
	}
	$output .= form_element('hidden', '', '', 'token', TOKEN);

	/* cancel button */

	if (USERS_EDIT == 1 || USERS_DELETE == 1)
	{
		$cancel_string = 'admin/view/users';
	}
	else
	{
		$cancel_string = 'admin';
	}
	$output .= '<a class="field_button_large field_button_backward" href="' . REWRITE_STRING . $cancel_string . '"><span><span>' . l('cancel') . '</span></span></a>';

	/* delete button */

	if ((USERS_DELETE == 1 || USERS_EXCEPTION == 1) && $id > 1)
	{
		$output .= '<a class="js_confirm field_button_large" href="' . REWRITE_STRING . 'admin/delete/users/' . $id . '/' . TOKEN . '"><span><span>' . l('delete') . '</span></span></a>';
	}

	/* submit button */

	if (USERS_NEW == 1 || USERS_EDIT == 1 || USERS_EXCEPTION == 1)
	{
		$output .= form_element('button', '', 'js_submit field_button_large field_button_forward', ADMIN_PARAMETER, $wording_submit);
	}
	$output .= '</form>';
	echo $output;
	hook(__FUNCTION__ . '_end');
}
?>
Return current item: Redaxscript