common.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. session_name ('erp-core');
  3. session_start();
  4. $start_time = microtime(TRUE);
  5. mb_internal_encoding('UTF-8');
  6. if(!file_exists(__DIR__.DIRECTORY_SEPARATOR.'constant.php'))
  7. header('location:install.php');
  8. require_once(__DIR__.DIRECTORY_SEPARATOR.'constant.php');
  9. require_once(__ROOT__.'function.php');
  10. date_default_timezone_set(TIME_ZONE);
  11. //set_error_handler('errorToException');
  12. set_exception_handler('unhandledException');
  13. spl_autoload_register('app_autoloader');
  14. global $myUser,$conf,$_,$success,$myFirm;
  15. $_ = array_map('secure_user_vars', array_merge($_POST, $_GET));
  16. $page = isset($_SERVER['REQUEST_URI'])? basename($_SERVER['REQUEST_URI']):'';
  17. $myUser = isset($_SESSION['currentUser']) ? unserialize($_SESSION['currentUser']) : new User();
  18. $myFirm = isset($_SESSION['firm']) ? unserialize($_SESSION['firm']): new Firm();
  19. $conf = new Configuration();
  20. $conf->getAll();
  21. //CONFS GÉNÉRALES
  22. Configuration::setting('configuration-global',array(
  23. "Général :",
  24. 'home_page' => array("label"=>"Page d'accueil","type"=>"text","legend"=>"Laisser vide pour gérer en automatique","placeholder"=>"eg : index.php?module=example"),
  25. 'show_application_name' => array("label"=>"Afficher le nom du programme", "legend"=>"Dans la barre de navigation / menu uniquement", "type"=>"checkbox"),
  26. "Gestion des clés Map Algolia API :",
  27. 'maps_api_id' => array("label"=>"ID de l'application","type"=>"text","legend"=>"Clé API pour le composant location","placeholder"=>"eg. pl0749TULNDW..."),
  28. 'maps_api_key' => array("label"=>"Clé publique de l'application","type"=>"password","legend"=>"Clé API pour le composant location","placeholder"=>"eg. db6788b1e4165d3370ed88a304704676..."),
  29. "Authentification :",
  30. '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"),
  31. '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"),
  32. 'account_block_delay' => array("label"=>"Durée de blocage", "legend"=>"(en minutes)", "type"=>"number", "placeholder"=>"eg. 30"),
  33. '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>',
  34. '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"),
  35. 'password_allow_lost'=>array("label"=>"Oubli de mot de passe", "legend"=>"Proposer la récuperation du mot de passe oublié", "type"=>"checkbox"),
  36. "Connectivité :",
  37. '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"),
  38. ));
  39. //CACHE CSS & JS
  40. $cacheVersion = 1;
  41. if(file_exists(__DIR__.SLASH.'.git'.SLASH.'HEAD')){
  42. $versionFile = str_replace(array('ref: ',PHP_EOL,"\r","\n"),'',file_get_contents(__DIR__.SLASH.'.git'.SLASH.'HEAD'));
  43. if(file_exists(__DIR__.SLASH.'.git'.SLASH.$versionFile)){
  44. $cacheVersion = str_replace(array("\r","\n"),'',file_get_contents(__DIR__.SLASH.'.git'.SLASH.$versionFile));
  45. }
  46. }
  47. if($myUser->login==null && isset($_COOKIE[COOKIE_NAME])){
  48. $cookie = UserPreference::load(array('key'=>'cookie','value'=>$_COOKIE[COOKIE_NAME]));
  49. if($cookie!=false){
  50. if(Plugin::is_active('fr.sys1.activedirectory'))
  51. require_once(PLUGIN_PATH.'activedirectory'.SLASH.'activedirectory.plugin.php');
  52. $myUser = User::byLogin($cookie->user);
  53. if($myUser->origin != 'active_directory'){
  54. $myUser->ranks = array();
  55. $myUser->firms = array();
  56. $myUser->loadRanks();
  57. $myUser->loadPreferences();
  58. }
  59. $defaultFirm = !empty($myUser->preference('default_firm')) ? $myUser->preferences['default_firm'] : key($myUser->firms);
  60. $myFirm = isset($myUser->firms[$defaultFirm]) ? $myUser->firms[$defaultFirm]:key($myUser->firms);
  61. $_SESSION['currentUser'] = serialize($myUser);
  62. $_SESSION['firm'] = serialize($myFirm);
  63. }
  64. }
  65. $myFirm = isset($_SESSION['firm']) ? unserialize($_SESSION['firm']): new Firm();
  66. //MENUS
  67. Plugin::addHook("menu_account", function(&$accountMenu){
  68. global $myUser;
  69. if(!$myUser->connected()) throw new Exception('Vous devez être connecté pour accéder à cette fonctionnalité');
  70. $accountMenu[]= array(
  71. 'sort' =>0,
  72. 'url' => 'account.php?section=global',
  73. 'icon' => 'fas fa-angle-right',
  74. 'label' => 'Général',
  75. );
  76. });
  77. Plugin::addHook("menu_setting", function(&$settingMenu){
  78. global $myUser;
  79. $settingMenu[]= array(
  80. 'sort' =>0,
  81. 'url' => 'setting.php?section=global',
  82. 'icon' => 'fas fa-angle-right',
  83. 'label' => 'Général',
  84. );
  85. if($myUser->can('plugin','configure'))
  86. $settingMenu[]= array(
  87. 'sort' =>18,
  88. 'url' => 'setting.php?section=plugin',
  89. 'icon' => 'fas fa-angle-right',
  90. 'label' => 'Plugins',
  91. 'category' => 'administration'
  92. );
  93. if($myUser->can('user','configure'))
  94. $settingMenu[]= array(
  95. 'sort' =>20,
  96. 'url' => 'setting.php?section=user',
  97. 'icon' => 'fas fa-angle-right',
  98. 'label' => 'Utilisateurs',
  99. 'category' => 'administration'
  100. );
  101. if($myUser->can('rank','configure'))
  102. $settingMenu[]= array(
  103. 'sort' =>21,
  104. 'url' => 'setting.php?section=rank',
  105. 'icon' => 'fas fa-angle-right',
  106. 'label' => 'Rangs & Accès',
  107. 'category' => 'administration'
  108. );
  109. if($myUser->can('firm','configure'))
  110. $settingMenu[]= array(
  111. 'sort' =>22,
  112. 'url' => 'setting.php?section=firm',
  113. 'icon' => 'fas fa-angle-right',
  114. 'label' => 'Établissements',
  115. 'category' => 'administration'
  116. );
  117. if($myUser->can('user','configure'))
  118. $settingMenu[]= array(
  119. 'sort' =>23,
  120. 'url' => 'setting.php?section=userfirmrank',
  121. 'icon' => 'fas fa-angle-right',
  122. 'label' => 'Établissement / Utilisateur / Rang',
  123. 'category' => 'administration'
  124. );
  125. if($myUser->can('plugin','configure'))
  126. $settingMenu[]= array(
  127. 'sort' =>24,
  128. 'url' => 'setting.php?section=firmPlugin',
  129. 'icon' => 'fas fa-angle-right',
  130. 'label' => 'Établissement / Plugins',
  131. 'category' => 'administration'
  132. );
  133. if($myUser->can('dictionnary','configure'))
  134. $settingMenu[]= array(
  135. 'sort' =>20,
  136. 'url' => 'setting.php?section=dictionnary',
  137. 'icon' => 'fas fa-angle-right',
  138. 'label' => 'Listes de valeur'
  139. );
  140. if($myUser->can('log','read'))
  141. $settingMenu[]= array(
  142. 'sort' =>16,
  143. 'url' => 'setting.php?section=log',
  144. 'icon' => 'fas fa-angle-right',
  145. 'label' => 'Logs',
  146. 'category' => 'administration'
  147. );
  148. if($myUser->login!='')
  149. $settingMenu[]= array(
  150. 'sort' =>16,
  151. 'url' => 'setting.php?section=update',
  152. 'icon' => 'fas fa-angle-right',
  153. 'label' => 'Mises à jour',
  154. 'category' => 'administration'
  155. );
  156. });
  157. Plugin::addHook("menu_main", function(&$mainMenu) {
  158. global $myUser;
  159. $mainMenu[] = array(
  160. 'sort' =>0,
  161. 'icon' => 'fas fa-home',
  162. 'label' => 'Accueil',
  163. 'url' => 'index.php',
  164. 'color' => '#383838'
  165. );
  166. if(!$myUser->connected()) return;
  167. $settingMenu = array();
  168. Plugin::callHook("menu_setting", array(&$settingMenu));
  169. });
  170. Plugin::addHook("menu_user", function(&$userMenu){
  171. global $myUser,$myFirm;
  172. $rankLabels = array();
  173. if($myUser->superadmin){
  174. $rankLabels[] = 'Super Admin';
  175. } else {
  176. if(isset($myUser->ranks[$myFirm->id])){
  177. foreach($myUser->ranks[$myFirm->id] as $rank){
  178. $rankLabels[] = $rank->label;
  179. }
  180. }
  181. }
  182. if(count($rankLabels)!=0){
  183. $rankLabels = '<div class="firm-ranks"><ul><li>'.implode('</li><li>',$rankLabels).'</li></ul></div>';
  184. } else {
  185. $rankLabels = '';
  186. }
  187. $userMenu[]= array(
  188. 'sort' =>-2,
  189. 'custom' => "<div class='firm-item' onclick='event.stopPropagation();'><small>Rang : ".$rankLabels."</small></div><div class='dropdown-divider'></div>",
  190. );
  191. if(count($myUser->firms)>1){
  192. $userIcon = 'far fa-user';
  193. $options = '';
  194. foreach ($myUser->firms as $firm) {
  195. $options .= '<option '.($myFirm->id == $firm->id ? "selected='selected'":"").' value="'.$firm->id.'">'.$firm->label.'</option>';
  196. }
  197. $userMenu[]= array(
  198. 'sort' =>1,
  199. 'custom' => "<div class='firm-item' onclick='event.stopPropagation();'><small>É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>",
  200. );
  201. } else {
  202. $userIcon = 'fas fa-user';
  203. $userMenu[]= array(
  204. 'sort' =>-1,
  205. 'custom' => "<div class='firm-item' onclick='event.stopPropagation();'><small>Établissement : ".$myFirm->label."</small></div><div class='dropdown-divider'></div>",
  206. );
  207. }
  208. if($myUser->can('account','read'))
  209. $userMenu[]= array(
  210. 'sort' =>0,
  211. 'label' => 'Mon compte',
  212. 'icon' => $userIcon,
  213. 'url' => 'account.php'
  214. );
  215. if($myUser->can('setting_global', 'read'))
  216. $userMenu[]= array(
  217. 'sort' =>1,
  218. 'icon' => 'fas fa-cog',
  219. 'label' => 'Réglages',
  220. 'url' => 'setting.php'
  221. );
  222. $userMenu[]= array(
  223. 'sort' =>100,
  224. 'icon' => 'fas fa-sign-out-alt',
  225. 'label' => 'Déconnexion',
  226. 'url' => 'action.php?action=logout'
  227. );
  228. });
  229. Plugin::addHook("content_setting", function(){
  230. global $_;
  231. $_['section'] = !isset($_['section']) ? 'global': $_['section'];
  232. if(in_array($_['section'],array('global','plugin','rank','right','user','firm','userfirmrank','firmPlugin','log','dictionnary','update')) && file_exists('setting.'.$_['section'].'.php'))
  233. require_once('setting.'.$_['section'].'.php');
  234. });
  235. Plugin::addHook("content_account", function(){
  236. global $_;
  237. $_['section'] = !isset($_['section']) ? 'global': $_['section'];
  238. if(in_array($_['section'],array('global')) && file_exists('account.'.$_['section'].'.php'))
  239. require_once('account.'.$_['section'].'.php');
  240. });
  241. Plugin::addHook("section",function(&$sections){
  242. $sections['setting_global'] = 'Gestion des parametres globaux';
  243. $sections['user'] = 'Gestion des utilisateurs';
  244. $sections['firm'] = 'Gestion des établissements';
  245. $sections['plugin'] = 'Gestion des plugins';
  246. $sections['rank'] = 'Gestion des rangs et droits';
  247. $sections['log'] = 'Gestion des logs programme';
  248. $sections['dictionnary'] = 'Gestion des listes programme';
  249. $sections['file'] = 'Gestion des fichiers';
  250. $sections['account'] = 'Gestion du compte courant';
  251. });
  252. Plugin::addHook("cron",function(){
  253. if(date('H:i')!='01:00') return;
  254. //Clear automatique des logs
  255. global $conf;
  256. foreach(Log::staticQuery('SELECT DISTINCT category FROM {{table}}',array(),true) as $log):
  257. $slug = slugify($log->category);
  258. $key = 'log_retention_time_'.$slug;
  259. if($conf->get($key)=='') continue;
  260. Log::clear($conf->get($key));
  261. endforeach;
  262. });
  263. Plugin::includeAll();
  264. ?>