Example #1
0
 /**
  * CSVI VirtueMart view display method
  *
  * @return void
  */
 function display($tpl = null)
 {
     // Show the toolbar
     JToolBarHelper::title(JText::_('COM_CSVI_CONTROL_PANEL'), 'csvi_logo_48.png');
     // Options button.
     if (JFactory::getUser()->authorise('core.admin', 'com_csvi')) {
         JToolBarHelper::preferences('com_csvi');
     }
     //JToolBarHelper::help('control_panel.html', true);
     // Assign data for display
     $helper = new CsviHelper();
     $this->cpanel_images = $helper->getButtons();
     // Display the page
     parent::display($tpl);
 }
Example #2
0
 /**
  * Template types display method
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		4.0
  */
 public function display($tpl = null)
 {
     // Load the template types
     $this->items = $this->get('Items');
     // Get the pagination
     $this->pagination = $this->get('Pagination');
     // Load the user state
     $this->state = $this->get('State');
     // Render the submenu
     if (version_compare(JVERSION, '3.0', '>=')) {
         CsviHelper::addSubmenu('replacements');
         $this->sidebar = JHtmlSidebar::render();
     } else {
         // Get the panel
         $this->loadHelper('panel');
         $this->sidebar = '';
     }
     // Show the toolbar
     JToolBarHelper::title(JText::_('COM_CSVI_REPLACEMENTS'), 'csvi_replacement_48');
     JToolBarHelper::addNew('replacement.add');
     JToolBarHelper::editList('replacement.edit');
     JToolBarHelper::deleteList('', 'replacements.delete');
     //JToolBarHelper::help('about.html', true);
     // Display it all
     parent::display($tpl);
 }
Example #3
0
 /**
  * About view display method
  * @return void
  * */
 function display($tpl = null)
 {
     // Assign the values
     $this->folders = $this->get('FolderCheck');
     // Get the schema version
     $this->schemaVersion = $this->get('SchemaVersion');
     // Check for database errors
     $changeSet = $this->get('ChangeSet');
     $this->errors = $changeSet->check();
     // Render the submenu
     if (version_compare(JVERSION, '3.0', '>=')) {
         CsviHelper::addSubmenu('about');
         $this->sidebar = JHtmlSidebar::render();
     } else {
         // Get the panel
         $this->loadHelper('panel');
         $this->sidebar = '';
     }
     // Show the toolbar
     JToolBarHelper::title(JText::_('COM_CSVI_ABOUT'), 'csvi_about_48');
     JToolBarHelper::custom('about.fix', 'refresh', 'refresh', 'COM_CSVI_TOOLBAR_DATABASE_FIX', false, false);
     //JToolBarHelper::help('about.html', true);
     // Display it all
     parent::display($tpl);
 }
Example #4
0
 /**
  * Maps view display method
  * @return void
  * */
 function display($tpl = null)
 {
     // Load the logs
     $this->items = $this->get('Items');
     // Get the pagination
     $this->pagination = $this->get('Pagination');
     // Load the user state
     $this->state = $this->get('State');
     // Render the submenu
     if (version_compare(JVERSION, '3.0', '>=')) {
         CsviHelper::addSubmenu('maps');
         $this->sidebar = JHtmlSidebar::render();
     } else {
         // Get the panel
         $this->loadHelper('panel');
         $this->sidebar = '';
     }
     // Show the toolbar
     JToolBarHelper::title(JText::_('COM_CSVI_MAPS'), 'csvi_map_48');
     JToolBarHelper::custom('map.add', 'csvi_add_32', 'csvi_add_32', 'JTOOLBAR_NEW', false);
     JToolBarHelper::custom('map.edit', 'csvi_edit_32', 'csvi_edit_32', 'JTOOLBAR_EDIT', true);
     JToolBarHelper::divider();
     JToolBarHelper::custom('maps.delete', 'csvi_delete_32', 'csvi_delete_32', JText::_('JTOOLBAR_DELETE'), true);
     // Display it all
     parent::display($tpl);
 }
Example #5
0
 /**
  * Template types display method
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		4.0
  */
 public function display($tpl = null)
 {
     // Load the template types
     $this->templatetypes = $this->get('Items');
     // Get the pagination
     $this->pagination = $this->get('Pagination');
     // Load the user state
     $this->state = $this->get('State');
     // Render the submenu
     if (version_compare(JVERSION, '3.0', '>=')) {
         CsviHelper::addSubmenu('templatetypes');
         $this->sidebar = JHtmlSidebar::render();
     } else {
         // Get the panel
         $this->loadHelper('panel');
         $this->sidebar = '';
     }
     // Show the toolbar
     JToolBarHelper::title(JText::_('COM_CSVI_TEMPLATETYPES'), 'csvi_templates_48');
     JToolBarHelper::custom('templatetypes.reset', 'csvi_reset_32', 'csvi_reset_32', JText::_('COM_CSVI_RESET_SETTINGS'), false);
     JToolBarHelper::divider();
     JToolBarHelper::custom('templatetype.add', 'csvi_add_32', 'csvi_add_32', 'JTOOLBAR_NEW', false);
     JToolBarHelper::custom('templatetype.edit', 'csvi_edit_32', 'csvi_edit_32', 'JTOOLBAR_EDIT', true);
     JToolBarHelper::divider();
     JToolBarHelper::custom('templatetypes.publish', 'csvi_publish_32', 'csvi_publish_32', JText::_('JTOOLBAR_PUBLISH'), true);
     JToolBarHelper::custom('templatetypes.unpublish', 'csvi_unpublish_32', 'csvi_unpublish_32', JText::_('JTOOLBAR_UNPUBLISH'), true);
     //JToolBarHelper::help('about.html', true);
     // Display it all
     parent::display($tpl);
 }
 /**
  * Available fields view display method
  *
  * @copyright
  * @author 		RolandD
  * @todo 		Replace JError
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		3.0
  */
 public function display($tpl = null)
 {
     // Get the list of available fields
     $this->availablefields = $this->get('Items');
     // Load the pagination
     $this->pagination = $this->get('Pagination');
     // Load the user state
     $this->state = $this->get('State');
     if (!$this->get('FieldCheck')) {
         throw new Exception(JText::_('COM_CSVI_NO_AVAILABLE_FIELDS'), 0);
     }
     // Get the list of actions
     $options = array();
     $options[] = JHtml::_('select.option', 'import', JText::_('COM_CSVI_IMPORT'));
     $options[] = JHtml::_('select.option', 'export', JText::_('COM_CSVI_EXPORT'));
     $this->actions = JHtml::_('select.genericlist', $options, 'jform_options_action', 'onchange="Csvi.loadTemplateTypes();"', 'value', 'text', $this->state->get('filter.action', ''));
     // Get the list of supported components
     $this->components = JHtml::_('select.genericlist', CsviHelper::getComponents(), 'jform_options_component', 'onchange="Csvi.loadTemplateTypes();"', 'value', 'text', $this->state->get('filter.component'), false, true);
     // Get the list of template types
     $model = $this->getModel();
     $templates_model = $model->getModel('templates');
     $operations = $templates_model->getTemplateTypes($this->state->get('filter.action', 'import'), $this->state->get('filter.component', false));
     // Create the operations list
     $this->operations = JHtml::_('select.genericlist', $operations, 'jform_options_operation', '', 'value', 'name', $this->state->get('filter.operation'), false, true);
     // Get the panel
     $this->loadHelper('panel');
     // Show the toolbar
     $this->addToolbar();
     // Display it all
     parent::display($tpl);
 }
Example #7
0
 /**
  * About view display method
  * @return void
  * */
 function display($tpl = null)
 {
     // Load the form
     $this->form = $this->get('Form');
     // Load a list of tables
     $this->tablelist = $this->get('TableList');
     // Get ICEcat statistics
     $this->icecat_stats = $this->get('IcecatStats');
     // Render the submenu
     if (version_compare(JVERSION, '3.0', '>=')) {
         CsviHelper::addSubmenu('settings');
         $this->sidebar = JHtmlSidebar::render();
     } else {
         // Get the panel
         $this->loadHelper('panel');
         $this->sidebar = '';
     }
     // Show the toolbar
     JToolBarHelper::title(JText::_('COM_CSVI_SETTINGS_TITLE'), 'csvi_settings_48');
     JToolBarHelper::custom('settings.reset', 'csvi_reset_32', 'csvi_reset_32', JText::_('COM_CSVI_RESET_SETTINGS'), false);
     JToolBarHelper::custom('settings.save', 'csvi_save_32', 'csvi_save_32', JText::_('COM_CSVI_SAVE'), false);
     //JToolBarHelper::help('settings.html', true);
     // Display it all
     parent::display($tpl);
 }
 /**
  * Table constructor
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param 		$db	object	A database connector object
  * @return
  * @since 		3.0
  */
 public function __construct($db)
 {
     $jinput = JFactory::getApplication()->input;
     $template = $jinput->get('template', null, null);
     // Find which table we are importing
     $tbl = $template->get('custom_table');
     // Find the primare key for this table
     $pk = CsviHelper::getPrimaryKey($tbl);
     parent::__construct('#__' . $tbl, $pk, $db);
 }
Example #9
0
 /**
  * Log view display method
  * @return void
  */
 function display($tpl = null)
 {
     $jinput = JFactory::getApplication()->input;
     // Get the task
     $task = $jinput->get('task');
     // Get the log
     $model = $this->getModel('log');
     switch ($task) {
         case 'logreader':
             $this->logdetails = $this->get('Logfile');
             $this->logfile = $logfile = CSVIPATH_DEBUG . '/com_csvi.log.' . JRequest::getInt('run_id') . '.php';
             break;
         default:
             // Load the logs
             $this->logentries = $this->get('Items');
             // Get the pagination
             $this->pagination = $this->get('Pagination');
             // Load the user state
             $this->state = $this->get('State');
             // Load the action types
             $actiontypes = $this->get('ActionTypes');
             $this->lists['actions'] = JHTML::_('select.genericlist', $actiontypes, 'filter_actiontype', '', 'value', 'text', JRequest::getWord('filter_actiontype'));
             // Render the submenu
             if (version_compare(JVERSION, '3.0', '>=')) {
                 CsviHelper::addSubmenu('log');
                 $this->sidebar = JHtmlSidebar::render();
             } else {
                 // Get the panel
                 $this->loadHelper('panel');
                 $this->sidebar = '';
             }
             // Add toolbar
             JToolBarHelper::title(JText::_('COM_CSVI_LOG'), 'csvi_log_48');
             JToolBarHelper::custom('logdetails.logdetails', 'csvi_logdetails_32', 'csvi_logdetails_32', JText::_('COM_CSVI_DETAILS'), true);
             JToolBarHelper::custom('log.remove', 'csvi_delete_32', 'csvi_delete_32', JText::_('COM_CSVI_DELETE'), true);
             JToolBarHelper::custom('log.remove_all', 'csvi_delete_32', 'csvi_delete_32', JText::_('COM_CSVI_DELETE_ALL'), false);
             // JToolBarHelper::help('log.html', true);
             break;
     }
     // Display it all
     parent::display($tpl);
 }
Example #10
0
 /**
  * Display the maintenance screen
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param 		string	$tpl	the template to use
  * @return
  * @since 		3.0
  */
 function display($tpl = null)
 {
     // Get the component list
     $this->components = $this->get('Components');
     // Get the maintenance options
     $this->options = $this->get('MaintenanceOptions');
     $app = JFactory::getApplication();
     $app->setUserState('com_csvi.global.form', false);
     // Load the results
     $jinput = JFactory::getApplication()->input;
     $settings = $jinput->get('settings', null, null);
     if ($settings->get('log.log_store', 1)) {
         $this->logresult = $this->get('Stats', 'log');
         $this->logmessage = $this->get('StatsMessage', 'log');
     } else {
         $this->logresult = false;
     }
     // Render the submenu
     if (version_compare(JVERSION, '3.0', '>=')) {
         CsviHelper::addSubmenu('maintenance');
         $this->sidebar = JHtmlSidebar::render();
     } else {
         // Get the panel
         $this->loadHelper('panel');
         $this->sidebar = '';
     }
     // Show the toolbar
     JToolBarHelper::title(JText::_('COM_CSVI_MAINTENANCE'), 'csvi_maintenance_48');
     if ($this->getLayout() != 'log') {
         JToolBarHelper::custom('cron.cron', 'csvi_cron_32', 'csvi_cron_32', JText::_('COM_CSVI_CRONLINE'), false);
         JToolBarHelper::custom('', 'csvi_continue_32.png', 'csvi_continue_32.png', JText::_('COM_CSVI_CONTINUE'), false);
         //JToolBarHelper::help('maintenance.html', true);
     } else {
         if ($settings->get('log.log_store', 1)) {
             JToolBarHelper::custom('logdetails.logdetails', 'csvi_logdetails_32', 'csvi_logdetails_32', JText::_('COM_CSVI_LOG_DETAILS'), false);
         }
     }
     // Display it all
     parent::display($tpl);
 }
Example #11
0
 /**
  * Analyzer view display method
  * @return void
  * */
 public function display($tpl = null)
 {
     $jinput = JFactory::getApplication()->input;
     $this->process = $jinput->get('process', false);
     // Check if we need to run the analyzer
     if ($this->process) {
         $this->items = $this->get('Analyze');
     }
     // Render the submenu
     if (version_compare(JVERSION, '3.0', '>=')) {
         CsviHelper::addSubmenu('analyzer');
         $this->sidebar = JHtmlSidebar::render();
     } else {
         // Get the panel
         $this->loadHelper('panel');
         $this->sidebar = '';
     }
     // Show the toolbar
     JToolBarHelper::title(JText::_('COM_CSVI_ANALYZER'), 'csvi_analyzer_48');
     JToolBarHelper::custom('analyzer.display', 'csvi_continue_32', 'csvi_continue_32', JText::_('COM_CSVI_ANALYZE'), false);
     //JToolBarHelper::help('about.html', true);
     // Display it all
     parent::display($tpl);
 }
