<vn>
<div id="title">
	<h1><t>Visits</t></h1>
</div>
<div id="actions">
	<htk-bar-button
		icon="refresh"
		tip="_Refresh"
		on-click="onRefreshClick"/>
	<htk-bar-button
		icon="user-info"
		tip="_Connections"
		on-click="onSessionsClick"/>
</div>
<div id="form" class="visits">
	<div class="box">
		<div class="form">
			<div class="form-group">
				<label><t>From</t></label>
				<htk-date-chooser>
					<vn-param property="param" id="from"/>
				</htk-date-chooser>
			</div>
			<div class="form-group">
				<label><t>To</t></label>
				<htk-date-chooser>
					<vn-param property="param" id="to"/>
				</htk-date-chooser>
			</div>
		</div>
	</div>
	<div class="summary box">
		<p>
			<htk-text>
				<db-calc-sum
					property="param"
					model="visits"
					column-name="visits"/>
			</htk-text> 
			<t>visits</t>,
			<htk-text>
				<db-calc-sum
					property="param"
					model="visits"
					column-name="new_visits"/>
			</htk-text> 
			<t>news</t>
		</p>
	</div>
	<div class="list box">
		<htk-repeater form-id="iter" empty-message="_Select date interval">
			<db-model property="model" id="visits">
				<custom>
					SELECT browser
					,MIN(CAST(version AS DECIMAL(4,1))) min_version
					,MAX(CAST(version AS DECIMAL(4,1))) max_version
					,MAX(e.date_time) last_visit
					,COUNT(DISTINCT c.id) visits
					,SUM(is_new) new_visits
						FROM visit_user e
						JOIN visit_access c ON e.access_id = c.id
						JOIN visit_agent a ON c.agent_id = a.id
						JOIN visit v ON a.visit_id = v.id
							WHERE e.date_time BETWEEN TIMESTAMP(#from,'00:00:00') AND TIMESTAMP(#to,'23:59:59')
							GROUP BY browser ORDER BY visits DESC
				</custom>
				<sql-batch property="batch">
					<custom>
						<item name="from" param="from"/>
						<item name="to" param="to"/>
					</custom>
				</sql-batch>
			</db-model>
			<custom>
				<div class="item">
					<p class="important">
						<htk-text form="iter" column="browser"/> 
						<htk-text form="iter" column="min_version"/> - 
						<htk-text form="iter" column="max_version"/>
					</p>
					<p>
						<htk-text form="iter" column="visits"/> 
						<t>visits</t>, 
						<htk-text form="iter" column="new_visits"/> 
						<t>news</t>
					</p>
					<p>
						<htk-text form="iter" column="last_visit" format="_%a, %e %b %Y at %T"/>
					</p>
			</div>
			</custom>
		</htk-repeater>
	</div>
</div>
</vn>
