30 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'ecmfiles';
45 public $table_element =
'ecm_files';
50 public $picto =
'generic';
86 public $fullpath_orig;
111 public $gen_or_uploaded;
146 public $src_object_type;
151 public $src_object_id;
180 if (isset($this->ref)) {
181 $this->ref = trim($this->ref);
183 if (isset($this->label)) {
184 $this->label = trim($this->label);
186 if (isset($this->share)) {
187 $this->share = trim($this->share);
189 if (isset($this->entity)) {
190 $this->entity = (int) $this->entity;
192 if (isset($this->filename)) {
193 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
195 if (isset($this->filepath)) {
196 $this->filepath = trim($this->filepath);
197 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
199 if (isset($this->fullpath_orig)) {
200 $this->fullpath_orig = trim($this->fullpath_orig);
205 if (isset($this->keywords)) {
206 $this->keywords = trim($this->keywords);
208 if (isset($this->cover)) {
209 $this->cover = trim($this->cover);
211 if (isset($this->gen_or_uploaded)) {
212 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
214 if (isset($this->extraparams)) {
215 $this->extraparams = trim($this->extraparams);
217 if (isset($this->fk_user_c)) {
218 $this->fk_user_c = (int) $this->fk_user_c;
220 if (isset($this->fk_user_m)) {
221 $this->fk_user_m = (int) $this->fk_user_m;
223 if (isset($this->acl)) {
224 $this->acl = trim($this->acl);
226 if (isset($this->src_object_type)) {
227 $this->src_object_type = trim($this->src_object_type);
229 if (empty($this->date_c)) {
232 if (empty($this->date_m)) {
238 if (!empty($this->ref)) {
241 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
242 $ref =
dol_hash($this->filepath.
'/'.$this->filename, 3);
246 if (empty($this->position)) {
248 $sql =
"SELECT MAX(position) as maxposition FROM ".MAIN_DB_PREFIX.$this->table_element;
249 $sql .=
" WHERE filepath ='".$this->db->escape($this->filepath).
"'";
253 $obj = $this->
db->fetch_object(
$resql);
254 $maxposition = (int) $obj->maxposition;
256 $this->errors[] =
'Error '.$this->db->lasterror();
259 $maxposition = $maxposition + 1;
261 $maxposition = $this->position;
265 if (empty($this->filename) || empty($this->filepath)) {
266 $this->errors[] =
'Bad property filename or filepath';
269 if (!isset($this->entity)) {
270 $this->entity = $conf->entity;
275 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
282 $sql .=
'fullpath_orig,';
283 $sql .=
'description,';
287 $sql .=
'gen_or_uploaded,';
288 $sql .=
'extraparams,';
291 $sql .=
'fk_user_c,';
292 $sql .=
'fk_user_m,';
294 $sql .=
'src_object_type,';
295 $sql .=
'src_object_id';
296 $sql .=
') VALUES (';
297 $sql .=
" '".$this->db->escape($ref).
"', ";
298 $sql .=
' '.(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
',';
299 $sql .=
' '.(!isset($this->share) ?
'NULL' :
"'".$this->db->escape($this->share).
"'").
',';
300 $sql .=
' '.$this->entity.
',';
301 $sql .=
' '.(!isset($this->filename) ?
'NULL' :
"'".$this->db->escape($this->filename).
"'").
',';
302 $sql .=
' '.(!isset($this->filepath) ?
'NULL' :
"'".$this->db->escape($this->filepath).
"'").
',';
303 $sql .=
' '.(!isset($this->fullpath_orig) ?
'NULL' :
"'".$this->db->escape($this->fullpath_orig).
"'").
',';
305 $sql .=
' '.(!isset($this->keywords) ?
'NULL' :
"'".$this->db->escape($this->keywords).
"'").
',';
306 $sql .=
' '.(!isset($this->cover) ?
'NULL' :
"'".$this->db->escape($this->cover).
"'").
',';
307 $sql .=
' '.$maxposition.
',';
308 $sql .=
' '.(!isset($this->gen_or_uploaded) ?
'NULL' :
"'".$this->db->escape($this->gen_or_uploaded).
"'").
',';
309 $sql .=
' '.(!isset($this->extraparams) ?
'NULL' :
"'".$this->db->escape($this->extraparams).
"'").
',';
310 $sql .=
' '.
"'".$this->
db->idate($this->date_c).
"'".
',';
311 $sql .=
' '.(!isset($this->date_m) ||
dol_strlen($this->date_m) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_m).
"'").
',';
312 $sql .=
' '.(!isset($this->fk_user_c) ? $user->id : $this->fk_user_c).
',';
313 $sql .=
' '.(!isset($this->fk_user_m) ?
'NULL' : $this->fk_user_m).
',';
314 $sql .=
' '.(!isset($this->acl) ?
'NULL' :
"'".$this->db->escape($this->acl).
"'").
',';
315 $sql .=
' '.(!isset($this->src_object_type) ?
'NULL' :
"'".$this->db->escape($this->src_object_type).
"'").
',';
316 $sql .=
' '.(!isset($this->src_object_id) ?
'NULL' : $this->src_object_id);
324 $this->errors[] =
'Error '.$this->db->lasterror();
325 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
329 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
330 $this->position = $maxposition;
335 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_CREATE', $user);
345 $this->
db->rollback();
367 public function fetch($id, $ref =
'', $relativepath =
'', $hashoffile =
'', $hashforshare =
'', $src_object_type =
'', $src_object_id = 0)
378 $sql .=
" t.entity,";
379 $sql .=
" t.filename,";
380 $sql .=
" t.filepath,";
381 $sql .=
" t.fullpath_orig,";
382 $sql .=
" t.description,";
383 $sql .=
" t.keywords,";
385 $sql .=
" t.position,";
386 $sql .=
" t.gen_or_uploaded,";
387 $sql .=
" t.extraparams,";
388 $sql .=
" t.date_c,";
389 $sql .=
" t.tms as date_m,";
390 $sql .=
" t.fk_user_c,";
391 $sql .=
" t.fk_user_m,";
393 $sql .=
" t.src_object_type,";
394 $sql .=
" t.src_object_id";
395 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
396 $sql .=
' WHERE 1 = 1';
402 $relativepathwithnoexe = preg_replace(
'/\.noexe$/',
'', $relativepath);
403 $sql .=
" AND t.filepath = '".$this->db->escape(dirname($relativepath)).
"'";
404 $filename = basename($relativepathwithnoexe);
405 if ($filename !=
'*') {
406 $sql .=
" AND t.filename = '".$this->db->escape($filename).
"'";
408 $sql .=
" AND t.entity = ".$conf->entity;
409 } elseif (!empty($ref)) {
410 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
411 $sql .=
" AND t.entity = ".$conf->entity;
412 } elseif (!empty($hashoffile)) {
413 $sql .=
" AND t.label = '".$this->db->escape($hashoffile).
"'";
414 $sql .=
" AND t.entity = ".$conf->entity;
415 } elseif (!empty($hashforshare)) {
416 $sql .=
" AND t.share = '".$this->db->escape($hashforshare).
"'";
418 } elseif ($src_object_type && $src_object_id) {
420 $sql .=
" AND t.src_object_type ='".$this->db->escape($src_object_type).
"' AND t.src_object_id = ".$this->
db->escape($src_object_id);
421 $sql .=
" AND t.entity = ".$conf->entity;
423 $sql .=
' AND t.rowid = '.$this->db->escape($id);
426 $this->
db->plimit(1);
427 $this->
db->order(
't.rowid',
'ASC');
431 $numrows = $this->
db->num_rows(
$resql);
433 $obj = $this->
db->fetch_object(
$resql);
435 $this->
id = $obj->rowid;
436 $this->ref = $obj->ref;
437 $this->label = $obj->label;
438 $this->share = $obj->share;
439 $this->entity = $obj->entity;
440 $this->filename = $obj->filename;
441 $this->filepath = $obj->filepath;
442 $this->fullpath_orig = $obj->fullpath_orig;
444 $this->keywords = $obj->keywords;
445 $this->cover = $obj->cover;
446 $this->position = $obj->position;
447 $this->gen_or_uploaded = $obj->gen_or_uploaded;
448 $this->extraparams = $obj->extraparams;
449 $this->date_c = $this->
db->jdate($obj->date_c);
450 $this->date_m = $this->
db->jdate($obj->date_m);
451 $this->fk_user_c = $obj->fk_user_c;
452 $this->fk_user_m = $obj->fk_user_m;
453 $this->acl = $obj->acl;
454 $this->src_object_type = $obj->src_object_type;
455 $this->src_object_id = $obj->src_object_id;
472 $this->errors[] =
'Error '.$this->db->lasterror();
473 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
491 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
499 $sql .=
" t.entity,";
500 $sql .=
" t.filename,";
501 $sql .=
" t.filepath,";
502 $sql .=
" t.fullpath_orig,";
503 $sql .=
" t.description,";
504 $sql .=
" t.keywords,";
506 $sql .=
" t.position,";
507 $sql .=
" t.gen_or_uploaded,";
508 $sql .=
" t.extraparams,";
509 $sql .=
" t.date_c,";
510 $sql .=
" t.tms as date_m,";
511 $sql .=
" t.fk_user_c,";
512 $sql .=
" t.fk_user_m,";
514 $sql .=
" t.src_object_type,";
515 $sql .=
" t.src_object_id";
516 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
520 if (count($filter) > 0) {
521 foreach ($filter as $key => $value) {
522 $sqlwhere [] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
525 $sql .=
' WHERE 1 = 1';
530 if (count($sqlwhere) > 0) {
531 $sql .=
' AND '.implode(
' '.$filtermode.
' ', $sqlwhere);
533 if (!empty($sortfield)) {
534 $sql .= $this->
db->order($sortfield, $sortorder);
536 if (!empty($limit)) {
537 $sql .=
' '.$this->db->plimit($limit, $offset);
540 $this->lines = array();
546 while ($obj = $this->
db->fetch_object(
$resql)) {
549 $line->id = $obj->rowid;
550 $line->ref = $obj->ref;
551 $line->label = $obj->label;
552 $line->share = $obj->share;
553 $line->entity = $obj->entity;
554 $line->filename = $obj->filename;
555 $line->filepath = $obj->filepath;
556 $line->fullpath_orig = $obj->fullpath_orig;
557 $line->description = $obj->description;
558 $line->keywords = $obj->keywords;
559 $line->cover = $obj->cover;
560 $line->position = $obj->position;
561 $line->gen_or_uploaded = $obj->gen_or_uploaded;
562 $line->extraparams = $obj->extraparams;
563 $line->date_c = $this->
db->jdate($obj->date_c);
564 $line->date_m = $this->
db->jdate($obj->date_m);
565 $line->fk_user_c = $obj->fk_user_c;
566 $line->fk_user_m = $obj->fk_user_m;
567 $line->acl = $obj->acl;
568 $line->src_object_type = $obj->src_object_type;
569 $line->src_object_id = $obj->src_object_id;
570 $this->lines[] = $line;
576 $this->errors[] =
'Error '.$this->db->lasterror();
577 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
601 if (isset($this->ref)) {
602 $this->ref = trim($this->ref);
604 if (isset($this->label)) {
605 $this->label = trim($this->label);
607 if (isset($this->share)) {
608 $this->share = trim($this->share);
610 if (isset($this->entity)) {
611 $this->entity = trim($this->entity);
613 if (isset($this->filename)) {
614 $this->filename = preg_replace(
'/\.noexe$/',
'', trim($this->filename));
616 if (isset($this->filepath)) {
617 $this->filepath = trim($this->filepath);
618 $this->filepath = preg_replace(
'/[\\/]+$/',
'', $this->filepath);
620 if (isset($this->fullpath_orig)) {
621 $this->fullpath_orig = trim($this->fullpath_orig);
626 if (isset($this->keywords)) {
627 $this->keywords = trim($this->keywords);
629 if (isset($this->cover)) {
630 $this->cover = trim($this->cover);
632 if (isset($this->gen_or_uploaded)) {
633 $this->gen_or_uploaded = trim($this->gen_or_uploaded);
635 if (isset($this->extraparams)) {
636 $this->extraparams = trim($this->extraparams);
638 if (isset($this->fk_user_m)) {
639 $this->fk_user_m = trim($this->fk_user_m);
641 if (isset($this->acl)) {
642 $this->acl = trim($this->acl);
644 if (isset($this->src_object_type)) {
645 $this->src_object_type = trim($this->src_object_type);
652 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
653 $sql .=
" ref = '".dol_hash($this->filepath.
'/'.$this->filename, 3).
"',";
654 $sql .=
' label = '.(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
655 $sql .=
' share = '.(!empty($this->share) ?
"'".$this->db->escape($this->share).
"'" :
"null").
',';
656 $sql .=
' entity = '.(isset($this->entity) ? $this->entity : $conf->entity).
',';
657 $sql .=
' filename = '.(isset($this->filename) ?
"'".$this->db->escape($this->filename).
"'" :
"null").
',';
658 $sql .=
' filepath = '.(isset($this->filepath) ?
"'".$this->db->escape($this->filepath).
"'" :
"null").
',';
659 $sql .=
' fullpath_orig = '.(isset($this->fullpath_orig) ?
"'".$this->db->escape($this->fullpath_orig).
"'" :
"null").
',';
660 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
661 $sql .=
' keywords = '.(isset($this->keywords) ?
"'".$this->db->escape($this->keywords).
"'" :
"null").
',';
662 $sql .=
' cover = '.(isset($this->cover) ?
"'".$this->db->escape($this->cover).
"'" :
"null").
',';
663 $sql .=
' position = '.(isset($this->position) ? $this->
db->escape($this->position) :
"0").
',';
664 $sql .=
' gen_or_uploaded = '.(isset($this->gen_or_uploaded) ?
"'".$this->db->escape($this->gen_or_uploaded).
"'" :
"null").
',';
665 $sql .=
' extraparams = '.(isset($this->extraparams) ?
"'".$this->db->escape($this->extraparams).
"'" :
"null").
',';
666 $sql .=
' date_c = '.(!isset($this->date_c) ||
dol_strlen($this->date_c) != 0 ?
"'".$this->db->idate($this->date_c).
"'" :
'null').
',';
668 $sql .=
' fk_user_m = '.($this->fk_user_m > 0 ? $this->fk_user_m : $user->id).
',';
669 $sql .=
' acl = '.(isset($this->acl) ?
"'".$this->db->escape($this->acl).
"'" :
"null").
',';
670 $sql .=
' src_object_id = '.($this->src_object_id > 0 ? $this->src_object_id :
"null").
',';
671 $sql .=
' src_object_type = '.(isset($this->src_object_type) ?
"'".$this->db->escape($this->src_object_type).
"'" :
"null");
672 $sql .=
' WHERE rowid='.$this->id;
679 $this->errors[] =
'Error '.$this->db->lasterror();
680 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
684 if (!$error && !$notrigger) {
686 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
695 $this->
db->rollback();
713 public function delete(
User $user, $notrigger =
false)
724 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_DELETE', $user);
734 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
735 $sql .=
' WHERE rowid='.$this->id;
740 $this->errors[] =
'Error '.$this->db->lasterror();
741 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
747 $this->
db->rollback();
769 $object =
new Ecmfiles($this->
db);
774 $object->fetch($fromid);
782 $object->context[
'createfromclone'] =
'createfromclone';
783 $result = $object->create($user);
788 $this->errors = $object->errors;
789 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
792 unset($object->context[
'createfromclone']);
800 $this->
db->rollback();
816 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
818 global $db, $conf, $langs;
819 global $dolibarr_main_authentication, $dolibarr_main_demo;
822 if (!empty($conf->dol_no_mouse_hover)) {
828 $label =
'<u>'.$langs->trans(
"MyModule").
'</u>';
830 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
832 $url = DOL_URL_ROOT.
'/ecm/'.$this->table_name.
'_card.php?id='.$this->id;
835 if (empty($notooltip)) {
836 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
837 $label = $langs->trans(
"ShowProject");
838 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
840 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
841 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
843 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
846 $linkstart =
'<a href="'.$url.
'"';
847 $linkstart .= $linkclose.
'>';
851 $result .= ($linkstart.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
852 if ($withpicto != 2) {
856 $result .= $linkstart.$this->ref.$linkend;
868 return $this->
LibStatut($this->status, $mode);
899 $this->label =
'0a1b2c3e4f59999999';
901 $this->filename =
'myspecimenfilefile.pdf';
902 $this->filepath =
'/aaa/bbb';
903 $this->fullpath_orig =
'c:/file on my disk.pdf';
904 $this->
description =
'This is a long description of file';
905 $this->keywords =
'key1,key2';
908 $this->gen_or_uploaded =
'uploaded';
909 $this->extraparams =
'';
910 $this->date_c = (
dol_now() - 3600 * 24 * 10);
912 $this->fk_user_c = $user->id;
913 $this->fk_user_m =
'';
915 $this->src_object_type =
'product';
916 $this->src_object_id = 1;
938 public $fullpath_orig;
948 public $gen_or_uploaded;
964 public $src_object_type;
965 public $src_object_id;
dol_hash($chain, $type= '0')
Returns a hash of a string.
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.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
static LibStatut($status, $mode=0)
Return the status.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, array $filter=array(), $filtermode= 'AND')
Load object in memory from the database.
$conf db
API class for accounts.
Class of an index line of a document.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
create(User $user, $notrigger=false)
Create object into database.
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...
getNomUrl($withpicto=0, $option= '', $notooltip=0, $maxlen=24, $morecss= '')
Return a link to the object card (with optionaly the picto)
update(User $user, $notrigger=false)
Update object into database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Class to manage ECM files.
fetch($id, $ref= '', $relativepath= '', $hashoffile= '', $hashforshare= '', $src_object_type= '', $src_object_id=0)
Load object in memory from the database.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
__construct(DoliDB $db)
Constructor.