Example #12
0
 /**
  * Customfields tables export
  *
  * Exports category details data to either csv, xml or HTML format
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		void
  * @since 		3.0
  */
 public function getStart()
 {
     // Get some basic data
     $db = JFactory::getDbo();
     $csvidb = new CsviDb();
     $jinput = JFactory::getApplication()->input;
     $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) {
             case 'id':
                 $userfields[] = $db->qn('c.id');
                 break;
             case 'custom_title':
                 $userfields[] = $db->qn('c.vm_custom_id');
                 break;
             case 'display_type':
                 $userfields[] = $db->qn('c.type_id');
                 $userfields[] = $db->qn('f.type', 'display_type');
                 break;
             case 'smart_search':
             case 'expanded':
             case 'scrollbar_after':
                 $userfields[] = $db->qn('c.params');
                 break;
             case 'custom':
                 break;
             default:
                 $userfields[] = $db->qn($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->qn("#__cf_customfields", "c"));
     $query->leftJoin($db->qn("#__cf_filtertypes", "f") . " ON " . $db->qn("c") . '.' . $db->qn("type_id") . ' = ' . $db->qn("f") . '.' . $db->qn("id"));
     // Ingore fields
     $ignore = array('custom', 'custom_title', 'display_type', 'smart_search', 'smart_search', 'expanded', 'scrollbar_after');
     // Check if we need to group the orders together
     $groupby = $template->get('groupby', 'general', false, 'bool');
     if ($groupby) {
         $filter = $this->getFilterBy('groupby', $ignore);
         if (!empty($filter)) {
             $query->group($filter);
         }
     }
     // Order by set field
     $orderby = $this->getFilterBy('sort', $ignore);
     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) {
                         case 'custom_title':
                             // Get the custom title
                             $query = $db->getQuery(true);
                             $query->select($db->qn('custom_title'));
                             $query->from($db->qn('#__virtuemart_customs'));
                             $query->where($db->qn('virtuemart_custom_id') . ' = ' . $db->q($record->vm_custom_id));
                             $db->setQuery($query);
                             $title = $db->loadResult();
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $title);
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'smart_search':
                         case 'expanded':
                         case 'scrollbar_after':
                             $params = json_decode($record->params);
                             $fieldvalue = $params->{$fieldname};
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'custom':
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         default:
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                     }
                 }
                 // Output the data
                 $this->addExportFields($record);
                 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();
         }
     }
 }
 /**
  * Subscription export
  *
  * Exports subscription details data to either csv, xml or HTML format
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		void
  * @since 		3.0
  */
 public function getStart()
 {
     // Get some basic data
     $db = JFactory::getDbo();
     $csvidb = new CsviDb();
     $jinput = JFactory::getApplication()->input;
     $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) {
         if ($field->process) {
             switch ($field->field_name) {
                 case 'user_id':
                 case 'akeebasubs_affiliate_id':
                     $userfields[] = $db->quoteName('#__akeebasubs_affiliates') . '.' . $db->quoteName($field->field_name);
                     break;
                 case 'money_owed':
                 case 'money_paid':
                 case 'total_commission':
                     $userfields[] = $db->quoteName('#__akeebasubs_affiliates') . '.' . $db->quoteName('akeebasubs_affiliate_id');
                     break;
                 case 'custom':
                     break;
                 default:
                     $userfields[] = $db->quoteName($field->field_name);
                     break;
             }
         }
     }
     // Build the query
     $userfields = array_unique($userfields);
     $query = $db->getQuery(true);
     $query->select(implode(",\n", $userfields));
     $query->from('#__akeebasubs_affiliates');
     $query->leftJoin('#__akeebasubs_affpayments ON #__akeebasubs_affpayments.akeebasubs_affiliate_id = #__akeebasubs_affiliates.akeebasubs_affiliate_id');
     $query->leftJoin('#__users ON #__users.id = #__akeebasubs_affiliates.user_id');
     // Check if there are any selectors
     $selectors = array();
     // Filter by published state
     $publish_state = $template->get('publish_state', 'general');
     if ($publish_state !== '' && ($publish_state == 1 || $publish_state == 0)) {
         $selectors[] = '#__akeebasubs_affiliates.enabled = ' . $publish_state;
     }
     // Check if we need to attach any selectors to the query
     if (count($selectors) > 0) {
         $query->where(implode("\n AND ", $selectors));
     }
     // Ignore some custom fields
     $ignore = array('money_owed', 'money_paid', 'total_commission');
     // Check if we need to group the orders together
     $groupby = $template->get('groupby', 'general', false, 'bool');
     if ($groupby) {
         $filter = $this->getFilterBy('groupby', $ignore);
         if (!empty($filter)) {
             $query->group($filter);
         }
     }
     // Order by set field
     $orderby = $this->getFilterBy('sort', $ignore);
     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;
                     // Add the replacement
                     if (isset($record->{$fieldname})) {
                         $fieldvalue = CsviHelper::replaceValue($field->replace, $record->{$fieldname});
                     } else {
                         $fieldvalue = '';
                     }
                     switch ($fieldname) {
                         case 'money_owed':
                             $query1 = $db->getQuery(true);
                             $query1->select('akeebasubs_affiliate_id, SUM(affiliate_comission) AS money_owed');
                             $query1->from('#__akeebasubs_subscriptions');
                             $query1->where('state = ' . $db->Quote('C'));
                             $query1->where('akeebasubs_affiliate_id = ' . $record->akeebasubs_affiliate_id);
                             $query1->group('akeebasubs_affiliate_id');
                             $query2 = $db->getQuery(true);
                             $query2->select('akeebasubs_affiliate_id, SUM(amount) AS money_paid');
                             $query2->from('#__akeebasubs_affpayments');
                             $query2->where('akeebasubs_affiliate_id = ' . $record->akeebasubs_affiliate_id);
                             $query2->group('akeebasubs_affiliate_id');
                             $query = $db->getQuery(true);
                             $query->select('money_owed-money_paid AS balance');
                             $query->from('#__akeebasubs_affiliates');
                             $query->leftJoin('(' . $query1 . ') AS o USING (' . $db->quoteName('akeebasubs_affiliate_id') . ')');
                             $query->leftJoin('(' . $query2 . ') AS p USING (' . $db->quoteName('akeebasubs_affiliate_id') . ')');
                             $query->where('akeebasubs_affiliate_id = ' . $record->akeebasubs_affiliate_id);
                             $db->setQuery($query);
                             $fieldvalue = $db->loadResult();
                             $fieldvalue = number_format($fieldvalue, $template->get('export_price_format_decimal', 'general', 2, 'int'), $template->get('export_price_format_decsep', 'general'), $template->get('export_price_format_thousep', 'general'));
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                             break;
                         case 'money_paid':
                             $query = $db->getQuery(true);
                             $query->select('SUM(amount) AS money_paid');
                             $query->from('lwraz_akeebasubs_affpayments');
                             $query->where('akeebasubs_affiliate_id = ' . $record->akeebasubs_affiliate_id);
                             $db->setQuery($query);
                             $fieldvalue = $db->loadResult();
                             $fieldvalue = number_format($fieldvalue, $template->get('export_price_format_decimal', 'general', 2, 'int'), $template->get('export_price_format_decsep', 'general'), $template->get('export_price_format_thousep', 'general'));
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                             break;
                         case 'total_commission':
                             $query = $db->getQuery(true);
                             $query->select('SUM(affiliate_comission) AS total_commision');
                             $query->from('#__akeebasubs_subscriptions');
                             $query->where('state = ' . $db->Quote('C'));
                             $query->where('akeebasubs_affiliate_id = ' . $record->akeebasubs_affiliate_id);
                             $query->group('akeebasubs_affiliate_id');
                             $db->setQuery($query);
                             $fieldvalue = $db->loadResult();
                             $fieldvalue = number_format($fieldvalue, $template->get('export_price_format_decimal', 'general', 2, 'int'), $template->get('export_price_format_decsep', 'general'), $template->get('export_price_format_thousep', 'general'));
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                             break;
                         case 'created_on':
                             $date = JFactory::getDate($record->{$fieldname});
                             $fieldvalue = CsviHelper::replaceValue($field->replace, date($template->get('export_date_format', 'general'), $date->toUnix()));
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                             break;
                         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();
         }
     }
 }
    /**
     * Product export
     *
     * Exports product data to either csv, xml or HTML format
     *
     * @copyright
     * @author		RolandD
     * @todo
     * @see
     * @access 		public
     * @param
     * @return 		void
     * @since 		3.0
     */
    public function getStart()
    {
        // Get some basic data
        $jinput = JFactory::getApplication()->input;
        $db = JFactory::getDbo();
        $csvidb = new CsviDb();
        $jinput = JFactory::getApplication()->input;
        $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');
        $this->_domainname = CsviHelper::getDomainName();
        $helper = new Com_VirtueMart();
        $sef = new CsviSef();
        // Build something fancy to only get the fieldnames the user wants
        $userfields = array();
        foreach ($export_fields as $column_id => $field) {
            if ($field->process) {
                switch ($field->field_name) {
                    case 'created_on':
                    case 'modified_on':
                    case 'locked_on':
                    case 'created_by':
                    case 'modified_by':
                    case 'locked_by':
                    case 'virtuemart_product_id':
                    case 'virtuemart_vendor_id':
                    case 'hits':
                    case 'metaauthor':
                    case 'metarobot':
                    case 'published':
                        $userfields[] = $db->quoteName('#__virtuemart_products') . '.' . $db->quoteName($field->field_name);
                        break;
                    case 'category_id':
                    case 'category_path':
                        $userfields[] = $db->quoteName('#__virtuemart_product_categories') . '.' . $db->quoteName('virtuemart_category_id');
                        $userfields[] = $db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('virtuemart_product_id');
                        break;
                    case 'product_name':
                    case 'product_s_desc':
                    case 'product_desc':
                    case 'metadesc':
                    case 'metakey':
                    case 'slug':
                    case 'customtitle':
                    case 'custom_value':
                    case 'custom_price':
                    case 'custom_param':
                    case 'custom_title':
                    case 'file_url':
                    case 'file_url_thumb':
                        $userfields[] = $db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('virtuemart_product_id');
                        break;
                    case 'product_parent_sku':
                        $userfields[] = $db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('product_parent_id');
                        break;
                    case 'related_products':
                        $userfields[] = $db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('virtuemart_product_id') . ' AS main_product_id';
                        break;
                    case 'product_box':
                        $userfields[] = $db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('product_packaging');
                        break;
                    case 'product_price':
                    case 'price_with_tax':
                        $userfields[] = $db->quoteName('#__virtuemart_product_prices') . '.' . $db->quoteName('product_price');
                        $userfields[] = $db->quoteName('#__virtuemart_currencies') . '.' . $db->quoteName('currency_code_3');
                        break;
                    case 'product_url':
                        $userfields[] = $db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('virtuemart_product_id');
                        $userfields[] = $db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('product_url');
                        $userfields[] = $db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('product_parent_id');
                        break;
                    case 'price_with_discount':
                        $userfields[] = $db->quoteName('#__virtuemart_product_prices') . '.' . $db->quoteName('product_price');
                        $userfields[] = $db->quoteName('#__virtuemart_currencies') . '.' . $db->quoteName('currency_code_3');
                        //$userfields[] = $db->quoteName('#__virtuemart_calcs').'.'.$db->quoteName('calc_value');
                        //$userfields[] = $db->quoteName('#__virtuemart_calcs').'.'.$db->quoteName('calc_value_mathop');
                        //$userfields[] = $db->quoteName('#__virtuemart_calcs').'.'.$db->quoteName('calc_kind');
                        break;
                    case 'product_currency':
                        $userfields[] = $db->quoteName('#__virtuemart_currencies') . '.' . $db->quoteName('currency_code_3');
                        break;
                    case 'custom_shipping':
                        $userfields[] = $db->quoteName('#__virtuemart_product_prices') . '.' . $db->quoteName('product_price');
                        $userfields[] = '1 AS tax_rate';
                        break;
                    case 'max_order_level':
                    case 'min_order_level':
                        $userfields[] = $db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('product_params');
                        break;
                        // Man made fields, do not export them
                    // Man made fields, do not export them
                    case 'custom':
                    case 'picture_url':
                    case 'basepricewithtax':
                    case 'discountedpricewithouttax':
                    case 'pricebeforetax':
                    case 'salesprice':
                    case 'taxamount':
                    case 'discountamount':
                    case 'pricewithouttax':
                    case 'manufacturer_name':
                        break;
                    default:
                        $userfields[] = $db->quoteName($field->field_name);
                        break;
                }
            }
        }
        /** Export SQL Query
         * Get all products - including items
         * as well as products without a price
         */
        $userfields = array_unique($userfields);
        $query = $db->getQuery(true);
        $query->select(implode(",\n", $userfields));
        $query->from('#__virtuemart_products');
        $query->leftJoin('#__virtuemart_product_prices ON #__virtuemart_products.virtuemart_product_id = #__virtuemart_product_prices.virtuemart_product_id');
        $query->leftJoin('#__virtuemart_product_manufacturers ON #__virtuemart_products.virtuemart_product_id = #__virtuemart_product_manufacturers.virtuemart_product_id');
        $query->leftJoin('#__virtuemart_shoppergroups ON #__virtuemart_product_prices.virtuemart_shoppergroup_id = #__virtuemart_shoppergroups.virtuemart_shoppergroup_id');
        $query->leftJoin('#__virtuemart_manufacturers ON #__virtuemart_product_manufacturers.virtuemart_manufacturer_id = #__virtuemart_manufacturers.virtuemart_manufacturer_id');
        $query->leftJoin('#__virtuemart_product_categories ON #__virtuemart_products.virtuemart_product_id = #__virtuemart_product_categories.virtuemart_product_id');
        $query->leftJoin('#__virtuemart_categories ON #__virtuemart_product_categories.virtuemart_category_id = #__virtuemart_categories.virtuemart_category_id');
        $query->leftJoin('#__virtuemart_currencies ON #__virtuemart_currencies.virtuemart_currency_id = #__virtuemart_product_prices.product_currency');
        // Check if there are any selectors
        $selectors = array();
        // Filter by product category
        /**
         * We are doing a selection on categories, need to redo the query to make sure child products get included
         * 1. Search all product ID's for that particular category
         * 2. Search for all child product ID's
         * 3. Load all products with these ids
         */
        $productcategories = $template->get('product_categories', 'product', false);
        if ($productcategories && $productcategories[0] != '') {
            $product_ids = array();
            // If selected get products of all subcategories as well
            if ($template->get('incl_subcategory', 'product', false)) {
                $q_subcat_ids = "SELECT category_child_id\r\n\t\t\t\t\t\t\t\t\tFROM #__virtuemart_category_categories\r\n\t\t\t\t\t\t\t\t\tWHERE category_parent_id IN ('" . implode("','", $productcategories) . "')";
                $db->setQuery($q_subcat_ids);
                $subcat_ids = $db->loadResultArray();
                $productcategories = array_merge($productcategories, $subcat_ids);
                $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
            }
            // Get only the parent products and products without children
            if ($template->get('parent_only', 'product', 0, 'bool')) {
                // Get all product IDs in the selected categories
                $q_product_ids = "SELECT p.virtuemart_product_id\r\n\t\t\t\t\t\t\tFROM #__virtuemart_products p\r\n\t\t\t\t\t\t\tLEFT JOIN #__virtuemart_product_categories x\r\n\t\t\t\t\t\t\tON p.virtuemart_product_id = x.virtuemart_product_id\r\n\t\t\t\t\t\t\tWHERE x.virtuemart_category_id IN ('" . implode("','", $productcategories) . "')\r\n\t\t\t\t\t\t\tAND p.product_parent_id = 0";
                $db->setQuery($q_product_ids);
                $product_ids = $db->loadResultArray();
                $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
            } else {
                if ($template->get('child_only', 'product', 0, 'bool')) {
                    // Load all non child IDs
                    $q_child = "SELECT p.virtuemart_product_id\r\n\t\t\t\t\t\t\t\t\tFROM #__virtuemart_products p\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN #__virtuemart_product_categories x\r\n\t\t\t\t\t\t\t\t\tON p.virtuemart_product_id = x.virtuemart_product_id\r\n\t\t\t\t\t\t\t\t\tWHERE x.virtuemart_category_id IN ('" . implode("','", $productcategories) . "')";
                    $db->setQuery($q_child);
                    $allproduct_ids = $db->loadResultArray();
                    $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
                    // Get all child product IDs in the selected categories
                    $q_child = "SELECT p.virtuemart_product_id\r\n\t\t\t\t\t\t\tFROM #__virtuemart_products p\r\n\t\t\t\t\t\t\tWHERE p.product_parent_id IN ('" . implode("','", $allproduct_ids) . "')";
                    $db->setQuery($q_child);
                    $child_ids = $db->loadResultArray();
                    $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
                    // Get all parent product IDs in the selected categories
                    $q_child = "SELECT p.product_parent_id\r\n\t\t\t\t\t\t\tFROM #__virtuemart_products p\r\n\t\t\t\t\t\t\tWHERE p.virtuemart_product_id IN ('" . implode("','", $child_ids) . "')";
                    $db->setQuery($q_child);
                    $parent_ids = $db->loadResultArray();
                    $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
                    // Combine all the IDs
                    $product_ids = array_merge($child_ids, array_diff($allproduct_ids, $parent_ids));
                } else {
                    // Get all product IDs
                    $q_product_ids = "SELECT p.virtuemart_product_id\r\n\t\t\t\t\t\t\tFROM #__virtuemart_products p\r\n\t\t\t\t\t\t\tLEFT JOIN #__virtuemart_product_categories x\r\n\t\t\t\t\t\t\tON p.virtuemart_product_id = x.virtuemart_product_id\r\n\t\t\t\t\t\t\tWHERE x.virtuemart_category_id IN ('" . implode("','", $productcategories) . "')";
                    $db->setQuery($q_product_ids);
                    $product_ids = $db->loadResultArray();
                    $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
                    // Get all child product IDs
                    if ($product_ids) {
                        $q_childproduct_ids = "SELECT p.virtuemart_product_id\r\n\t\t\t\t\t\t\t\tFROM #__virtuemart_products p\r\n\t\t\t\t\t\t\t\tWHERE p.product_parent_id IN ('" . implode("','", $product_ids) . "')";
                        $db->setQuery($q_childproduct_ids);
                        $childproduct_ids = $db->loadResultArray();
                        $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
                        // Now we have all the product IDs
                        $product_ids = array_merge($product_ids, $childproduct_ids);
                    }
                }
            }
            // Check if the user want child products
            if (!empty($product_ids)) {
                $selectors[] = '#__virtuemart_products.virtuemart_product_id IN (\'' . implode("','", $product_ids) . '\')';
            }
        } else {
            // Filter by published category state
            $category_publish = $template->get('publish_state_categories', 'product');
            // Filter on parent products and products without children
            if ($template->get('parent_only', 'product', 0, 'bool')) {
                $selectors[] = '#__virtuemart_products.product_parent_id = 0';
                if (!empty($category_publish)) {
                    $selectors[] = '#__virtuemart_categories.published = ' . $category_publish;
                }
            } else {
                if ($template->get('child_only', 'product', 0, 'bool')) {
                    // Load all non child IDs
                    $q_nonchild = 'SELECT #__virtuemart_products.virtuemart_product_id FROM #__virtuemart_products ';
                    $state = $category_publish == '1' ? '0' : '1';
                    if (!empty($category_publish)) {
                        $q_nonchild .= 'LEFT JOIN #__virtuemart_product_categories
								ON #__virtuemart_products.virtuemart_product_id = #__virtuemart_product_categories.virtuemart_product_id
								LEFT JOIN #__virtuemart_categories
								ON #__virtuemart_product_categories.virtuemart_category_id = #__virtuemart_categories.virtuemart_category_id
								WHERE #__virtuemart_categories.published = ' . $state;
                    }
                    $db->setQuery($q_nonchild);
                    $nonchild_ids = $db->loadResultArray();
                    $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
                    // Get the child IDs from the filtered category
                    if (!empty($category_publish)) {
                        $q_nonchild = 'SELECT #__virtuemart_products.virtuemart_product_id FROM #__virtuemart_products ';
                        $q_nonchild .= 'LEFT JOIN #__virtuemart_product_categories
								ON #__virtuemart_products.virtuemart_product_id = #__virtuemart_product_categories.virtuemart_product_id
								LEFT JOIN #__virtuemart_categories
								ON #__virtuemart_product_categories.virtuemart_category_id = #__virtuemart_categories.virtuemart_category_id
								WHERE #__virtuemart_products.product_parent_id IN (\'' . implode("','", $nonchild_ids) . '\')';
                        $q_nonchild .= ' GROUP BY virtuemart_product_id';
                        $db->setQuery($q_nonchild);
                        $child_ids = $db->loadResultArray();
                        $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
                        if (is_array($child_ids)) {
                            $nonchild_ids = array_merge($nonchild_ids, $child_ids);
                        }
                    }
                    $selectors[] = '#__virtuemart_products.virtuemart_product_id NOT IN (\'' . implode("','", $nonchild_ids) . '\')';
                } else {
                    if (!empty($category_publish)) {
                        // Get all product IDs
                        $q_product_ids = "SELECT p.virtuemart_product_id\r\n\t\t\t\t\t\t\t\tFROM #__virtuemart_products p\r\n\t\t\t\t\t\t\t\tLEFT JOIN #__virtuemart_product_categories x\r\n\t\t\t\t\t\t\t\tON p.virtuemart_product_id = x.virtuemart_product_id\r\n\t\t\t\t\t\t\t\tLEFT JOIN #__virtuemart_categories c\r\n\t\t\t\t\t\t\t\tON x.virtuemart_category_id = c.virtuemart_category_id\r\n\t\t\t\t\t\t\t\tWHERE c.category_publish = " . $db->Quote($category_publish);
                        $db->setQuery($q_product_ids);
                        $product_ids = $db->loadResultArray();
                        $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
                        // Get all child product IDs
                        if ($product_ids) {
                            $q_childproduct_ids = "SELECT p.virtuemart_product_id\r\n\t\t\t\t\t\t\t\t\tFROM #__virtuemart_products p\r\n\t\t\t\t\t\t\t\t\tWHERE p.product_parent_id IN ('" . implode("','", $product_ids) . "')";
                            $db->setQuery($q_childproduct_ids);
                            $childproduct_ids = $db->loadResultArray();
                            $csvilog->addDebug(JText::_('COM_CSVI_EXPORT_QUERY'), true);
                            // Now we have all the product IDs
                            $product_ids = array_merge($product_ids, $childproduct_ids);
                        }
                        // Check if the user want child products
                        if (!empty($product_ids)) {
                            $selectors[] = '#__virtuemart_products.virtuemart_product_id IN (\'' . implode("','", $product_ids) . '\')';
                        }
                    }
                }
            }
        }
        // Filter on featured products
        $featured = $template->get('featured', 'product', '');
        if ($featured) {
            $selectors[] = "#__virtuemart_products.product_special = 1";
        }
        // Filter by published state
        $product_publish = $template->get('publish_state', 'general');
        if ($product_publish !== '' && ($product_publish == 1 || $product_publish == 0)) {
            $selectors[] = '#__virtuemart_products.published = ' . $db->Quote($product_publish);
        }
        // Filter by product SKU
        $productskufilter = $template->get('productskufilter', 'product');
        if ($productskufilter) {
            $productskufilter .= ',';
            if (strpos($productskufilter, ',')) {
                $skus = explode(',', $productskufilter);
                $wildcard = '';
                $normal = array();
                foreach ($skus as $sku) {
                    if (!empty($sku)) {
                        if (strpos($sku, '%')) {
                            $wildcard .= "#__virtuemart_products.product_sku LIKE " . $db->Quote($sku) . " OR ";
                        } else {
                            $normal[] = $db->Quote($sku);
                        }
                    }
                }
                if (substr($wildcard, -3) == 'OR ') {
                    $wildcard = substr($wildcard, 0, -4);
                }
                if (!empty($wildcard) && !empty($normal)) {
                    $selectors[] = "(" . $wildcard . " OR #__virtuemart_products.product_sku IN (" . implode(',', $normal) . "))";
                } else {
                    if (!empty($wildcard)) {
                        $selectors[] = "(" . $wildcard . ")";
                    } else {
                        if (!empty($normal)) {
                            $selectors[] = "(#__virtuemart_products.product_sku IN (" . implode(',', $normal) . "))";
                        }
                    }
                }
            }
        }
        // Filter on price from
        $priceoperator = $template->get('priceoperator', 'product', 'gt');
        $pricefrom = $template->get('pricefrom', 'product', 0, 'float');
        $priceto = $template->get('priceto', 'product', 0, 'float');
        if (!empty($pricefrom)) {
            switch ($priceoperator) {
                case 'gt':
                    $selectors[] = "ROUND(#__virtuemart_product_prices.product_price, " . $template->get('export_price_format_decimal', 'general', 2, 'int') . ") > " . $pricefrom;
                    break;
                case 'eq':
                    $selectors[] = "ROUND(#__virtuemart_product_prices.product_price, " . $template->get('export_price_format_decimal', 'general', 2, 'int') . ") = " . $pricefrom;
                    break;
                case 'lt':
                    $selectors[] = "ROUND(#__virtuemart_product_prices.product_price, " . $template->get('export_price_format_decimal', 'general', 2, 'int') . ") < " . $pricefrom;
                    break;
                case 'bt':
                    $selectors[] = "ROUND(#__virtuemart_product_prices.product_price, " . $template->get('export_price_format_decimal', 'general', 2, 'int') . ") BETWEEN " . $pricefrom . " AND " . $priceto;
                    break;
            }
        }
        // Filter by stocklevel start
        $stocklevelstart = $template->get('stocklevelstart', 'product', 0, 'int');
        if ($stocklevelstart) {
            $selectors[] = '#__virtuemart_products.product_in_stock >= ' . $stocklevelstart;
        }
        // Filter by stocklevel end
        $stocklevelend = $template->get('stocklevelend', 'product', 0, 'int');
        if ($stocklevelend) {
            $selectors[] = '#__virtuemart_products.product_in_stock <= ' . $stocklevelend;
        }
        // Filter by shopper group id
        $shopper_group = $template->get('shopper_groups', 'product', array());
        if ($shopper_group && $shopper_group[0] != 'none') {
            $selectors[] = "#__virtuemart_product_prices.virtuemart_shoppergroup_id IN ('" . implode("','", $shopper_group) . "')";
        }
        // Filter by manufacturer
        $manufacturer = $template->get('manufacturers', 'product', array());
        if ($manufacturer && $manufacturer[0] != 'none') {
            $selectors[] = "#__virtuemart_manufacturers.virtuemart_manufacturer_id IN ('" . implode("','", $manufacturer) . "')";
        }
        // Check if we need to attach any selectors to the query
        if (count($selectors) > 0) {
            $query->where(implode("\n AND ", $selectors));
        }
        // Ingore fields
        $ignore = array('metadesc', 'metakey', 'product_name', 'product_s_desc', 'product_desc', 'slug', 'customtitle', 'category_path', 'manufacturer_name', 'category_id', 'picture_url', 'product_box', 'product_parent_sku', 'related_products', 'custom_shipping', 'basepricewithtax', 'discountedpricewithouttax', 'pricebeforetax', 'salesprice', 'taxamount', 'discountamount', 'pricewithouttax', 'custom_title', 'custom_value', 'custom_price', 'custom_param', 'file_url', 'file_url_thumb', 'min_order_level', 'max_order_level');
        // Check if we need to group the orders together
        $groupby = $template->get('groupby', 'general', false, 'bool');
        if ($groupby) {
            $filter = $this->getFilterBy('groupby', $ignore);
            if (!empty($filter)) {
                $query->group($filter);
            }
        }
        // Order by set field
        $orderby = $this->getFilterBy('sort', $ignore);
        if (!empty($orderby)) {
            $query->order($orderby);
        }
        // Add export limits
        $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();
            JRequest::setVar('logcount', $logcount);
            if ($logcount > 0) {
                $linenumber = 1;
                while ($record = $csvidb->getRow()) {
                    $csvilog->setLinenumber($linenumber++);
                    // Start the XML/HTML output
                    if ($template->get('export_file', 'general') == 'xml' || $template->get('export_file', 'general') == 'html') {
                        $this->addExportContent($exportclass->NodeStart());
                    }
                    // Load JoomFish translation if needed
                    $joomfish = array();
                    if ($template->get('use_joomfish', 'product', false)) {
                        $jfdb = JFactory::getDBO();
                        // Get the product details
                        $q = "SELECT value, reference_field\r\n\t\t\t\t\t\t\tFROM #__jf_content\r\n\t\t\t\t\t\t\tWHERE reference_table = 'vm_product'\r\n\t\t\t\t\t\t\tAND language_id = " . $template->get('joomfish_language', 'product') . "\r\n\t\t\t\t\t\t\tAND reference_id = " . $record->main_product_id;
                        $jfdb->setQuery($q);
                        $joomfish = $jfdb->loadObjectList('reference_field');
                    }
                    // Reset the prices
                    $this->_prices = array();
                    // Process all the export fields
                    foreach ($export_fields as $column_id => $field) {
                        if ($field->process) {
                            $fieldname = $field->field_name;
                            // Add the replacement & JoomFish
                            if (isset($record->{$fieldname})) {
                                // Get the JoomFish data
                                if (array_key_exists($fieldname, $joomfish)) {
                                    $fieldvalue = $joomfish[$fieldname]->value;
                                } else {
                                    $fieldvalue = $record->{$fieldname};
                                }
                                $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                            } else {
                                $fieldvalue = '';
                            }
                            switch ($fieldname) {
                                case 'category_id':
                                    $category_path = trim($helper->createCategoryPath($record->virtuemart_product_id, true));
                                    if (strlen(trim($category_path)) == 0) {
                                        $category_path = $field->default_value;
                                    }
                                    $category_path = CsviHelper::replaceValue($field->replace, $category_path);
                                    $this->addExportField($field->combine, $category_path, $fieldname, $field->column_header, true);
                                    break;
                                case 'category_path':
                                    $category_path = trim($helper->createCategoryPath($record->virtuemart_product_id));
                                    if (strlen(trim($category_path)) == 0) {
                                        $category_path = $field->default_value;
                                    }
                                    $category_path = CsviHelper::replaceValue($field->replace, $category_path);
                                    $this->addExportField($field->combine, $category_path, $fieldname, $field->column_header, true);
                                    break;
                                case 'product_name':
                                case 'product_s_desc':
                                case 'product_desc':
                                case 'metadesc':
                                case 'metakey':
                                case 'slug':
                                case 'customtitle':
                                    $query = $db->getQuery(true);
                                    $query->select($fieldname);
                                    $query->from('#__virtuemart_products_' . $template->get('language', 'general'));
                                    $query->where('virtuemart_product_id = ' . $record->virtuemart_product_id);
                                    $db->setQuery($query);
                                    $fieldvalue = CsviHelper::replaceValue($field->replace, $db->loadResult());
                                    // 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, true);
                                    break;
                                case 'picture_url':
                                    $query = $db->getQuery(true);
                                    $query->select('file_url');
                                    $query->from('#__virtuemart_medias');
                                    $query->leftJoin('#__virtuemart_product_medias ON #__virtuemart_product_medias.virtuemart_media_id = #__virtuemart_medias.virtuemart_media_id');
                                    $query->where('virtuemart_product_id = ' . $record->virtuemart_product_id);
                                    $query->order('#__virtuemart_product_medias.ordering');
                                    $db->setQuery($query, 0, 1);
                                    $fieldvalue = $db->loadResult();
                                    // Check if there is already a product full image
                                    if (strlen(trim($fieldvalue)) > 0) {
                                        $picture_url = $this->_domainname . '/' . $fieldvalue;
                                    } else {
                                        $picture_url = $field->default_value;
                                    }
                                    $picture_url = CsviHelper::replaceValue($field->replace, $picture_url);
                                    $this->addExportField($field->combine, $picture_url, $fieldname, $field->column_header);
                                    break;
                                case 'product_parent_sku':
                                    $query = $db->getQuery(true);
                                    $query->select('product_sku');
                                    $query->from('#__virtuemart_products');
                                    $query->where('virtuemart_product_id = ' . $record->product_parent_id);
                                    $db->setQuery($query);
                                    $product_parent_sku = $db->loadResult();
                                    $product_parent_sku = CsviHelper::replaceValue($field->replace, $product_parent_sku);
                                    $this->addExportField($field->combine, $product_parent_sku, $fieldname, $field->column_header);
                                    break;
                                case 'related_products':
                                    // Get the custom ID
                                    $related_records = array();
                                    $query = $db->getQuery(true);
                                    $query->select($db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('product_sku'));
                                    $query->from($db->quoteName('#__virtuemart_product_customfields'));
                                    $query->leftJoin($db->quoteName('#__virtuemart_customs') . ' ON ' . $db->quoteName('#__virtuemart_customs') . '.' . $db->quoteName('virtuemart_custom_id') . ' = ' . $db->quoteName('#__virtuemart_product_customfields') . '.' . $db->quoteName('virtuemart_custom_id'));
                                    $query->leftJoin($db->quoteName('#__virtuemart_products') . ' ON ' . $db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('virtuemart_product_id') . ' = ' . $db->quoteName('#__virtuemart_product_customfields') . '.' . $db->quoteName('custom_value'));
                                    $query->where($db->quoteName('#__virtuemart_customs') . '.' . $db->quoteName('field_type') . ' = ' . $db->quote('R'));
                                    $query->where($db->quoteName('#__virtuemart_product_customfields') . '.' . $db->quoteName('virtuemart_product_id') . ' = ' . $db->quote($record->virtuemart_product_id));
                                    $query->group($db->quoteName('#__virtuemart_products') . '.' . $db->quoteName('product_sku'));
                                    $db->setQuery($query);
                                    $related_records = $db->loadResultArray();
                                    if (is_array($related_records)) {
                                        $related_products = implode('|', $related_records);
                                    } else {
                                        $related_products = '';
                                    }
                                    if (strlen(trim($related_products)) == 0) {
                                        $related_products = $field->default_value;
                                    }
                                    $related_products = CsviHelper::replaceValue($field->replace, $related_products);
                                    $this->addExportField($field->combine, $related_products, $fieldname, $field->column_header);
                                    break;
                                case 'product_available_date':
                                case 'created_on':
                                case 'modified_on':
                                case 'locked_on':
                                    $date = JFactory::getDate($record->{$fieldname});
                                    $fieldvalue = CsviHelper::replaceValue($field->replace, date($template->get('export_date_format', 'general'), $date->toUnix()));
                                    $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                                    break;
                                case 'product_box':
                                    $product_box = $record->product_packaging >> 16 & 0xffff;
                                    $product_box = CsviHelper::replaceValue($field->replace, $product_box);
                                    $this->addExportField($field->combine, $product_box, $fieldname, $field->column_header);
                                    break;
                                case 'product_packaging':
                                    $product_packaging = $record->product_packaging & 0xffff;
                                    $product_packaging = CsviHelper::replaceValue($field->replace, $product_packaging);
                                    $this->addExportField($field->combine, $product_packaging, $fieldname, $field->column_header);
                                    break;
                                case 'product_price':
                                    $product_price = $this->_convertPrice($record->product_price, $record->currency_code_3);
                                    $product_price = number_format($product_price, $template->get('export_price_format_decimal', 'general', 2, 'int'), $template->get('export_price_format_decsep', 'general'), $template->get('export_price_format_thousep', 'general'));
                                    if (strlen(trim($product_price)) == 0) {
                                        $product_price = $field->default_value;
                                    }
                                    if ($template->get('add_currency_to_price', 'general')) {
                                        if ($template->get('targetcurrency', 'product') != '') {
                                            $product_price = $template->get('targetcurrency', 'product') . ' ' . $product_price;
                                        } else {
                                            $product_price = $record->currency_code_3 . ' ' . $product_price;
                                        }
                                    }
                                    $product_price = CsviHelper::replaceValue($field->replace, $product_price);
                                    $this->addExportField($field->combine, $product_price, $fieldname, $field->column_header);
                                    break;
                                case 'product_override_price':
                                    $product_price = number_format($record->product_override_price, $template->get('export_price_format_decimal', 'general', 2, 'int'), $template->get('export_price_format_decsep', 'general'), $template->get('export_price_format_thousep', 'general'));
                                    if (strlen(trim($product_price)) == 0) {
                                        $product_price = $field->default_value;
                                    }
                                    if ($template->get('add_currency_to_price', 'general')) {
                                        if ($template->get('targetcurrency', 'product') != '') {
                                            $product_price = $template->get('targetcurrency', 'product') . ' ' . $product_price;
                                        } else {
                                            $product_price = $record->currency_code_3 . ' ' . $product_price;
                                        }
                                    }
                                    $product_price = CsviHelper::replaceValue($field->replace, $product_price);
                                    $this->addExportField($field->combine, $product_price, $fieldname, $field->column_header);
                                    break;
                                case 'product_url':
                                    // Check if there is already a product URL
                                    if (is_null($record->product_url) || strlen(trim($record->product_url)) == 0) {
                                        // Get the category id
                                        // Check to see if we have a child product
                                        $category_id = $helper->getCategoryId($record->virtuemart_product_id);
                                        if ($category_id > 0) {
                                            // Let's create a SEF URL
                                            $_SERVER['QUERY_STRING'] = 'option=com_virtuemart&Itemid=' . $template->get('vm_itemid', 'product', 1, 'int') . '&view=productdetails&virtuemart_product_id=' . $record->virtuemart_product_id . '&virtuemart_category_id=' . $category_id;
                                            $product_url = $sef->getSiteRoute('index.php?' . $_SERVER['QUERY_STRING']);
                                        } else {
                                            $product_url = "";
                                        }
                                    } else {
                                        $product_url = $record->product_url;
                                    }
                                    // Add the suffix
                                    if (!empty($product_url)) {
                                        $product_url .= $template->get('producturl_suffix', 'product');
                                    }
                                    // Check for https, replace with http. https has unnecessary overhead
                                    if (substr($product_url, 0, 5) == 'https') {
                                        $product_url = 'http' . substr($product_url, 5);
                                    }
                                    $product_url = CsviHelper::replaceValue($field->replace, $product_url);
                                    $this->addExportField($field->combine, $product_url, $fieldname, $field->column_header, true);
                                    break;
                                case 'price_with_tax':
                                    $prices = $this->_getProductPrice($record->virtuemart_product_id);
                                    $price_with_tax = number_format($prices['salesPrice'], $template->get('export_price_format_decimal', 'general', 2, 'int'), $template->get('export_price_format_decsep', 'general'), $template->get('export_price_format_thousep', 'general'));
                                    // Check if we have any content otherwise use the default value
                                    if (strlen(trim($price_with_tax)) == 0) {
                                        $price_with_tax = $field->default_value;
                                    }
                                    if ($template->get('add_currency_to_price', 'general')) {
                                        $price_with_tax = $record->product_currency . ' ' . $price_with_tax;
                                    }
                                    $price_with_tax = CsviHelper::replaceValue($field->replace, $price_with_tax);
                                    $this->addExportField($field->combine, $price_with_tax, $fieldname, $field->column_header);
                                    break;
                                case 'basepricewithtax':
                                case 'discountedpricewithouttax':
                                case 'pricebeforetax':
                                case 'salesprice':
                                case 'taxamount':
                                case 'discountamount':
                                case 'pricewithouttax':
                                    $prices = $this->_getProductPrice($record->virtuemart_product_id);
                                    if (isset($prices[$fieldname])) {
                                        $price = number_format($prices[$fieldname], $template->get('export_price_format_decimal', 'general', 2, 'int'), $template->get('export_price_format_decsep', 'general'), $template->get('export_price_format_thousep', 'general'));
                                    }
                                    // Check if we have any content otherwise use the default value
                                    if (strlen(trim($price)) == 0) {
                                        $price = $field->default_value;
                                    }
                                    // Check if the currency needs to be added
                                    if ($template->get('add_currency_to_price', 'general')) {
                                        $price = $record->product_currency . ' ' . $price;
                                    }
                                    // Perform the replacement rules
                                    $price = CsviHelper::replaceValue($field->replace, $price);
                                    // Export the data
                                    $this->addExportField($field->combine, $price, $fieldname, $field->column_header);
                                    break;
                                case 'product_currency':
                                    $fieldvalue = $record->currency_code_3;
                                    // Check if we have any content otherwise use the default value
                                    if ($template->get('targetcurrency', 'product') != '') {
                                        $fieldvalue = $template->get('targetcurrency', 'product');
                                    }
                                    if (strlen(trim($fieldvalue)) == 0) {
                                        $fieldvalue = $field->default_value;
                                    }
                                    $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                                    break;
                                case 'custom_shipping':
                                    // Get the prices
                                    $prices = $this->_getProductPrice($record->virtuemart_product_id);
                                    // Check the shipping cost
                                    if (isset($prices['salesprice'])) {
                                        $price_with_tax = number_format($prices['salesprice'], $template->get('export_price_format_decimal', 'general', 2, 'int'), $template->get('export_price_format_decsep', 'general'), $template->get('export_price_format_thousep', 'general'));
                                        $result = $helper->shippingCost($price_with_tax);
                                        if ($result) {
                                            $fieldvalue = $result;
                                        }
                                    }
                                    // 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;
                                case 'manufacturer_name':
                                    $query = $db->getQuery(true);
                                    $query->select('mf_name');
                                    $query->from('#__virtuemart_manufacturers_' . $template->get('language', 'general'));
                                    $query->leftJoin('#__virtuemart_product_manufacturers ON #__virtuemart_product_manufacturers.virtuemart_manufacturer_id = #__virtuemart_manufacturers_' . $template->get('language', 'general') . '.virtuemart_manufacturer_id');
                                    $query->where('virtuemart_product_id = ' . $record->virtuemart_product_id);
                                    $db->setQuery($query);
                                    $fieldvalue = CsviHelper::replaceValue($field->replace, $db->loadResult());
                                    // 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, true);
                                    break;
                                case 'custom_title':
                                    // Get the custom title
                                    $query = $db->getQuery(true);
                                    $query->select($db->quoteName('custom_title'));
                                    $query->from($db->quoteName('#__virtuemart_customs') . ' AS c');
                                    $query->leftJoin($db->quoteName('#__virtuemart_product_customfields') . ' AS f ON c.virtuemart_custom_id = f.virtuemart_custom_id');
                                    $query->where($db->quoteName('virtuemart_product_id') . ' = ' . $db->quote($record->virtuemart_product_id));
                                    // Check if we need to filter
                                    $title_filter = array();
                                    $title_filter = $template->get('custom_title', 'product', array(), 'array');
                                    if (!empty($title_filter) && $title_filter[0] != '') {
                                        $query->where($db->quoteName('f') . '.' . $db->quoteName('virtuemart_custom_id') . ' IN (' . implode(',', $title_filter) . ')');
                                    }
                                    $query->order($db->quoteName('f') . '.' . $db->quoteName('virtuemart_custom_id'));
                                    $db->setQuery($query);
                                    $titles = $db->loadResultArray();
                                    if (is_array($titles)) {
                                        $fieldvalue = CsviHelper::replaceValue($field->replace, implode('|', $titles));
                                        // Check if we have any content otherwise use the default value
                                    } else {
                                        $fieldvalue = '';
                                    }
                                    if (strlen(trim($fieldvalue)) == 0) {
                                        $fieldvalue = $field->default_value;
                                    }
                                    $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header, true);
                                    break;
                                case 'custom_value':
                                case 'custom_price':
                                case 'custom_param':
                                    if (!isset($this->_customfields[$record->virtuemart_product_id][$fieldname])) {
                                        $query = $db->getQuery(true);
                                        $query->select($db->quoteName($fieldname));
                                        $query->from($db->quoteName('#__virtuemart_product_customfields'));
                                        $query->where($db->quoteName('virtuemart_product_id') . ' = ' . $db->quote($record->virtuemart_product_id));
                                        // Check if we need to filter
                                        $title_filter = array();
                                        $title_filter = $template->get('custom_title', 'product', array());
                                        if (!empty($title_filter) && $title_filter[0] != '') {
                                            $query->where($db->quoteName('virtuemart_custom_id') . ' IN (' . implode(',', $title_filter) . ')');
                                        }
                                        $query->order($db->quoteName('virtuemart_custom_id'));
                                        $db->setQuery($query);
                                        $customfields = $db->loadObjectList();
                                        $csvilog->addDebug('COM_CSVI_CUSTOM_FIELD_QUERY', true);
                                        if (!empty($customfields)) {
                                            $values = array();
                                            foreach ($customfields as $customfield) {
                                                $values[] = $customfield->{$fieldname};
                                            }
                                            $this->_customfields[$record->virtuemart_product_id][$fieldname] = $values;
                                            $fieldvalue = implode('|', $this->_customfields[$record->virtuemart_product_id][$fieldname]);
                                        } else {
                                            $fieldvalue = '';
                                        }
                                    } else {
                                        $fieldvalue = implode('|', $this->_customfields[$record->virtuemart_product_id][$fieldname]);
                                    }
                                    $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                                    // 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, true);
                                    break;
                                case 'file_url':
                                case 'file_url_thumb':
                                    $query = $db->getQuery(true);
                                    $query->select($db->quoteName($fieldname));
                                    $query->from($db->quoteName('#__virtuemart_medias') . ' AS m');
                                    $query->leftJoin($db->quoteName('#__virtuemart_product_medias') . ' AS p ON m.virtuemart_media_id = p.virtuemart_media_id');
                                    $query->where($db->quoteName('virtuemart_product_id') . ' = ' . $db->quote($record->virtuemart_product_id));
                                    $query->where($db->quoteName('file_type') . ' = ' . $db->quote('product'));
                                    $query->order('p.ordering');
                                    $db->setQuery($query);
                                    $titles = $db->loadResultArray();
                                    if (is_array($titles)) {
                                        $fieldvalue = CsviHelper::replaceValue($field->replace, implode('|', $titles));
                                        // Check if we have any content otherwise use the default value
                                    } else {
                                        $fieldvalue = '';
                                    }
                                    if (strlen(trim($fieldvalue)) == 0) {
                                        $fieldvalue = $field->default_value;
                                    }
                                    $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header, true);
                                    break;
                                case 'min_order_level':
                                case 'max_order_level':
                                    if (strpos($record->product_params, '|')) {
                                        $params = explode('|', $record->product_params);
                                        foreach ($params as $param) {
                                            if ($param) {
                                                list($param_name, $param_value) = explode('=', $param);
                                                if ($param_name == $fieldname) {
                                                    $fieldvalue = str_replace('"', '', $param_value);
                                                }
                                            }
                                        }
                                    } else {
                                        $fieldvalue = '';
                                    }
                                    if (strlen(trim($fieldvalue)) == 0) {
                                        $fieldvalue = $field->default_value;
                                    }
                                    $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                                    $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                                    break;
                                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();
            }
        }
    }
Example #15
0
 /**
  * Initialise some settings
  */
 public function runCron()
 {
     // Buffer all output to prevent conflicts with external software
     ob_start();
     // Start the clock
     $starttime = time();
     $db = JFactory::getDbo();
     // First check if we deal with a valid user
     if ($this->Login()) {
         // Set some global values
         $jinput = JFactory::getApplication()->input;
         $jfilter = new JFilterInput();
         // Get the parameters
         require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/settings.php';
         $settings = new CsviSettings();
         // Check if we are running cron mode and set some necessary variables
         $_SERVER['SERVER_ADDR'] = $_SERVER['HTTP_HOST'] = $settings->get('site.hostname');
         $_SERVER['SCRIPT_NAME'] = '/index.php';
         $_SERVER['REQUEST_URI'] = '/';
         $_SERVER['PHP_SELF'] = '/index.php';
         // Get the task to do
         if (isset($this->_variables['task'])) {
             $task = $jfilter->clean($this->_variables['task']);
         } else {
             $task = '';
         }
         // Perform the requested task
         switch ($task) {
             case 'maintenance':
                 $jinput->set('task', 'maintenance.' . $this->_variables['operation']);
                 // Fire CSVI VirtueMart
                 $this->ExecuteJob();
                 break;
             default:
                 // Second check if any template is set to process
                 if (array_key_exists('template_id', $this->_variables)) {
                     $template_id = $jfilter->clean($this->_variables['template_id'], 'int');
                 } else {
                     $template_id = false;
                 }
                 if (array_key_exists('template_name', $this->_variables)) {
                     $template_name = $jfilter->clean($this->_variables['template_name']);
                 } else {
                     $template_name = false;
                 }
                 if ($template_id || $template_name) {
                     // There is a template_id or template name, get some details to streamline processing
                     $where = empty($template_id) ? 'name=' . $db->Quote($template_name) : 'id=' . $template_id;
                     // There is a template name, get some details to streamline processing
                     $q = "SELECT id AS template_id, name AS template_name, settings\r\n\t\t\t\t\t\t\tFROM #__csvi_template_settings\r\n\t\t\t\t\t\t\tWHERE " . $where;
                     $db->setQuery($q);
                     $row = $db->loadObject();
                     if (is_object($row)) {
                         echo JText::sprintf('COM_CSVI_PROCESSING_STARTED', date('jS F Y, g:i a')) . "\n";
                         echo JText::sprintf('COM_CSVI_TEMPLATE', $row->template_name) . "\n";
                         // Set the template ID
                         $jinput->set('select_template', $row->template_id);
                         $jinput->set('template_name', $row->template_name);
                         // Set the settings
                         if (array_key_exists('jform', $this->_variables)) {
                             $settings = CsviHelper::arrayExtend(json_decode($row->settings, true), $this->_variables['jform']);
                         } else {
                             $settings = json_decode($row->settings, true);
                         }
                         // Set some export settings
                         if ($settings['options']['action'] == 'export') {
                             // Export settings
                             $jinput->set('task', 'exportfile.process');
                             // Set export to
                             if ($settings['general']['exportto'] == 'todownload') {
                                 $settings['general']['exportto'] = 'tofile';
                             }
                         } else {
                             if ($settings['options']['action'] == 'import') {
                                 // Import settings
                                 $jinput->set('task', 'importfile.doimport');
                                 // Turn off preview
                                 $settings['general']['show_preview'] = 0;
                             }
                         }
                         // Post the settings
                         $jinput->set('jform', $settings, 'post');
                         // Fire CSVI
                         $this->ExecuteJob();
                     } else {
                         if ($template_name) {
                             echo JText::sprintf('COM_CSVI_NO_TEMPLATE_FOUND', $template_name) . "\n";
                         } else {
                             if ($template_id) {
                                 echo JText::sprintf('COM_CSVI_NO_TEMPLATE_FOUND', $template_id) . "\n";
                             }
                         }
                     }
                 } else {
                     echo JText::_('COM_CSVI_NO_TEMPLATE_SPECIFIED') . "\n";
                 }
                 break;
         }
     } else {
         $error = JError::getError();
         echo $error->message . "\n";
     }
     echo sprintf(JText::_('COM_CSVI_PROCESSING_FINISHED'), date('jS F Y, g:i a')) . "\n";
     $duration = time() - $starttime;
     if ($duration < 60) {
         echo sprintf(JText::_('COM_CSVI_PROCESSING_SECONDS'), $duration) . "\n";
     } else {
         echo sprintf(JText::_('COM_CSVI_PROCESSING_MINUTES'), number_format($duration / 60, 2)) . "\n";
     }
     // Done, lets log the user out
     $this->UserLogout();
     // Display any generated messages
     $messages = ob_get_contents();
     @ob_end_clean();
     echo $messages;
 }
 /**
  * Validate input data
  *
  * Checks if the field has a value, if not check if the user wants us to
  * use the default value
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		protected
  * @param 		string 	$fieldname 	the fieldname to validate
  * @param		int		$replaceid	the ID of the replacement rule
  * @return		true returns validated value | return false if the column count does not match
  * @since
  */
 protected function validateInput($fieldname, $replaceid = null)
 {
     $jinput = JFactory::getApplication()->input;
     $csvilog = $jinput->get('csvilog', null, null);
     $template = $jinput->get('template', null, null);
     $newvalue = '';
     // Check if the user wants ICEcat data
     if ($template->get('use_icecat', 'product', false, 'bool') && !empty($this->icecat_data) && array_key_exists($fieldname, $this->icecat_data)) {
         $csvilog->addDebug(JText::sprintf('COM_CSVI_USE_ICECAT_FIELD', $fieldname));
         $newvalue = $this->icecat_data[$fieldname];
     } else {
         if (isset($this->_csvifields[$fieldname])) {
             // Check if the field has a value
             if (array_key_exists($this->_csvifields[$fieldname]["order"], $this->csvi_data) && strlen($this->csvi_data[$this->_csvifields[$fieldname]["order"]]) > 0) {
                 $csvilog->addDebug(JText::_('COM_CSVI_USE_FIELD_VALUE'));
                 $newvalue = trim($this->csvi_data[$this->_csvifields[$fieldname]["order"]]);
             } else {
                 if (!$this->_skip_default_value) {
                     $csvilog->addDebug(JText::_('COM_CSVI_USE_DEFAULT_VALUE'));
                     $newvalue = $this->_csvifields[$fieldname]["default_value"];
                 } else {
                     $csvilog->addDebug(JText::_('COM_CSVI_USE_NO_VALUE'));
                     return '';
                 }
             }
         } else {
             return false;
         }
     }
     // Replace the value and return
     if (!empty($newvalue) && !empty($replaceid)) {
         return CsviHelper::replaceValue($replaceid, $newvalue);
     } else {
         return $newvalue;
     }
 }
Example #17
0
 /**
  * Import the available fields in steps
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		3.5
  */
 public function getAvailableFieldsSingle()
 {
     $db = JFactory::getDbo();
     $jinput = JFactory::getApplication()->input;
     $queries = array();
     // Load the session data
     $session = JFactory::getSession();
     $option = $jinput->get('option');
     $csvilog = unserialize($session->get($option . '.csvilog'));
     $lines = unserialize($session->get($option . '.linesprocessed'));
     if (empty($lines)) {
         $lines = 0;
     }
     $lines++;
     // Set the line number
     $csvilog->setLinenumber($lines);
     $errors = false;
     $process = false;
     // Load a table to index
     while (!$process) {
         $query = $db->getQuery(true);
         $query->select('template_table, component')->from('#__csvi_template_tables')->where('indexed = 0')->where($db->qn('template_table') . ' != ' . $db->qn('template_type_name'))->group($db->qn('template_table'));
         $db->setQuery($query, 0, 1);
         $table = $db->loadObject();
         if (is_object($table)) {
             // Set the table name
             $showtable = $table->template_table;
             // Check if the table exists
             $tables = $db->getTableList();
             if (in_array($db->getPrefix() . $showtable, $tables)) {
                 // Get the primary key for the table
                 $primarykey = CsviHelper::getPrimaryKey($showtable);
                 $fields = $this->DbFields($showtable, true);
                 if (is_array($fields)) {
                     $process = true;
                     // Process all fields
                     foreach ($fields as $name => $value) {
                         // Check if the field is a primary field
                         if ($primarykey == $name) {
                             $primary = 1;
                         } else {
                             $primary = 0;
                         }
                         if ($name) {
                             $q = "INSERT IGNORE INTO " . $db->qn('#__csvi_available_fields') . " VALUES (" . "0," . $db->q($name) . "," . $db->q($name) . "," . $db->q($value) . "," . $db->q($table->component) . "," . $db->q($primary) . ")";
                             $db->setQuery($q);
                             if (!$db->query()) {
                                 $errors = true;
                             }
                         }
                     }
                     // foreach
                     // Check for any errors
                     if (!$errors) {
                         $jinput->set('updatetable', $showtable);
                         $csvilog->AddStats('added', JText::sprintf('COM_CSVI_AVAILABLE_FIELDS_HAVE_BEEN_ADDED', $showtable));
                     } else {
                         $csvilog->AddStats('error', JText::_('COM_CSVI_AVAILABLE_FIELDS_HAVE_NOT_BEEN_ADDED'));
                     }
                 }
                 // is_array
             }
             // Set the table to indexed
             $query = $db->getQuery(true);
             $query->update('#__csvi_template_tables')->set('indexed = 1')->where('template_table = ' . $db->quote($showtable))->where('component = ' . $db->quote($table->component));
             $db->setQuery($query);
             $db->query();
             // Assign the tables to the session
             $session->set($option . '.linesprocessed', serialize($lines));
             $continue = true;
         } else {
             $jinput->set('csvilog', $csvilog);
             // Clear the session
             $session->set($option . '.csvilog', serialize('0'));
             $session->set($option . '.linesprocessed', serialize('0'));
             // Set the run ID
             $jinput->set('run_id', $csvilog->getId());
             $continue = false;
             $process = true;
         }
         // Assign the log to the session
         $session->set($option . '.csvilog', serialize($csvilog));
     }
     return $continue;
 }
Example #18
0
 /**
  * Property tables export
  *
  * Exports category details data to either csv, xml or HTML format
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		void
  * @since 		3.4
  */
 public function getStart()
 {
     // Get some basic data
     $db = JFactory::getDbo();
     $csvidb = new CsviDb();
     $jinput = JFactory::getApplication()->input;
     $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');
     $this->_domainname = CsviHelper::getDomainName();
     $classname = 'CsviCom_Ezrealty_Config';
     if (class_exists($classname)) {
         $config = new $classname();
     }
     // Build something fancy to only get the fieldnames the user wants
     $userfields = array();
     foreach ($export_fields as $column_id => $field) {
         switch ($field->field_name) {
             case 'id':
             case 'alias':
             case 'checked_out':
             case 'checked_out_time':
             case 'editor':
             case 'ordering':
             case 'published':
                 $userfields[] = $db->qn('e.' . $field->field_name);
                 break;
             case 'category':
                 $userfields[] = $db->qn('c.name');
                 break;
             case 'country':
                 $userfields[] = $db->qn('cn.name', 'country');
                 break;
             case 'state':
                 $userfields[] = $db->qn('st.name', 'state');
                 break;
             case 'city':
                 $userfields[] = $db->qn('loc.ezcity', 'city');
                 break;
             case 'fname':
             case 'file_title':
             case 'file_description':
             case 'file_ordering':
             case 'picture_url':
             case 'picture_url_thumb':
                 $userfields[] = $db->qn('e.id');
                 break;
             case 'custom':
                 break;
             default:
                 $userfields[] = $db->qn($field->field_name);
                 break;
         }
     }
     // Build the query
     $userfields = array_unique($userfields);
     $query = $db->getQuery(true);
     $query->select(implode(",\n", $userfields));
     $query->from($db->qn('#__ezrealty', 'e'));
     $query->leftJoin($db->qn('#__ezrealty_catg', 'c') . ' ON ' . $db->qn('e.cid') . ' = ' . $db->qn('c.id'));
     $query->leftJoin($db->qn('#__ezrealty_country', 'cn') . ' ON ' . $db->qn('e.cnid') . ' = ' . $db->qn('cn.id'));
     $query->leftJoin($db->qn('#__ezrealty_state', 'st') . ' ON ' . $db->qn('e.stid') . ' = ' . $db->qn('st.id'));
     $query->leftJoin($db->qn('#__ezrealty_locality', 'loc') . ' ON ' . $db->qn('e.locid') . ' = ' . $db->qn('loc.id'));
     $selectors = array();
     // Filter by published state
     $publish_state = $template->get('publish_state', 'general');
     if ($publish_state != '' && ($publish_state == 1 || $publish_state == 0)) {
         $selectors[] = $db->qn('e.published') . ' = ' . $publish_state;
     }
     // Filter by transaction type
     $transaction_type = $template->get('transaction_type', 'property');
     if ($transaction_type[0] != '') {
         $selectors[] = $db->qn('e.type') . ' IN (' . implode(',', $transaction_type) . ')';
     }
     // Filter by property type
     $property_type = $template->get('property_type', 'property');
     if ($property_type[0] != '') {
         $selectors[] = $db->qn('e.cid') . ' IN (' . implode(',', $property_type) . ')';
     }
     // Filter by street
     $street = $template->get('street', 'property');
     if ($street[0] != '') {
         $selectors[] = $db->qn('e.address2') . " IN ('" . implode("','", $street) . "')";
     }
     // Filter by locality
     $locality = $template->get('locality', 'property');
     if ($locality[0] != '') {
         $selectors[] = $db->qn('e.locality') . " IN ('" . implode("','", $locality) . "')";
     }
     // Filter by states
     $state = $template->get('state', 'property');
     if ($state[0] != '') {
         $selectors[] = $db->qn('e.state') . " IN ('" . implode("','", $state) . "')";
     }
     // Filter by countries
     $country = $template->get('country', 'property');
     if ($country[0] != '') {
         $selectors[] = $db->qn('e.country') . " IN ('" . implode("','", $country) . "')";
     }
     // Filter by owner
     $owner = $template->get('owner', 'property');
     if ($owner[0] != '') {
         $selectors[] = $db->qn('e.owner') . ' IN (' . implode(',', $owner) . ')';
     }
     // Check if we need to attach any selectors to the query
     if (count($selectors) > 0) {
         $query->where(implode("\n AND ", $selectors));
     }
     // Ingore fields
     $ignore = array('custom', 'category', 'country', 'state', 'city', 'fname', 'file_title', 'file_description', 'file_ordering', 'picture_url', 'picture_url_thumb');
     // Check if we need to group the orders together
     $groupby = $template->get('groupby', 'general', false, 'bool');
     if ($groupby) {
         $filter = $this->getFilterBy('groupby', $ignore);
         if (!empty($filter)) {
             $query->group($filter);
         }
     }
     // Order by set field
     $orderby = $this->getFilterBy('sort', $ignore);
     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) {
                         case 'aucdate':
                         case 'availdate':
                         case 'checked_out_time':
                         case 'listdate':
                         case 'ohdate':
                         case 'ohdate2':
                             $date = JFactory::getDate($record->{$fieldname});
                             $fieldvalue = CsviHelper::replaceValue($field->replace, date($template->get('export_date_format', 'general'), $date->toUnix()));
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'expdate':
                         case 'lastupdate':
                             $fieldvalue = CsviHelper::replaceValue($field->replace, date($template->get('export_date_format', 'general'), $record->{$fieldname}));
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'bond':
                         case 'closeprice':
                         case 'offpeak':
                         case 'price':
                             $fieldvalue = number_format($fieldvalue, $template->get('export_price_format_decimal', 'general', 2, 'int'), $template->get('export_price_format_decsep', 'general'), $template->get('export_price_format_thousep', 'general'));
                             if ($template->get('add_currency_to_price', 'general')) {
                                 $fieldvalue = $config->get('er_currencycode') . ' ' . $fieldvalue;
                             }
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'custom_title':
                             // Get the custom title
                             $query = $db->getQuery(true);
                             $query->select($db->qn('custom_title'));
                             $query->from($db->qn('#__virtuemart_customs'));
                             $query->where($db->qn('virtuemart_custom_id') . ' = ' . $db->q($record->vm_custom_id));
                             $db->setQuery($query);
                             $title = $db->loadResult();
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $title);
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'category':
                             $fieldvalue = $record->name;
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'fname':
                         case 'file_title':
                         case 'file_description':
                         case 'file_ordering':
                             $query = $db->getQuery(true);
                             $query->select($db->qn('i.' . str_ireplace('file_', '', $fieldname)));
                             $query->from($db->qn('#__ezrealty_images', 'i'));
                             $query->leftJoin($db->qn('#__ezrealty', 'e') . ' ON ' . $db->qn('i.propid') . ' = ' . $db->qn('e.id'));
                             $query->where($db->qn('e.id') . ' = ' . $db->q($record->id));
                             $query->order('i.ordering');
                             $db->setQuery($query);
                             $titles = $db->loadColumn();
                             if (is_array($titles)) {
                                 $fieldvalue = CsviHelper::replaceValue($field->replace, implode('|', $titles));
                                 // Check if we have any content otherwise use the default value
                             } else {
                                 $fieldvalue = '';
                             }
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'picture_url':
                         case 'picture_url_thumb':
                             $query = $db->getQuery(true);
                             $query->select($db->qn('fname'));
                             $query->from($db->qn('#__ezrealty_images'));
                             $query->where($db->qn('propid') . ' = ' . $record->id);
                             $query->order($db->qn('ordering'));
                             $db->setQuery($query, 0, 1);
                             $fieldvalue = $db->loadResult();
                             // Check if there is already a product full image
                             if (strlen(trim($fieldvalue)) > 0) {
                                 if ($fieldname == 'picture_url') {
                                     $picture_url = $this->_domainname . '/components/com_ezrealty/ezrealty/' . $fieldvalue;
                                 } else {
                                     $picture_url = $this->_domainname . '/components/com_ezrealty/ezrealty/th/' . $fieldvalue;
                                 }
                             } else {
                                 $picture_url = $field->default_value;
                             }
                             $picture_url = CsviHelper::replaceValue($field->replace, $picture_url);
                             $record->output[$column_id] = $picture_url;
                             break;
                         case 'custom':
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         default:
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                     }
                 }
                 // Output the data
                 $this->addExportFields($record);
                 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();
         }
     }
 }
