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';
78 public $fullpath_orig;
108 public $gen_or_uploaded;
143 public $src_object_type;
148 public $src_object_id;
160 public $fields = array(
161 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 1,
'notnull' => 1,
'visible' => 0,
'noteditable' => 1,
'index' => 1,
'css' =>
'left',
'comment' =>
"Id"),
162 '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"),
163 '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"),
164 '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"),
165 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 50,
'index' => 1),
166 '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"),
167 '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"),
168 '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', ...)"),
169 'src_object_id' => array(
'type' =>
'integer',
'label' =>
'SourceID',
'default' =>
'1',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 90,
'index' => 1,
'comment' =>
"Source object id"),
170 '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"),
171 'description' => array(
'type' =>
'text',
'label' =>
'Description',
'enabled' => 1,
'visible' => 0,
'position' => 110),
172 '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."),
173 '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."),
174 'cover' => array(
'type' =>
'text',
'label' =>
'Cover',
'enabled' => 1,
'visible' => 0,
'position' => 130,
'comment' =>
"is this file a file to use for a cover"),
175 'position' => array(
'type' =>
'integer',
'label' =>
'Position',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 140,
'index' => 1,
'comment' =>
"position of file among others"),
176 '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'"),
177 '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"),
178 'date_c' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 170),
179 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 175),
180 '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',),
181 'fk_user_m' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'position' => 511,
'notnull' => -1,
'visible' => -2,),
182 'note_public' => array(
'type' =>
'text',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 155),
183 'note_private' => array(
'type' =>
'text',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 160),
184 'acl' => array(
'type' =>
'text',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 160,
'comment' =>
"for future permission 'per file'"),
185 'agenda_id' => array(
'type' =>
'integer',
'label' =>
'IdAgenda',
'enabled' => 1,
'visible' => 0,
'position' => 180,
'comment' =>
"Link to an actioncomm"),
215 if (isset($this->
ref)) {
216 $this->
ref = trim($this->
ref);
218 if (isset($this->label)) {
219 $this->label = trim($this->label);
221 if (isset($this->share)) {
222 $this->share = trim($this->share);
224 if (isset($this->entity)) {
225 $this->entity = (int) $this->entity;
227 if (isset($this->filename)) {
228 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
230 if (isset($this->filepath)) {
231 $this->filepath = trim($this->filepath);
232 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
234 if (isset($this->fullpath_orig)) {
235 $this->fullpath_orig = trim($this->fullpath_orig);
240 if (isset($this->keywords)) {
241 $this->keywords = trim($this->keywords);
243 if (isset($this->cover)) {
244 $this->cover = trim($this->cover);
246 if (isset($this->gen_or_uploaded)) {
247 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
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();
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;
302 $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) :
null);
303 $extraparams =
dol_trunc($extraparams, 250);
306 if (!empty($this->agenda_id)) {
307 $this->agenda_id = (int) $this->agenda_id;
311 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
318 $sql .=
'fullpath_orig,';
319 $sql .=
'description,';
326 $sql .=
'gen_or_uploaded,';
327 $sql .=
'extraparams,';
330 $sql .=
'fk_user_c,';
331 $sql .=
'fk_user_m,';
333 $sql .=
'src_object_type,';
334 $sql .=
'src_object_id,';
336 $sql .=
') VALUES (';
337 $sql .=
" '".$this->db->escape($this->
ref).
"', ";
338 $sql .=
' '.(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
',';
339 $sql .=
' '.(!isset($this->share) ?
'NULL' :
"'".$this->db->escape($this->share).
"'").
',';
340 $sql .=
' '.((int) $this->entity).
',';
341 $sql .=
' '.(!isset($this->filename) ?
'NULL' :
"'".$this->db->escape($this->filename).
"'").
',';
342 $sql .=
' '.(!isset($this->filepath) ?
'NULL' :
"'".$this->db->escape($this->filepath).
"'").
',';
343 $sql .=
' '.(!isset($this->fullpath_orig) ?
'NULL' :
"'".$this->db->escape($this->fullpath_orig).
"'").
',';
345 $sql .=
' '.(!isset($this->keywords) ?
'NULL' :
"'".$this->db->escape($this->keywords).
"'").
',';
347 $sql .=
' '.(!isset($this->content) ?
'NULL' :
"'".$this->db->escape($this->content).
"'").
',';
349 $sql .=
' '.(!isset($this->cover) ?
'NULL' :
"'".$this->db->escape($this->cover).
"'").
',';
350 $sql .=
' '.((int) $maxposition).
',';
351 $sql .=
' '.(!isset($this->gen_or_uploaded) ?
'NULL' :
"'".$this->db->escape($this->gen_or_uploaded).
"'").
',';
352 $sql .=
' '.(!isset($extraparams) ?
'NULL' :
"'".$this->db->escape($extraparams).
"'").
',';
353 $sql .=
" '".$this->db->idate($this->date_c).
"',";
354 $sql .=
' '.(!isset($this->date_m) ||
dol_strlen((
string) $this->date_m) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_m).
"'").
',';
355 $sql .=
' '.(!isset($this->fk_user_c) ? $user->id : $this->fk_user_c).
',';
356 $sql .=
' '.(!isset($this->fk_user_m) ?
'NULL' : $this->fk_user_m).
',';
357 $sql .=
' '.(!isset($this->acl) ?
'NULL' :
"'".$this->db->escape($this->acl).
"'").
',';
358 $sql .=
' '.(!isset($this->src_object_type) ?
'NULL' :
"'".$this->db->escape($this->src_object_type).
"'").
',';
359 $sql .=
' '.(!isset($this->src_object_id) ?
'NULL' : $this->src_object_id).
',';
360 $sql .=
' '.(empty($this->agenda_id) ?
'NULL' : (int) $this->agenda_id);
365 $resql = $this->db->query($sql);
368 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
369 $this->errors[] =
'Error DB_ERROR_RECORD_ALREADY_EXISTS : '.$this->db->lasterror();
371 $this->errors[] =
'Error '.$this->db->lasterror();
373 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
377 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
383 $result = $this->call_trigger(strtoupper(get_class($this)).
'_CREATE', $user);
393 $this->db->rollback();
416 public function fetch($id, $ref =
'', $relativepath =
'', $hashoffile =
'', $hashforshare =
'', $src_object_type =
'', $src_object_id = 0, $entity =
null)
427 $sql .=
" t.entity,";
428 $sql .=
" t.filename,";
429 $sql .=
" t.filepath,";
430 $sql .=
" t.fullpath_orig,";
431 $sql .=
" t.description,";
432 $sql .=
" t.keywords,";
434 $sql .=
" t.content,";
437 $sql .=
" t.position,";
438 $sql .=
" t.gen_or_uploaded,";
439 $sql .=
" t.extraparams,";
440 $sql .=
" t.date_c,";
441 $sql .=
" t.tms as date_m,";
442 $sql .=
" t.fk_user_c,";
443 $sql .=
" t.fk_user_m,";
444 $sql .=
' t.note_private,';
445 $sql .=
' t.note_public,';
447 $sql .=
" t.src_object_type,";
448 $sql .=
" t.src_object_id,";
449 $sql .=
" t.agenda_id";
450 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
451 $sql .=
' WHERE 1 = 1';
458 $relativepathwithnoexe = preg_replace(
'/\.noexe$/',
'', $relativepath);
459 $sql .=
" AND t.filepath = '".$this->db->escape(dirname($relativepath)).
"'";
460 $filename = basename($relativepathwithnoexe);
461 if ($filename !=
'*') {
462 $sql .=
" AND t.filename = '".$this->db->escape($filename).
"'";
464 if (isset($entity)) {
465 $sql .=
" AND t.entity = " . (int) $entity;
467 $sql .=
" AND t.entity = " . $conf->entity;
472 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
473 if (isset($entity)) {
474 $sql .=
" AND t.entity = " . (int) $entity;
476 $sql .=
" AND t.entity = " . $conf->entity;
480 if (!empty($hashoffile)) {
481 $sql .=
" AND t.label = '".$this->db->escape($hashoffile).
"'";
482 if (isset($entity)) {
483 $sql .=
" AND t.entity = " . (int) $entity;
485 $sql .=
" AND t.entity = " . $conf->entity;
489 if (!empty($hashforshare)) {
490 if ($hashforshare !=
'shared') {
491 $sql .=
" AND t.share = '".$this->db->escape($hashforshare).
"'";
493 $sql .=
" AND t.share IS NOT NULL AND t.share <> ''";
498 if ($src_object_type && $src_object_id) {
499 $sql .=
" AND t.src_object_type = '".$this->db->escape($src_object_type).
"' AND t.src_object_id = ".((int) $src_object_id);
500 if (isset($entity)) {
501 $sql .=
" AND t.entity = " . (int) $entity;
503 $sql .=
" AND t.entity = " . $conf->entity;
507 if ($id > 0 || empty($filterfound)) {
508 $sql .=
' AND t.rowid = '.((int) $id);
512 $this->db->plimit(1);
513 $this->db->order(
't.rowid',
'ASC');
515 $resql = $this->db->query($sql);
517 $numrows = $this->db->num_rows($resql);
519 $obj = $this->db->fetch_object($resql);
521 $this->
id = $obj->rowid;
522 $this->
ref = $obj->ref;
523 $this->label = $obj->label;
524 $this->share = $obj->share;
525 $this->entity = $obj->entity;
526 $this->filename = $obj->filename;
527 $this->filepath = $obj->filepath;
528 $this->fullpath_orig = $obj->fullpath_orig;
530 $this->keywords = $obj->keywords;
532 $this->content = $obj->content;
534 $this->cover = $obj->cover;
536 $this->gen_or_uploaded = $obj->gen_or_uploaded;
537 $this->date_c = $this->db->jdate($obj->date_c);
538 $this->date_m = $this->db->jdate($obj->date_m);
539 $this->fk_user_c = $obj->fk_user_c;
540 $this->fk_user_m = $obj->fk_user_m;
541 $this->note_private = $obj->note_private;
542 $this->note_public = $obj->note_public;
543 $this->acl = $obj->acl;
544 $this->src_object_type = $obj->src_object_type;
545 $this->src_object_id = $obj->src_object_id;
546 $this->agenda_id = $obj->agenda_id;
547 $this->extraparams = (isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) :
null);
556 $this->db->free($resql);
564 $this->errors[] =
'Error '.$this->db->lasterror();
565 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
582 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
590 $sql .=
" t.entity,";
591 $sql .=
" t.filename,";
592 $sql .=
" t.filepath,";
593 $sql .=
" t.fullpath_orig,";
594 $sql .=
" t.description,";
595 $sql .=
" t.keywords,";
597 $sql .=
" t.content,";
600 $sql .=
" t.position,";
601 $sql .=
" t.gen_or_uploaded,";
602 $sql .=
" t.extraparams,";
603 $sql .=
" t.date_c,";
604 $sql .=
" t.tms as date_m,";
605 $sql .=
" t.fk_user_c,";
606 $sql .=
" t.fk_user_m,";
608 $sql .=
" t.src_object_type,";
609 $sql .=
" t.src_object_id,";
610 $sql .=
" t.agenda_id";
611 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
612 $sql .=
' WHERE 1 = 1';
615 if (is_array($filter)) {
617 if (count($filter) > 0) {
618 foreach ($filter as $key => $value) {
619 if ($key ==
't.src_object_id') {
620 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
622 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
626 if (count($sqlwhere) > 0) {
627 $sql .=
' AND '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
637 $this->errors[] = $errormessage;
638 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
646 if (!empty($sortfield)) {
647 $sql .= $this->db->order($sortfield, $sortorder);
649 if (!empty($limit)) {
650 $sql .= $this->db->plimit($limit, $offset);
653 $this->lines = array();
655 $resql = $this->db->query($sql);
657 $num = $this->db->num_rows($resql);
659 while ($obj = $this->db->fetch_object($resql)) {
662 $line->id = $obj->rowid;
663 $line->ref = $obj->rowid;
664 $line->label = $obj->label;
665 $line->share = $obj->share;
666 $line->entity = $obj->entity;
667 $line->filename = $obj->filename;
668 $line->filepath = $obj->filepath;
669 $line->fullpath_orig = $obj->fullpath_orig;
670 $line->description = $obj->description;
671 $line->keywords = $obj->keywords;
673 $line->content = $obj->content;
675 $line->cover = $obj->cover;
676 $line->position = $obj->position;
677 $line->gen_or_uploaded = $obj->gen_or_uploaded;
678 $line->extraparams = $obj->extraparams;
679 $line->date_c = $this->db->jdate($obj->date_c);
680 $line->date_m = $this->db->jdate($obj->date_m);
681 $line->fk_user_c = $obj->fk_user_c;
682 $line->fk_user_m = $obj->fk_user_m;
683 $line->acl = $obj->acl;
684 $line->src_object_type = $obj->src_object_type;
685 $line->src_object_id = $obj->src_object_id;
686 $line->agenda_id = $obj->agenda_id;
687 $this->lines[] = $line;
689 $this->db->free($resql);
693 $this->errors[] =
'Error '.$this->db->lasterror();
694 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
717 if (isset($this->
ref)) {
718 $this->
ref = trim($this->
ref);
720 if (isset($this->label)) {
721 $this->label = trim($this->label);
723 if (isset($this->share)) {
724 $this->share = trim($this->share);
726 if (isset($this->entity)) {
727 $this->entity = (int) $this->entity;
729 if (isset($this->filename)) {
730 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
732 if (isset($this->filepath)) {
733 $this->filepath = trim($this->filepath);
734 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
736 if (isset($this->fullpath_orig)) {
737 $this->fullpath_orig = trim($this->fullpath_orig);
742 if (isset($this->keywords)) {
743 $this->keywords = trim($this->keywords);
745 if (isset($this->cover)) {
746 $this->cover = trim($this->cover);
748 if (isset($this->gen_or_uploaded)) {
749 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
751 if (isset($this->fk_user_m)) {
752 $this->fk_user_m = (int) $this->fk_user_m;
754 if (isset($this->acl)) {
755 $this->acl = trim($this->acl);
757 if (isset($this->src_object_type)) {
758 $this->src_object_type = trim($this->src_object_type);
760 if (!empty($this->agenda_id)) {
761 $this->agenda_id = (int) $this->agenda_id;
763 $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) :
null);
764 $extraparams =
dol_trunc($extraparams, 250);
767 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
768 $sql .=
" ref = '".$this->db->escape(
dol_hash($this->filepath.
"/".$this->filename,
'3')).
"',";
769 $sql .=
' label = '.(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
770 $sql .=
' share = '.(!empty($this->share) ?
"'".$this->db->escape($this->share).
"'" :
"null").
',';
771 $sql .=
' entity = '.(isset($this->entity) ? $this->entity : $conf->entity).
',';
772 $sql .=
' filename = '.(isset($this->filename) ?
"'".$this->db->escape($this->filename).
"'" :
"null").
',';
773 $sql .=
' filepath = '.(isset($this->filepath) ?
"'".$this->db->escape($this->filepath).
"'" :
"null").
',';
774 $sql .=
' fullpath_orig = '.(isset($this->fullpath_orig) ?
"'".$this->db->escape($this->fullpath_orig).
"'" :
"null").
',';
775 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
776 $sql .=
' keywords = '.(isset($this->keywords) ?
"'".$this->db->escape($this->keywords).
"'" :
"null").
',';
778 $sql .=
' content = '.(isset($this->content) ?
"'".$this->db->escape($this->content).
"'" :
"null").
',';
780 $sql .=
' cover = '.(isset($this->cover) ?
"'".$this->db->escape($this->cover).
"'" :
"null").
',';
781 $sql .=
' position = '.(isset($this->
position) ? $this->db->escape((
string) $this->position) :
"0").
',';
782 $sql .=
' gen_or_uploaded = '.(isset($this->gen_or_uploaded) ?
"'".$this->db->escape($this->gen_or_uploaded).
"'" :
"null").
',';
783 $sql .=
' extraparams = '.(isset($extraparams) ?
"'".$this->db->escape($extraparams).
"'" :
"null").
',';
784 $sql .=
' date_c = '.(!isset($this->date_c) ||
dol_strlen($this->date_c) != 0 ?
"'".$this->db->idate($this->date_c).
"'" :
'null').
',';
786 $sql .=
' fk_user_m = '.($this->fk_user_m > 0 ? $this->fk_user_m : $user->id).
',';
787 $sql .=
' acl = '.(isset($this->acl) ?
"'".$this->db->escape($this->acl).
"'" :
"null").
',';
788 $sql .=
' src_object_id = '.($this->src_object_id > 0 ? $this->src_object_id :
"null").
',';
789 $sql .=
' src_object_type = '.(isset($this->src_object_type) ?
"'".$this->db->escape($this->src_object_type).
"'" :
"null").
',';
790 $sql .=
' agenda_id = '.($this->agenda_id > 0 ? (int) $this->agenda_id :
"null");
791 $sql .=
' WHERE rowid='.((int) $this->
id);
794 $resql = $this->db->query($sql);
797 $this->errors[] =
'Error '.$this->db->lasterror();
798 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
810 if (!$error && !$notrigger) {
812 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
821 $this->db->rollback();
838 public function delete(
User $user, $notrigger = 0)
849 $result = $this->call_trigger(strtoupper(get_class($this)).
'_DELETE', $user);
860 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
865 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
866 $sql .=
' WHERE rowid='.((int) $this->
id);
868 $resql = $this->db->query($sql);
871 $this->errors[] =
'Error '.$this->db->lasterror();
872 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
878 $this->db->rollback();
913 $object->context[
'createfromclone'] =
'createfromclone';
914 $result =
$object->create($user);
919 $this->errors =
$object->errors;
920 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
923 unset(
$object->context[
'createfromclone']);
931 $this->db->rollback();
946 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'ecm_files SET';
947 $sql .=
' filepath = "'.$this->db->escape($newdir).
'"';
950 $sql .=
' filepath = "'.$this->db->escape($olddir).
'"';
953 $this->db->query($sql);
969 $nofetch = !empty($params[
'nofetch']);
972 return [
'optimize' => $langs->trans(
"ShowFile")];
974 $datas[
'picto'] =
img_picto(
'', $this->picto,
'', 0, 0, 0,
'',
'paddingrightonly') .
'<u>' . $langs->trans(
"File") .
'</u>';
975 if (!empty($this->filename)) {
976 $datas[
'name'] =
'<br><b>'.$langs->trans(
'Name').
':</b> '.basename($this->filename);
978 if (!empty($this->
ref)) {
979 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'HashOfFileContent').
':</b> '.$this->ref;
981 if (!empty($this->share)) {
982 $datas[
'share'] =
'<br>'.$langs->trans(
"FileSharedViaALink");
984 $datas[
'share'] =
'<br>'.$langs->trans(
"FileNotShared");
986 if (!empty($this->gen_or_uploaded)) {
987 $datas[
'gen_or_upload'] =
'<br><b>'.$langs->trans(
'GenOrUpload').
':</b> '.$this->gen_or_uploaded;
989 if (!empty($this->content)) {
990 $datas[
'content'] =
'<br>'.$langs->trans(
'FileHasAnIndexedTextContent');
1006 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
1008 global $conf, $hookmanager, $langs;
1010 if (!empty($conf->dol_no_mouse_hover)) {
1018 'objecttype' => $this->element,
1019 'option' => $option,
1022 $classfortooltip =
'classfortooltip';
1025 $classfortooltip =
'classforajaxtooltip';
1026 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1033 if ($option ==
'facture_fournisseur') {
1034 $tmppath = preg_replace(
'/^(\d+\/)?fournisseur\/facture\//',
'', $this->filepath);
1035 } elseif ($option ==
'commande_fournisseur') {
1036 $tmppath = preg_replace(
'/^(\d+\/)?fournisseur\/commande\//',
'', $this->filepath);
1037 } elseif ($option ==
'tax-vat') {
1038 $tmppath = preg_replace(
'/^(\d+\/)?tax\/vat\//',
'', $this->filepath);
1039 } elseif ($option ==
'remisecheque') {
1040 $tmppath = preg_replace(
'/^bank\/checkdeposits\//',
'', $this->filepath);
1042 if ((
int) $this->entity > 1) {
1044 $tmppath = preg_replace(
'/^\d+\/[^\/]+\//',
'', $this->filepath);
1047 $tmppath = preg_replace(
'/^[^\/]+\//',
'', $this->filepath);
1050 $url = DOL_URL_ROOT.
'/document.php?modulepart='.urlencode($option).
'&file='.urlencode($tmppath.
'/'.$this->filename).
'&entity='.((int) $this->entity);
1052 $url = DOL_URL_ROOT.
'/ecm/file_card.php?id='.$this->id;
1056 if (empty($notooltip)) {
1058 $label = $langs->trans(
"ShowFile");
1059 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1061 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1062 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' '.($morecss ?
' '.$morecss :
'').
'"';
1064 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1067 $linkstart =
'<a href="'.$url.
'"';
1069 $linkstart .=
'target="_blank" ';
1071 $linkstart .= $linkclose.
'>';
1075 if (empty($this->filename)) {
1076 $result .= ($linkstart.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="paddingright"')).$linkend);
1078 $result .= ($linkstart.img_mime($this->filename, ($notooltip ?
'' :
dol_escape_htmltag($label, 1)), ($notooltip ?
'' :
' paddingright')).$linkend);
1081 $result .= $linkstart.$this->filename.$linkend;
1084 $hookmanager->initHooks(array($this->element .
'dao'));
1085 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1086 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1088 $result = $hookmanager->resPrint;
1090 $result .= $hookmanager->resPrint;
1131 global $conf, $user;
1134 $this->specimen = 1;
1135 $this->label =
'0a1b2c3e4f59999999';
1137 $this->filename =
'myspecimenfilefile.pdf';
1138 $this->filepath =
'/aaa/bbb';
1139 $this->fullpath_orig =
'c:/file on my disk.pdf';
1140 $this->
description =
'This is a description of the file';
1141 $this->keywords =
'key1,key2';
1142 $this->content =
'This is the text content of the file';
1145 $this->gen_or_uploaded =
'uploaded';
1146 $this->extraparams =
'';
1147 $this->date_c = (
dol_now() - 3600 * 24 * 10);
1149 $this->fk_user_c = $user->id;
1150 $this->fk_user_m = $user->id;
1152 $this->src_object_type =
'product';
1153 $this->src_object_id = 1;
1186 public $fullpath_orig;
1191 public $description;
1214 public $gen_or_uploaded;
1218 public $extraparams;
1222 public $date_c =
'';
1226 public $date_m =
'';
1245 public $src_object_type;
1249 public $src_object_id;
if(! $sortfield) if(! $sortorder) $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.
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.
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)
fetch($id, $ref='', $relativepath='', $hashoffile='', $hashforshare='', $src_object_type='', $src_object_id=0, $entity=null)
Load object in memory from the database.
__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.
dol_now($mode='gmt')
Return date for now.
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
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...
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.