{% include 'overall_header.html' %}

<a id="maincontent"></a>

{% if S_ADD_AD or S_EDIT_AD %}
	{% INCLUDECSS '@phpbb_ads/phpbbads.css' %}

	<a href="{{ U_BACK }}" style="float: {{ S_CONTENT_FLOW_END }};">&laquo; {{ lang('BACK') }}</a>

	<h1>{% if S_ADD_AD %}{{ lang('ACP_ADS_ADD') }}{% else %}{{ lang('ACP_ADS_EDIT') }}{% endif %}</h1>

	{% if PREVIEW %}
		<fieldset>
			<legend>{{ lang('PREVIEW') }}</legend>
			{% set PHPBB_ADS_CODE, S_PHPBB_ADS_CENTER = PREVIEW, AD_CENTERING %}
			{% include '@phpbb_ads/phpbb_ads_default.html' %}
		</fieldset>
	{% endif %}

	{% if S_ERROR %}
		<div class="errorbox">
			<h3>{{ lang('WARNING') }}</h3>
			<p>{{ ERROR_MSG }}</p>
		</div>
	{% endif %}

	<form id="acp_admanagement_add" method="post" action="{{ U_ACTION }}" enctype="multipart/form-data">
		<fieldset>
			<legend>{{ lang('AD_SETTINGS') }}</legend>
			<dl>
				<dt><label for="ad_name">{{ lang('AD_NAME') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_NAME_EXPLAIN') }}</span></dt>
				<dd><input class="text medium" id="ad_name" name="ad_name" value="{{ AD_NAME }}" maxlength="255" /></dd>
			</dl>
			<dl>
				<dt><label for="ad_enabled">{{ lang('AD_ENABLED') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_ENABLED_EXPLAIN') }}</span></dt>
				<dd><label><input type="radio" class="radio" id="ad_enabled" name="ad_enabled" value="1"{% if AD_ENABLED %} checked{% endif %} /> {{ lang('ENABLED') }}</label>
					<label><input type="radio" class="radio" name="ad_enabled" value="0"{% if not AD_ENABLED %} checked{% endif %} /> {{ lang('DISABLED') }}</label></dd>
			</dl>
			<dl>
				<dt><label for="ad_note">{{ lang('AD_NOTE') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_NOTE_EXPLAIN') }}</span></dt>
				<dd><textarea id="ad_note" name="ad_note" rows="5" cols="60" style="width: 95%;">{{ AD_NOTE }}</textarea></dd>
			</dl>
			<dl>
				<dt><label for="ad_code">{{ lang('AD_CODE') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_CODE_EXPLAIN') }}</span></dt>
				<dd>
					<textarea id="ad_code" name="ad_code" rows="20" cols="60" style="width: 95%;">{{ AD_CODE }}</textarea>
					<button class="button2 phpbb-ads-button" id="analyse_ad_code" name="analyse_ad_code"><i class="icon fa-fw fa-stethoscope"></i> <span>{{ lang('ANALYSE_AD_CODE') }}</span></button>
					<div class="analyser-results">
						{% if loops.analyser_results_notice or loops.analyser_results_warning %}
							{% if loops.analyser_results_notice %}
								{% for notice in loops.analyser_results_notice %}
									<p class="warningbox">{{ notice.MESSAGE }}</p>
								{% endfor %}
							{% endif %}

							{% if loops.analyser_results_warning %}
								{% for warning in loops.analyser_results_warning %}
									<p class="errorbox">{{ warning.MESSAGE }}</p>
								{% endfor %}
							{% endif %}
						{% elseif CODE_ANALYSED %}
							<p class="successbox">{{ lang('EVERYTHING_OK') }}</p>
						{% endif %}
					</div>
				</dd>
			</dl>
		</fieldset>
		<fieldset>
			<legend>{{ lang('AD_BANNER') }}</legend>
			<dl>
				<dt><label for="banner">{{ lang('BANNER') ~ lang('COLON') }}</label><br /><span>{{ lang('BANNER_EXPLAIN') }}</span></dt>
				<dd>
					<input type="file" accept="image/*" class="inputbox autowidth" id="banner" name="banner" />
					<button class="button2 phpbb-ads-button" id="upload_banner" name="upload_banner"><i class="icon fa-fw fa-upload"></i> <span>{{ lang('BANNER_UPLOAD') }}</span></button>
				</dd>
			</dl>
		</fieldset>
		<fieldset>
			<legend>{{ lang('AD_PLACEMENT') }}</legend>
			<dl>
				<dt><label for="ad_locations">{{ lang('AD_LOCATIONS') ~ lang('COLON') }}</label><br />
					<span>{{ lang('AD_LOCATIONS_EXPLAIN') }}<br><br>
						<a class="phpbb-ads-button" href="{{ U_ENABLE_VISUAL_DEMO }}" target="_blank">
							<i class="icon fa-fw fa-eye"></i> <span>{{ lang('AD_LOCATIONS_VISUAL_DEMO') }}</span>
						</a><br><br>{{ lang('VISUAL_DEMO_EXPLAIN') }}
					</span>
				</dt>
				<dd><select id="ad_locations" name="ad_locations[]" multiple size="10">
					{% for location in loops.ad_locations %}
						{% if location.CATEGORY_NAME %}
							{% if not loop.first %}</optgroup>{% endif %}
							<optgroup label="{{ location.CATEGORY_NAME }}">
						{% else %}
							<option value="{{ location.LOCATION_ID }}"{% if location.S_SELECTED %} selected{% endif %} title="{{ location.LOCATION_DESC }}">{{ location.LOCATION_NAME }}</option>
						{% endif %}
						</optgroup>
					{% endfor %}
					</select>
				</dd>
			</dl>
			<dl>
				<dt><label for="ad_priority">{{ lang('AD_PRIORITY') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_PRIORITY_EXPLAIN') }}</span></dt>
				<dd><input type="number" id="ad_priority" name="ad_priority" value="{{ AD_PRIORITY ?: constant('\\phpbb\\ads\\ext::DEFAULT_PRIORITY') }}" min="1" max="10" /></dd>
			</dl>
			<dl>
				<dt><label for="ad_content_only">{{ lang('AD_CONTENT_ONLY') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_CONTENT_ONLY_EXPLAIN') }}</span></dt>
				<dd><label><input type="radio" class="radio" name="ad_content_only" value="1"{% if AD_CONTENT_ONLY %} checked{% endif %} /> {{ lang('YES') }}</label>
					<label><input type="radio" class="radio" id="ad_content_only" name="ad_content_only" value="0"{% if not AD_CONTENT_ONLY %} checked{% endif %} /> {{ lang('NO') }}</label></dd>
			</dl>
			<dl>
				<dt><label for="ad_centering">{{ lang('AD_CENTERING') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_CENTERING_EXPLAIN') }}</span></dt>
				<dd><label><input type="radio" class="radio" id="ad_centering" name="ad_centering" value="1"{% if AD_CENTERING %} checked{% endif %} /> {{ lang('YES') }}</label>
					<label><input type="radio" class="radio" name="ad_centering" value="0"{% if not AD_CENTERING %} checked{% endif %} /> {{ lang('NO') }}</label></dd>
			</dl>
		</fieldset>
		<fieldset>
			<legend>{{ lang('AD_OPTIONS') }}</legend>
			<dl>
				<dt><label for="ad_owner">{{ lang('AD_OWNER') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_OWNER_EXPLAIN') }}</span></dt>
				<dd><input class="text medium" id="ad_owner" name="ad_owner" value="{{ AD_OWNER }}" /></dd>
				<dd>[ <a href="{{ U_FIND_USERNAME }}" onclick="find_username(this.href); return false;">{{ lang('FIND_USERNAME') }}</a> ]</dd>
			</dl>
			<dl>
				<dt><label for="ad_views_limit">{{ lang('AD_VIEWS_LIMIT') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_VIEWS_LIMIT_EXPLAIN') }}</span></dt>
				<dd><input class="text" type="number" id="ad_views_limit" name="ad_views_limit" value="{{ AD_VIEWS_LIMIT }}" size="20" min="0" /></dd>
			</dl>
			<dl>
				<dt><label for="ad_clicks_limit">{{ lang('AD_CLICKS_LIMIT') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_CLICKS_LIMIT_EXPLAIN') }}</span></dt>
				<dd><input class="text" type="number" id="ad_clicks_limit" name="ad_clicks_limit" value="{{ AD_CLICKS_LIMIT }}" size="20" min="0" /></dd>
			</dl>
			<dl>
				<dt><label for="ad_start_date">{{ lang('AD_START_DATE') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_START_DATE_EXPLAIN') }}</span></dt>
				<dd><input class="text" id="ad_start_date" name="ad_start_date" value="{{ AD_START_DATE ? AD_START_DATE|date(constant('\\phpbb\\ads\\ext::DATE_FORMAT')) }}" size="20" maxlength="20" /></dd>
			</dl>
			<dl>
				<dt><label for="ad_end_date">{{ lang('AD_END_DATE') ~ lang('COLON') }}</label><br /><span>{{ lang('AD_END_DATE_EXPLAIN') }}</span></dt>
				<dd><input class="text" id="ad_end_date" name="ad_end_date" value="{{ AD_END_DATE ? AD_END_DATE|date(constant('\\phpbb\\ads\\ext::DATE_FORMAT')) }}" size="20" maxlength="20" /></dd>
			</dl>
			<dl>
				<dt><label for="ad_groups">{{ lang('HIDE_GROUPS') ~ lang('COLON') }}</label><br /><span>{{ lang('HIDE_GROUPS_EXPLAIN') }}</span></dt>
				<dd><select id="ad_groups" name="ad_groups[]" multiple size="8">
						{% for group in loops.groups %}
							<option value="{{ group.ID }}"{% if group.S_SELECTED %} selected{% endif %}>{{ group.NAME }}</option>
						{% endfor %}
					</select>
				</dd>
			</dl>
		</fieldset>
		<fieldset class="submit-buttons">
			<input class="button1" type="submit" id="preview" name="preview" value="{{ lang('PREVIEW') }}" />&nbsp;
			<input class="button1" type="submit" id="submit" name="submit_{% if S_EDIT_AD %}edit{% else %}add{% endif %}" value="{{ lang('SUBMIT') }}" />&nbsp;
			<input class="button2" type="reset" id="reset" name="reset" value="{{ lang('RESET') }}" />
			{% if S_EDIT_AD %}
				<input type="hidden" name="id" value="{{ EDIT_ID }}" />
				<input type="hidden" name="action" value="edit" />
			{% else %}
				<input type="hidden" name="action" value="add" />
			{% endif %}
			{{ S_FORM_TOKEN }}
		</fieldset>
	</form>

{% else %}

	<h1>{{ lang('ACP_MANAGE_ADS_TITLE') }}</h1>

	<table class="table1 zebra-table fixed-width-table">
		<thead>
			<tr>
				<th style="width: 30%">{{ lang('AD_NAME') }}</th>
				<th>{{ lang('AD_PRIORITY') }}</th>
				<th>{{ lang('AD_START_DATE') }}</th>
				<th>{{ lang('AD_END_DATE') }}</th>
				{% if S_VIEWS_ENABLED %}<th>{{ lang('AD_VIEWS') }}</th>{% endif %}
				{% if S_CLICKS_ENABLED %}<th>{{ lang('AD_CLICKS') }}</th>{% endif %}
				<th>{{ lang('STATUS') }}</th>
				<th>{{ lang('ACTION') }}</th>
			</tr>
		</thead>
		<tbody>
			{% set NOW = "now"|date("U") %}
			{% for list in [
				{
					'heading': lang('ACTIVE_ADS'),
					'loop': loops.ads,
					'allow_enable': true
				},
				{
					'heading': lang('EXPIRED_ADS'),
					'loop': loops.expired,
					'allow_enable': false
				}
			] %}
				{% if list.loop %}
					<td class="row3" colspan="{{ 6 + S_VIEWS_ENABLED + S_CLICKS_ENABLED }}"><strong>{{ list.heading }}</strong></td>
					{% for ad in list.loop %}
						<tr{% if ad.S_EXPIRED %} title="{{ lang('AD_EXPIRED_EXPLAIN') }}"{% endif %}>
							<td><strong>{{ ad.NAME }}</strong></td>
							<td>{{ ad.PRIORITY }}</td>
							<td>{{ ad.START_DATE ? ad.START_DATE|date(constant('\\phpbb\\ads\\ext::DATE_FORMAT')) }}</td>
							<td>
								{% if ad.END_DATE < NOW %}<strong class="error">{% endif %}
									{{ ad.END_DATE ? ad.END_DATE|date(constant('\\phpbb\\ads\\ext::DATE_FORMAT')) }}
								{% if ad.END_DATE < NOW %}</strong>{% endif %}
							</td>
							{% if S_VIEWS_ENABLED %}
								<td>
									{% if ad.VIEWS_LIMIT and ad.VIEWS >= ad.VIEWS_LIMIT %}<strong class="error">{% endif %}
										{{ ad.VIEWS }}{% if ad.VIEWS_LIMIT %} / {{ ad.VIEWS_LIMIT }}{% endif %}
									{% if ad.VIEWS_LIMIT and ad.VIEWS >= ad.VIEWS_LIMIT %}</strong>{% endif %}
								</td>
							{% endif %}
							{% if S_CLICKS_ENABLED %}
								<td>
									{% if ad.CLICKS_LIMIT and ad.CLICKS >= ad.CLICKS_LIMIT %}<strong class="error">{% endif %}
										{{ ad.CLICKS }}{% if ad.CLICKS_LIMIT %} / {{ ad.CLICKS_LIMIT }}{% endif %}
									{% if ad.CLICKS_LIMIT and ad.CLICKS >= ad.CLICKS_LIMIT %}</strong>{% endif %}
								</td>
							{% endif %}
							<td>
								{% if list.allow_enable %}
									<a href="{{ ad.U_ENABLE }}" title="{{ lang('AD_ENABLE_TITLE', ad.S_ENABLED) }}" data-ajax="toggle_enable">
										{% if ad.S_ENABLED %}{{ lang('ENABLED') }}{% else %}{{ lang('DISABLED') }}{% endif %}
									</a>
								{% else %}
									{{ lang('DISABLED') }}
								{% endif %}
							</td>
							<td class="actions"><a href="{{ ad.U_EDIT }}">{{ ICON_EDIT }}</a> <a href="{{ ad.U_DELETE }}" data-ajax="row_delete">{{ ICON_DELETE }}</a></td>
						</tr>
					{% endfor %}
				{% elseif not loops.ads and not loops.expired and loop.last %}
					<tr>
						<td colspan="{{ 6 + S_VIEWS_ENABLED + S_CLICKS_ENABLED }}" style="text-align: center;">{{ lang('ACP_ADS_EMPTY') }}</td>
					</tr>
				{% endif %}
			{% endfor %}
		</tbody>
	</table>

	<form id="acp_phpbb_ads_quick_add" method="post" action="{{ U_ACTION_ADD }}">
		<fieldset class="quick">
			<input class="button2" type="submit" value="{{ lang('ACP_ADS_ADD') }}" />
			{{ S_FORM_TOKEN }}
		</fieldset>
	</form>

{% endif %}

{% include 'overall_footer.html' %}
