function logToDatabase($cbResult = null)
 {
     // CONTENTBUILDER
     global $database, $ff_config;
     $database = JFactory::getDBO();
     if ($this->dying) {
         return;
     }
     if (!is_object($cbResult['form']) && $this->editable && $this->editable_override) {
         $database->setQuery("Select id From #__facileforms_records Where form = " . $database->Quote($this->form) . " And user_id = " . $database->Quote(JFactory::getUser()->get('id', 0)) . " And user_id <> 0");
         $records = $database->loadObjectList();
         foreach ($records as $record) {
             $database->setQuery("Delete From #__facileforms_subrecords Where record = " . $record->id);
             $database->query();
             $database->setQuery("Delete From #__facileforms_records Where id = " . $record->id);
             $database->query();
         }
     }
     $record = new facileFormsRecords($database);
     $record->submitted = $this->submitted;
     $record->form = $this->form;
     $record->title = $this->formrow->title;
     $record->name = $this->formrow->name;
     $record->ip = $this->ip;
     $record->browser = $this->browser;
     $record->opsys = $this->opsys;
     $record->provider = $this->provider;
     $record->viewed = 0;
     $record->exported = 0;
     $record->archived = 0;
     if (JFactory::getUser()->get('id', 0) > 0) {
         $record->user_id = JFactory::getUser()->get('id', 0);
         $record->username = JFactory::getUser()->get('username', '');
         $record->user_full_name = JFactory::getUser()->get('name', '');
     } else {
         $record->user_id = JFactory::getUser()->get('id', 0);
         $record->username = '******';
         $record->user_full_name = '-';
     }
     // CONTENTBUILDER WILL TAKE OVER SAVING/UPDATE IF EXISTS
     $cbFileFields = array();
     if (!is_object($cbResult['form'])) {
         if (!$record->store()) {
             $this->status = _FF_STATUS_SAVERECORD_FAILED;
             $this->message = $record->getError();
             return;
         }
         // if
         $record_return = $record->id;
         if ($record_return && JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_contentbuilder' . DS . 'contentbuilder.xml')) {
             $last_update = JFactory::getDate();
             jimport('joomla.version');
             $version = new JVersion();
             $is3 = false;
             if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                 $is3 = true;
             }
             $last_update = $is3 ? $last_update->toSql() : $last_update->toMySQL();
             $db = JFactory::getDBO();
             $db->setQuery("Select id From #__contentbuilder_records Where `type` = 'com_breezingforms' And `reference_id` = " . $db->Quote($this->form) . " And record_id = " . $db->Quote($record_return));
             $res = $db->loadResult();
             if (!$res) {
                 $db->setQuery("Insert Into #__contentbuilder_records (session_id,`type`,last_update, published, record_id, reference_id) Values ('" . JFactory::getSession()->getId() . "','com_breezingforms'," . $db->Quote($last_update) . ",0, " . $db->Quote($record_return) . ", " . $db->Quote($this->form) . ")");
                 $db->query();
             } else {
                 $db->setQuery("Update #__contentbuilder_records Set last_update = " . $db->Quote($last_update) . ",edited = edited + 1 Where `type` = 'com_breezingforms' And `reference_id` = " . $db->Quote($this->form) . " And record_id = " . $db->Quote($record_return));
                 $db->query();
             }
         }
     }
     $this->record_id = $record->id;
     $names = array();
     $subrecord = new facileFormsSubrecords($database);
     $subrecord->record = $record->id;
     if (count($this->savedata)) {
         $cbData = array();
         // CONTENTBUILDER file deletion/upgrade
         if (is_object($cbResult['form'])) {
             $db = JFactory::getDBO();
             $db->setQuery('Select SQL_CALC_FOUND_ROWS * From #__contentbuilder_forms Where id = ' . JRequest::getInt('cb_form_id', 0) . ' And published = 1');
             $_settings = $db->loadObject();
             $_record = $cbResult['form']->getRecord(JRequest::getInt('record_id', 0), $_settings->published_only, $cbResult['frontend'] ? $_settings->own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($_settings->own_only ? JFactory::getUser()->get('id', 0) : -1), true);
             foreach ($_record as $_rec) {
                 $_files_deleted = array();
                 if ($_rec->recType == 'File Upload') {
                     $_array = JRequest::getVar('cb_delete_' . $_rec->recElementId, array(), '', 'ARRAY');
                     foreach ($_array as $_key => $_arr) {
                         if ($_arr == 1) {
                             $_values = explode("\n", $_rec->recValue);
                             if (isset($_values[$_key])) {
                                 if (strpos(strtolower($_values[$_key]), '{cbsite}') === 0) {
                                     $_values[$_key] = str_replace(array('{cbsite}', '{CBSite}'), array(JPATH_SITE, JPATH_SITE), $_values[$_key]);
                                 }
                                 if (JFile::exists($_values[$_key])) {
                                     JFile::delete($_values[$_key]);
                                 }
                                 if (!isset($_files_deleted[$_rec->recElementId])) {
                                     $_files_deleted[$_rec->recElementId] = array();
                                 }
                                 $_files_deleted[$_rec->recElementId][] = $_key;
                             }
                         }
                     }
                     if (isset($_files_deleted[$_rec->recElementId]) && is_array($_files_deleted[$_rec->recElementId]) && count($_files_deleted[$_rec->recElementId])) {
                         $_i = 0;
                         foreach ($this->savedata as $data) {
                             if ($data[_FF_DATA_ID] == $_rec->recElementId) {
                                 $_is_values = explode("\n", $_rec->recValue);
                                 $_j = 0;
                                 foreach ($_is_values as $_is_value) {
                                     if (!in_array($_j, $_files_deleted[$_rec->recElementId])) {
                                         $this->savedata[$_i][_FF_DATA_VALUE] .= $_is_value . "\n";
                                     }
                                     $_j++;
                                 }
                                 $this->savedata[$_i][_FF_DATA_VALUE] = rtrim($this->savedata[$_i][_FF_DATA_VALUE]);
                                 break;
                             }
                             $_i++;
                         }
                     } else {
                         if (true) {
                             $next = count($this->savedata);
                             $this->savedata[$next] = array();
                             $this->savedata[$next][_FF_DATA_ID] = $_rec->recElementId;
                             $this->savedata[$next][_FF_DATA_NAME] = $_rec->recName;
                             $this->savedata[$next][_FF_DATA_TITLE] = $_rec->recTitle;
                             $this->savedata[$next][_FF_DATA_TYPE] = $_rec->recType;
                             $this->savedata[$next][_FF_DATA_VALUE] = '';
                             $_is_values = explode("\n", $_rec->recValue);
                             foreach ($_is_values as $_is_value) {
                                 $this->savedata[$next][_FF_DATA_VALUE] .= $_is_value . "\n";
                             }
                             $this->savedata[$next][_FF_DATA_VALUE] = rtrim($this->savedata[$next][_FF_DATA_VALUE]);
                         }
                     }
                 }
             }
         }
         $_savedata = array();
         if (!is_object($cbResult['form'])) {
             foreach ($this->savedata as $data) {
                 if ($data[_FF_DATA_TYPE] == 'File Upload') {
                     if (!isset($_savedata[$data[_FF_DATA_ID]])) {
                         $_savedata[$data[_FF_DATA_ID]] = '';
                     }
                     $_savedata[$data[_FF_DATA_ID]] .= $data[_FF_DATA_VALUE] . "\n";
                 }
             }
         }
         $isset = array();
         foreach ($this->savedata as $data) {
             // CONTENTBUILDER WILL TAKE OVER SAVING/UPDATE IF EXISTS
             if (!is_object($cbResult['form'])) {
                 $subrecord->id = NULL;
                 $subrecord->element = $data[_FF_DATA_ID];
                 $subrecord->name = $data[_FF_DATA_NAME];
                 $subrecord->title = $data[_FF_DATA_TITLE];
                 $subrecord->type = $data[_FF_DATA_TYPE];
                 if (isset($_savedata[$data[_FF_DATA_ID]]) && !isset($isset[$data[_FF_DATA_ID]])) {
                     $subrecord->value = trim($_savedata[$data[_FF_DATA_ID]]);
                 } else {
                     $subrecord->value = $data[_FF_DATA_VALUE];
                 }
                 if (!isset($isset[$data[_FF_DATA_ID]])) {
                     if (!$subrecord->store()) {
                         $this->status = _FF_STATUS_SAVESUBRECORD_FAILED;
                         $this->message = $subrecord->getError();
                         return;
                     }
                 }
                 if ($data[_FF_DATA_TYPE] == 'File Upload') {
                     $isset[$data[_FF_DATA_ID]] = true;
                 }
             } else {
                 require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
                 $cbNonEditableFields = contentbuilder::getListNonEditableElements($cbResult['data']['id']);
                 if (!in_array($data[_FF_DATA_ID], $cbNonEditableFields)) {
                     switch ($data[_FF_DATA_TYPE]) {
                         case 'Checkbox':
                         case 'Checkbox Group':
                         case 'Radio Button':
                         case 'Radio Group':
                         case 'Select List':
                             if (!isset($cbData[$data[_FF_DATA_ID]])) {
                                 $cbData[$data[_FF_DATA_ID]] = array();
                             }
                             $cbData[$data[_FF_DATA_ID]][] = $data[_FF_DATA_VALUE];
                             break;
                         case 'File Upload':
                             if (!isset($cbData[$data[_FF_DATA_ID]])) {
                                 $cbData[$data[_FF_DATA_ID]] = '';
                                 $cbFileFields[] = $data[_FF_DATA_ID];
                             }
                             $cbData[$data[_FF_DATA_ID]] .= $data[_FF_DATA_VALUE] . "\n";
                             break;
                         default:
                             $cbData[$data[_FF_DATA_ID]] = $data[_FF_DATA_VALUE];
                     }
                 }
             }
         }
         // foreach
         // CONTENTBUILDER BEGIN
         if (is_object($cbResult['form'])) {
             JPluginHelper::importPlugin('contentbuilder_submit');
             $submit_dispatcher = JDispatcher::getInstance();
             jimport('joomla.version');
             $version = new JVersion();
             $is15 = true;
             if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                 $is15 = false;
             }
             $values = array();
             $names = $cbResult['form']->getAllElements();
             foreach ($names as $id => $name) {
                 if (isset($cbData[$id])) {
                     if (in_array($id, $cbFileFields) && trim($cbData[$id]) == '') {
                         $values[$id] = '';
                     } else {
                         if (in_array($id, $cbFileFields) && trim($cbData[$id]) != '') {
                             $values[$id] = trim($cbData[$id]);
                         } else {
                             $values[$id] = $cbData[$id];
                         }
                     }
                 }
             }
             $submit_before_result = $submit_dispatcher->trigger('onBeforeSubmit', array(JRequest::getInt('cb_record_id', 0), $cbResult['form'], $values));
             $record_return = $cbResult['form']->saveRecord(JRequest::getInt('cb_record_id', 0), $values);
             $db = JFactory::getDBO();
             $db->setQuery('Select SQL_CALC_FOUND_ROWS * From #__contentbuilder_forms Where id = ' . JRequest::getInt('cb_form_id', 0) . ' And published = 1');
             $cbData = $db->loadObject();
             if ($record_return) {
                 $this->record_id = $record_return;
                 $sef = '';
                 $ignore_lang_code = '*';
                 if ($cbResult['data']['default_lang_code_ignore']) {
                     jimport('joomla.version');
                     $version = new JVersion();
                     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                         $db->setQuery("Select lang_code From #__languages Where published = 1 And sef = " . $db->Quote(trim(JRequest::getCmd('lang', ''))));
                         $ignore_lang_code = $db->loadResult();
                         if (!$ignore_lang_code) {
                             $ignore_lang_code = '*';
                         }
                     } else {
                         $codes = contentbuilder::getLanguageCodes();
                         foreach ($codes as $code) {
                             if (strstr(strtolower($code), strtolower(trim(JRequest::getCmd('lang', '')))) !== false) {
                                 $ignore_lang_code = strtolower($code);
                                 break;
                             }
                         }
                     }
                     $sef = trim(JRequest::getCmd('lang', ''));
                     if ($ignore_lang_code == '*') {
                         $sef = '';
                     }
                 } else {
                     jimport('joomla.version');
                     $version = new JVersion();
                     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                         $db->setQuery("Select sef From #__languages Where published = 1 And lang_code = " . $db->Quote($cbResult['data']['default_lang_code']));
                         $sef = $db->loadResult();
                     } else {
                         $codes = contentbuilder::getLanguageCodes();
                         foreach ($codes as $code) {
                             if ($code == $cbResult['data']['default_lang_code']) {
                                 $sef = explode('-', $code);
                                 if (count($sef)) {
                                     $sef = strtolower($sef[0]);
                                 }
                                 break;
                             }
                         }
                     }
                 }
                 $language = $cbResult['data']['default_lang_code_ignore'] ? $ignore_lang_code : $cbResult['data']['default_lang_code'];
                 $db->setQuery("Select id From #__contentbuilder_records Where `type` = 'com_breezingforms' And `reference_id` = " . $db->Quote($cbResult['form']->getReferenceId()) . " And record_id = " . $db->Quote($record_return));
                 $res = $db->loadResult();
                 $last_update = JFactory::getDate();
                 $version = new JVersion();
                 $is3 = false;
                 if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                     $is3 = true;
                 }
                 $last_update = $is3 ? $last_update->toSql() : $last_update->toMySQL();
                 if (!$res) {
                     $is_future = 0;
                     $created_up = JFactory::getDate();
                     $created_up = $is3 ? $created_up->toSql() : $created_up->toMySQL();
                     if (intval($cbData->default_publish_up_days) != 0) {
                         $is_future = 1;
                         $date = JFactory::getDate(strtotime('now +' . intval($cbData->default_publish_up_days) . ' days'));
                         $created_up = $is3 ? $date->toSql() : $date->toMySQL();
                     }
                     $created_down = '0000-00-00 00:00:00';
                     if (intval($cbData->default_publish_down_days) != 0) {
                         $date = JFactory::getDate(strtotime($created_up . ' +' . intval($cbData->default_publish_down_days) . ' days'));
                         $created_down = $is3 ? $date->toSql() : $date->toMySQL();
                     }
                     $db->setQuery("Insert Into #__contentbuilder_records (session_id,`type`,last_update,is_future,lang_code, sef, published, record_id, reference_id, publish_up, publish_down) Values ('" . JFactory::getSession()->getId() . "','com_breezingforms'," . $db->Quote($last_update) . ",{$is_future}, " . $db->Quote($language) . "," . $db->Quote(trim($sef)) . "," . $db->Quote($cbData->auto_publish && !$is_future ? 1 : 0) . ", " . $db->Quote($record_return) . ", " . $db->Quote($cbResult['form']->getReferenceId()) . ", " . $db->Quote($created_up) . ", " . $db->Quote($created_down) . ")");
                     $db->query();
                 } else {
                     $db->setQuery("Update #__contentbuilder_records Set last_update = " . $db->Quote($last_update) . ",lang_code = " . $db->Quote($language) . ", sef = " . $db->Quote(trim($sef)) . ", edited = edited + 1 Where `type` = 'com_breezingforms' And `reference_id` = " . $db->Quote($cbResult['form']->getReferenceId()) . " And record_id = " . $db->Quote($record_return));
                     $db->query();
                 }
             }
             $article_id = 0;
             // creating the article
             if (is_object($cbData) && $cbData->create_articles) {
                 JRequest::setVar('cb_category_id', null);
                 JRequest::setVar('cb_controller', null);
                 jimport('joomla.version');
                 $version = new JVersion();
                 if (JFactory::getApplication()->isSite() && JRequest::getInt('Itemid', 0)) {
                     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                         $menu = JSite::getMenu();
                         $item = $menu->getActive();
                         if (is_object($item)) {
                             JRequest::setVar('cb_category_id', $item->params->get('cb_category_id', null));
                             JRequest::setVar('cb_controller', $item->params->get('cb_controller', null));
                         }
                     } else {
                         $params = JComponentHelper::getParams('com_contentbuilder');
                         JRequest::setVar('cb_category_id', $params->get('cb_category_id', null));
                         JRequest::setVar('cb_controller', $params->get('cb_controller', null));
                     }
                 }
                 $cbData->page_title = $cbData->use_view_name_as_title ? $cbData->name : $cbResult['form']->getPageTitle();
                 $cbData->labels = $cbResult['form']->getElementLabels();
                 $ids = array();
                 foreach ($cbData->labels as $reference_id => $label) {
                     $ids[] = $db->Quote($reference_id);
                 }
                 $cbData->labels = array();
                 if (count($ids)) {
                     $db->setQuery("Select Distinct `label`, reference_id From #__contentbuilder_elements Where form_id = " . JRequest::getInt('cb_form_id', 0) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 Order By ordering");
                     $rows = $db->loadAssocList();
                     $ids = array();
                     foreach ($rows as $row) {
                         $ids[] = $row['reference_id'];
                     }
                 }
                 $cbData->items = $cbResult['form']->getRecord($record_return, $cbData->published_only, $cbResult['frontend'] ? $cbData->own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($cbData->own_only ? JFactory::getUser()->get('id', 0) : -1), true);
                 if (!count($cbData->items)) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
                 }
                 $config = array();
                 $full = false;
                 $article_id = contentbuilder::createArticle(JRequest::getInt('cb_form_id', 0), $record_return, $cbData->items, $ids, $cbData->title_field, $cbResult['form']->getRecordMetadata($record_return), $config, $full, true, JRequest::getVar('cb_category_id', null));
                 $cache = JFactory::getCache('com_content');
                 $cache->clean();
                 $cache = JFactory::getCache('com_contentbuilder');
                 $cache->clean();
             }
             $submit_after_result = $submit_dispatcher->trigger('onAfterSubmit', array($record_return, $article_id, $cbResult['form'], $values));
         }
         // CONTENTBUILDER END
         // joomla 3 tagging
         $db = JFactory::getDBO();
         jimport('joomla.version');
         $version = new JVersion();
         if (version_compare($version->getShortVersion(), '3.1', '>=') && $this->formrow->tags_content != '') {
             $title = '';
             $tags_body = '';
             if (trim($this->formrow->tags_content_template) == '') {
                 $lol = 0;
                 $tags_body = '<ul class="category list-striped list-condensed">' . "\n";
                 foreach ($this->savedata as $data) {
                     if ($data[_FF_DATA_ID] == $this->formrow->tags_content_template_default_element) {
                         $title = $data[_FF_DATA_VALUE];
                     }
                     if ($lol == 1) {
                         $lol = 0;
                     }
                     $tagvalue = '';
                     if (is_array($data[_FF_DATA_VALUE])) {
                         $tagvalue = implode(', ', $data[_FF_DATA_VALUE]);
                     } else {
                         $tagvalue = $data[_FF_DATA_VALUE];
                     }
                     $tagvalue = bf_cleanString($tagvalue);
                     $tags_body .= '<li class="cat-list-row' . $lol . '"><strong class="list-title">' . htmlentities($data[_FF_DATA_TITLE], ENT_QUOTES, 'UTF-8') . '</strong><div>' . htmlentities($tagvalue, ENT_QUOTES, 'UTF-8') . '</div></li>' . "\n";
                     $lol++;
                 }
                 $tags_body .= '</ul>' . "\n";
             } else {
                 $tags_body = $this->formrow->tags_content_template;
                 foreach ($this->savedata as $data) {
                     if ($data[_FF_DATA_ID] == $this->formrow->tags_content_template_default_element) {
                         $title = $data[_FF_DATA_VALUE];
                     }
                     $tagvalue = '';
                     if (is_array($data[_FF_DATA_VALUE])) {
                         $tagvalue = implode(', ', $data[_FF_DATA_VALUE]);
                     } else {
                         $tagvalue = $data[_FF_DATA_VALUE];
                     }
                     $tagvalue = bf_cleanString($tagvalue);
                     $tags_body = str_replace('{' . $data[_FF_DATA_NAME] . ':label}', htmlentities($data[_FF_DATA_TITLE], ENT_QUOTES, 'UTF-8'), $tags_body);
                     $tags_body = str_replace('{' . $data[_FF_DATA_NAME] . ':value}', htmlentities($tagvalue, ENT_QUOTES, 'UTF-8'), $tags_body);
                 }
                 $matches = array();
                 preg_match_all("/\\{BFImageScale([^}]*)\\}/i", $tags_body, $matches);
                 if (isset($matches[0]) && isset($matches[1]) && is_array($matches[1]) && count($matches[1]) > 0) {
                     $i = 0;
                     foreach ($matches[1] as $match) {
                         $options = explode(';', trim($match));
                         $options_length = count($options);
                         for ($x = 0; $x < $options_length; $x++) {
                             $options[$x] = trim($options[$x]);
                             if ($options[$x] == '') {
                                 unset($options[$x]);
                             }
                         }
                         $options[] = 'record-id: ' . $this->record_id;
                         $options[] = 'form-id: ' . $this->form;
                         $out = implode('; ', $options);
                         $tags_body = str_replace($matches[0][$i], '{BFImageScale ' . $out . '}', $tags_body);
                         $i++;
                     }
                 }
                 $matches = array();
                 preg_match_all("/\\{BFDownload([^}]*)\\}/i", $tags_body, $matches);
                 if (isset($matches[0]) && isset($matches[1]) && is_array($matches[1]) && count($matches[1]) > 0) {
                     $i = 0;
                     foreach ($matches[1] as $match) {
                         $options = explode(';', trim($match));
                         $options_length = count($options);
                         for ($x = 0; $x < $options_length; $x++) {
                             $options[$x] = trim($options[$x]);
                             if ($options[$x] == '') {
                                 unset($options[$x]);
                             }
                         }
                         $options[] = 'record-id: ' . $this->record_id;
                         $options[] = 'form-id: ' . $this->form;
                         $out = implode('; ', $options);
                         $tags_body = str_replace($matches[0][$i], '{BFDownload ' . $out . '}', $tags_body);
                         $i++;
                     }
                 }
             }
             if (trim($title) == '' && isset($this->savedata[0])) {
                 $title = $this->savedata[0][_FF_DATA_TITLE];
             } else {
                 if (trim($title) == '' && !isset($this->savedata[0])) {
                     $title = 'Unknown';
                 }
             }
             $tag_date = JFactory::getDate();
             // Clean text for xhtml transitional compliance
             $introtext = '';
             $fulltext = '';
             $tags_body = str_replace('<br>', '<br />', $tags_body);
             // Search for the {readmore} tag and split the text up accordingly.
             $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i';
             $tagPos = preg_match($pattern, $tags_body);
             if ($tagPos == 0) {
                 $introtext = $tags_body;
             } else {
                 list($introtext, $fulltext) = preg_split($pattern, $tags_body, 2);
             }
             $db->setQuery("Insert Into \n                    #__content \n                        (\n                         `title`,\n                         `alias`,\n                         `introtext`,\n                         `fulltext`,\n                         `state`,\n                         `catid`,\n                         `created`,\n                         `created_by`,\n                         `modified`,\n                         `modified_by`,\n                         `checked_out`,\n                         `checked_out_time`,\n                         `publish_up`,\n                         `publish_down`,\n                         `attribs`,\n                         `version`,\n                         `metakey`,\n                         `metadesc`,\n                         `metadata`,\n                         `access`,\n                         `created_by_alias`,\n                         `language`,\n                         `featured`\n                        ) \n                    Values \n                        (\n                          " . $db->quote($title) . ",\n                          " . $db->quote(bf_stringURLUnicodeSlug($item_id . '-' . $title)) . ",\n                          " . $db->quote($introtext) . ",\n                          " . $db->quote($fulltext) . ",\n                          " . intval($this->formrow->tags_content_default_state) . ",\n                          " . intval($this->formrow->tags_content_default_category) . ",\n                          '" . $tag_date->toSql() . "',\n                          " . $db->quote(JFactory::getUser()->get('id', 0)) . ",\n                          '" . $tag_date->toSql() . "',\n                          " . $db->quote(JFactory::getUser()->get('id', 0)) . ",\n                          '0',\n                          '0000-00-00 00:00:00',\n                          '" . ($this->formrow->tags_content_default_publishup == '' || $this->formrow->tags_content_default_publishup == '0000-00-00 00:00:00' ? $tag_date->toSql() : $this->formrow->tags_content_default_publishup) . "',\n                          '" . ($this->formrow->tags_content_default_publishdown == '' || $this->formrow->tags_content_default_publishdown == '0000-00-00 00:00:00' ? '0000-00-00 00:00:00' : $this->formrow->tags_content_default_publishdown) . "',\n                          '',\n                          '1',\n                          '',\n                          '',\n                          '',\n                          " . intval($this->formrow->tags_content_default_access) . ",\n                          " . $db->quote(JFactory::getUser()->get('username', 'Anonymous')) . ",\n                          " . $db->quote($this->formrow->tags_content_default_language) . ",\n                          " . intval($this->formrow->tags_content_default_featured) . "\n                       )\n                ");
             $db->query();
             $item_id = $db->insertid();
             JFactory::getDbo()->setQuery("Select type_id From #__content_types Where type_alias = 'com_content.article'");
             $tag_typeid = JFactory::getDbo()->loadResult();
             $db->setQuery("Insert Into #__ucm_content (\n                    core_catid,\n                    core_content_item_id,\n                    core_type_alias, \n                    core_title, \n                    core_alias, \n                    core_body, \n                    core_created_time,\n                    core_modified_time,\n                    core_created_user_id,\n                    core_created_by_alias,\n                    core_modified_user_id,\n                    core_state,\n                    core_access,\n                    core_language,\n                    core_type_id,\n                    core_featured,\n                    core_publish_up,\n                    core_publish_down\n                 ) Values (\n                    " . intval($this->formrow->tags_content_default_category) . ",\n                    '" . $item_id . "',\n                    'com_content.article',\n                    " . $db->quote($title) . ",\n                    " . $db->quote(bf_stringURLUnicodeSlug($title)) . ",\n                    " . $db->quote($tags_body) . ",\n                    '" . $tag_date->toSql() . "',\n                    '" . $tag_date->toSql() . "',\n                    " . $db->quote(JFactory::getUser()->get('id', 0)) . ",\n                    " . $db->quote(JFactory::getUser()->get('username', 'Anonymous')) . ",\n                    " . $db->quote(JFactory::getUser()->get('id', 0)) . ",\n                    " . intval($this->formrow->tags_content_default_state) . ",\n                    " . intval($this->formrow->tags_content_default_access) . ",\n                    " . $db->quote($this->formrow->tags_content_default_language) . ",\n                    " . intval($tag_typeid) . ",\n                    " . intval($this->formrow->tags_content_default_featured) . ",\n                    '" . ($this->formrow->tags_content_default_publishup == '' || $this->formrow->tags_content_default_publishup == '0000-00-00 00:00:00' ? $tag_date->toSql() : $this->formrow->tags_content_default_publishup) . "',\n                    '" . ($this->formrow->tags_content_default_publishdown == '' || $this->formrow->tags_content_default_publishdown == '0000-00-00 00:00:00' ? '0000-00-00 00:00:00' : $this->formrow->tags_content_default_publishdown) . "'\n                 )");
             $db->query();
             $ucm_id = $db->insertid();
             JFactory::getDbo()->setQuery("Select lang_id From #__languages Where lang_code=" . $db->quote($this->formrow->tags_content_default_language));
             $lang_id = JFactory::getDbo()->loadColumn();
             JFactory::getDbo()->setQuery("Insert Into #__ucm_base (\n                    ucm_id, \n                    ucm_item_id, \n                    ucm_type_id, \n                    ucm_language_id\n                 ) Values (\n                    " . $ucm_id . ",\n                    " . $item_id . ",\n                    " . intval($tag_typeid) . ",\n                    " . ($lang_id ? intval($lang_id) : 0) . "\n                 )");
             JFactory::getDbo()->query();
             $tags_content = explode(',', $this->formrow->tags_content);
             JArrayHelper::toInteger($tags_content);
             foreach ($tags_content as $tags_content_entry) {
                 JFactory::getDbo()->setQuery("Insert Into #__contentitem_tag_map (\n                        type_alias, \n                        core_content_id, \n                        content_item_id, \n                        tag_id, \n                        tag_date, \n                        type_id\n                     ) Values (\n                        'com_content.article',\n                        " . $ucm_id . ",\n                        " . $item_id . ",\n                        " . $tags_content_entry . ",\n                        '" . $tag_date->toSql() . "',\n                        " . $tag_typeid . "\n                     )");
                 try {
                     JFactory::getDbo()->query();
                 } catch (Exception $e) {
                 }
             }
         }
         // joomla 3 tagging end
     }
     require_once JPATH_SITE . '/administrator/components/com_breezingforms/libraries/crosstec/classes/BFIntegrate.php';
     $integrate = new BFIntegrate($this->form);
     if (count($this->savedata)) {
         foreach ($this->savedata as $data) {
             $integrate->field($data);
         }
     }
     $integrate->commit();
     if (isset($record_return)) {
         return $record_return;
     }
 }
