212 if (isset($this->
ref)) {
213 $this->
ref = trim($this->
ref);
215 if (isset($this->label)) {
216 $this->label = trim($this->label);
218 if (isset($this->share)) {
219 $this->share = trim($this->share);
221 if (isset($this->entity)) {
222 $this->entity = (int) $this->entity;
224 if (isset($this->filename)) {
225 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
227 if (isset($this->filepath)) {
228 $this->filepath = trim($this->filepath);
229 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
231 if (isset($this->fullpath_orig)) {
232 $this->fullpath_orig = trim($this->fullpath_orig);
237 if (isset($this->keywords)) {
238 $this->keywords = trim($this->keywords);
240 if (isset($this->cover)) {
241 $this->cover = trim($this->cover);
243 if (isset($this->gen_or_uploaded)) {
244 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
246 if (isset($this->extraparams)) {
247 $this->extraparams = trim($this->extraparams);
249 if (isset($this->fk_user_c)) {
250 $this->fk_user_c = (int) $this->fk_user_c;
252 if (isset($this->fk_user_m)) {
253 $this->fk_user_m = (int) $this->fk_user_m;
255 if (isset($this->acl)) {
256 $this->acl = trim($this->acl);
258 if (isset($this->src_object_type)) {
259 $this->src_object_type = trim($this->src_object_type);
261 if (empty($this->date_c)) {
264 if (empty($this->date_m)) {
269 if (empty($this->
ref)) {
270 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
271 $this->
ref =
dol_hash($this->filepath.
'/'.$this->filename, 3);
277 $sql =
"SELECT MAX(position) as maxposition FROM ".MAIN_DB_PREFIX.$this->table_element;
278 $sql .=
" WHERE filepath ='".$this->db->escape($this->filepath).
"'";
280 $resql = $this->db->query($sql);
282 $obj = $this->db->fetch_object($resql);
283 $maxposition = (int) $obj->maxposition;
285 $this->errors[] =
'Error '.$this->db->lasterror();
288 $maxposition = $maxposition + 1;
290 $maxposition = $this->position;
294 if (empty($this->filename) || empty($this->filepath)) {
295 $this->errors[] =
'Bad property filename or filepath';
298 if (!isset($this->entity)) {
299 $this->entity = $conf->entity;
304 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
311 $sql .=
'fullpath_orig,';
312 $sql .=
'description,';
316 $sql .=
'gen_or_uploaded,';
317 $sql .=
'extraparams,';
320 $sql .=
'fk_user_c,';
321 $sql .=
'fk_user_m,';
323 $sql .=
'src_object_type,';
324 $sql .=
'src_object_id';
325 $sql .=
') VALUES (';
326 $sql .=
" '".$this->db->escape($this->
ref).
"', ";
327 $sql .=
' '.(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
',';
328 $sql .=
' '.(!isset($this->share) ?
'NULL' :
"'".$this->db->escape($this->share).
"'").
',';
329 $sql .=
' '.((int) $this->entity).
',';
330 $sql .=
' '.(!isset($this->filename) ?
'NULL' :
"'".$this->db->escape($this->filename).
"'").
',';
331 $sql .=
' '.(!isset($this->filepath) ?
'NULL' :
"'".$this->db->escape($this->filepath).
"'").
',';
332 $sql .=
' '.(!isset($this->fullpath_orig) ?
'NULL' :
"'".$this->db->escape($this->fullpath_orig).
"'").
',';
334 $sql .=
' '.(!isset($this->keywords) ?
'NULL' :
"'".$this->db->escape($this->keywords).
"'").
',';
335 $sql .=
' '.(!isset($this->cover) ?
'NULL' :
"'".$this->db->escape($this->cover).
"'").
',';
336 $sql .=
' '.((int) $maxposition).
',';
337 $sql .=
' '.(!isset($this->gen_or_uploaded) ?
'NULL' :
"'".$this->db->escape($this->gen_or_uploaded).
"'").
',';
338 $sql .=
' '.(!isset($this->extraparams) ?
'NULL' :
"'".$this->db->escape($this->extraparams).
"'").
',';
339 $sql .=
" '".$this->db->idate($this->date_c).
"',";
340 $sql .=
' '.(!isset($this->date_m) ||
dol_strlen($this->date_m) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_m).
"'").
',';
341 $sql .=
' '.(!isset($this->fk_user_c) ? $user->id : $this->fk_user_c).
',';
342 $sql .=
' '.(!isset($this->fk_user_m) ?
'NULL' : $this->fk_user_m).
',';
343 $sql .=
' '.(!isset($this->acl) ?
'NULL' :
"'".$this->db->escape($this->acl).
"'").
',';
344 $sql .=
' '.(!isset($this->src_object_type) ?
'NULL' :
"'".$this->db->escape($this->src_object_type).
"'").
',';
345 $sql .=
' '.(!isset($this->src_object_id) ?
'NULL' : $this->src_object_id);
350 $resql = $this->db->query($sql);
353 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
354 $this->errors[] =
'Error DB_ERROR_RECORD_ALREADY_EXISTS : '.$this->db->lasterror();
356 $this->errors[] =
'Error '.$this->db->lasterror();
358 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
362 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
368 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_CREATE', $user);
378 $this->db->rollback();
400 public function fetch($id, $ref =
'', $relativepath =
'', $hashoffile =
'', $hashforshare =
'', $src_object_type =
'', $src_object_id = 0)
411 $sql .=
" t.entity,";
412 $sql .=
" t.filename,";
413 $sql .=
" t.filepath,";
414 $sql .=
" t.fullpath_orig,";
415 $sql .=
" t.description,";
416 $sql .=
" t.keywords,";
418 $sql .=
" t.position,";
419 $sql .=
" t.gen_or_uploaded,";
420 $sql .=
" t.extraparams,";
421 $sql .=
" t.date_c,";
422 $sql .=
" t.tms as date_m,";
423 $sql .=
" t.fk_user_c,";
424 $sql .=
" t.fk_user_m,";
425 $sql .=
' t.note_private,';
426 $sql .=
' t.note_public,';
428 $sql .=
" t.src_object_type,";
429 $sql .=
" t.src_object_id";
430 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
431 $sql .=
' WHERE 1 = 1';
438 $relativepathwithnoexe = preg_replace(
'/\.noexe$/',
'', $relativepath);
439 $sql .=
" AND t.filepath = '".$this->db->escape(dirname($relativepath)).
"'";
440 $filename = basename($relativepathwithnoexe);
441 if ($filename !=
'*') {
442 $sql .=
" AND t.filename = '".$this->db->escape($filename).
"'";
444 $sql .=
" AND t.entity = ".$conf->entity;
448 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
449 $sql .=
" AND t.entity = ".$conf->entity;
452 if (!empty($hashoffile)) {
453 $sql .=
" AND t.label = '".$this->db->escape($hashoffile).
"'";
454 $sql .=
" AND t.entity = ".$conf->entity;
457 if (!empty($hashforshare)) {
458 if ($hashforshare !=
'shared') {
459 $sql .=
" AND t.share = '".$this->db->escape($hashforshare).
"'";
461 $sql .=
" AND t.share IS NOT NULL AND t.share <> ''";
466 if ($src_object_type && $src_object_id) {
467 $sql .=
" AND t.src_object_type = '".$this->db->escape($src_object_type).
"' AND t.src_object_id = ".((int) $src_object_id);
468 $sql .=
" AND t.entity = ".((int) $conf->entity);
471 if ($id > 0 || empty($filterfound)) {
472 $sql .=
' AND t.rowid = '.((int) $id);
476 $this->db->plimit(1);
477 $this->db->order(
't.rowid',
'ASC');
479 $resql = $this->db->query($sql);
481 $numrows = $this->db->num_rows($resql);
483 $obj = $this->db->fetch_object($resql);
485 $this->
id = $obj->rowid;
486 $this->
ref = $obj->ref;
487 $this->label = $obj->label;
488 $this->share = $obj->share;
489 $this->entity = $obj->entity;
490 $this->filename = $obj->filename;
491 $this->filepath = $obj->filepath;
492 $this->fullpath_orig = $obj->fullpath_orig;
494 $this->keywords = $obj->keywords;
495 $this->cover = $obj->cover;
497 $this->gen_or_uploaded = $obj->gen_or_uploaded;
498 $this->extraparams = $obj->extraparams;
499 $this->date_c = $this->db->jdate($obj->date_c);
500 $this->date_m = $this->db->jdate($obj->date_m);
501 $this->fk_user_c = $obj->fk_user_c;
502 $this->fk_user_m = $obj->fk_user_m;
503 $this->note_private = $obj->note_private;
504 $this->note_public = $obj->note_public;
505 $this->acl = $obj->acl;
506 $this->src_object_type = $obj->src_object_type;
507 $this->src_object_id = $obj->src_object_id;
516 $this->db->free($resql);
524 $this->errors[] =
'Error '.$this->db->lasterror();
525 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
542 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
550 $sql .=
" t.entity,";
551 $sql .=
" t.filename,";
552 $sql .=
" t.filepath,";
553 $sql .=
" t.fullpath_orig,";
554 $sql .=
" t.description,";
555 $sql .=
" t.keywords,";
557 $sql .=
" t.position,";
558 $sql .=
" t.gen_or_uploaded,";
559 $sql .=
" t.extraparams,";
560 $sql .=
" t.date_c,";
561 $sql .=
" t.tms as date_m,";
562 $sql .=
" t.fk_user_c,";
563 $sql .=
" t.fk_user_m,";
565 $sql .=
" t.src_object_type,";
566 $sql .=
" t.src_object_id";
567 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
568 $sql .=
' WHERE 1 = 1';
571 if (is_array($filter)) {
573 if (count($filter) > 0) {
574 foreach ($filter as $key => $value) {
575 if ($key ==
't.src_object_id') {
576 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
578 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
582 if (count($sqlwhere) > 0) {
583 $sql .=
' AND '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
593 $this->errors[] = $errormessage;
594 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
602 if (!empty($sortfield)) {
603 $sql .= $this->db->order($sortfield, $sortorder);
605 if (!empty($limit)) {
606 $sql .= $this->db->plimit($limit, $offset);
609 $this->lines = array();
611 $resql = $this->db->query($sql);
613 $num = $this->db->num_rows($resql);
615 while ($obj = $this->db->fetch_object($resql)) {
618 $line->id = $obj->rowid;
619 $line->ref = $obj->rowid;
620 $line->label = $obj->label;
621 $line->share = $obj->share;
622 $line->entity = $obj->entity;
623 $line->filename = $obj->filename;
624 $line->filepath = $obj->filepath;
625 $line->fullpath_orig = $obj->fullpath_orig;
626 $line->description = $obj->description;
627 $line->keywords = $obj->keywords;
628 $line->cover = $obj->cover;
629 $line->position = $obj->position;
630 $line->gen_or_uploaded = $obj->gen_or_uploaded;
631 $line->extraparams = $obj->extraparams;
632 $line->date_c = $this->db->jdate($obj->date_c);
633 $line->date_m = $this->db->jdate($obj->date_m);
634 $line->fk_user_c = $obj->fk_user_c;
635 $line->fk_user_m = $obj->fk_user_m;
636 $line->acl = $obj->acl;
637 $line->src_object_type = $obj->src_object_type;
638 $line->src_object_id = $obj->src_object_id;
639 $this->lines[] = $line;
641 $this->db->free($resql);
645 $this->errors[] =
'Error '.$this->db->lasterror();
646 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
669 if (isset($this->
ref)) {
670 $this->
ref = trim($this->
ref);
672 if (isset($this->label)) {
673 $this->label = trim($this->label);
675 if (isset($this->share)) {
676 $this->share = trim($this->share);
678 if (isset($this->entity)) {
679 $this->entity = (int) $this->entity;
681 if (isset($this->filename)) {
682 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
684 if (isset($this->filepath)) {
685 $this->filepath = trim($this->filepath);
686 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
688 if (isset($this->fullpath_orig)) {
689 $this->fullpath_orig = trim($this->fullpath_orig);
694 if (isset($this->keywords)) {
695 $this->keywords = trim($this->keywords);
697 if (isset($this->cover)) {
698 $this->cover = trim($this->cover);
700 if (isset($this->gen_or_uploaded)) {
701 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
703 if (isset($this->extraparams)) {
704 $this->extraparams = trim($this->extraparams);
706 if (isset($this->fk_user_m)) {
707 $this->fk_user_m = (int) $this->fk_user_m;
709 if (isset($this->acl)) {
710 $this->acl = trim($this->acl);
712 if (isset($this->src_object_type)) {
713 $this->src_object_type = trim($this->src_object_type);
720 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
721 $sql .=
" ref = '".$this->db->escape(
dol_hash($this->filepath.
"/".$this->filename, 3)).
"',";
722 $sql .=
' label = '.(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
723 $sql .=
' share = '.(!empty($this->share) ?
"'".$this->db->escape($this->share).
"'" :
"null").
',';
724 $sql .=
' entity = '.(isset($this->entity) ? $this->entity : $conf->entity).
',';
725 $sql .=
' filename = '.(isset($this->filename) ?
"'".$this->db->escape($this->filename).
"'" :
"null").
',';
726 $sql .=
' filepath = '.(isset($this->filepath) ?
"'".$this->db->escape($this->filepath).
"'" :
"null").
',';
727 $sql .=
' fullpath_orig = '.(isset($this->fullpath_orig) ?
"'".$this->db->escape($this->fullpath_orig).
"'" :
"null").
',';
728 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
729 $sql .=
' keywords = '.(isset($this->keywords) ?
"'".$this->db->escape($this->keywords).
"'" :
"null").
',';
730 $sql .=
' cover = '.(isset($this->cover) ?
"'".$this->db->escape($this->cover).
"'" :
"null").
',';
731 $sql .=
' position = '.(isset($this->
position) ? $this->db->escape($this->
position) :
"0").
',';
732 $sql .=
' gen_or_uploaded = '.(isset($this->gen_or_uploaded) ?
"'".$this->db->escape($this->gen_or_uploaded).
"'" :
"null").
',';
733 $sql .=
' extraparams = '.(isset($this->extraparams) ?
"'".$this->db->escape($this->extraparams).
"'" :
"null").
',';
734 $sql .=
' date_c = '.(!isset($this->date_c) ||
dol_strlen($this->date_c) != 0 ?
"'".$this->db->idate($this->date_c).
"'" :
'null').
',';
736 $sql .=
' fk_user_m = '.($this->fk_user_m > 0 ? $this->fk_user_m : $user->id).
',';
737 $sql .=
' acl = '.(isset($this->acl) ?
"'".$this->db->escape($this->acl).
"'" :
"null").
',';
738 $sql .=
' src_object_id = '.($this->src_object_id > 0 ? $this->src_object_id :
"null").
',';
739 $sql .=
' src_object_type = '.(isset($this->src_object_type) ?
"'".$this->db->escape($this->src_object_type).
"'" :
"null");
740 $sql .=
' WHERE rowid='.((int) $this->
id);
744 $resql = $this->db->query($sql);
747 $this->errors[] =
'Error '.$this->db->lasterror();
748 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
760 if (!$error && !$notrigger) {
762 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
771 $this->db->rollback();
897 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
899 global $db, $conf, $langs;
900 global $dolibarr_main_authentication, $dolibarr_main_demo;
901 global $menumanager, $hookmanager;
903 if (!empty($conf->dol_no_mouse_hover)) {
909 $label =
'<u>'.$langs->trans(
"MyModule").
'</u>';
911 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
913 $url = DOL_URL_ROOT.
'/ecm/file_card.php?id='.$this->id;
916 if (empty($notooltip)) {
918 $label = $langs->trans(
"ShowProject");
919 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
921 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
922 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
924 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
927 $linkstart =
'<a href="'.$url.
'"';
928 $linkstart .= $linkclose.
'>';
932 $result .= ($linkstart.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
933 if ($withpicto != 2) {
937 $result .= $linkstart.$this->ref.$linkend;
940 $hookmanager->initHooks(array($this->element .
'dao'));
941 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
942 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
944 $result = $hookmanager->resPrint;
946 $result .= $hookmanager->resPrint;