<?php

function USERS2_MARKETING_ANALIZA_APP() {
	echo '<h1>' . "Analiza L_APPOITMENT_USER w bazie marketingowej" . '</h1>';

	$rows = array();
	$db = DB::getDB();
	$sql = "select count(1) as `cnt`, m.`L_APPOITMENT_USER`
		from `USERS2_MARKETING` as m
			left join `ADMIN_USERS` as u on(u.`ADM_ACCOUNT`=m.`L_APPOITMENT_USER`)
		where m.`L_APPOITMENT_DATE`!=''
			and m.`L_APPOITMENT_USER`!=''
			and u.`A_STATUS`!='NORMAL'
		group by m.`L_APPOITMENT_USER`
		order by `cnt` desc
	";
	$res = $db->query($sql);
	while ($r = $db->fetch($res)) {
		$rows[] = $r;
	}


	$time = time();
	?>
	<table class="table table-bordered" style="width:400px;">
		<tr>
			<td>Ilość</td>
			<td>Login</td>
			<td></td>
		</tr>
		<?php foreach ($rows as $r) : ?>
			<tr>
				<td><?php echo $r->cnt; ?></td>
				<td><?php echo $r->L_APPOITMENT_USER; ?></td>
				<td><a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=23&_hash=<?php echo 'USERS2_MARKETING' . md5("{$r->L_APPOITMENT_USER}{$time}"); ?>&f_L_APPOITMENT_USER=<?php echo $r->L_APPOITMENT_USER; ?>" target="_blank">wyszukaj</a></td>
			</tr>
		<?php endforeach; ?>
	</table>
	<?php

}
