211 if (isset($this->
ref)) {
212 $this->
ref = trim($this->
ref);
214 if (isset($this->label)) {
215 $this->label = trim($this->label);
217 if (isset($this->share)) {
218 $this->share = trim($this->share);
220 if (isset($this->entity)) {
221 $this->entity = (int) $this->entity;
223 if (isset($this->filename)) {
224 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
226 if (isset($this->filepath)) {
227 $this->filepath = trim($this->filepath);
228 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
230 if (isset($this->fullpath_orig)) {
231 $this->fullpath_orig = trim($this->fullpath_orig);
236 if (isset($this->keywords)) {
237 $this->keywords = trim($this->keywords);
239 if (isset($this->cover)) {
240 $this->cover = trim($this->cover);
242 if (isset($this->gen_or_uploaded)) {
243 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
245 if (isset($this->extraparams)) {
246 $this->extraparams = trim($this->extraparams);
248 if (isset($this->fk_user_c)) {
249 $this->fk_user_c = (int) $this->fk_user_c;
251 if (isset($this->fk_user_m)) {
252 $this->fk_user_m = (int) $this->fk_user_m;
254 if (isset($this->acl)) {
255 $this->acl = trim($this->acl);
257 if (isset($this->src_object_type)) {
258 $this->src_object_type = trim($this->src_object_type);
260 if (empty($this->date_c)) {
263 if (empty($this->date_m)) {
268 if (empty($this->
ref)) {
269 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
270 $this->
ref =
dol_hash($this->filepath.
'/'.$this->filename, 3);
276 $sql =
"SELECT MAX(position) as maxposition FROM ".MAIN_DB_PREFIX.$this->table_element;
277 $sql .=
" WHERE filepath ='".$this->db->escape($this->filepath).
"'";
279 $resql = $this->db->query($sql);
281 $obj = $this->db->fetch_object($resql);
282 $maxposition = (int) $obj->maxposition;
284 $this->errors[] =
'Error '.$this->db->lasterror();
287 $maxposition = $maxposition + 1;
289 $maxposition = $this->position;
293 if (empty($this->filename) || empty($this->filepath)) {
294 $this->errors[] =
'Bad property filename or filepath';
297 if (!isset($this->entity)) {
298 $this->entity = $conf->entity;
303 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
310 $sql .=
'fullpath_orig,';
311 $sql .=
'description,';
315 $sql .=
'gen_or_uploaded,';
316 $sql .=
'extraparams,';
319 $sql .=
'fk_user_c,';
320 $sql .=
'fk_user_m,';
322 $sql .=
'src_object_type,';
323 $sql .=
'src_object_id';
324 $sql .=
') VALUES (';
325 $sql .=
" '".$this->db->escape($this->
ref).
"', ";
326 $sql .=
' '.(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
',';
327 $sql .=
' '.(!isset($this->share) ?
'NULL' :
"'".$this->db->escape($this->share).
"'").
',';
328 $sql .=
' '.((int) $this->entity).
',';
329 $sql .=
' '.(!isset($this->filename) ?
'NULL' :
"'".$this->db->escape($this->filename).
"'").
',';
330 $sql .=
' '.(!isset($this->filepath) ?
'NULL' :
"'".$this->db->escape($this->filepath).
"'").
',';
331 $sql .=
' '.(!isset($this->fullpath_orig) ?
'NULL' :
"'".$this->db->escape($this->fullpath_orig).
"'").
',';
333 $sql .=
' '.(!isset($this->keywords) ?
'NULL' :
"'".$this->db->escape($this->keywords).
"'").
',';
334 $sql .=
' '.(!isset($this->cover) ?
'NULL' :
"'".$this->db->escape($this->cover).
"'").
',';
335 $sql .=
' '.((int) $maxposition).
',';
336 $sql .=
' '.(!isset($this->gen_or_uploaded) ?
'NULL' :
"'".$this->db->escape($this->gen_or_uploaded).
"'").
',';
337 $sql .=
' '.(!isset($this->extraparams) ?
'NULL' :
"'".$this->db->escape($this->extraparams).
"'").
',';
338 $sql .=
" '".$this->db->idate($this->date_c).
"',";
339 $sql .=
' '.(!isset($this->date_m) ||
dol_strlen($this->date_m) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_m).
"'").
',';
340 $sql .=
' '.(!isset($this->fk_user_c) ? $user->id : $this->fk_user_c).
',';
341 $sql .=
' '.(!isset($this->fk_user_m) ?
'NULL' : $this->fk_user_m).
',';
342 $sql .=
' '.(!isset($this->acl) ?
'NULL' :
"'".$this->db->escape($this->acl).
"'").
',';
343 $sql .=
' '.(!isset($this->src_object_type) ?
'NULL' :
"'".$this->db->escape($this->src_object_type).
"'").
',';
344 $sql .=
' '.(!isset($this->src_object_id) ?
'NULL' : $this->src_object_id);
348 $resql = $this->db->query($sql);
351 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
352 $this->errors[] =
'Error DB_ERROR_RECORD_ALREADY_EXISTS : '.$this->db->lasterror();
354 $this->errors[] =
'Error '.$this->db->lasterror();
356 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
360 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
366 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_CREATE', $user);
376 $this->db->rollback();
398 public function fetch($id, $ref =
'', $relativepath =
'', $hashoffile =
'', $hashforshare =
'', $src_object_type =
'', $src_object_id = 0)
409 $sql .=
" t.entity,";
410 $sql .=
" t.filename,";
411 $sql .=
" t.filepath,";
412 $sql .=
" t.fullpath_orig,";
413 $sql .=
" t.description,";
414 $sql .=
" t.keywords,";
416 $sql .=
" t.position,";
417 $sql .=
" t.gen_or_uploaded,";
418 $sql .=
" t.extraparams,";
419 $sql .=
" t.date_c,";
420 $sql .=
" t.tms as date_m,";
421 $sql .=
" t.fk_user_c,";
422 $sql .=
" t.fk_user_m,";
423 $sql .=
' t.note_private,';
424 $sql .=
' t.note_public,';
426 $sql .=
" t.src_object_type,";
427 $sql .=
" t.src_object_id";
428 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
429 $sql .=
' WHERE 1 = 1';
436 $relativepathwithnoexe = preg_replace(
'/\.noexe$/',
'', $relativepath);
437 $sql .=
" AND t.filepath = '".$this->db->escape(dirname($relativepath)).
"'";
438 $filename = basename($relativepathwithnoexe);
439 if ($filename !=
'*') {
440 $sql .=
" AND t.filename = '".$this->db->escape($filename).
"'";
442 $sql .=
" AND t.entity = ".$conf->entity;
446 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
447 $sql .=
" AND t.entity = ".$conf->entity;
450 if (!empty($hashoffile)) {
451 $sql .=
" AND t.label = '".$this->db->escape($hashoffile).
"'";
452 $sql .=
" AND t.entity = ".$conf->entity;
455 if (!empty($hashforshare)) {
456 if ($hashforshare !=
'shared') {
457 $sql .=
" AND t.share = '".$this->db->escape($hashforshare).
"'";
459 $sql .=
" AND t.share IS NOT NULL AND t.share <> ''";
464 if ($src_object_type && $src_object_id) {
465 $sql .=
" AND t.src_object_type = '".$this->db->escape($src_object_type).
"' AND t.src_object_id = ".((int) $src_object_id);
466 $sql .=
" AND t.entity = ".((int) $conf->entity);
469 if ($id > 0 || empty($filterfound)) {
470 $sql .=
' AND t.rowid = '.((int) $id);
474 $this->db->plimit(1);
475 $this->db->order(
't.rowid',
'ASC');
477 $resql = $this->db->query($sql);
479 $numrows = $this->db->num_rows($resql);
481 $obj = $this->db->fetch_object($resql);
483 $this->
id = $obj->rowid;
484 $this->
ref = $obj->ref;
485 $this->label = $obj->label;
486 $this->share = $obj->share;
487 $this->entity = $obj->entity;
488 $this->filename = $obj->filename;
489 $this->filepath = $obj->filepath;
490 $this->fullpath_orig = $obj->fullpath_orig;
492 $this->keywords = $obj->keywords;
493 $this->cover = $obj->cover;
495 $this->gen_or_uploaded = $obj->gen_or_uploaded;
496 $this->extraparams = $obj->extraparams;
497 $this->date_c = $this->db->jdate($obj->date_c);
498 $this->date_m = $this->db->jdate($obj->date_m);
499 $this->fk_user_c = $obj->fk_user_c;
500 $this->fk_user_m = $obj->fk_user_m;
501 $this->note_private = $obj->note_private;
502 $this->note_public = $obj->note_public;
503 $this->acl = $obj->acl;
504 $this->src_object_type = $obj->src_object_type;
505 $this->src_object_id = $obj->src_object_id;
514 $this->db->free($resql);
522 $this->errors[] =
'Error '.$this->db->lasterror();
523 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
541 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
549 $sql .=
" t.entity,";
550 $sql .=
" t.filename,";
551 $sql .=
" t.filepath,";
552 $sql .=
" t.fullpath_orig,";
553 $sql .=
" t.description,";
554 $sql .=
" t.keywords,";
556 $sql .=
" t.position,";
557 $sql .=
" t.gen_or_uploaded,";
558 $sql .=
" t.extraparams,";
559 $sql .=
" t.date_c,";
560 $sql .=
" t.tms as date_m,";
561 $sql .=
" t.fk_user_c,";
562 $sql .=
" t.fk_user_m,";
564 $sql .=
" t.src_object_type,";
565 $sql .=
" t.src_object_id";
566 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
570 if (count($filter) > 0) {
571 foreach ($filter as $key => $value) {
572 if ($key ==
't.src_object_id') {
573 $sqlwhere[] = $key.
" = ".((int) $value);
575 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
579 $sql .=
' WHERE 1 = 1';
584 if (count($sqlwhere) > 0) {
585 $sql .=
' AND '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
587 if (!empty($sortfield)) {
588 $sql .= $this->db->order($sortfield, $sortorder);
590 if (!empty($limit)) {
591 $sql .= $this->db->plimit($limit, $offset);
594 $this->lines = array();
596 $resql = $this->db->query($sql);
598 $num = $this->db->num_rows($resql);
600 while ($obj = $this->db->fetch_object($resql)) {
603 $line->id = $obj->rowid;
604 $line->ref = $obj->rowid;
605 $line->label = $obj->label;
606 $line->share = $obj->share;
607 $line->entity = $obj->entity;
608 $line->filename = $obj->filename;
609 $line->filepath = $obj->filepath;
610 $line->fullpath_orig = $obj->fullpath_orig;
611 $line->description = $obj->description;
612 $line->keywords = $obj->keywords;
613 $line->cover = $obj->cover;
614 $line->position = $obj->position;
615 $line->gen_or_uploaded = $obj->gen_or_uploaded;
616 $line->extraparams = $obj->extraparams;
617 $line->date_c = $this->db->jdate($obj->date_c);
618 $line->date_m = $this->db->jdate($obj->date_m);
619 $line->fk_user_c = $obj->fk_user_c;
620 $line->fk_user_m = $obj->fk_user_m;
621 $line->acl = $obj->acl;
622 $line->src_object_type = $obj->src_object_type;
623 $line->src_object_id = $obj->src_object_id;
624 $this->lines[] = $line;
626 $this->db->free($resql);
630 $this->errors[] =
'Error '.$this->db->lasterror();
631 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
655 if (isset($this->
ref)) {
656 $this->
ref = trim($this->
ref);
658 if (isset($this->label)) {
659 $this->label = trim($this->label);
661 if (isset($this->share)) {
662 $this->share = trim($this->share);
664 if (isset($this->entity)) {
665 $this->entity = trim($this->entity);
667 if (isset($this->filename)) {
668 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
670 if (isset($this->filepath)) {
671 $this->filepath = trim($this->filepath);
672 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
674 if (isset($this->fullpath_orig)) {
675 $this->fullpath_orig = trim($this->fullpath_orig);
680 if (isset($this->keywords)) {
681 $this->keywords = trim($this->keywords);
683 if (isset($this->cover)) {
684 $this->cover = trim($this->cover);
686 if (isset($this->gen_or_uploaded)) {
687 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
689 if (isset($this->extraparams)) {
690 $this->extraparams = trim($this->extraparams);
692 if (isset($this->fk_user_m)) {
693 $this->fk_user_m = trim($this->fk_user_m);
695 if (isset($this->acl)) {
696 $this->acl = trim($this->acl);
698 if (isset($this->src_object_type)) {
699 $this->src_object_type = trim($this->src_object_type);
706 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
707 $sql .=
" ref = '".$this->db->escape(
dol_hash($this->filepath.
"/".$this->filename, 3)).
"',";
708 $sql .=
' label = '.(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
709 $sql .=
' share = '.(!empty($this->share) ?
"'".$this->db->escape($this->share).
"'" :
"null").
',';
710 $sql .=
' entity = '.(isset($this->entity) ? $this->entity : $conf->entity).
',';
711 $sql .=
' filename = '.(isset($this->filename) ?
"'".$this->db->escape($this->filename).
"'" :
"null").
',';
712 $sql .=
' filepath = '.(isset($this->filepath) ?
"'".$this->db->escape($this->filepath).
"'" :
"null").
',';
713 $sql .=
' fullpath_orig = '.(isset($this->fullpath_orig) ?
"'".$this->db->escape($this->fullpath_orig).
"'" :
"null").
',';
714 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
715 $sql .=
' keywords = '.(isset($this->keywords) ?
"'".$this->db->escape($this->keywords).
"'" :
"null").
',';
716 $sql .=
' cover = '.(isset($this->cover) ?
"'".$this->db->escape($this->cover).
"'" :
"null").
',';
717 $sql .=
' position = '.(isset($this->
position) ? $this->db->escape($this->
position) :
"0").
',';
718 $sql .=
' gen_or_uploaded = '.(isset($this->gen_or_uploaded) ?
"'".$this->db->escape($this->gen_or_uploaded).
"'" :
"null").
',';
719 $sql .=
' extraparams = '.(isset($this->extraparams) ?
"'".$this->db->escape($this->extraparams).
"'" :
"null").
',';
720 $sql .=
' date_c = '.(!isset($this->date_c) ||
dol_strlen($this->date_c) != 0 ?
"'".$this->db->idate($this->date_c).
"'" :
'null').
',';
722 $sql .=
' fk_user_m = '.($this->fk_user_m > 0 ? $this->fk_user_m : $user->id).
',';
723 $sql .=
' acl = '.(isset($this->acl) ?
"'".$this->db->escape($this->acl).
"'" :
"null").
',';
724 $sql .=
' src_object_id = '.($this->src_object_id > 0 ? $this->src_object_id :
"null").
',';
725 $sql .=
' src_object_type = '.(isset($this->src_object_type) ?
"'".$this->db->escape($this->src_object_type).
"'" :
"null");
726 $sql .=
' WHERE rowid='.((int) $this->
id);
730 $resql = $this->db->query($sql);
733 $this->errors[] =
'Error '.$this->db->lasterror();
734 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
738 if (!$error && !$notrigger) {
740 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
749 $this->db->rollback();
876 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
878 global $db, $conf, $langs;
879 global $dolibarr_main_authentication, $dolibarr_main_demo;
880 global $menumanager, $hookmanager;
882 if (!empty($conf->dol_no_mouse_hover)) {
888 $label =
'<u>'.$langs->trans(
"MyModule").
'</u>';
890 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
892 $url = DOL_URL_ROOT.
'/ecm/file_card.php?id='.$this->id;
895 if (empty($notooltip)) {
897 $label = $langs->trans(
"ShowProject");
898 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
900 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
901 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
903 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
906 $linkstart =
'<a href="'.$url.
'"';
907 $linkstart .= $linkclose.
'>';
911 $result .= ($linkstart.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
912 if ($withpicto != 2) {
916 $result .= $linkstart.$this->ref.$linkend;
919 $hookmanager->initHooks(array($this->element .
'dao'));
920 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
921 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
923 $result = $hookmanager->resPrint;
925 $result .= $hookmanager->resPrint;