/**
  *	Retourne la liste des categories du type choisi
  *
  *  @param	int		$selected    		Id categorie preselectionnee
  *  @param  string	$select_name		Nom formulaire HTML
  *  @return	string						String with HTML select
  */
 function select_all_sections($selected = 0, $select_name = '')
 {
     global $langs;
     $langs->load("ecm");
     if ($select_name == "") {
         $select_name = "catParent";
     }
     $cat = new EcmDirectory($this->db);
     $cate_arbo = $cat->get_full_arbo();
     $output = '<select class="flat" name="' . $select_name . '">';
     if (is_array($cate_arbo)) {
         if (!count($cate_arbo)) {
             $output .= '<option value="-1" disabled="disabled">' . $langs->trans("NoCategoriesDefined") . '</option>';
         } else {
             $output .= '<option value="-1">&nbsp;</option>';
             foreach ($cate_arbo as $key => $value) {
                 if ($cate_arbo[$key]['id'] == $selected) {
                     $add = 'selected="selected" ';
                 } else {
                     $add = '';
                 }
                 $output .= '<option ' . $add . 'value="' . $cate_arbo[$key]['id'] . '">' . $cate_arbo[$key]['fulllabel'] . '</option>';
             }
         }
     }
     $output .= '</select>';
     $output .= "\n";
     return $output;
 }
            setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
        }
        $result = $ecmdir->changeNbOfFiles('-');
        clearstatcache();
    }
    $action = 'file_manager';
}
// Remove directory
if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes') {
    $result = $ecmdir->delete($user);
    setEventMessage($langs->trans("ECMSectionWasRemoved", $ecmdir->label));
    clearstatcache();
}
// Refresh directory view
if ($action == 'refreshmanual') {
    $ecmdirtmp = new EcmDirectory($db);
    // This part of code is same than into file ecm/ajax/ecmdatabase.php TODO Remove duplicate
    clearstatcache();
    $diroutputslash = str_replace('\\', '/', $conf->ecm->dir_output);
    $diroutputslash .= '/';
    // Scan directory tree on disk
    $disktree = dol_dir_list($conf->ecm->dir_output, 'directories', 1, '', '^temp$', '', '', 0);
    // Scan directory tree in database
    $sqltree = $ecmdirstatic->get_full_arbo(0);
    $adirwascreated = 0;
    // Now we compare both trees to complete missing trees into database
    //var_dump($disktree);
    //var_dump($sqltree);
    foreach ($disktree as $dirdesc) {
        $dirisindatabase = 0;
        foreach ($sqltree as $dirsqldesc) {
Beispiel #3
0
    $pagenext = $page + 1;
    if (!$sortorder) {
        $sortorder = "ASC";
    }
    if (!$sortfield) {
        $sortfield = "name";
    }
    $upload_dir = dirname(str_replace("../", "/", $conf->ecm->dir_output . '/' . $file));
    $ecmdir = new EcmDirectory($db);
    $result = $ecmdir->fetch($section);
    if (!$result > 0) {
        dol_print_error($db, $ecmdir->error);
        exit;
    }
} else {
    $ecmdir = new EcmDirectory($db);
    $relativepath = '';
    if ($section > 0) {
        $result = $ecmdir->fetch($section);
        if (!$result > 0) {
            dol_print_error($db, $ecmdir->error);
            exit;
        }
    }
    $relativepath = $ecmdir->getRelativePath();
    $upload_dir = $conf->ecm->dir_output . '/' . $relativepath;
}
// Load traductions files
$langs->load("ecm");
$langs->load("companies");
$langs->load("other");
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOST("page", 'int');
if ($page == -1) {
    $page = 0;
}
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
    $sortorder = "ASC";
}
if (!$sortfield) {
    $sortfield = "label";
}
$ecmdir = new EcmDirectory($db);
if (!empty($section)) {
    $result = $ecmdir->fetch($section);
    if (!$result > 0) {
        dol_print_error($db, $ecmdir->error);
        exit;
    }
}
/*
 * Actions
 */
// Action ajout d'un produit ou service
if ($action == 'add' && $user->rights->ecm->setup) {
    if (!empty($_POST["cancel"])) {
        header("Location: " . DOL_URL_ROOT . '/ecm/index.php?action=file_manager');
        exit;
 /**
  *  Create record into database
  *
  *  @param      User	$user       User that create
  *  @return     int      			<0 if KO, >0 if OK
  */
 function create($user)
 {
     global $conf, $langs;
     $error = 0;
     $now = dol_now();
     // Clean parameters
     $this->label = dol_sanitizeFileName(trim($this->label));
     $this->fk_parent = trim($this->fk_parent);
     $this->description = trim($this->description);
     $this->date_c = $now;
     $this->fk_user_c = $user->id;
     if ($this->fk_parent <= 0) {
         $this->fk_parent = 0;
     }
     // Check if same directory does not exists with this name
     $relativepath = $this->label;
     if ($this->fk_parent) {
         $parent = new EcmDirectory($this->db);
         $parent->fetch($this->fk_parent);
         $relativepath = $parent->getRelativePath() . $relativepath;
     }
     $relativepath = preg_replace('/([\\/])+/i', '/', $relativepath);
     // Avoid duplicate / or \
     //print $relativepath.'<br>';
     $cat = new EcmDirectory($this->db);
     $cate_arbo = $cat->get_full_arbo(1);
     $pathfound = 0;
     foreach ($cate_arbo as $key => $categ) {
         $path = str_replace($this->forbiddenchars, '_', $categ['fulllabel']);
         //print $path.'<br>';
         if ($path == $relativepath) {
             $pathfound = 1;
             break;
         }
     }
     if ($pathfound) {
         $this->error = "ErrorDirAlreadyExists";
         dol_syslog(get_class($this) . "::create " . $this->error, LOG_WARNING);
         return -1;
     } else {
         $this->db->begin();
         // Insert request
         $sql = "INSERT INTO " . MAIN_DB_PREFIX . "ecm_directories(";
         $sql .= "label,";
         $sql .= "entity,";
         $sql .= "fk_parent,";
         $sql .= "description,";
         $sql .= "cachenbofdoc,";
         $sql .= "date_c,";
         $sql .= "fk_user_c";
         $sql .= ") VALUES (";
         $sql .= " '" . $this->db->escape($this->label) . "',";
         $sql .= " '" . $conf->entity . "',";
         $sql .= " '" . $this->fk_parent . "',";
         $sql .= " '" . $this->db->escape($this->description) . "',";
         $sql .= " " . $this->cachenbofdoc . ",";
         $sql .= " '" . $this->db->idate($this->date_c) . "',";
         $sql .= " '" . $this->fk_user_c . "'";
         $sql .= ")";
         dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG);
         $resql = $this->db->query($sql);
         if ($resql) {
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "ecm_directories");
             $dir = $conf->ecm->dir_output . '/' . $this->getRelativePath();
             $result = dol_mkdir($dir);
             if ($result < 0) {
                 $error++;
                 $this->error = "ErrorFailedToCreateDir";
             }
             // Appel des triggers
             include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
             $interface = new Interfaces($this->db);
             $result = $interface->run_triggers('MYECMDIR_CREATE', $this, $user, $langs, $conf);
             if ($result < 0) {
                 $error++;
                 $this->errors = $interface->errors;
             }
             // Fin appel triggers
             if (!$error) {
                 $this->db->commit();
                 return $this->id;
             } else {
                 $this->db->rollback();
                 return -1;
             }
         } else {
             $this->error = "Error " . $this->db->lasterror();
             dol_syslog(get_class($this) . "::create " . $this->error, LOG_ERR);
             $this->db->rollback();
             return -1;
         }
     }
 }
Beispiel #6
0
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOST("page", 'int');
if ($page == -1) {
    $page = 0;
}
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
    $sortorder = "ASC";
}
if (!$sortfield) {
    $sortfield = "label";
}
$ecmdir = new EcmDirectory($db);
if (!empty($section)) {
    $result = $ecmdir->fetch($section);
    if (!$result > 0) {
        dol_print_error($db, $ecmdir->error);
        exit;
    }
}
/*******************************************************************
 * ACTIONS
 *
 * Put here all code to do according to value of "action" parameter
 ********************************************************************/
