'added DESC'); protected $_columns4ExportCsv; protected $_hasFilter = true; protected $_thanksPageAlias = 'thanks.html'; protected $_exportFileName = null; protected function _postInsert() { $data = $this->dataObj->clearData()->getData(); $this->_sendAdminNotification($data); $this->_redirect(); return $this; } protected function _redirect() { $this->redirect($this->url() . '/' . $this->_thanksPageAlias); } protected function _sendAdminNotification($data) { $subject = App_Settings_Obj::get($this->_settingsPrefix . 'Subject'); $body = App_Settings_Obj::get($this->_settingsPrefix . 'Body'); $from = App_Settings_Obj::get($this->_settingsPrefix . 'From'); $to = App_Settings_Obj::getFormEmails($this->_settingsPrefix . 'To'); if (empty($to)) { return false; } $mailData = $this->_getMailData($data); foreach ($mailData as $field => $value) { $body = str_replace('{' . $field . '}', $value, $body); } $mail = new Qs_Mail(); $mail->setFrom($from); $mail->setSubject($subject); Qs_Mail::cutImageBaseUrl($body, BASE_URL); $mail->setHtml($body, null, WWW_PATH); $mail->addTo($to); $mail->send(); return $this; } protected function _doView() { $item = $this->dataObj->getData(); if (empty($item)) { $this->doc->displayError('Invalid submission ID'); return $this; } $this->dataObj->table->updateByKey(array('viewed' => 'y'), $this->dataObj->getPrimaryKey()); $item['config'] = (array) $this->getConfig(); $item['tpl'] = $this->getTemplate('view.tpl'); $this->doc->addItem($item); $this->doc->addStylesheet('css/admin-print.css', array('media' => 'print')); return $this; } protected function _getDefaultLinks() { $links = parent::_getDefaultLinks(); $params = array(); if ($orderBy = Qs_Request::getGetValue('orderBy')) { $params['orderBy'] = $orderBy; } if ($query = Qs_Request::getGetValue('query')) { $params['query'] = $query; } $params['action'] = 'exportCsv'; $links['exportCsv'] = array('title' => 'Export to .csv', 'url' => $this->url($params)); return $links; } protected function _doExportCsv() { if ($this->dataObj->hasFilter()) { $form = $this->_getFilterForm(); if ($form->validate()) { $this->dataObj->addFilter($form->getValues()); } } $options = array(); $options['order'] = array($this->list->getOrderBy()); $stmt = $this->dataObj->getListStatement($options); $fp = fopen('php://output', 'w'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D,d M YH:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); header('Content-type: text/comma-separated-values'); header('Content-Disposition: attachment; filename="' . $this->_getExportFileName() . '"'); $columns = $this->_getColumns4ExportCsv(); fputcsv($fp, $columns); $blankRow = array_combine(array_keys($columns), array_fill(0, count($columns), '')); while ($row = $stmt->fetch()) { $row = $this->_getRow4ExportCsv($row); $row = array_intersect_key($row, $columns); $row = array_merge($blankRow, $row); fputcsv($fp, $row); } fclose($fp); exit; } protected function _getExportFileName() { if (null == $this->_exportFileName) { $this->_exportFileName = $this->dataObj->itemsName . ' ' . date('M d Y g:i A') . '.csv'; } return $this->_exportFileName; } protected function _getColumns4ExportCsv() { if (null === $this->_columns4ExportCsv) { $this->_columns4ExportCsv = array('added' => 'Submitted'); $fields = array_keys(Qs_Array::exclude($this->dataObj->table->getMetaData(), 'id', 'added', 'changed')); foreach ($fields as $field) { $this->_columns4ExportCsv[$field] = ucfirst(preg_replace('/([a-z])([A-Z])/', '$1 $2', $field)); } } return $this->_columns4ExportCsv; } protected function _getRow4ExportCsv(&$data) { $row = str_replace(array("\n", "\r"), ' ', $data); return $row; } protected function _getMailData(array $data) { throw new Qs_Exception('_getMailData() not implemented'); } protected function _getFilterFields() { if (null === $this->_filterFields) { $this->_filterFields = $this->dataObj->getFilterFields(); $this->_filterFields = array_flip($this->_filterFields); $columns = $this->_getColumns4ExportCsv(); $this->_filterFields = array_intersect_key($columns, $this->_filterFields); } return $this->_filterFields; } }