<?php
$object = $request['object'];

if (isset($object['copy'])) {
    $copy = $object['copy'];
    $select = $DLA->Select("SELECT * FROM `app_acceptor_document` WHERE `idFor`='{$object['ID']}'");
    $query = "";
    $table = array(
        'copy-shenasname' => 'CopyOfBirthCertificate',
        'copy-cart-meli' => 'CopyTheNationalCard',
        'copy-cart-meli-posht' => 'CopyTheNationalCardBack',
        'copy-javaz-kasb' => 'CopyBusinessLicense',
        'copy-bargh-gaz-ab' => 'CopyTheBillForWaterOrGas',
        'copy-gharardad' => 'CopyTheFrontPageOfTheContract'
    );


    if ($select) {
        $query = "UPDATE `app_acceptor_document` SET `" . $table[$object['field']] . "`='{$copy}' WHERE `idFor`='{$object['ID']}'";
    } else {
        $query = "INSERT INTO `app_acceptor_document` (`idFor`,`" . $table[$object['field']] . "`) VALUES ('{$object['ID']}','{$copy}')";
    }
    echo($DLA->DoCommand($query) ? '1' : '0');
} else {
    echo "0";
}