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);
349 $resql = $this->db->query($sql);
352 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
353 $this->errors[] =
'Error DB_ERROR_RECORD_ALREADY_EXISTS : '.$this->db->lasterror();
355 $this->errors[] =
'Error '.$this->db->lasterror();
357 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
361 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
367 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_CREATE', $user);
377 $this->db->rollback();
399 public function fetch($id, $ref =
'', $relativepath =
'', $hashoffile =
'', $hashforshare =
'', $src_object_type =
'', $src_object_id = 0)
410 $sql .=
" t.entity,";
411 $sql .=
" t.filename,";
412 $sql .=
" t.filepath,";
413 $sql .=
" t.fullpath_orig,";
414 $sql .=
" t.description,";
415 $sql .=
" t.keywords,";
417 $sql .=
" t.position,";
418 $sql .=
" t.gen_or_uploaded,";
419 $sql .=
" t.extraparams,";
420 $sql .=
" t.date_c,";
421 $sql .=
" t.tms as date_m,";
422 $sql .=
" t.fk_user_c,";
423 $sql .=
" t.fk_user_m,";
424 $sql .=
' t.note_private,';
425 $sql .=
' t.note_public,';
427 $sql .=
" t.src_object_type,";
428 $sql .=
" t.src_object_id";
429 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
430 $sql .=
' WHERE 1 = 1';
437 $relativepathwithnoexe = preg_replace(
'/\.noexe$/',
'', $relativepath);
438 $sql .=
" AND t.filepath = '".$this->db->escape(dirname($relativepath)).
"'";
439 $filename = basename($relativepathwithnoexe);
440 if ($filename !=
'*') {
441 $sql .=
" AND t.filename = '".$this->db->escape($filename).
"'";
443 $sql .=
" AND t.entity = ".$conf->entity;
447 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
448 $sql .=
" AND t.entity = ".$conf->entity;
451 if (!empty($hashoffile)) {
452 $sql .=
" AND t.label = '".$this->db->escape($hashoffile).
"'";
453 $sql .=
" AND t.entity = ".$conf->entity;
456 if (!empty($hashforshare)) {
457 if ($hashforshare !=
'shared') {
458 $sql .=
" AND t.share = '".$this->db->escape($hashforshare).
"'";
460 $sql .=
" AND t.share IS NOT NULL AND t.share <> ''";
465 if ($src_object_type && $src_object_id) {
466 $sql .=
" AND t.src_object_type = '".$this->db->escape($src_object_type).
"' AND t.src_object_id = ".((int) $src_object_id);
467 $sql .=
" AND t.entity = ".((int) $conf->entity);
470 if ($id > 0 || empty($filterfound)) {
471 $sql .=
' AND t.rowid = '.((int) $id);
475 $this->db->plimit(1);
476 $this->db->order(
't.rowid',
'ASC');
478 $resql = $this->db->query($sql);
480 $numrows = $this->db->num_rows($resql);
482 $obj = $this->db->fetch_object($resql);
484 $this->
id = $obj->rowid;
485 $this->
ref = $obj->ref;
486 $this->label = $obj->label;
487 $this->share = $obj->share;
488 $this->entity = $obj->entity;
489 $this->filename = $obj->filename;
490 $this->filepath = $obj->filepath;
491 $this->fullpath_orig = $obj->fullpath_orig;
493 $this->keywords = $obj->keywords;
494 $this->cover = $obj->cover;
496 $this->gen_or_uploaded = $obj->gen_or_uploaded;
497 $this->extraparams = $obj->extraparams;
498 $this->date_c = $this->db->jdate($obj->date_c);
499 $this->date_m = $this->db->jdate($obj->date_m);
500 $this->fk_user_c = $obj->fk_user_c;
501 $this->fk_user_m = $obj->fk_user_m;
502 $this->note_private = $obj->note_private;
503 $this->note_public = $obj->note_public;
504 $this->acl = $obj->acl;
505 $this->src_object_type = $obj->src_object_type;
506 $this->src_object_id = $obj->src_object_id;
515 $this->db->free($resql);
523 $this->errors[] =
'Error '.$this->db->lasterror();
524 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
542 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $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';
571 if (count($filter) > 0) {
572 foreach ($filter as $key => $value) {
573 if ($key ==
't.src_object_id') {
574 $sqlwhere[] = $key.
" = ".((int) $value);
576 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
580 $sql .=
' WHERE 1 = 1';
585 if (count($sqlwhere) > 0) {
586 $sql .=
' AND '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
588 if (!empty($sortfield)) {
589 $sql .= $this->db->order($sortfield, $sortorder);
591 if (!empty($limit)) {
592 $sql .= $this->db->plimit($limit, $offset);
595 $this->lines = array();
597 $resql = $this->db->query($sql);
599 $num = $this->db->num_rows($resql);
601 while ($obj = $this->db->fetch_object($resql)) {
604 $line->id = $obj->rowid;
605 $line->ref = $obj->rowid;
606 $line->label = $obj->label;
607 $line->share = $obj->share;
608 $line->entity = $obj->entity;
609 $line->filename = $obj->filename;
610 $line->filepath = $obj->filepath;
611 $line->fullpath_orig = $obj->fullpath_orig;
612 $line->description = $obj->description;
613 $line->keywords = $obj->keywords;
614 $line->cover = $obj->cover;
615 $line->position = $obj->position;
616 $line->gen_or_uploaded = $obj->gen_or_uploaded;
617 $line->extraparams = $obj->extraparams;
618 $line->date_c = $this->db->jdate($obj->date_c);
619 $line->date_m = $this->db->jdate($obj->date_m);
620 $line->fk_user_c = $obj->fk_user_c;
621 $line->fk_user_m = $obj->fk_user_m;
622 $line->acl = $obj->acl;
623 $line->src_object_type = $obj->src_object_type;
624 $line->src_object_id = $obj->src_object_id;
625 $this->lines[] = $line;
627 $this->db->free($resql);
631 $this->errors[] =
'Error '.$this->db->lasterror();
632 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
656 if (isset($this->
ref)) {
657 $this->
ref = trim($this->
ref);
659 if (isset($this->label)) {
660 $this->label = trim($this->label);
662 if (isset($this->share)) {
663 $this->share = trim($this->share);
665 if (isset($this->entity)) {
666 $this->entity = trim($this->entity);
668 if (isset($this->filename)) {
669 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
671 if (isset($this->filepath)) {
672 $this->filepath = trim($this->filepath);
673 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
675 if (isset($this->fullpath_orig)) {
676 $this->fullpath_orig = trim($this->fullpath_orig);
681 if (isset($this->keywords)) {
682 $this->keywords = trim($this->keywords);
684 if (isset($this->cover)) {
685 $this->cover = trim($this->cover);
687 if (isset($this->gen_or_uploaded)) {
688 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
690 if (isset($this->extraparams)) {
691 $this->extraparams = trim($this->extraparams);
693 if (isset($this->fk_user_m)) {
694 $this->fk_user_m = trim($this->fk_user_m);
696 if (isset($this->acl)) {
697 $this->acl = trim($this->acl);
699 if (isset($this->src_object_type)) {
700 $this->src_object_type = trim($this->src_object_type);
707 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
708 $sql .=
" ref = '".$this->db->escape(
dol_hash($this->filepath.
"/".$this->filename, 3)).
"',";
709 $sql .=
' label = '.(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
710 $sql .=
' share = '.(!empty($this->share) ?
"'".$this->db->escape($this->share).
"'" :
"null").
',';
711 $sql .=
' entity = '.(isset($this->entity) ? $this->entity : $conf->entity).
',';
712 $sql .=
' filename = '.(isset($this->filename) ?
"'".$this->db->escape($this->filename).
"'" :
"null").
',';
713 $sql .=
' filepath = '.(isset($this->filepath) ?
"'".$this->db->escape($this->filepath).
"'" :
"null").
',';
714 $sql .=
' fullpath_orig = '.(isset($this->fullpath_orig) ?
"'".$this->db->escape($this->fullpath_orig).
"'" :
"null").
',';
715 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
716 $sql .=
' keywords = '.(isset($this->keywords) ?
"'".$this->db->escape($this->keywords).
"'" :
"null").
',';
717 $sql .=
' cover = '.(isset($this->cover) ?
"'".$this->db->escape($this->cover).
"'" :
"null").
',';
718 $sql .=
' position = '.(isset($this->
position) ? $this->db->escape($this->
position) :
"0").
',';
719 $sql .=
' gen_or_uploaded = '.(isset($this->gen_or_uploaded) ?
"'".$this->db->escape($this->gen_or_uploaded).
"'" :
"null").
',';
720 $sql .=
' extraparams = '.(isset($this->extraparams) ?
"'".$this->db->escape($this->extraparams).
"'" :
"null").
',';
721 $sql .=
' date_c = '.(!isset($this->date_c) ||
dol_strlen($this->date_c) != 0 ?
"'".$this->db->idate($this->date_c).
"'" :
'null').
',';
723 $sql .=
' fk_user_m = '.($this->fk_user_m > 0 ? $this->fk_user_m : $user->id).
',';
724 $sql .=
' acl = '.(isset($this->acl) ?
"'".$this->db->escape($this->acl).
"'" :
"null").
',';
725 $sql .=
' src_object_id = '.($this->src_object_id > 0 ? $this->src_object_id :
"null").
',';
726 $sql .=
' src_object_type = '.(isset($this->src_object_type) ?
"'".$this->db->escape($this->src_object_type).
"'" :
"null");
727 $sql .=
' WHERE rowid='.((int) $this->
id);
731 $resql = $this->db->query($sql);
734 $this->errors[] =
'Error '.$this->db->lasterror();
735 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
739 if (!$error && !$notrigger) {
741 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
750 $this->db->rollback();
877 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
879 global $db, $conf, $langs;
880 global $dolibarr_main_authentication, $dolibarr_main_demo;
881 global $menumanager, $hookmanager;
883 if (!empty($conf->dol_no_mouse_hover)) {
889 $label =
'<u>'.$langs->trans(
"MyModule").
'</u>';
891 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
893 $url = DOL_URL_ROOT.
'/ecm/'.$this->table_name.
'_card.php?id='.$this->id;
896 if (empty($notooltip)) {
897 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
898 $label = $langs->trans(
"ShowProject");
899 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
901 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
902 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
904 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
907 $linkstart =
'<a href="'.$url.
'"';
908 $linkstart .= $linkclose.
'>';
912 $result .= ($linkstart.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
913 if ($withpicto != 2) {
917 $result .= $linkstart.$this->ref.$linkend;
920 $hookmanager->initHooks(array($this->element .
'dao'));
921 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
922 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
924 $result = $hookmanager->resPrint;
926 $result .= $hookmanager->resPrint;