31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
42 public $element =
'ecmfiles';
47 public $table_element =
'ecm_files';
52 public $picto =
'folder-open';
88 public $fullpath_orig;
118 public $gen_or_uploaded;
153 public $src_object_type;
158 public $src_object_id;
170 public $fields = array(
171 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 1,
'notnull' => 1,
'visible' => 0,
'noteditable' => 1,
'index' => 1,
'css' =>
'left',
'comment' =>
"Id"),
172 'ref' => array(
'type' =>
'varchar(128)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 20,
'notnull' => 1,
'visible' => -1,
'index' => 1,
'searchall' => 1,
'showoncombobox' => 1,
'validate' => 1,
'comment' =>
"contains hash from filename+filepath"),
173 'label' => array(
'type' =>
'varchar(128)',
'label' =>
'Label',
'enabled' => 1,
'position' => 30,
'notnull' => 0,
'visible' => -1,
'searchall' => 1,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'showoncombobox' => 2,
'validate' => 1,
'comment' =>
"contains hash of file content"),
174 'share' => array(
'type' =>
'varchar(128)',
'label' =>
'Share',
'enabled' => 1,
'position' => 40,
'notnull' => 0,
'visible' => -1,
'searchall' => 1,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'showoncombobox' => 2,
'validate' => 1,
'comment' =>
"contains hash for file sharing"),
175 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 50,
'index' => 1),
176 'filepath' => array(
'type' =>
'varchar(255)',
'label' =>
'FilePath',
'enabled' => 1,
'position' => 60,
'notnull' => 0,
'visible' => 0,
'searchall' => 0,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'showoncombobox' => 2,
'validate' => 1,
'comment' =>
"relative to dolibarr document dir. Example module/def"),
177 'filename' => array(
'type' =>
'varchar(255)',
'label' =>
'FileName',
'enabled' => 1,
'position' => 70,
'notnull' => 0,
'visible' => 1,
'searchall' => 1,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'showoncombobox' => 2,
'validate' => 1,
'comment' =>
"file name only without any directory"),
178 'src_object_type' => array(
'type' =>
'varchar(64)',
'label' =>
'SourceType',
'enabled' => 1,
'position' => 80,
'notnull' => 0,
'visible' => 0,
'searchall' => 1,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'showoncombobox' => 2,
'validate' => 1,
'comment' =>
"Source object type ('proposal', 'invoice', ...)"),
179 'src_object_id' => array(
'type' =>
'integer',
'label' =>
'SourceID',
'default' =>
'1',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 90,
'index' => 1,
'comment' =>
"Source object id"),
180 'fullpath_orig' => array(
'type' =>
'varchar(750)',
'label' =>
'FullPathOrig',
'enabled' => 1,
'position' => 100,
'notnull' => 0,
'visible' => 0,
'searchall' => 0,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'showoncombobox' => 2,
'validate' => 1,
'comment' =>
"full path of original filename, when file is uploaded from a local computer"),
181 'description' => array(
'type' =>
'text',
'label' =>
'Description',
'enabled' => 1,
'visible' => 0,
'position' => 110),
182 'keywords' => array(
'type' =>
'varchar(750)',
'label' =>
'Keywords',
'enabled' => 1,
'position' => 120,
'notnull' => 0,
'visible' => 1,
'searchall' => 1,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'showoncombobox' => 2,
'validate' => 1,
'comment' =>
"list of keywords, separated with comma. Must be limited to most important keywords."),
183 'content' => array(
'type' =>
'html',
'label' =>
'Content',
'enabled' =>
'getDolGlobalString("MAIN_SAVE_FILE_CONTENT_AS_TEXT")',
'position' => 120,
'notnull' => 0,
'visible' => 1,
'searchall' => 1,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'csslist' =>
'tdoverflowmax200',
'help' =>
"Text content of file",
'showoncombobox' => 2,
'validate' => 1,
'comment' =>
"Text content if option to store txt content was set."),
184 'cover' => array(
'type' =>
'text',
'label' =>
'Cover',
'enabled' => 1,
'visible' => 0,
'position' => 130,
'comment' =>
"is this file a file to use for a cover"),
185 'position' => array(
'type' =>
'integer',
'label' =>
'Position',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 140,
'index' => 1,
'comment' =>
"position of file among others"),
186 'gen_or_uploaded' => array(
'type' =>
'varchar(12)',
'label' =>
'GenOrUpload',
'enabled' => 1,
'position' => 150,
'notnull' => 0,
'visible' => -1,
'searchall' => 1,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'showoncombobox' => 2,
'validate' => 1,
'comment' =>
"'generated' or 'uploaded'"),
187 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'ExtraParams',
'enabled' => 1,
'position' => 160,
'notnull' => 0,
'visible' => 1,
'searchall' => 1,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'showoncombobox' => 2,
'validate' => 1,
'comment' =>
"for stocking other parameters with json format"),
188 'date_c' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 170),
189 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 175),
190 'fk_user_c' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'position' => 510,
'notnull' => 1,
'visible' => -2,
'foreignkey' =>
'user.rowid',),
191 'fk_user_m' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'position' => 511,
'notnull' => -1,
'visible' => -2,),
192 'note_public' => array(
'type' =>
'text',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 155),
193 'note_private' => array(
'type' =>
'text',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 160),
194 'acl' => array(
'type' =>
'text',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 160,
'comment' =>
"for future permission 'per file'"),
195 'agenda_id' => array(
'type' =>
'integer',
'label' =>
'IdAgenda',
'enabled' => 1,
'visible' => 0,
'position' => 180,
'comment' =>
"Link to an actioncomm"),
225 if (isset($this->
ref)) {
226 $this->
ref = trim($this->
ref);
228 if (isset($this->label)) {
229 $this->label = trim($this->label);
231 if (isset($this->share)) {
232 $this->share = trim($this->share);
234 if (isset($this->entity)) {
235 $this->entity = (int) $this->entity;
237 if (isset($this->filename)) {
238 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
240 if (isset($this->filepath)) {
241 $this->filepath = trim($this->filepath);
242 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
244 if (isset($this->fullpath_orig)) {
245 $this->fullpath_orig = trim($this->fullpath_orig);
250 if (isset($this->keywords)) {
251 $this->keywords = trim($this->keywords);
253 if (isset($this->cover)) {
254 $this->cover = trim($this->cover);
256 if (isset($this->gen_or_uploaded)) {
257 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
259 if (isset($this->fk_user_c)) {
260 $this->fk_user_c = (int) $this->fk_user_c;
262 if (isset($this->fk_user_m)) {
263 $this->fk_user_m = (int) $this->fk_user_m;
265 if (isset($this->acl)) {
266 $this->acl = trim($this->acl);
268 if (isset($this->src_object_type)) {
269 $this->src_object_type = trim($this->src_object_type);
271 if (empty($this->date_c)) {
274 if (empty($this->date_m)) {
279 if (empty($this->
ref)) {
280 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
281 $this->
ref =
dol_hash($this->filepath.
'/'.$this->filename,
'3');
287 $sql =
"SELECT MAX(position) as maxposition FROM ".MAIN_DB_PREFIX.$this->table_element;
288 $sql .=
" WHERE filepath ='".$this->db->escape($this->filepath).
"'";
290 $resql = $this->db->query($sql);
292 $obj = $this->db->fetch_object($resql);
293 $maxposition = (int) $obj->maxposition;
295 $this->errors[] =
'Error '.$this->db->lasterror();
300 $maxposition = $this->position;
304 if (empty($this->filename) || empty($this->filepath)) {
305 $this->errors[] =
'Bad property filename or filepath';
308 if (!isset($this->entity)) {
309 $this->entity =
$conf->entity;
312 $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) :
null);
313 $extraparams =
dol_trunc($extraparams, 250);
316 if (!empty($this->agenda_id)) {
317 $this->agenda_id = (int) $this->agenda_id;
321 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
328 $sql .=
'fullpath_orig,';
329 $sql .=
'description,';
336 $sql .=
'gen_or_uploaded,';
337 $sql .=
'extraparams,';
340 $sql .=
'fk_user_c,';
341 $sql .=
'fk_user_m,';
343 $sql .=
'src_object_type,';
344 $sql .=
'src_object_id,';
346 $sql .=
') VALUES (';
347 $sql .=
" '".$this->db->escape($this->
ref).
"', ";
348 $sql .=
' '.(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
',';
349 $sql .=
' '.(!isset($this->share) ?
'NULL' :
"'".$this->db->escape($this->share).
"'").
',';
350 $sql .=
' '.((int) $this->entity).
',';
351 $sql .=
' '.(!isset($this->filename) ?
'NULL' :
"'".$this->db->escape($this->filename).
"'").
',';
352 $sql .=
' '.(!isset($this->filepath) ?
'NULL' :
"'".$this->db->escape($this->filepath).
"'").
',';
353 $sql .=
' '.(!isset($this->fullpath_orig) ?
'NULL' :
"'".$this->db->escape($this->fullpath_orig).
"'").
',';
355 $sql .=
' '.(!isset($this->keywords) ?
'NULL' :
"'".$this->db->escape($this->keywords).
"'").
',';
357 $sql .=
' '.(!isset($this->content) ?
'NULL' :
"'".$this->db->escape($this->content).
"'").
',';
359 $sql .=
' '.(!isset($this->cover) ?
'NULL' :
"'".$this->db->escape($this->cover).
"'").
',';
360 $sql .=
' '.((int) $maxposition).
',';
361 $sql .=
' '.(!isset($this->gen_or_uploaded) ?
'NULL' :
"'".$this->db->escape($this->gen_or_uploaded).
"'").
',';
362 $sql .=
' '.(!isset($extraparams) ?
'NULL' :
"'".$this->db->escape($extraparams).
"'").
',';
363 $sql .=
" '".$this->db->idate($this->date_c).
"',";
364 $sql .=
' '.(!isset($this->date_m) ||
dol_strlen((
string) $this->date_m) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_m).
"'").
',';
365 $sql .=
' '.(!isset($this->fk_user_c) ? $user->id : $this->fk_user_c).
',';
366 $sql .=
' '.(!isset($this->fk_user_m) ?
'NULL' : $this->fk_user_m).
',';
367 $sql .=
' '.(!isset($this->acl) ?
'NULL' :
"'".$this->db->escape($this->acl).
"'").
',';
368 $sql .=
' '.(!isset($this->src_object_type) ?
'NULL' :
"'".$this->db->escape($this->src_object_type).
"'").
',';
369 $sql .=
' '.(!isset($this->src_object_id) ?
'NULL' : $this->src_object_id).
',';
370 $sql .=
' '.(empty($this->agenda_id) ?
'NULL' : (int) $this->agenda_id);
375 $resql = $this->db->query($sql);
378 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
379 $this->errors[] =
'Error DB_ERROR_RECORD_ALREADY_EXISTS : '.$this->db->lasterror();
381 $this->errors[] =
'Error '.$this->db->lasterror();
383 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
387 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
393 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_CREATE', $user);
403 $this->db->rollback();
426 public function fetch($id, $ref =
'', $relativepath =
'', $hashoffile =
'', $hashforshare =
'', $src_object_type =
'', $src_object_id = 0, $entity = 0)
437 $sql .=
" t.entity,";
438 $sql .=
" t.filename,";
439 $sql .=
" t.filepath,";
440 $sql .=
" t.fullpath_orig,";
441 $sql .=
" t.description,";
442 $sql .=
" t.keywords,";
444 $sql .=
" t.content,";
447 $sql .=
" t.position,";
448 $sql .=
" t.gen_or_uploaded,";
449 $sql .=
" t.extraparams,";
450 $sql .=
" t.date_c,";
451 $sql .=
" t.tms as date_m,";
452 $sql .=
" t.fk_user_c,";
453 $sql .=
" t.fk_user_m,";
454 $sql .=
' t.note_private,';
455 $sql .=
' t.note_public,';
457 $sql .=
" t.src_object_type,";
458 $sql .=
" t.src_object_id,";
459 $sql .=
" t.agenda_id";
460 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
461 $sql .=
' WHERE 1 = 1';
468 $relativepathwithnoexe = preg_replace(
'/\.noexe$/',
'', $relativepath);
469 $sql .=
" AND t.filepath = '".$this->db->escape(dirname($relativepath)).
"'";
470 $filename = basename($relativepathwithnoexe);
471 if ($filename !=
'*') {
472 $sql .=
" AND t.filename = '".$this->db->escape($filename).
"'";
474 if (! empty($entity)) {
475 $sql .=
" AND t.entity = " . (int) $entity;
477 $sql .=
" AND t.entity = " .
$conf->entity;
482 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
483 if (! empty($entity)) {
484 $sql .=
" AND t.entity = " . (int) $entity;
486 $sql .=
" AND t.entity = " .
$conf->entity;
490 if (!empty($hashoffile)) {
491 $sql .=
" AND t.label = '".$this->db->escape($hashoffile).
"'";
492 if (! empty($entity)) {
493 $sql .=
" AND t.entity = " . (int) $entity;
495 $sql .=
" AND t.entity = " .
$conf->entity;
499 if (!empty($hashforshare)) {
500 if ($hashforshare !=
'shared') {
501 $sql .=
" AND t.share = '".$this->db->escape($hashforshare).
"'";
503 $sql .=
" AND t.share IS NOT NULL AND t.share <> ''";
508 if ($src_object_type && $src_object_id) {
509 $sql .=
" AND t.src_object_type = '".$this->db->escape($src_object_type).
"' AND t.src_object_id = ".((int) $src_object_id);
510 if (! empty($entity)) {
511 $sql .=
" AND t.entity = " . (int) $entity;
513 $sql .=
" AND t.entity = " .
$conf->entity;
517 if ($id > 0 || empty($filterfound)) {
518 $sql .=
' AND t.rowid = '.((int) $id);
522 $this->db->plimit(1);
523 $this->db->order(
't.rowid',
'ASC');
525 $resql = $this->db->query($sql);
527 $numrows = $this->db->num_rows($resql);
529 $obj = $this->db->fetch_object($resql);
531 $this->
id = $obj->rowid;
532 $this->
ref = $obj->ref;
533 $this->label = $obj->label;
534 $this->share = $obj->share;
535 $this->entity = $obj->entity;
536 $this->filename = $obj->filename;
537 $this->filepath = $obj->filepath;
538 $this->fullpath_orig = $obj->fullpath_orig;
540 $this->keywords = $obj->keywords;
542 $this->content = $obj->content;
544 $this->cover = $obj->cover;
546 $this->gen_or_uploaded = $obj->gen_or_uploaded;
547 $this->date_c = $this->db->jdate($obj->date_c);
548 $this->date_m = $this->db->jdate($obj->date_m);
549 $this->fk_user_c = $obj->fk_user_c;
550 $this->fk_user_m = $obj->fk_user_m;
551 $this->note_private = $obj->note_private;
552 $this->note_public = $obj->note_public;
553 $this->acl = $obj->acl;
554 $this->src_object_type = $obj->src_object_type;
555 $this->src_object_id = $obj->src_object_id;
556 $this->agenda_id = $obj->agenda_id;
557 $this->extraparams = (isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) :
null);
566 $this->db->free($resql);
574 $this->errors[] =
'Error '.$this->db->lasterror();
575 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
592 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
600 $sql .=
" t.entity,";
601 $sql .=
" t.filename,";
602 $sql .=
" t.filepath,";
603 $sql .=
" t.fullpath_orig,";
604 $sql .=
" t.description,";
605 $sql .=
" t.keywords,";
607 $sql .=
" t.content,";
610 $sql .=
" t.position,";
611 $sql .=
" t.gen_or_uploaded,";
612 $sql .=
" t.extraparams,";
613 $sql .=
" t.date_c,";
614 $sql .=
" t.tms as date_m,";
615 $sql .=
" t.fk_user_c,";
616 $sql .=
" t.fk_user_m,";
618 $sql .=
" t.src_object_type,";
619 $sql .=
" t.src_object_id,";
620 $sql .=
" t.agenda_id";
621 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
622 $sql .=
' WHERE 1 = 1';
625 if (is_array($filter)) {
627 if (count($filter) > 0) {
628 foreach ($filter as $key => $value) {
629 if ($key ==
't.src_object_id') {
630 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
632 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
636 if (count($sqlwhere) > 0) {
637 $sql .=
' AND '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
647 $this->errors[] = $errormessage;
648 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
656 if (!empty($sortfield)) {
657 $sql .= $this->db->order($sortfield, $sortorder);
659 if (!empty($limit)) {
660 $sql .= $this->db->plimit($limit, $offset);
663 $this->lines = array();
665 $resql = $this->db->query($sql);
667 $num = $this->db->num_rows($resql);
669 while ($obj = $this->db->fetch_object($resql)) {
672 $line->id = $obj->rowid;
673 $line->ref = $obj->rowid;
674 $line->label = $obj->label;
675 $line->share = $obj->share;
676 $line->entity = $obj->entity;
677 $line->filename = $obj->filename;
678 $line->filepath = $obj->filepath;
679 $line->fullpath_orig = $obj->fullpath_orig;
680 $line->description = $obj->description;
681 $line->keywords = $obj->keywords;
683 $line->content = $obj->content;
685 $line->cover = $obj->cover;
686 $line->position = $obj->position;
687 $line->gen_or_uploaded = $obj->gen_or_uploaded;
688 $line->extraparams = $obj->extraparams;
689 $line->date_c = $this->db->jdate($obj->date_c);
690 $line->date_m = $this->db->jdate($obj->date_m);
691 $line->fk_user_c = $obj->fk_user_c;
692 $line->fk_user_m = $obj->fk_user_m;
693 $line->acl = $obj->acl;
694 $line->src_object_type = $obj->src_object_type;
695 $line->src_object_id = $obj->src_object_id;
696 $line->agenda_id = $obj->agenda_id;
697 $this->lines[] = $line;
699 $this->db->free($resql);
703 $this->errors[] =
'Error '.$this->db->lasterror();
704 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
727 if (isset($this->
ref)) {
728 $this->
ref = trim($this->
ref);
730 if (isset($this->label)) {
731 $this->label = trim($this->label);
733 if (isset($this->share)) {
734 $this->share = trim($this->share);
736 if (isset($this->entity)) {
737 $this->entity = (int) $this->entity;
739 if (isset($this->filename)) {
740 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
742 if (isset($this->filepath)) {
743 $this->filepath = trim($this->filepath);
744 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
746 if (isset($this->fullpath_orig)) {
747 $this->fullpath_orig = trim($this->fullpath_orig);
752 if (isset($this->keywords)) {
753 $this->keywords = trim($this->keywords);
755 if (isset($this->cover)) {
756 $this->cover = trim($this->cover);
758 if (isset($this->gen_or_uploaded)) {
759 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
761 if (isset($this->fk_user_m)) {
762 $this->fk_user_m = (int) $this->fk_user_m;
764 if (isset($this->acl)) {
765 $this->acl = trim($this->acl);
767 if (isset($this->src_object_type)) {
768 $this->src_object_type = trim($this->src_object_type);
770 if (!empty($this->agenda_id)) {
771 $this->agenda_id = (int) $this->agenda_id;
773 $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) :
null);
774 $extraparams =
dol_trunc($extraparams, 250);
777 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
778 $sql .=
" ref = '".$this->db->escape(
dol_hash($this->filepath.
"/".$this->filename,
'3')).
"',";
779 $sql .=
' label = '.(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
780 $sql .=
' share = '.(!empty($this->share) ?
"'".$this->db->escape($this->share).
"'" :
"null").
',';
781 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
$conf->entity).
',';
782 $sql .=
' filename = '.(isset($this->filename) ?
"'".$this->db->escape($this->filename).
"'" :
"null").
',';
783 $sql .=
' filepath = '.(isset($this->filepath) ?
"'".$this->db->escape($this->filepath).
"'" :
"null").
',';
784 $sql .=
' fullpath_orig = '.(isset($this->fullpath_orig) ?
"'".$this->db->escape($this->fullpath_orig).
"'" :
"null").
',';
785 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
786 $sql .=
' keywords = '.(isset($this->keywords) ?
"'".$this->db->escape($this->keywords).
"'" :
"null").
',';
788 $sql .=
' content = '.(isset($this->content) ?
"'".$this->db->escape($this->content).
"'" :
"null").
',';
790 $sql .=
' cover = '.(isset($this->cover) ?
"'".$this->db->escape($this->cover).
"'" :
"null").
',';
791 $sql .=
' position = '.(isset($this->
position) ? $this->db->escape((
string) $this->position) :
"0").
',';
792 $sql .=
' gen_or_uploaded = '.(isset($this->gen_or_uploaded) ?
"'".$this->db->escape($this->gen_or_uploaded).
"'" :
"null").
',';
793 $sql .=
' extraparams = '.(isset($extraparams) ?
"'".$this->db->escape($extraparams).
"'" :
"null").
',';
794 $sql .=
' date_c = '.(!isset($this->date_c) ||
dol_strlen($this->date_c) != 0 ?
"'".$this->db->idate($this->date_c).
"'" :
'null').
',';
796 $sql .=
' fk_user_m = '.($this->fk_user_m > 0 ? $this->fk_user_m : $user->id).
',';
797 $sql .=
' acl = '.(isset($this->acl) ?
"'".$this->db->escape($this->acl).
"'" :
"null").
',';
798 $sql .=
' src_object_id = '.($this->src_object_id > 0 ? $this->src_object_id :
"null").
',';
799 $sql .=
' src_object_type = '.(isset($this->src_object_type) ?
"'".$this->db->escape($this->src_object_type).
"'" :
"null").
',';
800 $sql .=
' agenda_id = '.($this->agenda_id > 0 ? (int) $this->agenda_id :
"null");
801 $sql .=
' WHERE rowid='.((int) $this->
id);
804 $resql = $this->db->query($sql);
807 $this->errors[] =
'Error '.$this->db->lasterror();
808 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
820 if (!$error && !$notrigger) {
822 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
831 $this->db->rollback();
848 public function delete(
User $user, $notrigger = 0)
859 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_DELETE', $user);
870 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
875 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
876 $sql .=
' WHERE rowid='.((int) $this->
id);
878 $resql = $this->db->query($sql);
881 $this->errors[] =
'Error '.$this->db->lasterror();
882 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
888 $this->db->rollback();
923 $object->context[
'createfromclone'] =
'createfromclone';
924 $result =
$object->create($user);
929 $this->errors =
$object->errors;
930 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
933 unset(
$object->context[
'createfromclone']);
941 $this->db->rollback();
956 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'ecm_files SET';
957 $sql .=
' filepath = "'.$this->db->escape($newdir).
'"';
960 $sql .=
' filepath = "'.$this->db->escape($olddir).
'"';
963 $this->db->query($sql);
979 $nofetch = !empty($params[
'nofetch']);
982 return [
'optimize' => $langs->trans(
"ShowFile")];
984 $datas[
'picto'] =
img_picto(
'', $this->picto,
'', 0, 0, 0,
'',
'paddingrightonly') .
'<u>' . $langs->trans(
"File") .
'</u>';
985 if (!empty($this->filename)) {
986 $datas[
'name'] =
'<br><b>'.$langs->trans(
'Name').
':</b> '.basename($this->filename);
988 if (!empty($this->
ref)) {
989 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'HashOfFileContent').
':</b> '.$this->ref;
991 if (!empty($this->share)) {
992 $datas[
'share'] =
'<br>'.$langs->trans(
"FileSharedViaALink");
994 $datas[
'share'] =
'<br>'.$langs->trans(
"FileNotShared");
996 if (!empty($this->gen_or_uploaded)) {
997 $datas[
'gen_or_upload'] =
'<br><b>'.$langs->trans(
'GenOrUpload').
':</b> '.$this->gen_or_uploaded;
999 if (!empty($this->content)) {
1000 $datas[
'content'] =
'<br>'.$langs->trans(
'FileHasAnIndexedTextContent');
1016 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
1018 global
$conf, $hookmanager, $langs;
1020 if (!empty(
$conf->dol_no_mouse_hover)) {
1028 'objecttype' => $this->element,
1029 'option' => $option,
1032 $classfortooltip =
'classfortooltip';
1035 $classfortooltip =
'classforajaxtooltip';
1036 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1043 if ($option ==
'facture_fournisseur') {
1044 $tmppath = preg_replace(
'/^(\d+\/)?fournisseur\/facture\//',
'', $this->filepath);
1045 } elseif ($option ==
'commande_fournisseur') {
1046 $tmppath = preg_replace(
'/^(\d+\/)?fournisseur\/commande\//',
'', $this->filepath);
1047 } elseif ($option ==
'tax-vat') {
1048 $tmppath = preg_replace(
'/^(\d+\/)?tax\/vat\//',
'', $this->filepath);
1049 } elseif ($option ==
'remisecheque') {
1050 $tmppath = preg_replace(
'/^bank\/checkdeposits\//',
'', $this->filepath);
1052 if ((
int) $this->entity > 1) {
1054 $tmppath = preg_replace(
'/^\d+\/[^\/]+\//',
'', $this->filepath);
1057 $tmppath = preg_replace(
'/^[^\/]+\//',
'', $this->filepath);
1060 $url = DOL_URL_ROOT.
'/document.php?modulepart='.urlencode($option).
'&file='.urlencode($tmppath.
'/'.$this->filename).
'&entity='.((int) $this->entity);
1062 $url = DOL_URL_ROOT.
'/ecm/file_card.php?id='.$this->id;
1066 if (empty($notooltip)) {
1068 $label = $langs->trans(
"ShowFile");
1069 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1071 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1072 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' '.($morecss ?
' '.$morecss :
'').
'"';
1074 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1077 $linkstart =
'<a href="'.$url.
'"';
1079 $linkstart .=
'target="_blank" ';
1081 $linkstart .= $linkclose.
'>';
1085 if (empty($this->filename)) {
1086 $result .= ($linkstart.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="paddingright"')).$linkend);
1088 $result .= ($linkstart.img_mime($this->filename, ($notooltip ?
'' :
dol_escape_htmltag($label, 1)), ($notooltip ?
'' :
' paddingright')).$linkend);
1091 $result .= $linkstart.$this->filename.$linkend;
1094 $hookmanager->initHooks(array($this->element .
'dao'));
1095 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1096 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1098 $result = $hookmanager->resPrint;
1100 $result .= $hookmanager->resPrint;
1141 global
$conf, $user;
1144 $this->specimen = 1;
1145 $this->label =
'0a1b2c3e4f59999999';
1147 $this->filename =
'myspecimenfilefile.pdf';
1148 $this->filepath =
'/aaa/bbb';
1149 $this->fullpath_orig =
'c:/file on my disk.pdf';
1150 $this->
description =
'This is a description of the file';
1151 $this->keywords =
'key1,key2';
1152 $this->content =
'This is the text content of the file';
1155 $this->gen_or_uploaded =
'uploaded';
1156 $this->extraparams =
'';
1157 $this->date_c = (
dol_now() - 3600 * 24 * 10);
1159 $this->fk_user_c = $user->id;
1160 $this->fk_user_m = $user->id;
1162 $this->src_object_type =
'product';
1163 $this->src_object_id = 1;
1196 public $fullpath_orig;
1201 public $description;
1224 public $gen_or_uploaded;
1228 public $extraparams;
1232 public $date_c =
'';
1236 public $date_m =
'';
1255 public $src_object_type;
1259 public $src_object_id;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage ECM files.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getTooltipContentArray($params)
getTooltipContentArray
getLibStatut($mode=0)
Return the label of the status.
fetch($id, $ref='', $relativepath='', $hashoffile='', $hashforshare='', $src_object_type='', $src_object_id=0, $entity=0)
Load object in memory from the database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
update(User $user, $notrigger=0)
Update object into database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link to the object card (with optionally the picto)
__construct(DoliDB $db)
Constructor.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load object in memory from the database.
static LibStatut($status, $mode=0)
Return the status.
updateAfterRename($olddir, $newdir)
updateAfterRename update entries in ecmfiles if exist to avoid losing info
create(User $user, $notrigger=0)
Create object into database.
Class of an index line of a document.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.