示例#1
0
 /**
  * Save all field in page form
  *
  * @param   type  $dataFormId      Form id
  *
  * @param   type  $dataFormLayout  Form layout
  *
  * @return void
  */
 public function saveField($dataFormId, $dataFormLayout)
 {
     $post = $_POST;
     $edition = defined('JSN_UNIFORM_EDITION') ? JSN_UNIFORM_EDITION : "free";
     $session = JFactory::getSession();
     $identify = array();
     $fieldSB = array();
     $pageId = array();
     $count = 0;
     $checkTableSubmission = true;
     $formId = $this->getState($this->getName() . '.id');
     $formId = intval($formId);
     $fieldIds = array();
     //get data form page
     $this->_db->setQuery($this->_db->getQuery(true)->select('page_id')->from('#__jsn_uniform_form_pages')->where('form_id=' . $formId))->order("page_id ASC");
     $dataFormPages = $this->_db->loadObjectList();
     $listFormPages = array();
     if (!empty($dataFormPages)) {
         foreach ($dataFormPages as $FormPage) {
             $listFormPages[] = $FormPage->page_id;
         }
     }
     if (!JSNUniformHelper::checkTableSql("jsn_uniform_submissions_{$formId}")) {
         $checkTableSubmission = false;
     } else {
         $this->_db->setQuery("SHOW COLUMNS FROM #__jsn_uniform_submissions_{$formId}");
         $columnSubmission = $this->_db->loadObjectList();
     }
     if (isset($post['name_page'])) {
         foreach ($post['name_page'] as $value => $text) {
             $dataField = array();
             $parsedFields = array();
             $formPages = "";
             $formFields = "";
             $pageContainer = "";
             if ($dataFormId == 0) {
                 $formFields = json_decode($session->get('form_page_' . $value, '', 'form-design-'));
                 $pcontainer = $_SESSION['__form-design-']['form_container_page_' . $value];
                 $pageContainer = get_magic_quotes_gpc() == true || get_magic_quotes_runtime() == true ? stripslashes($pcontainer) : $pcontainer;
                 $pageContainer = json_decode($pageContainer);
             } else {
                 $formFields = json_decode($session->get('form_page_' . $value, '', 'form-design-' . $dataFormId));
                 $pcontainer = $_SESSION['__form-design-' . $dataFormId]['form_container_page_' . $value];
                 $pageContainer = get_magic_quotes_gpc() == true || get_magic_quotes_runtime() == true ? stripslashes($pcontainer) : $pcontainer;
                 $pageContainer = json_decode($pageContainer);
             }
             if (!empty($formFields) && is_array($formFields)) {
                 foreach ($formFields as $index => $field) {
                     if ($index < 10 && strtolower($edition) == "free" || strtolower($edition) != "free") {
                         $count++;
                         $options = $field->options;
                         if (in_array($field->identify, $identify)) {
                             $field->identify = $field->identify . $count;
                         }
                         $identify[] = $field->identify;
                         $field->identify = preg_replace('/[^a-z0-9-._]/i', "", $field->identify);
                         $table = JTable::getInstance('JsnField', 'JSNUniformTable');
                         $table->bind(array('form_id' => $formId, 'field_id' => isset($field->id) ? $field->id : null, 'field_type' => $field->type, 'field_identifier' => $field->identify, 'field_title' => $options->label, 'field_instructions' => isset($options->instruction) ? $options->instruction : null, 'field_position' => $field->position, 'field_ordering' => $index, 'field_settings' => json_encode($field)));
                         if (!$table->store()) {
                             $this->setError($table->getError());
                             $result = false;
                         }
                         $fieldIds[] = $table->field_id;
                         $fieldSB[] = "sb_" . $table->field_id;
                         $parsedFields[] = array('id' => $table->field_id, 'type' => $table->field_type, 'position' => $table->field_position, 'identify' => $table->field_identifier, 'label' => $table->field_title, 'instruction' => $table->field_instructions, 'options' => $field->options);
                     }
                 }
             }
             if (in_array($value, $listFormPages)) {
                 $formPages['page_id'] = $value;
             }
             $formPages['page_title'] = get_magic_quotes_gpc() == true || get_magic_quotes_runtime() == true ? stripslashes($text) : $text;
             $formPages['form_id'] = $formId;
             $formPages['page_content'] = isset($parsedFields) ? json_encode($parsedFields) : "";
             $formPages['page_container'] = json_encode($pageContainer);
             $table = JTable::getInstance('JsnPage', 'JSNUniformTable');
             $table->bind($formPages);
             if (!$table->store()) {
                 $this->setError($table->getError());
                 $result = false;
             }
             $pageId[] = $table->page_id;
         }
     }
     if (!empty($fieldIds)) {
         $this->_db->setQuery("DELETE FROM #__jsn_uniform_fields WHERE form_id={$formId} AND field_id NOT IN (" . implode(', ', $fieldIds) . ")");
         $this->_db->execute();
     } else {
         $this->_db->setQuery("DELETE FROM #__jsn_uniform_fields WHERE form_id={$formId}");
         $this->_db->execute();
     }
     if (!empty($pageId)) {
         $this->_db->setQuery("DELETE FROM #__jsn_uniform_form_pages WHERE form_id={$formId} AND page_id NOT IN (" . implode(', ', $pageId) . ")");
         $this->_db->execute();
     }
 }
