<?php //http://www.archlinexp.com/maintenance/getdef.php?serial=3600178330000927
//if ($_SERVER['REMOTE_ADDR']!='46.139.109.235') {die('Not allowed access!');}

include("config.php");

$tomb = array();
$serial = $_GET['serial'];

$msh->query("SELECT * FROM " . CRMADATBAZIS . ".h_programs WHERE prPass='" . $serial . "' LIMIT 1;");
$prog = $msh->fetchAssoc();
if (empty($prog)) die();

$msh->query("SELECT hlUser FROM " . CRMADATBAZIS . ".hardlock WHERE hlNum='" . substr($serial, 0, 6) . "' LIMIT 1;");
$res = $msh->fetchAssoc();
if (empty($res)) die();

if ((int)$res[0]['hlUser'] > 0) {
  $tomb['nUserID'] = $res[0]['hlUser'];

  $msh->query("SELECT * FROM " . CRMADATBAZIS . ".u_emails WHERE nUserID='" . $tomb['nUserID'] . "';");
  $res = $msh->fetchAssoc();
  if (!empty($res)) {
    foreach ($res as $k => $row) {
      if ((int)$row['default'] == 1) {
        $tomb['strEmail'] = $row['email'];
        break;
      }
    }
    if ($tomb['email'] == "") $tomb['strEmail'] = $res[0]['email'];
  }

  $msh->query("SELECT * FROM " . CRMADATBAZIS . ".users WHERE nUserID=" . $tomb['nUserID'] . " LIMIT 1;");
  $res = $msh->fetchAssoc();
  if (empty($res)) die();

  $tomb['strName'] = $res[0]['strName'];
  $tomb['strCompany'] = $res[0]['strCompany'];
} else {
  $tomb['strName'] = $res[0]['hlUser'];
}

$strXML = '<?xml version="1.0" encoding="utf-8"' . '?' . '>
<User>
  <bActive>' . ((int)$prog[0]['prStat'] == 0 ? 'TRUE' : 'FALSE') . '</bActive>
  <strEmail>' . $tomb['strEmail'] . '</strEmail>
  <strName>' . $tomb['strName'] . '</strName>
  <strCompany>' . $tomb['strCompany'] . '</strCompany>
</User>';

print $strXML;
