39 public $signature =
'';
45 public $blockchain =
'';
79 $this->signature = $block_static->getSignature();
81 $blocks = $block_static->getLog(
'all', 0, 0,
'rowid',
'ASC');
83 $this->blockchain =
'';
85 if (is_array($blocks)) {
86 foreach ($blocks as &$b) {
87 $this->blockchain .= $b->signature;
91 return $this->blockchain;
102 return md5($this->signature.$this->blockchain);
126 $this->blockchain .= $block;
138 if (strlen($block) != 64) {
142 $blocks = str_split($this->blockchain, 64);
144 if (!in_array($block, $blocks)) {
159 public function fetch($id, $signature =
'')
164 dol_syslog(get_class($this).
"::fetch id=".((
int) $id), LOG_DEBUG);
166 if (empty($id) && empty($signature)) {
167 $this->error =
'BadParameter';
171 $langs->load(
"blockedlog");
173 $sql =
"SELECT b.rowid, b.signature, b.blockchain, b.tms";
174 $sql .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog_authority as b";
177 $sql .=
" WHERE b.rowid = ".((int) $id);
178 } elseif ($signature) {
179 $sql .=
" WHERE b.signature = '".$this->db->escape($signature).
"'";
185 $obj = $this->
db->fetch_object(
$resql);
187 $this->
id = $obj->rowid;
188 $this->
ref = $obj->rowid;
190 $this->signature = $obj->signature;
191 $this->blockchain = $obj->blockchain;
193 $this->tms = $this->
db->jdate($obj->tms);
197 $this->error = $langs->trans(
"RecordNotFound");
201 $this->error = $this->
db->error();
215 global $conf, $langs, $hookmanager;
217 $langs->load(
'blockedlog');
221 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
225 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog_authority (";
226 $sql .=
" signature,";
227 $sql .=
" blockchain";
228 $sql .=
") VALUES (";
229 $sql .=
"'".$this->db->escape($this->signature).
"',";
230 $sql .=
"'".$this->db->escape($this->blockchain).
"'";
233 $res = $this->
db->query($sql);
235 $id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog_authority");
244 $this->
db->rollback();
248 $this->error = $this->
db->error();
249 $this->
db->rollback();
263 global $conf, $langs, $hookmanager;
265 $langs->load(
'blockedlog');
269 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
273 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"blockedlog_authority SET ";
274 $sql .=
" blockchain='".$this->db->escape($this->blockchain).
"'";
275 $sql .=
" WHERE rowid=".((int) $this->
id);
277 $res = $this->
db->query($sql);
283 $this->error = $this->
db->error();
284 $this->
db->rollback();
296 global $conf, $langs;
300 if (empty($conf->global->BLOCKEDLOG_AUTHORITY_URL) || empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY)) {
301 $this->error = $langs->trans(
'NoAuthorityURLDefined');
305 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
309 $blocks = $block_static->getLog(
'not_certified', 0, 0,
'rowid',
'ASC');
311 $signature = $block_static->getSignature();
313 if (is_array($blocks)) {
314 foreach ($blocks as &$block) {
315 $url = $conf->global->BLOCKEDLOG_AUTHORITY_URL.
'/blockedlog/ajax/authority.php?s='.$signature.
'&b='.$block->signature;
318 echo $block->signature.
' '.$url.
' '.$res[
'content'].
'<br>';
319 if ($res[
'content'] ===
'blockalreadyadded' || $res[
'content'] ===
'blockadded') {
320 $block->setCertified();
322 $this->error = $langs->trans(
'ImpossibleToContactAuthority ', $url);