示例#2
0
 /**
  * Do any preparation needed before doing real data restore.
  *
  * @param   string   &$backup       Path to folder containing extracted backup files.
  * @param   boolean  $checkEdition  Check for matching edition before restore?
  *
  * @return  void
  */
 protected function beforeRestore(&$backup, $checkEdition = true)
 {
     // Initialize variables
     $com = preg_replace('/^com_/i', '', JFactory::getApplication()->input->getCmd('option'));
     $info = JSNUtilsXml::loadManifestCache();
     $jVer = new JVersion();
     // Extract backup file
     if (!JArchive::extract($backup, substr($backup, 0, -4))) {
         throw new Exception(JText::_('JSN_EXTFW_DATA_EXTRACT_UPLOAD_FILE_FAIL'));
     }
     $backup = substr($backup, 0, -4);
     // Auto-detect backup XML file
     $files = glob("{$backup}/*.xml");
     foreach ($files as $file) {
         $this->data = JSNUtilsXml::load($file);
         // Check if this XML file contain backup data for our product
         if (strcasecmp($this->data->getName(), 'backup') == 0 and isset($this->data['extension-name']) and isset($this->data['extension-version']) and isset($this->data['joomla-version'])) {
             // Store backup XML file name
             $this->xml = basename($file);
             // Simply break the loop if we found backup file
             break;
         }
         unset($this->data);
     }
     if (isset($this->data)) {
         // Check if Joomla series match
         if (!$jVer->isCompatible((string) $this->data['joomla-version'])) {
             throw new Exception(JText::_('JSN_EXTFW_DATA_JOOMLA_VERSION_NOT_MATCH'));
         }
         // Check if extension match
         if ((string) $this->data['extension-name'] != 'JSN ' . preg_replace('/JSN\\s*/i', '', JText::_($info->name))) {
             throw new Exception(JText::_('JSN_EXTFW_DATA_INVALID_PRODUCT'));
         } elseif (isset($this->data['extension-edition']) and $checkEdition and (!($const = JSNUtilsText::getConstant('EDITION')) or (string) $this->data['extension-edition'] != $const)) {
             throw new Exception(JText::_('JSN_EXTFW_DATA_INVALID_PRODUCT_EDITION'));
         } elseif (!version_compare($info->version, (string) $this->data['extension-version'], '=') and !$checkEdition) {
             // Get update link for out-of-date product
             $ulink = $info->authorUrl;
             if (isset($this->data['update-url'])) {
                 $ulink = (string) $this->data['update-url'];
             } elseif ($const = JSNUtilsText::getConstant('UPDATE_LINK')) {
                 $ulink = $const;
             }
             throw new Exception(JText::_('JSN_EXTFW_DATA_PRODUCT_VERSION_OUTDATE') . '&nbsp;<a href="' . $ulink . '" class="jsn-link-action">' . JText::_('JSN_EXTFW_GENERAL_UPDATE_NOW') . '</a>');
         } elseif (!version_compare($info->version, (string) $this->data['extension-version'], 'ge')) {
             // Get update link for out-of-date product
             $ulink = $info->authorUrl;
             if (isset($this->data['update-url'])) {
                 $ulink = (string) $this->data['update-url'];
             } elseif ($const = JSNUtilsText::getConstant('UPDATE_LINK')) {
                 $ulink = $const;
             }
             throw new Exception(JText::_('JSN_EXTFW_DATA_PRODUCT_VERSION_OUTDATE') . '&nbsp;<a href="' . $ulink . '" class="jsn-link-action">' . JText::_('JSN_EXTFW_GENERAL_UPDATE_NOW') . '</a>');
         }
     } else {
         throw new Exception(JText::_('JSN_EXTFW_DATA_BACKUP_XML_NOT_FOUND'));
     }
     $dataForm = $this->getForm();
     if (!empty($dataForm) && count($dataForm)) {
         foreach ($dataForm as $formId) {
             if (!empty($formId->form_id) && (int) $formId->form_id) {
                 $this->_db->setQuery("DROP TABLE IF EXISTS #__jsn_uniform_submissions_{$formId->form_id}");
                 $this->_db->execute();
             }
         }
     }
     if (JSNUniformHelper::checkTableSql('#__jsn_uniform_submissions') === false) {
         JSNUniformHelper::createTableIfNotExistsSubmissions();
     }
     if (JSNUniformHelper::checkTableSql('#__jsn_uniform_submission_data') === false) {
         JSNUniformHelper::createTableIfNotExistsSubmissionData();
     }
 }
