*/
/**
* \file htdocs/compta/facture/admin/facture_cust_extrafields.php
* \ingroup invoice
* \brief Page to setup extra fields of customer invoice
*/
require '../../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
$langs->load("companies");
$langs->load("admin");
$langs->load("bills");
$extrafields = new ExtraFields($db);
$form = new Form($db);
// List of supported format
$tmptype2label = getStaticMember(get_class($extrafields), 'type2label');
$type2label = array('');
foreach ($tmptype2label as $key => $val) {
    $type2label[$key] = $langs->trans($val);
}
$action = GETPOST('action', 'alpha');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'facturedet';
//Must be the $table_element of the class that manage extrafield
if (!$user->admin) {
    accessforbidden();
}
/*
* Actions
*/
require DOL_DOCUMENT_ROOT . '/core/actions_extrafields.inc.php';
if ($action == 'delete') {
    $file = $conf->admin->dir_output . '/' . GETPOST('urlfile');
    $ret = dol_delete_file($file, 1);
    if ($ret) {
        setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
    } else {
        setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
    }
    $action = '';
}
/*
 * View
 */
$form = new Form($db);
$formfile = new FormFile($db);
$label = getStaticMember($db, 'label');
$help_url = 'EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad';
llxHeader('', '', $help_url);
?>
<script type="text/javascript">
jQuery(document).ready(function() {

	function hideoptions () {
		jQuery("#mysql_options").hide();
		jQuery("#mysql_nobin_options").hide();
		jQuery("#postgresql_options").hide();
	}

	hideoptions();
	jQuery("#radio_dump_mysql").click(function() {
		hideoptions();
         $ok = 1;
     } else {
         print "<tr><td>" . $langs->trans("ErrorFailedToConnectToDatabase", $dolibarr_main_db_name) . "</td><td align=\"right\">" . $langs->trans("Error") . "</td></tr>\n";
         dolibarr_install_syslog("upgrade: " . $langs->transnoentities("ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
         $ok = 0;
     }
 }
 // Affiche version
 if ($ok) {
     $version = $db->getVersion();
     $versionarray = $db->getVersionArray();
     print '<tr><td>' . $langs->trans("ServerVersion") . '</td>';
     print '<td align="right">' . $version . '</td></tr>';
     dolibarr_install_syslog("upgrade: " . $langs->transnoentities("ServerVersion") . " : {$version}");
     // Test database version
     $versionmindb = getStaticMember(get_class($db), 'versionmin');
     //print join('.',$versionarray).' - '.join('.',$versionmindb);
     if (count($versionmindb) && count($versionarray) && versioncompare($versionarray, $versionmindb) < 0) {
         // Warning: database version too low.
         print "<tr><td>" . $langs->trans("ErrorDatabaseVersionTooLow", join('.', $versionarray), join('.', $versionmindb)) . "</td><td align=\"right\">" . $langs->trans("Error") . "</td></tr>\n";
         dolibarr_install_syslog("upgrade: " . $langs->transnoentities("ErrorDatabaseVersionTooLow", join('.', $versionarray), join('.', $versionmindb)));
         $ok = 0;
     }
 }
 // Force l'affichage de la progression
 if ($ok) {
     print '<tr><td colspan="2">' . $langs->trans("PleaseBePatient") . '</td></tr>';
     flush();
 }
 /*
  * Delete duplicates in table categorie_association
Esempio n. 4
0
// Scan les drivers
						$dir = DOL_DOCUMENT_ROOT . '/core/db';
						$handle = opendir($dir);
						if (is_resource($handle)) {
							while (($file = readdir($handle)) !== false) {
								if (is_readable($dir . "/" . $file) && preg_match('/^(.*)\.class\.php$/i', $file, $reg)) {
									$type = $reg[1];
									$class = 'DoliDB' . ucfirst($type);
									include_once($dir . "/" . $file);

									if ($type == 'sqlite')
										continue; // We hide sqlite because support can't be complete unti sqlit does not manage foreign key creation after table creation
// Version min of database
									$versionbasemin = getStaticMember($class, 'versionmin');
									$note = '(' . getStaticMember($class, 'label') . ' >= ' . versiontostring($versionbasemin) . ')';

									// Switch to mysql if mysqli is not present
									if ($defaultype == 'mysqli' && !function_exists('mysqli_connect'))
										$defaultype = 'mysql';

									// Show line into list
									if ($type == 'mysql') {
										$testfunction = 'mysql_connect';
										$testclass = '';
									}
									if ($type == 'mysqli') {
										$testfunction = 'mysqli_connect';
										$testclass = '';
									}
									if ($type == 'pgsql') {
Esempio n. 5
0
$apacheversion = version_webserver();
print "<tr {$bc['0']}><td width=\"280\">" . $langs->trans("Version") . "</td><td>" . $apacheversion . "</td></tr>\n";
print '</table>';
print "<br>\n";
// Php
print '<table class="noborder" width="100%">';
print "<tr class=\"liste_titre\"><td colspan=\"2\">" . $langs->trans("PHP") . "</td></tr>\n";
$phpversion = version_php();
print "<tr {$bc['0']}><td width=\"280\">" . $langs->trans("Version") . "</td><td>" . $phpversion . "</td></tr>\n";
print "<tr {$bc['1']}><td>" . $langs->trans("PhpWebLink") . "</td><td>" . php_sapi_name() . "</td></tr>\n";
print '</table>';
print "<br>\n";
// Database
print '<table class="noborder" width="100%">';
print "<tr class=\"liste_titre\"><td colspan=\"2\">" . $langs->trans("Database") . "</td></tr>\n";
$dblabel = getStaticMember(get_class($db), 'label');
$dbversion = $db->getVersion();
print "<tr {$bc['0']}><td width=\"280\">" . $langs->trans("Version") . "</td><td>" . $dblabel . " " . $dbversion . "</td></tr>\n";
print '</table>';
// Add checks on database options
if ($db->type == 'pgsql') {
    // Check option standard_conforming_strings is on
    $paramarray = $db->getServerParametersValues('standard_conforming_strings');
    if ($paramarray['standard_conforming_strings'] != 'on' && $paramarray['standard_conforming_strings'] != 1) {
        $langs->load("errors");
        //print '<div class="error">'.$langs->trans("ErrorDatabaseParameterWrong",'standard_conforming_strings','on').'</div>';
    }
}
print '<br>';
// Browser
print '<table class="noborder" width="100%">';
 */
require '../../main.inc.php';
$langs->load("admin");
if (!$user->admin) {
    accessforbidden();
}
/*
 * View
 */
$form = new Form($db);
llxHeader();
print_fiche_titre($langs->trans("InfoDatabase"), '', 'setup');
// Database
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="2">' . $langs->trans("Database") . '</td></tr>' . "\n";
print '<tr ' . $bc[0] . '><td width="300">' . $langs->trans("Version") . '</td><td>' . getStaticMember(get_class($db), 'label') . ' ' . $db->getVersion() . '</td></tr>' . "\n";
print '<tr ' . $bc[1] . '><td width="300">' . $langs->trans("DatabaseServer") . '</td><td>' . $conf->db->host . '</td></tr>' . "\n";
print '<tr ' . $bc[0] . '><td width="300">' . $langs->trans("DatabasePort") . '</td><td>' . (empty($conf->db->port) ? $langs->trans("Default") : $conf->db->port) . '</td></tr>' . "\n";
print '<tr ' . $bc[1] . '><td width="300">' . $langs->trans("DatabaseName") . '</td><td>' . $conf->db->name . '</td></tr>' . "\n";
print '<tr ' . $bc[0] . '><td width="300">' . $langs->trans("DriverType") . '</td><td>' . $conf->db->type . ($db->getDriverInfo() ? ' (' . $db->getDriverInfo() . ')' : '') . '</td></tr>' . "\n";
print '<tr ' . $bc[1] . '><td width="300">' . $langs->trans("User") . '</td><td>' . $conf->db->user . '</td></tr>' . "\n";
print '<tr ' . $bc[0] . '><td width="300">' . $langs->trans("Password") . '</td><td>' . preg_replace('/./i', '*', $dolibarr_main_db_pass) . '</td></tr>' . "\n";
print '<tr ' . $bc[1] . '><td width="300">' . $langs->trans("DBStoringCharset") . '</td><td>' . $db->getDefaultCharacterSetDatabase() . '</td></tr>' . "\n";
print '<tr ' . $bc[0] . '><td width="300">' . $langs->trans("DBSortingCharset") . '</td><td>' . $db->getDefaultCollationDatabase() . '</td></tr>' . "\n";
print '</table>';
// Tables
print '<br>';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="2">' . $langs->trans("Tables") . '</td></tr>' . "\n";
print '<tr ' . $bc[0] . '><td width="300"><a href="' . DOL_URL_ROOT . '/admin/system/database-tables.php?mainmenu=home">' . $langs->trans("List") . '</a></td></tr>' . "\n";
print '</table>';
/**	Backup the db OR just a table without mysqldump binary (does not require any exec permission)
 *	Author: David Walsh (http://davidwalsh.name/backup-mysql-database-php)
 *	Updated and enhanced by Stephen Larroque (lrq3000) and by the many commentators from the blog
 *	Note about foreign keys constraints: for Dolibarr, since there are a lot of constraints and when imported the tables will be inserted in the dumped order, not in constraints order, then we ABSOLUTELY need to use SET FOREIGN_KEY_CHECKS=0; when importing the sql dump.
 *	Note2: db2SQL by Howard Yeend can be an alternative, by using SHOW FIELDS FROM and SHOW KEYS FROM we could generate a more precise dump (eg: by getting the type of the field and then precisely outputting the right formatting - in quotes, numeric or null - instead of trying to guess like we are doing now).
 *
 *	@param	string	$outputfile		Output file name
 *	@param	string	$tables			Table name or '*' for all
 *	@return	int						<0 if KO, >0 if OK
 */
function backup_tables($outputfile, $tables = '*')
{
    global $db, $langs;
    global $errormsg;
    // Set to UTF-8
    $db->query('SET NAMES utf8');
    $db->query('SET CHARACTER SET utf8');
    //get all of the tables
    if ($tables == '*') {
        $tables = array();
        $result = $db->query('SHOW FULL TABLES WHERE Table_type = \'BASE TABLE\'');
        while ($row = $db->fetch_row($result)) {
            $tables[] = $row[0];
        }
    } else {
        $tables = is_array($tables) ? $tables : explode(',', $tables);
    }
    //cycle through
    $handle = fopen($outputfile, 'w+');
    if (fwrite($handle, '') === FALSE) {
        $langs->load("errors");
        dol_syslog("Failed to open file " . $outputfile, LOG_ERR);
        $errormsg = $langs->trans("ErrorFailedToWriteInDir");
        return -1;
    }
    // Print headers and global mysql config vars
    $sqlhead = '';
    $sqlhead .= "-- " . getStaticMember($db, 'label') . " dump via php\n--\n-- Host: " . $db->db->host_info . "    Database: " . $db->database_name . "\n-- ------------------------------------------------------\n-- Server version\t" . $db->db->server_info . "\n\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n/*!40101 SET NAMES utf8 */;\n\n";
    if (GETPOST("nobin_disable_fk")) {
        $sqlhead .= "SET FOREIGN_KEY_CHECKS=0;\n";
    }
    $sqlhead .= "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";\n";
    if (GETPOST("nobin_use_transaction")) {
        $sqlhead .= "SET AUTOCOMMIT=0;\nSTART TRANSACTION;\n";
    }
    fwrite($handle, $sqlhead);
    $ignore = '';
    if (GETPOST("nobin_sql_ignore")) {
        $ignore = 'IGNORE ';
    }
    $delayed = '';
    if (GETPOST("nobin_delayed")) {
        $delayed = 'DELAYED ';
    }
    // Process each table and print their definition + their datas
    foreach ($tables as $table) {
        // Saving the table structure
        fwrite($handle, "\n--\n-- Table structure for table `" . $table . "`\n--\n");
        if (GETPOST("nobin_drop")) {
            fwrite($handle, "DROP TABLE IF EXISTS `" . $table . "`;\n");
        }
        // Dropping table if exists prior to re create it
        //fwrite($handle,"/*!40101 SET @saved_cs_client     = @@character_set_client */;\n");
        //fwrite($handle,"/*!40101 SET character_set_client = utf8 */;\n");
        $resqldrop = $db->query('SHOW CREATE TABLE ' . $table);
        $row2 = $db->fetch_row($resqldrop);
        if (empty($row2[1])) {
            fwrite($handle, "\n-- WARNING: Show create table " . $table . " return empy string when it should not.\n");
        } else {
            fwrite($handle, $row2[1] . ";\n");
            //fwrite($handle,"/*!40101 SET character_set_client = @saved_cs_client */;\n\n");
            // Dumping the data (locking the table and disabling the keys check while doing the process)
            fwrite($handle, "\n--\n-- Dumping data for table `" . $table . "`\n--\n");
            if (!GETPOST("nobin_nolocks")) {
                fwrite($handle, "LOCK TABLES `" . $table . "` WRITE;\n");
            }
            // Lock the table before inserting data (when the data will be imported back)
            if (GETPOST("nobin_disable_fk")) {
                fwrite($handle, "ALTER TABLE `" . $table . "` DISABLE KEYS;\n");
            }
            $sql = 'SELECT * FROM ' . $table;
            $result = $db->query($sql);
            $num_fields = $db->num_rows($result);
            while ($row = $db->fetch_row($result)) {
                // For each row of data we print a line of INSERT
                fwrite($handle, 'INSERT ' . $delayed . $ignore . 'INTO `' . $table . '` VALUES (');
                $columns = count($row);
                for ($j = 0; $j < $columns; $j++) {
                    // Processing each columns of the row to ensure that we correctly save the value (eg: add quotes for string - in fact we add quotes for everything, it's easier)
                    if ($row[$j] == null and !is_string($row[$j])) {
                        // IMPORTANT: if the field is NULL we set it NULL
                        $row[$j] = 'NULL';
                    } elseif (is_string($row[$j]) and $row[$j] == '') {
                        // if it's an empty string, we set it as an empty string
                        $row[$j] = "''";
                    } elseif (is_numeric($row[$j]) and !strcmp($row[$j], $row[$j] + 0)) {
                        // test if it's a numeric type and the numeric version ($nb+0) == string version (eg: if we have 01, it's probably not a number but rather a string, else it would not have any leading 0)
                        // if it's a number, we return it as-is
                        $row[$j] = $row[$j];
                    } else {
                        // else for all other cases we escape the value and put quotes around
                        $row[$j] = addslashes($row[$j]);
                        $row[$j] = preg_replace("#\n#", "\\n", $row[$j]);
                        $row[$j] = "'" . $row[$j] . "'";
                    }
                }
                fwrite($handle, implode(',', $row) . ");\n");
            }
            if (GETPOST("nobin_disable_fk")) {
                fwrite($handle, "ALTER TABLE `" . $table . "` ENABLE KEYS;\n");
            }
            // Enabling back the keys/index checking
            if (!GETPOST("nobin_nolocks")) {
                fwrite($handle, "UNLOCK TABLES;\n");
            }
            // Unlocking the table
            fwrite($handle, "\n\n\n");
        }
    }
    /* Backup Procedure structure*/
    /*
     $result = $db->query('SHOW PROCEDURE STATUS');
    if ($db->num_rows($result) > 0)
    {
    while ($row = $db->fetch_row($result)) { $procedures[] = $row[1]; }
    foreach($procedures as $proc)
    {
    fwrite($handle,"DELIMITER $$\n\n");
    fwrite($handle,"DROP PROCEDURE IF EXISTS '$name'.'$proc'$$\n");
    $resqlcreateproc=$db->query("SHOW CREATE PROCEDURE '$proc'");
    $row2 = $db->fetch_row($resqlcreateproc);
    fwrite($handle,"\n".$row2[2]."$$\n\n");
    fwrite($handle,"DELIMITER ;\n\n");
    }
    }
    */
    /* Backup Procedure structure*/
    // Write the footer (restore the previous database settings)
    $sqlfooter = "\n\n";
    if (GETPOST("nobin_use_transaction")) {
        $sqlfooter .= "COMMIT;\n";
    }
    if (GETPOST("nobin_disable_fk")) {
        $sqlfooter .= "SET FOREIGN_KEY_CHECKS=1;\n";
    }
    $sqlfooter .= "\n\n-- Dump completed on " . date('Y-m-d G-i-s');
    fwrite($handle, $sqlfooter);
    fclose($handle);
    return 1;
}
Esempio n. 8
0
/**	Backup the db OR just a table without mysqldump binary (does not require any exec permission)
 *	Author: David Walsh (http://davidwalsh.name/backup-mysql-database-php)
 *	Updated and enhanced by Stephen Larroque (lrq3000) and by the many commentators from the blog
 *
 *	@param	string	$outputfile		Output file name
 *	@param	string	$tables			Table name or '*' for all
 *	@return	int						<0 if KO, >0 if OK
 */
function backup_tables($outputfile, $tables = '*')
{
    global $db, $langs;
    global $errormsg;
    // Set to UTF-8
    $db->query('SET NAMES utf8');
    $db->query('SET CHARACTER SET utf8');
    //get all of the tables
    if ($tables == '*') {
        $tables = array();
        $result = $db->query('SHOW FULL TABLES WHERE Table_type = \'BASE TABLE\'');
        while ($row = $db->fetch_row($result)) {
            $tables[] = $row[0];
        }
    } else {
        $tables = is_array($tables) ? $tables : explode(',', $tables);
    }
    //cycle through
    $handle = fopen($outputfile, 'w+');
    if (fwrite($handle, '') === FALSE) {
        $langs->load("errors");
        dol_syslog("Failed to open file " . $outputfile, LOG_ERR);
        $errormsg = $langs->trans("ErrorFailedToWriteInDir");
        return -1;
    }
    // Print headers and global mysql config vars
    $sqlhead = '';
    $sqlhead .= "-- " . getStaticMember($db, 'label') . " dump via php\n--\n-- Host: " . $db->db->host_info . "    Database: " . $db->database_name . "\n-- ------------------------------------------------------\n-- Server version\t" . $db->db->server_info . "\n\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n/*!40101 SET NAMES utf8 */;\n/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n/*!40103 SET TIME_ZONE='+00:00' */;\n/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n";
    fwrite($handle, $sqlhead);
    // Process each table and print their definition + their datas
    foreach ($tables as $table) {
        // Saving the table structure
        fwrite($handle, "--\n-- Table structure for table `" . $table . "`\n--\n\n");
        fwrite($handle, "DROP TABLE IF EXISTS `" . $table . "`;\n");
        fwrite($handle, "/*!40101 SET @saved_cs_client     = @@character_set_client */;\n");
        fwrite($handle, "/*!40101 SET character_set_client = utf8 */;\n");
        $resqldrop = $db->query('SHOW CREATE TABLE ' . $table);
        $row2 = $db->fetch_row($resqldrop);
        fwrite($handle, $row2[1] . ";\n");
        fwrite($handle, "/*!40101 SET character_set_client = @saved_cs_client */;\n\n");
        // Dumping the data (locking the table and disabling the keys check while doing the process)
        fwrite($handle, "--\n-- Dumping data for table `" . $table . "`\n--\n\n");
        fwrite($handle, "LOCK TABLES `" . $table . "` WRITE;\n");
        fwrite($handle, "/*!40000 ALTER TABLE `" . $table . "` DISABLE KEYS */;\n");
        $sql = 'SELECT * FROM ' . $table;
        $result = $db->query($sql);
        $num_fields = $db->num_rows($result);
        while ($row = $db->fetch_row($result)) {
            // For each row of data we print a line of INSERT
            fwrite($handle, 'INSERT INTO `' . $table . '` VALUES (');
            $columns = count($row);
            $rowsarr = array();
            for ($j = 0; $j < $columns; $j++) {
                // Processing each columns of the row to ensure that we correctly save the value (eg: add quotes for string - in fact we add quotes for everything, it's easier)
                if ($row[$j] == null and !is_string($row[$j])) {
                    // IMPORTANT: if the field is NULL we set it NULL
                    $row[$j] = 'NULL';
                } elseif (is_string($row[$j]) and $row[$j] == '') {
                    // if it's an empty string, we set it as an empty string
                    $row[$j] = "''";
                } elseif (is_numeric($row[$j])) {
                    // if it's a number, we return it as-is
                    $row[$j] = $row[$j];
                } else {
                    // else for all other cases we escape the value and put quotes around
                    $row[$j] = addslashes($row[$j]);
                    $row[$j] = preg_replace("#\n#", "\\n", $row[$j]);
                    $row[$j] = "'" . $row[$j] . "'";
                }
            }
            fwrite($handle, implode(',', $row) . ");\n");
        }
        fwrite($handle, "/*!40000 ALTER TABLE `" . $table . "` ENABLE KEYS */;\n");
        // Enabling back the keys/index checking
        fwrite($handle, "UNLOCK TABLES;\n");
        // Unlocking the tables
        fwrite($handle, "\n\n\n");
    }
    /* Backup Procedure structure*/
    /*
     $result = $db->query('SHOW PROCEDURE STATUS');
    if ($db->num_rows($result) > 0)
    {
    while ($row = $db->fetch_row($result)) { $procedures[] = $row[1]; }
    foreach($procedures as $proc)
    {
    fwrite($handle,"DELIMITER $$\n\n");
    fwrite($handle,"DROP PROCEDURE IF EXISTS '$name'.'$proc'$$\n");
    $resqlcreateproc=$db->query("SHOW CREATE PROCEDURE '$proc'");
    $row2 = $db->fetch_row($resqlcreateproc);
    fwrite($handle,"\n".$row2[2]."$$\n\n");
    fwrite($handle,"DELIMITER ;\n\n");
    }
    }
    */
    /* Backup Procedure structure*/
    // Write the footer (restore the previous database settings)
    $sqlfooter = '';
    $sqlfooter .= "\n/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n\n/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n\n-- Dump completed on " . date('Y-m-d G-i-s');
    fwrite($handle, $sqlfooter);
    fclose($handle);
    return 1;
}
Esempio n. 9
0
	if (!empty($_POST["db_create_database"])) {
		$result = $db->select_db($_POST["db_name"]);
		if ($result) {
			print '<div class="error">' . $langs->trans("ErrorDatabaseAlreadyExists", $_POST["db_name"]) . '</div>';
			print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate") . '<br><br>';
			print $langs->trans("ErrorGoBackAndCorrectParameters");
			$error++;
		}
	}
}

// Define $defaultCharacterSet and $defaultCollationConnection
if (!$error && $db->connected) {
	if (!empty($_POST["db_create_database"])) { // If we create database, we force default value
		$defaultCharacterSet = getStaticMember(get_class($db), 'forcecharset');
		$defaultCollationConnection = getStaticMember(get_class($db), 'forcecollate');
	} else { // If already created, we take current value
		$defaultCharacterSet = $db->getDefaultCharacterSetDatabase();
		$defaultCollationConnection = $db->getDefaultCollationDatabase();
	}

	print '<input type="hidden" name="dolibarr_main_db_character_set" value="' . $defaultCharacterSet . '">';
	print '<input type="hidden" name="dolibarr_main_db_collation" value="' . $defaultCollationConnection . '">';
	$_POST['dolibarr_main_db_character_set'] = $defaultCharacterSet;
	$_POST['dolibarr_main_db_collation'] = $defaultCollationConnection;
}


// Create config file
if (!$error && $db->connected && $action == "set") {
	umask(0);
Esempio n. 10
0
 *   \brief      Page to setup boxes
 */
require '../main.inc.php';
include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php';
include_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
$langs->load("admin");
$langs->load("boxes");
if (!$user->admin) {
    accessforbidden();
}
$rowid = GETPOST('rowid', 'int');
$action = GETPOST('action', 'alpha');
$errmesg = '';
// Define possible position of boxes
$pos_name = getStaticMember('InfoBox', 'listOfPages');
$boxes = array();
/*
 * Actions
 */
if ($action == 'addconst') {
    dolibarr_set_const($db, "MAIN_BOXES_MAXLINES", $_POST["MAIN_BOXES_MAXLINES"], '', 0, '', $conf->entity);
}
if ($action == 'add') {
    $error = 0;
    $db->begin();
    // Initialize distinct fkuser with all already existing values of fk_user (user that use a personalized view of boxes for page "pos")
    $distinctfkuser = array();
    if (!$error) {
        $sql = "SELECT fk_user";
        $sql .= " FROM " . MAIN_DB_PREFIX . "user_param";
 /**
  *  Insert boxes into llx_boxes_def
  *
  *	@param		string	$option		String with options when disabling module ('newboxdefonly'=insert only boxes definition)
  *  @return     int     			Nb of errors (0 if OK)
  */
 function insert_boxes($option = '')
 {
     require_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php';
     global $conf;
     $err = 0;
     if (is_array($this->boxes)) {
         foreach ($this->boxes as $key => $value) {
             $file = isset($this->boxes[$key]['file']) ? $this->boxes[$key]['file'] : '';
             $note = isset($this->boxes[$key]['note']) ? $this->boxes[$key]['note'] : '';
             $enabledbydefaulton = isset($this->boxes[$key]['enabledbydefaulton']) ? $this->boxes[$key]['enabledbydefaulton'] : 'Home';
             if (empty($file)) {
                 $file = isset($this->boxes[$key][1]) ? $this->boxes[$key][1] : '';
             }
             // For backward compatibility
             if (empty($note)) {
                 $note = isset($this->boxes[$key][2]) ? $this->boxes[$key][2] : '';
             }
             // For backward compatibility
             // Search if boxes def already present
             $sql = "SELECT count(*) as nb FROM " . MAIN_DB_PREFIX . "boxes_def";
             $sql .= " WHERE file = '" . $this->db->escape($file) . "'";
             $sql .= " AND entity = " . $conf->entity;
             if ($note) {
                 $sql .= " AND note ='" . $this->db->escape($note) . "'";
             }
             dol_syslog(get_class($this) . "::insert_boxes sql=" . $sql);
             $result = $this->db->query($sql);
             if ($result) {
                 $obj = $this->db->fetch_object($result);
                 if ($obj->nb == 0) {
                     $this->db->begin();
                     if (!$err) {
                         $sql = "INSERT INTO " . MAIN_DB_PREFIX . "boxes_def (file, entity, note)";
                         $sql .= " VALUES ('" . $this->db->escape($file) . "', ";
                         $sql .= $conf->entity . ", ";
                         $sql .= $note ? "'" . $this->db->escape($note) . "'" : "null";
                         $sql .= ")";
                         dol_syslog(get_class($this) . "::insert_boxes sql=" . $sql);
                         $resql = $this->db->query($sql);
                         if (!$resql) {
                             $err++;
                         }
                     }
                     if (!$err && !preg_match('/newboxdefonly/', $option)) {
                         $lastid = $this->db->last_insert_id(MAIN_DB_PREFIX . "boxes_def", "rowid");
                         $pos_name = getStaticMember('InfoBox', 'listOfPages');
                         foreach ($pos_name as $key2 => $val2) {
                             //print 'key2='.$key2.'-val2='.$val2."<br>\n";
                             if ($enabledbydefaulton && $val2 != $enabledbydefaulton) {
                                 continue;
                             }
                             // Not enabled by default onto this page.
                             $sql = "INSERT INTO " . MAIN_DB_PREFIX . "boxes (box_id,position,box_order,fk_user,entity)";
                             $sql .= " VALUES (" . $lastid . ", " . $key2 . ", '0', 0, " . $conf->entity . ")";
                             dol_syslog(get_class($this) . "::insert_boxes onto page " . $key2 . "=" . $val2 . " sql=" . $sql);
                             $resql = $this->db->query($sql);
                             if (!$resql) {
                                 $err++;
                             }
                         }
                     }
                     if (!$err) {
                         $this->db->commit();
                     } else {
                         $this->error = $this->db->lasterror();
                         dol_syslog(get_class($this) . "::insert_boxes " . $this->error, LOG_ERR);
                         $this->db->rollback();
                     }
                 }
                 // else box already registered into database
             } else {
                 $this->error = $this->db->lasterror();
                 dol_syslog(get_class($this) . "::insert_boxes " . $this->error, LOG_ERR);
                 $err++;
             }
         }
     }
     return $err;
 }