Example #2
0
 static function save($option, $pkg, $caller, $nonclassic, $quickmode)
 {
     global $database;
     $database = JFactory::getDBO();
     $row = new facileFormsForms($database);
     // TAGGING
     if (isset($_POST['tags_content_default_publishup'])) {
         if ($_POST['tags_content_default_publishup'] == '') {
             $_POST['tags_content_default_publishup'] = '0000-00-00 00:00:00';
         } else {
             $_POST['tags_content_default_publishup'] = date('Y-m-d H:i:s', strtotime($_POST['tags_content_default_publishup']));
         }
     }
     if (isset($_POST['tags_content_default_publishdown'])) {
         if ($_POST['tags_content_default_publishdown'] == '') {
             $_POST['tags_content_default_publishdown'] = '0000-00-00 00:00:00';
         } else {
             $_POST['tags_content_default_publishdown'] = date('Y-m-d H:i:s', strtotime($_POST['tags_content_default_publishdown']));
         }
     }
     $tags_form_array = array();
     if (isset($_POST['tags_form']) && is_array($_POST['tags_form'])) {
         $tags_form_array = $_POST['tags_form'];
         JArrayHelper::toInteger($tags_form_array);
         $tags_form = '';
         foreach ($_POST['tags_form'] as $tag_form) {
             $tags_form .= intval($tag_form) . ',';
         }
         $tags_form = rtrim($tags_form, ',');
         $_POST['tags_form'] = $tags_form;
     } else {
         $_POST['tags_form'] = '';
     }
     if (isset($_POST['tags_content']) && is_array($_POST['tags_content'])) {
         $tags_form = '';
         foreach ($_POST['tags_content'] as $tag_form) {
             $tags_form .= intval($tag_form) . ',';
         }
         $tags_form = rtrim($tags_form, ',');
         $_POST['tags_content'] = $tags_form;
     } else {
         $_POST['tags_content'] = '';
     }
     // TAGGING END
     if (isset($_POST['salesforce_fields']) && is_array($_POST['salesforce_fields'])) {
         $i = 0;
         foreach ($_POST['salesforce_fields'] as $sfield) {
             if ($sfield == '') {
                 unset($_POST['salesforce_fields'][$i]);
             }
             $i++;
         }
         $_POST['salesforce_fields'] = implode(',', $_POST['salesforce_fields']);
     }
     if (!isset($_POST['salesforce_enabled'])) {
         $_POST['salesforce_enabled'] = 0;
     }
     if (isset($_POST['dropbox_submission_types']) && is_array($_POST['dropbox_submission_types'])) {
         $_POST['dropbox_submission_types'] = implode(',', $_POST['dropbox_submission_types']);
     } else {
         $_POST['dropbox_submission_types'] = '';
     }
     // bind it to the table
     if (!$row->bind($_POST)) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     // if
     // store it in the db
     if (!$row->store()) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     // if
     // TAGGING
     jimport('joomla.version');
     $version = new JVersion();
     if (version_compare($version->getShortVersion(), '3.1', '>=')) {
         $insert = $database->insertid();
         $tag_date = JFactory::getDate();
         $plugin_call = '<div style="display:none;">BFTAGGED</div>{BreezingForms: ' . $_POST['tags_form_oldname'] . ',,0}';
         $plugin_call_new = '<div style="display:none;">BFTAGGED</div>{BreezingForms: ' . $_POST['name'] . ',,0}';
         if ($_POST['tags_form'] != '') {
             $ucm_created = '0000-00-00 00:00:00';
             $database->setQuery("Select core_content_id From  #__ucm_content Where core_body = " . $database->quote($plugin_call));
             $ucm_id = $database->loadResult();
             if ($ucm_id) {
                 $database->setQuery("Select core_created_time From  #__ucm_content Where core_body = " . $database->quote($plugin_call));
                 $ucm_created = $database->loadResult();
                 $database->setQuery("Delete From #__ucm_base Where ucm_id = " . $database->quote($ucm_id));
                 $database->query();
                 $database->setQuery("Delete From #__contentitem_tag_map Where core_content_id = " . $database->quote($ucm_id));
                 $database->query();
             }
             $database->setQuery("Delete From #__ucm_content Where core_body = " . $database->quote($plugin_call));
             $database->query();
             $database->setQuery("Insert Into #__ucm_content (\n                            core_type_alias, \n                            core_title, \n                            core_alias, \n                            core_body, \n                            core_created_time,\n                            core_modified_time,\n                            core_publish_up,\n                            core_state\n                         ) Values (\n                            'com_breezingforms.form',\n                            " . $database->quote($_POST['title']) . ",\n                            " . $database->quote(bf_stringURLUnicodeSlug($_POST['title'])) . ",\n                            " . $database->quote($plugin_call_new) . ",\n                            " . (!$ucm_id ? "'" . $tag_date->toSql() . "'," : "'" . $ucm_created . "',") . "\n                            '" . $tag_date->toSql() . "',\n                            " . (!$ucm_id ? "'" . $tag_date->toSql() . "'," : "'" . $ucm_created . "',") . "\n                            1\n                         )");
             $database->query();
             $ucm_id = JFactory::getDbo()->insertid();
             JFactory::getDbo()->setQuery("Select type_id From #__content_types Where type_alias = 'com_breezingforms.form'");
             $tag_typeid = JFactory::getDbo()->loadResult();
             JFactory::getDbo()->setQuery("Insert Into #__ucm_base (\n                            ucm_id, \n                            ucm_item_id, \n                            ucm_type_id, \n                            ucm_language_id\n                         ) Values (\n                            " . $ucm_id . ",\n                            " . (JRequest::getInt('id', 0) == 0 ? $insert : JRequest::getInt('id', 0)) . ",\n                            " . $tag_typeid . ",\n                            0\n                         )");
             JFactory::getDbo()->query();
             foreach ($tags_form_array as $tags_form_array_entry) {
                 JFactory::getDbo()->setQuery("Insert Into #__contentitem_tag_map (\n                                type_alias, \n                                core_content_id, \n                                content_item_id, \n                                tag_id, \n                                tag_date, \n                                type_id\n                             ) Values (\n                                'com_breezingforms.form',\n                                " . $ucm_id . ",\n                                " . (JRequest::getInt('id', 0) == 0 ? $insert : JRequest::getInt('id', 0)) . ",\n                                " . $tags_form_array_entry . ",\n                                '" . $tag_date->toSql() . "',\n                                " . $tag_typeid . "\n                             )");
                 try {
                     JFactory::getDbo()->query();
                 } catch (Exception $e) {
                 }
             }
         } else {
             if ($_POST['tags_form'] == '') {
                 $database->setQuery("Select core_content_id From  #__ucm_content Where core_body = " . $database->quote($plugin_call));
                 $ucm_id = $database->loadResult();
                 $database->setQuery("Delete From #__ucm_base Where ucm_id = " . $database->quote($ucm_id));
                 $database->query();
                 $database->setQuery("Delete From #__contentitem_tag_map Where core_content_id = " . $database->quote($ucm_id));
                 $database->query();
                 $database->setQuery("Delete From #__ucm_content Where core_body = " . $database->quote($plugin_call));
                 $database->query();
             }
         }
     }
     // TAGGING END
     $row->reorder("");
     JPluginHelper::importPlugin('breezingforms_addons');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onPropertiesSave', array(JRequest::getInt('id', 0)));
     if (trim($caller) == '') {
         $caller = "index.php?option={$option}&act=manageforms&pkg={$pkg}";
         JFactory::getApplication()->redirect($caller);
     }
     JFactory::getApplication()->redirect('index.php?option=com_breezingforms&task=editform&act=editpage&form=' . intval($_POST['id']) . ($quickmode ? '&pkg=QuickModeForms' : ''));
 }