<?php

/*******************************************************************************
 * Megkeresendő / Non-profit / Felhasználó beállítása,      
 ******************************************************************************/
if (!isset($config)) require_once('config.php');

$msh->query("TRUNCATE TABLE " . CRMADATBAZIS . ".switch");
$msh->query("INSERT INTO `" . CRMADATBAZIS . "`.switch
  SELECT h.hlUser,CONCAT(',',group_concat(p.prVerID),',') AS prVerID
  FROM (
  	SELECT hlUser,hlNum 
  	FROM `" . CRMADATBAZIS . "`.`hardlock` 
  	WHERE hlStat=1 AND CONVERT(hlUser,UNSIGNED)>0 AND LENGTH(hlUser)<=6 AND hlUser>=1 AND hlUser<=999999
  	) h
  LEFT OUTER JOIN (
  	SELECT prHlNum AS hlNum,MAX(prVerID) AS prVerID 
  	FROM (SELECT * FROM `" . CRMADATBAZIS . "`.`h_programs` WHERE prStat=0) AS `h_programs`
  	GROUP BY prHlNum
  	) p ON h.hlNum=p.hlNum 
  WHERE prVerID IS NOT NULL
  GROUP BY h.hlUser 
  ORDER BY hlUser;");

$msh->query("DELETE FROM `" . CRMADATBAZIS . "`.writelog WHERE `datum`<date_add(CURRENT_TIMESTAMP,INTERVAL -30 day) LIMIT 1000;");
