dolibarr  9.0.0
ecmfiles.class.php
1 <?php
2 /* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
4  * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2015 RaphaĆ«l Doursenaud <rdoursenaud@gpcsolutions.fr>
6  * Copyright (C) 2018 Francis Appels <francis.appels@yahoo.com>
7  * Copyright (C) ---Put here your own copyright and developer email---
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 // Put here all includes required by your class file
30 require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
31 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
32 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
33 
37 class EcmFiles extends CommonObject
38 {
42  public $element = 'ecmfiles';
43 
47  public $table_element = 'ecm_files';
48 
52  public $picto = 'generic';
53 
57  public $ref;
58 
63  public $label;
64 
65  public $share; // hash for file sharing, empty by default (example: getRandomPassword(true))
66 
70  public $entity;
71 
72  public $filename;
73  public $filepath;
74  public $fullpath_orig;
75 
79  public $description;
80 
81  public $keywords;
82  public $cover;
83  public $position;
84  public $gen_or_uploaded; // can be 'generated', 'uploaded', 'unknown'
85  public $extraparams;
86  public $date_c = '';
87  public $date_m = '';
88 
92  public $fk_user_c;
93 
97  public $fk_user_m;
98 
99  public $acl;
100  public $src_object_type;
101  public $src_object_id;
102 
103 
109  public function __construct(DoliDB $db)
110  {
111  $this->db = $db;
112  }
113 
121  public function create(User $user, $notrigger = false)
122  {
123  global $conf;
124 
125  dol_syslog(__METHOD__, LOG_DEBUG);
126 
127  $error = 0;
128 
129  // Clean parameters
130  if (isset($this->ref)) {
131  $this->ref = trim($this->ref);
132  }
133  if (isset($this->label)) {
134  $this->label = trim($this->label);
135  }
136  if (isset($this->share)) {
137  $this->share = trim($this->share);
138  }
139  if (isset($this->entity)) {
140  $this->entity = trim($this->entity);
141  }
142  if (isset($this->filename)) {
143  $this->filename = trim($this->filename);
144  }
145  if (isset($this->filepath)) {
146  $this->filepath = trim($this->filepath);
147  $this->filepath = preg_replace('/[\\/]+$/', '', $this->filepath); // Remove last /
148  }
149  if (isset($this->fullpath_orig)) {
150  $this->fullpath_orig = trim($this->fullpath_orig);
151  }
152  if (isset($this->description)) {
153  $this->description = trim($this->description);
154  }
155  if (isset($this->keywords)) {
156  $this->keywords = trim($this->keywords);
157  }
158  if (isset($this->cover)) {
159  $this->cover = trim($this->cover);
160  }
161  if (isset($this->gen_or_uploaded)) {
162  $this->gen_or_uploaded = trim($this->gen_or_uploaded);
163  }
164  if (isset($this->extraparams)) {
165  $this->extraparams = trim($this->extraparams);
166  }
167  if (isset($this->fk_user_c)) {
168  $this->fk_user_c = trim($this->fk_user_c);
169  }
170  if (isset($this->fk_user_m)) {
171  $this->fk_user_m = trim($this->fk_user_m);
172  }
173  if (isset($this->acl)) {
174  $this->acl = trim($this->acl);
175  }
176  if (isset($this->src_object_type)) {
177  $this->src_object_type = trim($this->src_object_type);
178  }
179  if (empty($this->date_c)) $this->date_c = dol_now();
180  if (empty($this->date_m)) $this->date_m = dol_now();
181 
182  // If ref not defined
183  $ref = '';
184  if (! empty($this->ref))
185  {
186  $ref=$this->ref;
187  }
188  else {
189  include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
190  $ref = dol_hash($this->filepath.'/'.$this->filename, 3);
191  }
192 
193  $maxposition=0;
194  if (empty($this->position)) // Get max used
195  {
196  $sql = "SELECT MAX(position) as maxposition FROM " . MAIN_DB_PREFIX . $this->table_element;
197  $sql.= " WHERE filepath ='".$this->db->escape($this->filepath)."'";
198 
199  $resql = $this->db->query($sql);
200  if ($resql)
201  {
202  $obj = $this->db->fetch_object($resql);
203  $maxposition = (int) $obj->maxposition;
204  }
205  else
206  {
207  $this->errors[] = 'Error ' . $this->db->lasterror();
208  return --$error;
209  }
210  $maxposition=$maxposition+1;
211  }
212  else
213  {
214  $maxposition=$this->position;
215  }
216 
217  // Check parameters
218  if (empty($this->filename) || empty($this->filepath))
219  {
220  $this->errors[] = 'Bad property filename or filepath';
221  return --$error;
222  }
223  if (! isset($this->entity))
224  {
225  $this->entity = $conf->entity;
226  }
227  // Put here code to add control on parameters values
228 
229  // Insert request
230  $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
231  $sql.= 'ref,';
232  $sql.= 'label,';
233  $sql.= 'share,';
234  $sql.= 'entity,';
235  $sql.= 'filename,';
236  $sql.= 'filepath,';
237  $sql.= 'fullpath_orig,';
238  $sql.= 'description,';
239  $sql.= 'keywords,';
240  $sql.= 'cover,';
241  $sql.= 'position,';
242  $sql.= 'gen_or_uploaded,';
243  $sql.= 'extraparams,';
244  $sql.= 'date_c,';
245  $sql.= 'date_m,';
246  $sql.= 'fk_user_c,';
247  $sql.= 'fk_user_m,';
248  $sql.= 'acl,';
249  $sql.= 'src_object_type,';
250  $sql.= 'src_object_id';
251  $sql .= ') VALUES (';
252  $sql .= " '".$ref."', ";
253  $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").',';
254  $sql .= ' '.(! isset($this->share)?'NULL':"'".$this->db->escape($this->share)."'").',';
255  $sql .= ' '.$this->entity.',';
256  $sql .= ' '.(! isset($this->filename)?'NULL':"'".$this->db->escape($this->filename)."'").',';
257  $sql .= ' '.(! isset($this->filepath)?'NULL':"'".$this->db->escape($this->filepath)."'").',';
258  $sql .= ' '.(! isset($this->fullpath_orig)?'NULL':"'".$this->db->escape($this->fullpath_orig)."'").',';
259  $sql .= ' '.(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").',';
260  $sql .= ' '.(! isset($this->keywords)?'NULL':"'".$this->db->escape($this->keywords)."'").',';
261  $sql .= ' '.(! isset($this->cover)?'NULL':"'".$this->db->escape($this->cover)."'").',';
262  $sql .= ' '.$maxposition.',';
263  $sql .= ' '.(! isset($this->gen_or_uploaded)?'NULL':"'".$this->db->escape($this->gen_or_uploaded)."'").',';
264  $sql .= ' '.(! isset($this->extraparams)?'NULL':"'".$this->db->escape($this->extraparams)."'").',';
265  $sql .= ' '."'".$this->db->idate($this->date_c)."'".',';
266  $sql .= ' '.(! isset($this->date_m) || dol_strlen($this->date_m)==0?'NULL':"'".$this->db->idate($this->date_m)."'").',';
267  $sql .= ' '.(! isset($this->fk_user_c)?$user->id:$this->fk_user_c).',';
268  $sql .= ' '.(! isset($this->fk_user_m)?'NULL':$this->fk_user_m).',';
269  $sql .= ' '.(! isset($this->acl)?'NULL':"'".$this->db->escape($this->acl)."'").',';
270  $sql .= ' '.(! isset($this->src_object_type)?'NULL':"'".$this->db->escape($this->src_object_type)."'").',';
271  $sql .= ' '.(! isset($this->src_object_id)?'NULL':$this->src_object_id);
272  $sql .= ')';
273 
274  $this->db->begin();
275 
276  $resql = $this->db->query($sql);
277  if (!$resql) {
278  $error ++;
279  $this->errors[] = 'Error ' . $this->db->lasterror();
280  dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
281  }
282 
283  if (!$error) {
284  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
285  $this->position = $maxposition;
286 
287  // Triggers
288  if (! $notrigger)
289  {
290  // Call triggers
291  $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user);
292  if ($result < 0) { $error++; }
293  // End call triggers
294  }
295  }
296 
297  // Commit or rollback
298  if ($error) {
299  $this->db->rollback();
300 
301  return - 1 * $error;
302  } else {
303  $this->db->commit();
304 
305  return $this->id;
306  }
307  }
308 
321  public function fetch($id, $ref = '', $relativepath = '', $hashoffile='', $hashforshare='', $src_object_type='', $src_object_id=0)
322  {
323  global $conf;
324 
325  dol_syslog(__METHOD__, LOG_DEBUG);
326 
327  $sql = 'SELECT';
328  $sql .= ' t.rowid,';
329  $sql .= " t.ref,";
330  $sql .= " t.label,";
331  $sql .= " t.share,";
332  $sql .= " t.entity,";
333  $sql .= " t.filename,";
334  $sql .= " t.filepath,";
335  $sql .= " t.fullpath_orig,";
336  $sql .= " t.description,";
337  $sql .= " t.keywords,";
338  $sql .= " t.cover,";
339  $sql .= " t.position,";
340  $sql .= " t.gen_or_uploaded,";
341  $sql .= " t.extraparams,";
342  $sql .= " t.date_c,";
343  $sql .= " t.date_m,";
344  $sql .= " t.fk_user_c,";
345  $sql .= " t.fk_user_m,";
346  $sql .= " t.acl,";
347  $sql .= " t.src_object_type,";
348  $sql .= " t.src_object_id";
349  $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
350  $sql.= ' WHERE 1 = 1';
351  /* Fetching this table depends on filepath+filename, it must not depends on entity
352  if (! empty($conf->multicompany->enabled)) {
353  $sql .= " AND entity IN (" . getEntity('ecmfiles') . ")";
354  }*/
355  if ($relativepath) {
356  $sql .= " AND t.filepath = '" . $this->db->escape(dirname($relativepath)) . "' AND t.filename = '".$this->db->escape(basename($relativepath))."'";
357  $sql .= " AND t.entity = ".$conf->entity; // unique key include the entity so each company has its own index
358  }
359  elseif (! empty($ref)) { // hash of file path
360  $sql .= " AND t.ref = '".$this->db->escape($ref)."'";
361  $sql .= " AND t.entity = ".$conf->entity; // unique key include the entity so each company has its own index
362  }
363  elseif (! empty($hashoffile)) { // hash of content
364  $sql .= " AND t.label = '".$this->db->escape($hashoffile)."'";
365  $sql .= " AND t.entity = ".$conf->entity; // unique key include the entity so each company has its own index
366  }
367  elseif (! empty($hashforshare)) {
368  $sql .= " AND t.share = '".$this->db->escape($hashforshare)."'";
369  //$sql .= " AND t.entity = ".$conf->entity; // hashforshare already unique
370  }
371  elseif ($src_object_type && $src_object_id)
372  {
373  // Warning: May return several record, and only first one is returned !
374  $sql .= " AND t.src_object_type ='".$this->db->escape($src_object_type)."' AND t.src_object_id = ".$this->db->escape($src_object_id);
375  $sql .= " AND t.entity = ".$conf->entity;
376  }
377  else {
378  $sql .= ' AND t.rowid = '.$this->db->escape($id); // rowid already unique
379  }
380 
381  $this->db->plimit(1); // When we search on src or on hash of content (hashforfile) to solve hash conflict when several files has same content, we take first one only
382  $this->db->order('t.rowid', 'ASC');
383 
384  $resql = $this->db->query($sql);
385  if ($resql) {
386  $numrows = $this->db->num_rows($resql);
387  if ($numrows) {
388  $obj = $this->db->fetch_object($resql);
389 
390  $this->id = $obj->rowid;
391  $this->ref = $obj->ref;
392  $this->label = $obj->label;
393  $this->share = $obj->share;
394  $this->entity = $obj->entity;
395  $this->filename = $obj->filename;
396  $this->filepath = $obj->filepath;
397  $this->fullpath_orig = $obj->fullpath_orig;
398  $this->description = $obj->description;
399  $this->keywords = $obj->keywords;
400  $this->cover = $obj->cover;
401  $this->position = $obj->position;
402  $this->gen_or_uploaded = $obj->gen_or_uploaded;
403  $this->extraparams = $obj->extraparams;
404  $this->date_c = $this->db->jdate($obj->date_c);
405  $this->date_m = $this->db->jdate($obj->date_m);
406  $this->fk_user_c = $obj->fk_user_c;
407  $this->fk_user_m = $obj->fk_user_m;
408  $this->acl = $obj->acl;
409  $this->src_object_type = $obj->src_object_type;
410  $this->src_object_id = $obj->src_object_id;
411  }
412 
413  // Retrieve all extrafields for invoice
414  // fetch optionals attributes and labels
415  // $this->fetch_optionals();
416 
417  // $this->fetch_lines();
418 
419  $this->db->free($resql);
420 
421  if ($numrows) {
422  return 1;
423  } else {
424  return 0;
425  }
426  } else {
427  $this->errors[] = 'Error ' . $this->db->lasterror();
428  dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
429 
430  return -1;
431  }
432  }
433 
446  public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
447  {
448  dol_syslog(__METHOD__, LOG_DEBUG);
449 
450  $sql = 'SELECT';
451  $sql .= ' t.rowid,';
452  $sql .= " t.label,";
453  $sql .= " t.share,";
454  $sql .= " t.entity,";
455  $sql .= " t.filename,";
456  $sql .= " t.filepath,";
457  $sql .= " t.fullpath_orig,";
458  $sql .= " t.description,";
459  $sql .= " t.keywords,";
460  $sql .= " t.cover,";
461  $sql .= " t.position,";
462  $sql .= " t.gen_or_uploaded,";
463  $sql .= " t.extraparams,";
464  $sql .= " t.date_c,";
465  $sql .= " t.date_m,";
466  $sql .= " t.fk_user_c,";
467  $sql .= " t.fk_user_m,";
468  $sql .= " t.acl,";
469  $sql .= " t.src_object_type,";
470  $sql .= " t.src_object_id";
471  $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
472 
473  // Manage filter
474  $sqlwhere = array();
475  if (count($filter) > 0) {
476  foreach ($filter as $key => $value) {
477  $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
478  }
479  }
480  $sql.= ' WHERE 1 = 1';
481  /* Fetching this table depends on filepath+filename, it must not depends on entity
482  if (! empty($conf->multicompany->enabled)) {
483  $sql .= " AND entity IN (" . getEntity('ecmfiles') . ")";
484  }*/
485  if (count($sqlwhere) > 0) {
486  $sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere);
487  }
488  if (!empty($sortfield)) {
489  $sql .= $this->db->order($sortfield,$sortorder);
490  }
491  if (!empty($limit)) {
492  $sql .= ' ' . $this->db->plimit($limit, $offset);
493  }
494 
495  $this->lines = array();
496 
497  $resql = $this->db->query($sql);
498  if ($resql) {
499  $num = $this->db->num_rows($resql);
500 
501  while ($obj = $this->db->fetch_object($resql)) {
502  $line = new EcmfilesLine();
503 
504  $line->id = $obj->rowid;
505  $line->ref = $obj->ref;
506  $line->label = $obj->label;
507  $line->share = $obj->share;
508  $line->entity = $obj->entity;
509  $line->filename = $obj->filename;
510  $line->filepath = $obj->filepath;
511  $line->fullpath_orig = $obj->fullpath_orig;
512  $line->description = $obj->description;
513  $line->keywords = $obj->keywords;
514  $line->cover = $obj->cover;
515  $line->position = $obj->position;
516  $line->gen_or_uploaded = $obj->gen_or_uploaded;
517  $line->extraparams = $obj->extraparams;
518  $line->date_c = $this->db->jdate($obj->date_c);
519  $line->date_m = $this->db->jdate($obj->date_m);
520  $line->fk_user_c = $obj->fk_user_c;
521  $line->fk_user_m = $obj->fk_user_m;
522  $line->acl = $obj->acl;
523  $line->src_object_type = $obj->src_object_type;
524  $line->src_object_id = $obj->src_object_id;
525  $this->lines[] = $line;
526  }
527  $this->db->free($resql);
528 
529  return $num;
530  } else {
531  $this->errors[] = 'Error ' . $this->db->lasterror();
532  dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
533 
534  return - 1;
535  }
536  }
537 
546  public function update(User $user, $notrigger = false)
547  {
548  global $conf;
549 
550  $error = 0;
551 
552  dol_syslog(__METHOD__, LOG_DEBUG);
553 
554  // Clean parameters
555 
556  if (isset($this->ref)) {
557  $this->ref = trim($this->ref);
558  }
559  if (isset($this->label)) {
560  $this->label = trim($this->label);
561  }
562  if (isset($this->share)) {
563  $this->share = trim($this->share);
564  }
565  if (isset($this->entity)) {
566  $this->entity = trim($this->entity);
567  }
568  if (isset($this->filename)) {
569  $this->filename = trim($this->filename);
570  }
571  if (isset($this->filepath)) {
572  $this->filepath = trim($this->filepath);
573  }
574  if (isset($this->fullpath_orig)) {
575  $this->fullpath_orig = trim($this->fullpath_orig);
576  }
577  if (isset($this->description)) {
578  $this->description = trim($this->description);
579  }
580  if (isset($this->keywords)) {
581  $this->keywords = trim($this->keywords);
582  }
583  if (isset($this->cover)) {
584  $this->cover = trim($this->cover);
585  }
586  if (isset($this->gen_or_uploaded)) {
587  $this->gen_or_uploaded = trim($this->gen_or_uploaded);
588  }
589  if (isset($this->extraparams)) {
590  $this->extraparams = trim($this->extraparams);
591  }
592  if (isset($this->fk_user_m)) {
593  $this->fk_user_m = trim($this->fk_user_m);
594  }
595  if (isset($this->acl)) {
596  $this->acl = trim($this->acl);
597  }
598  if (isset($this->src_object_type)) {
599  $this->src_object_type = trim($this->src_object_type);
600  }
601 
602  // Check parameters
603  // Put here code to add a control on parameters values
604 
605  // Update request
606  $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
607  $sql .= " ref = '".dol_hash($this->filepath.'/'.$this->filename, 3)."',";
608  $sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").',';
609  $sql .= ' share = '.(! empty($this->share)?"'".$this->db->escape($this->share)."'":"null").',';
610  $sql .= ' entity = '.(isset($this->entity)?$this->entity:$conf->entity).',';
611  $sql .= ' filename = '.(isset($this->filename)?"'".$this->db->escape($this->filename)."'":"null").',';
612  $sql .= ' filepath = '.(isset($this->filepath)?"'".$this->db->escape($this->filepath)."'":"null").',';
613  $sql .= ' fullpath_orig = '.(isset($this->fullpath_orig)?"'".$this->db->escape($this->fullpath_orig)."'":"null").',';
614  $sql .= ' description = '.(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").',';
615  $sql .= ' keywords = '.(isset($this->keywords)?"'".$this->db->escape($this->keywords)."'":"null").',';
616  $sql .= ' cover = '.(isset($this->cover)?"'".$this->db->escape($this->cover)."'":"null").',';
617  $sql .= ' position = '.(isset($this->position)?$this->db->escape($this->position):"0").',';
618  $sql .= ' gen_or_uploaded = '.(isset($this->gen_or_uploaded)?"'".$this->db->escape($this->gen_or_uploaded)."'":"null").',';
619  $sql .= ' extraparams = '.(isset($this->extraparams)?"'".$this->db->escape($this->extraparams)."'":"null").',';
620  $sql .= ' date_c = '.(! isset($this->date_c) || dol_strlen($this->date_c) != 0 ? "'".$this->db->idate($this->date_c)."'" : 'null').',';
621  //$sql .= ' date_m = '.(! isset($this->date_m) || dol_strlen($this->date_m) != 0 ? "'".$this->db->idate($this->date_m)."'" : 'null').','; // Field automatically updated
622  $sql .= ' fk_user_m = '.($this->fk_user_m > 0?$this->fk_user_m:$user->id).',';
623  $sql .= ' acl = '.(isset($this->acl)?"'".$this->db->escape($this->acl)."'":"null").',';
624  $sql .= ' src_object_id = '.($this->src_object_id > 0?$this->src_object_id:"null").',';
625  $sql .= ' src_object_type = '.(isset($this->src_object_type)?"'".$this->db->escape($this->src_object_type)."'":"null");
626  $sql .= ' WHERE rowid=' . $this->id;
627 
628  $this->db->begin();
629 
630  $resql = $this->db->query($sql);
631  if (!$resql) {
632  $error ++;
633  $this->errors[] = 'Error ' . $this->db->lasterror();
634  dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
635  }
636 
637  // Triggers
638  if (! $error && ! $notrigger)
639  {
640  // Call triggers
641  $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user);
642  if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail
643  // End call triggers
644  }
645 
646  // Commit or rollback
647  if ($error) {
648  $this->db->rollback();
649 
650  return - 1 * $error;
651  } else {
652  $this->db->commit();
653 
654  return 1;
655  }
656  }
657 
666  public function delete(User $user, $notrigger = false)
667  {
668  dol_syslog(__METHOD__, LOG_DEBUG);
669 
670  $error = 0;
671 
672  $this->db->begin();
673 
674  // Triggers
675  if (! $notrigger)
676  {
677  // Call triggers
678  $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE',$user);
679  if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail
680  // End call triggers
681  }
682 
683  // If you need to delete child tables to, you can insert them here
684 
685  if (!$error) {
686  $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
687  $sql .= ' WHERE rowid=' . $this->id;
688 
689  $resql = $this->db->query($sql);
690  if (!$resql) {
691  $error ++;
692  $this->errors[] = 'Error ' . $this->db->lasterror();
693  dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
694  }
695  }
696 
697  // Commit or rollback
698  if ($error) {
699  $this->db->rollback();
700 
701  return - 1 * $error;
702  } else {
703  $this->db->commit();
704 
705  return 1;
706  }
707  }
708 
716  public function createFromClone($fromid)
717  {
718  dol_syslog(__METHOD__, LOG_DEBUG);
719 
720  global $user;
721  $error = 0;
722  $object = new Ecmfiles($this->db);
723 
724  $this->db->begin();
725 
726  // Load source object
727  $object->fetch($fromid);
728  // Reset object
729  $object->id = 0;
730 
731  // Clear fields
732  // ...
733 
734  // Create clone
735  $object->context['createfromclone'] = 'createfromclone';
736  $result = $object->create($user);
737 
738  // Other options
739  if ($result < 0) {
740  $error ++;
741  $this->errors = $object->errors;
742  dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
743  }
744 
745  unset($object->context['createfromclone']);
746 
747  // End
748  if (!$error) {
749  $this->db->commit();
750 
751  return $object->id;
752  } else {
753  $this->db->rollback();
754 
755  return - 1;
756  }
757  }
758 
769  function getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
770  {
771  global $db, $conf, $langs;
772  global $dolibarr_main_authentication, $dolibarr_main_demo;
773  global $menumanager;
774 
775  if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
776 
777  $result = '';
778  $companylink = '';
779 
780  $label = '<u>' . $langs->trans("MyModule") . '</u>';
781  $label.= '<br>';
782  $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
783 
784  $url = DOL_URL_ROOT.'/ecm/'.$this->table_name.'_card.php?id='.$this->id;
785 
786  $linkclose='';
787  if (empty($notooltip))
788  {
789  if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
790  {
791  $label=$langs->trans("ShowProject");
792  $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
793  }
794  $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
795  $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
796  }
797  else $linkclose = ($morecss?' class="'.$morecss.'"':'');
798 
799  $linkstart = '<a href="'.$url.'"';
800  $linkstart.=$linkclose.'>';
801  $linkend='</a>';
802 
803  if ($withpicto)
804  {
805  $result.=($linkstart.img_object(($notooltip?'':$label), 'label', ($notooltip?'':'class="classfortooltip"')).$linkend);
806  if ($withpicto != 2) $result.=' ';
807  }
808  $result.= $linkstart . $this->ref . $linkend;
809  return $result;
810  }
811 
818  function getLibStatut($mode=0)
819  {
820  return $this->LibStatut($this->status,$mode);
821  }
822 
823  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
831  static function LibStatut($status,$mode=0)
832  {
833  // phpcs:enable
834  global $langs;
835  return '';
836  }
837 
838 
845  public function initAsSpecimen()
846  {
847  global $conf,$user;
848 
849  $this->id = 0;
850 
851  $this->label = '0a1b2c3e4f59999999';
852  $this->entity = '1';
853  $this->filename = 'myspecimenfilefile.pdf';
854  $this->filepath = '/aaa/bbb';
855  $this->fullpath_orig = 'c:/file on my disk.pdf';
856  $this->description = 'This is a long description of file';
857  $this->keywords = 'key1,key2';
858  $this->cover = '1';
859  $this->position = '5';
860  $this->gen_or_uploaded = 'uploaded';
861  $this->extraparams = '';
862  $this->date_c = (dol_now() - 3600 * 24 * 10);
863  $this->date_m = '';
864  $this->fk_user_c = $user->id;
865  $this->fk_user_m = '';
866  $this->acl = '';
867  $this->src_object_type = 'product';
868  $this->src_object_id = 1;
869  }
870 }
871 
872 
874 {
878  public $label;
879 
883  public $entity;
884 
885  public $filename;
886  public $filepath;
887  public $fullpath_orig;
888 
892  public $description;
893 
894  public $keywords;
895  public $cover;
896  public $position;
897  public $gen_or_uploaded; // can be 'generated', 'uploaded', 'unknown'
898  public $extraparams;
899  public $date_c = '';
900  public $date_m = '';
901 
905  public $fk_user_c;
906 
910  public $fk_user_m;
911 
912  public $acl;
913  public $src_object_type;
914  public $src_object_id;
915 }
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
getLibStatut($mode=0)
Retourne le libelle du status d&#39;un user (actif, inactif)
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object in memory from the database.
static LibStatut($status, $mode=0)
Return the status.
Class to manage Dolibarr users.
Definition: user.class.php:41
Class to manage Dolibarr database access.
fetch($id, $ref='', $relativepath='', $hashoffile='', $hashforshare='', $src_object_type='', $src_object_id=0)
Load object in memory from the database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
create(User $user, $notrigger=false)
Create object into database.
createFromClone($fromid)
Load an object from its id and create a new one in database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link to the object card (with optionaly the picto)
dol_now($mode='gmt')
Return date for now.
update(User $user, $notrigger=false)
Update object into database.
dol_hash($chain, $type='0')
Returns a hash of a string.
call_trigger($trigger_name, $user)
Call trigger based on this instance.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Class to manage ECM files.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
__construct(DoliDB $db)
Constructor.