Example #19
0
 /**
  * Import view display method
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		3.0
  */
 public function display($tpl = null)
 {
     $jinput = JFactory::getApplication()->input;
     $session = JFactory::getSession();
     $option = $jinput->get('option');
     // Load the models
     $model = $this->getModel();
     $this->setModel(JModelLegacy::getInstance('templates', 'CsviModel'));
     $this->setModel(JModelLegacy::getInstance('availablefields', 'CsviModel'));
     // Load stylesheet
     $document = JFactory::getDocument();
     $document->addStyleSheet(JURI::root() . 'administrator/components/com_csvi/assets/css/process.css');
     // Set the template ID
     $sess_template_id = $session->get($option . '.select_template', 0);
     if ($sess_template_id !== 0) {
         $sess_template_id = unserialize($sess_template_id);
     }
     $template_id = $jinput->get('template_id', $sess_template_id, 'int');
     $jinput->set('template_id', $template_id);
     // Load the saved templates
     $template_model = $this->getModel('Templates');
     $this->templates = JHtml::_('select.genericlist', $template_model->getTemplates(), 'select_template', 'class="input-xlarge"', 'value', 'text', $jinput->get('template_id', 0, 'int'));
     // Load the selected template
     $this->loadHelper('template');
     $this->template = new CsviTemplate();
     $this->template->load($template_id);
     $jinput->set('template', $this->template);
     // Set the action, component and operation for the form
     if ($template_id > 0) {
         $jinput->set('jform', $this->template->getSettings());
     }
     // Load the option templates
     $this->optiontemplates = $model->getOptions();
     // Get the options for the user
     $this->form = $model->getForm(array(), true, $this->optiontemplates);
     // Load the fields
     $av_model = $this->getModel('availablefields');
     $this->templatefields = $av_model->getAvailableFields($this->form->getValue('operation', 'options'), $this->form->getValue('component', 'options'), 'object', $this->form->getValue('custom_table'));
     // Load the replacements for the add field section
     $this->replacements = $this->get('Replacements');
     // Add the component path to find template files
     $this->addTemplatePath(JPATH_COMPONENT_ADMINISTRATOR . '/views/process/tmpl/' . $this->form->getValue('component', 'options') . '/' . $this->form->getValue('action', 'options'));
     $this->addTemplatePath(JPATH_COMPONENT_ADMINISTRATOR . '/views/process/tmpl/' . $this->form->getValue('action', 'options'));
     // Load the helper
     $this->loadHelper($this->form->getValue('component', 'options'));
     // Load the configuration helper
     $this->loadHelper($this->form->getValue('component', 'options') . '_config');
     $classname = 'Csvi' . $this->form->getValue('component', 'options') . '_config';
     if (class_exists($classname)) {
         $this->config = new $classname();
     }
     // Render the submenu
     if (version_compare(JVERSION, '3.0', '>=')) {
         CsviHelper::addSubmenu('process');
         $this->sidebar = JHtmlSidebar::render();
     } else {
         // Get the panel
         $this->loadHelper('panel');
         $this->sidebar = '';
     }
     // Get the toolbar title
     JToolBarHelper::title(JText::_('COM_CSVI_PROCESS'), 'csvi_process_48');
     // Get the toolbar
     JToolBarHelper::custom('analyzer', 'csvi_analyzer_32', 'csvi_analyzer_32', JText::_('COM_CSVI_ANALYZER'), false);
     JToolBarHelper::divider();
     JToolBarHelper::custom('cronline', 'csvi_cron_32', 'csvi_cron_32', JText::_('COM_CSVI_CRONLINE'), false);
     JToolBarHelper::custom('process.imexport', 'csvi_process_32', 'csvi_process_32', JText::_('COM_CSVI_PROCESS'), false);
     //JToolBarHelper::help('process.html', true);
     // Display it all
     parent::display($tpl);
 }
