public function actionTac_vu_khach()
 {
     $dangtin = new LoginForm();
     $khachhang = new Khachhang();
     $form = new CForm('application.views.admin.tac_vu_khach.form_tac_vu_khach', $khachhang);
     $khachhang->setScenario('dang_tin_khach');
     if ($form->submitted('dangtinkhach') && $form->validate()) {
         $id = $khachhang->idkhach;
         $arry = explode("_", $id);
         $username = $arry[0];
         if (isset($arry[1])) {
             $id = $arry[1];
             if ($user = Khachhang::model()->TTkhach($id, $username)) {
                 $dangtin->username = $user['ten_dang_nhap'];
                 $dangtin->password = $user['password'];
                 $dangtin->_identity = new UserIdentity($dangtin->username, $dangtin->password);
                 $dangtin->_identity->authenticate();
                 $dangtin->login();
                 $this->redirect(Yii::app()->request->baseUrl . '/dang-tin');
             } else {
                 $this->__message = "Nhập sai id khách hàng!";
             }
         } else {
             $this->__message = "Nhập sai cú pháp!";
         }
     }
     $this->render('tac_vu_khach', array('form' => $form, 'message' => $this->__message));
 }
 public function getKhachHangName()
 {
     $khachhang = Khachhang::model()->findByPk($this->khachhang_id);
     if ($khachhang) {
         return $khachhang->ten;
     } else {
         return 'Chưa Xác Định';
     }
 }
Example #3
0
 function edit($id = 0)
 {
     $khachhang = new khachhang($id);
     if ($_SERVER['REQUEST_METHOD'] == "GET") {
     } else {
         $file = 'img/logo/';
         $position = $this->input->post('position');
         $partner = new Khachhang();
         $partner->where('position >', $position);
         $partner->get()->all;
         foreach ($partner as $row) {
             $row->position = $row->position + 1;
             $row->save();
             $row->clear();
         }
         $this->load->library('file_lib');
         $khachhang->name_vietnamese = $this->input->post('name');
         $khachhang->description = $this->input->post('description');
         $khachhang->link = $this->input->post('link');
         $khachhang->address = $this->input->post('address');
         $khachhang->email = $this->input->post('email');
         $khachhang->phone = $this->input->post('phone');
         $khachhang->position = $position;
         $dataupload = $this->file_lib->upload('image', $file);
         if (!is_array($dataupload)) {
             flash_message('info', $dataupload);
         } else {
             $khachhang->logo = $file . $dataupload['file_name'];
             $this->resize_image('img/partner/' . $dataupload['file_name']);
         }
         if ($khachhang->save()) {
             redirect($this->admin . 'partner/edit/' . $khachhang->id);
         }
     }
     $dis['base_url'] = base_url();
     $dis['title'] = "Add/Edit Language";
     $dis['menu_active'] = "Đối tác";
     $dis['view'] = "khachhang/edit";
     $dis['object'] = $khachhang;
     $dis['nav_menu'] = array(array("type" => "back", "text" => "Back", "link" => "{$this->admin_url}partner", "onclick" => ""));
     $this->viewadmin($dis);
 }
Example #4
0
 /**
  * Authenticates a user.
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $record = Khachhang::model()->findByAttributes(array('ten_dang_nhap' => $this->username));
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($record->password !== $this->password) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->setState('userId', $record->ma_khach_hang);
             $this->setState('name', $record->ten_dang_nhap);
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
Example #5
0
 /**
  * Nạp tiền cho khách
  */
 public function NapTien($so_du_tai_khoan_new, $ma_khach_hang)
 {
     $sql = "UPDATE " . Khachhang::model()->tableName() . " SET so_du_tai_khoan = so_du_tai_khoan + {$so_du_tai_khoan_new}" . " WHERE ma_khach_hang = {$ma_khach_hang}";
     Yii::app()->db->createCommand($sql)->execute();
 }
$form = $this->beginWidget('CActiveForm', array('id' => 'hoadon-form', 'enableAjaxValidation' => false));
?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php 
echo $form->errorSummary($model);
?>

	<div class="form-group">
		<?php 
