'_doForm', 'cancel' => 'doBack', 'report' => '_doReport', 'save' => '_doSave', ); protected function _getForm() { $form = $this->_getBaseForm(); $items = $this->DBObj->getList4Grid(); foreach ($items['list'] as $item) { $form->addElement('text', 'price[' . $item['id'] . ']', '$'); } $form->action = CURR_PAGE; $form->addElement('hidden', 'action', 'save') ; return $form; } protected function _getReportForm() { $form = $this->_getBaseForm(); $form->addElement('text', 'format', 'Invoice Format'); $form->addElement('text', 'date', 'Invoice Date'); $form->addElement('text', 'batch_id', 'Batch ID'); $form->addElement('text', 'site_id', 'Site ID'); $form->addRuleRequired(array('format', 'date', 'site_id')); $form->action = CURR_PAGE; $form->addElement('hidden', 'action', 'report') ; return $form; } protected function _doForm() { $form = $this->_getForm(); $this->DBObj->initFromDB(); $form->setDefaults($this->DBObj->getData()); $form->return_form_arr = true; $item['itemform'] = $form->_execRendArrSmarty(); $item['itemlist'] = $this->DBObj->getList4Grid(); $reportForm = $this->_getReportForm(); $reportForm->return_form_arr = true; $item['reportform'] = $reportForm->_execRendArrSmarty(); $item['tpl'] = 'DuesReport/form.tpl'; $this->Doc->addContent($item); } protected function _doSave() { $form = $this->_getForm(); $this->DBObj->update($form->exportValues()); Session::setData($this->_getPage4SaveMessage(), 'msg', 'Items updated'); $this->doBack(); } protected function _doReport() { $result = $this->DBObj->getReportRes(); $values = $this->_getReportForm()->exportValues(); $columns = array( 'nrds_id' => 'Customer ID', 'location_nrds_id' => 'Location ID', 'first_name' => 'First Name', 'last_name' => 'Last Name', 'mncar_type' => 'MNCAR Member Type', 'mncar_l_type' => 'MNCAR-L Member Type', 'number' => 'Item Number', 'description' => 'Item Description', 'quantity' => 'Quantity', 'unit_price' => 'Unit Price', 'address' => 'Address', 'city' => 'City', 'state' => 'State', 'zip' => 'Zip', 'location_nrds_id' => 'Location ID', 'location_name' => 'Location Name', 'company_name' => 'Company Name', 'invoice_format' => 'Invoice Format', 'invoice_data' => 'Invoice Data', 'batch_id' => 'Batch ID', 'site_id' => 'Site ID', ); 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=mncar_dues_report.csv'); $fp = fopen('php://output', 'w'); fputcsv($fp, $columns); $blankRow = array_combine(array_keys($columns), array_fill(0, count($columns), '')); $blankRow['invoice_format'] = strtoupper($values['format']); $blankRow['invoice_data'] = $values['date']; $blankRow['site_id'] = strtoupper($values['site_id']); while ($row = $result->fetchRow()) { $data = array_merge($blankRow, array_intersect_key($row, $columns)); fputcsv($fp, $data); } fclose($fp); die(); } }