Beispiel #1
0
 /**
  * Prepare for export
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		3.0
  */
 public function getPrepareExport()
 {
     // Load the basics
     $jinput = JFactory::getApplication()->input;
     $db = JFactory::getDbo();
     $exportfile_model = $this->_getModel('exportfile');
     // Load the backend language file
     $lang = JFactory::getLanguage();
     $lang->load('com_csvi', JPATH_ADMINISTRATOR);
     // Load the template
     $template = new CsviTemplate();
     $template->load($jinput->get('template_id', 0, 'int'));
     $template->set('exportto', 'general', 'tofront');
     $jinput->set('template', $template);
     // Set the export type
     $jinput->set('export_type', $template->get('operation', 'options'));
     // Initiate the log
     $csvilog = new CsviLog();
     // Create a new Import ID in the logger
     $csvilog->setId();
     // Set to collect debug info
     $csvilog->setDebug($template->get('collect_debug_info', 'general'));
     // Set some log info
     $csvilog->SetAction('export');
     $csvilog->SetActionType($template->get('export_type'), $template->getName());
     // Add the logger to the registry
     $jinput->set('csvilog', $csvilog);
     // Load the fields to export
     $exportfields = $exportfile_model->getExportFields();
     if (!empty($exportfields)) {
         $jinput->set('export.fields', $exportfields);
         // Allow big SQL selects
         $db->setQuery("SET OPTION SQL_BIG_SELECTS=1");
         $db->query();
         // Get the filename for the export file
         $jinput->set('export.filename', $exportfile_model->exportFilename());
         // See if we need to get an XML/HTML class
         $export_format = $template->get('export_file', 'general');
         if ($export_format == 'xml' || $export_format == 'html') {
             $exportclass = $exportfile_model->getExportClass();
             if ($exportclass) {
                 $jinput->set('export.class', $exportclass);
             } else {
                 $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_EXPORT_CLASS'));
                 $jinput->set('logcount', 0);
                 return false;
             }
         }
         // Return all is good
         return true;
     } else {
         $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_EXPORT_FIELDS'));
         $jinput->set('logcount', 0);
         return false;
     }
 }