echo $form->labelEx($model, 'khachhang_id');
?>
		<?php 
echo $form->dropDownList($model, 'khachhang_id', Khachhang::model()->getKhachhangsName());
?>
		<?php 
echo $form->error($model, 'khachhang_id');
?>
	</div>

	<div class="form-group">
		<?php 
echo $form->labelEx($model, 'ngaymua');
?>
		<?php 
echo $form->textField($model, 'ngaymua', array('class' => 'form-control datetime'));
?>
		<?php 
echo $form->error($model, 'ngaymua');
Example #7
0
 function partners()
 {
     $partner = new Khachhang();
     $partner->order_by('id', 'desc');
     $partner->get_iterated();
     $dis['partner'] = $partner;
     $this->column = 2;
     $this->page_title = 'Đối tác - ' . $this->page_title;
     $dis['base_url'] = base_url();
     $dis['view'] = 'front/partner';
     $this->viewfront($dis);
 }
Example #8
0
 public function actionChinh_sua_thong_tin()
 {
     $this->_checkLogin();
     $form = new CForm('application.views.user.khach_hang._formChinhsuathongtin');
     $khachHang = $form->model = Khachhang::model()->findByPk(Yii::app()->user->userId);
     $pass = $khachHang->password;
     $khachHang->password = "";
     $khachHang->setScenario('update');
     $array = array(Yii::app()->user->name, Yii::app()->user->userId);
     $id = implode("_", $array);
     $khachHang->id = $id;
     $anh = $khachHang->anh_dai_dien;
     if ($form->submitted('chinhsua') && $form->validate()) {
         $image = CUploadedFile::getInstance($khachHang, 'anh_dai_dien');
         if ($image) {
             //Nếu tồn tại ảnh trong CSDL thì sẽ xóa ảnh cũ trong thư mục ảnh
             if ($anh) {
                 unlink(Yii::app()->basePath . '/../' . Khachhang::AVARTAR_DIR . $anh);
             }
             $newName = md5(microtime(true) . 'xechieuve') . $image->name;
             $khachHang->anh_dai_dien = $newName;
             $image->saveAs(Khachhang::AVARTAR_DIR . $newName);
         } else {
             $khachHang->anh_dai_dien = $anh;
         }
         if (md5($khachHang->password) == $pass) {
             $khachHang->password = md5($khachHang->password);
             $khachHang->save(FALSE);
             $this->__message = "Sửa thông tin thành công!";
         } else {
             $this->__message = "Thất bại,bạn nhập sai mật khẩu bạn cần nhập chính xác mật khẩu hiện tại của bạn!";
         }
     }
     $form2 = new CForm('application.views.user.khach_hang._formcapnhatpass');
     $khachHang2 = $form2->model = Khachhang::model()->findByPk(Yii::app()->user->userId);
     $khachHang2->setScenario('updatepass');
     if ($form2->submitted('doimatkhau') && $form2->validate()) {
         Khachhang::updatepassword(md5($khachHang2["newPassword"]));
         $this->__message = "Sửa thông tin thành công!";
     }
     $this->render('chinh_sua_thong_tin', array('form' => $form, 'anh' => $anh, 'form2' => $form2, 'message' => $this->__message));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Khachhang the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Khachhang::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #10
0
 /**
  * trừ tiền dựa theo mã loại tin
  */
 public function trutien($maLoaiTin)
 {
     //lấy giá tiền cần có để đăng tin
     $giaTien = Loaitin::model()->findByPk($maLoaiTin)->gia_dang;
     //lấy tổng số tiền trong tài khoản của khách hàng
     $tongTien = Khachhang::model()->findByPk(Yii::app()->user->userId)->so_du_tai_khoan;
     //Nếu không đủ tiền sẽ không cho đăng tin
     if ($tongTien < $giaTien) {
         return false;
     }
     if (Khachhang::model()->updateByPk(Yii::app()->user->userId, array('so_du_tai_khoan' => $tongTien - $giaTien))) {
         return true;
     }
     return false;
 }