<% my $projects = &subs::db_select('settings', undef, { setting => 't_project', device => &subs::device_setter(), value => $a }, { order_by => ($appts->{$a}->{'setting'}->{'m_project_sort'} || 'app') })->hashes; %>

<table style="width:100%;">
	<thead>
		<th>App</th>
		<th>Count</th>
		<th>
			<select class="app_setting" attribute="m_project_sort" onchange="appointmentGrabber('<%= $a %>','','onchange');">
				<% foreach my $s ( qw/app ost server_time timestamp/ ) { %>
					<option value="<%= $s %>" <% if ($s eq $appts->{$a}->{'setting'}->{'m_project_sort'}) { %> selected <% } %>><%= &subs::format_name($s) %></option>
				<% } %>
			</select>
		</th>
			
	</thead>
	<tbody style="border:solid;border-width:4px;border-radius:5px;">
		<% foreach my $proj ( @{$projects} ) { %>
			<% my $p_appts = &subs::db_select('appointments', undef, { app => $proj->{'app'} })->hashes; %>
			<tr>
				<td onclick="appointmentGrabber('<%= $proj->{'app'} %>');"><b><%= &subs::format_name($proj->{'app'}) %></td>
				<td><%= scalar @{$p_appts} %></td>
				<td>
					<select class="app_setting" attribute="t_project" style="max-width=50%;">
						<option selected="selected" value="<%= $a %>"><%= $appts->{$a}->{'formatted_name'} %></option>
						<% foreach my $ap (@{$appts->{'__projects'}}) { %>
							<option 
								value="<%= $ap->{'app'} %>"
								<% if ($a eq $ap->{'app'}) { %>
									selected
								<% } %>>
								<%= $ap->{'formatted_name'} %>
							</option>
						<% } %>
					</select>
				</td>
			</tr>
		<% } %>
	</tbody>
</table>
<label>Add to Project</label>
