33 public $element =
'ecm_directories';
38 public $table_element =
'ecm_directories';
43 public $picto =
'dir';
68 public $cachenbofdoc = -1;
98 public $cats = array();
103 public $motherof = array();
108 public $forbiddenchars = array(
'<',
'>',
':',
'/',
'\\',
'?',
'*',
'|',
'"');
113 public $forbiddencharsdir = array(
'<',
'>',
':',
'?',
'*',
'|',
'"');
118 public $full_arbo_loaded;
140 global $conf, $langs;
147 $this->fk_parent = trim($this->fk_parent);
149 $this->date_c = $now;
150 $this->fk_user_c = $user->id;
151 if ($this->fk_parent <= 0) {
152 $this->fk_parent = 0;
157 $relativepath = $this->label;
158 if ($this->fk_parent) {
160 $parent->fetch($this->fk_parent);
161 $relativepath = $parent->getRelativePath().$relativepath;
163 $relativepath = preg_replace(
'/([\/])+/i',
'/', $relativepath);
167 $cate_arbo = $cat->get_full_arbo(1);
169 foreach ($cate_arbo as $key => $categ) {
170 $path = str_replace($this->forbiddencharsdir,
'_', $categ[
'fullrelativename']);
172 if ($path == $relativepath) {
179 $this->error =
"ErrorDirAlreadyExists";
180 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
186 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"ecm_directories(";
189 $sql .=
"fk_parent,";
190 $sql .=
"description,";
191 $sql .=
"cachenbofdoc,";
194 $sql .=
") VALUES (";
195 $sql .=
" '".$this->db->escape($this->label).
"',";
196 $sql .=
" '".$this->db->escape($conf->entity).
"',";
197 $sql .=
" '".$this->db->escape($this->fk_parent).
"',";
198 $sql .=
" '".$this->db->escape($this->
description).
"',";
199 $sql .=
" ".$this->cachenbofdoc.
",";
200 $sql .=
" '".$this->db->idate($this->date_c).
"',";
201 $sql .=
" '".$this->db->escape($this->fk_user_c).
"'";
204 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
207 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"ecm_directories");
212 $error++; $this->error =
"ErrorFailedToCreateDir";
216 $result = $this->
call_trigger(
'MYECMDIR_CREATE', $user);
226 $this->
db->rollback();
230 $this->error =
"Error ".$this->db->lasterror();
231 $this->
db->rollback();
244 public function update($user = null, $notrigger = 0)
246 global $conf, $langs;
251 $this->label = trim($this->label);
252 $this->fk_parent = trim($this->fk_parent);
261 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
262 $sql .=
" label='".$this->db->escape($this->label).
"',";
263 $sql .=
" fk_parent='".$this->db->escape($this->fk_parent).
"',";
264 $sql .=
" description='".$this->db->escape($this->
description).
"'";
265 $sql .=
" WHERE rowid=".$this->id;
267 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
271 $this->error =
"Error ".$this->db->lasterror();
274 if (!$error && !$notrigger) {
276 $result = $this->
call_trigger(
'MYECMDIR_MODIFY', $user);
287 $this->
db->rollback();
302 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
303 if (preg_match(
'/[0-9]+/', $value)) {
304 $sql .=
" cachenbofdoc = ".(int) $value;
306 $sql .=
" cachenbofdoc = cachenbofdoc ".$value.
" 1";
308 $sql .=
" WHERE rowid = ".$this->id;
310 dol_syslog(get_class($this).
"::changeNbOfFiles", LOG_DEBUG);
313 $this->error =
"Error ".$this->db->lasterror();
316 if (preg_match(
'/[0-9]+/', $value)) {
317 $this->cachenbofdoc = (int) $value;
318 } elseif ($value ==
'+') {
319 $this->cachenbofdoc++;
320 } elseif ($value ==
'-') {
321 $this->cachenbofdoc--;
340 $sql .=
" t.fk_parent,";
341 $sql .=
" t.description,";
342 $sql .=
" t.cachenbofdoc,";
343 $sql .=
" t.fk_user_c,";
344 $sql .=
" t.fk_user_m,";
345 $sql .=
" t.date_c as date_c,";
346 $sql .=
" t.tms as date_m";
347 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_directories as t";
348 $sql .=
" WHERE t.rowid = ".((int) $id);
350 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
353 $obj = $this->
db->fetch_object(
$resql);
355 $this->
id = $obj->rowid;
356 $this->ref = $obj->rowid;
358 $this->label = $obj->label;
359 $this->fk_parent = $obj->fk_parent;
361 $this->cachenbofdoc = $obj->cachenbofdoc;
362 $this->fk_user_m = $obj->fk_user_m;
363 $this->fk_user_c = $obj->fk_user_c;
364 $this->date_c = $this->
db->jdate($obj->date_c);
365 $this->date_m = $this->
db->jdate($obj->date_m);
376 $this->error =
"Error ".$this->db->lasterror();
390 public function delete($user, $mode =
'all', $deletedirrecursive = 0)
392 global $conf, $langs;
393 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
397 if ($mode !=
'databaseonly') {
401 dol_syslog(get_class($this).
"::delete remove directory id=".$this->
id.
" mode=".$mode.(($mode ==
'databaseonly') ?
'' :
' relativepath='.$relativepath));
405 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ecm_directories";
406 $sql .=
" WHERE rowid=".$this->id;
408 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
411 $this->
db->rollback();
412 $this->error =
"Error ".$this->db->lasterror();
416 $result = $this->
call_trigger(
'MYECMDIR_DELETE', $user);
418 $this->
db->rollback();
424 if ($mode !=
'databaseonly') {
425 $file = $conf->ecm->dir_output.
"/".$relativepath;
426 if ($deletedirrecursive) {
436 $this->error =
'ErrorFailToDeleteDir';
437 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
438 $this->
db->rollback();
461 $this->label =
'MyDirectory';
462 $this->fk_parent =
'0';
477 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $more =
'', $notooltip = 0)
483 $newref = $this->ref;
484 $label = $langs->trans(
"ShowECMSection").
': '.$newref;
485 $linkclose =
'"'.($more ?
' '.$more :
'').
' title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
487 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/dir_card.php?section='.$this->
id.$linkclose;
488 if ($option ==
'index') {
489 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=true'.$linkclose;
491 if ($option ==
'indexexpanded') {
492 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=false'.$linkclose;
494 if ($option ==
'indexnotexpanded') {
495 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=true'.$linkclose;
502 $result .= $linkstart;
504 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
506 if ($withpicto != 2) {
507 $result .= ($max ?
dol_trunc($newref, $max,
'middle') : $newref);
525 $idtosearch = $this->id;
530 foreach ($this->cats as $key => $val) {
531 if ($this->cats[$key][
'id'] == $idtosearch) {
538 if ($cursorindex >= 0) {
542 $idtosearch = $this->cats[$cursorindex][
'id_mere'];
545 }
while ($cursorindex >= 0 && !empty($idtosearch) && $i < 100);
561 $this->motherof = array();
564 $sql =
"SELECT fk_parent as id_parent, rowid as id_son";
565 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_directories";
566 $sql .=
" WHERE fk_parent != 0";
567 $sql .=
" AND entity = ".$conf->entity;
569 dol_syslog(get_class($this).
"::load_motherof", LOG_DEBUG);
573 while ($obj = $this->
db->fetch_object(
$resql)) {
574 $this->motherof[$obj->id_son] = $obj->id_parent;
592 return $this->
LibStatut($this->status, $mode);
636 if (empty($force) && !empty($this->full_arbo_loaded)) {
644 $sql =
"SELECT c.rowid as rowid, c.label as label,";
645 $sql .=
" c.description as description, c.cachenbofdoc,";
646 $sql .=
" c.fk_user_c,";
647 $sql .=
" c.date_c,";
648 $sql .=
" u.login as login_c,";
649 $sql .=
" ca.rowid as rowid_fille";
650 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"ecm_directories as c";
651 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ecm_directories as ca";
652 $sql .=
" ON c.rowid = ca.fk_parent";
653 $sql .=
" WHERE c.fk_user_c = u.rowid";
654 $sql .=
" AND c.entity = ".$conf->entity;
655 $sql .=
" ORDER BY c.label, c.rowid";
657 dol_syslog(get_class($this).
"::get_full_arbo", LOG_DEBUG);
660 $this->cats = array();
663 while ($obj = $this->
db->fetch_object(
$resql)) {
664 $this->cats[$obj->rowid][
'id'] = $obj->rowid;
665 $this->cats[$obj->rowid][
'id_mere'] = (isset($this->motherof[$obj->rowid]) ? $this->motherof[$obj->rowid] :
'');
666 $this->cats[$obj->rowid][
'label'] = $obj->label;
667 $this->cats[$obj->rowid][
'description'] = $obj->description;
668 $this->cats[$obj->rowid][
'cachenbofdoc'] = $obj->cachenbofdoc;
669 $this->cats[$obj->rowid][
'date_c'] = $this->
db->jdate($obj->date_c);
670 $this->cats[$obj->rowid][
'fk_user_c'] = $obj->fk_user_c;
671 $this->cats[$obj->rowid][
'login_c'] = $obj->login_c;
673 if (!empty($obj->rowid_fille)) {
674 if (isset($this->cats[$obj->rowid][
'id_children']) && is_array($this->cats[$obj->rowid][
'id_children'])) {
675 $newelempos = count($this->cats[$obj->rowid][
'id_children']);
677 $this->cats[$obj->rowid][
'id_children'][$newelempos] = $obj->rowid_fille;
680 $this->cats[$obj->rowid][
'id_children'] = array($obj->rowid_fille);
691 foreach ($this->cats as $key => $val) {
692 if (isset($motherof[$key])) {
698 $this->cats =
dol_sort_array($this->cats,
'fulllabel',
'asc',
true,
false);
699 $this->full_arbo_loaded = 1;
717 if (!empty($this->cats[$id_categ][
'id_mere'])) {
718 $this->cats[$id_categ][
'fullpath'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullpath'];
719 $this->cats[$id_categ][
'fullpath'] .=
'_'.$id_categ;
720 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullrelativename'];
721 $this->cats[$id_categ][
'fullrelativename'] .=
'/'.$this->cats[$id_categ][
'label'];
722 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fulllabel'];
723 $this->cats[$id_categ][
'fulllabel'] .=
' >> '.$this->cats[$id_categ][
'label'];
725 $this->cats[$id_categ][
'fullpath'] =
'_'.$id_categ;
726 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$id_categ][
'label'];
727 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$id_categ][
'label'];
730 $this->cats[$id_categ][
'level'] = strlen(preg_replace(
'/([^_])/i',
'', $this->cats[$id_categ][
'fullpath']));
734 if ($protection > 20) {
737 if (isset($this->cats[$id_categ][
'id_children']) && is_array($this->cats[$id_categ][
'id_children'])) {
738 foreach ($this->cats[$id_categ][
'id_children'] as $key => $val) {
753 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
756 $filelist =
dol_dir_list($dir,
'files', 0,
'',
'(\.meta|_preview.*\.png)$');
762 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
763 $sql .=
" cachenbofdoc = '".count($filelist).
"'";
765 $sql .=
" WHERE rowid = ".$this->id;
767 $sql .=
" WHERE entity = ".$conf->entity;
770 dol_syslog(get_class($this).
"::refreshcachenboffile", LOG_DEBUG);
773 $this->cachenbofdoc = count($filelist);
774 return $this->cachenbofdoc;
776 $this->error =
"Error ".$this->db->lasterror();
797 global $langs, $conf;
799 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
801 $result = $interface->run_triggers($triggerName, $this, $user, $langs, $conf);
803 if (!empty($this->errors)) {
804 $this->errors = array_merge($this->errors, $interface->errors);
806 $this->errors = $interface->errors;
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
get_full_arbo($force=0)
Reconstruit l'arborescence des categories sous la forme d'un tableau à partir de la base de donnée Re...
</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.
dol_now($mode= 'auto')
Return date for now.
call_trigger($triggerName, $user)
Call trigger based on this instance.
build_path_from_id_categ($id_categ, $protection=0)
Define properties fullpath, fullrelativename, fulllabel of a directory of array this->cats and all it...
getRelativePath($force=0)
Return relative path of a directory on disk.
refreshcachenboffile($all=0)
Refresh value for cachenboffile.
$conf db
API class for accounts.
initAsSpecimen()
Initialise an instance with random values.
fetch($id)
Load object in memory from database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getLibStatut($mode=0)
Retourne le libelle du status d'un user (actif, inactif)
getNomUrl($withpicto=0, $option= '', $max=0, $more= '', $notooltip=0)
Return directory name you can click (and picto)
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
__construct($db)
Constructor.
static LibStatut($status, $mode=0)
Return the status.
create($user)
Create record 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...
dol_sort_array(&$array, $index, $order= 'asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
changeNbOfFiles($value)
Update cache of nb of documents into database.
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.
update($user=null, $notrigger=0)
Update database.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
load_motherof()
Load this->motherof that is array(id_son=>id_parent, ...)
dol_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
Class to manage ECM directories.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
Class to manage triggers.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...