34 public $signature =
'';
40 public $blockchain =
'';
68 $this->signature = $block_static->getSignature();
70 $blocks = $block_static->getLog(
'all', 0, 0,
'rowid',
'ASC');
72 $this->blockchain =
'';
74 foreach ($blocks as &$b) {
75 $this->blockchain .= $b->signature;
78 return $this->blockchain;
89 return md5($this->signature.$this->blockchain);
113 $this->blockchain .= $block;
125 if (strlen($block) != 64)
return false;
127 $blocks = str_split($this->blockchain, 64);
129 if (!in_array($block, $blocks)) {
144 public function fetch($id, $signature =
'')
149 dol_syslog(get_class($this).
"::fetch id=".$id, LOG_DEBUG);
151 if (empty($id) && empty($signature))
153 $this->error =
'BadParameter';
157 $langs->load(
"blockedlog");
159 $sql =
"SELECT b.rowid, b.signature, b.blockchain, b.tms";
160 $sql .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog_authority as b";
162 if ($id) $sql .=
" WHERE b.rowid = ".$id;
163 elseif ($signature)$sql .=
" WHERE b.signature = '".$this->db->escape($signature).
"'";
170 $obj = $this->
db->fetch_object(
$resql);
172 $this->
id = $obj->rowid;
173 $this->ref = $obj->rowid;
175 $this->signature = $obj->signature;
176 $this->blockchain = $obj->blockchain;
178 $this->tms = $this->
db->jdate($obj->tms);
182 $this->error = $langs->trans(
"RecordNotFound");
186 $this->error = $this->
db->error();
200 global $conf, $langs, $hookmanager;
202 $langs->load(
'blockedlog');
206 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
210 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog_authority (";
211 $sql .=
" signature,";
212 $sql .=
" blockchain";
213 $sql .=
") VALUES (";
214 $sql .=
"'".$this->db->escape($this->signature).
"',";
215 $sql .=
"'".$this->db->escape($this->blockchain).
"'";
218 $res = $this->
db->query($sql);
221 $id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog_authority");
231 $this->
db->rollback();
235 $this->error = $this->
db->error();
236 $this->
db->rollback();
250 global $conf, $langs, $hookmanager;
252 $langs->load(
'blockedlog');
256 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
260 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"blockedlog_authority SET ";
261 $sql .=
" blockchain='".$this->db->escape($this->blockchain).
"'";
262 $sql .=
" WHERE rowid=".$this->id;
264 $res = $this->
db->query($sql);
271 $this->error = $this->
db->error();
272 $this->
db->rollback();
284 global $conf, $langs;
288 if (empty($conf->global->BLOCKEDLOG_AUTHORITY_URL) || empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY)) {
289 $this->error = $langs->trans(
'NoAuthorityURLDefined');
293 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
297 $blocks = $block_static->getLog(
'not_certified', 0, 0,
'rowid',
'ASC');
299 $signature = $block_static->getSignature();
301 foreach ($blocks as &$block) {
302 $url = $conf->global->BLOCKEDLOG_AUTHORITY_URL.
'/blockedlog/ajax/authority.php?s='.$signature.
'&b='.$block->signature;
304 $res = file_get_contents($url);
305 echo $block->signature.
' '.$url.
' '.$res.
'<br>';
306 if ($res ===
'blockalreadyadded' || $res ===
'blockadded') {
307 $block->setCertified();
309 $this->error = $langs->trans(
'ImpossibleToContactAuthority ', $url);
syncSignatureWithAuthority()
For cron to sync to authority.
addBlock($block)
Add a new block to the chain.
update($user)
Create authority in database.
__construct($db)
Constructor.
Class to manage certif authority.
$conf db
API class for accounts.
create($user)
Create authority in database.
Class to manage Blocked Log.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
checkBlock($block)
hash already exist into chain ?
checkBlockchain($hash)
Get hash of the block chain to check.
getLocalBlockChain()
Get the blockchain.
fetch($id, $signature= '')
Get object from database.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
getBlockchainHash()
Get hash of the block chain to check.