123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <?php
- session_name ('erp-core');
- session_start();
- //Activation du ssl a travers un reverse proxy
- if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) $_SERVER['HTTPS'] = 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ? 'on' : 'off';
- $start_time = microtime(TRUE);
- mb_internal_encoding('UTF-8');
- if(!file_exists(__DIR__.DIRECTORY_SEPARATOR.'constant.php'))
- header('location:install.php');
- require_once(__DIR__.DIRECTORY_SEPARATOR.'constant.php');
- require_once(__ROOT__.'function.php');
- date_default_timezone_set(TIME_ZONE);
- //set_error_handler('errorToException');
- set_exception_handler('unhandledException');
- spl_autoload_register('app_autoloader');
- global $myUser,$conf,$_,$success,$myFirm;
- $_ = array_map('secure_user_vars', array_merge($_POST, $_GET));
- $page = isset($_SERVER['REQUEST_URI'])? basename($_SERVER['REQUEST_URI']):'';
- $myUser = isset($_SESSION['currentUser']) ? unserialize($_SESSION['currentUser']) : new User();
- $myFirm = isset($_SESSION['firm']) ? unserialize($_SESSION['firm']): new Firm();
- $conf = new Configuration();
- $conf->getAll();
- //CONFS GÉNÉRALES
- Configuration::setting('configuration-global',array(
- "Gestion des configurations générales :",
- 'home_page' => array("label"=>"Page d'accueil","type"=>"text","legend"=>"Laisser vide pour gérer en automatique","placeholder"=>"eg : index.php?module=example"),
- 'logo_website_header' => array("label"=>"Site web cible au clic sur le logo","type"=>"text","legend"=>"Dans le menu de navigation, laisser vide pour pointer vers l'Accueil du projet", "placeholder"=>"eg : https://example.com"),
- 'show_application_name' => array("label"=>"Afficher le nom du programme","type"=>"checkbox","legend"=>"Dans le menu de navigation"),
- 'show_application_name_footer' => array("label"=>"Afficher le nom du programme", "legend"=>"Dans le pied de page", "type"=>"checkbox"),
- 'show_application_author_footer' => array("label"=>"Afficher le nom de l'éditeur", "legend"=>"Dans le pied de page", "type"=>"checkbox"),
- 'application_author_website_footer' => array("label"=>"Lien vers le site de l'éditeur", "legend"=>"Dans le pied de page, laisser vide pour ne rien afficher", "type"=>"text", "placeholder"=>"eg : https://example.com"),
- 'show_application_documentation_footer' => array("label"=>"Lien vers la documentation utilisateur", "legend"=>"Dans le pied de page, laisser vide pour ne rien afficher", "type"=>"text"),
- 'show_process_time_footer' => array("label"=>"Afficher le temps de traitement", "legend"=>"Dans le pied de page", "type"=>"checkbox"),
- 'hide_header_login' => array("label"=>"Masquer le formulaire de connexion dans le header","type"=>"checkbox","legend"=>"(Barre de menu en haut à droite)","placeholder"=>"6"),
- "Gestion des clés API du composant <code>location</code> :",
- 'maps_api_suggest_url' => array("label"=>"URL de l'API de Suggestion","type"=>"text","legend"=>"URL de l'API à attaquer pour autocomplétion des adresses","placeholder"=>"eg. http://autocomplete.suggest.api.example.com/..."),
- 'maps_api_geocode_url' => array("label"=>"URL de l'API Geocoder","type"=>"text","legend"=>"URL de l'API à attaquer pour récupérer les détails d'une localisation","placeholder"=>"eg. http://autocomplete.geocoder.api.example.com/..."),
- 'maps_api_id' => array("label"=>"ID de l'application","type"=>"text","legend"=>"Identifiant de l'application API pour le composant location","placeholder"=>"eg. pl0749TULNDW..."),
- 'maps_api_key' => array("label"=>"Clé publique de l'application","type"=>"password","legend"=>"Code / Clé de l'application API pour le composant location","placeholder"=>"eg. db678804676..."),
- 'google_maps_api_key' => array("label"=>"Google Maps API","type"=>"text","legend"=>"Clé API de la console Google Cloud Platform","placeholder"=>"eg. AIzaSyAcnOX3qYl-Fzq..."),
- "Authentification :",
- 'account_block' => array("label"=>"Activer le blocage de compte au bout de N essais","legend"=>"Tous les utilisateurs seront soumis à la règle","type"=>"checkbox"),
- 'account_block_try' => array("label"=>"Nombre d'essais avant blocage du compte","legend"=>"L'utilisateur aura N tentatives pour se connecter avant d'être bloqué","type"=>"number", "placeholder"=>"eg. 10"),
- 'account_block_delay' => array("label"=>"Durée de blocage", "legend"=>"(en minutes)", "type"=>"number", "placeholder"=>"eg. 30"),
- "Identifiant :",
- 'login_forbidden_char' => array("label"=>"Caractères interdits","type"=>"text","legend"=>"<small class='text-danger'> La virgule ','' est par défaut interdite pour tout identifiant</small>","placeholder"=>"eg. <>&!?"),
- 'Mots de passe : <div class="btn btn-warning btn-small float-right" onclick="general_reset_password_delay()"><i class="fas fa-exclamation-triangle"></i> Forcer le renouvellement</div>',
- 'password_forbidden_char' => array("label"=>"Caractères interdits","type"=>"text","legend"=>"<small class='text-danger'> Aucun caractère n'est par défaut interdit</small>","placeholder"=>"eg. <>&!?"),
- 'password_delay'=>array("label"=>"Renouvellement", "legend"=>"Forcer l'utilisateur a renouveller son mot de passe tous les X jours (laisser vide pour désactiver)", "type"=>"number", "placeholder"=>"eg. 30"),
- 'password_allow_lost'=>array("label"=>"Oubli de mot de passe", "legend"=>"Proposer la récuperation du mot de passe oublié", "type"=>"checkbox"),
- "Connectivité :",
- 'offline_mode' => array("label"=>"Activer le mode hors ligne","legend"=>"(Désactive toutes les fonctionnalités ayant besoin d'un accès internet depuis le poste client cdn...)","type"=>"checkbox"),
- ));
- //CACHE CSS & JS
- $cacheVersion = SOURCE_VERSION;
- if(file_exists(__DIR__.SLASH.'.git'.SLASH.'HEAD')){
- $versionFile = str_replace(array('ref: ',PHP_EOL,"\r","\n"),'',file_get_contents(__DIR__.SLASH.'.git'.SLASH.'HEAD'));
- if(file_exists(__DIR__.SLASH.'.git'.SLASH.$versionFile)){
- $cacheVersion = str_replace(array("\r","\n"),'',file_get_contents(__DIR__.SLASH.'.git'.SLASH.$versionFile));
- }
- }
- if($myUser->login==null && isset($_COOKIE[COOKIE_NAME])){
- $cookie = UserPreference::load(array('key'=>'cookie','value'=>$_COOKIE[COOKIE_NAME]));
- if($cookie!=false){
- if(Plugin::is_active('fr.sys1.activedirectory'))
- require_once(PLUGIN_PATH.'activedirectory'.SLASH.'activedirectory.plugin.php');
-
- $myUser = User::byLogin($cookie->user);
- if(empty($myUser->origin)){
- $myUser->ranks = array();
- $myUser->firms = array();
- $myUser->loadRanks();
- $myUser->loadPreferences();
- }
- if($myUser->superadmin == 1){
- foreach(Firm::loadAll() as $firm)
- $firms[$firm->id] = $firm;
- $myUser->setFirms($firms);
- }
-
- $defaultFirm = !empty($myUser->preference('default_firm')) ? $myUser->preferences['default_firm'] : key($myUser->firms);
- $myFirm = isset($myUser->firms[$defaultFirm]) ? $myUser->firms[$defaultFirm]:key($myUser->firms);
- $myUser->loadRights();
-
- $_SESSION['currentUser'] = serialize($myUser);
- $_SESSION['firm'] = serialize($myFirm);
- }
- }
- $myFirm = isset($_SESSION['firm']) ? unserialize($_SESSION['firm']) : new Firm();
- //MENUS
- Plugin::addHook("menu_account", function(&$accountMenu){
- global $myUser;
- if(!$myUser->connected()) throw new Exception('Vous devez être connecté pour accéder à cette fonctionnalité');
- $accountMenu[]= array(
- 'sort' =>0,
- 'url' => 'account.php?section=global',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Général',
- );
- });
- Plugin::addHook("menu_setting", function(&$settingMenu){
- global $myUser;
- $settingMenu[]= array(
- 'sort' =>0,
- 'url' => 'setting.php?section=global',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Général',
- );
-
- if($myUser->can('plugin','configure'))
- $settingMenu[]= array(
- 'sort' =>18,
- 'url' => 'setting.php?section=plugin',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Plugins',
- 'category' => 'administration'
- );
- if($myUser->can('user','configure'))
- $settingMenu[]= array(
- 'sort' =>20,
- 'url' => 'setting.php?section=user',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Utilisateurs',
- 'category' => 'administration'
- );
- if($myUser->can('rank','configure'))
- $settingMenu[]= array(
- 'sort' =>21,
- 'url' => 'setting.php?section=rank',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Rangs & Accès',
- 'category' => 'administration'
- );
- if($myUser->can('firm','configure'))
- $settingMenu[]= array(
- 'sort' =>22,
- 'url' => 'setting.php?section=firm',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Établissements',
- 'category' => 'administration'
- );
- if($myUser->can('user','configure'))
- $settingMenu[]= array(
- 'sort' =>23,
- 'url' => 'setting.php?section=userfirmrank',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Établissement / Utilisateur / Rang',
- 'category' => 'administration'
- );
- if($myUser->can('plugin','configure'))
- $settingMenu[]= array(
- 'sort' =>24,
- 'url' => 'setting.php?section=firmPlugin',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Établissement / Plugins',
- 'category' => 'administration'
- );
- if($myUser->can('dictionnary','configure'))
- $settingMenu[]= array(
- 'sort' =>20,
- 'url' => 'setting.php?section=dictionnary',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Listes de valeur'
- );
- if($myUser->can('log','read'))
- $settingMenu[]= array(
- 'sort' =>16,
- 'url' => 'setting.php?section=log',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Logs',
- 'category' => 'administration'
- );
-
- if($myUser->login!='')
- $settingMenu[]= array(
- 'sort' =>16,
- 'url' => 'setting.php?section=update',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Mises à jour',
- 'category' => 'administration'
- );
- });
- Plugin::addHook("menu_main", function(&$mainMenu) {
- global $myUser;
-
- if(!$myUser->connected()) return;
- $mainMenu[] = array(
- 'sort' =>0,
- 'icon' => 'fas fa-fw fa-home',
- 'label' => 'Accueil',
- 'url' => 'index.php',
- 'color' => '#383838'
- );
- $settingMenu = array();
- Plugin::callHook("menu_setting", array(&$settingMenu));
- });
- Plugin::addHook("menu_user", function(&$userMenu){
- global $myUser,$myFirm;
- $rankLabels = array();
- if($myUser->superadmin){
- $rankLabels[] = 'Super Admin';
- } else {
- if(isset($myUser->ranks[$myFirm->id])){
- foreach($myUser->ranks[$myFirm->id] as $rank){
- $rankLabels[] = $rank->label;
- }
- }
- }
- $ranksHtml = count($rankLabels)!=0 ? '<div class="firm-ranks mt-1"><ul><li>'.implode('</li><li>',$rankLabels).'</li></ul></div>' : '';
- $userMenu[]= array(
- 'sort' => -2,
- 'custom' => "<div class='firm-item' onclick='event.stopPropagation();'><small>Rang : ".$ranksHtml."</small></div><div class='dropdown-divider'></div>",
- );
- if(count($myUser->firms)>1){
- $userIcon = 'far fa-fw fa-user';
- $options = '';
- foreach ($myUser->firms as $firm)
- $options .= '<option '.($myFirm->id == $firm->id ? "selected='selected'":"").' value="'.$firm->id.'">'.$firm->label.'</option>';
-
- $userMenu[]= array(
- 'sort' => 1,
- 'custom' => "<div class='firm-item mt-2' onclick='event.stopPropagation();'><small class='mb-1'>Établissement : </small><select class=\"form-control form-control-sm\" onchange=\"window.location='action.php?action=select_firm&firm='+$(this).val();\">".$options."</select></div><div class='dropdown-divider'></div>",
- );
- } else {
- $userIcon = 'fas fa-fw fa-user';
- $userMenu[]= array(
- 'sort' => -1,
- 'custom' => "<div class='firm-item' onclick='event.stopPropagation();'><small>Établissement : ".$myFirm->label."</small></div><div class='dropdown-divider'></div>",
- );
- }
- if($myUser->can('account','read'))
- $userMenu[]= array(
- 'sort' => 0,
- 'label' => 'Mon compte',
- 'icon' => $userIcon,
- 'url' => 'account.php'
- );
- if($myUser->can('setting_global', 'read'))
- $userMenu[]= array(
- 'sort' => 1,
- 'icon' => 'fas fa-fw fa-cog',
- 'label' => 'Réglages',
- 'url' => 'setting.php'
- );
- $userMenu[]= array(
- 'sort' => 100,
- 'icon' => 'fas fa-fw fa-sign-out-alt',
- 'label' => 'Déconnexion',
- 'url' => 'action.php?action=logout'
- );
- });
- Plugin::addHook("content_setting", function(){
- global $_;
- $_['section'] = !isset($_['section']) ? 'global': $_['section'];
- if(in_array($_['section'],array('global','plugin','rank','right','user','firm','userfirmrank','firmPlugin','log','dictionnary','update')) && file_exists('setting.'.$_['section'].'.php'))
- require_once('setting.'.$_['section'].'.php');
- });
- Plugin::addHook("content_account", function(){
- global $_;
- $_['section'] = !isset($_['section']) ? 'global': $_['section'];
- if(in_array($_['section'],array('global')) && file_exists('account.'.$_['section'].'.php'))
- require_once('account.'.$_['section'].'.php');
- });
- Plugin::addHook("section",function(&$sections){
- $sections['setting_global'] = 'Gestion des parametres globaux';
- $sections['user'] = 'Gestion des utilisateurs';
- $sections['firm'] = 'Gestion des établissements';
- $sections['plugin'] = 'Gestion des plugins';
- $sections['rank'] = 'Gestion des rangs et droits';
- $sections['log'] = 'Gestion des logs programme';
- $sections['dictionnary'] = 'Gestion des listes programme';
- $sections['file'] = 'Gestion des fichiers';
- $sections['account'] = 'Gestion du compte courant';
- });
- Plugin::addHook("cron",function(){
- if(date('H:i')!='01:00') return;
- //Clear automatique des logs
- global $conf;
- foreach(Log::staticQuery('SELECT DISTINCT category FROM {{table}}',array(),true) as $log):
- $slug = slugify($log->category);
- $key = 'log_retention_time_'.$slug;
- if($conf->get($key)=='') continue;
- Log::clear($conf->get($key));
- endforeach;
- });
- Plugin::includeAll();
- ?>
|