');
}
});
});
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 .='
// ';
// }
}
// **************************************************************
// 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));
}
}