diff --git a/admin_language/en-GB/en-GB.com_tjfields.ini b/admin_language/en-GB/en-GB.com_tjfields.ini index e5c071ce..8820d0e6 100755 --- a/admin_language/en-GB/en-GB.com_tjfields.ini +++ b/admin_language/en-GB/en-GB.com_tjfields.ini @@ -135,7 +135,7 @@ COM_TJFIELDS_FORM_DESC_EDITOR_WIDTH="Set width" COM_TJFIELDS_FORM_LBL_EDITOR_HEIGHT="Height" COM_TJFIELDS_FORM_DESC_EDITOR_HEIGHT="Set height" COM_TJFIELDS_FORM_LBL_FIELD_SIZE="Size" -COM_TJFIELDS_FORM_DESC_FIELD_SIZE="Set maximum allowed file size (In MB) e.g 10, 20" +COM_TJFIELDS_FORM_DESC_FIELD_SIZE="Set size" COM_TJFIELDS_FORM_LBL_FIELD_MAXLENGTH="Max Length" COM_TJFIELDS_FORM_LBL_FIELD_MIN="Min Value" COM_TJFIELDS_FORM_DESC_FIELD_MIN="Min Value" diff --git a/administrator/assets/js/field.js b/administrator/assets/js/field.js index 3751412a..2b6383a4 100755 --- a/administrator/assets/js/field.js +++ b/administrator/assets/js/field.js @@ -92,21 +92,8 @@ techjoomla.jQuery( document ).ready(function(){ // show the default path for file upload & attach the folder name with respect to name entered for file field if (field_type == 'file') { - // folder name should contain only alpahnumeric characters & also remove the underscores and spaces - if(field_id==0) + if(field_id != 0) { - techjoomla.jQuery('#jform_params_uploadpath').val(fileUploadDefaultPath+client+"/"); - techjoomla.jQuery("#jform_name").keyup(function(){ - techjoomla.jQuery('#jform_params_uploadpath').val(fileUploadDefaultPath+client+"_"+clientType+"_"+techjoomla.jQuery("#jform_name").val().replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '')+"/"); - }); - } - else - { - if (techjoomla.jQuery('#jform_params_uploadpath').val()=="") - { - techjoomla.jQuery('#jform_params_uploadpath').val(fileUploadDefaultPath+client+"/"+clientType+"/"); - } - // Show current file upload path & notice to admin user in case if he is going to custmozie the file upload path techjoomla.jQuery('#currentUploadPath').html(techjoomla.jQuery('#jform_params_uploadpath').val()); var fileUploadhtml = techjoomla.jQuery('.fileUploadAlert').html(); diff --git a/administrator/controllers/group.php b/administrator/controllers/group.php index 6807b961..6c3937f2 100755 --- a/administrator/controllers/group.php +++ b/administrator/controllers/group.php @@ -116,7 +116,7 @@ public function newsave() { $msg = JText::_('COMTJFILEDS_GROUP_CREATED_SUCCESSFULLY'); $link = JRoute::_('index.php?option=com_tjfields&view=group&layout=edit&client=' . $input->get('client', '', 'STRING'), false); - $this->setRedirect($link, $msg, 'error'); + $this->setRedirect($link, $msg, 'success'); } else { diff --git a/administrator/houseKeeping/1.5.0/fieldDefaultValue.php b/administrator/houseKeeping/1.5.0/fieldDefaultValue.php index 4813d87f..696e8d36 100644 --- a/administrator/houseKeeping/1.5.0/fieldDefaultValue.php +++ b/administrator/houseKeeping/1.5.0/fieldDefaultValue.php @@ -32,48 +32,65 @@ class TjHouseKeepingFieldDefaultValue extends TjModelHouseKeeping */ public function migrate() { - $db = JFactory::getDbo(); - JLoader::import('components.com_tjfields.tables.option', JPATH_ADMINISTRATOR); - $optionTable = Table::getInstance('Option', 'TjfieldsTable', array('dbo', $db)); - $optionTableColumns = $optionTable->getFields(); + $result = array(); - // No migration needed if the default_option column is already removed - if (!array_key_exists('default_option', $optionTableColumns)) + try { - return true; - } + $db = JFactory::getDbo(); + JLoader::import('components.com_tjfields.tables.option', JPATH_ADMINISTRATOR); + $optionTable = Table::getInstance('Option', 'TjfieldsTable', array('dbo', $db)); + $optionTableColumns = $optionTable->getFields(); - $query = $db->getQuery(true); - $query->select('*'); - $query->from($db->quoteName('#__tjfields_options')); - $query->where($db->quoteName('default_option') . '=1'); - $db->setQuery($query); - $fieldOptions = $db->loadObjectList(); + // No migration needed if the default_option column is already removed + if (!array_key_exists('default_option', $optionTableColumns)) + { + $result['status'] = true; + $result['message'] = "Migration successful"; - if (!empty($fieldOptions)) - { - JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR); - $fieldTable = JTable::getInstance('Field', 'TjfieldsTable', array('dbo', $db)); + return $result; + } + + $query = $db->getQuery(true); + $query->select('*'); + $query->from($db->quoteName('#__tjfields_options')); + $query->where($db->quoteName('default_option') . '=1'); + $db->setQuery($query); + $fieldOptions = $db->loadObjectList(); - foreach ($fieldOptions as $fieldOption) + if (!empty($fieldOptions)) { - if (!empty($fieldOption->default_option)) + JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR); + $fieldTable = JTable::getInstance('Field', 'TjfieldsTable', array('dbo', $db)); + + foreach ($fieldOptions as $fieldOption) { - $fieldTable->load($fieldOption->field_id); - $fieldParams = json_decode($fieldTable->params); - $fieldParams->default = $fieldOption->value; - $fieldTable->params = json_encode($fieldParams); - $fieldTable->store(); + if (!empty($fieldOption->default_option)) + { + $fieldTable->load($fieldOption->field_id); + $fieldParams = json_decode($fieldTable->params); + $fieldParams->default = $fieldOption->value; + $fieldTable->params = json_encode($fieldParams); + $fieldTable->store(); + } } } - } - // Drop 'default_option' column from options table - $query = $db->getQuery(true); - $query = "ALTER TABLE `#__tjfields_options` DROP `default_option`"; - $db->setQuery($query); - $db->execute(); + // Drop 'default_option' column from options table + $query = $db->getQuery(true); + $query = "ALTER TABLE `#__tjfields_options` DROP `default_option`"; + $db->setQuery($query); + $db->execute(); + + $result['status'] = true; + $result['message'] = "Migration successful"; + } + catch (Exception $e) + { + $result['err_code'] = ''; + $result['status'] = false; + $result['message'] = $e->getMessage(); + } - return true; + return $result; } } diff --git a/administrator/models/field.php b/administrator/models/field.php index 8d202757..28f0c2ab 100755 --- a/administrator/models/field.php +++ b/administrator/models/field.php @@ -84,7 +84,7 @@ public function getForm($data = array(), $loadData = true) } } - if ($form->getValue('type') == 'ucmsubform') + if ($form->getValue('type') == 'ucmsubform' || $form->getValue('type') == 'subform') { $form->setValue('showonlist', null, 0); $form->removeField('showonlist'); @@ -796,4 +796,25 @@ public function delete(&$pks) return true; } + + /** + * Method to get JForm for subform field. + * + * @param STRING $name name of the form + * @param STRING $formSource form source path + * @param OBJECT $loadData data to be loaded + * + * @return mixed JForm object if successful, false if an error occurs. + * + * @since 1.4.3 + */ + public function getSubFormFieldForm($name, $formSource, $loadData = array()) + { + if (empty($name) || empty($formSource) || !JFile::exists($formSource)) + { + return false; + } + + return $this->loadForm($name, $formSource, array('control' => 'jform','load_data' => $loadData)); + } } diff --git a/administrator/models/fields.php b/administrator/models/fields.php index f257a822..519d9007 100755 --- a/administrator/models/fields.php +++ b/administrator/models/fields.php @@ -184,7 +184,7 @@ protected function getListQuery() else { $search = $db->Quote('%' . $db->escape($search, true) . '%'); - $query->where('( a.type LIKE ' . $search . ' )'); + $query->where('( a.label LIKE ' . $search . ' )'); } } diff --git a/administrator/models/fields/file.php b/administrator/models/fields/file.php index 6a3d4374..7467915f 100644 --- a/administrator/models/fields/file.php +++ b/administrator/models/fields/file.php @@ -234,16 +234,6 @@ protected function buildData($layoutData) $data->fields_value_table = JTable::getInstance('Fieldsvalue', 'TjfieldsTable'); $data->fields_value_table->load(array('value' => $layoutData['value'])); - if ($data->isSubformField) - { - // Getting field value of subform file field using the content_id from url and subform_id which will be the field id - $data->fields_value_table->load(array('content_id' => $formValueId, 'field_id' => $data->subformId)); - } - else - { - $data->fields_value_table->load(array('value' => $layoutData['value'])); - } - $extraParamArray = array(); $extraParamArray['id'] = $data->fields_value_table->id; diff --git a/administrator/models/fields/fileuploadpath.php b/administrator/models/fields/fileuploadpath.php new file mode 100644 index 00000000..4c495f63 --- /dev/null +++ b/administrator/models/fields/fileuploadpath.php @@ -0,0 +1,54 @@ + + * @package TJFields + * @author Techjoomla + * @copyright Copyright (c) 2009-2019 TechJoomla. All rights reserved + * @license GNU General Public License version 2, or later + */ + +defined('JPATH_PLATFORM') or die; + +JFormHelper::loadFieldClass('textarea'); + +/** + * Form Field Textareacounter class + * Supports a multi line area for entry of plain text with count char + * + * @since 11.1 + */ +class JFormFieldFileUploadPath extends JFormFieldTextarea +{ + /** + * The form field type. + * + * @var string + * @since 11.1 + */ + protected $type = 'Fileuploadpath'; + + /** + * Method to get the textarea field input markup. + * Use the rows and columns attributes to specify the dimensions of the area. + * + * @return string The field input markup. + * + * @since 11.1 + */ + protected function getInput() + { + $layoutData = $this->getLayoutData(); + $client = $layoutData['field']->form->getData()->get('client'); + $client = str_replace('.', '_', $client); + + if (empty($this->value)) + { + $this->value = JPATH_SITE . '/media/' . $client . '/'; + $this->value = str_replace('/', DIRECTORY_SEPARATOR, $this->value); + } + + $html = parent::getInput(); + + return $html; + } +} diff --git a/administrator/models/fields/related.php b/administrator/models/fields/related.php index 46d13bc1..47e71d3c 100644 --- a/administrator/models/fields/related.php +++ b/administrator/models/fields/related.php @@ -39,7 +39,7 @@ class JFormFieldRelated extends JFormFieldList * * @since 3.7.0 */ - protected function getOptions() + public function getOptions() { // Load TJ-Fields language file $lang = Factory::getLanguage()->load('com_tjfields', JPATH_ADMINISTRATOR); diff --git a/administrator/models/fields/sql.php b/administrator/models/fields/sql.php new file mode 100644 index 00000000..0f0a413c --- /dev/null +++ b/administrator/models/fields/sql.php @@ -0,0 +1,320 @@ +$name; + } + + return parent::__get($name); + } + + /** + * Method to set certain otherwise inaccessible properties of the form field object. + * + * @param string $name The property name for which to set the value. + * @param mixed $value The value of the property. + * + * @return void + * + * @since 3.2 + */ + public function __set($name, $value) + { + switch ($name) + { + case 'keyField': + case 'valueField': + case 'translate': + case 'query': + $this->$name = (string) $value; + break; + + default: + parent::__set($name, $value); + } + } + + /** + * Method to attach a JForm object to the field. + * + * @param SimpleXMLElement $element The SimpleXMLElement object representing the `` tag for the form field object. + * @param mixed $value The form field value to validate. + * @param string $group The field name group control value. This acts as an array container for the field. + * For example if the field has name="foo" and the group value is set to "bar" then the + * full field name would end up being "bar[foo]". + * + * @return boolean True on success. + * + * @see JFormField::setup() + * @since 3.2 + */ + public function setup(SimpleXMLElement $element, $value, $group = null) + { + $return = parent::setup($element, $value, $group); + + if ($return) + { + // Check if its using the old way + $this->query = (string) $this->element['query']; + + if (empty($this->query)) + { + // Get the query from the form + $query = array(); + $defaults = array(); + + $sql_select = (string) $this->element['sql_select']; + $sql_from = (string) $this->element['sql_from']; + + if ($sql_select && $sql_from) + { + $query['select'] = $sql_select; + $query['from'] = $sql_from; + $query['join'] = (string) $this->element['sql_join']; + $query['where'] = (string) $this->element['sql_where']; + $query['group'] = (string) $this->element['sql_group']; + $query['order'] = (string) $this->element['sql_order']; + + // Get the filters + $filters = isset($this->element['sql_filter']) ? explode(',', $this->element['sql_filter']) : ''; + + // Get the default value for query if empty + if (is_array($filters)) + { + foreach ($filters as $filter) + { + $name = "sql_default_{$filter}"; + $attrib = (string) $this->element[$name]; + + if (!empty($attrib)) + { + $defaults[$filter] = $attrib; + } + } + } + + // Process the query + $this->query = $this->processQuery($query, $filters, $defaults); + } + } + + $this->keyField = (string) $this->element['key_field'] ?: 'value'; + $this->valueField = (string) $this->element['value_field'] ?: (string) $this->element['name']; + $this->translate = (string) $this->element['translate'] ?: false; + $this->header = (string) $this->element['header'] ?: false; + } + + return $return; + } + + /** + * Method to process the query from form. + * + * @param array $conditions The conditions from the form. + * @param string $filters The columns to filter. + * @param array $defaults The defaults value to set if condition is empty. + * + * @return JDatabaseQuery The query object. + * + * @since 3.5 + */ + protected function processQuery($conditions, $filters, $defaults) + { + // Get the database object. + $db = JFactory::getDbo(); + + // Get the query object + $query = $db->getQuery(true); + + // Select fields + $query->select($conditions['select']); + + // From selected table + $query->from($conditions['from']); + + // Join over the groups + if (!empty($conditions['join'])) + { + $query->join('LEFT', $conditions['join']); + } + + // Where condition + if (!empty($conditions['where'])) + { + $query->where($conditions['where']); + } + + // Group by + if (!empty($conditions['group'])) + { + $query->group($conditions['group']); + } + + // Process the filters + if (is_array($filters)) + { + $html_filters = JFactory::getApplication()->getUserStateFromRequest($this->context . '.filter', 'filter', array(), 'array'); + + foreach ($filters as $k => $value) + { + if (!empty($html_filters[$value])) + { + $escape = $db->quote($db->escape($html_filters[$value]), false); + + $query->where("{$value} = {$escape}"); + } + elseif (!empty($defaults[$value])) + { + $escape = $db->quote($db->escape($defaults[$value]), false); + + $query->where("{$value} = {$escape}"); + } + } + } + + // Add order to query + if (!empty($conditions['order'])) + { + $query->order($conditions['order']); + } + + return $query; + } + + /** + * Method to get the custom field options. + * Use the query attribute to supply a query to generate the list. + * + * @return array The field option objects. + * + * @since 1.7.0 + */ + public function getOptions() + { + $options = array(); + + // Initialize some field attributes. + $key = $this->keyField; + $value = $this->valueField; + $header = $this->header; + + if ($this->query) + { + // Get the database object. + $db = JFactory::getDbo(); + + // Set the query and get the result list. + $db->setQuery($this->query); + + try + { + $items = $db->loadObjectlist(); + } + catch (JDatabaseExceptionExecuting $e) + { + JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error'); + } + } + + // Add header. + if (!empty($header)) + { + $header_title = JText::_($header); + $options[] = JHtml::_('select.option', '', $header_title); + } + + // Build the field options. + if (!empty($items)) + { + foreach ($items as $item) + { + if ($this->translate == true) + { + $options[] = JHtml::_('select.option', $item->$key, JText::_($item->$value)); + } + else + { + $options[] = JHtml::_('select.option', $item->$key, $item->$value); + } + } + } + + // Merge any additional options in the XML definition. + $options = array_merge(parent::getOptions(), $options); + + return $options; + } +} diff --git a/administrator/models/forms/field.xml b/administrator/models/forms/field.xml index bf0de463..dda20010 100755 --- a/administrator/models/forms/field.xml +++ b/administrator/models/forms/field.xml @@ -2,88 +2,45 @@
- - - - - - - - - - - - - - - - - - - - - + - - - + + +
diff --git a/administrator/models/forms/types/forms/editor.xml b/administrator/models/forms/types/forms/editor.xml index 332f7541..24a3d6bf 100755 --- a/administrator/models/forms/types/forms/editor.xml +++ b/administrator/models/forms/types/forms/editor.xml @@ -23,6 +23,7 @@ + diff --git a/administrator/models/forms/types/forms/file.xml b/administrator/models/forms/types/forms/file.xml index f8fd0b26..20310525 100755 --- a/administrator/models/forms/types/forms/file.xml +++ b/administrator/models/forms/types/forms/file.xml @@ -2,7 +2,7 @@
- +
diff --git a/administrator/models/forms/types/forms/image.xml b/administrator/models/forms/types/forms/image.xml index f1b8fbbc..ba82239e 100644 --- a/administrator/models/forms/types/forms/image.xml +++ b/administrator/models/forms/types/forms/image.xml @@ -2,7 +2,7 @@
- + diff --git a/administrator/models/forms/types/forms/text.xml b/administrator/models/forms/types/forms/text.xml index c799805e..bc29b504 100755 --- a/administrator/models/forms/types/forms/text.xml +++ b/administrator/models/forms/types/forms/text.xml @@ -4,7 +4,7 @@
- +
diff --git a/administrator/views/field/tmpl/edit.php b/administrator/views/field/tmpl/edit.php index 2a7275a8..08541b55 100755 --- a/administrator/views/field/tmpl/edit.php +++ b/administrator/views/field/tmpl/edit.php @@ -33,17 +33,11 @@ // Call helper function TjfieldsHelper::getLanguageConstant(); -// Default path for file upload field -$fileUploadDefaultPath = JPATH_SITE."/media/"; - // Import CSS $document = JFactory::getDocument(); $document->addStyleSheet('components/com_tjfields/assets/css/tjfields.css'); ?>