| Server IP : 103.48.194.25 / Your IP : 216.73.217.98 Web Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux VMHostDefault 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 User : sieuthimay ( 1016) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/zomuaban.com/public_html/site/controllers/frontend/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Profile extends MY_Controller {
public function __construct() {
parent::__construct();
$this->load->model('user_model');
loadlang('profile');
}
# Hàm này dự bị sau này triển khai profile
public function index($any) {
# Tạm thời redirect qua trang quản trị
redirect(url_profile_ads($any));
# Tìm user với email
$this->load->helper('email');
# Tìm user bằng email
if (valid_email($any)){
$user = $this->user_model->get_user_by_email($any);
# Nếu user không tồn tại > hiện thông báo
if ($user) {
// trả về profile với user này
return $this->view_user_profile($user);
}else{
return $this->render_view('404/user-not-found');
}
}
# Tìm user bằng ID
else{
$user = $this->user_model->get_user_by_id($any);
# Nếu user không tồn tại > hiện thông báo
if (!$user) return $this->render_view('404/user-not-found');
else return $this->view_user_profile($user);
}
}
private function view_user_profile($user) {
# Nếu không phải Profile cá nhân > user này chưa có thông tin mô tả > redirect qua trang tin đăng
if(isMyProfile($user) || is_manager()){
}else {
if(empty($user->intro)){
redirect(url_profile_ads($user->id));
}
}
# Lấy thông tin user
$this->data['user'] = $user;
$this->data['title'] = $user->fullname . ' | '. siteConf('siteName') .'.com';
$this->data['description'] = $user->fullname . ( !empty($user->shortIntro) ? ' - '.$user->shortIntro : ' - Description mặc định - Chứa tên user' );
$this->render();
}
public function ads($any) {
# Tìm user với email
$this->load->helper('email');
if (valid_email($any)){
$user = $this->user_model->get_user_by_email($any);
# Nếu user không tồn tại > hiện thông báo
if ($user) {
// trả về profile với user này
return $this->view_user_ads($user);
}else{
#Kiểm tra xem list item tồn tại hay không, nếu có thì hiển thị, ko thì notfound
$this->load->model('item_model');
# trả về tất cả tin đăng của user này
$list = $this->item_model->get_item_by_email($any, -1);
if($list){
// trả về user tạm
$user = new stdClass;
$user->email = $any;
$user->fullname = email2name($any);
$user->phone = '';
$user->address = '';
return $this->view_user_ads($user, $list);
} else return $this->render_view('404/user-not-found');
}
}
# Tìm user bằng ID
else{
$user = $this->user_model->get_user_by_id($any);
# Nếu user không tồn tại > hiện thông báo
if (!$user) return $this->render_view('404/user-not-found');
else return $this->view_user_ads($user);
}
}
private function view_user_ads($user, $list = null) {
loadlang('itemad_report');
if(!isset($list)){
$this->load->model('item_model');
# trả về tất cả tin đăng của user này
$list = $this->item_model->get_item_by_email($user->email, -1);
}
$listing = [];
$listing['list'] = [];
$listing['dlist'] = [];
$listing['nalist'] = [];
$listing['wlist'] = [];
$listing['exlist'] = [];
$listing['blocklist'] = [];
$listing['draft'] = [];
if (is_array($list)) {
foreach($list as $item) {
#Phân loại tin đang đăng, hết hạn, đã hoàn thành
# -1 : Không được duyệt
# -2 : Tin nháp
# -3 : Đã bị xóa
# 0 : Chưa được duyệt
# 1 : Tin đang đăng
# 2 : Đã bán
# 3 : Tin hết hạn
$item = full_item_prop($item);
if ($item->state ==-2) array_push($listing['draft'], $item);
else if ($item->state ==-1) array_push($listing['blocklist'], $item);
else if ($item->state == 0 && $item->report != 0) array_push($listing['nalist'], $item);
else if ($item->state == 0 && $item->report == 0) array_push($listing['wlist'], $item);
else if ($item->state == 1) array_push($listing['list'], $item);
else if ($item->state == 2) array_push($listing['dlist'], $item);
else if ($item->state == 3) array_push($listing['exlist'], $item);
else {}
}
}
$this->data['listing'] = $listing;
# SET META
$this->data['title'] = lang('listing_ad_of', $user->fullname) .' | '.siteConf('siteName').'.com';
$this->data['description'] = lang('listing_ad_of', $user->fullname) .' - '.(!empty($user->shortIntro) ? $user->shortIntro : lang('list_ad_of_user_desc'));
$this->data['fbmeta'] = array( 'title' => $this->data['title'],
'url' => url_profile_ads($user->id),
'image' => url_profile_cover($user),
'description' => $this->data['description']);
# Lấy thông tin user
$this->data['user'] = $user;
$this->render('profile_ads');
}
# Hàm tùy chỉnh thông tin tài khoản user owner
public function edit(){
$user = $this->user_model->get_user_by_id($this->session->userdata('id'));
if ($user) {
$this->data['user'] = $user;
$this->data['title'] = lang('update_infomation') . ' ' . $user->fullname;
$this->render();
}else {
redirect(base_url());
}
}
# Hàm này cập nhật thông tin cá nhân của user
public function ajax_update_info(){
$pData = ajax_safe_get();
if(isLogin()){
$this->db->set('phone', trim($pData->phone));
$this->db->where('id', mine()->id);
$this->db->update(tableConf('user'));
$this->db->set('fullname', trim($pData->fullname));
$this->db->set('shortIntro',trim($pData->shortIntro));
$this->db->set('phone', trim($pData->phone));
$this->db->set('address', trim($pData->address));
$this->db->where('id', mine()->id);
$this->db->update(tableConf('profile'));
if ($this->db->affected_rows() > 0) {
# Update lại session
set_my_data('name', $pData->fullname);
set_my_data('phone', $pData->phone);
set_my_data('address', $pData->address);
# Xóa cached lưu ID lẫn Email
clear_my_profile_cached();
}
$this->setMsg(lang('infomation_updated'));
}else{
$this->setErr(lang('no_access_permission'));
}
echo json_encode($this->getState());
}
# Hàm này thống kê lượt giao dịch trên website
public function transaction(){
if (!isLogin()) redirect(base_url());
# Hiển thị thông tin tài khoản: Tổng tài khoản, trạng thái (đóng băng (lí do?), active ...)
# Hiển thị lịch sử giao dịch : theo ngày, loại giao dịch (thanh toán (quảng cáo, từ khóa ...), nạp vào (từ thẻ cào, từ sms...) ..)
$mine = mine();
$this->load->model('user_model');
$this->data['user'] = $this->user_model->get_user_by_id($mine->id);
$this->load->model('transaction_model');
$this->data['wallet'] = $this->transaction_model->get_wallet_by_userId($mine->id);
$this->data['history'] = $this->transaction_model->get_transaction_by_userId($mine->id);
$this->render();
}
public function ajax_update_profile_intro(){
$pData = ajax_safe_get();
# TODO: Kiểm tra nội dung chưa từ khóa cấm hay không
if(!isLogin() || !is_manager()) $this->setErr('No permision!');
$this->db->where('id', mine()->id);
$this->db->update(tableConf('profile'), array('intro'=>$pData->intro));
# Mỗi lần cập nhật thông tin gì clear thông tin PROFILE
clear_my_profile_cached();
$this->setMsg('Đã cập nhật thành công!');
echo json_encode($this->getState());
}
# Hàm này dùng ở trang chủ dùng để lựa chọn tỉnh/thành lần đầu tiên vào web
public function reset_location(){
$location = $this->input->get('location', true);
$redirect_url = $this->input->get('redirect', true);
# Lưu lại location
set_my_data('cityId', $location);
//Logger($location, $redirect_url); return;
# Trở về URL cũ
redirect($redirect_url);
}
}