コード例 #1
0
ファイル: security2.lib.php プロジェクト: ADDAdev/Dolibarr
/**
 *  Return a login if login/pass was successfull
 *
 *	@param		string	$usertotest			Login value to test
 *	@param		string	$passwordtotest		Password value to test
 *	@param		string	$entitytotest		Instance of data we must check
 *	@param		array	$authmode			Array list of selected authentication mode array('http', 'dolibarr', 'xxx'...)
 *  @return		string						Login or ''
 */
function checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode)
{
    global $conf, $langs;
    //global $dolauthmode;    // To return authentication finally used
    // Check parameters
    if ($entitytotest == '') {
        $entitytotest = 1;
    }
    dol_syslog("checkLoginPassEntity usertotest=" . $usertotest . " entitytotest=" . $entitytotest . " authmode=" . join(',', $authmode));
    $login = '';
    // Validation of login/pass/entity with standard modules
    if (empty($login)) {
        $test = true;
        foreach ($authmode as $mode) {
            if ($test && $mode && !$login) {
                // Validation of login/pass/entity for mode $mode
                $mode = trim($mode);
                $authfile = 'functions_' . $mode . '.php';
                $fullauthfile = '';
                $dirlogin = array_merge(array("/core/login"), (array) $conf->modules_parts['login']);
                foreach ($dirlogin as $reldir) {
                    $dir = dol_buildpath($reldir, 0);
                    $newdir = dol_osencode($dir);
                    // Check if file found (do not use dol_is_file to avoid loading files.lib.php)
                    if (is_file($newdir . '/' . $authfile)) {
                        $fullauthfile = $newdir . '/' . $authfile;
                    }
                }
                $result = false;
                if ($fullauthfile) {
                    $result = (include_once $fullauthfile);
                }
                if ($fullauthfile && $result) {
                    // Call function to check user/password
                    $function = 'check_user_password_' . $mode;
                    $login = call_user_func($function, $usertotest, $passwordtotest, $entitytotest);
                    if ($login) {
                        $test = false;
                        // To stop once at first login success
                        $conf->authmode = $mode;
                        // This properties is defined only when logged to say what mode was successfully used
                        $dol_tz = GETPOST('tz');
                        $dol_dst = GETPOST('dst');
                        $dol_screenwidth = GETPOST('screenwidth');
                        $dol_screenheight = GETPOST('screenheight');
                    }
                } else {
                    dol_syslog("Authentification ko - failed to load file '" . $authfile . "'", LOG_ERR);
                    sleep(1);
                    $langs->load('main');
                    $langs->load('other');
                    $_SESSION["dol_loginmesg"] = $langs->trans("ErrorFailedToLoadLoginFileForMode", $mode);
                }
            }
        }
    }
    return $login;
}
コード例 #2
0
ファイル: interfaces.class.php プロジェクト: ADDAdev/Dolibarr
 /**
  *  Return list of triggers. Function used by admin page htdoc/admin/triggers.
  *  List is sorted by trigger filename so by priority to run.
  *
  * 	@return	array					Array list of triggers
  */
 function getTriggersList()
 {
     global $conf, $langs;
     $files = array();
     $fullpath = array();
     $relpath = array();
     $iscoreorexternal = array();
     $modules = array();
     $orders = array();
     $i = 0;
     $dirtriggers = array_merge(array('/core/triggers/'), $conf->modules_parts['triggers']);
     foreach ($dirtriggers as $reldir) {
         $dir = dol_buildpath($reldir, 0);
         $newdir = dol_osencode($dir);
         //print "xx".$dir;exit;
         // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
         if (!is_dir($newdir)) {
             continue;
         }
         $handle = opendir($newdir);
         if (is_resource($handle)) {
             while (($file = readdir($handle)) !== false) {
                 if (is_readable($newdir . '/' . $file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\\.class\\.php/', $file, $reg)) {
                     $part1 = $reg[1];
                     $part2 = $reg[2];
                     $part3 = $reg[3];
                     $modName = 'Interface' . ucfirst($reg[3]);
                     //print "file=$file"; print "modName=$modName"; exit;
                     if (in_array($modName, $modules)) {
                         $langs->load("errors");
                         print '<div class="error">' . $langs->trans("Error") . ' : ' . $langs->trans("ErrorDuplicateTrigger", $modName, "/htdocs/core/triggers/") . '</div>';
                     } else {
                         include_once $newdir . '/' . $file;
                     }
                     $files[$i] = $file;
                     $fullpath[$i] = $dir . '/' . $file;
                     $relpath[$i] = preg_replace('/^\\//', '', $reldir) . '/' . $file;
                     $iscoreorexternal[$i] = $reldir == '/core/triggers/' ? 'internal' : 'external';
                     $modules[$i] = $modName;
                     $orders[$i] = $part1 . '_' . $part2 . '_' . $part3;
                     // Set sort criteria value
                     $i++;
                 }
             }
             closedir($handle);
         }
     }
     asort($orders);
     $triggers = array();
     $j = 0;
     // Loop on each trigger
     foreach ($orders as $key => $value) {
         $modName = $modules[$key];
         if (empty($modName)) {
             continue;
         }
         if (!class_exists($modName)) {
             print 'Error: A trigger file was found but its class "' . $modName . '" was not found.' . "<br>\n";
             continue;
         }
         $objMod = new $modName($this->db);
         // Define disabledbyname and disabledbymodule
         $disabledbyname = 0;
         $disabledbymodule = 1;
         $module = '';
         // Check if trigger file is disabled by name
         if (preg_match('/NORUN$/i', $files[$key])) {
             $disabledbyname = 1;
         }
         // Check if trigger file is for a particular module
         if (preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\\.class\\.php/i', $files[$key], $reg)) {
             $module = preg_replace('/^mod/i', '', $reg[2]);
             $constparam = 'MAIN_MODULE_' . strtoupper($module);
             if (strtolower($reg[2]) == 'all') {
                 $disabledbymodule = 0;
             } else {
                 if (empty($conf->global->{$constparam})) {
                     $disabledbymodule = 2;
                 }
             }
         }
         // We set info of modules
         $triggers[$j]['picto'] = $objMod->picto ? img_object('', $objMod->picto) : img_object('', 'generic');
         $triggers[$j]['file'] = $files[$key];
         $triggers[$j]['fullpath'] = $fullpath[$key];
         $triggers[$j]['relpath'] = $relpath[$key];
         $triggers[$j]['iscoreorexternal'] = $iscoreorexternal[$key];
         $triggers[$j]['version'] = $objMod->getVersion();
         $triggers[$j]['status'] = img_picto($langs->trans("Active"), 'tick');
         if ($disabledbyname > 0 || $disabledbymodule > 1) {
             $triggers[$j]['status'] = "&nbsp;";
         }
         $text = '<b>' . $langs->trans("Description") . ':</b><br>';
         $text .= $objMod->getDesc() . '<br>';
         $text .= '<br><b>' . $langs->trans("Status") . ':</b><br>';
         if ($disabledbyname == 1) {
             $text .= $langs->trans("TriggerDisabledByName") . '<br>';
             if ($disabledbymodule == 2) {
                 $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module) . '<br>';
             }
         } else {
             if ($disabledbymodule == 0) {
                 $text .= $langs->trans("TriggerAlwaysActive") . '<br>';
             }
             if ($disabledbymodule == 1) {
                 $text .= $langs->trans("TriggerActiveAsModuleActive", $module) . '<br>';
             }
             if ($disabledbymodule == 2) {
                 $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module) . '<br>';
             }
         }
         $triggers[$j]['info'] = $text;
         $j++;
     }
     return $triggers;
 }