Example #20
0
 /**
  * Calculation rules export
  *
  * Exports calculation rules details data to either csv, xml or HTML format
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		void
  * @since 		3.0
  */
 public function getStart()
 {
     // Get some basic data
     $db = JFactory::getDbo();
     $csvidb = new CsviDb();
     $jinput = JFactory::getApplication()->input;
     $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');
     $helper = new Com_VirtueMart();
     // Build something fancy to only get the fieldnames the user wants
     $userfields = array();
     foreach ($export_fields as $column_id => $field) {
         if ($field->process) {
             switch ($field->field_name) {
                 case 'virtuemart_calc_id':
                 case 'created_by':
                 case 'created_on':
                 case 'locked_by':
                 case 'locked_on':
                 case 'modified_by':
                 case 'modified_on':
                 case 'ordering':
                 case 'published':
                 case 'shared':
                 case 'virtuemart_vendor_id':
                     $userfields[] = '#__virtuemart_calcs.' . $field->field_name;
                     break;
                 case 'category_path':
                 case 'shopper_group_name':
                 case 'country_name':
                 case 'country_2_code':
                 case 'country_3_code':
                 case 'state_name':
                 case 'state_2_code':
                 case 'state_3_code':
                     $userfields[] = '#__virtuemart_calcs.virtuemart_calc_id';
                     break;
                 default:
                     $userfields[] = $db->quoteName($field->field_name);
                     break;
             }
         }
     }
     // Build the query
     $userfields = array_unique($userfields);
     $query = $db->getQuery(true);
     $query->select(implode(",\n", $userfields));
     $query->from('#__virtuemart_calcs');
     $query->leftJoin('#__virtuemart_calc_categories ON #__virtuemart_calc_categories.virtuemart_calc_id = #__virtuemart_calcs.virtuemart_calc_id');
     $query->leftJoin('#__virtuemart_calc_countries ON #__virtuemart_calc_countries.virtuemart_calc_id = #__virtuemart_calcs.virtuemart_calc_id');
     $query->leftJoin('#__virtuemart_calc_shoppergroups ON #__virtuemart_calc_shoppergroups.virtuemart_calc_id = #__virtuemart_calcs.virtuemart_calc_id');
     $query->leftJoin('#__virtuemart_calc_states ON #__virtuemart_calc_states.virtuemart_calc_id = #__virtuemart_calcs.virtuemart_calc_id');
     $query->leftJoin('#__virtuemart_currencies ON #__virtuemart_currencies.virtuemart_currency_id = #__virtuemart_calcs.calc_currency');
     // Check if there are any selectors
     $selectors = array();
     // Filter by published state
     $publish_state = $template->get('publish_state', 'general');
     if ($publish_state != '' && ($publish_state == 1 || $publish_state == 0)) {
         $selectors[] = '#__virtuemart_calcs.published = ' . $publish_state;
     }
     // Check if we need to attach any selectors to the query
     if (count($selectors) > 0) {
         $query->where(implode("\n AND ", $selectors));
     }
     // Ignore fields
     $ignore = array('category_path', 'shopper_group_name', 'country_name', 'country_2_code', 'country_3_code', 'state_name', 'state_2_code', 'state_3_code');
     // Check if we need to group the orders together
     $groupby = $template->get('groupby', 'general', false, 'bool');
     if ($groupby) {
         $filter = $this->getFilterBy('groupby', $ignore);
         if (!empty($filter)) {
             $query->group($filter);
         }
     }
     // Order by set field
     $orderby = $this->getFilterBy('sort', $ignore);
     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) {
             $linenumber = 1;
             while ($record = $csvidb->getRow()) {
                 $csvilog->setLinenumber($linenumber++);
                 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;
                     // Add the replacement
                     if (isset($record->{$fieldname})) {
                         $fieldvalue = CsviHelper::replaceValue($field->replace, $record->{$fieldname});
                     } else {
                         $fieldvalue = '';
                     }
                     switch ($fieldname) {
                         case 'category_path':
                             // Get all the category IDs
                             $query = $db->getQuery(true);
                             $query->select('virtuemart_category_id');
                             $query->from('#__virtuemart_calc_categories');
                             $query->where('virtuemart_calc_id = ' . $record->virtuemart_calc_id);
                             $db->setQuery($query);
                             $catids = $db->loadColumn();
                             if (!empty($catids)) {
                                 $categories = array();
                                 foreach ($catids as $catid) {
                                     $categories[] = $helper->createCategoryPathById($catid);
                                 }
                                 $fieldvalue = implode('|', $categories);
                             }
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header, true);
                             break;
                         case 'shopper_group_name':
                             $query = $db->getQuery(true);
                             $query->select('virtuemart_shoppergroup_id');
                             $query->from('#__virtuemart_calc_shoppergroups');
                             $query->where('virtuemart_calc_id = ' . $record->virtuemart_calc_id);
                             $db->setQuery($query);
                             $groupids = $db->loadResultArray();
                             if (!empty($groupids)) {
                                 $query = $db->getQuery(true);
                                 $query->select('shopper_group_name');
                                 $query->from('#__virtuemart_shoppergroups');
                                 $query->where('virtuemart_shoppergroup_id IN (' . implode(',', $groupids) . ')');
                                 $db->setQuery($query);
                                 $names = $db->loadResultArray();
                                 $fieldvalue = implode('|', $names);
                             }
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header, true);
                             break;
                         case 'country_name':
                         case 'country_2_code':
                         case 'country_3_code':
                             $query = $db->getQuery(true);
                             $query->select('virtuemart_country_id');
                             $query->from('#__virtuemart_calc_countries');
                             $query->where('virtuemart_calc_id = ' . $record->virtuemart_calc_id);
                             $db->setQuery($query);
                             $groupids = $db->loadResultArray();
                             if (!empty($groupids)) {
                                 $query = $db->getQuery(true);
                                 $query->select($fieldname);
                                 $query->from('#__virtuemart_countries');
                                 $query->where('virtuemart_country_id IN (' . implode(',', $groupids) . ')');
                                 $db->setQuery($query);
                                 $names = $db->loadResultArray();
                                 $fieldvalue = implode('|', $names);
                             }
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header, true);
                             break;
                         case 'state_name':
                         case 'state_2_code':
                         case 'state_3_code':
                             $query = $db->getQuery(true);
                             $query->select('virtuemart_state_id');
                             $query->from('#__virtuemart_calc_states');
                             $query->where('virtuemart_calc_id = ' . $record->virtuemart_calc_id);
                             $db->setQuery($query);
                             $groupids = $db->loadResultArray();
                             if (!empty($groupids)) {
                                 $query = $db->getQuery(true);
                                 $query->select($fieldname);
                                 $query->from('#__virtuemart_states');
                                 $query->where('virtuemart_state_id IN (' . implode(',', $groupids) . ')');
                                 $db->setQuery($query);
                                 $names = $db->loadResultArray();
                                 $fieldvalue = implode('|', $names);
                             }
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header, true);
                             break;
                         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();
         }
     }
 }
