public function addMerchantUser() { $merchant_id = Yii::app()->functions->getMerchantID(); $params = array('merchant_id' => $merchant_id, 'first_name' => $this->data['first_name'], 'last_name' => $this->data['last_name'], 'username' => $this->data['username'], 'user_access' => json_encode($this->data['access']), 'date_created' => date('c'), 'status' => $this->data['status'], 'ip_address' => $_SERVER['REMOTE_ADDR'], 'contact_email' => $this->data['contact_email']); if (isset($this->data['password'])) { if (!empty($this->data['password'])) { $params['password'] = md5($this->data['password']); } } /*dump($params); die(); */ $FunctionsK = new FunctionsK(); if (empty($this->data['id'])) { if (empty($params['password'])) { $this->msg = "Password is required."; return; } if ($err_msg = $FunctionsK->validateMerchantUserAccount($this->data['username'], $this->data['contact_email'])) { $this->msg = $err_msg; return; } if (!yii::app()->functions->validateMerchantUSername($this->data['username'])) { if ($this->insertData("{{merchant_user}}", $params)) { $this->details = Yii::app()->db->getLastInsertID(); $this->code = 1; $this->msg = Yii::t("default", "Successful"); } } else { $this->msg = "Sorry your username is already exist. Please choose another username."; } } else { unset($params['date_created']); $params['date_modified'] = date('c'); if (!empty($params['username'])) { if (Yii::app()->functions->validateMerchantUser($params['username'], $merchant_id)) { $this->msg = Yii::t("default", "Merchant Username is already been taken"); return; } } if ($err_msg = $FunctionsK->validateMerchantUserAccount($this->data['username'], $this->data['contact_email'], $this->data['id'])) { $this->msg = $err_msg; return; } $res = $this->updateData('{{merchant_user}}', $params, 'merchant_user_id', $this->data['id']); if ($res) { $this->code = 1; $this->msg = Yii::t("default", 'Merchant User updated.'); } else { $this->msg = Yii::t("default", "ERROR: cannot update"); } } }