Example #1
0
 /**
  * Backup Generate Process
  *
  * @param str $option
  */
 function backupDownload()
 {
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_rsform' . DS . 'helpers' . DS . 'backup.php';
     jimport('joomla.filesystem.archive');
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     // Get the selected items
     $cid = JRequest::getVar('cid', array(0), 'post', 'array');
     // Force array elements to be integers
     JArrayHelper::toInteger($cid, array(0));
     $tmpdir = uniqid('rsformbkp');
     $path = JPATH_SITE . DS . 'media' . DS . $tmpdir;
     if (!JFolder::create($path, 0777)) {
         JError::raiseWarning(500, JText::_('Could not create directory ') . $path);
         return $this->setRedirect('index.php?option=com_rsform&task=backup.restore');
     }
     $export_submissions = JRequest::getInt('submissions');
     if (!RSFormProBackup::create($cid, $export_submissions, $path . DS . 'install.xml')) {
         JError::raiseWarning(500, JText::_('Could not write to ') . $path);
         return $this->setRedirect('index.php?option=com_rsform&task=backup.restore');
     }
     $name = 'rsform_backup_' . date('Y-m-d_His') . '.zip';
     $files = array(array('data' => JFile::read($path . DS . 'install.xml'), 'name' => 'install.xml'));
     $adapter =& JArchive::getAdapter('zip');
     if (!$adapter->create($path . DS . $name, $files)) {
         JError::raiseWarning(500, JText::_('Could not create archive ') . $path . DS . $name);
         return $this->setRedirect('index.php?option=com_rsform&task=backup.restore');
     }
     $this->setRedirect(JURI::root() . 'media/' . $tmpdir . '/' . $name);
 }
Example #2
0
 function create($formIds, $submissions, $filename)
 {
     $db =& JFactory::getDBO();
     $user = JFactory::getUser();
     $config = JFactory::getConfig();
     $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
     $xml .= '<RSinstall type="rsformbackup">' . "\n";
     $xml .= '<name>RSform backup</name>' . "\n";
     $xml .= '<creationDate>' . date('Y-m-d') . '</creationDate>' . "\n";
     $xml .= '<author>' . $user->username . '</author>' . "\n";
     $xml .= '<copyright>(C) ' . date('Y') . ' ' . JURI::root() . '</copyright>' . "\n";
     $xml .= '<authorEmail>' . $config->getValue('config.mailfrom') . '</authorEmail>' . "\n";
     $xml .= '<authorUrl>' . JURI::root() . '</authorUrl>' . "\n";
     $xml .= '<version>' . _RSFORM_VERSION . '</version>' . "\n";
     $xml .= '<revision>' . _RSFORM_REVISION . '</revision>' . "\n";
     $xml .= '<description>RSForm! Pro Backup</description>' . "\n";
     $xml .= '<tasks>' . "\n";
     //LOAD FORMS
     $db->setQuery("SELECT * FROM #__rsform_forms WHERE FormId IN ('" . implode("','", $formIds) . "') ORDER BY FormId");
     $form_rows = $db->loadObjectList();
     foreach ($form_rows as $form_row) {
         $xml .= RSFormProBackup::createXMLEntry('#__rsform_forms', $form_row, 'FormId') . "\n";
         $xml .= "\t" . '<task type="eval" source="">$GLOBALS[\'q_FormId\'] = $db->insertid();</task>' . "\n";
         $db->setQuery("SELECT * FROM #__rsform_translations WHERE `form_id`='" . $form_row->FormId . "' AND `reference`='forms'");
         $translations = $db->loadObjectList();
         foreach ($translations as $translation) {
             $xml .= RSFormProBackup::createXMLEntry('#__rsform_translations', $translation, 'id') . "\n";
         }
         //LOAD COMPONENTS
         $db->setQuery("SELECT * FROM #__rsform_components WHERE FormId = '" . $form_row->FormId . "'");
         $component_rows = $db->loadObjectList();
         foreach ($component_rows as $component_row) {
             $xml .= RSFormProBackup::createXMLEntry('#__rsform_components', $component_row, 'ComponentId', 'FormId') . "\n";
             $xml .= "\t" . '<task type="eval" source="">$GLOBALS[\'q_ComponentId\'] = $db->insertid();</task>' . "\n";
             //LOAD PROPERTIES
             $db->setQuery("SELECT * FROM #__rsform_properties WHERE ComponentId = '" . $component_row->ComponentId . "'");
             $property_rows = $db->loadObjectList();
             foreach ($property_rows as $property_row) {
                 $xml .= RSFormProBackup::createXMLEntry('#__rsform_properties', $property_row, 'PropertyId', 'ComponentId') . "\n";
             }
             //LOAD TRANSLATIONS
             $db->setQuery("SELECT * FROM #__rsform_translations WHERE `form_id`='" . $form_row->FormId . "' AND `reference_id` LIKE '" . $component_row->ComponentId . ".%'");
             $translations = $db->loadObjectList();
             foreach ($translations as $translation) {
                 $xml .= RSFormProBackup::createXMLEntry('#__rsform_translations', $translation, 'id') . "\n";
             }
         }
         if ($submissions) {
             //LOAD SUBMISSIONS
             $db->setQuery("SELECT * FROM #__rsform_submissions WHERE FormId = '" . $form_row->FormId . "'");
             $submission_rows = $db->loadObjectList();
             foreach ($submission_rows as $submission_row) {
                 $xml .= RSFormProBackup::createXMLEntry('#__rsform_submissions', $submission_row, 'SubmissionId', 'FormId') . "\n";
                 $xml .= "\t" . '<task type="eval" source="">$GLOBALS[\'q_SubmissionId\'] = $db->insertid();</task>' . "\n";
                 //LOAD SUBMISSION_VALUES
                 $db->setQuery("SELECT * FROM #__rsform_submission_values WHERE SubmissionId = '" . $submission_row->SubmissionId . "'");
                 $submission_value_rows = $db->loadObjectList();
                 foreach ($submission_value_rows as $submission_value_row) {
                     $xml .= RSFormProBackup::createXMLEntry('#__rsform_submission_values', $submission_value_row, 'SubmissionValueId', array('SubmissionId', 'FormId')) . "\n";
                 }
             }
         }
     }
     $xml .= '</tasks>' . "\n";
     $xml .= '</RSinstall>';
     jimport('joomla.filesystem.file');
     return JFile::write($filename, $xml);
 }