Example #21
0
 /**
  * Multiple prices export
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		void
  * @since 		3.0
  */
 public function getStart()
 {
     // Get some basic data
     $db = JFactory::getDbo();
     $csvidb = new CsviDb();
     $jinput = JFactory::getApplication()->input;
     $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) {
         if ($field->process) {
             switch ($field->field_name) {
                 case 'product_sku':
                     $userfields[] = $db->qn('#__virtuemart_product_prices.virtuemart_product_id');
                     break;
                 case 'product_name':
                     $userfields[] = $db->qn('#__virtuemart_products.virtuemart_product_id');
                     break;
                 case 'product_currency':
                     $userfields[] = $db->qn('#__virtuemart_currencies.currency_code_3');
                     break;
                 case 'custom':
                     break;
                 default:
                     $userfields[] = $db->quoteName($field->field_name);
                     break;
             }
         }
     }
     // Build the query
     $userfields = array_unique($userfields);
     $query = $db->getQuery(true);
     $query->select(implode(",\n", $userfields));
     $query->from($db->qn('#__virtuemart_product_prices'));
     $query->leftJoin($db->qn('#__virtuemart_products') . ' ON ' . $db->qn('#__virtuemart_product_prices.virtuemart_product_id') . ' = ' . $db->qn('#__virtuemart_products.virtuemart_product_id'));
     $query->leftJoin($db->qn('#__virtuemart_shoppergroups') . ' ON ' . $db->qn('#__virtuemart_product_prices.virtuemart_shoppergroup_id') . ' = ' . $db->qn('#__virtuemart_shoppergroups.virtuemart_shoppergroup_id'));
     $query->leftJoin($db->qn('#__virtuemart_currencies') . ' ON ' . $db->qn('#__virtuemart_product_prices.product_currency') . ' = ' . $db->qn('#__virtuemart_currencies.virtuemart_currency_id'));
     // Check if there are any selectors
     $selectors = array();
     // Filter by published state
     $publish_state = $template->get('publish_state', 'general');
     if ($publish_state != '' && ($publish_state == 1 || $publish_state == 0)) {
         $selectors[] = '#__virtuemart_products.published = ' . $publish_state;
     }
     // Shopper group selector
     $shopper_group = $template->get('shopper_groups', 'multipleprices', array());
     if ($shopper_group && $shopper_group[0] != 'none') {
         $selectors[] = "#__virtuemart_shoppergroups.virtuemart_shoppergroup_id IN ('" . implode("','", $shopper_group) . "')";
     }
     // Check if we need to attach any selectors to the query
     if (count($selectors) > 0) {
         $query->where(implode("\n AND ", $selectors));
     }
     // Fields to ignore
     $ignore = array('product_sku', 'product_name', 'shopper_group_name', 'product_currency');
     // Check if we need to group the orders together
     $groupby = $template->get('groupby', 'general', false, 'bool');
     if ($groupby) {
         $filter = $this->getFilterBy('groupby', $ignore);
         if (!empty($filter)) {
             $query->group($filter);
         }
     }
     // Order by set field
     $orderby = $this->getFilterBy('sort', $ignore);
     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) {
             $linenumber = 1;
             while ($record = $csvidb->getRow()) {
                 $csvilog->setLinenumber($linenumber++);
                 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;
                     // Add the replacement
                     if (isset($record->{$fieldname})) {
                         $fieldvalue = CsviHelper::replaceValue($field->replace, $record->{$fieldname});
                     } else {
                         $fieldvalue = '';
                     }
                     switch ($fieldname) {
                         case 'product_sku':
                             $query = $db->getQuery(true);
                             $query->select('product_sku');
                             $query->from('#__virtuemart_products');
                             $query->where('virtuemart_product_id = ' . $record->virtuemart_product_id);
                             $db->setQuery($query);
                             $fieldvalue = $db->loadResult();
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'product_name':
                             $query = $db->getQuery(true);
                             $query->select($fieldname);
                             $query->from('#__virtuemart_products_' . $template->get('language', 'general'));
                             $query->where('virtuemart_product_id = ' . $record->virtuemart_product_id);
                             $db->setQuery($query);
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $db->loadResult());
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'product_price':
                             $product_price = number_format($record->product_price, $template->get('export_price_format_decimal', 'general', 2, 'int'), $template->get('export_price_format_decsep', 'general'), $template->get('export_price_format_thousep', 'general'));
                             if (strlen(trim($product_price)) == 0) {
                                 $product_price = $field->default_value;
                             }
                             $product_price = CsviHelper::replaceValue($field->replace, $product_price);
                             $record->output[$column_id] = $product_price;
                             break;
                         case 'product_price_publish_up':
                         case 'product_price_publish_down':
                             $date = JFactory::getDate($record->{$fieldname});
                             $fieldvalue = CsviHelper::replaceValue($field->replace, date($template->get('export_date_format', 'general'), $date->toUnix()));
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'product_currency':
                             $fieldvalue = $record->currency_code_3;
                             // Perform the replacement rules
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'shopper_group_name':
                             // Check if the shopper group name is empty
                             if (empty($field->default_value) && empty($fieldvalue)) {
                                 $fieldvalue = '*';
                             }
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         default:
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                     }
                 }
                 // Output the data
                 $this->addExportFields($record);
                 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();
         }
     }
 }
    /**
     * Product type names export
     *
     * Exports product type names data to either csv, xml or HTML format
     *
     * @copyright
     * @author		RolandD
     * @todo
     * @see
     * @access 		public
     * @param
     * @return 		void
     * @since 		3.0
     */
    public function getStart()
    {
        // Get some basic data
        $jinput = JFactory::getApplication()->input;
        $db = JFactory::getDbo();
        $csvidb = new CsviDb();
        $jinput = JFactory::getApplication()->input;
        $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');
        $producttypeid = $template->get('producttypenames', 'producttypename', false);
        // Create ID list for searching
        if (!$producttypeid) {
            return false;
        }
        $typeids = array();
        foreach ($producttypeid as $key => $value) {
            $typeids[] = $db->q('vm_product_type_' . $value);
        }
        $component_tables = implode(',', $typeids);
        // Build something fancy to only get the fieldnames the user wants
        $userfields = array();
        $vmtables = array();
        $vmids = array();
        $ignore = array();
        foreach ($export_fields as $column_id => $field) {
            switch ($field->field_name) {
                case 'product_sku':
                    $userfields[] = '#__virtuemart_products.product_sku';
                    break;
                case 'product_id':
                    $userfields[] = '#__virtuemart_products.virtuemart_product_id AS product_id';
                    break;
                case 'product_type_name':
                    $userfields[] = '#__vm_product_type.product_type_name';
                    break;
                case 'product_type_id':
                    $userfields[] = '#__vm_product_type.product_type_id';
                    break;
                    // Man made fields, do not export them
                // Man made fields, do not export them
                case 'custom':
                    $ignore[] = $field->field_name;
                    break;
                default:
                    // Check which product type table belongs to the field
                    $table = null;
                    $query = $db->getQuery(true);
                    $query->select($db->qn('component_table'))->from($db->qn('#__csvi_available_fields'))->where($db->qn('csvi_name') . ' = ' . $db->q($field->field_name))->where($db->qn('component_table') . ' IN (' . $component_tables . ')');
                    $db->setQuery($query, 0, 1);
                    $table = $db->loadResult();
                    if ($table) {
                        $vmtables[$table][] = $field->field_name;
                        $vmids[] = $table;
                    } else {
                        $ignore[] = $field->field_name;
                    }
                    break;
            }
        }
        // Check if we have any product type tables to export
        $vmids = array_unique($vmids);
        if (!empty($vmids)) {
            /**
             * Export SQL Query
             * Get all products - including items as well as products without a price
             */
            $queries = array();
            $filterid = '';
            $userfields = array_unique($userfields);
            foreach ($vmids as $vmidkey => $vmid) {
                $q = "(SELECT " . implode(",\n", $userfields);
                foreach ($vmtables as $vmtableskey => $vmfields) {
                    if ($vmid == $vmtableskey) {
                        $filterid = str_replace('vm_product_type_', '', $vmid);
                        foreach ($vmfields as $vmfieldkey => $vmfield) {
                            $q .= ",\n" . $db->qn('#__' . $vmid) . '.' . $db->qn($vmfield) . ' AS ' . $db->qn($vmfield);
                        }
                    } else {
                        foreach ($vmfields as $vmfieldkey => $vmfield) {
                            $q .= ",\n '' AS " . $db->qn($vmfield);
                        }
                    }
                }
                $q .= ' FROM #__vm_product_type
					LEFT JOIN #__vm_product_product_type_xref
					ON #__vm_product_product_type_xref.product_type_id = #__vm_product_type.product_type_id
					LEFT JOIN #__virtuemart_products
					ON #__vm_product_product_type_xref.product_id = #__virtuemart_products.virtuemart_product_id ';
                // Add the product type X tables
                $q .= "\nLEFT JOIN #__" . $vmid . " ON #__" . $vmid . ".product_id = #__virtuemart_products.virtuemart_product_id " . "\n";
                // Check if there are any selectors
                $selectors = array();
                // Add product type ID checks
                if (is_int($filterid)) {
                    $selectors[] = '#__vm_product_type.product_type_id = ' . $filterid;
                }
                // Filter by product type name
                if ($producttypeid) {
                    $selectors[] = '#__vm_product_type.product_type_id IN (' . implode(',', $producttypeid) . ')';
                }
                // Check if we need to attach any selectors to the query
                if (count($selectors) > 0) {
                    $q .= ' WHERE ' . implode(' AND ', $selectors) . "\n";
                }
                // Special field treatment
                $special = array();
                $special['product_sku'] = $db->qn('#__virtuemart_products') . '.' . $db->qn('product_sku');
                $special['product_id'] = $db->qn('#__virtuemart_products') . '.' . $db->qn('virtuemart_product_id');
                $special['product_type_name'] = $db->qn('#__vm_product_type') . '.' . $db->qn('product_type_name');
                $special['product_type_id'] = $db->qn('#__vm_product_type') . '.' . $db->qn('product_type_id');
                // Check if we need to group the orders together
                $groupby = $template->get('groupby', 'general', false, 'bool');
                if ($groupby) {
                    $filter = $this->getFilterBy('groupby', $ignore, $special);
                    if (!empty($filter)) {
                        $q .= " GROUP BY " . $filter;
                    }
                }
                // Order by set field
                $orderby = $this->getFilterBy('sort', $ignore, $special);
                if (!empty($orderby)) {
                    $q .= " ORDER BY " . $orderby;
                }
                $queries[] = $q . ')';
            }
            // Create the full query
            $q = implode("\nUNION\n", $queries);
            // Add export limits
            $limits = $this->getExportLimit();
            // Execute the query
            $csvidb->setQuery($q, $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) {
                            if ($field->process) {
                                $fieldname = $field->field_name;
                                // 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;
                                        }
                                        $record->output[$column_id] = $fieldvalue;
                                        break;
                                }
                            }
                        }
                        // Output the data
                        $this->addExportFields($record);
                        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();
                }
            }
        } else {
            $this->addExportContent(JText::_('COM_CSVI_NO_DATA_FOUND'));
            $this->writeOutput();
            $csvilog->AddStats('incorrect', $db->getErrorMsg());
        }
    }
					<td id="newfield_defaultvalue"><input type="text"
						name="_default_value" id="_default_value" value="" size="55" />
					</td>
					<!-- Process field -->
					<td id="newfield_processfield"><?php 
    echo CsviHelper::getYesNo('_process_field', '1', '', '_process_field_default');
    ?>
					</td>
					<!-- Combine field -->
					<td id="newfield_combinefield"><?php 
    echo CsviHelper::getYesNo('_combine_field', '0', '', '_combine_field_default');
    ?>
					</td>
					<!-- Sort field -->
					<td id="newfield_sortfield"><?php 
    echo CsviHelper::getYesNo('_sort_field', '0', '', '_sort_field_default');
    ?>
					</td>
					<!-- Replacement field -->
					<td id="newfield_replacementfield"><?php 
    echo JHtml::_('select.genericlist', $this->replacements, '_replace_field[]', 'multiple="true"', 'value', 'text', '', '_replace_field_default');
    ?>
					</td>
				</tr>
			</tbody>
		</table>
		<br />
		<div id="toolbar" class="toolbar-list">
			<ul>
				<li id="toolbar-quickadd" class="button"><?php 
    echo JHtml::_('link', '#', '<span class="icon-32-csvi_add_32 quickadd-button" id="quickadd-button">&nbsp;</span>' . JText::_('COM_CSVI_QUICKADD'));
