]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Users/Login.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Users / Login.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description: TODO:  To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45 if (isset($_SESSION['authenticated_user_id']))
46 {
47     ob_clean();
48     // fixing bug #46837: Previosly links/URLs to records in Sugar from MSO Excel/Word were referred to the home screen and not the record
49     // It used to appear when default browser was not MS IE
50     header("Location: ".$GLOBALS['app']->getLoginRedirect());
51     sugar_cleanup(true);
52     return;
53 }
54 global $current_language, $mod_strings, $app_strings;
55 if(isset($_REQUEST['login_language'])){
56     $lang = $_REQUEST['login_language'];
57     $_REQUEST['ck_login_language_20'] = $lang;
58         $current_language = $lang;
59     $_SESSION['authenticated_user_language'] = $lang;
60     $mod_strings = return_module_language($lang, "Users");
61     $app_strings = return_application_language($lang);
62 }
63 $sugar_smarty = new Sugar_Smarty();
64 echo '<link rel="stylesheet" type="text/css" media="all" href="'.getJSPath('modules/Users/login.css').'">';
65 echo '<script type="text/javascript" src="'.getJSPath('modules/Users/login.js').'"></script>';
66 global $app_language, $sugar_config;
67 //we don't want the parent module's string file, but rather the string file specifc to this subpanel
68 global $current_language;
69
70 // Get the login page image
71 if ( sugar_is_file('custom/include/images/sugar_md.png') ) {
72     $login_image = '<IMG src="custom/include/images/sugar_md.png" alt="Sugar" width="340" height="25">';
73 }
74 else {
75     $login_image = '<IMG src="include/images/sugar_md_open.png" alt="Sugar" width="340" height="25" style="margin: 5px 0;">';
76 }
77 $sugar_smarty->assign('LOGIN_IMAGE',$login_image);
78
79 // See if any messages were passed along to display to the user.
80 if(isset($_COOKIE['loginErrorMessage'])) {
81     if ( !isset($_REQUEST['loginErrorMessage']) ) {
82         $_REQUEST['loginErrorMessage'] = $_COOKIE['loginErrorMessage'];
83     }
84     SugarApplication::setCookie('loginErrorMessage', '', time()-42000, '/');
85 }
86 if(isset($_REQUEST['loginErrorMessage'])) {
87     if (isset($mod_strings[$_REQUEST['loginErrorMessage']])) {
88         echo "<p align='center' class='error' > ". $mod_strings[$_REQUEST['loginErrorMessage']]. "</p>";
89     } else if (isset($app_strings[$_REQUEST['loginErrorMessage']])) {
90         echo "<p align='center' class='error' > ". $app_strings[$_REQUEST['loginErrorMessage']]. "</p>";
91     }
92 }
93
94 $lvars = $GLOBALS['app']->getLoginVars();
95 $sugar_smarty->assign("LOGIN_VARS", $lvars);
96 foreach($lvars as $k => $v) {
97     $sugar_smarty->assign(strtoupper($k), $v);
98 }
99
100 // Retrieve username from the session if possible.
101 if(isset($_SESSION["login_user_name"])) {
102         if (isset($_REQUEST['default_user_name']))
103                 $login_user_name = $_REQUEST['default_user_name'];
104         else
105                 $login_user_name = $_SESSION['login_user_name'];
106 } else {
107         if(isset($_REQUEST['default_user_name'])) {
108                 $login_user_name = $_REQUEST['default_user_name'];
109         } elseif(isset($_REQUEST['ck_login_id_20'])) {
110                 $login_user_name = get_user_name($_REQUEST['ck_login_id_20']);
111         } else {
112                 $login_user_name = $sugar_config['default_user_name'];
113         }
114         $_SESSION['login_user_name'] = $login_user_name;
115 }
116 $sugar_smarty->assign('LOGIN_USER_NAME', $login_user_name);
117
118 $mod_strings['VLD_ERROR'] = $GLOBALS['app_strings']["\x4c\x4f\x47\x49\x4e\x5f\x4c\x4f\x47\x4f\x5f\x45\x52\x52\x4f\x52"];
119
120 // Retrieve password from the session if possible.
121 if(isset($_SESSION["login_password"])) {
122         $login_password = $_SESSION['login_password'];
123 } else {
124         $login_password = $sugar_config['default_password'];
125         $_SESSION['login_password'] = $login_password;
126 }
127 $sugar_smarty->assign('LOGIN_PASSWORD', $login_password);
128
129 if(isset($_SESSION["login_error"])) {
130         $sugar_smarty->assign('LOGIN_ERROR', $_SESSION['login_error']);
131 }
132 if(isset($_SESSION["waiting_error"])) {
133     $sugar_smarty->assign('WAITING_ERROR', $_SESSION['waiting_error']);
134 }
135
136 if (isset($_REQUEST['ck_login_language_20'])) {
137         $display_language = $_REQUEST['ck_login_language_20'];
138 } else {
139         $display_language = $sugar_config['default_language'];
140 }
141
142 if (empty($GLOBALS['sugar_config']['passwordsetting']['forgotpasswordON']))
143         $sugar_smarty->assign('DISPLAY_FORGOT_PASSWORD_FEATURE','none');
144
145 $the_languages = get_languages();
146 if ( count($the_languages) > 1 )
147     $sugar_smarty->assign('SELECT_LANGUAGE', get_select_options_with_id($the_languages, $display_language));
148 $the_themes = SugarThemeRegistry::availableThemes();
149 if ( !empty($logindisplay) )
150         $sugar_smarty->assign('LOGIN_DISPLAY', $logindisplay);;
151
152 // RECAPTCHA
153
154         $admin = new Administration();
155         $admin->retrieveSettings('captcha');
156         $captcha_privatekey = "";
157         $captcha_publickey="";
158         $captcha_js = "";
159         $Captcha='';
160
161         // if the admin set the captcha stuff, assign javascript and div
162         if(isset($admin->settings['captcha_on'])&& $admin->settings['captcha_on']=='1' && !empty($admin->settings['captcha_private_key']) && !empty($admin->settings['captcha_public_key'])){
163
164                         $captcha_privatekey = $admin->settings['captcha_private_key'];
165                         $captcha_publickey = $admin->settings['captcha_public_key'];
166                         $captcha_js .="<script type='text/javascript' src='" . getJSPath('cache/include/javascript/sugar_grp1_yui.js') . "'></script><script type='text/javascript' src='" . getJSPath('cache/include/javascript/sugar_grp_yui2.js') . "'></script>
167                         <script type='text/javascript' src='http://api.recaptcha.net/js/recaptcha_ajax.js'></script>
168                         <script>
169                         function initCaptcha(){
170                         Recaptcha.create('$captcha_publickey' ,'captchaImage',{theme:'custom'});
171                         }
172                         window.onload=initCaptcha;
173
174                         var handleFailure=handleSuccess;
175                         var handleSuccess = function(o){
176                                 if(o.responseText!==undefined && o.responseText =='Success'){
177                                         generatepwd();
178                                         Recaptcha.reload();
179                                 }
180                                 else{
181                                         if(o.responseText!='')
182                                                 document.getElementById('generate_success').innerHTML =o.responseText;
183                                         Recaptcha.reload();
184                                 }
185                         }
186                         var callback2 ={ success:handleSuccess, failure: handleFailure };
187
188                         function validateAndSubmit(){
189                                         var form = document.getElementById('form');
190                                         var url = '&to_pdf=1&module=Home&action=index&entryPoint=Changenewpassword&recaptcha_challenge_field='+Recaptcha.get_challenge()+'&recaptcha_response_field='+ Recaptcha.get_response();
191                                         YAHOO.util.Connect.asyncRequest('POST','index.php',callback2,url);
192                         }</script>";
193                 $Captcha.="<tr>
194                         <td scope='row' width='20%'>".$mod_strings['LBL_RECAPTCHA_INSTRUCTION'].":</td>
195                     <td width='70%'><input type='text' size='26' id='recaptcha_response_field' value=''></td>
196
197                 </tr>
198                 <tr>
199
200                         <td colspan='2'><div style='margin-left:2px'class='x-sqs-list' id='recaptcha_image'></div></td>
201                 </tr>
202                 <tr>
203                         <td colspan='2' align='right'><a href='javascript:Recaptcha.reload()'>".$mod_strings['LBL_RECAPTCHA_NEW_CAPTCHA']."</a>&nbsp;&nbsp;
204                                         <a class='recaptcha_only_if_image' href='javascript:Recaptcha.switch_type(\"audio\")'>".$mod_strings['LBL_RECAPTCHA_SOUND']."</a>
205                                         <a class='recaptcha_only_if_audio' href='javascript:Recaptcha.switch_type(\"image\")'> ".$mod_strings['LBL_RECAPTCHA_IMAGE']."</a>
206                         </td>
207                 </tr>";
208                 $sugar_smarty->assign('CAPTCHA', $Captcha);
209                 echo $captcha_js;
210
211         }else{
212                 echo "<script>
213                 function validateAndSubmit(){generatepwd();}
214                 </script>";
215         }
216
217 $sugar_smarty->display('modules/Users/login.tpl'); ?>