Config::$EDOK_API_LOCATION, "uri" => "eDokumentyAPI", 'encoding'=>'UTF-8' ); $client = new EDokApiClient(null, $ops); $client->setUser(Config::$EDOK_API_LOGIN); $client->setPass(md5(Config::$EDOK_API_PASSWORD)); $header = new SoapHeader('eDokumentyAPI', 'entity_symbol', Config::$DEFAULT_ENTITY_SYMBOL); $client->__setSoapHeaders($header); try { $file_name = trim($file_name); $pi = pathinfo($file_name); $fpath = $pi['dirname']; $file_name = $pi['basename']; $fpath = $cdir.$fpath.DIRECTORY_SEPARATOR.$file_name; if (file_exists($fpath) && is_readable($fpath)) { $eof = FALSE; $timeout = 15; while (--$timeout && !($fp = @fopen($fpath, 'rb'))) { sleep(1); } if ($fp) { fclose($fp); } } else { throw new Exception('can\'t open '.$fpath.' for reading'); } //kazdy tekst musi być w UTF-8 foreach($params as &$value) { if (!is_numeric($value)) { $value = iconv('Windows-1250', 'UTF-8', $value); } } $dscrpt = ''; $data = array(); if (!isset($params['dctpid']) AND isset($params['dctptp']) AND !empty($params['dctptp'])) { $data['dctptp'] = $params['dctptp']; } if (!empty($data)) { $dtyp = $client->getDocumentTypeData($data); $params['dctpid'] = NULL; if (isset($dtyp['dctpid'])) { $params['dctpid'] = $dtyp['dctpid']; if ($dtyp['dctptp'] != 'Other') $dscrpt = $dtyp['dctpnm']; } } $target = (isset($params['target']) and $params['target']) ? $params['target'] : (isset(Config::$TARGET_ORUNID) ? Config::$TARGET_ORUNID : 1); $data = array( 'dscrpt' => 'Dokument ('.iconv('Windows-1250', 'UTF-8', $file_name).')', 'fixinf' => iconv('Windows-1250', 'UTF-8', $file_name), 'target' => $target, 'dctpid' => isset($params['dctpid']) ? $params['dctpid'] : 2, ); try { $doc_id = $client->createDocument($data); } catch(SoapFault $fault) { throw new Exception("[{$fault->faultcode}]: {$fault->faultstring}"); } if (isset($doc_id) AND $doc_id) { $dd = 0; try { $file = base64_encode(file_get_contents($fpath)); $file_name = iconv('Windows-1250', 'UTF-8', $file_name); $dd = $client->addAttachmentToDocument($file, $file_name, $doc_id); } catch(SoapFault $fault) { throw new Exception("[{$fault->faultcode}]: {$fault->faultstring}"); } if ($dd > 0) { // po udanych operacjach usuń plik if (isset(Config::$SENT_DIR)) { rename($fpath, rtrim(Config::$SENT_DIR, '\\/').'/'.$file_name); } else { unlink($fpath); } } else { throw new Exception('Attachment not created'); } } else { throw new Exception('Document not created (unknown error)'); } } catch(Exception $e) { // oznacz błędny plik //rename($fpath, $fpath.'_'); trigger_error($e->getMessage(), E_USER_ERROR); } exit(0); ?>