Example #24
0
 /**
  * Category details export
  *
  * Exports category details data to either csv, xml or HTML format
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		void
  * @since 		3.0
  */
 public function getStart()
 {
     // Get some basic data
     $db = JFactory::getDbo();
     $csvidb = new CsviDb();
     $jinput = JFactory::getApplication()->input;
     $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');
     $helper = new Com_VirtueMart();
     // Get all categories
     $query = $db->getQuery(true);
     $query->select('LOWER(l.category_name) AS category_name, category_child_id AS cid, category_parent_id AS pid');
     $query->from('#__virtuemart_categories c');
     $query->leftJoin('#__virtuemart_category_categories x ON x.category_child_id = c.virtuemart_category_id');
     $query->leftJoin('#__virtuemart_categories_' . $template->get('language', 'general') . ' l ON l.virtuemart_category_id = c.virtuemart_category_id');
     $db->setQuery($query);
     $cats = $db->loadObjectList();
     // Check if there are any categories
     if (empty($cats)) {
         if (!is_null($csvidb->getErrorMsg())) {
             $this->addExportContent(JText::sprintf('COM_CSVI_ERROR_RETRIEVING_DATA', $csvidb->getErrorMsg()));
             $csvilog->AddStats('incorrect', $csvidb->getErrorMsg());
         } else {
             $this->addExportContent(JText::_('COM_CSVI_NO_DATA_FOUND'));
         }
         $this->writeOutput();
         return false;
     }
     $categories = array();
     // Group all categories together according to their level
     foreach ($cats as $key => $cat) {
         $categories[$cat->pid][$cat->cid] = $cat->category_name;
     }
     // Build something fancy to only get the fieldnames the user wants
     $userfields = array();
     foreach ($export_fields as $column_id => $field) {
         if ($field->process) {
             switch ($field->field_name) {
                 case 'virtuemart_category_id':
                 case 'ordering':
                     $userfields[] = '#__virtuemart_categories.' . $field->field_name;
                     break;
                 case 'file_url':
                 case 'file_url_thumb':
                     $userfields[] = '#__virtuemart_category_medias.virtuemart_media_id';
                     break;
                 case 'category_name':
                 case 'category_description':
                 case 'metadesc':
                 case 'metakey':
                 case 'slug':
                 case 'category_path':
                 case 'category_path_trans':
                     $userfields[] = $db->quoteName('#__virtuemart_categories') . '.' . $db->quoteName('virtuemart_category_id');
                     break;
                 default:
                     $userfields[] = $db->quoteName($field->field_name);
                     break;
             }
         }
     }
     // Build the query
     $userfields = array_unique($userfields);
     $query = $db->getQuery(true);
     $query->select(implode(",\n", $userfields));
     $query->from('#__virtuemart_categories');
     $query->leftJoin('#__virtuemart_categories_' . $template->get('language', 'general') . ' ON #__virtuemart_categories_' . $template->get('language', 'general') . '.virtuemart_category_id = #__virtuemart_categories.virtuemart_category_id');
     $query->leftJoin('#__virtuemart_category_medias ON #__virtuemart_category_medias.virtuemart_category_id = #__virtuemart_categories.virtuemart_category_id');
     // Check if there are any selectors
     $selectors = array();
     // Filter by published state
     $publish_state = $template->get('publish_state', 'general');
     if ($publish_state != '' && ($publish_state == 1 || $publish_state == 0)) {
         $selectors[] = '#__virtuemart_categories.published = ' . $publish_state;
     }
     // Check if we need to attach any selectors to the query
     if (count($selectors) > 0) {
         $query->where(implode("\n AND ", $selectors));
     }
     // Ignore fields
     $ignore = array('category_path', 'file_url', 'file_url_thumb', 'category_path_trans');
     // Check if we need to group the orders together
     $groupby = $template->get('groupby', 'general', false, 'bool');
     if ($groupby) {
         $filter = $this->getFilterBy('groupby', $ignore);
         if (!empty($filter)) {
             $query->group($filter);
         }
     }
     // Order by set field
     $orderby = $this->getFilterBy('sort', $ignore);
     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) {
             $linenumber = 1;
             while ($record = $csvidb->getRow()) {
                 $csvilog->setLinenumber($linenumber++);
                 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) {
                         case 'category_path':
                             $fieldvalue = $helper->createCategoryPathById($record->virtuemart_category_id);
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'category_path_trans':
                             $fieldvalue = $helper->createCategoryPathById($record->virtuemart_category_id, 'target_language');
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'file_url':
                         case 'file_url_thumb':
                             $query = $db->getQuery(true);
                             $query->select($fieldname);
                             $query->from('#__virtuemart_medias');
                             $query->where('virtuemart_media_id = ' . $record->virtuemart_media_id);
                             $db->setQuery($query);
                             $fieldvalue = $db->loadResult();
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'category_name':
                         case 'category_description':
                         case 'metadesc':
                         case 'metakey':
                         case 'slug':
                         case 'customtitle':
                             $query = $db->getQuery(true);
                             $query->select($fieldname);
                             $query->from('#__virtuemart_categories_' . $template->get('language', 'general'));
                             $query->where('virtuemart_category_id = ' . $record->virtuemart_category_id);
                             $db->setQuery($query);
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $db->loadResult());
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         case 'custom':
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             $record->output[$column_id] = $fieldvalue;
                             break;
                         default:
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $record->output[$column_id] = $fieldvalue;
                             break;
                     }
                 }
                 // Output the data
                 $this->addExportFields($record);
                 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();
         }
     }
 }
							<td><input type="text" name="jform[import_fields][_selected_name][]" value="<?php 
        echo $import_fields['_selected_name'][$rows];
        ?>
