145 lines
4.2 KiB
PHP
145 lines
4.2 KiB
PHP
<?php
|
|
ini_set('display_errors',1);
|
|
require_once 'include/ECM/GusApiSugar/vendor/autoload.php';
|
|
|
|
use GusApi\GusApi;
|
|
use GusApi\RegonConstantsInterface;
|
|
use GusApi\Exception\InvalidUserKeyException;
|
|
use GusApi\ReportTypes;
|
|
|
|
class GusApiSugar
|
|
{
|
|
|
|
private $key = 'eb11f76c0aee4c6e8501';
|
|
|
|
private $gus;
|
|
|
|
private $cuser;
|
|
|
|
private $array = null;
|
|
|
|
public function __construct ()
|
|
{
|
|
$this->gus = new GusApi($this->key,
|
|
new \GusApi\Adapter\Soap\SoapAdapter(
|
|
RegonConstantsInterface::BASE_WSDL_URL,
|
|
RegonConstantsInterface::BASE_WSDL_ADDRESS));
|
|
global $current_user;
|
|
$this->cuser = $current_user;
|
|
}
|
|
|
|
public function validate ($code)
|
|
{
|
|
$_SESSION['checkedgus'] = $this->gus->checkCaptcha($_SESSION['sigusd'],
|
|
$code);
|
|
var_dump($_SESSION['checkedgus']);
|
|
}
|
|
|
|
public function getRaport ($gusReport)
|
|
{
|
|
if ($gusReport->type == 'f') {
|
|
$nr = null;
|
|
|
|
foreach ($gusReport->silo as $val) {
|
|
if ($val != '') {
|
|
$nr = $val;
|
|
}
|
|
}
|
|
switch ($nr) {
|
|
case 0:
|
|
return $this->gus->getFullReport($_SESSION['sid'], $gusReport,
|
|
ReportTypes::REPORT_ACTIVITY_PHYSIC_PERSON);
|
|
break;
|
|
case 1:
|
|
return $this->gus->getFullReport($_SESSION['sid'], $gusReport,
|
|
ReportTypes::REPORT_ACTIVITY_PHYSIC_CEGID);
|
|
break;
|
|
case 2:
|
|
return $this->gus->getFullReport($_SESSION['sid'], $gusReport,
|
|
ReportTypes::REPORT_ACTIVITY_PHYSIC_AGRO);
|
|
break;
|
|
case 3:
|
|
return $this->gus->getFullReport($_SESSION['sid'], $gusReport,
|
|
ReportTypes::REPORT_ACTIVITY_PHYSIC_OTHER_PUBLIC);
|
|
break;
|
|
case 4:
|
|
return $this->gus->getFullReport($_SESSION['sid'], $gusReport,
|
|
ReportTypes::REPORT_ACTIVITY_LOCAL_PHYSIC_WKR_PUBLIC);
|
|
break;
|
|
}
|
|
|
|
} else {
|
|
return $this->gus->getFullReport($_SESSION['sid'], $gusReport,
|
|
ReportTypes::REPORT_PUBLIC_LAW);
|
|
}
|
|
}
|
|
|
|
public function getData ($nip)
|
|
{
|
|
$array = null;
|
|
try {
|
|
$gusReport = $this->gus->getByNip($_SESSION['sigusd'], $nip);
|
|
$array['type']=$gusReport->type;
|
|
$array[] = $this->getRaport($gusReport);
|
|
} catch (\GusApi\Exception\NotFoundException $e) {
|
|
|
|
$error = $this->gus->getResultSearchMessage();
|
|
if ('Wymagane pobranie i sprawdzenie kodu Captcha' == $error) {
|
|
$_SESSION['checkedgus'] = false;
|
|
$_SESSION['sigusd'] = '';
|
|
$this->doLogin();
|
|
return;
|
|
} else {
|
|
return array(
|
|
'error' => 'tak',
|
|
$error
|
|
);
|
|
}
|
|
}
|
|
if($array==null){
|
|
$this->doLogin();
|
|
return;
|
|
}
|
|
return $array;
|
|
}
|
|
|
|
public function doLogin ($code = null, $img = null)
|
|
{
|
|
if ($this->gus->serviceStatus() ===
|
|
RegonConstantsInterface::SERVICE_AVAILABLE) {
|
|
if (! isset($_SESSION['sigusd']) ||
|
|
! $this->gus->isLogged($_SESSION['sigusd'])) {
|
|
$_SESSION['sigusd'] = $this->gus->login();
|
|
$_SESSION['checkedgus'] = false;
|
|
}
|
|
|
|
if (isset($img)) {
|
|
$_SESSION['checkedgus'] = $this->gus->checkCaptcha($_SESSION['sigusd'],
|
|
$img);
|
|
}
|
|
|
|
if (! $_SESSION['checkedgus']) {
|
|
|
|
$image = fopen("upload/captcha" . $this->cuser->id . ".jpeg", 'w+');
|
|
|
|
$captcha = $this->gus->getCaptcha($_SESSION['sigusd']);
|
|
fwrite($image, base64_decode($captcha));
|
|
fclose($image);
|
|
|
|
return array(
|
|
'cuserid' => $this->cuser->id
|
|
);
|
|
} else {
|
|
return $this->getData($code);
|
|
}
|
|
} else {
|
|
return array(
|
|
'error' => 'tak'
|
|
);
|
|
}
|
|
}
|
|
}
|
|
$g= new GusApiSugar();
|
|
|
|
$back=$g->doLogin('5030056367');
|
|
?>
|