コード例 #3
0
 /**
  *  Deplace fichier recupere sur internet (utilise pour interface avec OSC)
  *
  *  @param  string	$sdir        	Repertoire destination finale
  *  @param  string	$file      		url de l'image
  *  @param  int		$idprod			Product id where store the image
  *  @return	void
  */
 function add_photo_web($sdir, $file, $idprod)
 {
     $dir = $sdir . '/' . get_exdir($idprod, 2) . $idprod . "/";
     $dir .= "photos/";
     $dir_osencoded = dol_osencode($dir);
     if (!file_exists($dir_osencoded)) {
         dol_syslog("Product Create " . $dir);
         dol_mkdir($dir);
     }
     if (file_exists($dir_osencoded)) {
         // Cree fichier en taille vignette
         // TODO A faire
         // Cree fichier en taille origine
         $content = @file_get_contents($file);
         if ($content) {
             $nom = basename($file);
             $im = fopen(dol_osencode($dir . $nom), 'wb');
             fwrite($im, $content);
             fclose($im);
         }
     }
 }
コード例 #4
0
ファイル: viewimage.php プロジェクト: nrjacker4/crm-php
    // This test is to avoid error images when image is not available (for example thumbs).
    if (! dol_is_file($original_file))
    {
        $original_file=DOL_DOCUMENT_ROOT.'/theme/common/nophoto.jpg';
        /*$error='Error: File '.$_GET["file"].' does not exists or filesystems permissions are not allowed';
        dol_print_error(0,$error);
        print $error;
        exit;*/
    }

    // Les drois sont ok et fichier trouve
    if ($type)
    {
        header('Content-Disposition: inline; filename="'.basename($original_file).'"');
        header('Content-type: '.$type);
    }
    else
    {
        header('Content-Disposition: inline; filename="'.basename($original_file).'"');
        header('Content-type: image/png');
    }

    $original_file_osencoded=dol_osencode($original_file);
    readfile($original_file_osencoded);
}


if (is_object($db)) $db->close();
?>
コード例 #5
0
 /**
  *    Load an exportable dataset
  *
  *    @param  	User		$user      	Object user making export
  *    @param  	string		$filter    	Load a particular dataset only
  *    @return	int						<0 if KO, >0 if OK
  */
 function load_arrays($user, $filter = '')
 {
     global $langs, $conf, $mysoc;
     dol_syslog(get_class($this) . "::load_arrays user="******" filter=" . $filter);
     $var = true;
     $i = 0;
     // Define list of modules directories into modulesdir
     require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
     $modulesdir = dolGetModulesDirs();
     foreach ($modulesdir as $dir) {
         // Search available exports
         $handle = @opendir(dol_osencode($dir));
         if (is_resource($handle)) {
             // Search module files
             while (($file = readdir($handle)) !== false) {
                 if (is_readable($dir . $file) && preg_match("/^(mod.*)\\.class\\.php\$/i", $file, $reg)) {
                     $modulename = $reg[1];
                     // Defined if module is enabled
                     $enabled = true;
                     $part = strtolower(preg_replace('/^mod/i', '', $modulename));
                     if ($part == 'propale') {
                         $part = 'propal';
                     }
                     if (empty($conf->{$part}->enabled)) {
                         $enabled = false;
                     }
                     if ($enabled) {
                         // Chargement de la classe
                         $file = $dir . $modulename . ".class.php";
                         $classname = $modulename;
                         require_once $file;
                         $module = new $classname($this->db);
                         if (isset($module->export_code) && is_array($module->export_code)) {
                             foreach ($module->export_code as $r => $value) {
                                 //print $i.'-'.$filter.'-'.$modulename.'-'.join(',',$module->export_code).'<br>';
                                 if ($filter && $filter != $module->export_code[$r]) {
                                     continue;
                                 }
                                 // Test if condition to show are ok
                                 if (!empty($module->export_enabled[$r]) && !verifCond($module->export_enabled[$r])) {
                                     continue;
                                 }
                                 // Test if permissions are ok
                                 $bool = true;
                                 foreach ($module->export_permission[$r] as $val) {
                                     $perm = $val;
                                     //print_r("$perm[0]-$perm[1]-$perm[2]<br>");
                                     if (!empty($perm[2])) {
                                         $bool = $user->rights->{$perm}[0]->{$perm}[1]->{$perm}[2];
                                     } else {
                                         $bool = $user->rights->{$perm}[0]->{$perm}[1];
                                     }
                                     if ($perm[0] == 'user' && $user->admin) {
                                         $bool = true;
                                     }
                                     if (!$bool) {
                                         break;
                                     }
                                 }
                                 //print $bool." $perm[0]"."<br>";
                                 // Permissions ok
                                 //	          if ($bool)
                                 //	          {
                                 // Charge fichier lang en rapport
                                 $langtoload = $module->getLangFilesArray();
                                 if (is_array($langtoload)) {
                                     foreach ($langtoload as $key) {
                                         $langs->load($key);
                                     }
                                 }
                                 // Module
                                 $this->array_export_module[$i] = $module;
                                 // Permission
                                 $this->array_export_perms[$i] = $bool;
                                 // Icon
                                 $this->array_export_icon[$i] = isset($module->export_icon[$r]) ? $module->export_icon[$r] : $module->picto;
                                 // Code du dataset export
                                 $this->array_export_code[$i] = $module->export_code[$r];
                                 // Libelle du dataset export
                                 $this->array_export_label[$i] = $module->getExportDatasetLabel($r);
                                 // Tableau des champ a exporter (cle=champ, valeur=libelle)
                                 $this->array_export_fields[$i] = $module->export_fields_array[$r];
                                 // Tableau des champs a filtrer (cle=champ, valeur1=type de donnees) on verifie que le module a des filtres
                                 $this->array_export_TypeFields[$i] = isset($module->export_TypeFields_array[$r]) ? $module->export_TypeFields_array[$r] : '';
                                 // Tableau des entites a exporter (cle=champ, valeur=entite)
                                 $this->array_export_entities[$i] = $module->export_entities_array[$r];
                                 // Tableau des entites qui requiert abandon du DISTINCT (cle=entite, valeur=champ id child records)
                                 $this->array_export_dependencies[$i] = !empty($module->export_dependencies_array[$r]) ? $module->export_dependencies_array[$r] : '';
                                 // Tableau des operations speciales sur champ
                                 $this->array_export_special[$i] = !empty($module->export_special_array[$r]) ? $module->export_special_array[$r] : '';
                                 // Requete sql du dataset
                                 $this->array_export_sql_start[$i] = $module->export_sql_start[$r];
                                 $this->array_export_sql_end[$i] = $module->export_sql_end[$r];
                                 $this->array_export_sql_order[$i] = $module->export_sql_order[$r];
                                 //$this->array_export_sql[$i]=$module->export_sql[$r];
                                 dol_syslog(get_class($this) . "::load_arrays loaded for module " . $modulename . " with index " . $i . ", dataset=" . $module->export_code[$r] . ", nb of fields=" . (!empty($module->export_fields_code[$r]) ? count($module->export_fields_code[$r]) : ''));
                                 $i++;
                                 //	          }
                             }
                         }
                     }
                 }
             }
             closedir($handle);
         }
     }
     return 1;
 }
