action.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. Action::register('organizational_setting_save',function(&$response){
  3. global $myUser,$conf,$_;
  4. User::check_access('organizational','configure');
  5. if(!$myUser->superadmin) return;
  6. foreach(Configuration::setting('organizational') as $key=>$value){
  7. if(!is_array($value)) continue;
  8. $allowed[] = $key;
  9. }
  10. foreach ($_['fields'] as $key => $value)
  11. if(in_array($key, $allowed)) $conf->put($key,$value);
  12. $response['message'] = 'Configuration enregistrée';
  13. });
  14. Action::register('organizational_employee_search',function(&$response){
  15. global $myUser,$conf,$_;
  16. User::check_access('organizational','read');
  17. $users = array();
  18. $rootLogin = stripslashes($conf->get('organizational_root'));
  19. $filterOrigin = $conf->get('organizational_origin');
  20. $hiddenUsersRanks = $conf->get('organizational_hidden_users_ranks');
  21. if(empty($rootLogin)) throw new Exception("Merci de bien vouloir configurer le nom du PDG dans la partie réglages");
  22. $boss = User::byLogin($rootLogin);
  23. $allUsers = User::getAll(array('right' => false, 'force' => true));
  24. foreach($allUsers as $user)
  25. $users[$user->login] = $user;
  26. $managers = array();
  27. //création du tableau de managers
  28. foreach($allUsers as $index => $user){
  29. if(!isset($user->manager)|| !is_object($user->manager) || $user->manager->login=='') {
  30. unset($allUsers[$index]);
  31. unset($users[$index]);
  32. continue;
  33. };
  34. if($user->login=='') continue;
  35. if (($filterOrigin && $user->origin != $filterOrigin)
  36. || ($hiddenUsersRanks && strpos($hiddenUsersRanks, $user->login) !== false )) {
  37. unset($allUsers[$index]);
  38. unset($users[$index]);
  39. continue;
  40. }
  41. if(!isset($managers[$user->manager->login])){
  42. $managers[$user->manager->login] = array(
  43. 'manager' => $users[$user->manager->login],
  44. 'employees' => array()
  45. );
  46. }
  47. $managers[$user->manager->login]['employees'][] = $user;
  48. }
  49. $json = array();
  50. function organizational_tree($user,$users,$managers,&$json){
  51. $user->meta = json_decode($user->meta);
  52. $jsonUser = array(
  53. 'name' => $user->fullName(),
  54. 'manager' => isset($user->manager) ? $user->manager->fullName() : null ,
  55. 'title' => isset($user->function)? $user->function:'Employé',
  56. 'mobile' => $employee['mobile'] = !empty($user->mobile) ? $user->mobile : (isset($user->meta->personalPhone) ? $user->meta->personalPhone : $user->phone),
  57. 'mail' => $user->mail,
  58. 'avatar' => $user->getAvatar(),
  59. 'service' => $user->service,
  60. 'sst' => isset($user->meta->sst) && $user->meta->sst,
  61. );
  62. //var_dump($jsonUser['sst']);
  63. if(isset($managers[$user->login]) && count($managers[$user->login])!=0){
  64. $jsonUser['children'] = array();
  65. foreach($managers[$user->login]['employees'] as $subaltern){
  66. organizational_tree($subaltern,$users,$managers,$jsonUser['children']);
  67. }
  68. }
  69. $json[] = $jsonUser;
  70. }
  71. organizational_tree($boss,$users,$managers,$json);
  72. $response['json'] = (object) $json[0];
  73. $response['count'] = count($allUsers);
  74. });
  75. ?>