<?
function usage_add($usagemodule, $usagetask, $usageitemid) {
	// prepare params..
	$usagepkey=md5(microtime());
	$usageuserpkey=$_SESSION['Xuserpkey'];
	$usagedatetime=gettimestamp();
	// update stats table..
	$sa = add_data_noaudit("portal_usage", "usagepkey, usageuserpkey, usagemodule, usagetask, usageitemid, usagedatetime",
		"'".$usagepkey."','".$usageuserpkey."','".$usagemodule."','".$usagetask.
		"','".$usageitemid."','".$usagedatetime."'");
}

function stats_logincount($resettime) {
  global $db_pms;
  $myquery="Select count(*) as lcount from system_audittrail where audit_module='Login' and audit_datetime>'".$resettime."'"; 
  $myresult=&$db_pms->query($myquery);
  $mycount=$myresult->numRows();
  if ($mycount!=0) {
    while($myrow=$myresult->fetchRow()) {
      return intval($myrow['lcount']);
    }
  } else {
    return 0;
  }
}

function stats_moduleaccesscount($starttime, $stoptime, $modulename, $taskname) {
  global $db_pms;
  if ($taskname!="") {
    $myquery="Select count(*) as acount from portal_usage where usagemodule='".$modulename."' and usagetask='".$taskname."' and usagedatetime>='".$starttime."' and usagedatetime<='".$stoptime."'"; 
  } else {
    $myquery="Select count(*) as acount from portal_usage where usagemodule='".$modulename."' and usagedatetime>='".$starttime."' and usagedatetime<='".$stoptime."'"; 
  }
  $myresult=&$db_pms->query($myquery);
  $mycount=$myresult->numRows();
  if ($mycount!=0) {
    while($myrow=$myresult->fetchRow()) {
      return intval($myrow['acount']);
    }
  } else {
    return 0;
  }
}

function stats_itemaccesscount($starttime, $stoptime, $modulename, $taskname, $itemid) {
  global $db_pms;
  $myquery="Select count(*) as icount from portal_usage where usagemodule='".$modulename."' and usagetask='".$taskname."' and usageitemid='".$itemid."' and usagedatetime>='".$starttime."' and usagedatetime<='".$stoptime."'"; 
  $myresult=&$db_pms->query($myquery);
  $mycount=$myresult->numRows();
  if ($mycount!=0) {
    while($myrow=$myresult->fetchRow()) {
      return intval($myrow['icount']);
    }
  } else {
    return 0;
  }
}

?>