source: sandbox/2.2.0.2/contactcenter/inc/hook_config_validate.inc.php @ 4504

Revision 4504, 3.3 KB checked in by airton, 13 years ago (diff)

Ticket #1929 - Validacao de campos do LDAP de acordo com os atributos extras de um contato

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /***************************************************************************\
3  * eGroupWare - Contacts Center                                              *
4  * http://www.egroupware.org                                                 *
5  * Written by:                                                               *
6  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
7  *  sponsored by Thyamad - http://www.thyamad.com
8  * ------------------------------------------------------------------------- *
9  *  This program is free software; you can redistribute it and/or modify it  *
10  *  under the terms of the GNU General Public License as published by the    *
11  *  Free Software Foundation; either version 2 of the License, or (at your   *
12  *  option) any later version.                                               *
13  \***************************************************************************/
14
15        /*
16          Set a global flag to indicate this file was found by admin/config.php.
17          config.php will unset it after parsing the form values.
18        */
19        $GLOBALS['phpgw_info']['server']['found_validation_hook'] = True;
20
21        /* Check all settings to validate input.  Name must be 'final_validation' */
22        function final_validation(&$value='')
23        {
24                $error = false;
25               
26//              if($value['cc_global_source0'] == 'ldap')
27//              {
28//                      if (!$value['cc_ldap_host0'])
29//                      {
30//                              $error[] = '<br>LDAP host must be set!';
31//                      }
32//                     
33//                      if(!$value['cc_ldap_context0'])
34//                      {
35//                              $error[] = '<br>There must be a Context';
36//                      }
37//                     
38//                      if(!$value['cc_ldap_browse_dn0'])
39//                      {
40//                              $error[] = '<br>The Browse Account must be set';
41//                      }       
42//              }
43               
44                foreach ($value as $attr_name => $attr_value) {
45                        if ($attr_value == '') {
46                                $v      = explode("_", $attr_name);
47                                $nums[] = $v[3];
48                        }
49                }
50               
51                foreach ($nums as $num) {
52                        //Deleta toda a tupla que contem o atributo vazio
53                        foreach ($value as $attr_name_x => $attr_value_x) {
54                       
55                                if (strpos($attr_name_x, $num) !== false) {
56                                        if (strpos($attr_name_x, 'cc_attribute_name') !== false)
57                                                $error[] = "<br/>" . lang("Could not find the LDAP attribute pointed by") . "  " . $attr_value_x;       
58                                       
59                                        unset($value[$attr_name_x]);   
60                                       
61                                }
62                        }
63                }
64               
65                if ($error)
66                {
67                        $GLOBALS['config_error'] = implode("\n", $error);
68                }
69        }
70
71       
72        /*
73         * @function cc_allow_details
74         * @abstract Recebe o valor do checkbox e força a saída para TRUE ou FALSE
75         * @author Prognus software livre - http://www.prognus.com.br | prognus@prognus.com.br
76         * @param $value
77         */
78        function cc_allow_details(&$value) {
79                if ($value == 'details') {
80                        $value = "true";
81                } else {
82                        $value = "false";
83                }
84        }
85       
86       
87       
88        /*
89         * @function cc_attribute_ldapname
90         * @abstract valida campo "Correspondente LDAP" se é um campo ldap válido
91         * @author Prognus Software Livre - http://www.prognus.com.br | prognus@prognus.com.br
92         * @param $value
93         */
94        function cc_attribute_ldapname(&$value) {
95                $ldap = CreateObject('contactcenter.bo_ldap_manager');
96                $ds = $GLOBALS['phpgw']->common->ldapConnect($ldap->srcs[1]['host'], $ldap->srcs[1]['acc'], $ldap->srcs[1]['pw'], true);                               
97                $dn=$ldap->srcs[1]['dn'];
98                $justThese = array('uid', 'cn', $value);
99                $sr = ldap_search($ds, $dn, "($value=*)", $justThese, 0, 1);
100                $info = ldap_get_entries($ds, $sr);
101               
102                if (!$info) 
103                        $value = "";
104                ldap_close($ds);
105        }
106?>
Note: See TracBrowser for help on using the repository browser.