private function addEdit($id = 0) { $model = new QrGenerateForm('nosubmit'); if ($id) { Yii::app()->user->checkAccess('ownQr'); $qr = $this->loadModel($id); $attributes = array(); foreach ($qr->qrData as $prop => $value) { $attributes[$qr->type . '_data_' . $prop] = $value; } $model->title = $qr->title; $model->qr_type = $qr->type; $model->attributes = $attributes; $model->vcard_data_fname = isset($attributes['vcard_data_fname']) && $attributes['vcard_data_fname'] != '' ? $attributes['vcard_data_fname'] : ''; $model->vcard_data_lname = isset($attributes['vcard_data_lname']) && $attributes['vcard_data_lname'] != '' ? $attributes['vcard_data_lname'] : ''; $model->vcard_data_telephone = isset($attributes['vcard_data_telephone']) && $attributes['vcard_data_telephone'] != '' ? $attributes['vcard_data_telephone'] : ''; $model->vcard_data_cell = isset($attributes['vcard_data_cell']) && $attributes['vcard_data_cell'] != '' ? $attributes['vcard_data_cell'] : ''; $model->vcard_data_fax = isset($attributes['vcard_data_fax']) && $attributes['vcard_data_fax'] != '' ? $attributes['vcard_data_fax'] : ''; } else { $qr = new Qr(); $qr->qr_type = Yii::app()->request->getParam('type'); $qr->qr_type = in_array($qr->qr_type, array('custom', 'transparent')) ? $qr->qr_type : 'custom'; } if (isset($_POST['QrGenerateForm'])) { $model->setScenario($_POST['QrGenerateForm']['qr_type']); $model->attributes = $_POST['QrGenerateForm']; $model->company = $_POST['QrGenerateForm']['company']; if ($model->validate()) { $qr->title = $model->title; $qr->type = $model->qr_type; $qr->user_id = Yii::app()->user->getId(); $qr->data = $_POST['QrGenerateForm']; $qr->company = $model->company; // $qr->vcard_data_fname = $model->vcard_data_fname; // $qr->vcard_data_lname = $model->vcard_data_lname; // $qr->vcard_data_telephone = $model->vcard_data_telephone; // $qr->vcard_data_cell = $model->vcard_data_cell; $qr->save(); Qr::saveInSession($qr->id); if (!$id) { $this->redirect(array($qr->qr_type == 'custom' ? 'customize' : 'transparent', 'id' => $qr->id)); } else { if ($logo_path = $qr->logo_image) { Qr::embedLogo($qr->image_path, $logo_path); } Utility::setFlash(Yii::t('dict', "QR Code {$id} edited successfully."), 'success'); $this->redirect(array('list')); } } } $model->setScenario('nosubmit'); $qr_type = $model->qr_type; $model_email = new Email('search'); if ($this->isExportRequest()) { //<==== [[ADD THIS BLOCK BEFORE RENDER]] $this->exportCSV($model_email->search(), array('id', 'email_id', 'timestamp', 'ip', 'browser', 'created_at')); } $this->render('generate', array('mode' => $id ? 'edit' : 'add', 'model' => $model, 'qr_type' => $qr_type, 'model_email' => $model_email)); }
private function addEdit($id = 0) { $model = new QrGenerateForm('nosubmit'); if ($id) { Yii::app()->user->checkAccess('ownQr'); $qr = $this->loadModel($id); $attributes = array(); foreach ($qr->qrData as $prop => $value) { $attributes[$qr->type . '_data_' . $prop] = $value; } $model->title = $qr->title; $model->qr_type = $qr->type; $model->attributes = $attributes; } else { $qr = new Qr(); $qr->qr_type = Yii::app()->request->getParam('type'); $qr->qr_type = in_array($qr->qr_type, array('custom', 'transparent')) ? $qr->qr_type : 'custom'; } if (isset($_POST['QrGenerateForm'])) { $model->setScenario($_POST['QrGenerateForm']['qr_type']); $model->attributes = $_POST['QrGenerateForm']; if ($model->validate()) { $qr->title = $model->title; $qr->type = $model->qr_type; $qr->user_id = Yii::app()->user->getId(); $qr->data = $_POST['QrGenerateForm']; $qr->save(); Qr::saveInSession($qr->id); if (!$id) { $this->redirect(array($qr->qr_type == 'custom' ? 'customize' : 'transparent', 'id' => $qr->id)); } else { if ($logo_path = $qr->logo_image) { Qr::embedLogo($qr->image_path, $logo_path); } Utility::setFlash(Yii::t('dict', "QR Code {$id} edited successfully."), 'success'); $this->redirect(array('list')); } } } $model->setScenario('nosubmit'); $qr_type = $model->qr_type; $this->render('generate', array('mode' => $id ? 'edit' : 'add', 'model' => $model, 'qr_type' => $qr_type)); }