<?php

$advOnto = $this->srvFactory("AdvOntology");
$item = $advOnto->getConceptByData("DownCounter", $url);

if($_REQUEST["downloadcnt"]) {
	$reqUrl = base64_decode($_REQUEST["downloadcnt"]);
	if($reqUrl == $url) {
		// cnt also!

		if($item) {
			$item["dcnt"] = $item["dcnt"]+1;
			$advOnto->setConcept("DownCounter", $item["id"], $item["data"], null, $item);
		} else {
			//$advOnto->addConcept("DownCounter", $url, null, array("dcnt" => "1"));
			$advOnto->addConcept("DownCounter", $url);
		}


		$this->redirect($url);


	}
} else {
  if(!$text) $text = $url.' ({cnt})';

  $resText = htmlspecialchars(str_replace('{cnt}',$item["dcnt"]?$item["dcnt"]:"0",$text));

  echo '<a href="'.$this->href('','','downloadcnt='.urlencode(base64_encode($url))).'">'.$resText.'</a>';
}


?>