]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Users/Login.php
Release 6.2.4
[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-2011 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     $nav = '';
51     $nav .= (isset($_GET['login_module'])) ? '&module='.$_GET['login_module'] : '';
52     $nav .= (isset($_GET['login_action'])) ? '&action='.$_GET['login_action'] : '';
53     $nav .= (isset($_GET['login_record'])) ? '&record='.$_GET['login_record'] : '';
54     
55     ($nav == '') 
56         ? header("Location: index.php?module=Home&action=index") 
57         : header("Location: index.php?".substr($nav, 1));
58     
59     sugar_cleanup(true);
60     return;
61 }
62 global $current_language, $mod_strings, $app_strings;
63 if(isset($_REQUEST['login_language'])){
64     $lang = $_REQUEST['login_language'];
65     $_REQUEST['ck_login_language_20'] = $lang;
66         $current_language = $lang;
67     $_SESSION['authenticated_user_language'] = $lang;
68     $mod_strings = return_module_language($lang, "Users");
69     $app_strings = return_application_language($lang);
70 }
71 $sugar_smarty = new Sugar_Smarty();
72 echo '<link rel="stylesheet" type="text/css" media="all" href="'.getJSPath('modules/Users/login.css').'">';
73 echo '<script type="text/javascript" src="'.getJSPath('modules/Users/login.js').'"></script>';
74 global $app_language, $sugar_config;
75 //we don't want the parent module's string file, but rather the string file specifc to this subpanel
76 global $current_language;
77
78 // Get the login page image
79 if ( sugar_is_file('custom/include/images/sugar_md.png') ) {
80     $login_image = '<IMG src="custom/include/images/sugar_md.png" alt="Sugar" width="340" height="25">';
81 }
82 else {
83     $login_image = '<IMG src="include/images/sugar_md_open.png" alt="Sugar" width="340" height="25" style="margin: 5px 0;">';
84 }
85 $sugar_smarty->assign('LOGIN_IMAGE',$login_image);
86
87 // See if any messages were passed along to display to the user.
88 if(isset($_COOKIE['loginErrorMessage'])) {
89     if ( !isset($_REQUEST['loginErrorMessage']) ) {
90         $_REQUEST['loginErrorMessage'] = $_COOKIE['loginErrorMessage'];
91     }
92     SugarApplication::setCookie('loginErrorMessage', '', time()-42000, '/');
93 }
94 if(isset($_REQUEST['loginErrorMessage'])) {
95     if (isset($mod_strings[$_REQUEST['loginErrorMessage']])) {
96         echo "<p align='center' class='error' > ". $mod_strings[$_REQUEST['loginErrorMessage']]. "</p>";
97     } else if (isset($app_strings[$_REQUEST['loginErrorMessage']])) {
98         echo "<p align='center' class='error' > ". $app_strings[$_REQUEST['loginErrorMessage']]. "</p>";
99     }
100 }
101 $query = "SELECT count(id) as total from users WHERE status='Active' AND deleted=0 AND is_group=0 AND portal_only=0";
102
103
104
105 if (isset($_GET['login_module']))
106         $sugar_smarty->assign('LOGIN_MODULE', $_GET['login_module']);
107 if (isset($_GET['login_action']))
108         $sugar_smarty->assign('LOGIN_ACTION', $_GET['login_action']);
109 if (isset($_GET['login_record']))
110         $sugar_smarty->assign('LOGIN_RECORD', $_GET['login_record']);
111
112 // Retrieve username from the session if possible.
113 if(isset($_SESSION["login_user_name"])) {
114         if (isset($_REQUEST['default_user_name']))
115                 $login_user_name = $_REQUEST['default_user_name'];
116         else
117                 $login_user_name = $_SESSION['login_user_name'];
118 } else {
119         if(isset($_REQUEST['default_user_name'])) {
120                 $login_user_name = $_REQUEST['default_user_name'];
121         } elseif(isset($_REQUEST['ck_login_id_20'])) {
122                 $login_user_name = get_user_name($_REQUEST['ck_login_id_20']);
123         } else {
124                 $login_user_name = $sugar_config['default_user_name'];
125         }
126         $_SESSION['login_user_name'] = $login_user_name;
127 }
128 $sugar_smarty->assign('LOGIN_USER_NAME', $login_user_name);
129
130 $mod_strings['VLD_ERROR'] = $GLOBALS['app_strings']["\x4c\x4f\x47\x49\x4e\x5f\x4c\x4f\x47\x4f\x5f\x45\x52\x52\x4f\x52"];
131
132 // Retrieve password from the session if possible.
133 if(isset($_SESSION["login_password"])) {
134         $login_password = $_SESSION['login_password'];
135 } else {
136         $login_password = $sugar_config['default_password'];
137         $_SESSION['login_password'] = $login_password;
138 }
139 $sugar_smarty->assign('LOGIN_PASSWORD', $login_password);
140
141 if(isset($_SESSION["login_error"])) {
142         $sugar_smarty->assign('LOGIN_ERROR', $_SESSION['login_error']);
143 }
144 if(isset($_SESSION["waiting_error"])) {
145     $sugar_smarty->assign('WAITING_ERROR', $_SESSION['waiting_error']);
146 }
147
148 if (isset($_REQUEST['ck_login_language_20'])) {
149         $display_language = $_REQUEST['ck_login_language_20'];
150 } else {
151         $display_language = $sugar_config['default_language'];
152 }
153
154 if (empty($GLOBALS['sugar_config']['passwordsetting']['forgotpasswordON']))
155         $sugar_smarty->assign('DISPLAY_FORGOT_PASSWORD_FEATURE','none');
156
157 $the_languages = get_languages();
158 if ( count($the_languages) > 1 )
159     $sugar_smarty->assign('SELECT_LANGUAGE', get_select_options_with_id($the_languages, $display_language));
160 $the_themes = SugarThemeRegistry::availableThemes();
161 if ( !empty($logindisplay) )
162         $sugar_smarty->assign('LOGIN_DISPLAY', $logindisplay);;
163
164 // RECAPTCHA
165
166         $admin = new Administration();
167         $admin->retrieveSettings('captcha');
168         $captcha_privatekey = "";
169         $captcha_publickey="";
170         $captcha_js = "";
171         $Captcha='';
172
173         // if the admin set the captcha stuff, assign javascript and div
174         if(isset($admin->settings['captcha_on'])&& $admin->settings['captcha_on']=='1' && !empty($admin->settings['captcha_private_key']) && !empty($admin->settings['captcha_public_key'])){
175
176                         $captcha_privatekey = $admin->settings['captcha_private_key'];
177                         $captcha_publickey = $admin->settings['captcha_public_key'];
178                         $captcha_js .="<script type='text/javascript' src='" . getJSPath('include/javascript/sugar_grp1_yui.js') . "'></script><script type='text/javascript' src='" . getJSPath('include/javascript/sugar_grp_yui2.js') . "'></script>
179                         <script type='text/javascript' src='http://api.recaptcha.net/js/recaptcha_ajax.js'></script>
180                         <script>
181                         function initCaptcha(){
182                         Recaptcha.create('$captcha_publickey' ,'captchaImage',{theme:'custom'});
183                         }
184                         window.onload=initCaptcha;
185
186                         var handleFailure=handleSuccess;
187                         var handleSuccess = function(o){
188                                 if(o.responseText!==undefined && o.responseText =='Success'){
189                                         generatepwd();
190                                         Recaptcha.reload();
191                                 }
192                                 else{
193                                         if(o.responseText!='')
194                                                 document.getElementById('generate_success').innerHTML =o.responseText;
195                                         Recaptcha.reload();
196                                 }
197                         }
198                         var callback2 ={ success:handleSuccess, failure: handleFailure };
199
200                         function validateAndSubmit(){
201                                         var form = document.getElementById('form');
202                                         var url = '&to_pdf=1&module=Home&action=index&entryPoint=Changenewpassword&recaptcha_challenge_field='+Recaptcha.get_challenge()+'&recaptcha_response_field='+ Recaptcha.get_response();
203                                         YAHOO.util.Connect.asyncRequest('POST','index.php',callback2,url);
204                         }</script>";
205                 $Captcha.="<tr>
206                         <td scope='row' width='20%'>".$mod_strings['LBL_RECAPTCHA_INSTRUCTION'].":</td>
207                     <td width='70%'><input type='text' size='26' id='recaptcha_response_field' value=''></td>
208
209                 </tr>
210                 <tr>
211
212                         <td colspan='2'><div style='margin-left:2px'class='x-sqs-list' id='recaptcha_image'></div></td>
213                 </tr>
214                 <tr>
215                         <td colspan='2' align='right'><a href='javascript:Recaptcha.reload()'>".$mod_strings['LBL_RECAPTCHA_NEW_CAPTCHA']."</a>&nbsp;&nbsp;
216                                         <a class='recaptcha_only_if_image' href='javascript:Recaptcha.switch_type(\"audio\")'>".$mod_strings['LBL_RECAPTCHA_SOUND']."</a>
217                                         <a class='recaptcha_only_if_audio' href='javascript:Recaptcha.switch_type(\"image\")'> ".$mod_strings['LBL_RECAPTCHA_IMAGE']."</a>
218                         </td>
219                 </tr>";
220                 $sugar_smarty->assign('CAPTCHA', $Captcha);
221                 echo $captcha_js;
222
223         }else{
224                 echo "<script>
225                 function validateAndSubmit(){generatepwd();}
226                 </script>";
227         }
228
229 $sugar_smarty->display('modules/Users/login.tpl'); ?>