/*******************************************************************
 * PAGE
 *
Beispiel #7
0
$totalsize = 0;
foreach ($filearray as $key => $file) {
    $totalsize += $file['size'];
}
$head = ecm_prepare_head($ecmdir);
dol_fiche_head($head, 'card', $langs->trans("ECMSectionManual"), '', 'dir');
if ($_GET["action"] == 'edit') {
    print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
    print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
    print '<input type="hidden" name="section" value="' . $section . '">';
    print '<input type="hidden" name="action" value="update">';
}
print '<table class="border" width="100%">';
print '<tr><td width="30%">' . $langs->trans("Ref") . '</td><td>';
$s = '';
$tmpecmdir = new EcmDirectory($db);
// Need to create a new one
$tmpecmdir->fetch($ecmdir->id);
$result = 1;
$i = 0;
while ($tmpecmdir && $result > 0) {
    $tmpecmdir->ref = $tmpecmdir->label;
    if ($i == 0 && $_GET["action"] == 'edit') {
        $s = '<input type="text" name="label" size="40" maxlength="32" value="' . $tmpecmdir->label . '">';
    } else {
        $s = $tmpecmdir->getNomUrl(1) . $s;
    }
    if ($tmpecmdir->fk_parent) {
        $s = ' -> ' . $s;
        $result = $tmpecmdir->fetch($tmpecmdir->fk_parent);
    } else {
Beispiel #8
0
    if (count($filesarray)) {
        foreach ($filesarray as $key => $value) {
            //print "x ".$filesarray[$key]['fullname']."<br>\n";
            if ($filesarray[$key]['type'] == 'dir') {
                $count += dol_delete_dir_recursive($filesarray[$key]['fullname']);
            } elseif ($filesarray[$key]['type'] == 'file') {
                // If (file that is not logfile) or (if logfile with option logfile)
                if ($filesarray[$key]['fullname'] != $filelog || $choice == 'logfile') {
                    $count += dol_delete_file($filesarray[$key]['fullname']);
                }
            }
        }
        // Update cachenbofdoc
        if (!empty($conf->ecm->enabled) && $choice == 'allfiles') {
            require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmdirectory.class.php';
            $ecmdirstatic = new EcmDirectory($db);
            $result = $ecmdirstatic->refreshcachenboffile(1);
        }
    }
    if ($count) {
        $mesg = $langs->trans("PurgeNDirectoriesDeleted", $count);
    } else {
        $mesg = $langs->trans("PurgeNothingToDelete");
    }
    setEventMessage($mesg);
}
/*
 * View
 */