" readonly="readonly" size="35" /></td>
							<td><input type="text" name="jform[import_fields][_default_value][]" value="<?php 
        echo $import_fields['_default_value'][$rows];
        ?>
" size="75"/></td>
							<td><?php 
        echo CsviHelper::getYesNo('jform[import_fields][_process_field][' . $rows . ']', $import_fields['_process_field'][$rows], '', '_process_field' . $id);
        ?>
							<td><?php 
        if (!array_key_exists('_combine_field', $import_fields)) {
            $import_fields['_combine_field'] = array();
        }
        echo CsviHelper::getYesNo('jform[import_fields][_combine_field][' . $rows . ']', $import_fields['_combine_field'][$rows], '', '_combine_field' . $id);
        ?>
</td>
							<td><?php 
        if (!array_key_exists('_replace_field', $import_fields)) {
            $import_fields['_replace_field'] = array();
        }
        if (!isset($import_fields['_replace_field'][$rows])) {
            $import_fields['_replace_field'][$rows] = '';
        }
        echo JHtml::_('select.genericlist', $this->replacements, 'jform[import_fields][_replace_field][' . $rows . ']', '', 'value', 'text', $import_fields['_replace_field'][$rows], '_replace_field_' . $id);
        ?>
</td>
							<td class="center"><?php 
        echo JHtml::_('link', 'index.php?option=com_csvi&view=import', JHtml::_('image', JURI::root() . '/administrator/components/com_csvi/assets/images/csvi_delete_32.png', 'width="20" height="20" border="0" alt="' . JText::_('COM_CSVI_DELETE') . '"'), 'onclick="jQuery(this).parents(\'tr\').remove(); jQuery(\'#fieldslist\').tableDnD(); return false;"');
        ?>
 /**
  * Waiting list export
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		void
  * @since 		3.1
  */
 public function getStart()
 {
     // Get some basic data
     $db = JFactory::getDbo();
     $csvidb = new CsviDb();
     $jinput = JFactory::getApplication()->input;
     $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) {
         if ($field->process) {
             switch ($field->field_name) {
                 case 'virtuemart_user_id':
                 case 'virtuemart_product_id':
                 case 'created_on':
                 case 'modified_on':
                 case 'locked_on':
                 case 'created_by':
                 case 'modified_by':
                 case 'locked_by':
                     $userfields[] = $db->quoteName('#__virtuemart_waitingusers') . '.' . $db->quoteName($field->field_name);
                     break;
                     // Man made fields, do not export them
                 // Man made fields, do not export them
                 case 'custom':
                 case 'username':
                     break;
                 default:
                     $userfields[] = $db->quoteName($field->field_name);
                     break;
             }
         }
     }
     // Build the query
     $userfields = array_unique($userfields);
     $query = $db->getQuery(true);
     $query->select(implode(",\n", $userfields));
     $query->from('#__virtuemart_waitingusers');
     $query->leftJoin('#__virtuemart_products ON #__virtuemart_products.virtuemart_product_id = #__virtuemart_waitingusers.virtuemart_product_id');
     $query->leftJoin('#__users ON #__users.id = #__virtuemart_waitingusers.virtuemart_user_id');
     // Ignore fields
     $ignore = array('custom', 'username');
     // Check if we need to group the orders together
     $groupby = $template->get('groupby', 'general', false, 'bool');
     if ($groupby) {
         $filter = $this->getFilterBy('groupby', $ignore);
         if (!empty($filter)) {
             $query->group($filter);
         }
     }
     // Order by set field
     $orderby = $this->getFilterBy('sort', $ignore);
     if (!empty($orderby)) {
         $query->order($orderby);
     }
     // Add export limits
     $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) {
             $linenumber = 1;
             while ($record = $csvidb->getRow()) {
                 $csvilog->setLinenumber($linenumber++);
                 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;
                     // Add the replacement
                     if (isset($record->{$fieldname})) {
                         $fieldvalue = CsviHelper::replaceValue($field->replace, $record->{$fieldname});
                     } else {
                         $fieldvalue = '';
                     }
                     switch ($fieldname) {
                         case 'created_on':
                         case 'modified_on':
                         case 'locked_on':
                             $date = JFactory::getDate($record->{$fieldname});
                             $fieldvalue = CsviHelper::replaceValue($field->replace, date($template->get('export_date_format', 'general'), $date->toUnix()));
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                             break;
                         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();
         }
     }
 }
 /**
  * User info export
  *
  * Exports user info data to either csv, xml or HTML format
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		void
  * @since 		3.0
  */
 public function getStart()
 {
     // Get some basic data
     $db = JFactory::getDbo();
     $csvidb = new CsviDb();
     $jinput = JFactory::getApplication()->input;
     $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) {
             case 'virtuemart_user_id':
             case 'created_on':
             case 'modified_on':
             case 'locked_on':
             case 'created_by':
             case 'modified_by':
             case 'locked_by':
             case 'name':
             case 'agreed':
                 $userfields[] = $db->quoteName('#__virtuemart_userinfos') . '.' . $db->quoteName($field->field_name);
                 break;
             case 'full_name':
                 $userfields[] = $db->quoteName('#__virtuemart_userinfos') . '.' . $db->quoteName('first_name');
                 $userfields[] = $db->quoteName('#__virtuemart_userinfos') . '.' . $db->quoteName('middle_name');
                 $userfields[] = $db->quoteName('#__virtuemart_userinfos') . '.' . $db->quoteName('last_name');
                 break;
             case 'id':
                 $userfields[] = $db->quoteName('#__users') . '.' . $db->quoteName('id');
                 break;
             case 'usergroup_name':
                 $userfields[] = $db->quoteName('#__virtuemart_userinfos') . '.' . $db->quoteName('virtuemart_user_id');
                 break;
             case 'virtuemart_vendor_id':
                 $userfields[] = $db->quoteName('#__virtuemart_vmusers') . '.' . $db->quoteName('virtuemart_vendor_id');
                 break;
             case 'state_2_code':
             case 'state_3_code':
             case 'state_name':
                 $userfields[] = $db->quoteName('#__virtuemart_userinfos') . '.' . $db->quoteName('virtuemart_state_id');
                 break;
             case 'country_2_code':
             case 'country_3_code':
             case 'country_name':
             case 'virtuemart_country_id':
                 $userfields[] = $db->quoteName('#__virtuemart_userinfos') . '.' . $db->quoteName('virtuemart_country_id');
                 break;
             case 'custom':
                 break;
             default:
                 $userfields[] = $db->quoteName($field->field_name);
                 break;
         }
     }
     /** Export SQL Query
      * Get all products - including items
      * as well as products without a price
      */
     $userfields = array_unique($userfields);
     $query = $db->getQuery(true);
     $query->select(implode(",\n", $userfields));
     $query->from('#__virtuemart_userinfos');
     $query->leftJoin('#__virtuemart_vmusers ON #__virtuemart_vmusers.virtuemart_user_id = #__virtuemart_userinfos.virtuemart_user_id');
     $query->leftJoin('#__virtuemart_vmuser_shoppergroups ON #__virtuemart_vmuser_shoppergroups.virtuemart_user_id = #__virtuemart_userinfos.virtuemart_user_id');
     $query->leftJoin('#__virtuemart_vendors ON #__virtuemart_vendors.virtuemart_vendor_id = #__virtuemart_vmusers.virtuemart_vendor_id');
     $query->leftJoin('#__virtuemart_shoppergroups ON #__virtuemart_shoppergroups.virtuemart_shoppergroup_id = #__virtuemart_vmuser_shoppergroups.virtuemart_shoppergroup_id');
     $query->leftJoin('#__users ON #__users.id = #__virtuemart_userinfos.virtuemart_user_id');
     // Check if there are any selectors
     $selectors = array();
     // Filter by vendors
     $vendors = $template->get('vendors', 'userinfo', false);
     if ($vendors && $vendors[0] != 'none') {
         $selectors[] = '#__virtuemart_vmusers.virtuemart_vendor_id IN (\'' . implode("','", $vendors) . '\')';
     }
     // Filter by permissions
     $permissions = $template->get('permissions', 'userinfo', false);
     if ($permissions && $permissions[0] != 'none') {
         $selectors[] = '#__virtuemart_vmusers.perms IN (\'' . implode("','", $permissions) . '\')';
     }
     // Filter by address type
     $address = $template->get('userinfo_address', 'userinfo', false);
     if ($address) {
         $selectors[] = '#__virtuemart_userinfos.address_type = ' . $db->Quote(strtoupper($address));
     }
     // Filter by user info modified date start
     $date = $template->get('userinfomdatestart', 'userinfo', false);
     if ($date) {
         $userinfomdate = JFactory::getDate($date);
         $selectors[] = '#__virtuemart_userinfos.modified_on >= ' . $db->Quote($userinfomdate->toMySQL());
     }
     // Filter by user info date end
     $date = $template->get('userinfomdateend', 'userinfo', false);
     if ($date) {
         $userinfomdate = JFactory::getDate($date);
         $selectors[] = '#__virtuemart_userinfos.modified_on <= ' . $db->Quote($userinfomdate->toMySQL());
     }
     // Check if we need to attach any selectors to the query
     if (count($selectors) > 0) {
         $query->where(implode("\n AND ", $selectors));
     }
     // Array of fields not to handle
     $ignore = array('full_name', 'usergroup_name', 'state_2_code', 'state_3_code', 'state_name', 'country_2_code', 'country_3_code', 'country_name');
     // Check if we need to group the orders together
     $groupby = $template->get('groupby', 'general', false, 'bool');
     if ($groupby) {
         $filter = $this->getFilterBy('groupby', $ignore);
         if (!empty($filter)) {
             $query->group($filter);
         }
     }
     // Order by set field
     $orderby = $this->getFilterBy('sort', $ignore);
     if (!empty($orderby)) {
         $query->order($orderby);
     }
     // Add export limits
     $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();
         JRequest::setVar('logcount', array('export' => $logcount));
         if ($logcount > 0) {
             $linenumber = 1;
             while ($record = $csvidb->getRow()) {
                 $csvilog->setLinenumber($linenumber++);
                 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;
                     // Add the replacement
                     if (isset($record->{$fieldname})) {
                         $fieldvalue = CsviHelper::replaceValue($field->replace, $record->{$fieldname});
                     } else {
                         $fieldvalue = '';
                     }
                     switch ($fieldname) {
                         case 'created_on':
                         case 'modified_on':
                         case 'locked_on':
                         case 'lastvisitdate':
                             $date = JFactory::getDate($record->{$fieldname});
                             $fieldvalue = CsviHelper::replaceValue($field->replace, date($template->get('export_date_format', 'general'), $date->toUnix()));
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                             break;
                         case 'address_type':
                             // Check if we have any content otherwise use the default value
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             if ($fieldvalue == 'BT') {
                                 $fieldvalue = JText::_('COM_CSVI_BILLING_ADDRESS');
                             } else {
                                 if ($fieldvalue == 'ST') {
                                     $fieldvalue = JText::_('COM_CSVI_SHIPPING_ADDRESS');
                                 }
                             }
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                             break;
                         case 'full_name':
                             $fieldvalue = str_replace('  ', ' ', $record->first_name . ' ' . $record->middle_name . ' ' . $record->last_name);
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $fieldvalue);
                             // 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;
                         case 'usergroup_name':
                             $query = $db->getQuery(true);
                             $query->select($fieldname);
                             $query->from('#__usergroups');
                             $query->leftJoin('#__user_usergroup_map ON #__user_usergroup_map.group_id = #__usergroups.id');
                             $query->where($db->quoteName('user_id') . ' = ' . $record->virtuemart_user_id);
                             $db->setQuery($query);
                             $fieldvalue = $db->loadResult();
                             if (strlen(trim($fieldvalue)) == 0) {
                                 $fieldvalue = $field->default_value;
                             }
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                             break;
                         case 'state_2_code':
                         case 'state_3_code':
                         case 'state_name':
                             $query = $db->getQuery(true);
                             $query->select($fieldname);
                             $query->from('#__virtuemart_states');
                             $query->where('virtuemart_state_id = ' . $record->virtuemart_state_id);
                             $db->setQuery($query);
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $db->loadResult());
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                             break;
                         case 'country_2_code':
                         case 'country_3_code':
                         case 'country_name':
                             $query = $db->getQuery(true);
                             $query->select($fieldname);
                             $query->from('#__virtuemart_countries');
                             $query->where('virtuemart_country_id = ' . $record->virtuemart_country_id);
                             $db->setQuery($query);
                             $fieldvalue = CsviHelper::replaceValue($field->replace, $db->loadResult());
                             $this->addExportField($field->combine, $fieldvalue, $fieldname, $field->column_header);
                             break;
                         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();
         }
     }
 }
 /**
  * Create a thumbnail image
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param		string 	$original		the full path and name of the large image
  * @param		string	$output_path	the path to store the thumbnail
  * @param		string	$output_name	the name of the thumbnail
  * @return
  * @since 		4.0
  */
 public function createThumbnail($original, $output_path, $output_name)
 {
     $jinput = JFactory::getApplication()->input;
     $template = $jinput->get('template', null, null);
     $csvilog = $jinput->get('csvilog', null, null);
     $base = JPath::clean(JPATH_SITE, '/');
     // Make sure the thumbnail is the same file type as the full image
     if ($template->get('thumb_check_filetype', 'image') && JFile::getExt($original) != JFile::getExt($output_name)) {
         $output_name = JFile::stripExt($output_name) . '.' . JFile::getExt($original);
     }
     $output_name = $this->_setCase($output_name);
     // Check if the original is an external image
     if (!$this->isRemote($original)) {
         $original = $base . '/' . $original;
         $file_exists = JFile::exists($original);
         $remote = false;
     } else {
         $file_exists = CsviHelper::fileExistsRemote($original);
         $remote = true;
     }
     // Check if thumbsize is greater than 0
     if ($template->get('thumb_width', 'image') >= 1 && $template->get('thumb_height', 'image') >= 1) {
         // Check if the image folders exists
         $thumb_folder = JPATH_SITE . '/' . $output_path . dirname($output_name);
         if (!JFolder::exists($thumb_folder)) {
             $csvilog->addDebug(JText::sprintf('COM_CSVI_CREATE_THUMB_FOLDER', $thumb_folder));
             JFolder::create($thumb_folder);
         }
         // Check if the target thumb exists, if yes delete it
         if (JFile::exists($base . '/' . $output_path . $output_name)) {
             JFile::delete($base . '/' . $output_path . $output_name);
         }
         // Check if the original file exists
         $csvilog->addDebug(JText::sprintf('COM_CSVI_CHECK_ORIGINAL', $original));
         if ($file_exists) {
             // Collect all thumbnail details
             $thumb_file_details = array();
             $thumb_file_details['file'] = $original;
             $thumb_file_details['file_extension'] = JFile::getExt($original);
             $thumb_file_details['file_out'] = $base . '/' . $output_path . $output_name;
             $thumb_file_details['maxsize'] = 0;
             $thumb_file_details['bgred'] = 255;
             $thumb_file_details['bggreen'] = 255;
             $thumb_file_details['bgblue'] = 255;
             $thumb_file_details['file_out_width'] = $template->get('thumb_width', 'image');
             $thumb_file_details['file_out_height'] = $template->get('thumb_height', 'image');
             $thumb_file_details['file_out_extension'] = JFile::getExt($output_name);
             $thumb_file_details['mime_type'] = $this->findMimeType($original, $remote);
             // We need to resize the image and Save the new one only if it is in a different location
             $csvilog->addDebug(JText::sprintf('COM_CSVI_DEBUG_CREATING_A_THUMBNAIL', $original, $thumb_file_details['file_out']));
             if ($original != $thumb_file_details['file_out']) {
                 $new_img = $this->convertImage($thumb_file_details);
                 // Check if an image was created
                 if ($new_img) {
                     // Get the details of the thumb image
                     if (JFile::exists($new_img)) {
                         $csvilog->addDebug(JText::_('COM_CSVI_DEBUG_THUMB_CREATED'));
                         return $output_path . $output_name;
                     } else {
                         $csvilog->addDebug(JText::_('COM_CSVI_THUMBNAIL_NOT_CREATED'));
                         return false;
                     }
                 } else {
                     $csvilog->addDebug(JText::_('COM_CSVI_THUMBNAIL_NOT_CREATED'));
                     return false;
                 }
             } else {
                 $csvilog->addDebug('COM_CSVI_THUMB_SAME_AS_FULL');
                 $csvilog->AddStats('incorrect', 'COM_CSVI_THUMB_SAME_AS_FULL');
                 return false;
             }
         } else {
             $csvilog->addDebug(JText::sprintf('COM_CSVI_FILE_DOES_NOT_EXIST_NOTHING_TO_DO', $original));
             $csvilog->AddStats('nofiles', JText::sprintf('COM_CSVI_FILE_DOES_NOT_EXIST_NOTHING_TO_DO', $original));
             return false;
         }
     } else {
         $csvilog->addDebug('COM_CSVI_THUMBNAIL_SIZE_TOO_SMALL');
         $csvilog->AddStats('incorrect', 'COM_CSVI_THUMBNAIL_SIZE_TOO_SMALL');
         return false;
     }
 }
 /**
  * Subscription export
  *
  * Exports subscription details data to either csv, xml or HTML format
  *
  * @copyright
  * @author		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		void
  * @since 		3.0
  */
 public function getStart()
 {
     // Get some basic data
     $db = JFactory::getDbo();
     $csvidb = new CsviDb();
     $jinput = JFactory::getApplication()->input;
     $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) {
         if ($field->process) {
             switch ($field->field_name) {
                 case 'custom':
                     break;
                 default:
                     $userfields[] = $db->quoteName($field->field_name);
                     break;
             }
         }
     }
     // Build the query
     $userfields = array_unique($userfields);
     $query = $db->getQuery(true);
     $query->select(implode(",\n", $userfields));
     $query->from('#__scrollerwithtabs_content');
     // Check if there are any selectors
     $selectors = array();
     // Filter by published state
     $publish_state = $template->get('publish_state', 'general');
     if ($publish_state !== '' && ($publish_state == 1 || $publish_state == 0)) {
         $selectors[] = '#__awocoupon_vm.published = ' . $publish_state;
     }
     // Check if we need to attach any selectors to the query
     if (count($selectors) > 0) {
         $query->where(implode("\n AND ", $selectors));
     }
     // Any fields to ignore
     $ignore = array();
     // Check if we need to group the orders together
     $groupby = $template->get('groupby', 'general', false, 'bool');
     if ($groupby) {
         $filter = $this->getFilterBy('groupby', $ignore);
         if (!empty($filter)) {
             $query->group($filter);
         }
     }
     // Order by set field
     $orderby = $this->getFilterBy('sort', $ignore);
     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;
                     // 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();
         }
     }
 }
