source: branches/2.0/phpgwapi/templates/classic/login_classic.php @ 1718

Revision 1718, 13.5 KB checked in by niltonneto, 14 years ago (diff)

Ticket #795 - Corrigido problema no template classic.

  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * eGroupWare 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        \**************************************************************************/
13
14        function check_logoutcode($code)
15        {
16                switch($code)
17                {
18                        case 1:
19                                return lang('You have been successfully logged out');
20                               
21                        case 2:
22                                return lang('Sorry, your login has expired');
23                               
24                        case 4:
25                                return lang('Cookies are required to login to this site.');
26                               
27                        case 5:
28                                return '<font color="FF0000">' . lang('Bad login or password') . '</font>';
29
30                        case 6:
31                                return '<font color="FF0000">' . lang('Your password has expired, and you do not have access to change it') . '</font>';
32                               
33                        case 98:
34                                return '<font color="FF0000">' . lang('Account is expired') . '</font>';
35                               
36                        case 99:
37                                return '<font color="FF0000">' . lang('Blocked, too many attempts') . '</font>';
38                               
39                        case 10:
40                                $GLOBALS['phpgw']->session->phpgw_setcookie('sessionid');
41                                $GLOBALS['phpgw']->session->phpgw_setcookie('kp3');
42                                $GLOBALS['phpgw']->session->phpgw_setcookie('domain');
43
44                                //fix for bug php4 expired sessions bug
45                                if($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4')
46                                {
47                                        $GLOBALS['phpgw']->session->phpgw_setcookie(PHPGW_PHPSESSID);
48                                }
49
50                                return '<font color="#FF0000">' . lang('Your session could not be verified.') . '</font>';
51                               
52                        default:
53                                return '&nbsp;';
54                }
55        }
56       
57        /* Program starts here */
58
59        if($GLOBALS['phpgw_info']['server']['auth_type'] == 'http' && isset($_SERVER['PHP_AUTH_USER']))
60        {
61                $submit = True;
62                $login  = $_SERVER['PHP_AUTH_USER'];
63                $passwd = $_SERVER['PHP_AUTH_PW'];
64                $passwd_type = 'text';
65        }
66        else
67        {
68                $passwd = $_POST['passwd'];
69                $passwd_type = $_POST['passwd_type'];
70        }
71
72        # Apache + mod_ssl style SSL certificate authentication
73        # Certificate (chain) verification occurs inside mod_ssl
74        if($GLOBALS['phpgw_info']['server']['auth_type'] == 'sqlssl' && isset($_SERVER['SSL_CLIENT_S_DN']) && !isset($_GET['cd']))
75        {
76                # an X.509 subject looks like:
77                # /CN=john.doe/OU=Department/O=Company/C=xx/Email=john@comapy.tld/L=City/
78                # the username is deliberately lowercase, to ease LDAP integration
79                $sslattribs = explode('/',$_SERVER['SSL_CLIENT_S_DN']);
80                # skip the part in front of the first '/' (nothing)
81                while($sslattrib = next($sslattribs))
82                {
83                        list($key,$val) = explode('=',$sslattrib);
84                        $sslattributes[$key] = $val;
85                }
86
87                if(isset($sslattributes['Email']))
88                {
89                        $submit = True;
90
91                        # login will be set here if the user logged out and uses a different username with
92                        # the same SSL-certificate.
93                        if(!isset($_POST['login'])&&isset($sslattributes['Email']))
94                        {
95                                $login = $sslattributes['Email'];
96                                # not checked against the database, but delivered to authentication module
97                                $passwd = $_SERVER['SSL_CLIENT_S_DN'];
98                        }
99                }
100                unset($key);
101                unset($val);
102                unset($sslattributes);
103        }
104
105        if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit)
106        {
107                if($_POST['user']) {
108                        if($GLOBALS['phpgw_info']['server']['use_prefix_organization']) {
109                                $common = CreateObject('phpgwapi.common');
110                                $ldap_conn = $common->ldapConnect();
111                                $justthese = array("uid");
112                                $filter="(&(phpgwAccountType=u)(uid=".$_POST['user']."))";
113                                $ldap_search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
114                                $ldap_info       = ldap_get_entries($ldap_conn, $ldap_search);
115                                ldap_close($ldap_conn);
116                                if ($ldap_info['count'] != 0) {
117                                        $_POST['login'] = $_POST['user'];
118                                }
119                        }
120                        else
121                                $_POST['login'] = $_POST['user'];
122                }
123                if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' &&
124                        !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN']))
125                {
126                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=5'));
127                }
128               
129                // don't get login data again when $submit is true
130                if($submit == false)
131                {
132                        $login = $_POST['login'];
133                }
134               
135                if(strstr($login,'@') === False && isset($_POST['logindomain']))
136                {
137                        $login .= '@' . $_POST['logindomain'];
138                }
139                elseif(!isset($GLOBALS['phpgw_domain'][$GLOBALS['phpgw_info']['user']['domain']]))
140                {
141                        $login .= '@'.$GLOBALS['phpgw_info']['server']['default_domain'];
142                }
143                $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u');
144
145                if(!isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid'])
146                {
147                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason);
148                }
149                else
150                {
151                        if ($_POST['lang'] && preg_match('/^[a-z]{2}(-[a-z]{2}){0,1}$/',$_POST['lang']) &&
152                            $_POST['lang'] != $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
153                        {
154                                $GLOBALS['phpgw']->preferences->add('common','lang',$_POST['lang'],'session');
155                        }
156
157                        if(!$GLOBALS['phpgw_info']['server']['disable_autoload_langfiles'])
158                        {
159                                $GLOBALS['phpgw']->translation->autoload_changed_langfiles();
160                        }
161                        $forward = isset($_GET['phpgw_forward']) ? urldecode($_GET['phpgw_forward']) : @$_POST['phpgw_forward'];
162                        if (!$forward)
163                        {
164                                $extra_vars['cd'] = 'yes';
165                                $forward = '/home.php';
166                        }
167                        else
168                        {
169                                list($forward,$extra_vars) = explode('?',$forward,2);
170                        }
171                        if ($GLOBALS['phpgw_info']['server']['use_https'] != 2)
172                        {
173                                $forward = 'http://'.$_SERVER['HTTP_HOST'].($GLOBALS['phpgw']->link($forward.'?cd=yes'));
174                                echo "<script language='Javascript1.3'>location.href='".$forward."'</script>";
175                        }
176                        else
177                        {
178                                $GLOBALS['phpgw']->redirect_link($forward,$extra_vars);
179                        }
180                }
181        }
182        else
183        {
184                // !!! DONT CHANGE THESE LINES !!!
185                // If there is something wrong with this code TELL ME!
186                // Commenting out the code will not fix it. (jengo)
187                if(isset($_COOKIE['last_loginid']))
188                {
189                        $accounts = CreateObject('phpgwapi.accounts');
190                        $prefs = CreateObject('phpgwapi.preferences', $accounts->name2id($_COOKIE['last_loginid']));
191
192                        if($prefs->account_id)
193                        {
194                                $GLOBALS['phpgw_info']['user']['preferences'] = $prefs->read_repository();
195                        }
196                }
197                if ($_GET['lang'])
198                {
199                        $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang'];
200                }
201                elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id)
202                {
203                        // If the lastloginid cookies isn't set, we will default to the first language,
204                        // the users browser accepts.
205                        list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
206                        /*
207                        if(strlen($lang) > 2)
208                        {
209                                $lang = substr($lang,0,2);
210                        }
211                        */
212                        $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang;
213                }
214                #print 'LANG:' . $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] . '<br>';
215
216                $GLOBALS['phpgw']->translation->init(); // this will set the language according to the (new) set prefs
217                $GLOBALS['phpgw']->translation->add_app('login');
218                $GLOBALS['phpgw']->translation->add_app('loginscreen');
219                if(lang('loginscreen_message') == 'loginscreen_message*')
220                {
221                        $GLOBALS['phpgw']->translation->add_app('loginscreen','en');    // trying the en one
222                }
223                if(lang('loginscreen_message') != 'loginscreen_message*')
224                {
225                        $tmpl->set_var('lang_message',stripslashes(lang('loginscreen_message')));
226                }
227        }
228
229        if($GLOBALS['phpgw_info']['server']['use_prefix_organization'])
230        {
231                $organization_select = "<tr><td width=\"96\" class=\"loginLabel\">";
232                $organization_select .= lang("organization").":&nbsp;</td>";
233                $organization_select .= "<td width=\"135\">";                                                           
234                $organization_select .= "<select name=\"organization\">\n";             
235               
236                $obj_organization = CreateObject('phpgwapi.sector_search_ldap');
237                $organizations = $obj_organization->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']);
238               
239                for ($i=0; $i<count($organizations); $i++)
240                {
241                        $tmp_array[strtolower($organizations[$i])] = $organizations[$i];       
242                }
243               
244                $arrayOrganization = $tmp_array;               
245                ksort($arrayOrganization);
246               
247                foreach($arrayOrganization
248                         as $organization_name => $organization_vars)
249                {
250                        $organization_select .= '<option value="' . $organization_name . '"';
251
252                        if($organization_name == $_COOKIE['last_organization'])
253                        {
254                                $organization_select .= ' selected';
255                        }
256                        $organization_select .= '>' . $organization_vars . "</option>\n";
257                }
258                $organization_select .= "</select>\n";
259                $organization_select .="</td><td>&nbsp;</td></tr>";
260                $tmpl->set_var('select_organization',$organization_select);
261        }
262               
263        $domain_select = '&nbsp;';
264        $last_loginid = $_COOKIE['last_loginid'];
265        if($GLOBALS['phpgw_info']['server']['show_domain_selectbox'])
266        {
267                $domain_select = "<select name=\"logindomain\">\n";
268                foreach($GLOBALS['phpgw_domain'] as $domain_name => $domain_vars)
269                {
270                        $domain_select .= '<option value="' . $domain_name . '"';
271
272                        if($domain_name == $_COOKIE['last_domain'])
273                        {
274                                $domain_select .= ' selected';
275                        }
276                        $domain_select .= '>' . $domain_name . "</option>\n";
277                }
278                $domain_select .= "</select>\n";
279        }
280        elseif($last_loginid !== '')
281        {
282                reset($GLOBALS['phpgw_domain']);
283                list($default_domain) = each($GLOBALS['phpgw_domain']);
284
285                if($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain']))
286                {
287                        $last_loginid .= '@' . $_COOKIE['last_domain'];
288                }
289        }
290        $tmpl->set_var('select_domain',$domain_select);
291
292        foreach($_GET as $name => $value)
293        {
294                if(ereg('phpgw_',$name))
295                {
296                        $extra_vars .= '&' . $name . '=' . urlencode($value);
297                }
298        }
299
300        if($extra_vars)
301        {
302                $extra_vars = '?' . substr($extra_vars,1);
303        }
304
305        /********************************************************\
306        * Check is the registration app is installed, activated  *
307        * And if the register link must be placed                *
308        \********************************************************/
309       
310        $cnf_reg = createobject('phpgwapi.config','registration');
311        $cnf_reg->read_repository();
312        $config_reg = $cnf_reg->config_data;
313
314        if($config_reg[enable_registration]=='True' && $config_reg[register_link]=='True')
315        {
316                $reg_link='&nbsp;<a href="registration/">'.lang('Not a user yet? Register now').'</a><br/>';
317        }
318
319        $GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
320
321        $tmpl->set_var('register_link',$reg_link);
322        $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset());
323        $tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
324        $tmpl->set_var('registration_url',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/');
325        $tmpl->set_var('version',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']);
326        $tmpl->set_var('cd',check_logoutcode($_GET['cd']));
327        $tmpl->set_var('cookie',$last_loginid);
328
329        $tmpl->set_var('lang_username',lang('username'));
330        $tmpl->set_var('lang_password',lang('password'));
331        $tmpl->set_var('lang_login',lang('login'));
332
333        $tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']);
334        $tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']);
335        $tmpl->set_var('bg_color',($GLOBALS['phpgw_info']['server']['login_bg_color']?$GLOBALS['phpgw_info']['server']['login_bg_color']:'FFFFFF'));
336        $tmpl->set_var('bg_color_title',($GLOBALS['phpgw_info']['server']['login_bg_color_title']?$GLOBALS['phpgw_info']['server']['login_bg_color_title']:'486591'));
337
338        if($GLOBALS['phpgw_info']['server']['use_frontend_name'])
339                $tmpl->set_var('frontend_name', " - ".$GLOBALS['phpgw_info']['server']['use_frontend_name']);
340
341        if (substr($GLOBALS['phpgw_info']['server']['login_logo_file'],0,4) == 'http')
342        {
343                $var['logo_file'] = $GLOBALS['phpgw_info']['server']['login_logo_file'];
344        }
345        else
346        {
347                $var['logo_file'] = $GLOBALS['phpgw']->common->image('phpgwapi',$GLOBALS['phpgw_info']['server']['login_logo_file']?$GLOBALS['phpgw_info']['server']['login_logo_file']:'logo');
348        }
349        $var['logo_url'] = $GLOBALS['phpgw_info']['server']['login_logo_url']?$GLOBALS['phpgw_info']['server']['login_logo_url']:'http://www.eGroupWare.org';
350        if (substr($var['logo_url'],0,4) != 'http')
351        {
352                $var['logo_url'] = 'http://'.$var['logo_url'];
353        }
354        $var['logo_title'] = $GLOBALS['phpgw_info']['server']['login_logo_title']?$GLOBALS['phpgw_info']['server']['login_logo_title']:'www.eGroupWare.org';
355        $tmpl->set_var($var);
356
357        if (@$GLOBALS['phpgw_info']['server']['login_show_language_selection'])
358        {
359                $select_lang = '<select name="lang" onchange="'."location.href=location.href+(location.search?'&':'?')+'lang='+this.value".'">';
360                $langs = $GLOBALS['phpgw']->translation->get_installed_langs();
361                uasort($langs,'strcasecmp');
362                foreach ($langs as $key => $name)       // if we have a translation use it
363                {
364                        $select_lang .= "\n\t".'<option value="'.$key.'"'.($key == $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] ? ' selected="1"' : '').'>'.$name.'</option>';
365                }
366                $select_lang .= "\n</select>\n";
367                $tmpl->set_var(array(
368                        'lang_language' => lang('Language'),
369                        'select_language' => $select_lang,
370                ));
371        }
372        else
373        {
374                $tmpl->set_block('login_form','language_select');
375                $tmpl->set_var('language_select','');
376        }
377
378        $tmpl->set_var('autocomplete', ($GLOBALS['phpgw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : ''));
379
380        $tmpl->pfp('loginout','login_form');
381?>
Note: See TracBrowser for help on using the repository browser.