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.
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.
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
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
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.
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.
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 ********************************************************************************/
38 /*********************************************************************************
40 * Description: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
46 require_once('include/entryPoint.php');
48 require_once('modules/Users/language/en_us.lang.php');
54 $mod_strings=return_module_language('','Users');
55 $res=$GLOBALS['sugar_config']['passwordsetting'];
56 $regexmail = "/^\w+(['\.\-\+]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+\$/";
58 ///////////////////////////////////////////////////
62 if(isset( $_POST['user_name'])){
63 $username = $_POST['user_name'];
64 }else if(isset( $_POST['username'])){
65 $username = $_POST['username'];
68 if(isset( $_POST['Users0emailAddress0'])){
69 $useremail = $_POST['Users0emailAddress0'];
70 }else if(isset( $_POST['user_email'])){
71 $useremail = $_POST['user_email'];
75 if(isset($username) && $username != '' && isset($useremail) && $useremail != '')
77 if ($username != '' && $useremail != ''){
78 $usr_id=$usr->retrieve_user_id($username);
79 $usr->retrieve($usr_id);
80 if ($usr->email1 != $useremail){
81 echo $mod_strings['LBL_PROVIDE_USERNAME_AND_EMAIL'];
85 if ($usr->portal_only || $usr->is_group){
86 echo $mod_strings['LBL_PROVIDE_USERNAME_AND_EMAIL'];
92 echo $mod_strings['LBL_PROVIDE_USERNAME_AND_EMAIL'];
97 if (isset($_POST['userId']) && $_POST['userId'] != ''){
98 $usr->retrieve($_POST['userId']);
101 if(!empty( $_POST['sugar_user_name'])){
102 $usr_id=$usr->retrieve_user_id($_POST['sugar_user_name']);
103 $usr->retrieve($usr_id);
106 echo $mod_strings['LBL_PROVIDE_USERNAME_AND_EMAIL'];
111 // Check if current_user is admin or the same user
112 if(empty($current_user->id) || empty($usr->id) || ($usr->id != $current_user->id && !$current_user->is_admin)) {
113 echo $mod_strings['LBL_PROVIDE_USERNAME_AND_EMAIL'];
119 ///////////////////////////////////////////////////
121 ///////////////////////////////////////////////////
122 /////// Check email address
124 if (!preg_match($regexmail, $usr->emailAddress->getPrimaryAddress($usr))){
125 echo $mod_strings['ERR_EMAIL_INCORRECT'];
130 ///////////////////////////////////////////////////
131 $isLink = isset($_POST['link']) && $_POST['link'] == '1';
132 // if i need to generate a password (not a link)
133 $password = $isLink ? '' : User::generatePassword();
135 ///////////////////////////////////////////////////
138 // if i need to generate a link
142 $url=$GLOBALS['sugar_config']['site_url']."/index.php?entryPoint=Changenewpassword&guid=$guid";
143 $time_now=TimeDate::getInstance()->nowDb();
144 //$q2="UPDATE `users_password_link` SET `deleted` = '1' WHERE `username` = '".$username."'";
145 //$usr->db->query($q2);
146 $q = "INSERT INTO users_password_link (id, username, date_generated) VALUES('".$guid."','".$username."','".$time_now."') ";
150 ///////////////////////////////////////////////////
152 /////// Email creation
154 $emailTemp_id = $res['lostpasswordtmpl'];
156 $emailTemp_id = $res['generatepasswordtmpl'];
158 $additionalData = array(
160 'password' => $password
164 $additionalData['url'] = $url;
166 $result = $usr->sendEmailForPassword($emailTemp_id, $additionalData);
167 if ($result['status'] == false && $result['message'] != '')
169 echo $result['message'];
174 if ($result['status'] == true)
179 if ($current_user->is_admin){
180 $email_errors=$mod_strings['ERR_EMAIL_NOT_SENT_ADMIN'];
181 $email_errors.="\n-".$mod_strings['ERR_RECIPIENT_EMAIL'];
182 $email_errors.="\n-".$mod_strings['ERR_SERVER_STATUS'];
186 echo $mod_strings['LBL_EMAIL_NOT_SENT'];