Beispiel #1
0
 public function storeMetaData()
 {
     // Load forms from the database
     $db =& $this->db;
     $query = $db->getQuery(true);
     $query->select('*')->from($db->qn('#__rsform_forms'))->where($db->qn('FormId') . ' IN (' . RSFormProBackupHelper::qi($this->formIds) . ')');
     $db->setQuery($query);
     $this->forms = $db->loadObjectList('FormId');
     // Count the number of submissions as well, if requested.
     if ($this->submissions) {
         $query->clear()->select('COUNT(' . $db->qn('SubmissionId') . ') AS ' . $db->qn('count'))->select($db->qn('FormId'))->from($db->qn('#__rsform_submissions'))->where($db->qn('FormId') . ' IN (' . RSFormProBackupHelper::qi($this->formIds) . ')')->group($db->qn('FormId'));
         $db->setQuery($query);
         if ($submissions = $db->loadObjectList()) {
             foreach ($submissions as $submission) {
                 if (isset($this->forms[$submission->FormId])) {
                     $this->forms[$submission->FormId]->SubmissionsCount = $submission->count;
                 }
             }
         }
     }
     // Initialize XML writer.
     $xml = new RSFormProBackupXML();
     $xml->addHeader()->add('rsform')->add('version', (string) new RSFormProVersion())->add('cms', JVERSION)->add('php', phpversion())->add('os', PHP_OS)->add('url', JUri::root())->add('root', JPATH_ROOT)->add('author', JFactory::getUser()->get('email'))->add('date', JFactory::getDate()->toSql());
     // Start adding form information
     if ($this->forms) {
         $xml->add('forms');
         foreach ($this->forms as $form) {
             $xml->add('form')->add('id', RSFormProBackupHelper::getHash($form->FormId))->add('name', $form->FormName)->add('title', $form->FormTitle)->add('submissions', !empty($form->SubmissionsCount) ? $form->SubmissionsCount : 0)->add('/form');
         }
         $xml->add('/forms');
     }
     // Finishup
     $xml->add('/rsform');
     $archive = new RSFormProTar($this->getPath());
     $buffer = (string) $xml;
     $size = strlen($buffer);
     $archive->addHeader($size, 'metadata.xml');
     $archive->add($buffer);
     $archive->addPadding($size);
     $archive->close();
 }
Beispiel #2
0
 protected function getConditions()
 {
     $db =& $this->db;
     $query = $db->getQuery(true);
     $conditions = array();
     $query->select('*')->from($db->qn('#__rsform_conditions'))->where($db->qn('form_id') . '=' . $db->q($this->form->FormId));
     $db->setQuery($query);
     if ($conditions = $db->loadObjectList('id')) {
         $query->clear()->select('*')->from($db->qn('#__rsform_condition_details'))->where($db->qn('condition_id') . ' IN (' . RSFormProBackupHelper::qi(array_keys($conditions)) . ')');
         $db->setQuery($query);
         if ($details = $db->loadObjectList()) {
             foreach ($details as $detail) {
                 $condition_id = $detail->condition_id;
                 $component_id = $detail->component_id;
                 // No need for these.
                 unset($detail->id, $detail->condition_id, $detail->component_id);
                 // Add the field's name so that we can restore correctly.
                 $detail->component_id = isset($this->fields[$component_id]) ? $this->fields[$component_id] : '';
                 if (!isset($conditions[$condition_id]->details)) {
                     $conditions[$condition_id]->details = array();
                 }
                 $conditions[$condition_id]->details[] = $detail;
             }
         }
     }
     return $conditions;
 }
Beispiel #3
0
 public function store()
 {
     $archive = new RSFormProTar($this->path);
     $db =& $this->db;
     $done = false;
     // Set the data XML file number
     if ($this->limitstart >= $this->limit) {
         $xmlNumber = round($this->limitstart / $this->limit);
     } else {
         $xmlNumber = 0;
     }
     // Grab the submissions
     $query = $db->getQuery(true);
     $query->select('*')->from($db->qn('#__rsform_submissions'))->where($db->qn('FormId') . '=' . $db->q($this->id));
     $db->setQuery($query, $this->limitstart, $this->limit);
     if ($submissions = $db->loadObjectList('SubmissionId')) {
         $query->clear()->select('*')->from($db->qn('#__rsform_submission_values'))->where($db->qn('SubmissionId') . ' IN (' . RSFormProBackupHelper::qi(array_keys($submissions)) . ')');
         $db->setQuery($query);
         $values = $db->loadObjectList();
         // Record the position
         $this->header = $archive->tell();
         // Add the 512-bytes dummy header
         $archive->addEmptyHeader();
         // Add the XML header & opening tag.
         $this->xml->addHeader();
         $this->xml->add('submissions');
         foreach ($values as $value) {
             if (empty($submissions[$value->SubmissionId]->values)) {
                 $submissions[$value->SubmissionId]->values = array();
             }
             $submissions[$value->SubmissionId]->values[$value->FieldName] = $value->FieldValue;
         }
         foreach ($submissions as $submission) {
             $values = isset($submission->values) ? $submission->values : array();
             // No need for these.
             unset($submission->values, $submission->SubmissionId, $submission->FormId);
             $this->xml->add('submission');
             foreach ($submission as $property => $value) {
                 $this->xml->add($property, $value);
             }
             // Add values
             $this->xml->add('values');
             foreach ($values as $property => $value) {
                 $this->xml->add('value');
                 $this->xml->add('fieldname', $property);
                 $this->xml->add('fieldvalue', $value);
                 $this->xml->add('/value');
             }
             $this->xml->add('/values');
             $this->xml->add('/submission');
         }
         // We've finished, no more submissions, add the closing tag.
         $this->xml->add('/submissions');
         // Add data to archive.
         $archive->add((string) $this->xml);
         // Compute size of current file in archive.
         $size = $archive->tell() - $this->header - 512;
         // Add missing padding.
         $archive->addPadding($size);
         // Go to header (so we can add missing header data).
         $archive->seek($this->header);
         // Add missing header data.
         $archive->addHeader($size, RSFormProBackupHelper::getHash($this->id) . '-data-' . $xmlNumber . '.xml');
     } else {
         // Flag so that we can move on to the next form
         $done = true;
     }
     $archive->close();
     return (object) array('done' => $done, 'header' => $this->header);
 }