30 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'ecmfiles';
45 public $table_element =
'ecm_files';
50 public $picto =
'folder-open';
86 public $fullpath_orig;
111 public $gen_or_uploaded;
146 public $src_object_type;
151 public $src_object_id;
186 if (isset($this->
ref)) {
187 $this->
ref = trim($this->
ref);
189 if (isset($this->label)) {
190 $this->label = trim($this->label);
192 if (isset($this->share)) {
193 $this->share = trim($this->share);
195 if (isset($this->entity)) {
196 $this->entity = (int) $this->entity;
198 if (isset($this->filename)) {
199 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
201 if (isset($this->filepath)) {
202 $this->filepath = trim($this->filepath);
203 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
205 if (isset($this->fullpath_orig)) {
206 $this->fullpath_orig = trim($this->fullpath_orig);
211 if (isset($this->keywords)) {
212 $this->keywords = trim($this->keywords);
214 if (isset($this->cover)) {
215 $this->cover = trim($this->cover);
217 if (isset($this->gen_or_uploaded)) {
218 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
220 if (isset($this->extraparams)) {
221 $this->extraparams = trim($this->extraparams);
223 if (isset($this->fk_user_c)) {
224 $this->fk_user_c = (int) $this->fk_user_c;
226 if (isset($this->fk_user_m)) {
227 $this->fk_user_m = (int) $this->fk_user_m;
229 if (isset($this->acl)) {
230 $this->acl = trim($this->acl);
232 if (isset($this->src_object_type)) {
233 $this->src_object_type = trim($this->src_object_type);
235 if (empty($this->date_c)) {
238 if (empty($this->date_m)) {
244 if (!empty($this->
ref)) {
247 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
248 $ref =
dol_hash($this->filepath.
'/'.$this->filename, 3);
252 if (empty($this->position)) {
254 $sql =
"SELECT MAX(position) as maxposition FROM ".MAIN_DB_PREFIX.$this->table_element;
255 $sql .=
" WHERE filepath ='".$this->db->escape($this->filepath).
"'";
259 $obj = $this->
db->fetch_object(
$resql);
260 $maxposition = (int) $obj->maxposition;
262 $this->errors[] =
'Error '.$this->db->lasterror();
265 $maxposition = $maxposition + 1;
267 $maxposition = $this->position;
271 if (empty($this->filename) || empty($this->filepath)) {
272 $this->errors[] =
'Bad property filename or filepath';
275 if (!isset($this->entity)) {
276 $this->entity = $conf->entity;
281 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
288 $sql .=
'fullpath_orig,';
289 $sql .=
'description,';
293 $sql .=
'gen_or_uploaded,';
294 $sql .=
'extraparams,';
297 $sql .=
'fk_user_c,';
298 $sql .=
'fk_user_m,';
300 $sql .=
'src_object_type,';
301 $sql .=
'src_object_id';
302 $sql .=
') VALUES (';
303 $sql .=
" '".$this->db->escape($ref).
"', ";
304 $sql .=
' '.(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
',';
305 $sql .=
' '.(!isset($this->share) ?
'NULL' :
"'".$this->db->escape($this->share).
"'").
',';
306 $sql .=
' '.((int) $this->entity).
',';
307 $sql .=
' '.(!isset($this->filename) ?
'NULL' :
"'".$this->db->escape($this->filename).
"'").
',';
308 $sql .=
' '.(!isset($this->filepath) ?
'NULL' :
"'".$this->db->escape($this->filepath).
"'").
',';
309 $sql .=
' '.(!isset($this->fullpath_orig) ?
'NULL' :
"'".$this->db->escape($this->fullpath_orig).
"'").
',';
311 $sql .=
' '.(!isset($this->keywords) ?
'NULL' :
"'".$this->db->escape($this->keywords).
"'").
',';
312 $sql .=
' '.(!isset($this->cover) ?
'NULL' :
"'".$this->db->escape($this->cover).
"'").
',';
313 $sql .=
' '.((int) $maxposition).
',';
314 $sql .=
' '.(!isset($this->gen_or_uploaded) ?
'NULL' :
"'".$this->db->escape($this->gen_or_uploaded).
"'").
',';
315 $sql .=
' '.(!isset($this->extraparams) ?
'NULL' :
"'".$this->db->escape($this->extraparams).
"'").
',';
316 $sql .=
" '".$this->db->idate($this->date_c).
"',";
317 $sql .=
' '.(!isset($this->date_m) ||
dol_strlen($this->date_m) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_m).
"'").
',';
318 $sql .=
' '.(!isset($this->fk_user_c) ? $user->id : $this->fk_user_c).
',';
319 $sql .=
' '.(!isset($this->fk_user_m) ?
'NULL' : $this->fk_user_m).
',';
320 $sql .=
' '.(!isset($this->acl) ?
'NULL' :
"'".$this->db->escape($this->acl).
"'").
',';
321 $sql .=
' '.(!isset($this->src_object_type) ?
'NULL' :
"'".$this->db->escape($this->src_object_type).
"'").
',';
322 $sql .=
' '.(!isset($this->src_object_id) ?
'NULL' : $this->src_object_id);
330 if ($this->
db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
331 $this->errors[] =
'Error DB_ERROR_RECORD_ALREADY_EXISTS : '.$this->db->lasterror();
333 $this->errors[] =
'Error '.$this->db->lasterror();
335 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
339 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
340 $this->position = $maxposition;
345 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_CREATE', $user);
355 $this->
db->rollback();
377 public function fetch($id, $ref =
'', $relativepath =
'', $hashoffile =
'', $hashforshare =
'', $src_object_type =
'', $src_object_id = 0)
388 $sql .=
" t.entity,";
389 $sql .=
" t.filename,";
390 $sql .=
" t.filepath,";
391 $sql .=
" t.fullpath_orig,";
392 $sql .=
" t.description,";
393 $sql .=
" t.keywords,";
395 $sql .=
" t.position,";
396 $sql .=
" t.gen_or_uploaded,";
397 $sql .=
" t.extraparams,";
398 $sql .=
" t.date_c,";
399 $sql .=
" t.tms as date_m,";
400 $sql .=
" t.fk_user_c,";
401 $sql .=
" t.fk_user_m,";
402 $sql .=
' t.note_private,';
403 $sql .=
' t.note_public,';
405 $sql .=
" t.src_object_type,";
406 $sql .=
" t.src_object_id";
407 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
408 $sql .=
' WHERE 1 = 1';
414 $relativepathwithnoexe = preg_replace(
'/\.noexe$/',
'', $relativepath);
415 $sql .=
" AND t.filepath = '".$this->db->escape(dirname($relativepath)).
"'";
416 $filename = basename($relativepathwithnoexe);
417 if ($filename !=
'*') {
418 $sql .=
" AND t.filename = '".$this->db->escape($filename).
"'";
420 $sql .=
" AND t.entity = ".$conf->entity;
421 } elseif (!empty($ref)) {
422 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
423 $sql .=
" AND t.entity = ".$conf->entity;
424 } elseif (!empty($hashoffile)) {
425 $sql .=
" AND t.label = '".$this->db->escape($hashoffile).
"'";
426 $sql .=
" AND t.entity = ".$conf->entity;
427 } elseif (!empty($hashforshare)) {
428 if ($hashforshare !=
'shared') {
429 $sql .=
" AND t.share = '".$this->db->escape($hashforshare).
"'";
431 $sql .=
" AND t.share IS NOT NULL AND t.share <> ''";
434 } elseif ($src_object_type && $src_object_id) {
436 $sql .=
" AND t.src_object_type = '".$this->db->escape($src_object_type).
"' AND t.src_object_id = ".((int) $src_object_id);
437 $sql .=
" AND t.entity = ".((int) $conf->entity);
439 $sql .=
' AND t.rowid = '.((int) $id);
442 $this->
db->plimit(1);
443 $this->
db->order(
't.rowid',
'ASC');
447 $numrows = $this->
db->num_rows(
$resql);
449 $obj = $this->
db->fetch_object(
$resql);
451 $this->
id = $obj->rowid;
452 $this->
ref = $obj->ref;
453 $this->label = $obj->label;
454 $this->share = $obj->share;
455 $this->entity = $obj->entity;
456 $this->filename = $obj->filename;
457 $this->filepath = $obj->filepath;
458 $this->fullpath_orig = $obj->fullpath_orig;
460 $this->keywords = $obj->keywords;
461 $this->cover = $obj->cover;
462 $this->position = $obj->position;
463 $this->gen_or_uploaded = $obj->gen_or_uploaded;
464 $this->extraparams = $obj->extraparams;
465 $this->date_c = $this->
db->jdate($obj->date_c);
466 $this->date_m = $this->
db->jdate($obj->date_m);
467 $this->fk_user_c = $obj->fk_user_c;
468 $this->fk_user_m = $obj->fk_user_m;
469 $this->note_private = $obj->note_private;
470 $this->note_public = $obj->note_public;
471 $this->acl = $obj->acl;
472 $this->src_object_type = $obj->src_object_type;
473 $this->src_object_id = $obj->src_object_id;
490 $this->errors[] =
'Error '.$this->db->lasterror();
491 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
509 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
517 $sql .=
" t.entity,";
518 $sql .=
" t.filename,";
519 $sql .=
" t.filepath,";
520 $sql .=
" t.fullpath_orig,";
521 $sql .=
" t.description,";
522 $sql .=
" t.keywords,";
524 $sql .=
" t.position,";
525 $sql .=
" t.gen_or_uploaded,";
526 $sql .=
" t.extraparams,";
527 $sql .=
" t.date_c,";
528 $sql .=
" t.tms as date_m,";
529 $sql .=
" t.fk_user_c,";
530 $sql .=
" t.fk_user_m,";
532 $sql .=
" t.src_object_type,";
533 $sql .=
" t.src_object_id";
534 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
538 if (count($filter) > 0) {
539 foreach ($filter as $key => $value) {
540 if ($key ==
't.src_object_id') {
541 $sqlwhere[] = $key.
" = ".((int) $value);
543 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
547 $sql .=
' WHERE 1 = 1';
552 if (count($sqlwhere) > 0) {
553 $sql .=
' AND '.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere);
555 if (!empty($sortfield)) {
556 $sql .= $this->
db->order($sortfield, $sortorder);
558 if (!empty($limit)) {
559 $sql .= $this->
db->plimit($limit, $offset);
562 $this->lines = array();
568 while ($obj = $this->
db->fetch_object(
$resql)) {
571 $line->id = $obj->rowid;
572 $line->ref = $obj->rowid;
573 $line->label = $obj->label;
574 $line->share = $obj->share;
575 $line->entity = $obj->entity;
576 $line->filename = $obj->filename;
577 $line->filepath = $obj->filepath;
578 $line->fullpath_orig = $obj->fullpath_orig;
579 $line->description = $obj->description;
580 $line->keywords = $obj->keywords;
581 $line->cover = $obj->cover;
582 $line->position = $obj->position;
583 $line->gen_or_uploaded = $obj->gen_or_uploaded;
584 $line->extraparams = $obj->extraparams;
585 $line->date_c = $this->
db->jdate($obj->date_c);
586 $line->date_m = $this->
db->jdate($obj->date_m);
587 $line->fk_user_c = $obj->fk_user_c;
588 $line->fk_user_m = $obj->fk_user_m;
589 $line->acl = $obj->acl;
590 $line->src_object_type = $obj->src_object_type;
591 $line->src_object_id = $obj->src_object_id;
592 $this->lines[] = $line;
598 $this->errors[] =
'Error '.$this->db->lasterror();
599 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
623 if (isset($this->
ref)) {
624 $this->
ref = trim($this->
ref);
626 if (isset($this->label)) {
627 $this->label = trim($this->label);
629 if (isset($this->share)) {
630 $this->share = trim($this->share);
632 if (isset($this->entity)) {
633 $this->entity = trim($this->entity);
635 if (isset($this->filename)) {
636 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
638 if (isset($this->filepath)) {
639 $this->filepath = trim($this->filepath);
640 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
642 if (isset($this->fullpath_orig)) {
643 $this->fullpath_orig = trim($this->fullpath_orig);
648 if (isset($this->keywords)) {
649 $this->keywords = trim($this->keywords);
651 if (isset($this->cover)) {
652 $this->cover = trim($this->cover);
654 if (isset($this->gen_or_uploaded)) {
655 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
657 if (isset($this->extraparams)) {
658 $this->extraparams = trim($this->extraparams);
660 if (isset($this->fk_user_m)) {
661 $this->fk_user_m = trim($this->fk_user_m);
663 if (isset($this->acl)) {
664 $this->acl = trim($this->acl);
666 if (isset($this->src_object_type)) {
667 $this->src_object_type = trim($this->src_object_type);
674 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
675 $sql .=
" ref = '".$this->db->escape(
dol_hash($this->filepath.
"/".$this->filename, 3)).
"',";
676 $sql .=
' label = '.(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
677 $sql .=
' share = '.(!empty($this->share) ?
"'".$this->db->escape($this->share).
"'" :
"null").
',';
678 $sql .=
' entity = '.(isset($this->entity) ? $this->entity : $conf->entity).
',';
679 $sql .=
' filename = '.(isset($this->filename) ?
"'".$this->db->escape($this->filename).
"'" :
"null").
',';
680 $sql .=
' filepath = '.(isset($this->filepath) ?
"'".$this->db->escape($this->filepath).
"'" :
"null").
',';
681 $sql .=
' fullpath_orig = '.(isset($this->fullpath_orig) ?
"'".$this->db->escape($this->fullpath_orig).
"'" :
"null").
',';
682 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
683 $sql .=
' keywords = '.(isset($this->keywords) ?
"'".$this->db->escape($this->keywords).
"'" :
"null").
',';
684 $sql .=
' cover = '.(isset($this->cover) ?
"'".$this->db->escape($this->cover).
"'" :
"null").
',';
685 $sql .=
' position = '.(isset($this->position) ? $this->
db->escape($this->position) :
"0").
',';
686 $sql .=
' gen_or_uploaded = '.(isset($this->gen_or_uploaded) ?
"'".$this->db->escape($this->gen_or_uploaded).
"'" :
"null").
',';
687 $sql .=
' extraparams = '.(isset($this->extraparams) ?
"'".$this->db->escape($this->extraparams).
"'" :
"null").
',';
688 $sql .=
' date_c = '.(!isset($this->date_c) ||
dol_strlen($this->date_c) != 0 ?
"'".$this->db->idate($this->date_c).
"'" :
'null').
',';
690 $sql .=
' fk_user_m = '.($this->fk_user_m > 0 ? $this->fk_user_m : $user->id).
',';
691 $sql .=
' acl = '.(isset($this->acl) ?
"'".$this->db->escape($this->acl).
"'" :
"null").
',';
692 $sql .=
' src_object_id = '.($this->src_object_id > 0 ? $this->src_object_id :
"null").
',';
693 $sql .=
' src_object_type = '.(isset($this->src_object_type) ?
"'".$this->db->escape($this->src_object_type).
"'" :
"null");
694 $sql .=
' WHERE rowid='.((int) $this->
id);
701 $this->errors[] =
'Error '.$this->db->lasterror();
702 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
706 if (!$error && !$notrigger) {
708 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
717 $this->
db->rollback();
735 public function delete(
User $user, $notrigger =
false)
746 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_DELETE', $user);
757 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
762 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
763 $sql .=
' WHERE rowid='.((int) $this->
id);
768 $this->errors[] =
'Error '.$this->db->lasterror();
769 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
775 $this->
db->rollback();
797 $object =
new Ecmfiles($this->
db);
802 $object->fetch($fromid);
810 $object->context[
'createfromclone'] =
'createfromclone';
811 $result = $object->create($user);
816 $this->errors = $object->errors;
817 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
820 unset($object->context[
'createfromclone']);
828 $this->
db->rollback();
844 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
846 global $db, $conf, $langs;
847 global $dolibarr_main_authentication, $dolibarr_main_demo;
848 global $menumanager, $hookmanager;
850 if (!empty($conf->dol_no_mouse_hover)) {
856 $label =
'<u>'.$langs->trans(
"MyModule").
'</u>';
858 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
860 $url = DOL_URL_ROOT.
'/ecm/'.$this->table_name.
'_card.php?id='.$this->id;
863 if (empty($notooltip)) {
864 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
865 $label = $langs->trans(
"ShowProject");
866 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
868 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
869 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
871 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
874 $linkstart =
'<a href="'.$url.
'"';
875 $linkstart .= $linkclose.
'>';
879 $result .= ($linkstart.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
880 if ($withpicto != 2) {
884 $result .= $linkstart.$this->ref.$linkend;
887 $hookmanager->initHooks(array($this->element .
'dao'));
888 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
889 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
891 $result = $hookmanager->resPrint;
893 $result .= $hookmanager->resPrint;
906 return $this->
LibStatut($this->status, $mode);
937 $this->label =
'0a1b2c3e4f59999999';
939 $this->filename =
'myspecimenfilefile.pdf';
940 $this->filepath =
'/aaa/bbb';
941 $this->fullpath_orig =
'c:/file on my disk.pdf';
942 $this->
description =
'This is a long description of file';
943 $this->keywords =
'key1,key2';
946 $this->gen_or_uploaded =
'uploaded';
947 $this->extraparams =
'';
948 $this->date_c = (
dol_now() - 3600 * 24 * 10);
950 $this->fk_user_c = $user->id;
951 $this->fk_user_m =
'';
953 $this->src_object_type =
'product';
954 $this->src_object_id = 1;
976 public $fullpath_orig;
986 public $gen_or_uploaded;
1002 public $src_object_type;
1003 public $src_object_id;
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
getLibStatut($mode=0)
Retourne le libelle du status d'un user (actif, inactif)
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
update(User $user, $notrigger=false)
Update object into database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link to the object card (with optionaly the picto)
fetch($id, $ref='', $relativepath='', $hashoffile='', $hashforshare='', $src_object_type='', $src_object_id=0)
Load object in memory from the database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object in memory from the database.
__construct(DoliDB $db)
Constructor.
create(User $user, $notrigger=false)
Create object into database.
static LibStatut($status, $mode=0)
Return the status.
Class of an index line of a document.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_hash($chain, $type='0')
Returns a hash (non reversible encryption) of a string.
$conf db
API class for accounts.