コード例 #6
0
 /**
  * Read a file on disk and return encoded content for emails (mode = 'mail')
  *
  * @param	string	$sourcefile		Path to file to encode
  * @return 	int					    <0 if KO, encoded string if OK
  */
 function _encode_file($sourcefile)
 {
     $newsourcefile = dol_osencode($sourcefile);
     if (is_readable($newsourcefile)) {
         $contents = file_get_contents($newsourcefile);
         // Need PHP 4.3
         $encoded = chunk_split(base64_encode($contents), 76, $this->eol);
         // 76 max is defined into http://tools.ietf.org/html/rfc2047
         return $encoded;
     } else {
         $this->error = "Error: Can't read file '" . $sourcefile . "' into _encode_file";
         dol_syslog("CMailFile::encode_file: " . $this->error, LOG_ERR);
         return -1;
     }
 }
コード例 #7
0
 /**
  *  Return path of a catergory image 
  *  
  *  @param 		int		$idCat		Id of Category
  *  @return      string				Image path
  */
 public static function getImageProduct($idProd, $thumb = false)
 {
     global $conf, $db;
     $extName = "_small";
     $extImgTarget = ".jpg";
     $outDir = "pos";
     $maxWidth = 90;
     $maxHeight = 90;
     $quality = 50;
     if ($idProd > 0) {
         $objProd = new Product($db);
         $objProd->fetch($idProd);
         $pdir = get_exdir($idProd, 2) . $idProd . "/photos/";
         $dir = $conf->product->multidir_output[$objProd->entity] . '/' . $pdir;
         foreach ($objProd->liste_photos($dir, 1) as $key => $obj) {
             $filename = $dir . $obj['photo'];
             $filethumbs = $dir . $outDir . '/' . $obj['photo'];
             $fileName = preg_replace('/(\\.gif|\\.jpeg|\\.jpg|\\.png|\\.bmp)$/i', '', $filethumbs);
             $fileName = basename($fileName);
             $imgThumbName = $dir . $outDir . '/' . $fileName . $extName . $extImgTarget;
             $file_osencoded = $imgThumbName;
             if (!file_exists($file_osencoded)) {
                 $file_osencoded = dol_osencode($filename);
                 if (file_exists($file_osencoded)) {
                     require_once DOL_DOCUMENT_ROOT . "/core/lib/images.lib.php";
                     vignette($filename, $maxWidth, $maxHeight, $extName, $quality, $outDir, 2);
                 }
             }
             if (!$thumb) {
                 $filename = $obj['photo'];
             } else {
                 $filename = $outDir . '/' . $fileName . $extName . $extImgTarget;
             }
             $realpath = DOL_URL_ROOT . '/viewimage.php?modulepart=product&entity=' . $objProd->entity . '&file=' . urlencode($pdir . $filename);
         }
         if (!$realpath) {
             $realpath = DOL_URL_ROOT . '/viewimage.php?modulepart=product&file=' . urlencode('noimage.jpg');
         }
         return $realpath;
     }
 }
コード例 #8
0
 /**
  *  Load size of image file
  *
  *  @param  string	$file        Path to file
  *  @return	void
  */
 function get_image_size($file)
 {
     $file_osencoded = dol_osencode($file);
     $infoImg = getimagesize($file_osencoded);
     // Get information on image
     $this->imgWidth = $infoImg[0];
     // Largeur de l'image
     $this->imgHeight = $infoImg[1];
     // Hauteur de l'image
 }
コード例 #9
0
/**
 *  Add external modules to list of contact element
 *
 * 	@param		array		$elementList			elementList
 * 	@return		int			1
 */