Example #30
0
 /**
  * Build the command to use for the cron command to do an import/export
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return 		string	the parameters for the cron line
  * @since 		3.0
  */
 public function getCronLine()
 {
     $jinput = JFactory::getApplication()->input;
     $db = JFactory::getDbo();
     $settings = $jinput->get('com_csvi.data', array(), 'array');
     $cronline = '';
     $notemplate = false;
     $details = new StdClass();
     // Get the template used
     $template_id = $jinput->get('template_id', 0, 'int');
     if ($template_id) {
         $cronline .= ' template_id="' . $template_id . '"';
         // Load the template settings to compare against selection
         $query = $db->getQuery(true);
         $query->select('settings');
         $query->from('#__csvi_template_settings');
         $query->where('id = ' . $template_id);
         $db->setQuery($query);
         $template = new CsviTemplate(json_decode($db->loadResult(), true));
         $details->type = $template->get('action', 'options');
     } else {
         $notemplate = true;
         // Initialise the details
         $details->type = $settings['options']['action'];
     }
     // Check if this is an import or export cron
     if ($details->type == 'export') {
         foreach ($settings as $group => $values) {
             switch ($group) {
                 case 'options':
                     break;
                 case 'general':
                     if ($notemplate) {
                         $general = $settings['general'];
                     } else {
                         $general = CsviHelper::recurseArrayDiff($settings['general'], $template->get('general'));
                     }
                     foreach ($general as $name => $setting) {
                         switch ($name) {
                             case 'exportto':
                                 if (!empty($setting)) {
                                     if ($setting == 'todownload') {
                                         $setting = 'tofile';
                                     }
                                     $cronline .= ' jform:general:' . $name . '="' . $setting . '" ';
                                 }
                                 break;
                             case 'localpath':
                                 if (!empty($setting)) {
                                     if ($template->get('exportto', 'general') == 'todownload' || $template->get('exportto', 'general') == 'tofile') {
                                         $cronline .= ' jform:general:' . $name . '="' . $setting . '" ';
                                     }
                                 }
                                 break;
                             default:
                                 if (!empty($setting)) {
                                     $cronline .= ' jform:general:' . $name . '="' . $setting . '" ';
                                 }
                                 break;
                         }
                     }
                     break;
                 case 'export_fields':
                     if ($notemplate) {
                         if (array_key_exists('export_fields', $settings)) {
                             $fields = $settings['export_fields'];
                         } else {
                             $fields = array();
                         }
                     } else {
                         $fields = $template->get('export_fields', '', array());
                     }
                     if (!empty($fields)) {
                         $fields['_selected_name'] = CsviHelper::recurseArrayDiff($settings['export_fields']['_selected_name'], $fields['_selected_name']);
                         if (!empty($fields['_selected_name'])) {
                             $cronline .= ' jform:export_fields:_selected_name = "' . implode('|', $settings['export_fields']['_selected_name']) . '|"';
                             $cronline .= ' jform:export_fields:_column_header = "' . implode('|', $settings['export_fields']['_column_header']) . '|"';
                             $cronline .= ' jform:export_fields:_default_value = "' . implode('|', $settings['export_fields']['_default_value']) . '|"';
                             $cronline .= ' jform:export_fields:_process_field = "' . implode('|', $settings['export_fields']['_process_field']) . '|"';
                         }
                     }
                     break;
                 default:
                     if ($notemplate) {
                         $values = $settings[$group];
                     } else {
                         $values = CsviHelper::recurseArrayDiff($settings[$group], $template->get($group));
                     }
                     $cronline .= $this->_getCronSetting($values, $group);
                     break;
             }
         }
     } else {
         if ($details->type == 'import') {
             foreach ($settings as $group => $values) {
                 switch ($group) {
                     case 'options':
                         break;
                     case 'import_fields':
                         if ($notemplate) {
                             if (array_key_exists('import_fields', $settings)) {
                                 $fields = $settings['import_fields'];
                             } else {
                                 $fields = array();
                             }
                         } else {
                             // Create a default value
                             $default = array();
                             $default['_selected_name'][] = '';
                             $fields = $template->get('import_fields', '', $default);
                             $fields['_selected_name'] = CsviHelper::recurseArrayDiff($settings['import_fields']['_selected_name'], $fields['_selected_name']);
                         }
                         if (!empty($fields)) {
                             if (!empty($fields['_selected_name'])) {
                                 $cronline .= ' jform:import_fields:_selected_name = "' . implode('|', $settings['import_fields']['_selected_name']) . '|"';
                                 $cronline .= ' jform:import_fields:_default_value = "' . implode('|', $settings['import_fields']['_default_value']) . '|"';
                                 $cronline .= ' jform:import_fields:_process_field = "' . implode('|', $settings['import_fields']['_process_field']) . '|"';
                             }
                         }
                         break;
                     default:
                         if ($notemplate) {
                             $values = $settings[$group];
                             if (!is_array($values)) {
                                 $values = array();
                                 $values[$group] = $settings[$group];
                             }
                         } else {
                             $values = CsviHelper::recurseArrayDiff($settings[$group], $template->get($group));
                         }
                         $cronline .= $this->_getCronSetting($values, $group);
                         break;
                 }
             }
         }
     }
     return $cronline;
 }