Example #3
0
 public static function create($formIds, $submissions, $filename)
 {
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     $config = JFactory::getConfig();
     $version = new RSFormProVersion();
     $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
     $xml .= '<RSinstall type="rsformbackup">' . "\n";
     $xml .= '<name>RSform backup</name>' . "\n";
     $xml .= '<creationDate>' . date('Y-m-d') . '</creationDate>' . "\n";
     $xml .= '<author>' . $user->username . '</author>' . "\n";
     $xml .= '<copyright>(C) ' . date('Y') . ' ' . JURI::root() . '</copyright>' . "\n";
     $xml .= '<authorEmail>' . $config->get('mailfrom') . '</authorEmail>' . "\n";
     $xml .= '<authorUrl>' . JURI::root() . '</authorUrl>' . "\n";
     $xml .= '<version>' . (string) $version . '</version>' . "\n";
     $xml .= '<revision>' . $version->revision . '</revision>' . "\n";
     $xml .= '<description>RSForm! Pro Backup</description>' . "\n";
     $xml .= '<tasks>' . "\n";
     // We need to see all available languages here, because the conditions are attached to languages
     $lang = JFactory::getLanguage();
     $languages = $lang->getKnownLanguages(JPATH_SITE);
     //LOAD FORMS
     $db->setQuery("SELECT * FROM #__rsform_forms WHERE FormId IN ('" . implode("','", $formIds) . "') ORDER BY FormId");
     $form_rows = $db->loadObjectList();
     foreach ($form_rows as $form_row) {
         $xml .= RSFormProBackup::createXMLEntry('#__rsform_forms', $form_row, 'FormId') . "\n";
         $xml .= "\t" . '<task type="eval"><![CDATA[$GLOBALS[\'q_FormId\'] = $db->insertid();]]></task>' . "\n";
         $db->setQuery("SELECT * FROM #__rsform_translations WHERE `form_id`='" . $form_row->FormId . "' AND `reference`='forms'");
         $translations = $db->loadObjectList();
         foreach ($translations as $translation) {
             $xml .= RSFormProBackup::createXMLEntry('#__rsform_translations', $translation, 'id') . "\n";
         }
         $xml .= "\t" . '<task type="eval"><![CDATA[$GLOBALS[\'ComponentIds\'] = array();]]></task>' . "\n";
         //LOAD COMPONENTS
         $db->setQuery("SELECT * FROM #__rsform_components WHERE FormId = '" . $form_row->FormId . "'");
         $component_rows = $db->loadObjectList();
         foreach ($component_rows as $component_row) {
             $xml .= RSFormProBackup::createXMLEntry('#__rsform_components', $component_row, 'ComponentId', 'FormId') . "\n";
             $xml .= "\t" . '<task type="eval"><![CDATA[$GLOBALS[\'q_ComponentId\'] = $db->insertid();]]></task>' . "\n";
             //LOAD PROPERTIES
             $db->setQuery("SELECT * FROM #__rsform_properties WHERE ComponentId = '" . $component_row->ComponentId . "'");
             $property_rows = $db->loadObjectList();
             $ComponentName = '';
             foreach ($property_rows as $property_row) {
                 if ($property_row->PropertyName == 'NAME') {
                     $ComponentName = $property_row->PropertyValue;
                 }
                 $xml .= RSFormProBackup::createXMLEntry('#__rsform_properties', $property_row, 'PropertyId', 'ComponentId') . "\n";
             }
             if ($ComponentName) {
                 $xml .= "\t" . '<task type="eval"><![CDATA[$GLOBALS[\'ComponentIds\'][\'' . $ComponentName . '\'] = $GLOBALS[\'q_ComponentId\'];]]></task>' . "\n";
             }
             //LOAD TRANSLATIONS
             $db->setQuery("SELECT * FROM #__rsform_translations WHERE `form_id`='" . $form_row->FormId . "' AND `reference_id` LIKE '" . $component_row->ComponentId . ".%'");
             $translations = $db->loadObjectList();
             foreach ($translations as $translation) {
                 $xml .= RSFormProBackup::createXMLEntry('#__rsform_translations', $translation, 'id') . "\n";
             }
         }
         if ($submissions) {
             //LOAD SUBMISSIONS
             $db->setQuery("SELECT * FROM #__rsform_submissions WHERE FormId = '" . $form_row->FormId . "'");
             $submission_rows = $db->loadObjectList();
             foreach ($submission_rows as $submission_row) {
                 $xml .= RSFormProBackup::createXMLEntry('#__rsform_submissions', $submission_row, 'SubmissionId', 'FormId') . "\n";
                 $xml .= "\t" . '<task type="eval"><![CDATA[$GLOBALS[\'q_SubmissionId\'] = $db->insertid();]]></task>' . "\n";
                 //LOAD SUBMISSION_VALUES
                 $db->setQuery("SELECT * FROM #__rsform_submission_values WHERE SubmissionId = '" . $submission_row->SubmissionId . "'");
                 $submission_value_rows = $db->loadObjectList();
                 foreach ($submission_value_rows as $submission_value_row) {
                     $xml .= RSFormProBackup::createXMLEntry('#__rsform_submission_values', $submission_value_row, 'SubmissionValueId', array('SubmissionId', 'FormId')) . "\n";
                 }
             }
         }
         //LOAD CONDITIONS
         foreach ($languages as $tag => $properties) {
             $conditions = RSFormProHelper::getConditions($form_row->FormId, $tag);
             if ($conditions) {
                 foreach ($conditions as $condition) {
                     $xml .= RSFormProBackup::createXMLEntry('#__rsform_conditions', $condition, array('id')) . "\n";
                     $xml .= "\t" . '<task type="eval"><![CDATA[$GLOBALS[\'q_ConditionId\'] = $db->insertid();]]></task>' . "\n";
                     if ($condition->details) {
                         foreach ($condition->details as $detail) {
                             $xml .= RSFormProBackup::createXMLEntry('#__rsform_condition_details', $detail, array('id')) . "\n";
                         }
                     }
                 }
             }
         }
         //LOAD POSTS
         $db->setQuery("SELECT * FROM #__rsform_posts WHERE `form_id`='" . $form_row->FormId . "'");
         if ($post = $db->loadObject()) {
             $xml .= RSFormProBackup::createXMLEntry('#__rsform_posts', $post, null, null, true) . "\n";
         }
         //LOAD CALCULATIONS
         if ($calculations = RSFormProHelper::getCalculations($form_row->FormId)) {
             foreach ($calculations as $calculation) {
                 $xml .= RSFormProBackup::createXMLEntry('#__rsform_calculations', $calculation, null, null, true) . "\n";
             }
         }
         //Trigger Event - onFormBackup
         $app->triggerEvent('rsfp_bk_onFormBackup', array(array('formId' => $form_row->FormId, 'xml' => &$xml)));
     }
     $xml .= '</tasks>' . "\n";
     $xml .= '</RSinstall>';
     jimport('joomla.filesystem.file');
     return JFile::write($filename, $xml);
 }
Example #4
0
 public function download()
 {
     $input = JFactory::getApplication()->input;
     $key = $input->get('key', '', 'cmd');
     $data = $input->get('jform', array(), 'array');
     $options = array('key' => $key, 'name' => empty($data['name']) ? 'backup' : $data['name']);
     try {
         $backup = new RSFormProBackup($options);
         $backup->download();
     } catch (Exception $e) {
         JError::raiseError(500, $e->getMessage());
     }
 }