function complete_elementList_with_modules(&$elementList)
{
    global $db, $modules, $conf, $langs;
    // Search modules
    $filename = array();
    $modules = array();
    $orders = array();
    $categ = array();
    $dirmod = array();
    $i = 0;
    // is a sequencer of modules found
    $j = 0;
    // j is module number. Automatically affected if module number not defined.
    $modulesdir = dolGetModulesDirs();
    foreach ($modulesdir as $dir) {
        // Load modules attributes in arrays (name, numero, orders) from dir directory
        //print $dir."\n<br>";
        dol_syslog("Scan directory " . $dir . " for modules");
        $handle = @opendir(dol_osencode($dir));
        if (is_resource($handle)) {
            while (($file = readdir($handle)) !== false) {
                //print "$i ".$file."\n<br>";
                if (is_readable($dir . $file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
                    $modName = substr($file, 0, dol_strlen($file) - 10);
                    if ($modName) {
                        include_once $dir . $file;
                        $objMod = new $modName($db);
                        if ($objMod->numero > 0) {
                            $j = $objMod->numero;
                        } else {
                            $j = 1000 + $i;
                        }
                        $modulequalified = 1;
                        // We discard modules according to features level (PS: if module is activated we always show it)
                        $const_name = 'MAIN_MODULE_' . strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
                        if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && !$conf->global->{$const_name}) {
                            $modulequalified = 0;
                        }
                        if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && !$conf->global->{$const_name}) {
                            $modulequalified = 0;
                        }
                        //If module is not activated disqualified
                        if (empty($conf->global->{$const_name})) {
                            $modulequalified = 0;
                        }
                        if ($modulequalified) {
                            // Load languages files of module
                            if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
                                foreach ($objMod->langfiles as $langfile) {
                                    $langs->load($langfile);
                                }
                            }
                            $modules[$i] = $objMod;
                            $filename[$i] = $modName;
                            $orders[$i] = $objMod->family . "_" . $j;
                            // Tri par famille puis numero module
                            //print "x".$modName." ".$orders[$i]."\n<br>";
                            if (isset($categ[$objMod->special])) {
                                $categ[$objMod->special]++;
                            } else {
                                $categ[$objMod->special] = 1;
                            }
                            $dirmod[$i] = $dirroot;
                            if (!empty($objMod->module_parts['contactelement'])) {
                                $elementList[$objMod->name] = $langs->trans($objMod->name);
                                //exit;
                            }
                            $j++;
                            $i++;
                        } else {
                            dol_syslog("Module " . get_class($objMod) . " not qualified");
                        }
                    }
                }
            }
            closedir($handle);
        } else {
            dol_syslog("htdocs/admin/modules.php: Failed to open directory " . $dir . ". See permission and open_basedir option.", LOG_WARNING);
        }
    }
    return 1;
}
コード例 #10
0
ファイル: admin.lib.php プロジェクト: nrjacker4/crm-php
/**
 *  Add external modules to list of dictionnaries
 *
 * 	@param		array		&$taborder			Taborder
 * 	@param		array		&$tabname			Tabname
 * 	@param		array		&$tablib			Tablib
 * 	@param		array		&$tabsql			Tabsql
 * 	@param		array		&$tabsqlsort		Tabsqlsort
 * 	@param		array		&$tabfield			Tabfield
 * 	@param		array		&$tabfieldvalue		Tabfieldvalue
 * 	@param		array		&$tabfieldinsert	Tabfieldinsert
 * 	@param		array		&$tabrowid			Tabrowid
 * 	@param		array		&$tabcond			Tabcond
 * 	@param		array		&$tabhelp			Tabhelp
 * 	@return		int			1
 */
function complete_dictionnary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp)
{
    global $db, $modules, $conf, $langs;
    // Search modules
    $filename = array();
    $modules = array();
    $orders = array();
    $categ = array();
    $dirmod = array();
    $modulesdir = array();
    $i = 0;
    // is a sequencer of modules found
    $j = 0;
    // j is module number. Automatically affected if module number not defined.
    foreach ($conf->file->dol_document_root as $type => $dirroot) {
        $modulesdir[$dirroot . '/core/modules/'] = $dirroot . '/core/modules/';
        $handle = @opendir($dirroot);
        if (is_resource($handle)) {
            while (($file = readdir($handle)) !== false) {
                if (is_dir($dirroot . '/' . $file) && substr($file, 0, 1) != '.' && substr($file, 0, 3) != 'CVS' && $file != 'includes') {
                    if (is_dir($dirroot . '/' . $file . '/core/modules/')) {
                        $modulesdir[$dirroot . '/' . $file . '/core/modules/'] = $dirroot . '/' . $file . '/core/modules/';
                    }
                }
            }
            closedir($handle);
        }
    }
    //var_dump($modulesdir);
    foreach ($modulesdir as $dir) {
        // Load modules attributes in arrays (name, numero, orders) from dir directory
        //print $dir."\n<br>";
        dol_syslog("Scan directory " . $dir . " for modules");
        $handle = @opendir(dol_osencode($dir));
        if (is_resource($handle)) {
            while (($file = readdir($handle)) !== false) {
                //print "$i ".$file."\n<br>";
                if (is_readable($dir . $file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
                    $modName = substr($file, 0, dol_strlen($file) - 10);
                    if ($modName) {
                        include_once $dir . $file;
                        $objMod = new $modName($db);
                        if ($objMod->numero > 0) {
                            $j = $objMod->numero;
                        } else {
                            $j = 1000 + $i;
                        }
                        $modulequalified = 1;
                        // We discard modules according to features level (PS: if module is activated we always show it)
                        $const_name = 'MAIN_MODULE_' . strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
                        if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && !$conf->global->{$const_name}) {
                            $modulequalified = 0;
                        }
                        if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && !$conf->global->{$const_name}) {
                            $modulequalified = 0;
                        }
                        if ($modulequalified) {
                            // Load languages files of module
                            if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
                                foreach ($objMod->langfiles as $langfile) {
                                    $langs->load($langfile);
                                }
                            }
                            $modules[$i] = $objMod;
                            $filename[$i] = $modName;
                            $orders[$i] = $objMod->family . "_" . $j;
                            // Tri par famille puis numero module
                            //print "x".$modName." ".$orders[$i]."\n<br>";
                            if (isset($categ[$objMod->special])) {
                                $categ[$objMod->special]++;
                            } else {
                                $categ[$objMod->special] = 1;
                            }
                            $dirmod[$i] = $dirroot;
                            // Complete arrays
                            //&$tabname,&$tablib,&$tabsql,&$tabsqlsort,&$tabfield,&$tabfieldvalue,&$tabfieldinsert,&$tabrowid,&$tabcond
                            //$objMod
                            if (!empty($objMod->dictionnaries)) {
                                //var_dump($objMod->dictionnaries['tabname']);
                                $taborder[] = 0;
                                foreach ($objMod->dictionnaries['tabname'] as $val) {
                                    $taborder[] = count($tabname) + 1;
                                    $tabname[] = $val;
                                }
                                foreach ($objMod->dictionnaries['tablib'] as $val) {
                                    $tablib[] = $val;
                                }
                                foreach ($objMod->dictionnaries['tabsql'] as $val) {
                                    $tabsql[] = $val;
                                }
                                foreach ($objMod->dictionnaries['tabsqlsort'] as $val) {
                                    $tabsqlsort[] = $val;
                                }
                                foreach ($objMod->dictionnaries['tabfield'] as $val) {
                                    $tabfield[] = $val;
                                }
                                foreach ($objMod->dictionnaries['tabfieldvalue'] as $val) {
                                    $tabfieldvalue[] = $val;
                                }
                                foreach ($objMod->dictionnaries['tabfieldinsert'] as $val) {
                                    $tabfieldinsert[] = $val;
                                }
                                foreach ($objMod->dictionnaries['tabrowid'] as $val) {
                                    $tabrowid[] = $val;
                                }
                                foreach ($objMod->dictionnaries['tabcond'] as $val) {
                                    $tabcond[] = $val;
                                }
                                if (!empty($objMod->dictionnaries['tabhelp'])) {
                                    foreach ($objMod->dictionnaries['tabhelp'] as $val) {
                                        $tabhelp[] = $val;
                                    }
                                }
                                //foreach($objMod->dictionnaries['tabsqlsort'] as $val) $tablib[] = $val;
                                //$tabname = array_merge ($tabname, $objMod->dictionnaries['tabname']);
                                //var_dump($tabcond);
                                //exit;
                            }
                            $j++;
                            $i++;
                        } else {
                            dol_syslog("Module " . get_class($objMod) . " not qualified");
                        }
                    }
                }
            }
            closedir($handle);
        } else {
            dol_syslog("htdocs/admin/modules.php: Failed to open directory " . $dir . ". See permission and open_basedir option.", LOG_WARNING);
        }
    }
    return 1;
}
コード例 #11
0
 /**
  *  Build thumb
  *
  *  @param      string	$file           Path file in UTF8 to original file to create thumbs from.
  *	@return		void
  */
 function add_thumb($file)
 {
     global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';
     // This define also $maxwidthsmall, $quality, ...
     $file_osencoded = dol_osencode($file);
     if (file_exists($file_osencoded)) {
         // Create small thumbs for company (Ratio is near 16/9)
         // Used on logon for example
         vignette($file_osencoded, $maxwidthsmall, $maxheightsmall, '_small', $quality);
         // Create mini thumbs for company (Ratio is near 16/9)
         // Used on menu or for setup page for example
         vignette($file_osencoded, $maxwidthmini, $maxheightmini, '_mini', $quality);
     }
 }