示例#3
0
 /**
  * Convert data Submissions
  *
  * @return boolen
  */
 public static function convertTableSubmissions($action = null)
 {
     $db = JFactory::getDBO();
     $checkConvert = false;
     if (self::checkTableSql('#__jsn_uniform_submissions') == false) {
         self::createTableIfNotExistsSubmissions();
         $checkConvert = true;
     } else {
         if ($action == "restore") {
             $checkConvert = true;
         }
     }
     if ($checkConvert && JSNUniformHelper::checkTableSql('#__jsn_uniform_data')) {
         $query = $db->getQuery(true);
         $query->delete('#__jsn_uniform_submissions');
         $db->setQuery($query);
         $db->execute();
         $db->getQuery(true);
         $db->setQuery($db->getQuery(true)->select('*')->from('#__jsn_uniform_data'));
         $dataForms = $db->loadObjectList();
         if (!empty($dataForms)) {
             foreach ($dataForms as $data) {
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query->insert('#__jsn_uniform_submissions');
                 $query->columns(array($db->quoteName('submission_id'), $db->quoteName('form_id'), $db->quoteName('user_id'), $db->quoteName('submission_ip'), $db->quoteName('submission_country'), $db->quoteName('submission_country_code'), $db->quoteName('submission_browser'), $db->quoteName('submission_browser_version'), $db->quoteName('submission_browser_agent'), $db->quoteName('submission_os'), $db->quoteName('submission_created_by'), $db->quoteName('submission_created_at'), $db->quoteName('submission_state')));
                 $query->values($db->quote($data->data_id) . ', ' . $db->quote($data->form_id) . ', ' . $db->quote($data->user_id) . ', ' . $db->quote($data->data_ip) . ', ' . $db->quote($data->data_country) . ', ' . $db->quote($data->data_country_code) . ', ' . $db->quote($data->data_browser) . ', ' . $db->quote($data->data_browser_version) . ', ' . $db->quote($data->data_browser_agent) . ', ' . $db->quote($data->data_os) . ', ' . $db->quote($data->data_created_by) . ', ' . $db->quote($data->data_created_at) . ', ' . $db->quote($data->data_state));
                 $db->setQuery($query);
                 $db->query();
             }
         }
     }
 }