public function actionRequest()
 {
     if (isset($_POST['request'])) {
         $request = $_POST['request'];
         $accountId = intval($_POST['accountId']);
         $customerId = intval($_POST['customerId']);
         switch ($request) {
             case 'add_account':
                 $record = new AccountCustomerAssignment();
                 $record->accountId = $accountId;
                 $record->customerId = $customerId;
                 if ($record->save()) {
                     $response = array('type' => 'success', 'message' => 'saved record successfully');
                 } else {
                     $response = array('type' => 'fail', 'message' => 'Could not save the entry into the database');
                 }
                 echo json_encode($response);
                 break;
             case 'remove_account':
                 if (AccountCustomerAssignment::model()->deleteByPk(array('accountId' => $accountId, 'customerId' => $customerId))) {
                     $response = array('type' => 'success', 'message' => 'removed record successfully');
                 } else {
                     $response = array('type' => 'fail', 'message' => 'Could not remve the entry from the database');
                 }
                 echo json_encode($response);
                 break;
             default:
                 # code...
                 break;
         }
     } else {
         $response = array('type' => 'fail', 'message' => 'no request was found');
         echo json_encode($response);
     }
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     $model = $this->loadAccount();
     if (isset($_POST['Account'])) {
         $modelBeforeChange = $model->toString();
         $model->attributes = $_POST['Account'];
         if ($model->save()) {
             $stringModel = $model->toString();
             if ($modelBeforeChange != $stringModel) {
                 ChangeLog::addLog('UPDATE', 'Account', 'BEFORE<br />' . $modelBeforeChange . '<br />AFTER<br />' . $stringModel);
             }
             $this->redirect(array('admin', 'id' => $model->id));
         }
     }
     // Get the Accounts associated with this Customer
     $accountId = $model->id;
     $count = AccountCustomerAssignment::model()->count(array('condition' => 'accountId=:accountId', 'params' => array(':accountId' => intval($accountId))));
     $tags = array();
     if ($count > 0) {
         $tags = AccountCustomerAssignment::model()->findAll(array('condition' => 'accountId=:accountId', 'params' => array(':accountId' => intval($accountId))));
     }
     $tagList = Account::model()->findAll();
     $this->render('update', array('model' => $model, 'tags' => $tags, 'count' => $count, 'tagList' => $tagList));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     $model = $this->loadCustomer();
     if (isset($_POST['Customer'])) {
         $modelBeforeChange = $model->toString();
         $model->attributes = $_POST['Customer'];
         $model->companyId = Yii::app()->user->getState('selectedCompanyId');
         if ($model->save()) {
             $stringModel = $model->toString();
             if ($modelBeforeChange != $stringModel) {
                 ChangeLog::addLog('UPDATE', 'Customer', 'BEFORE<br />' . $modelBeforeChange . '<br />AFTER<br />' . $stringModel);
             }
             $this->redirect(array('admin', 'id' => $model->id));
         }
     }
     // Get the Accounts associated with this Customer
     $customerId = $model->id;
     $count = AccountCustomerAssignment::model()->count(array('condition' => 'customerId=:customerId', 'params' => array(':customerId' => intval($customerId))));
     $taggedAccounts = array();
     if ($count > 0) {
         $taggedAccounts = AccountCustomerAssignment::model()->findAll(array('condition' => 'customerId=:customerId', 'params' => array(':customerId' => intval($customerId))));
     }
     $accountList = Account::model()->findAll();
     $this->render('update', array('model' => $model, 'taggedAccounts' => $taggedAccounts, 'numTaggedAccounts' => $count, 'accountList' => $accountList));
     // echo '<pre>';
     // foreach ($taggedAccounts as $t_acc) {
     // 	echo "Tagged Account: " . $t_acc->accountId;
     // 	echo "Tagged Account name: " . $t_acc->account->name;
     // }
     // echo '</pre>';
     // $taggedAccounts = array();
 }