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) ? ((int) $user->id) : ((int) $this->fk_user_c)).
',';
356 $sql .=
' '.(!isset($this->fk_user_m) ?
'NULL' : ((int) $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' : ((int) $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);
635 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
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 $line->fetch_optionals();
688 $this->lines[] = $line;
690 $this->db->free($resql);
694 $this->errors[] =
'Error '.$this->db->lasterror();
695 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
718 if (isset($this->
ref)) {
719 $this->
ref = trim($this->
ref);
721 if (isset($this->label)) {
722 $this->label = trim($this->label);
724 if (isset($this->share)) {
725 $this->share = trim($this->share);
727 if (isset($this->entity)) {
728 $this->entity = (int) $this->entity;
730 if (isset($this->filename)) {
731 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
733 if (isset($this->filepath)) {
734 $this->filepath = trim($this->filepath);
735 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
737 if (isset($this->fullpath_orig)) {
738 $this->fullpath_orig = trim($this->fullpath_orig);
743 if (isset($this->keywords)) {
744 $this->keywords = trim($this->keywords);
746 if (isset($this->cover)) {
747 $this->cover = trim($this->cover);
749 if (isset($this->gen_or_uploaded)) {
750 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
752 if (isset($this->fk_user_m)) {
753 $this->fk_user_m = (int) $this->fk_user_m;
755 if (isset($this->acl)) {
756 $this->acl = trim($this->acl);
758 if (isset($this->src_object_type)) {
759 $this->src_object_type = trim($this->src_object_type);
761 if (!empty($this->agenda_id)) {
762 $this->agenda_id = (int) $this->agenda_id;
764 $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) :
null);
765 $extraparams =
dol_trunc($extraparams, 250);
768 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
769 $sql .=
" ref = '".$this->db->escape(
dol_hash($this->filepath.
"/".$this->filename,
'3')).
"',";
770 $sql .=
' label = '.(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
771 $sql .=
' share = '.(!empty($this->share) ?
"'".$this->db->escape($this->share).
"'" :
"null").
',';
772 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
$conf->entity).
',';
773 $sql .=
' filename = '.(isset($this->filename) ?
"'".$this->db->escape($this->filename).
"'" :
"null").
',';
774 $sql .=
' filepath = '.(isset($this->filepath) ?
"'".$this->db->escape($this->filepath).
"'" :
"null").
',';
775 $sql .=
' fullpath_orig = '.(isset($this->fullpath_orig) ?
"'".$this->db->escape($this->fullpath_orig).
"'" :
"null").
',';
776 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
777 $sql .=
' keywords = '.(isset($this->keywords) ?
"'".$this->db->escape($this->keywords).
"'" :
"null").
',';
779 $sql .=
' content = '.(isset($this->content) ?
"'".$this->db->escape($this->content).
"'" :
"null").
',';
781 $sql .=
' cover = '.(isset($this->cover) ?
"'".$this->db->escape($this->cover).
"'" :
"null").
',';
782 $sql .=
' position = '.(isset($this->
position) ? $this->db->escape((
string) $this->position) :
"0").
',';
783 $sql .=
' gen_or_uploaded = '.(isset($this->gen_or_uploaded) ?
"'".$this->db->escape($this->gen_or_uploaded).
"'" :
"null").
',';
784 $sql .=
' extraparams = '.(isset($extraparams) ?
"'".$this->db->escape($extraparams).
"'" :
"null").
',';
785 $sql .=
' date_c = '.(!isset($this->date_c) ||
dol_strlen($this->date_c) != 0 ?
"'".$this->db->idate($this->date_c).
"'" :
'null').
',';
787 $sql .=
' fk_user_m = '.($this->fk_user_m > 0 ? ((int) $this->fk_user_m) : ((int) $user->id)).
',';
788 $sql .=
' acl = '.(isset($this->acl) ?
"'".$this->db->escape($this->acl).
"'" :
"null").
',';
789 $sql .=
' src_object_id = '.($this->src_object_id > 0 ? ((int) $this->src_object_id) :
"null").
',';
790 $sql .=
' src_object_type = '.(isset($this->src_object_type) ?
"'".$this->db->escape($this->src_object_type).
"'" :
"null").
',';
791 $sql .=
' agenda_id = '.($this->agenda_id > 0 ? ((int) $this->agenda_id) :
"null");
792 $sql .=
' WHERE rowid='.((int) $this->
id);
795 $resql = $this->db->query($sql);
798 $this->errors[] =
'Error '.$this->db->lasterror();
799 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
811 if (!$error && !$notrigger) {
813 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
822 $this->db->rollback();
839 public function delete(
User $user, $notrigger = 0)
850 $result = $this->call_trigger(strtoupper(get_class($this)).
'_DELETE', $user);
861 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
866 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
867 $sql .=
' WHERE rowid='.((int) $this->
id);
869 $resql = $this->db->query($sql);
872 $this->errors[] =
'Error '.$this->db->lasterror();
873 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
879 $this->db->rollback();
914 $object->context[
'createfromclone'] =
'createfromclone';
915 $result =
$object->create($user);
920 $this->errors =
$object->errors;
921 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
924 unset(
$object->context[
'createfromclone']);
932 $this->db->rollback();
947 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'ecm_files SET';
948 $sql .=
' filepath = "'.$this->db->escape($newdir).
'"';
951 $sql .=
' filepath = "'.$this->db->escape($olddir).
'"';
954 $this->db->query($sql);
970 $nofetch = !empty($params[
'nofetch']);
973 return [
'optimize' => $langs->trans(
"ShowFile")];
975 $datas[
'picto'] =
img_picto(
'', $this->picto,
'', 0, 0, 0,
'',
'paddingrightonly') .
'<u>' . $langs->trans(
"File") .
'</u>';
976 if (!empty($this->filename)) {
977 $datas[
'name'] =
'<br><b>'.$langs->trans(
'Name').
':</b> '.basename($this->filename);
979 if (!empty($this->
ref)) {
980 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'HashOfFileContent').
':</b> '.$this->ref;
982 if (!empty($this->share)) {
983 $datas[
'share'] =
'<br>'.$langs->trans(
"FileSharedViaALink");
985 $datas[
'share'] =
'<br>'.$langs->trans(
"FileNotShared");
987 if (!empty($this->gen_or_uploaded)) {
988 $datas[
'gen_or_upload'] =
'<br><b>'.$langs->trans(
'GenOrUpload').
':</b> '.$this->gen_or_uploaded;
990 if (!empty($this->content)) {
991 $datas[
'content'] =
'<br>'.$langs->trans(
'FileHasAnIndexedTextContent');
1007 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
1009 global
$conf, $hookmanager, $langs;
1011 if (!empty(
$conf->dol_no_mouse_hover)) {
1019 'objecttype' => $this->element,
1020 'option' => $option,
1023 $classfortooltip =
'classfortooltip';
1026 $classfortooltip =
'classforajaxtooltip';
1027 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1034 if ($option ==
'facture_fournisseur') {
1035 $tmppath = preg_replace(
'/^(\d+\/)?fournisseur\/facture\//',
'', $this->filepath);
1036 } elseif ($option ==
'commande_fournisseur') {
1037 $tmppath = preg_replace(
'/^(\d+\/)?fournisseur\/commande\//',
'', $this->filepath);
1038 } elseif ($option ==
'tax-vat') {
1039 $tmppath = preg_replace(
'/^(\d+\/)?tax\/vat\//',
'', $this->filepath);
1040 } elseif ($option ==
'remisecheque') {
1041 $tmppath = preg_replace(
'/^bank\/checkdeposits\//',
'', $this->filepath);
1043 if ((
int) $this->entity > 1) {
1045 $tmppath = preg_replace(
'/^\d+\/[^\/]+\//',
'', $this->filepath);
1048 $tmppath = preg_replace(
'/^[^\/]+\//',
'', $this->filepath);
1051 $url = DOL_URL_ROOT.
'/document.php?modulepart='.urlencode($option).
'&file='.urlencode($tmppath.
'/'.$this->filename).
'&entity='.((int) $this->entity);
1053 $url = DOL_URL_ROOT.
'/ecm/file_card.php?id='.$this->id;
1057 if (empty($notooltip)) {
1059 $label = $langs->trans(
"ShowFile");
1060 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1062 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1063 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' '.($morecss ?
' '.$morecss :
'').
'"';
1065 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1068 $linkstart =
'<a href="'.$url.
'"';
1070 $linkstart .=
'target="_blank" ';
1072 $linkstart .= $linkclose.
'>';
1076 if (empty($this->filename)) {
1077 $result .= ($linkstart.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="paddingright"')).$linkend);
1079 $result .= ($linkstart.img_mime($this->filename, ($notooltip ?
'' :
dol_escape_htmltag($label, 1)), ($notooltip ?
'' :
' paddingright')).$linkend);
1082 $result .= $linkstart.$this->filename.$linkend;
1085 $hookmanager->initHooks(array($this->element .
'dao'));
1086 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1087 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1089 $result = $hookmanager->resPrint;
1091 $result .= $hookmanager->resPrint;
1132 global
$conf, $user;
1135 $this->specimen = 1;
1136 $this->label =
'0a1b2c3e4f59999999';
1138 $this->filename =
'myspecimenfilefile.pdf';
1139 $this->filepath =
'/aaa/bbb';
1140 $this->fullpath_orig =
'c:/file on my disk.pdf';
1141 $this->
description =
'This is a description of the file';
1142 $this->keywords =
'key1,key2';
1143 $this->content =
'This is the text content of the file';
1146 $this->gen_or_uploaded =
'uploaded';
1147 $this->extraparams =
'';
1148 $this->date_c = (
dol_now() - 3600 * 24 * 10);
1150 $this->fk_user_c = $user->id;
1151 $this->fk_user_m = $user->id;
1153 $this->src_object_type =
'product';
1154 $this->src_object_id = 1;
1179 public $table_element =
'ecm_files';
1192 public $fullpath_orig;
1197 public $description;
1220 public $gen_or_uploaded;
1224 public $extraparams;
1228 public $date_c =
'';
1232 public $date_m =
'';
1251 public $src_object_type;
1255 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.
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.