field_type, static::$field_types) ) return; $field->label = JText::_($field->label); $use_ingroup = $field->parameters->get('use_ingroup', 0); if (!isset($field->formhidden_grp)) $field->formhidden_grp = $field->formhidden; if ($use_ingroup) $field->formhidden = 3; if ($use_ingroup && empty($field->ingroup)) return; $is_ingroup = 0; //!empty($field->ingroup); // initialize framework objects and other variables $document = JFactory::getDocument(); $cparams = JComponentHelper::getParams( 'com_flexicontent' ); $db = JFactory::getDBO(); $tooltip_class = 'hasTooltip'; $add_on_class = $cparams->get('bootstrap_ver', 2)==2 ? 'add-on' : 'input-group-addon'; $input_grp_class = $cparams->get('bootstrap_ver', 2)==2 ? 'input-append input-prepend' : 'input-group'; // Get a unique id to use as item id if current item is new $u_item_id = $item->id ? $item->id : substr(JFactory::getApplication()->input->get('unique_tmp_itemid', '', 'string'), 0, 1000); // **************** // Number of values // **************** $multiple = $use_ingroup || (int) $field->parameters->get( 'allow_multiple', 1 ) ; $max_values = $use_ingroup ? 0 : (int) $field->parameters->get( 'max_values', 0 ) ; $required = $field->parameters->get( 'required', 0 ) ; $required_class = $required ? ' required' : ''; $add_position = (int) $field->parameters->get( 'add_position', 0 ) ; $has_values = count($field->value); // Input field display size & max characters $display_label_form = (int) $field->parameters->get( 'display_label_form', 1 ) ; // CSS classes of value container $value_classes = 'fcfieldval_container valuebox fcfieldval_container_'.$field->id; // Field name and HTML TAG id $fieldname = 'custom['.$field->name.']'; $elementid = 'custom_'.$field->name; /* if ( !$field->item_id ) { $inventory_data = new stdClass(); $inventory_data->value = ''; $inventory_data->editable = 0; $inventory_data->access_group = 0; $inventory_data->datalist_id = ''; } else{ //inventory data $inventory_data = $this->getInventoryData($item->id,$field->id); }*/ // get all published flexicontent types $types_q = "SELECT id, name FROM #__flexicontent_types WHERE published=1 order by id asc"; $db->setQuery($types_q); $types_q = $db->loadObjectList(); $type_js = ""; foreach($types_q as $type){ $type_js .= ""; } $js = " jQuery(document).ready(function(){ var num=1; jQuery('#add').on('click',function(){ event.preventDefault(); jQuery('#add_subitem').append('
'); num = num+1; }); jQuery(document).on('change','.selectType',function(){ var divId = jQuery(this).parent().attr('id'); var subItemName = jQuery('#'+divId).find('#subItemName'+divId).val(); var subItemType = jQuery(this).val(); if(subItemName != '' && subItemType != 0){ jQuery('#btn'+divId).prop('disabled', false); jQuery('#btn'+divId).addClass('btn-success'); } else{ jQuery('#btn'+divId).prop('disabled', true); jQuery('#btn'+divId).removeClass('btn-success'); } // console.log(divId); // console.log(subItemName); // console.log(subItemType); }); jQuery(document).on('change','.nameText',function(){ var divId = jQuery(this).parent().attr('id'); var subItemName = jQuery(this).val(); var subItemType = jQuery('#'+divId).find('#subItemType'+divId).val(); if(subItemName != '' && subItemType > 0){ jQuery('#btn'+divId).prop('disabled', false); jQuery('#btn'+divId).addClass('btn-success'); } else{ jQuery('#btn'+divId).prop('disabled', true); jQuery('#btn'+divId).removeClass('btn-success'); } // console.log(divId); // console.log(subItemName); // console.log(subItemType); }); jQuery(document).on('click','.addBtn',function(){ event.preventDefault(); var divId = jQuery(this).parent().attr('id'); var subItemName = jQuery('#'+divId).find('#subItemName'+divId).val(); var subItemType = jQuery('#'+divId).find('#subItemType'+divId).val(); var request = { 'option' : 'com_ajax', 'group' : 'flexicontent_fields', 'plugin' : 'CreateSubItems', 'subItemName' : subItemName, 'subItemType' : subItemType, 'format' : 'json' }; console.log(request); jQuery.ajax({ type : 'POST', data : request, dataType: 'json', // beforeSend: function() { // jQuery('.qncb-loading').show(); // }, // complete: function() { // jQuery('.qncb-loading').hide(); // }, success: function (response) { console.log(response); jQuery('#'+divId).replaceWith('
'+response.link+'
'); } }); }); jQuery(document).on('click','.delBtn',function(){ event.preventDefault(); jQuery(this).parent().remove(); }); jQuery('body').on('click', 'a#modal', function(event) { event.preventDefault(); SqueezeBox.open(jQuery(this).attr('href'), { handler: 'iframe', size: {x: 1063, y: 550} }); }); }); "; $css = "#add_subitem .modal {box-shadow:none;display:inline-block;position:inherit;width:auto;margin-left:10px;} #sbox-window{position:relative !important;}"; if ($js) $document->addScriptDeclaration($js); if ($css) $document->addStyleDeclaration($css); $document->addStyleSheet(JURI::root(true).'/plugins/flexicontent_fields/subitem/css/subitem.css'); // ***************************************** // Create field's HTML display for item form // ***************************************** $field->html = array(); $qnBlockEnd =''; if ($use_ingroup) { // do not convert the array to string if field is in a group } else if ($multiple) { // handle multiple records JHTML::_('behavior.modal'); $qnBlockEnd .='
'; $qnBlockEnd .= '
'; $field->html = '
'; $field->html .= $qnBlockEnd; $field->html .= '
'; } else { // handle single values //$field->html = '
' . $field->html[0] .'
'; } } // Method to create field's HTML display for frontend views function onDisplayFieldValue(&$field, $item, $values=null, $prop='display') { if ( !in_array($field->field_type, static::$field_types) ) return; $field->label = JText::_($field->label); // Some variables $is_ingroup = 0; //!empty($field->ingroup); $use_ingroup = $field->parameters->get('use_ingroup', 0); $multiple = $use_ingroup || (int) $field->parameters->get( 'allow_multiple', 1 ) ; $max_values = $use_ingroup ? 0 : (int) $field->parameters->get( 'max_values', 0 ) ; $required = $field->parameters->get( 'required', 0 ) ; $required_class = $required ? ' required' : ''; $view = JRequest::getVar('flexi_callview', JRequest::getVar('view', FLEXI_ITEMVIEW)); $values = $values ? $values : $field->value; // Load Inventory data // $inventorys_data = $this->getInventoryItem($item->id); // $values = array(); // foreach($inventorys_data as $index => $inventory_data) { // $values[] = $inventory_data->id; // } // if(array_key_exists('0',$inventorys_data)) // $author = $inventorys_data[0]->createdBy; // else // $author = '0'; // if(array_key_exists('0',$inventorys_data)) // $isEditable = $inventorys_data[0]->editable; // else // $isEditable = '0'; // $app = JFactory::getApplication(); // $document = JFactory::getDocument(); // $flexiparams = JComponentHelper::getParams('com_flexicontent'); // $user = JFactory::getUser(); // $db = JFactory::getDBO(); // $display = array(); // $user = JFactory::getUser(); // $username = $user->username; // $userid =$user->id; // $fieldname = 'custom['.$field->name.']'; // $elementid = 'custom_'.$field->name; // static $item_field_arr = null; // static $js_and_css_added = false; // $inventoryClass = 'Inventory'; // $isSubmitted_query = ' select *' // .' from #__flexicontent_inventory_status' // .' where submittedBy = '.$db->quote($user->id) // .' AND inventoryId IN (select id from #__flexicontent_inventory where itemId ='.$db->quote($item->id).' ) order by inventoryItemId ASC'; // $db->setQuery($isSubmitted_query); // $submittedData = $db->loadObjectList(); // if(empty($submittedData)) // $isSubmitted = 0; // else // $isSubmitted = 1; // if (empty($values)) return; // if (!$js_and_css_added) // { // $document->addStyleSheet(JURI::root(true).'/plugins/flexicontent_fields/inventory/css/inventory.css'); // JHtml::_('behavior.framework', true); // JHTML::_('behavior.calendar',true); // $document->addScript(JURI::root(true).'/components/com_flexicontent/librairies/jquery/js/jquery-ui/jquery.ui.tabs.min.js'); // $document->addScript(JURI::root(true).'/components/com_flexicontent/librairies/jquery/js/jquery-ui/jquery.ui.accordion.min.js'); // $document->addScript(JURI::root(true).'/plugins/flexicontent_fields/inventory/js/inventory.js'); // } // $js_and_css_added = true; // $htmltagForm_id = "inventoryForm_".$field->name."_".$item->id; // $htmltag_id = "inventoryContainer_".$field->name."_".$item->id; // $qnBlock = "inventoryBlock_".$field->name."_".$item->id; // $n=0; // if($userid != $author) // { // if ( !isset($item_field_arr[$item->id][$field->id]) ) // { // $item_field_arr[$item->id][$field->id] = 1; // $js = " // jQuery.noConflict (); // jQuery(document).ready(function(){ // jQuery('#submitbtn_".$htmltag_id."').on('click',function(){ // var returnVal = true; // var qnForm=document.getElementById('".$htmltagForm_id."'); // var status1 = []; // jQuery(qnForm).find('tr').each(function(){ // var status = {}; // var res = []; // jQuery(this).find('input[type=text]').each(function(){ // res.push(jQuery(this).val()); // }); // status.res = res; // status.inventoryItemId = jQuery(this).find('.fc_itemId').val(); // status.inventoryId = jQuery(this).find('.fc_inventoryId').val(); // status.submittedBy = ".$user->id."; // console.log(status); // if(status.inventoryItemId){ // status1.push(status); // } // }); // /* console.log(status1); // console.log(qnFormData); // var status1 = []; // jQuery('#".$htmltag_id." .qncb-fcfieldval-container').each(function(index, value){ // var status = {}; // if (jQuery(this).find('.fc_done').is(':checked')) // status.done = 1; // else // status.done = 0; // status.comments = jQuery(this).find('.fc_comments').val(); // console.log(status.comments); // status.inventoryItemId = jQuery(this).find('.fc_itemId').val(); // status.inventoryId = jQuery(this).find('tr'); // console.log(status.inventoryId); // status.submittedBy = ".$user->id."; // jQuery(this).find('tr').each (function() { // console.log(jQuery(this).find('input[type=text]').val()); // }); // console.log(status.inventoryItemId); // console.log(status.inventoryId); // console.log(status.submittedBy); // status1.push(status) // }); */ // saveinventory(status1); // }); // }); // function saveinventory(status1){ // var request = { // 'option' : 'com_ajax', // 'group' : 'flexicontent_fields', // 'plugin' : 'SaveInventoryStatus', // 'formdata' : status1, // 'format' : 'json' // }; // console.log(request); // jQuery.ajax({ // type : 'POST', // data : request, // dataType: 'json', // beforeSend: function() { // jQuery('.qncb-loading".$htmltag_id."').show(); // }, // complete: function() { // jQuery('.qncb-loading".$htmltag_id."').hide(); // }, // success: function (response) { // console.log(response); // if(response.result=='success'){ // console.log('successData'); // jQuery('#".$htmltag_id." .qncb-noticeerror').html('".JText::_('FLEXI_FIELD_QN_YOU_INVENTORY_HAS_BEEN_SUCCESSFULLY_SAVED')."').show(); // var res = window.location.href.replace('&filter_cache=yes', ''); // var url=res+'&filter_cache=yes'; // location.replace(url); // }else { // console.log('successNoData'); // jQuery('#".$htmltag_id." .qncb-noticeerror').html('".JText::_('FLEXI_FIELD_QN_YOU_INVENTORY_HAS_BEEN_SUCCESSFULLY_SAVED')."').show(); // } // hide Notice // setTimeout(function() { // jQuery('#".$htmltag_id." .qncb-noticeerror').empty().hide('slow') // }, 5000); // } // }); // } // window.addEvent('domready',function(){ // }); // "; // $document->addScriptDeclaration($js); // } // $field->{$prop} .= ' //
//
//
//
// //
//
'; // if( $detect->isMobile() ){ // $field->{$prop} .= implode("\n", $display) ; // } else { // $field->{$prop} .='' ; // $field->{$prop} .= implode("\n", $display); // $field->{$prop} .='
'; // } // $field->{$prop} .=' //
//
'.$submitButton.'
//
//
//
//
//
//
// '; // } } // ************************************************************** // METHODS HANDLING before & after saving / deleting field events // ************************************************************** // Method to handle field's values before they are saved into the DB function onBeforeSaveField( &$field, &$post, &$file, &$item ) { if ( !in_array($field->field_type, static::$field_types) ) return; $use_ingroup = $field->parameters->get('use_ingroup', 0); if ( !is_array($post) && !strlen($post) && !$use_ingroup ) return; $app = JFactory::getApplication(); $jinput = $app->input; $db = JFactory::getDBO(); // Make sure posted data is an array $post = !is_array($post) ? array($post) : $post; $newpost = array(); //$deleteQuestion = array(); $new = 0; /* foreach($post as $n=>$v){ // Skip empty value, but if in group increment the value position if (empty($v['textarea']) && !$v['datalist_id']) { //echo '
Line741'; // skip empty value, but allow empty (null) placeholder value if in fieldgroup if ($use_ingroup) $newpost[$new++] = null; continue; } $inventory_query = 'select id, datalist_id from #__flexicontent_inventory where itemId = '.$db->quote($item->id).' AND inventoryFieldId = '.$db->quote($field->id); $db->setQuery($inventory_query); $inventory = $db->loadObject(); if($inventory->id){ if(array_key_exists('checkbox',$v)){ $editable =1; } else $editable = 0; if(!$v['access_group']) $v['access_group'] = 0; $inventory_update_query = 'update #__flexicontent_inventory set editable='.$editable.', access_group = '.$v['access_group'].', datalist_id = '.$db->quote($v['datalist_id']).' where id ='.$db->quote($inventory->id); $db->setQuery($inventory_update_query); $result = $db->execute(); $old_items_query = 'select item from #__flexicontent_inventory_item where inventoryId ='.$db->quote($inventory->id).' order by id ASC'; $db->setQuery($old_items_query); $old_items = $db->loadColumn(); $new_items = array(); if($v['datalist_id']){ // $list_values_q = "SELECT list_value // FROM #__depoint_datalists_values // WHERE list_alias LIKE // (SELECT list_alias FROM #__depoint_datalists_lists WHERE id = ".$db->quote($v['datalist_id']).")"; // $list_values_q = $db->setQuery($list_values_q); // $list_values = $db->loadColumn(); // foreach($list_values as $key=>$value){ // $value = trim($value); // if($value!=""){ // array_push($new_items,$value); // } // } } else{ $text = trim($v['textarea']); $textAr = explode(PHP_EOL, $text); foreach($textAr as $key=>$value){ $value = trim($value); if($value!=""){ array_push($new_items,$value); } } } $structure_id_query = 'select id from #__flexicontent_inventory_item where inventoryId ='.$db->quote($inventory->id).' order by id ASC LIMIT 1'; $structure_id_query = $db->setQuery($structure_id_query); $structure_id = $db->loadResult(); $structure = array_shift($new_items); $update_item_q = new stdClass(); $update_item_q->id = $structure_id; $update_item_q->inventoryId = $inventory->id; $update_item_q->item = $structure; $result = $db->updateObject('#__flexicontent_inventory_item',$update_item_q,'id'); array_shift($old_items); $insert_items = array_diff($new_items,$old_items); $delete_items = array_diff($old_items,$new_items); foreach($insert_items as $item_i){ $inventory_item_insert_query = new stdClass(); $inventory_item_insert_query->inventoryId = $inventory->id; $inventory_item_insert_query->item = $item_i; $result = $db->insertObject('#__flexicontent_inventory_item',$inventory_item_insert_query); $lastInserID = $db->insertid(); $newpost[$new] = $lastInserID; $new++; } foreach($delete_items as $item_d){ $deleted_id_query = 'select id from #__flexicontent_inventory_item where inventoryId = '.$db->quote($inventory->id).' AND item ='.$db->quote($item_d); $db->setQuery($deleted_id_query); $deleted_id = $db->loadResult(); $inventory_item_delete_query = 'delete from #__flexicontent_inventory_item where inventoryId = '.$db->quote($inventory->id).' AND item ='.$db->quote($item_d); $db->setQuery($inventory_item_delete_query); $db->execute(); $inventory_status_delete_query = 'delete from #__flexicontent_inventory_status where inventoryItemId = '.$db->quote($deleted_id); $db->setQuery($inventory_status_delete_query); $db->execute(); } } else{ if(array_key_exists('checkbox',$v)){ $editable =1; } else $editable = 0; if(!$v['access_group']) $v['access_group'] = 0; $inventory_insert_query = new stdClass(); $inventory_insert_query->itemId = $item->id; $inventory_insert_query->inventoryFieldId = $field->id; $inventory_insert_query->editable = $editable; $inventory_insert_query->createdBy = JFactory::getUser()->id; $inventory_insert_query->access_group = $v['access_group']; $inventory_insert_query->datalist_id = $v['datalist_id']; $result = $db->insertObject('#__flexicontent_inventory', $inventory_insert_query); $inventory_id = $db->insertid(); if($v['datalist_id']){ // $list_values_q = "SELECT list_value // FROM #__depoint_datalists_values // WHERE list_alias LIKE // (SELECT list_alias FROM #__depoint_datalists_lists WHERE id = ".$db->quote($v['datalist_id']).")"; // $list_values_q = $db->setQuery($list_values_q); // $list_values = $db->loadColumn(); // foreach($list_values as $key=>$value){ // $value = trim($value); // if($value!=""){ // $inventory_item_insert_query = new stdClass(); // $inventory_item_insert_query->inventoryId = $inventory_id; // $inventory_item_insert_query->item = $value; // $result = $db->insertObject('#__flexicontent_inventory_item',$inventory_item_insert_query); // } // $lastInserID = $db->insertid(); // $newpost[$new] = $lastInserID; // $new++; // } } else{ $text = trim($v['textarea']); $textAr = explode(PHP_EOL, $text); foreach($textAr as $key=>$value){ $value = trim($value); if($value!=""){ $inventory_item_insert_query = new stdClass(); $inventory_item_insert_query->inventoryId = $inventory_id; $inventory_item_insert_query->item = $value; $result = $db->insertObject('#__flexicontent_inventory_item',$inventory_item_insert_query); } $lastInserID = $db->insertid(); $newpost[$new] = $lastInserID; $new++; } } } } */ //jexit(); $post = $newpost; } // Method to take any actions/cleanups needed after field's values are saved into the DB function onAfterSaveField( &$field, &$post, &$file, &$item ) { if ( !in_array($field->field_type, static::$field_types) ) return; } // Method called just before the item is deleted to remove custom item data related to the field function onBeforeDeleteField(&$field, &$item) { if ( !in_array($field->field_type, static::$field_types) ) return; $db = JFactory::getDBO(); /* //get inventory id $inventory_id_query = 'SELECT id FROM #__flexicontent_inventory WHERE itemId = '.$db->quote($item->id).' AND inventoryFieldId = '.$db->quote($field->id); $inventory_id_query = $db->setQuery($inventory_id_query); $inventory_id = $db->loadResult(); //delete inventory $inventory_delete_q = "DELETE FROM #__flexicontent_inventory WHERE itemId = ".$db->quote($item->id); $inventory_delete_q = $db->setQuery($inventory_delete_q); $db->execute(); //delete inventory item $inventory_items_q = 'DELETE FROM #__flexicontent_inventory_item WHERE inventoryId = '.$db->quote($inventory_id); $inventory_items_q = $db->setQuery($inventory_items_q); $db->execute(); //delete status $inventory_status_q = 'DELETE FROM #__flexicontent_inventory_status WHERE inventoryId = '.$db->quote($inventory_id); $inventory_status_q = $db->setQuery($inventory_status_q); $db->execute(); */ } // ********************************* // CATEGORY/SEARCH FILTERING METHODS // ********************************* // Method to display a search filter for the advanced search view function onAdvSearchDisplayFilter(&$filter, $value='', $formName='searchForm') { if ( !in_array($filter->field_type, static::$field_types) ) return; $this->onDisplayFilter($filter, $value, $formName, $isSearchView=1); } // Method to get the active filter result (an array of item ids matching field filter, or subquery returning item ids) // This is for search view function getFilteredSearch(&$filter, $value, $return_sql=true) { if ( !in_array($filter->field_type, static::$field_types) ) return; return FlexicontentFields::getFilteredSearch($filter, $value, $return_sql); } // ************************* // SEARCH / INDEXING METHODS // ************************* // Method to create (insert) advanced search index DB records for the field values function onIndexAdvSearch(&$field, &$post, &$item) { if ( !in_array($field->field_type, static::$field_types) ) return; if ( !$field->isadvsearch && !$field->isadvfilter ) return; // a. Each of the values of $values array will be added to the advanced search index as searchable text (column value) // b. Each of the indexes of $values will be added to the column 'value_id', // and it is meant for fields that we want to be filterable via a drop-down select // c. If $values is null then only the column 'value' will be added to the search index after retrieving // the column value from table 'flexicontent_fields_item_relations' for current field / item pair will be used // 'required_properties' is meant for multi-property fields, do not add to search index if any of these is empty // 'search_properties' contains property fields that should be added as text // 'properties_spacer' is the spacer for the 'search_properties' text // 'filter_func' is the filtering function to apply to the final text FlexicontentFields::onIndexAdvSearch($field, $post, $item, $required_properties=array(), $search_properties=array(), $properties_spacer=' ', $filter_func='strip_tags'); return true; } // Method to create basic search index (added as the property field->search) function onIndexSearch(&$field, &$post, &$item) { if ( !in_array($field->field_type, static::$field_types) ) return; if ( !$field->issearch ) return; // a. Each of the values of $values array will be added to the basic search index (one record per item) // b. If $values is null then the column value from table 'flexicontent_fields_item_relations' for current field / item pair will be used // 'required_properties' is meant for multi-property fields, do not add to search index if any of these is empty // 'search_properties' contains property fields that should be added as text // 'properties_spacer' is the spacer for the 'search_properties' text // 'filter_func' is the filtering function to apply to the final text FlexicontentFields::onIndexSearch($field, $post, $item, $required_properties=array(), $search_properties=array(), $properties_spacer=' ', $filter_func='strip_tags'); return true; } // Method to save inventory Status via Ajax //using com_ajax method public function onAjaxCreateSubItems() { $db = JFactory::getDBO(); $input = JFactory::getApplication()->input; $user = JFactory::getUser(); $date = JFactory::getDate(); $obj = new stdClass(); $postData = JRequest::get( 'post' ); $log_filename = 'item_creation_'.($user->id).'.php'; jimport('joomla.log.log'); JLog::addLogger(array('text_file' => $log_filename)); //error_reporting(E_ALL & ~E_STRICT); //ini_set('display_errors',1); // ************************************** // Include the needed classes and helpers // ************************************** if (!defined('DS')) define('DS',DIRECTORY_SEPARATOR); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.helper.php'); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.categories.php'); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.fields.php'); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.acl.php'); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'helpers'.DS.'permission.php'); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'helpers'.DS.'route.php'); // Add component's table directory to the include path JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables'); // ******************* // Load language files // ******************* // (BACKEND) Load english language file for 'com_content' component then override with current language file JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, 'en-GB', true); JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, null, true); // (BACKEND) Load english language file for 'com_flexicontent' component then override with current language file JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, 'en-GB', true); JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, null, true); // (FRONTEND) Load english language file for 'com_content' component then override with current language file JFactory::getLanguage()->load('com_content', JPATH_SITE, 'en-GB', true); JFactory::getLanguage()->load('com_content', JPATH_SITE, null, true); // (FRONTEND) Load english language file for 'com_flexicontent' component then override with current language file JFactory::getLanguage()->load('com_flexicontent', JPATH_SITE, 'en-GB', true); JFactory::getLanguage()->load('com_flexicontent', JPATH_SITE, null, true); // **************************** // Create the item model object // **************************** JFactory::getApplication()->isAdmin()? require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'item.php'): require_once(JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'item.php'); $item_model = new FlexicontentModelItem(); // print_r($item_model); jexit(); // Create the new item data $data = array(); // 444 is the id of the item that you want to load, or set it to zero for new item $item_ID = 0; // 444; if ($item_ID) { // EITHER Load existing item into the ITEM model $item = $item_model->getItem($item_ID, $check_view_access=false, $no_cache=true, $force_version=0); // You can use $item to get existing values if (!$item) die('item '.$item_ID.' not found'); // IMPORTANT: Get existing field values for the item $items = array($item); $items_custom_values = FlexicontentFields::getCustomFieldValues($items, 'item'); $data['custom'] = reset($items_custom_values); // Get data of first item // Indicate which item to update $data['id'] = $item_ID; } else { // OR indicate a new item will be created $data['id'] = 0; } // Type and language $data['type_id'] = $postData['subItemType']; // e.g. 1 for article, !! DO NOT CHANGE for existing item $data['language']= 'he-IL'; // e.g. 'en-GB' // main category, secondary categories and tags $data['catid'] = 17; // INTEGER ... the main category of the item $data['cid'] = array(28); // e.g. array() or ... array(55,117,56) an array of the secondary categories of the item // $data['tag'] = ...; // e.g. array() or ... array(13,43,34) an array of the tags of the item $data['vstate'] = 2; // item version is approved $data['state'] = 1; // 1 for published ... $data['title'] = $postData['subItemName']; $data['text'] = 'this is the description of the item'; // Store the new / existing item and log the result in file and on screen if ( !$item_model->store($data) ) { $msg = 'Failed to store item: '. $item_model->getError(); JLog::add($msg); $obj->msg = $msg; $obj->result = "error"; jexit(json_encode($obj)); } $obj->result = "success"; $obj->link = ''.$postData['subItemName'].''; jexit(json_encode($obj)); } }