Skip to content
Snippets Groups Projects
Class_Install.php 85.4 KiB
Newer Older
  • Learn to ignore specific revisions
  • Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    <?php
    
    /**
    * Copyright Maarch since 2008 under licence GPLv3.
    * See LICENCE.txt file at the root folder for more details.
    * This file is part of Maarch software.
    
     *
     * @file
     *
     * @author Laurent Giovannoni
     * @author Arnaud Veber
     * @date $date$
     *
     * @version $Revision$
     * @ingroup install
     */
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    //Loads the required class
    try {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        require_once 'core/class/class_functions.php';
        require_once 'core/class/class_db.php';
        require_once 'install/class/Class_Merge.php';
    
        require_once 'core'.DIRECTORY_SEPARATOR.'class'
            .DIRECTORY_SEPARATOR.'class_security.php';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    } catch (Exception $e) {
    
        functions::xecho($e->getMessage()).' // ';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    }
    
    class Install extends functions
    {
        private $lang = 'en';
    
        private $docservers = array(
            array('FASTHD_AI', 'ai'),
    
            array('FASTHD_MAN', 'manual'),
    
            array('FASTHD_ATTACH', 'manual_attachments'),
    
            array('FASTHD_ATTACH_VERSION', 'manual_attachments_version'),
            array('CONVERT_MLB', 'convert_mlb'),
            array('CONVERT_ATTACH', 'convert_attachments'),
            array('CONVERT_ATTACH_VERSION', 'convert_attachments_version'),
            array('TNL_MLB', 'thumbnails_mlb'),
            array('TNL_ATTACH', 'thumbnails_attachments'),
            array('TNL_ATTACH_VERSION', 'thumbnails_attachments_version'),
            array('FULLTEXT_MLB', 'fulltext_mlb'),
            array('FULLTEXT_ATTACH', 'fulltext_attachments'),
            array('FULLTEXT_ATTACH_VERSION', 'fulltext_attachments_version'),
    
            array('TEMPLATES', 'templates'),
    
            array('ARCHIVETRANSFER', 'archive_transfer'),
    
        public function __construct()
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        {
            //merge css & js
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            //load lang
            $this->loadLang();
        }
    
        public function getLangList()
        {
            $langList = array();
    
            foreach (glob('install/lang/*.php') as $fileLangPath) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                $langFile = str_replace('.php', '', end(explode('/', $fileLangPath)));
                array_push($langList, $langFile);
            }
    
            return $langList;
        }
    
    
        public function loadLang()
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        {
            if (!isset($_SESSION['lang'])) {
                $this->lang = 'en';
            }
            $this->lang = $_SESSION['lang'];
    
            $langList = $this->getLangList();
            if (!in_array($this->lang, $langList)) {
                $this->lang = 'en';
            }
    
    
            require_once 'install/lang/'.$this->lang.'.php';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        }
    
        public function getActualLang()
        {
            return $this->lang;
        }
    
        public function checkPrerequisites(
            $is = false,
            $optional = false
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if ($is) {
                return '<img src="img/green_light.png" width="20px"/>';
                exit;
            }
            if (!$optional) {
                return '<img src="img/red_light.png"  width="20px"/>';
                exit;
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            return '<img src="img/orange_light.png"  width="20px"/>';
        }
    
        public function checkAllNeededPrerequisites()
        {
            if (!$this->isPhpVersion()) {
                return false;
            }
            if (!$this->isPhpRequirements('pgsql')) {
                return false;
            }
    
            if (!$this->isPhpRequirements('mbstring')) {
                return false;
            }
    
            if (!$this->isMaarchPathWritable()) {
                return false;
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if (!$this->isDependenciesExist()) {
                return false;
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if (!$this->isPhpRequirements('gd')) {
                return false;
            }
    
            /*if (!$this->isPhpRequirements('imagick')) {
    
                return false;
    
            /*if (!$this->isPhpRequirements('ghostscript')) {
                return false;
            }*/
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if (!$this->isPearRequirements('System.php')) {
                return false;
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            // if (!$this->isPearRequirements('MIME/Type.php')) {
            //     return false;
            // }
    
            /*if (!$this-&gt;isIniErrorRepportingRequirements()) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                return false;
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if (!$this->isIniDisplayErrorRequirements()) {
                return false;
            }
            if (!$this->isIniShortOpenTagRequirements()) {
                return false;
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            // if (!$this->isIniMagicQuotesGpcRequirements()) {
            //     return false;
            // }
    
            if (DIRECTORY_SEPARATOR != '/' && !$this->isPhpRequirements('fileinfo')) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            return true;
        }
    
        public function isPhpVersion()
        {
            if (version_compare(PHP_VERSION, '5.3') < 0) {
                return false;
                exit;
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            return true;
        }
    
        public function isPhpRequirements($phpLibrary)
        {
            if (!@extension_loaded($phpLibrary)) {
                return false;
                exit;
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            return true;
        }
    
        public function isPearRequirements($pearLibrary)
        {
            $includePath = array();
            $includePath = explode(';', ini_get('include_path'));
    
            for ($i = 0; $i < count($includePath); ++$i) {
                if (file_exists($includePath[$i].'/'.$pearLibrary)) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                    return true;
                    exit;
                }
            }
            $includePath = explode(':', ini_get('include_path'));
    
            for ($i = 0; $i < count($includePath); ++$i) {
                if (file_exists($includePath[$i].'/'.$pearLibrary)) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                    return true;
                    exit;
                }
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            return false;
        }
    
        public function isIniErrorRepportingRequirements()
        {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if (version_compare(PHP_VERSION, '5.4') >= 0) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            } else {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            }
        }
    
        public function isIniDisplayErrorRequirements()
        {
    
            if (strtoupper(ini_get('display_errors')) == 'OFF') {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                return false;
            } else {
                return true;
            }
        }
    
        public function isIniShortOpenTagRequirements()
        {
    
            if (strtoupper(ini_get('short_open_tag')) == 'OFF') {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                return false;
            } else {
                return true;
            }
        }
    
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        // public function isIniMagicQuotesGpcRequirements()
        // {
        //     if (strtoupper(ini_get('magic_quotes_gpc')) ==  'ON') {
        //         return false;
        //     } else {
        //         return true;
        //     }
        // }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        public function getProgress(
            $stepNb,
            $stepNbTotal
    
            if ($stepNb == 0) {
                return '';
                exit;
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            $return = '';
    
            $percentProgress = round(($stepNb / $stepNbTotal) * 100);
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            $sizeProgress = round(($percentProgress * 910) / 100);
    
            $return .= '<div id="progressButton" style="width: '.$sizeProgress.'px;">';
    
            $return .= '<div align="center">';
            $return .= $percentProgress.'%';
            $return .= '</div>';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            $return .= '</div>';
    
            return $return;
        }
    
    
        public function setPreviousStep($previousStep)
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            $_SESSION['previousStep'] = $previousStep;
        }
    
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        public function checkDatabaseParameters(
            $databaseserver,
            $databaseserverport,
            $databaseuser,
            $databasepassword,
            $databasetype
    
            $connect = 'host='.$databaseserver.' ';
            $connect .= 'port='.$databaseserverport.' ';
            $connect .= 'user='.$databaseuser.' ';
            $connect .= 'password='.$databasepassword.' ';
    
            $connect .= 'dbname=postgres';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if (!@pg_connect($connect)) {
                return false;
                exit;
            }
    
            pg_close();
    
            return true;
        }
    
    
        public function createCustom($databasename)
        {
    
            $customAlreadyExist = realpath('.').'/custom/cs_'.$databasename;
    
            if (file_exists($customAlreadyExist)) {
    
                if (is_dir(realpath('.')."/custom/cs_$databasename/apps/") && is_dir(realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise/") && is_dir(realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise/xml/")) {
                } elseif (is_dir(realpath('.')."/custom/cs_$databasename/apps/") && !is_dir(realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise/")) {
                    $cheminCustomMaarchCourrierAppsMaarchEntreprise = realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise";
                    mkdir($cheminCustomMaarchCourrierAppsMaarchEntreprise, 0755);
    
                    $cheminCustomMaarchCourrierAppsMaarchEntrepriseXml = realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise/xml";
                    mkdir($cheminCustomMaarchCourrierAppsMaarchEntrepriseXml, 0755);
                } elseif (is_dir(realpath('.')."/custom/cs_$databasename/apps/") && is_dir(realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise/") && !is_dir(realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise/xml/")) {
                    $cheminCustomMaarchCourrierAppsMaarchEntrepriseXml = realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise/xml";
                    mkdir($cheminCustomMaarchCourrierAppsMaarchEntrepriseXml, 0755);
                } elseif (!is_dir(realpath('.')."/custom/cs_$databasename/apps/")) {
                    $cheminCustomMaarchCourrierApps = realpath('.')."/custom/cs_$databasename/apps";
                    mkdir($cheminCustomMaarchCourrierApps, 0755);
    
                    $cheminCustomMaarchCourrierAppsMaarchEntreprise = realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise";
                    mkdir($cheminCustomMaarchCourrierAppsMaarchEntreprise, 0755);
    
                    $cheminCustomMaarchCourrierAppsMaarchEntrepriseXml = realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise/xml";
                    mkdir($cheminCustomMaarchCourrierAppsMaarchEntrepriseXml, 0755);
                }
    
                if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/")) {
                    $cheminCustomMaarchCourrierModules = realpath('.')."/custom/cs_$databasename/modules";
                    mkdir($cheminCustomMaarchCourrierModules, 0755);
    
                    /** Création répertoire thumbnails dans le custom **/
                    $cheminCustomMaarchCourrierModulesThumbnails = realpath('.')."/custom/cs_$databasename/modules/thumbnails";
    
                    mkdir($cheminCustomMaarchCourrierModulesThumbnails, 0755);
    
                    $cheminCustomMaarchCourrierModulesThumbnailsXml = realpath('.')."/custom/cs_$databasename/modules/thumbnails/xml";
                    mkdir($cheminCustomMaarchCourrierModulesThumbnailsXml, 0755);
    
                    $cheminCustomMaarchCourrierModulesThumbnailsScripts = realpath('.')."/custom/cs_$databasename/modules/thumbnails/scripts";
                    mkdir($cheminCustomMaarchCourrierModulesThumbnailsScripts, 0755);
    
                    /** Création répertoire notification dans le custom **/
                    $cheminCustomMaarchCourrierModulesNotifications = realpath('.')."/custom/cs_$databasename/modules/notifications";
    
                    mkdir($cheminCustomMaarchCourrierModulesNotifications, 0755);
    
                    $cheminCustomMaarchCourrierModulesNotificationsBatch = realpath('.')."/custom/cs_$databasename/modules/notifications/batch";
                    mkdir($cheminCustomMaarchCourrierModulesNotificationsBatch, 0755);
    
                    $cheminCustomMaarchCourrierModulesNotificationsConfig = realpath('.')."/custom/cs_$databasename/modules/notifications/batch/config";
                    mkdir($cheminCustomMaarchCourrierModulesNotificationsConfig, 0755);
    
                    $cheminCustomMaarchCourrierModulesNotificationsScripts = realpath('.')."/custom/cs_$databasename/modules/notifications/batch/scripts";
                    mkdir($cheminCustomMaarchCourrierModulesNotificationsScripts, 0755);
    
                    /** Création répertoire sendmail dans le custom **/
                    $cheminCustomMaarchCourrierModulesSendmail = realpath('.')."/custom/cs_$databasename/modules/sendmail";
    
                    mkdir($cheminCustomMaarchCourrierModulesSendmail, 0755);
    
                    $cheminCustomMaarchCourrierModulesSendmailBatch = realpath('.')."/custom/cs_$databasename/modules/sendmail/batch";
                    mkdir($cheminCustomMaarchCourrierModulesSendmailBatch, 0755);
    
                    $cheminCustomMaarchCourrierModulesSendmailBatchConfig = realpath('.')."/custom/cs_$databasename/modules/sendmail/batch/config";
                    mkdir($cheminCustomMaarchCourrierModulesSendmailBatchConfig, 0755);
    
                    $cheminCustomMaarchCourrierModulesSendmailBatchScripts = realpath('.')."/custom/cs_$databasename/modules/sendmail/batch/scripts";
                    mkdir($cheminCustomMaarchCourrierModulesSendmailBatchScripts, 0755);
    
                    /** Création répertoire LDAP dans le custom **/
                    $cheminCustomMaarchCourrierModulesLdap = realpath('.')."/custom/cs_$databasename/modules/ldap";
    
                    mkdir($cheminCustomMaarchCourrierModulesLdap, 0755);
    
                    $cheminCustomMaarchCourrierModulesLdapXml = realpath('.')."/custom/cs_$databasename/modules/ldap/xml";
                    mkdir($cheminCustomMaarchCourrierModulesLdapXml, 0755);
    
                    $cheminCustomMaarchCourrierModulesLdapScript = realpath('.')."/custom/cs_$databasename/modules/ldap/script";
                    mkdir($cheminCustomMaarchCourrierModulesLdapScript, 0755);
    
                    /** Création répertoire fulltext dans le custom **/
                    $cheminCustomMaarchCourrierModulesFullText = realpath('.')."/custom/cs_$databasename/modules/full_text";
    
                    mkdir($cheminCustomMaarchCourrierModulesFullText, 0755);
    
                    $cheminCustomMaarchCourrierModulesFullTextXml = realpath('.')."/custom/cs_$databasename/modules/full_text/xml";
                    mkdir($cheminCustomMaarchCourrierModulesFullTextXml, 0755);
    
                    $cheminCustomMaarchCourrierModulesFullTextScripts = realpath('.')."/custom/cs_$databasename/modules/full_text/scripts";
                    mkdir($cheminCustomMaarchCourrierModulesFullTextScripts, 0755);
                }
    
                if (is_dir(realpath('.')."/custom/cs_$databasename/modules/")) {
    
                    /* Création répertoire thumbnails dans le custom **/
    
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/thumbnails/")) {
                        $cheminCustomMaarchCourrierModulesThumbnails = realpath('.')."/custom/cs_$databasename/modules/thumbnails";
                        mkdir($cheminCustomMaarchCourrierModulesThumbnails, 0755);
                    }
    
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/thumbnails/xml/")) {
                        $cheminCustomMaarchCourrierModulesThumbnailsXml = realpath('.')."/custom/cs_$databasename/modules/thumbnails/xml";
                        mkdir($cheminCustomMaarchCourrierModulesThumbnailsXml, 0755);
                    }
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/thumbnails/scripts/")) {
                        $cheminCustomMaarchCourrierModulesThumbnailsScripts = realpath('.')."/custom/cs_$databasename/modules/thumbnails/scripts";
                        mkdir($cheminCustomMaarchCourrierModulesThumbnailsScripts, 0755);
                    }
    
                    /* Création répertoire thumbnails dans le custom **/
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/notifications/")) {
                        $cheminCustomMaarchCourrierModulesNotifications = realpath('.')."/custom/cs_$databasename/modules/notifications/";
                        mkdir($cheminCustomMaarchCourrierModulesNotifications, 0755);
                    }
    
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/notifications/batch/")) {
                        $cheminCustomMaarchCourrierModulesNotificationsBatch = realpath('.')."/custom/cs_$databasename/modules/notifications/batch";
                        mkdir($cheminCustomMaarchCourrierModulesNotificationsBatch, 0755);
                    }
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/notifications/batch/config/")) {
                        $cheminCustomMaarchCourrierModulesNotificationsConfig = realpath('.')."/custom/cs_$databasename/modules/notifications/batch/config";
                        mkdir($cheminCustomMaarchCourrierModulesNotificationsConfig, 0755);
                    }
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/notifications/batch/scripts/")) {
                        $cheminCustomMaarchCourrierModulesNotificationsScripts = realpath('.')."/custom/cs_$databasename/modules/notifications/batch/scripts";
                        mkdir($cheminCustomMaarchCourrierModulesNotificationsScripts, 0755);
                    }
    
                    /* Création répertoire thumbnails dans le custom **/
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/sendmail/")) {
                        $cheminCustomMaarchCourrierModulesSendmail = realpath('.')."/custom/cs_$databasename/modules/sendmail";
                        mkdir($cheminCustomMaarchCourrierModulesSendmail, 0755);
                    }
    
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/sendmail/batch/")) {
                        $cheminCustomMaarchCourrierModulesSendmailBatch = realpath('.')."/custom/cs_$databasename/modules/sendmail/batch";
                        mkdir($cheminCustomMaarchCourrierModulesSendmailBatch, 0755);
                    }
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/sendmail/batch/config/")) {
                        $cheminCustomMaarchCourrierModulesSendmailBatchConfig = realpath('.')."/custom/cs_$databasename/modules/sendmail/batch/config";
                        mkdir($cheminCustomMaarchCourrierModulesSendmailBatchConfig, 0755);
                    }
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/sendmail/batch/scripts/")) {
    
                        $cheminCustomMaarchCourrierModulesSendmailBatchScripts = realpath('.')."/custom/cs_$databasename/modules/sendmail/batch/scripts";
                        mkdir($cheminCustomMaarchCourrierModulesSendmailBatchScripts, 0755);
    
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/ldap/")) {
                        $cheminCustomMaarchCourrierModulesLdap = realpath('.')."/custom/cs_$databasename/modules/ldap";
                        mkdir($cheminCustomMaarchCourrierModulesLdap, 0755);
                    }
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/ldap/xml/")) {
                        $cheminCustomMaarchCourrierModulesLdapXml = realpath('.')."/custom/cs_$databasename/modules/ldap/xml";
                        mkdir($cheminCustomMaarchCourrierModulesLdapXml, 0755);
                    }
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/ldap/script/")) {
    
                        $cheminCustomMaarchCourrierModulesLdapScript = realpath('.')."/custom/cs_$databasename/modules/ldap/script";
                        mkdir($cheminCustomMaarchCourrierModulesLdapScript, 0755);
    
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/full_text/")) {
                        $cheminCustomMaarchCourrierModulesFullText = realpath('.')."/custom/cs_$databasename/modules/full_text";
                        mkdir($cheminCustomMaarchCourrierModulesFullText, 0755);
                    }
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/full_text/xml")) {
    
                        $cheminCustomMaarchCourrierModulesFullTextXml = realpath('.')."/custom/cs_$databasename/modules/full_text/xml";
                        mkdir($cheminCustomMaarchCourrierModulesFullTextXml, 0755);
    
                    }
                    if (!is_dir(realpath('.')."/custom/cs_$databasename/modules/full_text/scripts")) {
    
                        $cheminCustomMaarchCourrierModulesFullTextScripts = realpath('.')."/custom/cs_$databasename/modules/full_text/scripts";
                        mkdir($cheminCustomMaarchCourrierModulesFullTextScripts, 0755);
                    }
    
    
                //Création du lien symbolique sous linux
    
                if (strtoupper(substr(PHP_OS, 0, 3)) === 'LIN') {
    
                    $cmd = 'ln -s '.realpath('.')."/ cs_$databasename";
    
                    exec($cmd);
                }/*elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
                    $cmd = "mklink cs_$databasename ".realpath('.');
                    var_dump($cmd);
                    var_dump(exec($cmd));
                    exit;
                    exec($cmd);
    
                $chemin = realpath('.');
    
                if (strtoupper(substr(PHP_OS, 0, 3)) === 'LIN') {
    
                } elseif (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    
    
                if ($pos === false) {
                    //echo "Désolé, impossible de trouver ($needle) dans ($chemin)";
                } else {
                    // echo "Félicitations !\n";
                    // echo "Nous avons trouvé le dernier ($needle) dans ($chemin) à la position ($pos)";
                }
    
    
                $rest = substr($chemin, $pos + 1);    // contient le nom de l'appli (le nom du dossier où se situe l'appli)
                // var_dump($rest);
    
    
                // $cheminCustom = realpath('.')."/custom";
                // // var_dump($cheminCustom);
                // mkdir($cheminCustom, 0755);
                $filename = realpath('.').'/custom/custom.xml';
                //var_dump(file_exists($filename));
                if (file_exists($filename)) {
                    //var_dump('dans if');
    
                    $xmlCustom = simplexml_load_file(realpath('.').'/custom/custom.xml');
    
                    //$xmlCustom->addChild('custom');
                    $custom = $xmlCustom->addChild('custom');
    
                    $custom->addChild('custom_id', 'cs_'.$databasename);
                    $custom->addChild('ip');
                    $custom->addChild('external_domain');
                    $custom->addChild('domain');
                    if (strtoupper(substr(PHP_OS, 0, 3)) === 'LIN') {
    
                        $custom->addChild('path', 'cs_'.$databasename);
    
                    } elseif (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                        $custom->addChild('path', $rest);
                    }
    
                    $res = $xmlCustom->asXML();
    
                    $fp = @fopen(realpath('.').'/custom/custom.xml', 'w+');
    
                    if (!$fp) {
                        return false;
                        exit;
                    }
                    $write = fwrite($fp, $res);
                    if (!$write) {
                        return false;
                        exit;
                    }
    
                if (!file_exists($filename)) {
    
                    $manip2 = fopen(realpath('.').'/custom/custom.xml', 'w+');
    
                    $contenuXmlCustom = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
                    $contenuXmlCustom .= "<root>\n";
                    $contenuXmlCustom .= "\t<custom>\n";
                    $contenuXmlCustom .= "\t\t<custom_id>cs_".$databasename."</custom_id>\n";
                    $contenuXmlCustom .= "\t\t<ip></ip>\n";
                    $contenuXmlCustom .= "\t\t<external_domain></external_domain>\n";
                    $contenuXmlCustom .= "\t\t<domain></domain>\n";
                    if (strtoupper(substr(PHP_OS, 0, 3)) === 'LIN') {
                        $contenuXmlCustom .= "\t\t<path>cs_".$databasename."</path>\n";
                    } elseif (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                        $contenuXmlCustom .= "\t\t<path>$rest</path>\n";
                    }
                    $contenuXmlCustom .= "\t</custom>\n";
    
                    fputs($manip2, $contenuXmlCustom);
                    fclose($manip2);
    
                }
    
                $cheminCustomMaarchCourrier = realpath('.')."/custom/cs_$databasename";
    
    
                if (!@mkdir($cheminCustomMaarchCourrier, 0755)) {
                    return false;
                }
    
                /**
                Création répertoire apps/maarch_entreprise dans le custom
    
                $cheminCustomMaarchCourrierApps = realpath('.')."/custom/cs_$databasename/apps";
                mkdir($cheminCustomMaarchCourrierApps, 0755);
    
                $cheminCustomMaarchCourrierAppsMaarchEntreprise = realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise";
                mkdir($cheminCustomMaarchCourrierAppsMaarchEntreprise, 0755);
    
                $cheminCustomMaarchCourrierAppsMaarchEntrepriseXml = realpath('.')."/custom/cs_$databasename/apps/maarch_entreprise/xml";
                mkdir($cheminCustomMaarchCourrierAppsMaarchEntrepriseXml, 0755);
    
    
                /**
                Création répertoire modules dans le custom
    
                $cheminCustomMaarchCourrierModules = realpath('.')."/custom/cs_$databasename/modules";
                mkdir($cheminCustomMaarchCourrierModules, 0755);
    
                /** Création répertoire thumbnails dans le custom **/
                $cheminCustomMaarchCourrierModulesThumbnails = realpath('.')."/custom/cs_$databasename/modules/thumbnails";
                mkdir($cheminCustomMaarchCourrierModulesThumbnails, 0755);
    
                $cheminCustomMaarchCourrierModulesThumbnailsXml = realpath('.')."/custom/cs_$databasename/modules/thumbnails/xml";
                mkdir($cheminCustomMaarchCourrierModulesThumbnailsXml, 0755);
    
                $cheminCustomMaarchCourrierModulesThumbnailsScripts = realpath('.')."/custom/cs_$databasename/modules/thumbnails/scripts";
                mkdir($cheminCustomMaarchCourrierModulesThumbnailsScripts, 0755);
    
    
                /** Création répertoire notification dans le custom **/
    
                $cheminCustomMaarchCourrierModulesNotifications = realpath('.')."/custom/cs_$databasename/modules/notifications";
                mkdir($cheminCustomMaarchCourrierModulesNotifications, 0755);
    
                $cheminCustomMaarchCourrierModulesNotificationsBatch = realpath('.')."/custom/cs_$databasename/modules/notifications/batch";
                mkdir($cheminCustomMaarchCourrierModulesNotificationsBatch, 0755);
    
                $cheminCustomMaarchCourrierModulesNotificationsConfig = realpath('.')."/custom/cs_$databasename/modules/notifications/batch/config";
                mkdir($cheminCustomMaarchCourrierModulesNotificationsConfig, 0755);
    
                $cheminCustomMaarchCourrierModulesNotificationsScripts = realpath('.')."/custom/cs_$databasename/modules/notifications/batch/scripts";
                mkdir($cheminCustomMaarchCourrierModulesNotificationsScripts, 0755);
    
                /** Création répertoire sendmail dans le custom **/
                $cheminCustomMaarchCourrierModulesSendmail = realpath('.')."/custom/cs_$databasename/modules/sendmail";
                mkdir($cheminCustomMaarchCourrierModulesSendmail, 0755);
    
                $cheminCustomMaarchCourrierModulesSendmailBatch = realpath('.')."/custom/cs_$databasename/modules/sendmail/batch";
                mkdir($cheminCustomMaarchCourrierModulesSendmailBatch, 0755);
    
                $cheminCustomMaarchCourrierModulesSendmailBatchConfig = realpath('.')."/custom/cs_$databasename/modules/sendmail/batch/config";
                mkdir($cheminCustomMaarchCourrierModulesSendmailBatchConfig, 0755);
    
                $cheminCustomMaarchCourrierModulesSendmailBatchScripts = realpath('.')."/custom/cs_$databasename/modules/sendmail/batch/scripts";
                mkdir($cheminCustomMaarchCourrierModulesSendmailBatchScripts, 0755);
    
                /** Création répertoire LDAP dans le custom **/
                $cheminCustomMaarchCourrierModulesLdap = realpath('.')."/custom/cs_$databasename/modules/ldap";
                mkdir($cheminCustomMaarchCourrierModulesLdap, 0755);
    
                $cheminCustomMaarchCourrierModulesLdapXml = realpath('.')."/custom/cs_$databasename/modules/ldap/xml";
                mkdir($cheminCustomMaarchCourrierModulesLdapXml, 0755);
    
                $cheminCustomMaarchCourrierModulesLdapScript = realpath('.')."/custom/cs_$databasename/modules/ldap/script";
                mkdir($cheminCustomMaarchCourrierModulesLdapScript, 0755);
    
                /** Création répertoire fulltext dans le custom **/
                $cheminCustomMaarchCourrierModulesFullText = realpath('.')."/custom/cs_$databasename/modules/full_text";
                mkdir($cheminCustomMaarchCourrierModulesFullText, 0755);
    
                $cheminCustomMaarchCourrierModulesFullTextXml = realpath('.')."/custom/cs_$databasename/modules/full_text/xml";
                mkdir($cheminCustomMaarchCourrierModulesFullTextXml, 0755);
    
                $cheminCustomMaarchCourrierModulesFullTextScripts = realpath('.')."/custom/cs_$databasename/modules/full_text/scripts";
                mkdir($cheminCustomMaarchCourrierModulesFullTextScripts, 0755);
                // exit;
    
                //Création du lien symbolique sous linux
                if (strtoupper(substr(PHP_OS, 0, 3)) === 'LIN') {
    
                    $cmd = 'ln -s '.realpath('.')."/ cs_$databasename";
    
                    exec($cmd);
                }/*elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
                    $cmd = "mklink cs_$databasename ".realpath('.');
    
                    var_dump($cmd);
                    var_dump(exec($cmd));
                    exit;
    
                }*/
                // Création du lien symbolique sous windows mais il faut être en administrateur pour lancer la commande : mklink nomDuCustom cheminDeLAPPLI
    
        }
    
        public function updateDocserverForXml($docserverPath)
        {
    
            $xmlconfig = simplexml_load_file(realpath('.').'/custom/cs_'.$_SESSION['config']['databasename'].'/apps/maarch_entreprise/xml/config.xml');
    
            //$xmlconfig = 'apps/maarch_entreprise/xml/config.xml.default';
    
            $COLLECTION_1 = $xmlconfig->COLLECTION[0];
    
            $COLLECTION_1->path_to_lucene_index = $docserverPath.'/indexes/letterbox_coll/';
    
            $COLLECTION_2 = $xmlconfig->COLLECTION[1];
    
            $COLLECTION_2->path_to_lucene_index = $docserverPath.'/indexes/attachments_coll/';
    
    
            $COLLECTION_3 = $xmlconfig->COLLECTION[2];
    
            $COLLECTION_3->path_to_lucene_index = $docserverPath.'/indexes/version_attachments_coll/';
    
            $res = $xmlconfig->asXML();
            // $fp = @fopen("apps/maarch_entreprise/xml/config.xml", "w+");
    
            $fp = @fopen(realpath('.').'/custom/cs_'.$_SESSION['config']['databasename'].'/apps/maarch_entreprise/xml/config.xml', 'w+');
    
            if (!$fp) {
                return false;
                exit;
            }
    
            $write = fwrite($fp, $res);
    
            if (!$write) {
                return false;
                exit;
            }
    
            //configuration du chemin dans config_batch_letterbox.xml
    
            $xmlconfig2 = simplexml_load_file(realpath('.').'/custom/cs_'.$_SESSION['config']['databasename'].'/modules/full_text/xml/config_batch_letterbox.xml');
    
            //$xmlconfig = 'apps/maarch_entreprise/xml/config.xml.default';
            $CONFIG = $xmlconfig2->CONFIG;
    
    
            $CONFIG->INDEX_FILE_DIRECTORY = $docserverPath.'/indexes/letterbox_coll/';
    
            $res = $xmlconfig2->asXML();
            // $fp = @fopen("apps/maarch_entreprise/xml/config.xml", "w+");
    
            $fp = @fopen(realpath('.').'/custom/cs_'.$_SESSION['config']['databasename'].'/modules/full_text/xml/config_batch_letterbox.xml', 'w+');
    
            if (!$fp) {
                return false;
                exit;
            }
    
            $write = fwrite($fp, $res);
    
            if (!$write) {
                return false;
                exit;
            }
    
    
            //configuration du chemin dans config_batch_attachments.xml
    
            $xmlconfig3 = simplexml_load_file(realpath('.').'/custom/cs_'.$_SESSION['config']['databasename'].'/modules/full_text/xml/config_batch_attachments.xml');
    
            //$xmlconfig = 'apps/maarch_entreprise/xml/config.xml.default';
            $CONFIG = $xmlconfig3->CONFIG;
    
    
            $CONFIG->INDEX_FILE_DIRECTORY = $docserverPath.'/indexes/attachments_coll/';
    
            $res = $xmlconfig3->asXML();
            // $fp = @fopen("apps/maarch_entreprise/xml/config.xml", "w+");
    
            $fp = @fopen(realpath('.').'/custom/cs_'.$_SESSION['config']['databasename'].'/modules/full_text/xml/config_batch_attachments.xml', 'w+');
    
            $write = fwrite($fp, $res);
    
            if (!$write) {
                return false;
                exit;
            }
    
            //configuration du chemin dans config_batch_version_attachments.xml
    
            $xmlconfig4 = simplexml_load_file(realpath('.').'/custom/cs_'.$_SESSION['config']['databasename'].'/modules/full_text/xml/config_batch_version_attachments.xml');
    
            //$xmlconfig = 'apps/maarch_entreprise/xml/config.xml.default';
            $CONFIG = $xmlconfig4->CONFIG;
    
    
            $CONFIG->INDEX_FILE_DIRECTORY = $docserverPath.'/indexes/version_attachments_coll/';
    
            $res = $xmlconfig4->asXML();
            // $fp = @fopen("apps/maarch_entreprise/xml/config.xml", "w+");
    
            $fp = @fopen(realpath('.').'/custom/cs_'.$_SESSION['config']['databasename'].'/modules/full_text/xml/config_batch_version_attachments.xml', 'w+');
    
            $write = fwrite($fp, $res);
    
        public function verificationDatabase($databasename)
        {
    
            $connect = 'host='.$_SESSION['config']['databaseserver'].' ';
            $connect .= 'port='.$_SESSION['config']['databaseserverport'].' ';
            $connect .= 'user='.$_SESSION['config']['databaseuser'].' ';
            $connect .= 'password='.$_SESSION['config']['databasepassword'].' ';
    
            $connect .= 'dbname=postgres';
    
            //var_dump($connect);
    
            if (!@pg_connect($connect)) {
                return false;
                exit;
    
    
            $sqlCreateDatabase = "select datname from pg_database where datname = '".$databasename."'";
    
    
            $result = @pg_query($sqlCreateDatabase);
            if (!$result) {
    
                echo "Une erreur s'est produite.\n";
                exit;
    
            }
    
            while ($row = pg_fetch_row($result)) {
    
                //echo "datname: $row[0] ";
    
        public function verifCustom($databasename)
        {
            $customAlreadyExist = realpath('.').'/custom/cs_'.$databasename;
            if (file_exists($customAlreadyExist)) {
    
                return false;
    
        public function fillConfigOfAppAndModule($databasename)
        {
    
            $_SESSION['config']['databasename'] = $databasename;
    
            $connect = 'host='.$_SESSION['config']['databaseserver'].' ';
            $connect .= 'port='.$_SESSION['config']['databaseserverport'].' ';
            $connect .= 'user='.$_SESSION['config']['databaseuser'].' ';
            $connect .= 'password='.$_SESSION['config']['databasepassword'].' ';
    
            $connect .= 'dbname=postgres';
    
            if (!$this->setConfigXmlThumbnails()) {
                return false;
                exit;
            }
            if (!$this->setConfig_batch_XmlThumbnails()) {
                return false;
                exit;
    
            if (!$this->setConfigScriptLaunchThumbnails()) {
                return false;
                exit;
            }
            if (!$this->setConfig_sendmail()) {
                return false;
                exit;
            }
    
    
            if (!$this->setConfigXml()) {
    
            // if (!$this->setConfigXmlVisa()) {
            //     return false;
            //     exit;
            // }
    
    
            if (!$this->setScriptNotificationSendmailSh()) {
                return false;
                exit;
            }
    
            if (!$this->setScriptNotificationNctNccAndAncSh()) {
                return false;
                exit;
            }
    
            if (!$this->setScriptSendmailSendmailSh()) {
                return false;
                exit;
            }
    
            if (!$this->setConfig_LDAP()) {
                return false;
                exit;
            }
    
            if (!$this->setScript_syn_LDAP_sh()) {
                return false;
                exit;
            }
    
            if (!$this->setConfig_fulltext()) {
                return false;
                exit;
            }
    
            if (!$this->setScript_full_text()) {
                return false;
                exit;
            }
    
            if (!$this->setConfig_batch_XmlNotifications()) {
                return false;
                exit;
            }
    
            if (!$this->setConfig_batch_XmlSendmail()) {
                return false;
                exit;
            }
    
    
            if (!$this->setConfigCron()) {
                return false;
                exit;
            }
    
            if (!$this->setRight()) {
                return false;
                exit;
            }
    
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        public function createDatabase(
            $databasename
    
            $connect = 'host='.$_SESSION['config']['databaseserver'].' ';
            $connect .= 'port='.$_SESSION['config']['databaseserverport'].' ';
            $connect .= 'user='.$_SESSION['config']['databaseuser'].' ';
            $connect .= 'password='.$_SESSION['config']['databasepassword'].' ';
    
            $connect .= 'dbname=postgres';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if (!@pg_connect($connect)) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                return false;
                exit;
            }
    
    
            $sqlCreateDatabase = 'CREATE DATABASE "'.$databasename.'"';
            $sqlCreateDatabase .= ' WITH TEMPLATE template0';
    
            $sqlCreateDatabase .= " ENCODING = 'UTF8'";
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    
    
            $execute = pg_query($sqlCreateDatabase);
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if (!$execute) {
                return false;
                exit;
            }
    
            @pg_query('ALTER DATABASE "'.$databasename.'" SET DateStyle =iso, dmy');
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            pg_close();
    
    
            $db = new Database();
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if (!$db) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                return false;
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                exit;
    
            if (!$this->executeSQLScript('sql/structure.sql')) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                return false;
                exit;
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    
    
            if (!$this->setConfigXmlThumbnails()) {
                return false;
                exit;
            }
            if (!$this->setConfig_batch_XmlThumbnails()) {
                return false;
                exit;
    
            if (!$this->setConfigScriptLaunchThumbnails()) {
                return false;
                exit;
            }
            if (!$this->setConfig_sendmail()) {
                return false;
                exit;
            }
    
    
            if (!$this->setConfigXml()) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                return false;
                exit;
            }
    
            // if (!$this->setConfigXmlVisa()) {
            //     return false;
            //     exit;
            // }
    
    
            if (!$this->setScriptNotificationSendmailSh()) {
                return false;
                exit;
            }
    
            if (!$this->setScriptNotificationNctNccAndAncSh()) {
                return false;
                exit;
            }
    
            if (!$this->setScriptSendmailSendmailSh()) {
                return false;
                exit;
            }
    
            if (!$this->setConfig_LDAP()) {
                return false;
                exit;
            }
    
            if (!$this->setScript_syn_LDAP_sh()) {
                return false;
                exit;
            }
    
    
            if (!$this->setConfig_fulltext()) {
                return false;
                exit;
            }
    
            if (!$this->setScript_full_text()) {
                return false;
                exit;
            }
    
            if (!$this->setConfig_batch_XmlNotifications()) {
                return false;
                exit;
            }
    
            if (!$this->setConfig_batch_XmlSendmail()) {
                return false;
                exit;
            }
    
    
            if (!$this->setLog4php()) {
                return false;
                exit;
            }
    
            if (!$this->setConfigCron()) {
                return false;
                exit;
            }
    
            if (!$this->setRight()) {
                return false;
                exit;
            }