<tal:block metal:use-macro="python:here.getLayoutTool().getCurrentSkin().folder_administration_macro.macros['page']">

<h1 metal:fill-slot="title" i18n:translate="">User management</h1>

<tal:block metal:fill-slot="section"
		tal:define="site_url here/getSitePath;
					mode python:request.get('mode', '');
					user_tool here/getAuthenticationTool">

<tal:block tal:condition="python:mode==''">
	<div class="tabbedmenu">
	<ul>
		<li class="currenttab"><a tal:attributes="href string:${here/absolute_url}/administration_users_html" i18n:translate="">Local users</a></li>
		<li tal:repeat="item user_tool/getSources">
			<a tal:attributes="href string:${here/absolute_url}/administration_source_html?id=${item/id}" tal:content="item/title_or_id" i18n:translate="">source</a>
		</li>
	</ul>
	</div>
	<div class="cleaner"></div>
	<script type="text/javascript">
	function emptyLocation()
	{
	   if (document.forms['frmUsersRoles'].loc[0].checked == true)
		   document.forms['frmUsersRoles'].location.value = '';
	}

	function setupWin(url, theWidth, theHeight)
	{
	   wwinn=window.open(url,'wwinn','width='+theWidth+',height='+theHeight+',scrollbars,top=50,left=600');
	   wwinn.focus();
	   return true;
	}

	function createKey(key)
	{
	   document.forms['frmUsersRoles'].location.value = key;
	}
	</script>
	<p class="page-description" i18n:translate="">
		This page displays the existing users in the folder and their corresponding roles.
		You can revoke a role prior assigned to a user by ticking in the appropiate check box
		and clicking on the Revoke selected roles button.
	</p>

	<div class="form-buttons cleaner">
		<span class="buttons">
				<a tal:attributes="href string: ${site_url}/admin_adduser_html" title="Add new local user" i18n:attributes="title" i18n:translate="">Add user</a>
		</span>
	</div>

	<table class="datatable">
		<thead>
			<tr>
				<th width="10%" align="left" i18n:translate="">Username</th>
				<th width="30%" align="left" i18n:translate="">Name/Email</th>
				<th width="50%" align="left" i18n:translate="">Roles/Location</th>
				<th width="10%" i18n:translate="">Revoke roles</th>
			</tr>
		</thead>
		<tbody>
			<tr tal:define="users_roles here/getUsersRoles"
				tal:repeat="username users_roles/keys"
				tal:attributes="class python:test(path('repeat/username/odd'), 'zebraodd', 'zebraeven')">
				<tal:block define="user python:user_tool.getUser(username)">
				<td>
					<strong>
						<a tal:define="user_quoted python:here.utUrlEncode(username)"
              tal:attributes="href string:${site_url}/admin_edituser_html?name=${user_quoted}&from=local"
							tal:content="username">username</a>
					</strong>
				</td>
				<td>
					<div class="datatable-username">
						<tal:block replace="python:user_tool.getUserFirstName(user) + ' ' + user_tool.getUserLastName(user)"></tal:block>
					</div>
					<div class="datatable-email" tal:define="email python:user_tool.getUserEmail(user)">
						<a tal:attributes="href string:mailto:${email}; title string:Click to open email client" i18n:attributes="title" tal:content="email" />
					</div>
        </td>
        <td tal:define="roles python:users_roles[username]">
            <div class="user-role" tal:repeat="role roles">
                <tal:block condition="python: role[0]">
                <span class="roles-title" tal:content="python: ', '.join(role[0])"></span> in
                <a class="roles-location" tal:define="obj python: here.getSite().utGetObject(role[1])" tal:attributes="href obj/absolute_url" tal:content="obj/title_or_id"></a>
                </tal:block>
            </div>
            <tal:block condition="python: roles == [([], '')] ">-</tal:block>
        </td>
        <td tal:define="roles python: users_roles[username]">
            <div class="user-role-revoke" tal:repeat="role roles">
                <a class="revoke-role" i18n:attributes="title" title="Revoke role"
									  tal:condition="python: role[0]"
                    tal:define="location python: role[1]"
                    tal:attributes="href string:${site_url}/admin_revokerole?user=${username}&location=${location}">
                    <img src="/misc_/Naaya/revoke_permission.png" alt="Revoke role" i18n:attributes="alt" />
                </a>
            </div>
        </td>
				</tal:block>
			</tr>
		</tbody>
	</table>
	<br />

	<form method="post" name="frmUsersRoles" tal:attributes="action string:${here/absolute_url}/admin_folder_addroles">
	<fieldset><legend i18n:translate="">Assign role to existing user</legend>
	<p i18n:translate="">Select the username from the drop-down list, select the intended role(s) and choose the specific
	location from the folder you want to grant this permissions.</p>
	<table width="100%" border="0" cellspacing="2" cellpadding="6"
		tal:define="name python:request.get('name', '');
					roles python:here.utConvertToList(request.get('roles', []));
					location python:request.get('location', '')">
	<tr>
		<td align="top" width="20%" class="form-label" i18n:translate="">Username:</td>
		<td align="top" width="*" tal:define="users here/admin_getusers">
			<select name="name">
				<option tal:repeat="user users"
					tal:attributes="value user; selected python:user==name" tal:content="user" />
			</select>
		</td>
	</tr>
	<tr>
		<td align="top" width="20%" class="form-label" i18n:translate="">Roles:</td>
		<td align="top" width="*">
			<select name="roles" size="5" multiple="multiple">
				<tal:block repeat="role user_tool/list_valid_roles">
				<option tal:condition="python:role=='Manager' and request.AUTHENTICATED_USER.has_role('Manager')" tal:attributes="value role; selected python:role in roles" tal:content="role" />
				<option tal:condition="python:role!='Manager'" tal:attributes="value role; selected python:role in roles" tal:content="role" />
				</tal:block>
			</select>
		</td>
	</tr>
	<tr>
		<td valign="top" width="20%" class="form-label" i18n:translate="">Location:(folder)<br i18n:name="br" />e.g. /folderURL</td>
		<td valign="top" width="*">
			<script type="text/javascript">
			<!--
			function fTreeClick(expand)
			{
				document.frmUsersRoles.action = '';
				document.frmUsersRoles.expand.value = expand;
			}
			function fTreeNodeClick(node_path)
			{
				document.frmUsersRoles.location.value = node_path;
			}
			//-->
			</script>
			<tal:block tal:define="expand python:request.get('expand', '');
									expand_list python:here.splitToList(expand);
									tree python:here.getSiteMap(expand_list, here, 0)">
			<table border="0" cellspacing="1" cellpadding="1" width="100%">
			<tr tal:repeat="tree_node tree">
				<td>
					<table border="0" cellspacing="1" cellpadding="1">
						<tr>
							<td>
								<img tal:repeat="i python:range(0, tree_node[2])" src="misc_/Naaya/square.gif" alt="" />
								<tal:block tal:condition="python:tree_node[1]==-1">
									<img src="misc_/Naaya/square.gif" alt="" />
								</tal:block>
								<tal:block
									tal:define="node_expand python:here.processCollapse(expand_list, tree_node[0].absolute_url(1))"
									tal:condition="python:tree_node[1]==0">
									<input type="image" tal:attributes="onclick string:javascript:fTreeClick('${node_expand}')"
									src="misc_/Naaya/minus.gif" alt="Collapse node" />
								</tal:block>
								<tal:block
									tal:define="node_expand python:here.processExpand(expand_list, tree_node[0].absolute_url(1))"
									tal:condition="python:tree_node[1]==1">
									<input type="image" tal:attributes="onclick string:javascript:fTreeClick('${node_expand}')"
									src="misc_/Naaya/plus.gif" alt="Expand node" />
								</tal:block>
							</td>
							<td><img tal:attributes="src python:tree_node[0].icon" alt="" /></td>
							<td><a tal:define="node_path python:tree_node[0].absolute_url(1)" tal:attributes="href string:javascript:fTreeNodeClick('${node_path}')" tal:content="python:tree_node[0].title_or_id()">folder</a></td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<input type="text" name="location" tal:attributes="value location" size="35" readonly="readonly" />
					<input type="button" value="Pick" i18n:translate="" tal:define="acl_users_path user_tool/absolute_url" tal:attributes="onclick string:setupWin('${acl_users_path}/sitemap', 300, 500);;" />
				</td>
			</tr>
			</table>
			<input type="hidden" name="expand" tal:attributes="value expand">
			</tal:block>
		</td>
	</tr>
	<tr>
		<td class="cell-header"><input type="submit" name="add" i18n:attributes="value" value="Assign role" /></td>
		<td></td>
	</tr>
	</table>
	</fieldset>
	</form>
	</tal:block>
	<tal:block tal:condition="python:mode=='add'">
	<form name="frmAddUser" method="post" tal:attributes="action string:${here/absolute_url}/admin_adduser">
		<p i18n:translate="">Fill the form below with user's credentials and account and click on <em i18n:name="save-button" i18n:translate="">Save</em>:</p>
		<fieldset><legend i18n:translate="">Personal settings</legend>
		<table border="0" cellspacing="0" cellpadding="3" width="100%">
			<tr>
				<td nowrap="nowrap" i18n:translate="">First Name:</td>
				<td><input type="text" name="firstname" tal:attributes="value here/getSessionUserFirstname" size="35" maxLength="255" />
				</td>
			</tr>
			<tr>
				<td nowrap="nowrap" i18n:translate="">Last Name:</td>
				<td><input type="text" name="lastname" tal:attributes="value here/getSessionUserLastname" size="35" maxLength="255" />
				</td>
			</tr>
			<tr>
				<td nowrap="nowrap" i18n:translate="">Email address:</td>
				<td><input type="text" name="email" tal:attributes="value here/getSessionUserEmail" size="35" maxLength="255" />
				</td>
			</tr>
		</table>
		</fieldset>
		<br />

		<fieldset><legend><b i18n:translate="">User&nbsp;Settings</b></legend>
		<table border="0" cellspacing="0" cellpadding="3">
		<tr>
			<td i18n:translate="">Username:</td>
			<td><input type="text" name="name" size="30" tal:attributes="value here/getSessionUserName" maxLength="255" /></td>
		</tr>
		<tr>
			<td nowrap="nowrap" i18n:translate="">Password:</td>
			<td><input type="password" name="password" size="30" value="" maxLength="255" />
			</td>
		</tr>
		<tr>
			<td nowrap="nowrap" i18n:translate="">Password Verification:</td>
			<td><input type="password" name="confirm" value="" size="30" maxLength="255" />
			</td>
		</tr>
		</table>
		</fieldset>
		<br />

		<input type="submit" name="ActionButton" value="Save" class="button" />
		<input type="button" name="CancelButton" value="Cancel" class="button"
			   tal:attributes="onclick string:javascript:document.location.href='${here/absolute_url}/administration_users_html';" />
	</form>
	<span tal:content="python:here.delSessionErrors()" tal:omit-tag=""></span>
	<span tal:content="python:here.delUserSession()" tal:omit-tag=""></span>
	</tal:block>

	<tal:block condition="python:mode=='edit'">
		<tal:block define="user_info python:here.admin_getuser(request.get('name', ''));
							user_firstname python:user_info[0];
							user_lastname python:user_info[1];
							user_email python:user_info[2];
							user_account python:user_info[3];
							user_password python:user_info[4];
							user_roles python:user_info[5];
							user_created python:user_info[6];
							user_lastupdated python:user_info[7];">

		<div class="system-msg" tal:condition="python:request.has_key('save')">
			<tal:block i18n:translate="">Saved changes</tal:block>. (<span tal:replace="here/ZopeTime"/>)<br />
		</div>

		<form name="frmEditUser" method="post" tal:attributes="action string:${here/absolute_url}/admin_saveuser_credentials">
		<p i18n:translate="">Change the form below with user's credentials and account and click on <em i18n:name="save-button" i18n:translate="">Save</em>:</p>
		<fieldset><legend i18n:translate="">Personal settings</legend>
		<table border="0" cellspacing="0" cellpadding="3" width="100%">
			<tr>
				<td nowrap="nowrap" i18n:translate="">First name:</td>
				<td><input type="text" name="firstname" size="35" maxLength="255"
						tal:attributes="value python:here.getSessionUserFirstname(user_firstname)" />
				</td>
			</tr>
			<tr>
				<td nowrap="nowrap" i18n:translate="">Last name:</td>
				<td><input type="text" name="lastname" size="35" maxLength="255"
						tal:attributes="value python:here.getSessionUserLastname(user_lastname)" />
				</td>
			</tr>
			<tr>
				<td nowrap="nowrap" i18n:translate="">Email address:</td>
				<td><input type="text" name="email" size="35" maxLength="255" tal:attributes="value python:here.getSessionUserEmail(user_email)" />
				</td>
			</tr>
		</table>
		</fieldset>
		<br />

		<fieldset><legend i18n:translate="">User settings</legend>
		<table border="0" cellspacing="0" cellpadding="3">
			<tr>
				<td i18n:translate="">Username:</td>
				<td tal:content="user_account">username</td>
			</tr>
			<tr>
				<td i18n:translate="">Password:</td>
				<td><input type="password" name="password" maxLength="255" tal:attributes="value user_password" />
				</td>
			</tr>
			<tr>
				<td nowrap="nowrap" i18n:translate="">Password Verification:</td>
				<td><input type="password" name="confirm" maxLength="255" tal:attributes="value user_password" />
				</td>
			</tr>
		</table>
		</fieldset>
		<br />

		<input type="hidden" name="name" maxLength="255" tal:attributes="value user_account" />
		<input type="submit" name="ActionButton" value="Save" class="button" />
		<input type="button" name="CancelButton" value="Cancel" class="button"
		   tal:attributes="onclick string:javascript:document.location.href='${here/absolute_url}/administration_users_html';" />
		<br /><br />

		<fieldset><legend i18n:translate="">Record information</legend>
		<p>Created: <tal:block tal:content="python:test(user_created=='', ' - ', user_created)" /><br />
		   Last updated: <tal:block tal:content="python:test(user_lastupdated=='', ' - ', user_lastupdated)" /></p>
		</fieldset>
		</form>

		<span tal:content="python:here.delSessionErrors()" tal:omit-tag=""></span>
		<span tal:content="python:here.delUserSession()" tal:omit-tag=""></span>
		</tal:block>
	</tal:block>

</tal:block>

</tal:block>
