[3018] | 1 | <?php |
---|
[182] | 2 | /***********************************************************************************\ |
---|
| 3 | * Expresso Administração * |
---|
| 4 | * by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br) * |
---|
| 5 | * ---------------------------------------------------------------------------------* |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \***********************************************************************************/ |
---|
| 11 | |
---|
| 12 | include_once('class.db_functions.inc.php'); |
---|
| 13 | include_once('class.functions.inc.php'); |
---|
| 14 | |
---|
| 15 | class manager |
---|
| 16 | { |
---|
| 17 | var $db_functions; |
---|
| 18 | var $functions; |
---|
| 19 | var $current_config; |
---|
| 20 | |
---|
| 21 | function manager() |
---|
| 22 | { |
---|
| 23 | $this->db_functions = new db_functions; |
---|
| 24 | $this->functions = new functions; |
---|
| 25 | $this->current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin']; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | function save($params) |
---|
| 29 | { |
---|
| 30 | $manager_acl = $this->make_manager_acl($params); |
---|
| 31 | |
---|
| 32 | $this->db_functions->save_manager($params, $manager_acl); |
---|
| 33 | |
---|
| 34 | $return['status'] = 'true'; |
---|
| 35 | $return['type'] = 'save'; |
---|
| 36 | return $return; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | function create($params) |
---|
| 40 | { |
---|
| 41 | $manager_acl = $this->make_manager_acl($params); |
---|
| 42 | |
---|
| 43 | $this->db_functions->create_manager($params, $manager_acl); |
---|
| 44 | |
---|
| 45 | $return['status'] = 'true'; |
---|
| 46 | $return['type'] = 'create'; |
---|
| 47 | return $return; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | function make_manager_acl($array_post) |
---|
| 51 | { |
---|
[5133] | 52 | |
---|
| 53 | $total_manager_acl = array(); |
---|
| 54 | |
---|
[182] | 55 | foreach ($array_post as $atribute=>$value) |
---|
| 56 | { |
---|
| 57 | $acl = strstr($atribute, 'acl_'); |
---|
| 58 | |
---|
[5133] | 59 | if ($acl !== false && $value = 'true') |
---|
| 60 | array_push($total_manager_acl, $atribute); |
---|
| 61 | |
---|
[182] | 62 | } |
---|
[5133] | 63 | |
---|
[182] | 64 | return $total_manager_acl; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | function validate($params) |
---|
| 68 | { |
---|
| 69 | if (is_array($_SESSION['phpgw_info']['expresso']['server'])) |
---|
| 70 | $GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server']; |
---|
| 71 | else |
---|
| 72 | $_SESSION['phpgw_info']['expresso']['server'] = $GLOBALS['phpgw_info']['server']; |
---|
| 73 | |
---|
| 74 | $return['status'] = 'true'; |
---|
| 75 | |
---|
[5593] | 76 | $contexts = preg_split('/%/', $params['contexts']); |
---|
[182] | 77 | $manager_lid = $params['manager_lid']; |
---|
| 78 | $type = $params['type']; |
---|
| 79 | |
---|
[6418] | 80 | if ($params['contexts'] == '') |
---|
[182] | 81 | { |
---|
| 82 | $return['status'] = 'false'; |
---|
[493] | 83 | $return['msg'] = $this->functions->lang('context field is empty') . '.'; |
---|
| 84 | |
---|
[182] | 85 | return $return; |
---|
| 86 | } |
---|
| 87 | if (($manager_lid == '') && ($type == 'add')) |
---|
| 88 | { |
---|
| 89 | $return['status'] = 'false'; |
---|
[493] | 90 | $return['msg'] = $this->functions->lang('select one manager') . '.'; |
---|
| 91 | |
---|
[182] | 92 | return $return; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | // Verifica se o contexto existe. |
---|
| 96 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
| 97 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
| 98 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
| 99 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 100 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
| 101 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
| 102 | |
---|
| 103 | foreach ($contexts as $index=>$context) |
---|
| 104 | { |
---|
| 105 | $sr=@ldap_list($ldap_conn, $context, "cn=*"); |
---|
| 106 | if (!$sr) |
---|
| 107 | { |
---|
| 108 | $return['status'] = 'false'; |
---|
[493] | 109 | $this->functions->lang('context does not exist') . ": $context"; |
---|
[182] | 110 | return $return; |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | if ($type == 'add') |
---|
| 115 | { |
---|
| 116 | include_once('class.db_functions.inc.php'); |
---|
| 117 | $db = new db_functions(); |
---|
| 118 | |
---|
| 119 | if ($db->manager_lid_exist($manager_lid)) |
---|
| 120 | { |
---|
| 121 | $return['status'] = 'false'; |
---|
[493] | 122 | $return['msg'] = $this->functions->lang('manager already exist') . "."; |
---|
| 123 | |
---|
[182] | 124 | return $return; |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | return $return; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | function manager_lid_exist($manager_lid) |
---|
| 132 | { |
---|
[5133] | 133 | $query = "SELECT manager_lid FROM phpgw_expressoadmin_acls WHERE manager_lid = '" . $manager_lid . "'"; |
---|
[182] | 134 | $this->db->query($query); |
---|
| 135 | while($this->db->next_record()) |
---|
| 136 | $result[] = $this->db->row(); |
---|
| 137 | if (count($result) > 0) |
---|
| 138 | return true; |
---|
| 139 | else |
---|
| 140 | return false; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | } |
---|
[1913] | 144 | ?> |
---|