private function edit(Offer $model)
 {
     if (isset($_POST['restore'])) {
         if ($model->restore()) {
             Yii::app()->user->setFlash('offer-restored', 'Offer is restored!');
         }
     }
     if (isset($_POST['delete'])) {
         $model->deactivate();
     }
     if ($model->off_status == Offer::STATUS_DELETED) {
         // status becomes read-only. until restored
         unset($_POST['Offer']['off_status']);
     }
     if (isset($_POST['Offer']) && $_POST['Offer']) {
         $model->attributes = $_POST['Offer'];
         if (isset($_POST['client']) && $_POST['client']) {
             $model->setClients($_POST['client']);
         }
         if ($model->save()) {
             if ($_POST['clientStatus']) {
                 foreach ($model->clients as $client) {
                     $client->cli_salestatus = $_POST['clientStatus'];
                     $client->save();
                 }
             }
             Yii::app()->user->setFlash('offer-success', 'Offer is saved!');
             $this->redirect(['update', 'id' => $model->off_id, 'popup' => $this->popupMode, 'callback' => isset($_GET['callback']) ? $_GET['callback'] : ""]);
         }
     }
     if (isset($_GET['callback']) && $_GET['callback']) {
         $callback = new PopupCallback($_GET['callback']);
         $callback->run([], isset($_POST['close']));
     } else {
         if (isset($_POST['close'])) {
             echo '<script type="text/javascript">window.close()</script>';
             Yii::app()->end();
         }
     }
     $this->render('edit', array('model' => $model));
 }