コード例 #12
0
/**
 * Compress a file
 *
 * @param 	string	$inputfile		Source file name
 * @param 	string	$outputfile		Target file name
 * @param 	string	$mode			'gz' or 'bz' or 'zip'
 * @return	int						<0 if KO, >0 if OK
 */
function dol_compress_file($inputfile, $outputfile, $mode = "gz")
{
    $foundhandler = 0;
    try {
        $data = implode("", file(dol_osencode($inputfile)));
        if ($mode == 'gz') {
            $foundhandler = 1;
            $compressdata = gzencode($data, 9);
        } elseif ($mode == 'bz') {
            $foundhandler = 1;
            $compressdata = bzcompress($data, 9);
        } elseif ($mode == 'zip') {
            if (defined('ODTPHP_PATHTOPCLZIP')) {
                $foundhandler = 1;
                include_once ODTPHP_PATHTOPCLZIP . '/pclzip.lib.php';
                $archive = new PclZip($outputfile);
                $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
                //$archive->add($inputfile);
                return 1;
            }
        }
        if ($foundhandler) {
            $fp = fopen($outputfile, "w");
            fwrite($fp, $compressdata);
            fclose($fp);
            return 1;
        } else {
            dol_syslog("Try to zip with format " . $mode . " with no handler for this format", LOG_ERR);
            return -2;
        }
    } catch (Exception $e) {
        global $langs, $errormsg;
        $langs->load("errors");
        dol_syslog("Failed to open file " . $outputfile, LOG_ERR);
        $errormsg = $langs->trans("ErrorFailedToWriteInDir");
        return -1;
    }
}
コード例 #13
0
ファイル: index.php プロジェクト: Samara94/dolibarr
     $obj = 'facture';
 }
 if (empty($conf->{$module}->enabled)) {
     $enabled = false;
 }
 if ($enabled) {
     /*
      * If exists, load the API class for enable module
      *
      * Search files named api_<object>.class.php into /htdocs/<module>/class directory
      *
      * @todo : take care of externals module!
      * @todo : use getElementProperties() function ?
      */
     $dir_part = DOL_DOCUMENT_ROOT . '/' . $part . '/class/';
     $handle_part = @opendir(dol_osencode($dir_part));
     if (is_resource($handle_part)) {
         while (($file_searched = readdir($handle_part)) !== false) {
             if (is_readable($dir_part . $file_searched) && preg_match("/^(api_.*)\\.class\\.php\$/i", $file_searched, $reg)) {
                 $classname = $reg[1];
                 $classname = str_replace('Api_', '', ucwords($reg[1])) . 'Api';
                 $classname = ucfirst($classname);
                 require_once $dir_part . $file_searched;
                 if (class_exists($classname)) {
                     dol_syslog("Found API classname=" . $classname);
                     $api->r->addAPIClass($classname, '');
                     $listofapis[] = array('classname' => $classname, 'fullpath' => $file_searched);
                 }
             }
         }
     }
コード例 #14
0
ファイル: files.lib.php プロジェクト: remyyounes/dolibarr
/**
 *  Remove a directory $dir and its subdirectories
 *  @param      dir             Dir to delete
 *  @param      count           Counter to count nb of deleted elements
 *  @param      nophperrors     Disable all PHP output errors
 *  @return     int             Number of files and directory removed
 */
function dol_delete_dir_recursive($dir,$count=0,$nophperrors=0)
{
    dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG);
    if (dol_is_dir($dir))
    {
        $dir_osencoded=dol_osencode($dir);
        if ($handle = opendir("$dir_osencoded"))
        {
            while (false !== ($item = readdir($handle)))
            {
                if (! utf8_check($item)) $item=utf8_encode($item);  // should be useless

                if ($item != "." && $item != "..")
                {
                    if (is_dir(dol_osencode("$dir/$item")))
                    {
                        $count=dol_delete_dir_recursive("$dir/$item",$count,$nophperrors);
                    }
                    else
                    {
                        dol_delete_file("$dir/$item",1,$nophperrors);
                        $count++;
                        //echo " removing $dir/$item<br>\n";
                    }
                }
            }
            closedir($handle);
            dol_delete_dir($dir,$nophperrors);
            $count++;
            //echo "removing $dir<br>\n";
        }
    }

    //echo "return=".$count;
    return $count;
}
コード例 #15
0
 /**
  *      Return full text translated to language label for a key. Store key-label in a cache.
  *      This function need module "numberwords" to be installed. If not it will return
  *      same number (this module is not provided by default as it use non GPL source code).
  *
  *		@param	int		$number		Number to encode in full text
  * 		@param	int		$isamount	1=It's an amount, 0=it's just a number
  *      @return string				Label translated in UTF8 (but without entities)
  * 									10 if setDefaultLang was en_US => ten
  * 									123 if setDefaultLang was fr_FR => cent vingt trois
  */
 function getLabelFromNumber($number, $isamount = 0)
 {
     global $conf;
     $newnumber = $number;
     $dirsubstitutions = array_merge(array(), $conf->modules_parts['substitutions']);
     foreach ($dirsubstitutions as $reldir) {
         $dir = dol_buildpath($reldir, 0);
         $newdir = dol_osencode($dir);
         // Check if directory exists
         if (!is_dir($newdir)) {
             continue;
         }
         // We must not use dol_is_dir here, function may not be loaded
         $fonc = 'numberwords';
         if (file_exists($newdir . '/functions_' . $fonc . '.lib.php')) {
             include_once $newdir . '/functions_' . $fonc . '.lib.php';
             $newnumber = numberwords_getLabelFromNumber($this, $number, $isamount);
             break;
         }
     }
     return $newnumber;
 }
