  [% META title = 'Admin &raquo; Email Contacts' -%]

<!-- BEGIN admin/config/emailcontacts/default.tt -->
	[% # PROCESS dumper.tt dump = c.config('msg') %]

	[% PROCESS site/autosuggest.tt varname = 'hospital' %]

	[% email_contacts_dfv_js %]

	[% meta_data = c.get_meta_data('EmailContact') %]

	[% # PROCESS admin/misc_nav.tt page = 'error-codes' %]

  <h2 align="center">Email Contacts</h2>

    [% IF dfv_errors %]
        <p class="error">[% c.config('msg').dfv_errors %]</p>
    [% END %]

	[% INCLUDE site/snippets/help.tt file = 'emailcontact' %]
	
    <p class="title">
		[% div_name = 'new'; INCLUDE site/snippets/toggleview.tt %]
		Add new entry
	</p>

	<div class="[% dfv_errors ? 'visible' : 'itemhidden' %]" id="[% div_name %]">
		<form method="post" action="[% app_url %]/config/email-contacts/update"
			[% email_contacts_onsubmit %] name="email-contact" id="email-contact">
		<div class="indent">
			<table>
				<tr>
					<td class="label">Display name:</td>
					<td class="content">
            <input type="text" name="display_name" value="" size="40" />
						[% error_display_name %]
 					</td>
				</tr>
				<tr>
					<td class="label">Scope:</td>
					<td class="content">
						<select name="scope">
						<option value=""></option>
						[% FOREACH item IN meta_data.column('scope').check_in %]
              <option value="[% item %]">[% item %]</option>
            [% END %]
						[% error_scope %]
 					</td>
				</tr>
				<tr>
					<td class="label">Location:</td>
					<td class="search_bar">
            <input style="width: 300px" type="text" id="location_name" name="_display_name"
              value="[% c.query.param('_display_name') %]"/>
            <input type="hidden" id="source_id" name="referral_source_id" />
              [% IF error_referral_source_id %]
                [% error_referral_source_id %]
              [% ELSE %]
                [ <a href="[% app_url %]/config/referral-sources">new</a> ]
              [% END %]
          </td>
				</tr>
				<tr>
					<td class="label">Type:</td>
					<td class="content">
						<select name="type" [% site.html.onfocus %]>
						<option value=""></option>
						[% FOREACH item IN meta_data.column('type').check_in %]
              <option value="[% item %]">[% item %]</option>
						[% END %]
						</select>
						[% error_type %]
 					</td>
				</tr>
				<tr>
					<td class="label">Email address:</td>
					<td class="content">
            <input type="text" name="contact_address" value="" size="50" />
						[% error_contact_address %]
 					</td>
				</tr>
				<tr>
					<td class="label">Active:</td>
					<td class="content">
						<select name="is_active" [% site.html.onfocus %]>
						[% FOREACH option IN ['yes', 'no'] %]
						 <option value="[% option %]">[% option %]</option>
						[% END %]
						</select>
						[% error_is_active %]
 					</td>
				</tr>
      </table>

			<p class="indent">[% site.html.submit %] [% site.html.reset %]</p>
		</div>
		</form>
	</div>

	<p class="spacer">&nbsp;</p>

	[% IF email_contacts.size # only empty if new db %]
	<div class="[% dfv_errors ? 'itemhidden' : 'visible' %]">
		<table>
			<tr>
				<th></th>
				<th>Display Name</th>
				<th>Scope</th>
				<th>Location</th>
				<th>Type</th>
				<th>Email Address</th>
				<th>Active</th>			
			</tr>

			[% FOREACH item IN email_contacts %][% # PROCESS dumper.tt dump = item %]
			<tr>
				<td>[% loop.count %]</td>
				<td>
					<input type="text" value="[% item.display_name | html %]"
						[% site.html.disabled %] />
				</td>
				<td>
					<input type="text" value="[% item.scope %]"	size="10" [% site.html.disabled %] />
				</td>
				<td>
					<input type="text" value="[% item.referral_source.display_name %]"
            [% site.html.disabled %] />
				</td>
				<td>
					<input type="text" value="[% item.type %]" size="5"	[% site.html.disabled %] />
				</td>
				<td>
					<input type="text" value="[% item.contact_address %]"	size="30"
              [% site.html.disabled %] />
				</td>
				<td>
					<select name="is_unique" [% site.html.disabled %]>
					[% FOREACH option IN ['yes', 'no'] %]
						 <option value="[% option %]" [% 'selected' IF option == item.is_active %]>
							[% option %]
						</option>
					[% END %]
					</select>
				</td>
				<td align="center">
					<a href="[% app_url %]/config/email-contacts/edit/[% item.id %]">Edit</a>
				</td>
			 </tr>
			[% END %]
		</table>
	</div>
	[% END %]
<!-- END admin/config/emailcontacts/default.tt -->
