source: trunk/phpgwapi/templates/classic/login_celepar.php @ 1151

Revision 1151, 13.5 KB checked in by amuller, 15 years ago (diff)

Ticket #475 - Mudando o nome dos templates azul para default e celepar para 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/////   Início - Código temporário: Para renomeação de login com organização para sem. //////
108/*              $common = CreateObject('phpgwapi.common');
109                $ldap_conn = $common->ldapConnect();
110                $justthese = array("uid");
111                $filter="(&(phpgwAccountType=u)(uid=".$_POST['user']."))";
112                $ldap_search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
113                $ldap_info       = ldap_get_entries($ldap_conn, $ldap_search);
114                if ($ldap_info['count'] != 0) // Verifica se o login existe sem organização.
115                {
116                        $_POST['login'] = $_POST['user'];
117                }
118                ldap_close($ldap_conn);*/
119///     Fim - Código temporário: Para renomeação de login com organização para sem. //////
120                if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' &&
121                        !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN']))
122                {
123                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=5'));
124                }
125               
126                // don't get login data again when $submit is true
127                if($submit == false)
128                {
129                        $login = $_POST['login'];
130                }
131               
132                if(strstr($login,'@') === False && isset($_POST['logindomain']))
133                {
134                        $login .= '@' . $_POST['logindomain'];
135                }
136                elseif(!isset($GLOBALS['phpgw_domain'][$GLOBALS['phpgw_info']['user']['domain']]))
137                {
138                        $login .= '@'.$GLOBALS['phpgw_info']['server']['default_domain'];
139                }
140                $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u');
141
142                if(!isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid'])
143                {
144                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason);
145                }
146                else
147                {
148                        if ($_POST['lang'] && preg_match('/^[a-z]{2}(-[a-z]{2}){0,1}$/',$_POST['lang']) &&
149                            $_POST['lang'] != $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
150                        {
151                                $GLOBALS['phpgw']->preferences->add('common','lang',$_POST['lang'],'session');
152                        }
153
154                        if(!$GLOBALS['phpgw_info']['server']['disable_autoload_langfiles'])
155                        {
156                                $GLOBALS['phpgw']->translation->autoload_changed_langfiles();
157                        }
158                        $forward = isset($_GET['phpgw_forward']) ? urldecode($_GET['phpgw_forward']) : @$_POST['phpgw_forward'];
159                        if (!$forward)
160                        {
161                                $extra_vars['cd'] = 'yes';
162                                $forward = '/home.php';
163                        }
164                        else
165                        {
166                                list($forward,$extra_vars) = explode('?',$forward,2);
167                        }
168                        if ($GLOBALS['phpgw_info']['server']['use_https'] != 2)
169                        {
170                                $forward = 'http://'.$_SERVER['HTTP_HOST'].($GLOBALS['phpgw']->link($forward.'?cd=yes'));
171                                echo "<script language='Javascript1.3'>location.href='".$forward."'</script>";
172                        }
173                        else
174                        {
175                                $GLOBALS['phpgw']->redirect_link($forward,$extra_vars);
176                        }
177                }
178        }
179        else
180        {
181                // !!! DONT CHANGE THESE LINES !!!
182                // If there is something wrong with this code TELL ME!
183                // Commenting out the code will not fix it. (jengo)
184                if(isset($_COOKIE['last_loginid']))
185                {
186                        $accounts = CreateObject('phpgwapi.accounts');
187                        $prefs = CreateObject('phpgwapi.preferences', $accounts->name2id($_COOKIE['last_loginid']));
188
189                        if($prefs->account_id)
190                        {
191                                $GLOBALS['phpgw_info']['user']['preferences'] = $prefs->read_repository();
192                        }
193                }
194                if ($_GET['lang'])
195                {
196                        $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang'];
197                }
198                elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id)
199                {
200                        // If the lastloginid cookies isn't set, we will default to the first language,
201                        // the users browser accepts.
202                        list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
203                        /*
204                        if(strlen($lang) > 2)
205                        {
206                                $lang = substr($lang,0,2);
207                        }
208                        */
209                        $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang;
210                }
211                #print 'LANG:' . $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] . '<br>';
212
213                $GLOBALS['phpgw']->translation->init(); // this will set the language according to the (new) set prefs
214                $GLOBALS['phpgw']->translation->add_app('login');
215                $GLOBALS['phpgw']->translation->add_app('loginscreen');
216                if(lang('loginscreen_message') == 'loginscreen_message*')
217                {
218                        $GLOBALS['phpgw']->translation->add_app('loginscreen','en');    // trying the en one
219                }
220                if(lang('loginscreen_message') != 'loginscreen_message*')
221                {
222                        $tmpl->set_var('lang_message',stripslashes(lang('loginscreen_message')));
223                }
224        }
225
226        if($GLOBALS['phpgw_info']['server']['use_prefix_organization'])
227        {
228                $organization_select = "<tr><td width=\"66\" class=\"loginLabel\">";
229                $organization_select .= lang("organization").":</td>";
230                $organization_select .="<td width=\"135\">";                                                                                   
231                $organization_select .="<select name=\"organization\">\n";             
232               
233                $obj_organization = CreateObject('phpgwapi.sector_search_ldap');
234                $organizations = $obj_organization->organization_search($GLOBALS['phpgw_info']['server']['ldap_context']);
235               
236                for ($i=0; $i<count($organizations); $i++)
237                {
238                        $tmp_array[strtolower($organizations[$i])] = $organizations[$i];       
239                }
240               
241                $arrayOrganization = $tmp_array;               
242                ksort($arrayOrganization);
243               
244                foreach($arrayOrganization
245                         as $organization_name => $organization_vars)
246                {
247                        $organization_select .= '<option value="' . $organization_name . '"';
248
249                        if($organization_name == $_COOKIE['last_organization'])
250                        {
251                                $organization_select .= ' selected';
252                        }
253                        $organization_select .= '>' . $organization_vars . "</option>\n";
254                }
255                $organization_select .= "</select>\n";
256                $organization_select .="</td><td>&nbsp;</td></tr>";
257                $tmpl->set_var('select_organization',$organization_select);
258        }
259               
260        $domain_select = '&nbsp;';
261        $last_loginid = $_COOKIE['last_loginid'];
262        if($GLOBALS['phpgw_info']['server']['show_domain_selectbox'])
263        {
264                $domain_select = "<select name=\"logindomain\">\n";
265                foreach($GLOBALS['phpgw_domain'] as $domain_name => $domain_vars)
266                {
267                        $domain_select .= '<option value="' . $domain_name . '"';
268
269                        if($domain_name == $_COOKIE['last_domain'])
270                        {
271                                $domain_select .= ' selected';
272                        }
273                        $domain_select .= '>' . $domain_name . "</option>\n";
274                }
275                $domain_select .= "</select>\n";
276        }
277        elseif($last_loginid !== '')
278        {
279                reset($GLOBALS['phpgw_domain']);
280                list($default_domain) = each($GLOBALS['phpgw_domain']);
281
282                if($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain']))
283                {
284                        $last_loginid .= '@' . $_COOKIE['last_domain'];
285                }
286        }
287        $tmpl->set_var('select_domain',$domain_select);
288
289        foreach($_GET as $name => $value)
290        {
291                if(ereg('phpgw_',$name))
292                {
293                        $extra_vars .= '&' . $name . '=' . urlencode($value);
294                }
295        }
296
297        if($extra_vars)
298        {
299                $extra_vars = '?' . substr($extra_vars,1);
300        }
301
302        /********************************************************\
303        * Check is the registration app is installed, activated  *
304        * And if the register link must be placed                *
305        \********************************************************/
306       
307        $cnf_reg = createobject('phpgwapi.config','registration');
308        $cnf_reg->read_repository();
309        $config_reg = $cnf_reg->config_data;
310
311        if($config_reg[enable_registration]=='True' && $config_reg[register_link]=='True')
312        {
313                $reg_link='&nbsp;<a href="registration/">'.lang('Not a user yet? Register now').'</a><br/>';
314        }
315
316        $GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
317
318        $tmpl->set_var('register_link',$reg_link);
319        $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset());
320        $tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
321        $tmpl->set_var('registration_url',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/');
322        $tmpl->set_var('version',$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']);
323        $tmpl->set_var('cd',check_logoutcode($_GET['cd']));
324        $tmpl->set_var('cookie',$last_loginid);
325
326        $tmpl->set_var('lang_username',lang('username'));
327        $tmpl->set_var('lang_password',lang('password'));
328        $tmpl->set_var('lang_login',lang('login'));
329
330        $tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']);
331        $tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']);
332        $tmpl->set_var('bg_color',($GLOBALS['phpgw_info']['server']['login_bg_color']?$GLOBALS['phpgw_info']['server']['login_bg_color']:'FFFFFF'));
333        $tmpl->set_var('bg_color_title',($GLOBALS['phpgw_info']['server']['login_bg_color_title']?$GLOBALS['phpgw_info']['server']['login_bg_color_title']:'486591'));
334
335        if($GLOBALS['phpgw_info']['server']['use_frontend_name'])
336                $tmpl->set_var('frontend_name', " - ".$GLOBALS['phpgw_info']['server']['use_frontend_name']);
337
338        if (substr($GLOBALS['phpgw_info']['server']['login_logo_file'],0,4) == 'http')
339        {
340                $var['logo_file'] = $GLOBALS['phpgw_info']['server']['login_logo_file'];
341        }
342        else
343        {
344                $var['logo_file'] = $GLOBALS['phpgw']->common->image('phpgwapi',$GLOBALS['phpgw_info']['server']['login_logo_file']?$GLOBALS['phpgw_info']['server']['login_logo_file']:'logo');
345        }
346        $var['logo_url'] = $GLOBALS['phpgw_info']['server']['login_logo_url']?$GLOBALS['phpgw_info']['server']['login_logo_url']:'http://www.eGroupWare.org';
347        if (substr($var['logo_url'],0,4) != 'http')
348        {
349                $var['logo_url'] = 'http://'.$var['logo_url'];
350        }
351        $var['logo_title'] = $GLOBALS['phpgw_info']['server']['login_logo_title']?$GLOBALS['phpgw_info']['server']['login_logo_title']:'www.eGroupWare.org';
352        $tmpl->set_var($var);
353
354        if (@$GLOBALS['phpgw_info']['server']['login_show_language_selection'])
355        {
356                $select_lang = '<select name="lang" onchange="'."location.href=location.href+(location.search?'&':'?')+'lang='+this.value".'">';
357                $langs = $GLOBALS['phpgw']->translation->get_installed_langs();
358                uasort($langs,'strcasecmp');
359                foreach ($langs as $key => $name)       // if we have a translation use it
360                {
361                        $select_lang .= "\n\t".'<option value="'.$key.'"'.($key == $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] ? ' selected="1"' : '').'>'.$name.'</option>';
362                }
363                $select_lang .= "\n</select>\n";
364                $tmpl->set_var(array(
365                        'lang_language' => lang('Language'),
366                        'select_language' => $select_lang,
367                ));
368        }
369        else
370        {
371                $tmpl->set_block('login_form','language_select');
372                $tmpl->set_var('language_select','');
373        }
374
375        $tmpl->set_var('autocomplete', ($GLOBALS['phpgw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : ''));
376
377        $tmpl->pfp('loginout','login_form');
378?>
Note: See TracBrowser for help on using the repository browser.