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 if (is_array($blocks)) {
75 foreach ($blocks as &$b) {
76 $this->blockchain .= $b->signature;
80 return $this->blockchain;
91 return md5($this->signature.$this->blockchain);
115 $this->blockchain .= $block;
127 if (strlen($block) != 64) {
131 $blocks = str_split($this->blockchain, 64);
133 if (!in_array($block, $blocks)) {
148 public function fetch($id, $signature =
'')
153 dol_syslog(get_class($this).
"::fetch id=".((
int) $id), LOG_DEBUG);
155 if (empty($id) && empty($signature)) {
156 $this->error =
'BadParameter';
160 $langs->load(
"blockedlog");
162 $sql =
"SELECT b.rowid, b.signature, b.blockchain, b.tms";
163 $sql .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog_authority as b";
166 $sql .=
" WHERE b.rowid = ".((int) $id);
167 } elseif ($signature) {
168 $sql .=
" WHERE b.signature = '".$this->db->escape($signature).
"'";
174 $obj = $this->
db->fetch_object(
$resql);
176 $this->
id = $obj->rowid;
177 $this->
ref = $obj->rowid;
179 $this->signature = $obj->signature;
180 $this->blockchain = $obj->blockchain;
182 $this->tms = $this->
db->jdate($obj->tms);
186 $this->error = $langs->trans(
"RecordNotFound");
190 $this->error = $this->
db->error();
204 global $conf, $langs, $hookmanager;
206 $langs->load(
'blockedlog');
210 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
214 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog_authority (";
215 $sql .=
" signature,";
216 $sql .=
" blockchain";
217 $sql .=
") VALUES (";
218 $sql .=
"'".$this->db->escape($this->signature).
"',";
219 $sql .=
"'".$this->db->escape($this->blockchain).
"'";
222 $res = $this->
db->query($sql);
224 $id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog_authority");
233 $this->
db->rollback();
237 $this->error = $this->
db->error();
238 $this->
db->rollback();
252 global $conf, $langs, $hookmanager;
254 $langs->load(
'blockedlog');
258 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
262 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"blockedlog_authority SET ";
263 $sql .=
" blockchain='".$this->db->escape($this->blockchain).
"'";
264 $sql .=
" WHERE rowid=".((int) $this->
id);
266 $res = $this->
db->query($sql);
272 $this->error = $this->
db->error();
273 $this->
db->rollback();
285 global $conf, $langs;
289 if (empty($conf->global->BLOCKEDLOG_AUTHORITY_URL) || empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY)) {
290 $this->error = $langs->trans(
'NoAuthorityURLDefined');
294 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
298 $blocks = $block_static->getLog(
'not_certified', 0, 0,
'rowid',
'ASC');
300 $signature = $block_static->getSignature();
302 if (is_array($blocks)) {
303 foreach ($blocks as &$block) {
304 $url = $conf->global->BLOCKEDLOG_AUTHORITY_URL.
'/blockedlog/ajax/authority.php?s='.$signature.
'&b='.$block->signature;
307 echo $block->signature.
' '.$url.
' '.$res.
'<br>';
308 if ($res ===
'blockalreadyadded' || $res ===
'blockadded') {
309 $block->setCertified();
311 $this->error = $langs->trans(
'ImpossibleToContactAuthority ', $url);