コード例 #16
0
 /**
  *  Load description int this->array_import_module, this->array_import_fields, ... of an importable dataset
  *
  *  @param		User	$user      	Object user making import
  *  @param  	string	$filter		Load a particular dataset only. Index will start to 0.
  *  @return		int					<0 if KO, >0 if OK
  */
 function load_arrays($user, $filter = '')
 {
     global $langs, $conf;
     dol_syslog(get_class($this) . "::load_arrays user="******" filter=" . $filter);
     $var = true;
     $i = 0;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
     $modulesdir = dolGetModulesDirs();
     // Load list of modules
     foreach ($modulesdir as $dir) {
         $handle = @opendir(dol_osencode($dir));
         if (!is_resource($handle)) {
             continue;
         }
         // Search module files
         while (($file = readdir($handle)) !== false) {
             if (!preg_match("/^(mod.*)\\.class\\.php/i", $file, $reg)) {
                 continue;
             }
             $modulename = $reg[1];
             // Defined if module is enabled
             $enabled = true;
             $part = strtolower(preg_replace('/^mod/i', '', $modulename));
             if (empty($conf->{$part}->enabled)) {
                 $enabled = false;
             }
             if (empty($enabled)) {
                 continue;
             }
             // Init load class
             $file = $dir . "/" . $modulename . ".class.php";
             $classname = $modulename;
             require_once $file;
             $module = new $classname($this->db);
             if (isset($module->import_code) && is_array($module->import_code)) {
                 foreach ($module->import_code as $r => $value) {
                     if ($filter && $filter != $module->import_code[$r]) {
                         continue;
                     }
                     // Test if permissions are ok
                     /*$perm=$module->import_permission[$r][0];
                     		//print_r("$perm[0]-$perm[1]-$perm[2]<br>");
                     		if ($perm[2])
                     		{
                     		$bool=$user->rights->$perm[0]->$perm[1]->$perm[2];
                     		}
                     		else
                     		{
                     		$bool=$user->rights->$perm[0]->$perm[1];
                     		}
                     		if ($perm[0]=='user' && $user->admin) $bool=true;
                     		//print $bool." $perm[0]"."<br>";
                     		*/
                     // Load lang file
                     $langtoload = $module->getLangFilesArray();
                     if (is_array($langtoload)) {
                         foreach ($langtoload as $key) {
                             $langs->load($key);
                         }
                     }
                     // Permission
                     $this->array_import_perms[$i] = $user->rights->import->run;
                     // Icon
                     $this->array_import_icon[$i] = isset($module->import_icon[$r]) ? $module->import_icon[$r] : $module->picto;
                     // Code du dataset export
                     $this->array_import_code[$i] = $module->import_code[$r];
                     // Libelle du dataset export
                     $this->array_import_label[$i] = $module->getImportDatasetLabel($r);
                     // Array of tables to import (key=alias, value=tablename)
                     $this->array_import_tables[$i] = $module->import_tables_array[$r];
                     // Array of tables creator field to import (key=alias, value=creator field)
                     $this->array_import_tables_creator[$i] = isset($module->import_tables_creator_array[$r]) ? $module->import_tables_creator_array[$r] : '';
                     // Array of fields to import (key=field, value=label)
                     $this->array_import_fields[$i] = $module->import_fields_array[$r];
                     // Array of hidden fields to import (key=field, value=label)
                     $this->array_import_fieldshidden[$i] = $module->import_fieldshidden_array[$r];
                     // Tableau des entites a exporter (cle=champ, valeur=entite)
                     $this->array_import_entities[$i] = $module->import_entities_array[$r];
                     // Tableau des alias a exporter (cle=champ, valeur=alias)
                     $this->array_import_regex[$i] = $module->import_regex_array[$r];
                     // Tableau des alias a exporter (cle=champ, valeur=exemple)
                     $this->array_import_examplevalues[$i] = $module->import_examplevalues_array[$r];
                     // Tableau des regles de conversion d'une valeur depuis une autre source (cle=champ, valeur=tableau des regles)
                     $this->array_import_convertvalue[$i] = isset($module->import_convertvalue_array[$r]) ? $module->import_convertvalue_array[$r] : '';
                     // Module
                     $this->array_import_module[$i] = $module;
                     dol_syslog("Import loaded for module " . $modulename . " with index " . $i . ", dataset=" . $module->import_code[$r] . ", nb of fields=" . count($module->import_fields_array[$r]));
                     $i++;
                 }
             }
         }
         closedir($handle);
     }
     return 1;
 }
コード例 #17
0
 /**
  *  Return if a filename $filename exists for current language (or alternate language)
  *
  *  @param	string	$filename       Language filename to search
  *  @param  string	$searchalt      Search also alernate language file
  *  @return boolean         		true if exists and readable
  */
 function file_exists($filename, $searchalt = 0)
 {
     // Test si fichier dans repertoire de la langue
     foreach ($this->dir as $searchdir) {
         if (is_readable(dol_osencode($searchdir . "/langs/" . $this->defaultlang . "/" . $filename))) {
             return true;
         }
         if ($searchalt) {
             // Test si fichier dans repertoire de la langue alternative
             if ($this->defaultlang != "en_US") {
                 $filenamealt = $searchdir . "/langs/en_US/" . $filename;
             }
             //else $filenamealt = $searchdir."/langs/fr_FR/".$filename;
             if (is_readable(dol_osencode($filenamealt))) {
                 return true;
             }
         }
     }
     return false;
 }
コード例 #18
0
ファイル: functions.lib.php プロジェクト: netors/dolibarr
/**
 *	Creation of a directory (recursive)
 *	@param      $dir        Directory to create
 *	@return     int         < 0 if KO, 0 = already exists, > 0 if OK
 */