Beispiel #2
0
 /**
  * Process an uploaded file with headers
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access
  * @param
  * @return
  * @since 		5.8
  */
 public function processFile($pk, $validData)
 {
     $jinput = JFactory::getApplication()->input;
     // Get the file details
     $upload = array();
     $upload['name'] = $_FILES['jform']['name']['mapfile'];
     $upload['type'] = $_FILES['jform']['type']['mapfile'];
     $upload['tmp_name'] = $_FILES['jform']['tmp_name']['mapfile'];
     $upload['error'] = $_FILES['jform']['error']['mapfile'];
     if (!$upload['error']) {
         // Move the temporary file
         if (is_uploaded_file($upload['tmp_name'])) {
             // Get some basic info
             jimport('joomla.filesystem.file');
             jimport('joomla.filesystem.folder');
             $folder = CSVIPATH_TMP . '/' . time();
             $upload_parts = pathinfo($upload['name']);
             // Create the temp folder
             if (JFolder::create($folder)) {
                 // Move the uploaded file to its temp location
                 if (JFile::upload($upload['tmp_name'], $folder . '/' . $upload['name'])) {
                     if (array_key_exists('extension', $upload_parts)) {
                         // Load the base class
                         require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/file.php';
                         // Load the extension specific class
                         switch ($upload_parts['extension']) {
                             case 'xml':
                                 require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/file/import/xml.php';
                                 $fileclass = 'Xml';
                                 break;
                             case 'xls':
                                 require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/file/import/xls.php';
                                 require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/file/import/excel_reader2.php';
                                 $fileclass = 'Xls';
                                 break;
                             case 'ods':
                                 require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/file/import/ods.php';
                                 require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/file/import/ods_reader.php';
                                 $fileclass = 'Ods';
                                 break;
                             default:
                                 // Treat any unknown type as CSV
                                 require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/file/import/csv.php';
                                 $fileclass = 'Csv';
                                 break;
                         }
                         // Set the file class name
                         $fileclass .= 'File';
                         // Get a template object
                         if (!class_exists('CsviTemplate')) {
                             require JPATH_COMPONENT_ADMINISTRATOR . '/helpers/template.php';
                         }
                         $template = new CsviTemplate();
                         $template->set('source', 'general', 'fromserver');
                         $template->set('local_csv_file', 'general', $folder . '/' . $upload['name']);
                         $jinput->set('template', $template);
                         // Get the file handler
                         $file = new $fileclass();
                         // Validate and process the file
                         $file->validateFile();
                         $file->processFile();
                         // Get the header
                         if ($file->loadColumnHeaders()) {
                             $header = $jinput->get('columnheaders', array(), 'array');
                             if (is_array($header)) {
                                 // Load the table
                                 $table = $this->getTable('mapheaders');
                                 // Remove existing entries
                                 $db = JFactory::getDbo();
                                 $query = $db->getQuery(true)->delete($db->qn('#__csvi_mapheaders'))->where($db->qn('map_id') . '=' . $pk);
                                 $db->setQuery($query);
                                 $db->query();
                                 // Store the headers
                                 $map = array();
                                 $map['map_id'] = $pk;
                                 foreach ($header as $name) {
                                     $map['csvheader'] = $name;
                                     // Store the data
                                     $table->save($map);
                                     $table->reset();
                                 }
                             } else {
                                 return false;
                             }
                         } else {
                             return false;
                         }
                     } else {
                         return false;
                     }
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         } else {
             return false;
         }
     }
 }
Beispiel #3
0
 /**
  * Export for front-end
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		3.0
  */
 public function export()
 {
     // Create the view
     $view = $this->getView('export', 'raw');
     // Add the export model
     $view->setModel($this->getModel('export', 'CsviModel'), true);
     // Add the export model path
     $this->addModelPath(JPATH_COMPONENT_ADMINISTRATOR . '/models');
     // General export functions
     $view->setModel($this->getModel('exportfile', 'CsviModel'));
     // Log functions
     $view->setModel($this->getModel('log', 'CsviModel'));
     // Settings functions
     $view->setModel($this->getModel('settings', 'CsviModel'));
     // General category functions
     $view->setModel($this->getModel('category', 'CsviModel'));
     // Available fields
     $view->setModel($this->getModel('availablefields', 'CsviModel'));
     // Load the model
     $model = $this->getModel('exportfile');
     // Add extra helper paths
     $view->addHelperPath(JPATH_COMPONENT_ADMINISTRATOR . '/helpers');
     $view->addHelperPath(JPATH_COMPONENT_ADMINISTRATOR . '/helpers/xml');
     $view->addHelperPath(JPATH_COMPONENT_ADMINISTRATOR . '/helpers/html');
     // Load the helper classes
     $view->loadHelper('csvidb');
     $view->loadHelper('template');
     $view->loadHelper('csvisef');
     // Load the template details
     $jinput = JFactory::getApplication()->input;
     $template = new CsviTemplate();
     $template->load($jinput->get('template_id', 0, 'int'));
     $jinput->set('jform', $template->getSettings());
     // Set the output destination
     $template->set('exportto', 'general', $jinput->get('exportto', 'tofront', 'cmd'));
     $jinput->set('template', $template);
     if ($template->get('action', 'options', 'export') == 'export') {
         // Prepare for export
         if ($model->getPrepareExport()) {
             // Set the export override
             $app = JFactory::getApplication();
             $jinput = JFactory::getApplication()->input;
             $overridefile = JPATH_BASE . '/templates/' . $app->getTemplate() . '/html/com_csvi/models/export/' . $template->get('operation', 'options') . '.php';
             // Add the export model path if override exists
             if (file_exists($overridefile)) {
                 $this->addModelPath(JPATH_BASE . '/templates/' . $app->getTemplate() . '/html/com_csvi/models/' . $template->get('component', 'options') . '/export');
             } else {
                 $this->addModelPath(JPATH_COMPONENT_ADMINISTRATOR . '/models/' . $template->get('component', 'options') . '/export');
             }
             // Load export specifc helper
             $view->loadHelper($template->get('component', 'options'));
             $view->loadHelper($template->get('component', 'options') . '_config');
             // Display it all
             $view->display();
         } else {
             // Clean up first
             $model->getCleanSession();
             // Add appropriate message
         }
     } else {
         // Add appropriate message
     }
 }