llxHeader();
$form = new Form($db);
 /**
  *  Purge files into directory of data files.
  *
  *  @param	string		$choice		Choice of purge mode ('tempfiles', 'tempfilesold' to purge temp older than 24h, 'allfiles', 'logfiles')
  *  @return	int						0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) 
  */
 function purgeFiles($choice = 'tempfilesold')
 {
     global $conf, $langs, $dolibarr_main_data_root;
     dol_syslog("Utils::purgeFiles choice=" . $choice, LOG_DEBUG);
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $filesarray = array();
     if (empty($choice)) {
         $choice = 'tempfilesold';
     }
     if ($choice == 'tempfiles' || $choice == 'tempfilesold') {
         // Delete temporary files
         if ($dolibarr_main_data_root) {
             $filesarray = dol_dir_list($dolibarr_main_data_root, "directories", 1, '^temp$', '', '', '', 2);
             if ($choice == 'tempfilesold') {
                 $now = dol_now();
                 foreach ($filesarray as $key => $val) {
                     if ($val['date'] > $now - 24 * 3600) {
                         unset($filesarray[$key]);
                     }
                     // Discard files not older than 24h
                 }
             }
         }
     }
     if ($choice == 'allfiles') {
         // Delete all files
         if ($dolibarr_main_data_root) {
             $filesarray = dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\\.lock$');
         }
     }
     if ($choice == 'logfile') {
         // Define filelog to discard it from purge
         $filelog = '';
         if (!empty($conf->syslog->enabled)) {
             $filelog = SYSLOG_FILE;
             $filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
         }
         $filesarray[] = array('fullname' => $filelog, 'type' => 'file');
     }
     $count = 0;
     if (count($filesarray)) {
         foreach ($filesarray as $key => $value) {
             //print "x ".$filesarray[$key]['fullname']."<br>\n";
             if ($filesarray[$key]['type'] == 'dir') {
                 $count += dol_delete_dir_recursive($filesarray[$key]['fullname']);
             } elseif ($filesarray[$key]['type'] == 'file') {
                 // If (file that is not logfile) or (if logfile with option logfile)
                 if ($filesarray[$key]['fullname'] != $filelog || $choice == 'logfile') {
                     $count += dol_delete_file($filesarray[$key]['fullname']) ? 1 : 0;
                 }
             }
         }
         // Update cachenbofdoc
         if (!empty($conf->ecm->enabled) && $choice == 'allfiles') {
             require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmdirectory.class.php';
             $ecmdirstatic = new EcmDirectory($this->db);
             $result = $ecmdirstatic->refreshcachenboffile(1);
         }
     }
     if ($count > 0) {
         $this->output = $langs->trans("PurgeNDirectoriesDeleted", $count);
     } else {
         $this->output = $langs->trans("PurgeNothingToDelete");
     }
     //return $count;
     return 0;
     // This function can be called by cron so must return 0 if OK
 }
    exit;
}
// Check permissions
if ($modulepart == 'ecm') {
    if (!$user->rights->ecm->read) {
        accessforbidden();
    }
}
/*
 * View
 */