function dol_mkdir($dir)
{
    global $conf;
    dol_syslog("functions.lib::create_exdir: dir=" . $dir, LOG_INFO);
    $dir_osencoded = dol_osencode($dir);
    if (@is_dir($dir_osencoded)) {
        return 0;
    }
    $nberr = 0;
    $nbcreated = 0;
    $ccdir = '';
    $cdir = explode("/", $dir);
    for ($i = 0; $i < sizeof($cdir); $i++) {
        if ($i > 0) {
            $ccdir .= '/' . $cdir[$i];
        } else {
            $ccdir = $cdir[$i];
        }
        if (preg_match("/^.:\$/", $ccdir, $regs)) {
            continue;
        }
        // Si chemin Windows incomplet, on poursuit par rep suivant
        // Attention, le is_dir() peut echouer bien que le rep existe.
        // (ex selon config de open_basedir)
        if ($ccdir) {
            $ccdir_osencoded = dol_osencode($ccdir);
            if (!@is_dir($ccdir_osencoded)) {
                dol_syslog("functions.lib::create_exdir: Directory '" . $ccdir . "' does not exists or is outside open_basedir PHP setting.", LOG_DEBUG);
                umask(0);
                $dirmaskdec = octdec('0755');
                if (!empty($conf->global->MAIN_UMASK)) {
                    $dirmaskdec = octdec($conf->global->MAIN_UMASK);
                }
                $dirmaskdec |= octdec('0111');
                // Set x bit required for directories
                if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
                    // Si le is_dir a renvoye une fausse info, alors on passe ici.
                    dol_syslog("functions.lib::create_exdir: Fails to create directory '" . $ccdir . "' or directory already exists.", LOG_WARNING);
                    $nberr++;
                } else {
                    dol_syslog("functions.lib::create_exdir: Directory '" . $ccdir . "' created", LOG_DEBUG);
                    $nberr = 0;
                    // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignore
                    $nbcreated++;
                }
            } else {
                $nberr = 0;
                // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignores
            }
        }
    }
    return $nberr ? -$nberr : $nbcreated;
}
コード例 #19
0
 function is_photo_available($sdir)
 {
     include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $pdir = get_exdir($this->id, 2) . $this->id . "/photos/";
     $dir = $sdir . '/' . $pdir;
     $nbphoto = 0;
     $dir_osencoded = dol_osencode($dir);
     if (file_exists($dir_osencoded)) {
         $handle = opendir($dir_osencoded);
         if (is_resource($handle)) {
             while (($file = readdir($handle)) != false) {
                 if (!utf8_check($file)) {
                     $file = utf8_encode($file);
                 }
                 // To be sure data is stored in UTF8 in memory
                 if (dol_is_file($dir . $file)) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
コード例 #20
0
/**
 * Migrate file from old path to new one for product $product
 *
 * @param 	Product	$product 	Object product
 * @return	void
 */
function migrate_product_photospath($product)
{
    global $conf;
    $dir = $conf->product->multidir_output[$product->entity];
    $origin = $dir . '/' . get_exdir($product->id, 2) . $product->id . "/photos";
    $destin = $dir . '/' . dol_sanitizeFileName($product->ref);
    $error = 0;
    $origin_osencoded = dol_osencode($origin);
    $destin_osencoded = dol_osencode($destin);
    dol_mkdir($destin);
    if (dol_is_dir($origin)) {
        $handle = opendir($origin_osencoded);
        if (is_resource($handle)) {
            while (($file = readdir($handle)) != false) {
                if ($file != '.' && $file != '..' && is_dir($origin_osencoded . '/' . $file)) {
                    $thumbs = opendir($origin_osencoded . '/' . $file);
                    if (is_resource($thumbs)) {
                        dol_mkdir($destin . '/' . $file);
                        while (($thumb = readdir($thumbs)) != false) {
                            dol_move($origin . '/' . $file . '/' . $thumb, $destin . '/' . $file . '/' . $thumb);
                        }
                        //		    			dol_delete_dir($origin.'/'.$file);
                    }
                } else {
                    if (dol_is_file($origin . '/' . $file)) {
                        dol_move($origin . '/' . $file, $destin . '/' . $file);
                    }
                }
            }
        }
    }
}
コード例 #21
0
ファイル: update.php プロジェクト: TAASA/Dolibarr-ERP-3.8.1
print '<br>';
// Install external module
$allowonlineinstall = true;
$allowfromweb = 1;
if (dol_is_file($dolibarrdataroot . '/installmodules.lock')) {
    $allowonlineinstall = false;
}
$fullurl = '<a href="' . $urldolibarrmodules . '" target="_blank">' . $urldolibarrmodules . '</a>';
$message = '';
if (!empty($allowonlineinstall)) {
    if (!in_array('/custom', explode(',', $dolibarr_main_url_root_alt))) {
        $message = info_admin($langs->trans("ConfFileMuseContainCustom", DOL_DOCUMENT_ROOT . '/custom', DOL_DOCUMENT_ROOT));
        $allowfromweb = -1;
    } else {
        if ($dirins_ok) {
            if (!is_writable(dol_osencode($dirins))) {
                $langs->load("errors");
                $message = info_admin($langs->trans("ErrorFailedToWriteInDir", $dirins));
                $allowfromweb = 0;
            }
        } else {
            $message = info_admin($langs->trans("NotExistsDirect", $dirins) . $langs->trans("InfDirAlt") . $langs->trans("InfDirExample"));
            $allowfromweb = 0;
        }
    }
} else {
    $message = info_admin($langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot . '/installmodules.lock'));
    $allowfromweb = 0;
}
print $langs->trans("AddExtensionThemeModuleOrOther") . '<br>';
print '<hr>';
コード例 #22
0
         setEventMessages('Failed to get bar code type information ' . $stdobject->error, $stdobject->errors, 'errors');
     }
 }
 if (!$error) {
     $code = $forbarcode;
     $generator = $stdobject->barcode_type_coder;
     // coder (loaded by fetch_barcode). Engine.
     $encoding = strtoupper($stdobject->barcode_type_code);
     // code (loaded by fetch_barcode). Example 'ean', 'isbn', ...
     $diroutput = $conf->barcode->dir_temp;
     dol_mkdir($diroutput);
     // Generate barcode
     $dirbarcode = array_merge(array("/core/modules/barcode/doc/"), $conf->modules_parts['barcode']);
     foreach ($dirbarcode as $reldir) {
         $dir = dol_buildpath($reldir, 0);
         $newdir = dol_osencode($dir);
         // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
         if (!is_dir($newdir)) {
             continue;
         }
         $result = @(include_once $newdir . $generator . '.modules.php');
         if ($result) {
             break;
         }
     }
     // Load barcode class for generating barcode image
     $classname = "mod" . ucfirst($generator);
     $module = new $classname($db);
     if ($generator != 'tcpdfbarcode') {
         // May be phpbarcode
         $template = 'standardlabel';
コード例 #23
0
ファイル: document.php プロジェクト: remyyounes/dolibarr
	dol_syslog("document.php back to ".urldecode($urlsource), LOG_DEBUG);

	header("Location: ".urldecode($urlsource));

	return;
}
else						// Open and return file
{
	clearstatcache();

	$filename = basename($original_file);

	// Output file on browser
	dol_syslog("document.php download $original_file $filename content-type=$type");
	$original_file_osencoded=dol_osencode($original_file);	// New file name encoded in OS encoding charset

	// This test if file exists should be useless. We keep it to find bug more easily
	if (! file_exists($original_file_osencoded))
	{
		dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
		exit;
	}

	// Les drois sont ok et fichier trouve, on l'envoie

	if ($encoding)   header('Content-Encoding: '.$encoding);
	if ($type)       header('Content-Type: '.$type.(preg_match('/text/',$type)?'; charset="'.$conf->file->character_set_client:''));
	if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
	else header('Content-Disposition: inline; filename="'.$filename.'"');
コード例 #24
0
	/**
	 *	Open input file
	 *	@param		file		Path of filename
	 *	@return		int			<0 if KO, >=0 if OK
	 */
	function import_open_file($file)
	{
		global $langs;
		$ret=1;

		dol_syslog("ImportCsv::open_file file=".$file);

		ini_set('auto_detect_line_endings',1);	// For MAC compatibility

		$this->handle = fopen(dol_osencode($file), "r");
		if (! $this->handle)
		{
			$langs->load("errors");
			$this->error=$langs->trans("ErrorFailToOpenFile",$file);
			$ret=-1;
		}
		else
		{
			$this->file=$file;
		}

		return $ret;
	}
コード例 #25
0
 /**
  * 	Delete object on database and/or on disk
  *
  *	@param	User	$user		User that delete
  *  @param	int		$mode		'all'=delete all, 'databaseonly'=only database entry, 'fileonly' (not implemented)
  *	@return	int					<0 if KO, >0 if OK
  */
 function delete($user, $mode = 'all')
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $error = 0;
     $result = 0;
     if ($mode != 'databaseonly') {
         $relativepath = $this->getRelativePath(1);
     }
     // Ex: dir1/dir2/dir3
     dol_syslog(get_class($this) . "::delete remove directory id=" . $this->id . " mode=" . $mode . ($mode == 'databaseonly' ? '' : ' relativepath=' . $relativepath));
     $this->db->begin();
     $sql = "DELETE FROM " . MAIN_DB_PREFIX . "ecm_directories";
     $sql .= " WHERE rowid=" . $this->id;
     dol_syslog(get_class($this) . "::delete sql=" . $sql);
     $resql = $this->db->query($sql);
     if (!$resql) {
         $this->db->rollback();
         $this->error = "Error " . $this->db->lasterror();
         dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR);
         return -2;
     }
     if ($mode != 'databaseonly') {
         $file = $conf->ecm->dir_output . "/" . $relativepath;
         $result = @dol_delete_dir($file);
     }
     if ($result || !@is_dir(dol_osencode($file))) {
         $this->db->commit();
     } else {
         $this->error = 'ErrorFailToDeleteDir';
         dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR);
         $this->db->rollback();
         $error++;
     }
     if (!$error) {
         // Appel des triggers
         include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
         $interface = new Interfaces($this->db);
         $result = $interface->run_triggers('MYECMDIR_DELETE', $this, $user, $langs, $conf);
         if ($result < 0) {
             $error++;
             $this->errors = $interface->errors;
         }
         // Fin appel triggers
     }
     if (!$error) {
         return 1;
     } else {
         return -1;
     }
 }
