📄 sql.users.class.inc
字号:
function update_profile($user) { if($this->update_row('users', 'id', $user)) { if($user['id'] == $_SESSION['GO_SESSION']['user_id']) { return $this->update_session($user['id']); } return true; } return false; } /* function update_profile($user_id, $first_name, $middle_name, $last_name, $initials, $title, $sex, $birthday, $email, $work_phone, $home_phone, $fax, $cellular, $country, $state, $city, $zip, $address, $company, $work_country, $work_state, $work_city, $work_zip, $work_address, $work_fax, $homepage, $department, $function) { $middle_name = trim($middle_name); $sql = "UPDATE users SET first_name='$first_name', ". "middle_name='$middle_name', last_name='$last_name', ". "initials='$initials', title='$title', sex='$sex', ". "birthday='$birthday', email='$email', work_phone='$work_phone',". "home_phone='$home_phone', fax='$fax', cellular='$cellular',". "country='$country', state='$state', city='$city', zip='$zip', ". "address='$address',company='$company', department='$department',". "function='$function', work_country='$work_country', ". "work_state='$work_state', work_city='$work_city',". "work_zip='$work_zip', work_address='$work_address', ". "work_fax='$work_fax', homepage='$homepage' WHERE id='$user_id'"; if ($this->query($sql)) { if ($user_id == $_SESSION['GO_SESSION']['user_id']) { $middle_name = $middle_name == '' ? '' : $middle_name.' '; $_SESSION['GO_SESSION']['name'] = $first_name.' '.$middle_name.$last_name; $_SESSION['GO_SESSION']['first_name'] = $first_name; $_SESSION['GO_SESSION']['middle_name'] = $middle_name; $_SESSION['GO_SESSION']['last_name'] = $last_name; $_SESSION['GO_SESSION']['email'] = $email; } return true; } return false; }*/ function update_password($user_id, $password) { $sql = "UPDATE users SET password='".md5($password)."' WHERE id='$user_id'"; if ($this->query($sql)) { return true; } return false; } function get_user_by_username($username) { $sql = "SELECT * FROM users WHERE username='$username'"; $this->query($sql); if ($this->next_record()) { return $this->Record; } return false; } function email_exists($email) { $sql = "SELECT id FROM users WHERE email='$email'"; $this->query($sql); if ($this->num_rows() > 0) { return true; } return false; } // the following fields are removed now: acl_id, authcode function add_user( $user, $user_groups=array(), $visible_user_groups=array(), $modules_read=array(), $modules_write=array(), $acl=array()) { global $GO_CONFIG, $GO_LANGUAGE, $GO_SECURITY, $GO_GROUPS, $GO_MODULES; require($GO_LANGUAGE->language_path.'languages.inc'); // We check if we are able to add a new user. If we already have too much // of them we do not want new ones ;) if ( $this->max_users_reached() ) { return false; } // We check if a user with this email address already exists. Since the // email address is used as key for the acl_id, no two users may have the // same address. It also should not be possible to have multiple users // with the same name... $this->query( "SELECT id FROM users WHERE email='".$user['email']."' OR username='".$user['username']."'" ); if ( $this->num_rows() > 0 ) { return false; } //if local_code is empty try HTTP_ACCEPT_LANGUAGE //if that failes use default from GO_CONFIG $hal = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : $GO_CONFIG->language; $language = isset($user['language']) ? $user['language'] : $hal; if (isset($languages[$language])) { $language_info = $languages[$language]; } else { $language_info = $languages[$GO_LANGUAGE->default_language]; } $user['password'] = md5($user['password']); $user['currency'] = isset($language_info['currency']) ? $language_info['currency'] : 'EUR'; $user['decimal_seperator'] = isset($language_info['decimal_seperator']) ? $language_info['decimal_seperator'] : ','; $user['thousands_seperator'] = isset($language_info['thousands_seperator']) ? $language_info['thousands_seperator'] : '.'; $user['time_format'] = isset($language_info['time_format']) ? $language_info['time_format'] : $GO_CONFIG->time_formats[0]; $user['date_format'] = isset($language_info['date_format']) ? $language_info['date_format'] : $GO_CONFIG->date_formats[0]; $user['date_seperator'] = isset($language_info['date_seperator']) ? $language_info['date_seperator'] : $GO_CONFIG->date_seperators[0]; $user['first_weekday'] = isset($language_info['first_weekday']) ? $language_info['first_weekday'] : '1'; $user['timezone'] = isset($language_info['timezone']) ? $language_info['timezone'] : '1'; $user['DST'] = isset($language_info['DST']) ? $language_info['DST'] : '0'; $user['theme'] = isset($user['theme']) ? $user['theme'] : $GO_CONFIG->theme; if (!isset($user['id'])){ $user['id'] = $this->nextid("users"); } $user['acl_id'] = $GO_SECURITY->get_new_acl( $user['email'] ); $user['authcode'] = $this->random_password(); $user['registration_time'] = get_gmt_time(); if ($user['id'] > 0 && $this->insert_row('users', $user)) { $GO_SECURITY->set_acl_owner( $user['acl_id'], $user['id'] ); $GO_GROUPS->add_user_to_group( $user['id'], $GO_CONFIG->group_everyone); foreach($user_groups as $group_id) { if($group_id > 0 && $group_id != $GO_CONFIG->group_everyone) { $GO_GROUPS->add_user_to_group($user['id'], $group_id); } } foreach($visible_user_groups as $group_id) { if($group_id > 0) { $GO_SECURITY->add_group_to_acl($group_id, $user['acl_id']); } } foreach($modules_read as $module_name) { if($module = $GO_MODULES->get_module($module_name)) { $GO_SECURITY->add_user_to_acl($user['id'], $module['acl_read']); } } foreach($modules_write as $module_name) { if($module = $GO_MODULES->get_module($module_name)) { $GO_SECURITY->add_user_to_acl($user['id'], $module['acl_write']); } } foreach($acl as $acl_id) { $GO_SECURITY->add_user_to_acl($user['id'], $acl_id); } return $user['id']; } else { $GO_SECURITY->delete_acl( $user['id'] ); } return false; } function max_users_reached() { global $GO_CONFIG; if($this->get_users() < $GO_CONFIG->max_users || $GO_CONFIG->max_users == 0) { return false; }else { return true; } } /*function set_preferences($user_id, $date_format, $time_format, $thousands_seperator, $decimal_seperator, $currency, $mail_client, $max_rows_list, $timezone_offset,$DST, $start_module, $language, $theme, $first_weekday, $sort_name) { global $GO_LANGUAGE; if($this->query("UPDATE users SET time_format='$time_format', ". "date_format='$date_format', ". "thousands_seperator='$thousands_seperator', ". "decimal_seperator='$decimal_seperator', ". "currency='$currency', ". "mail_client='$mail_client', max_rows_list='$max_rows_list', ". "timezone='$timezone_offset', ". "DST='$DST', ". "start_module='$start_module', ". "theme='$theme', ". "language='$language', ". "first_weekday='$first_weekday', ". "sort_name='$sort_name' ". "WHERE id='$user_id'")) { $GO_LANGUAGE->set_language($language); $this->update_session($user_id); } } /** * This function stores the user's language * * @access public * * @param int $user_id * @param string $language * * @return bool function set_language($user_id, $language) { global $GO_LANGUAGE; if($this->query("UPDATE users SET ". "language='$language' ". "WHERE id='$user_id'")) { $GO_LANGUAGE->set_language($language); $this->update_session($user_id); } } /** * This function stores the user's start module * * @access public * * @param int $user_id * @param string $module_id * * @return bool function set_start_module($user_id, $module_id) { return $this->query("UPDATE users SET ". "start_module='$module_id' ". "WHERE id='$user_id'"); } function set_notations($user_id, $date_format, $time_format, $thousands_seperator, $decimal_seperator, $currency, $timezone_offset,$DST, $first_weekday, $sort_name) { global $GO_LANGUAGE; if($this->query("UPDATE users SET time_format='$time_format', ". "date_format='$date_format', ". "thousands_seperator='$thousands_seperator', ". "decimal_seperator='$decimal_seperator', ". "currency='$currency', ". "timezone='$timezone_offset', ". "DST='$DST', ". "first_weekday='$first_weekday', ". "sort_name='$sort_name' ". "WHERE id='$user_id'")) { $this->update_session($user_id); } } function set_look_and_feel($user_id, $max_rows_list, $start_module, $language, $theme) { global $GO_LANGUAGE; if($this->query("UPDATE users SET max_rows_list='$max_rows_list', ". "start_module='$start_module', ". "theme='$theme', ". "language='$language' ". "WHERE id='$user_id'")) { $GO_LANGUAGE->set_language($language); $this->update_session($user_id); } }*/ function delete_user($user_id) { global $GO_CONFIG,$GO_SECURITY, $GO_MODULES, $GO_GROUPS; if($user = $this->get_user($user_id)) { $acl_id = $this->f("acl_id"); $username = $this->f("username"); $sql = "DELETE FROM users WHERE id='$user_id'"; if ($this->query($sql)) { $GO_SECURITY->delete_acl($acl_id); $GO_SECURITY->delete_user($user_id); foreach($GO_MODULES->modules as $module) { if(file_exists($module['class_path'].$module['id'].'.class.inc')) { require_once($module['class_path'].$module['id'].'.class.inc'); $module_object = new $module['id']; if(method_exists($module_object, 'delete_user')) { $module_object->delete_user($user_id); } } } $GO_GROUPS->delete_user($user_id); if(file_exists($GO_CONFIG->root_path.'sync/classes/syncml.class.inc')) { require_once($GO_CONFIG->root_path.'sync/classes/syncml.class.inc'); $sync_settings = new syncml_settings(); $sync_settings->delete_user($user_id); } /*$sql = "SELECT * FROM acl_items WHERE user_id='$user_id'"; $this->query($sql); while($this->next_record()) { $GO_SECURITY->delete_acl($this->f('id')); }*/ system('rm -Rf '.$GO_CONFIG->file_storage_path.$username); return true; } } return false; } function increment_logins( $user_id ) { $sql = "UPDATE users SET logins=logins+1, lastlogin='".get_gmt_time(). "' WHERE id='$user_id'"; $this->query( $sql ); }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -