source: branches/2.4/expressoMail1_2/login_offline.php @ 5934

Revision 5934, 13.9 KB checked in by marcosw, 12 years ago (diff)

Ticket #2398 - Compatibilizacao com PHP-5.3 em alguns módulos do expresso

Line 
1<?php
2        /**************************************************************************\
3        * ExpressoMail Offline login                                                         *
4        * http://www.egroupware.org                                                *
5        * Originaly written by Dan Kuykendall <seek3r@phpgroupware.org>            *
6        *                      Joseph Engo    <jengo@phpgroupware.org>             *
7        * Updated by Nilton Emilio Buhrer Neto <niltonneto@celepar.pr.gov.br>      *
8        *  This program is free software; you can redistribute it and/or modify it *
9        *  under the terms of the GNU General Public License as published by the   *
10        *  Free Software Foundation; either version 2 of the License, or (at your  *
11        *  option) any later version.                                              *
12        \**************************************************************************/
13ini_set("display_errors","1");
14        $phpgw_info = array();
15        $submit = False;                        // set to some initial value
16
17        $GLOBALS['phpgw_info']['flags'] = array(
18                'disable_Template_class' => True,
19                'login'                  => True,
20                'currentapp'             => 'expressoMail1_2',
21                'noheader'               => True
22        );
23
24        include('../header.inc.php');
25
26//      $GLOBALS['phpgw_info']['server']['template_dir'] = PHPGW_SERVER_ROOT . '/phpgwapi/templates/' . $GLOBALS['phpgw_info']['login_template_set'];
27        $tmpl = CreateObject('phpgwapi.Template', 'templates/default');
28
29        // read the images from the login-template-set, not the (maybe not even set) users template-set
30        $GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
31
32        $tmpl->set_file(array('login_form' => 'login_offline.tpl'));
33
34        # Apache + mod_ssl style SSL certificate authentication
35        # Certificate (chain) verification occurs inside mod_ssl
36        /*if($GLOBALS['phpgw_info']['server']['auth_type'] == 'sqlssl' && isset($_SERVER['SSL_CLIENT_S_DN']) && !isset($_GET['cd']))
37        {
38                # an X.509 subject looks like:
39                # /CN=john.doe/OU=Department/O=Company/C=xx/Email=john@comapy.tld/L=City/
40                # the username is deliberately lowercase, to ease LDAP integration
41                $sslattribs = explode('/',$_SERVER['SSL_CLIENT_S_DN']);
42                # skip the part in front of the first '/' (nothing)
43                while($sslattrib = next($sslattribs))
44                {
45                        list($key,$val) = explode('=',$sslattrib);
46                        $sslattributes[$key] = $val;
47                }
48
49                if(isset($sslattributes['Email']))
50                {
51                        $submit = True;
52
53                        # login will be set here if the user logged out and uses a different username with
54                        # the same SSL-certificate.
55                        if(!isset($_POST['login'])&&isset($sslattributes['Email']))
56                        {
57                                $login = $sslattributes['Email'];
58                                # not checked against the database, but delivered to authentication module
59                                $passwd = $_SERVER['SSL_CLIENT_S_DN'];
60                        }
61                }
62                unset($key);
63                unset($val);
64                unset($sslattributes);
65        }*/
66
67        //if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit)
68        //{
69/////   Início - Código temporário: Para renomeação de login com organização para sem. //////
70/*              $common = CreateObject('phpgwapi.common');
71                $ldap_conn = $common->ldapConnect();
72                $justthese = array("uid");
73                $filter="(&(phpgwAccountType=u)(uid=".$_POST['user']."))";
74                $ldap_search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
75                $ldap_info       = ldap_get_entries($ldap_conn, $ldap_search);
76                if ($ldap_info['count'] != 0) // Verifica se o login existe sem organização.
77                {
78                        $_POST['login'] = $_POST['user'];
79                }
80                ldap_close($ldap_conn);*/
81///     Fim - Código temporário: Para renomeação de login com organização para sem. //////
82                /*if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' &&
83                        !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN']))
84                {
85                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=5'));
86                }*/
87               
88                // don't get login data again when $submit is true
89                /*if($submit == false)
90                {
91                        $login = $_POST['login'];
92                }
93               
94                if(strstr($login,'@') === False && isset($_POST['logindomain']))
95                {
96                        $login .= '@' . $_POST['logindomain'];
97                }
98                elseif(!isset($GLOBALS['phpgw_domain'][$GLOBALS['phpgw_info']['user']['domain']]))
99                {
100                        $login .= '@'.$GLOBALS['phpgw_info']['server']['default_domain'];
101                }
102                $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u');
103
104                if(!isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid'])
105                {
106                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason);
107                }
108                else
109                {
110                        if ($_POST['lang'] && preg_match('/^[a-z]{2}(-[a-z]{2}){0,1}$/',$_POST['lang']) &&
111                            $_POST['lang'] != $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
112                        {
113                                $GLOBALS['phpgw']->preferences->add('common','lang',$_POST['lang'],'session');
114                        }
115
116                        if(!$GLOBALS['phpgw_info']['server']['disable_autoload_langfiles'])
117                        {
118                                $GLOBALS['phpgw']->translation->autoload_changed_langfiles();
119                        }
120                        $forward = isset($_GET['phpgw_forward']) ? urldecode($_GET['phpgw_forward']) : @$_POST['phpgw_forward'];
121                        if (!$forward)
122                        {
123                                $extra_vars['cd'] = 'yes';
124                                $forward = '/home.php';
125                        }
126                        else
127                        {
128                                list($forward,$extra_vars) = explode('?',$forward,2);
129                        }
130                        if ($GLOBALS['phpgw_info']['server']['use_https'] != 2)
131                        {
132                                $forward = 'http://'.$_SERVER['HTTP_HOST'].($GLOBALS['phpgw']->link($forward.'?cd=yes'));
133                                echo "<script language='Javascript1.3'>location.href='".$forward."'</script>";
134                        }
135                        else
136                        {
137                                $GLOBALS['phpgw']->redirect_link($forward,$extra_vars);
138                        }
139                }
140        }
141        else
142        {*/
143                // !!! DONT CHANGE THESE LINES !!!
144                // If there is something wrong with this code TELL ME!
145                // Commenting out the code will not fix it. (jengo)
146                /*if(isset($_COOKIE['last_loginid']))
147                {
148                        $accounts = CreateObject('phpgwapi.accounts');
149                        $prefs = CreateObject('phpgwapi.preferences', $accounts->name2id($_COOKIE['last_loginid']));
150
151                        if($prefs->account_id)
152                        {
153                                $GLOBALS['phpgw_info']['user']['preferences'] = $prefs->read_repository();
154                        }
155                }
156                if ($_GET['lang'])
157                {
158                        $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang'];
159                }
160                elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id)
161                {
162                        // If the lastloginid cookies isn't set, we will default to the first language,
163                        // the users browser accepts.
164                        list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
165                        /*
166                        if(strlen($lang) > 2)
167                        {
168                                $lang = substr($lang,0,2);
169                        }
170                        */
171                        /*$GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang;
172                }*/
173                #print 'LANG:' . $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] . '<br>';
174
175                $GLOBALS['phpgw']->translation->init(); // this will set the language according to the (new) set prefs
176                $GLOBALS['phpgw']->translation->add_app('login');
177                $GLOBALS['phpgw']->translation->add_app('loginscreen');
178                if(lang('loginscreen_message') == 'loginscreen_message*')
179                {
180                        $GLOBALS['phpgw']->translation->add_app('loginscreen','en');    // trying the en one
181                }
182                if(lang('loginscreen_message') != 'loginscreen_message*')
183                {
184                        $tmpl->set_var('lang_message',stripslashes(lang('loginscreen_message')));
185                }
186        //}
187
188/*      if($GLOBALS['phpgw_info']['server']['use_prefix_organization'])
189        {
190                $organization_select = "<tr><td width=\"66\" class=\"loginLabel\">";
191                $organization_select .= lang("organization").":</td>";
192                $organization_select .="<td width=\"135\">";                                                                                   
193                $organization_select .="<select name=\"organization\">\n";             
194               
195                $obj_organization = CreateObject('phpgwapi.sector_search_ldap');
196                $organizations = $obj_organization->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']);
197               
198                for ($i=0; $i<count($organizations); $i++)
199                {
200                        $tmp_array[strtolower($organizations[$i])] = $organizations[$i];       
201                }
202               
203                $arrayOrganization = $tmp_array;               
204                ksort($arrayOrganization);
205               
206                foreach($arrayOrganization
207                         as $organization_name => $organization_vars)
208                {
209                        $organization_select .= '<option value="' . $organization_name . '"';
210
211                        if($organization_name == $_COOKIE['last_organization'])
212                        {
213                                $organization_select .= ' selected';
214                        }
215                        $organization_select .= '>' . $organization_vars . "</option>\n";
216                }
217                $organization_select .= "</select>\n";
218                $organization_select .="</td><td>&nbsp;</td></tr>";
219                $tmpl->set_var('select_organization',$organization_select);
220        }*/
221               
222        /*$domain_select = '&nbsp;';
223        $last_loginid = $_COOKIE['last_loginid'];
224        if($GLOBALS['phpgw_info']['server']['show_domain_selectbox'])
225        {
226                $domain_select = "<select name=\"logindomain\">\n";
227                foreach($GLOBALS['phpgw_domain'] as $domain_name => $domain_vars)
228                {
229                        $domain_select .= '<option value="' . $domain_name . '"';
230
231                        if($domain_name == $_COOKIE['last_domain'])
232                        {
233                                $domain_select .= ' selected';
234                        }
235                        $domain_select .= '>' . $domain_name . "</option>\n";
236                }
237                $domain_select .= "</select>\n";
238        }
239        elseif($last_loginid !== '')
240        {
241                reset($GLOBALS['phpgw_domain']);
242                list($default_domain) = each($GLOBALS['phpgw_domain']);
243
244                if($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain']))
245                {
246                        $last_loginid .= '@' . $_COOKIE['last_domain'];
247                }
248        }
249        $tmpl->set_var('select_domain',$domain_select);*/
250
251        /*foreach($_GET as $name => $value)
252        {
253                if(preg_match('/phpgw_/',$name))
254                {
255                        $extra_vars .= '&' . $name . '=' . urlencode($value);
256                }
257        }
258
259        if($extra_vars)
260        {
261                $extra_vars = '?' . substr($extra_vars,1);
262        }*/
263
264        /********************************************************\
265        * Check is the registration app is installed, activated  *
266        * And if the register link must be placed                *
267        \********************************************************/
268       
269        /*$cnf_reg = createobject('phpgwapi.config','registration');
270        $cnf_reg->read_repository();
271        $config_reg = $cnf_reg->config_data;
272
273        if($config_reg[enable_registration]=='True' && $config_reg[register_link]=='True')
274        {
275                $reg_link='&nbsp;<a href="registration/">'.lang('Not a user yet? Register now').'</a><br/>';
276        }*/
277
278        $GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
279
280        $tmpl->set_var('register_link',$reg_link);
281        $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset());
282        $tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
283        $tmpl->set_var('registration_url',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/');
284        $tmpl->set_var('version',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']);
285        //$tmpl->set_var('cd',check_logoutcode($_GET['cd']));
286        $tmpl->set_var('cookie',$last_loginid);
287        //david
288        $tmpl->set_var('teste_compatibilidade',$GLOBALS['phpgw_info']['server']['teste_compatibilidade']);
289
290        $tmpl->set_var('lang_username',lang('username'));
291        $tmpl->set_var('lang_password',lang('password'));
292        $tmpl->set_var('lang_login',lang('login'));
293
294        $tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']);
295        $tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']);
296        $tmpl->set_var('bg_color',($GLOBALS['phpgw_info']['server']['login_bg_color']?$GLOBALS['phpgw_info']['server']['login_bg_color']:'FFFFFF'));
297        $tmpl->set_var('bg_color_title',($GLOBALS['phpgw_info']['server']['login_bg_color_title']?$GLOBALS['phpgw_info']['server']['login_bg_color_title']:'486591'));
298
299        if($GLOBALS['phpgw_info']['server']['use_frontend_name'])
300                $tmpl->set_var('frontend_name', " - ".$GLOBALS['phpgw_info']['server']['use_frontend_name']);
301
302        if (substr($GLOBALS['phpgw_info']['server']['login_logo_file'],0,4) == 'http')
303        {
304                $var['logo_file'] = $GLOBALS['phpgw_info']['server']['login_logo_file'];
305        }
306        else
307        {
308                $var['logo_file'] = $GLOBALS['phpgw']->common->image('phpgwapi',$GLOBALS['phpgw_info']['server']['login_logo_file']?$GLOBALS['phpgw_info']['server']['login_logo_file']:'logo');
309        }
310        $var['logo_url'] = $GLOBALS['phpgw_info']['server']['login_logo_url']?$GLOBALS['phpgw_info']['server']['login_logo_url']:'http://www.eGroupWare.org';
311        if (substr($var['logo_url'],0,4) != 'http')
312        {
313                $var['logo_url'] = 'http://'.$var['logo_url'];
314        }
315        $var['logo_title'] = $GLOBALS['phpgw_info']['server']['login_logo_title']?$GLOBALS['phpgw_info']['server']['login_logo_title']:'www.eGroupWare.org';
316        $tmpl->set_var($var);
317
318        if (@$GLOBALS['phpgw_info']['server']['login_show_language_selection'])
319        {
320                $select_lang = '<select name="lang" onchange="'."location.href=location.href+(location.search?'&':'?')+'lang='+this.value".'">';
321                $langs = $GLOBALS['phpgw']->translation->get_installed_langs();
322                uasort($langs,'strcasecmp');
323                foreach ($langs as $key => $name)       // if we have a translation use it
324                {
325                        $select_lang .= "\n\t".'<option value="'.$key.'"'.($key == $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] ? ' selected="1"' : '').'>'.$name.'</option>';
326                }
327                $select_lang .= "\n</select>\n";
328                $tmpl->set_var(array(
329                        'lang_language' => lang('Language'),
330                        'select_language' => $select_lang,
331                ));
332        }
333        else
334        {
335                $tmpl->set_block('login_form','language_select');
336                $tmpl->set_var('language_select','');
337        }
338       
339        if (count($GLOBALS['phpgw_info']['server']['login_logo_file']) > 0) {
340                $logo_config = $GLOBALS['phpgw_info']['server']['login_logo_file'];
341                $logo_config = preg_replace('/phpgwapi\//','../phpgwapi/',$logo_config);
342                $tmpl->set_var('logo_config',$logo_config);     
343        }
344                else
345                        $tmpl->set_var('logo_config','<a title="Governo do Paran&aacute" href="http://www.pr.gov.br" target="_blank"><img src="../phpgwapi/templates/'.$GLOBALS['phpgw_info']['login_template_set'].'/images/logo_governo.gif" border="0"></a></td>
346                        <td><div align="center"><font color="#9a9a9a" face="Verdana, Arial, Helvetica, sans-serif" size="1">
347        <a title="Celepar Inform&aacute;tica do Paran&aacute;" target="_blank" href="http://www.celepar.pr.gov.br/">
348        <img src="../phpgwapi/templates/'.$GLOBALS['phpgw_info']['login_template_set'].'/images/logo_celepar.gif" border="0"></a>');
349       
350/*foreach ($GLOBALS['phpgw_info']['user'] as $indice => $valor)
351                                        echo "$indice > $valor <br>";
352                                        exit(0);*/
353        $tmpl->set_var('autocomplete', ($GLOBALS['phpgw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : ''));
354
355        $tmpl->pfp('loginout','login_form');
356?>
Note: See TracBrowser for help on using the repository browser.