top_httphead();
//print '<!-- selecteddir = '.$selecteddir.', openeddir = '.$openeddir.', modulepart='.$modulepart.' -->'."\n";
$userstatic = new User($db);
$form = new Form($db);
$ecmdirstatic = new EcmDirectory($db);
// Load full tree from database. We will use it to define nbofsubdir and nboffilesinsubdir
if (empty($sqltree)) {
    $sqltree = $ecmdirstatic->get_full_arbo(0);
}
// Try to find key into $sqltree
$current_ecmdir_id = -1;
foreach ($sqltree as $keycursor => $val) {
    //print $val['fullrelativename']." == ".$selecteddir;
    if ($val['fullrelativename'] == $selecteddir) {
        $current_ecmdir_id = $keycursor;
    }
}
if (file_exists($fullpathselecteddir)) {
    $files = @scandir($fullpathselecteddir);
    if ($files) {
}
if (!$sortfield) {
    $sortfield = "label";
}
$section = GETPOST("section");
if (!$section) {
    dol_print_error('', 'Error, section parameter missing');
    exit;
}
$urlfile = GETPOST("urlfile");
if (!$urlfile) {
    dol_print_error('', "ErrorParamNotDefined");
    exit;
}
// Load ecm object
$ecmdir = new EcmDirectory($db);
$result = $ecmdir->fetch(GETPOST("section"));
if (!$result > 0) {
    dol_print_error($db, $ecmdir->error);
    exit;
}
$relativepath = $ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output . '/' . $relativepath;
/*
$ecmfile = new ECMFile($db);
if (! empty($_GET["fileid"]))
{
	$result=$ecmfile->fetch($_GET["fileid"]);
	if (! $result > 0)
	{
		dol_print_error($db,$ecmfile->error);
Beispiel #12
0
     if ($parentdirisindatabase > 0) {
         dol_syslog("Yes with id " . $parentdirisindatabase);
         //print "Yes with id ".$parentdirisindatabase."<br>\n";
         $fk_parent = $parentdirisindatabase;
         //break;  // We found parent, we can stop the while loop
     } else {
         dol_syslog("No");
         //print "No<br>\n";
     }
 } else {
     dol_syslog("Parent is root");
     $fk_parent = 0;
     // Parent is root
 }
 if ($fk_parent >= 0) {
     $ecmdirtmp = new EcmDirectory($db);
     $ecmdirtmp->ref = 'NOTUSEDYET';
     $ecmdirtmp->label = dol_basename($dirdesc['fullname']);
     $ecmdirtmp->description = '';
     $ecmdirtmp->fk_parent = $fk_parent;
     $txt = "We create directory " . $ecmdirtmp->label . " with parent " . $fk_parent;
     dol_syslog($txt);
     //print $txt."<br>\n";
     $id = $ecmdirtmp->create($user);
     if ($id > 0) {
         $newdirsql = array('id' => $id, 'id_mere' => $ecmdirtmp->fk_parent, 'label' => $ecmdirtmp->label, 'description' => $ecmdirtmp->description, 'fullrelativename' => $relativepathmissing);
         $sqltree[] = $newdirsql;
         // We complete fulltree for following loops
         //var_dump($sqltree);
         $adirwascreated = 1;
     } else {
Beispiel #13
0
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOST("page", 'int');
if ($page == -1) {
    $page = 0;
}
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
    $sortorder = "ASC";
}
if (!$sortfield) {
    $sortfield = "label";
}
$ecmdir = new EcmDirectory($db);
if (!empty($_REQUEST["section"])) {
    $result = $ecmdir->fetch($_REQUEST["section"]);
    if (!$result > 0) {
        dol_print_error($db, $ecmdir->error);
        exit;
    }
}
/*******************************************************************
 * ACTIONS
 *
 * Put here all code to do according to value of "action" parameter
 ********************************************************************/
/*******************************************************************
 * PAGE
 *
Beispiel #14
0
    dol_print_error(0, $langs->trans("ErrorFileNameInvalid", GETPOST("file")));
    exit;
}
// Check permissions
if ($modulepart == 'ecm') {
    if (!$user->rights->ecm->read) {
        accessforbidden();
    }
}
/*
 * View
 */
top_httphead();
$userstatic = new User($db);
$form = new Form($db);
$ecmdirstatic = new EcmDirectory($db);
// Load full tree. We will use it to define nbofsubdir and nboffilesinsubdir
if (empty($sqltree)) {
    $sqltree = $ecmdirstatic->get_full_arbo(0);
}
// Try to find key into $sqltree
$current_ecmdir_id = -1;
foreach ($sqltree as $keycursor => $val) {
    //print $val['fullrelativename']." == ".$selecteddir;
    if ($val['fullrelativename'] == $selecteddir) {
        $current_ecmdir_id = $keycursor;
    }
}
if (file_exists($fullpathselecteddir)) {
    $files = @scandir($fullpathselecteddir);
    if ($files) {
Beispiel #15
0
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOST("page", 'int');
if ($page == -1) {
    $page = 0;
}
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
    $sortorder = "ASC";
}
if (!$sortfield) {
    $sortfield = "label";
}
$ecmdir = new EcmDirectory($db);
if (!empty($_GET["section"])) {
    $result = $ecmdir->fetch($_GET["section"]);
    if (!$result > 0) {
        dol_print_error($db, $ecmdir->error);
        exit;
    }
}
/*******************************************************************
 * ACTIONS
 *
 * Put here all code to do according to value of "action" parameter
 ********************************************************************/
// Action ajout d'un produit ou service
if ($_POST["action"] == 'add' && $user->rights->ecm->setup) {
    if (!empty($_POST["cancel"])) {