コード例 #26
0
ファイル: perms.php プロジェクト: Samara94/dolibarr
 $fgroup->fetch($id);
 $fgroup->getrights();
 /*
  * Affichage onglets
  */
 $head = group_prepare_head($fgroup);
 $title = $langs->trans("Group");
 dol_fiche_head($head, 'rights', $title, 0, 'group');
 // Charge les modules soumis a permissions
 $modules = array();
 $modulesdir = dolGetModulesDirs();
 $db->begin();
 foreach ($modulesdir as $dir) {
     // Load modules attributes in arrays (name, numero, orders) from dir directory
     //print $dir."\n<br>";
     $handle = @opendir(dol_osencode($dir));
     if (is_resource($handle)) {
         while (($file = readdir($handle)) !== false) {
             if (is_readable($dir . $file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
                 $modName = substr($file, 0, dol_strlen($file) - 10);
                 if ($modName) {
                     include_once $dir . "/" . $file;
                     $objMod = new $modName($db);
                     // Load all lang files of module
                     if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
                         foreach ($objMod->langfiles as $domain) {
                             $langs->load($domain);
                         }
                     }
                     // Load all permissions
                     if ($objMod->rights_class) {
コード例 #27
0
 $linkid = GETPOST('linkid', 'int');
 // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
 if ($urlfile) {
     $dir = dirname($file) . '/';
     // Chemin du dossier contenant l'image d'origine
     $dirthumb = $dir . '/thumbs/';
     // Chemin du dossier contenant la vignette
     $ret = dol_delete_file($file, 0, 0, 0, $object);
     // Si elle existe, on efface la vignette
     if (preg_match('/(\\.jpg|\\.jpeg|\\.bmp|\\.gif|\\.png|\\.tiff)$/i', $file, $regs)) {
         $photo_vignette = basename(preg_replace('/' . $regs[0] . '/i', '', $file) . '_small' . $regs[0]);
         if (file_exists(dol_osencode($dirthumb . $photo_vignette))) {
             dol_delete_file($dirthumb . $photo_vignette);
         }
         $photo_vignette = basename(preg_replace('/' . $regs[0] . '/i', '', $file) . '_mini' . $regs[0]);
         if (file_exists(dol_osencode($dirthumb . $photo_vignette))) {
             dol_delete_file($dirthumb . $photo_vignette);
         }
     }
     if ($ret) {
         setEventMessage($langs->trans("FileWasRemoved", $urlfile));
     } else {
         setEventMessage($langs->trans("ErrorFailToDeleteFile", $urlfile), 'errors');
     }
 } elseif ($linkid) {
     require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
     $link = new Link($db);
     $link->id = $linkid;
     $link->fetch();
     $res = $link->delete($user);
     $langs->load('link');