common.php 9.5 KB

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