AAAAhome/academiac/www/administrator/components/com_csvi/models/com_csvi/export/customexport.php000060400000010076151475415740026766 0ustar00input; $csvilog = $jinput->get('csvilog', null, null); $template = $jinput->get('template', null, null); $exportclass = $jinput->get('export.class', null, null); $export_fields = $jinput->get('export.fields', array(), 'array'); // Build something fancy to only get the fieldnames the user wants $userfields = array(); foreach ($export_fields as $column_id => $field) { switch ($field->field_name) { // Man made fields, do not export them case 'custom': break; default: $userfields[] = $db->quoteName($field->field_name); break; } } // Export SQL Query // Build the query $userfields = array_unique($userfields); $query = $db->getQuery(true); $query->select(implode(",\n", $userfields)); $query->from($db->quoteName("#__".$template->get('custom_table'))); // Check if we need to group the orders together $groupby = $template->get('groupby', 'general', false, 'bool'); if ($groupby) { $filter = $this->getFilterBy('groupby'); if (!empty($filter)) $query->group($filter); } // Order by set field $orderby = $this->getFilterBy('sort'); if (!empty($orderby)) $query->order($orderby); // Add a limit if user wants us to $limits = $this->getExportLimit(); // Execute the query $csvidb->setQuery($query, $limits['offset'], $limits['limit']); $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true); // There are no records, write SQL query to log if (!is_null($csvidb->getErrorMsg())) { $this->addExportContent(JText::sprintf('COM_CSVI_ERROR_RETRIEVING_DATA', $csvidb->getErrorMsg())); $this->writeOutput(); $csvilog->AddStats('incorrect', $csvidb->getErrorMsg()); } else { $logcount = $csvidb->getNumRows(); $jinput->set('logcount', $logcount); if ($logcount > 0) { while ($record = $csvidb->getRow()) { if ($template->get('export_file', 'general') == 'xml' || $template->get('export_file', 'general') == 'html') $this->addExportContent($exportclass->NodeStart()); foreach ($export_fields as $column_id => $field) { $fieldname = $field->field_name; $fieldreplace = $field->field_name.$field->column_header; // Add the replacement if (isset($record->$fieldname)) $fieldvalue = CsviHelper::replaceValue($field->replace, $record->$fieldname); else $fieldvalue = ''; switch ($fieldname) { default: // Check if we have any content otherwise use the default value if (strlen(trim($fieldvalue)) == 0) $fieldvalue = $field->default_value; $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header); break; } } if ($template->get('export_file', 'general') == 'xml' || $template->get('export_file', 'general') == 'html') { $this->addExportContent($exportclass->NodeEnd()); } // Output the contents $this->writeOutput(); } } else { $this->addExportContent(JText::_('COM_CSVI_NO_DATA_FOUND')); // Output the contents $this->writeOutput(); } } } } ?>