| Server IP : 54.36.91.62 / Your IP : 216.73.217.117 Web Server : Apache System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : coopiak ( 151928) PHP Version : 8.3.23 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/coopiak/amisdesseniors-fr/administrator/components/com_djclassifieds/controllers/ |
Upload File : |
<?php
/**
* @package DJ-Classifieds
* @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
* @license http://www.gnu.org/licenses GNU/GPL
* @author url: http://dj-extensions.com
* @author email: contact@dj-extensions.com
*/
defined('_JEXEC') or die;
class DJClassifiedsControllerCategory extends JControllerForm
{
public function save($key = null, $urlVar = null) {
return parent::save($key, $urlVar);
}
protected function postSaveHook(JModelLegacy $model, $validData = array())
{
$app = JFactory::getApplication();
$db = JFactory::getDBO();
$par = JComponentHelper::getParams('com_djclassifieds');
$cat_id = $model->getItem()->id;
$jform = $app->input->getArray()['jform'];
// custom plugins support (saving additional columns with no jform wrapper)
$row = JTable::getInstance('Categories', 'DJClassifiedsTable');
$row->load($cat_id);
$row->bind($app->input->post->getArray());
$row->store();
if(!empty($validData['header_text_all_level'])){
$cat_id_lvl = null;
$cat_all = DJClassifiedsCategory::getCatAll();
$cats_lvl = array();
foreach($cat_all as $cat){
if($cat->id == $cat_id){
$cat_id_lvl = $cat->level;
}else{
if(!isset($cats_lvl[$cat->level])){
$cats_lvl[$cat->level] = array();
}
$cats_lvl[$cat->level][] = $cat->id;
}
}
if(!empty($cats_lvl[$cat_id_lvl])){
$query = "UPDATE #__djcf_categories SET header_text=".$db->q($validData['header_text'])." WHERE id IN (".implode(',',$cats_lvl[$cat_id_lvl]).")";
$db->setQuery($query);
$db->execute();
}
}
$query = "DELETE FROM #__djcf_categories_groups WHERE cat_id=".$cat_id;
$db->setQuery($query);
$db->execute();
if(!empty($jform['usergroup_access'])){
$ins_arr = array();
foreach($jform['usergroup_access'] as $ug){
$ins_arr[] = "(".$cat_id.", ".$ug.")";
}
if($ins_arr){
$query = "INSERT INTO #__djcf_categories_groups(`cat_id`, `group_id`) VALUES "
.implode(', ', $ins_arr);
$db->setQuery($query);
$db->execute();
}
}
$query = "DELETE FROM #__djcf_fields_xref WHERE cat_id=".$cat_id;
$db->setQuery($query);
$db->execute();
if(!empty($jform['custom_fields'])){
$fields_active = array();
$ins_arr = array();
$ord = 1;
foreach($jform['custom_fields'] as $f){
if(!empty($f['active'])){
$fields_active[] = $f['id'];
$ins_arr[] = "(".$cat_id.", ".$f['id'].", ".$ord.")";
$ord++;
}
}
if($ins_arr){
$query = "INSERT INTO #__djcf_fields_xref(`cat_id`,`field_id`,`ordering`) VALUES "
.implode(', ', $ins_arr);
$db->setQuery($query);
$db->execute();
}
if(!$fields_active){
$fields_active[] = '0';
}
$query = "UPDATE #__djcf_fields SET all_cats=0 WHERE id NOT IN (".implode(',', $fields_active).")";
$db->setQuery($query);
$db->execute();
if(!empty($jform['add_to_subcats'])){
$cat_ids = DJClassifiedsCategory::getSubCat($cat_id, 0, 'ord', 1, 0);
if($cat_ids){
$query = "SELECT * FROM #__djcf_fields_xref WHERE cat_id = ".$cat_id." ";
$db = JFactory::getDBO();
$db->setQuery($query);
$fields = $db->loadObjectList();
$query = "DELETE FROM #__djcf_fields_xref WHERE cat_id IN (".$cat_ids.") ";
$db->setQuery($query);
$db->execute();
if($fields){
$ins_arr = array();
$cat_ids_a = explode(',', $cat_ids);
foreach($cat_ids_a as $cat_i){
foreach($fields as $field){
$ins_arr[] = "(".$cat_i.", ".$field->field_id.", ".$field->ordering.")";
}
}
if($ins_arr){
$query = "INSERT INTO #__djcf_fields_xref(`cat_id`,`field_id`,`ordering`) VALUES "
.implode(', ', $ins_arr);
$db->setQuery($query);
$db->execute();
$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_CUSTOM_FIELDS_ASSIGNED'), 'success');
}
}
}
}
}
if($app->input->get('task') == 'save2copy' && $app->input->getInt('id')){
$query = "SELECT * FROM #__djcf_images WHERE item_id=".$app->input->getInt('id')." AND type='category'";
$db->setQuery($query);
$base_cat_images = $db->loadObjectList('id');
if($base_cat_images){
$query_img = "INSERT INTO #__djcf_images(`item_id`,`type`,`name`,`ext`,`path`,`caption`,`ordering`,`optimized`) VALUES ";
$new_img_path_rel = DJClassifiedsImage::generatePath($par->get('category_img_path','/components/com_djclassifieds/images/category/'), $cat_id);
foreach($base_cat_images as $cat_img){
$path_from_copy = JPATH_ROOT.$cat_img->path.$cat_img->name;
$new_img_name = str_ireplace($cat_img->item_id.'_', $cat_id.'_', $cat_img->name);
$path_to_copy = JPATH_SITE.$new_img_path_rel.$new_img_name;
if (JFile::exists($path_from_copy.'.'.$cat_img->ext)){
JFile::copy($path_from_copy.'.'.$cat_img->ext,$path_to_copy.'.'.$cat_img->ext);
}
if (JFile::exists($path_from_copy.'_ths.'.$cat_img->ext)){
JFile::copy($path_from_copy.'_ths.'.$cat_img->ext,$path_to_copy.'_ths.'.$cat_img->ext);
}
$query_img .= "('".$cat_id."','category','".$new_img_name."','".$cat_img->ext."','".$new_img_path_rel."','".$db->escape($cat_img->caption)."','".$cat_img->ordering."',0), ";
}
$query_img = substr($query_img, 0, -2).';';
$db->setQuery($query_img);
$db->execute();
}
}
DJClassifiedsImage::saveImage('category', $cat_id, $par->get('category_img_path','/components/com_djclassifieds/images/category/'), $app->input->files->get('jform')['icon'], $app->input->get('del_img'), array('ths' => array('w' => $par->get('catth_width','68'), 'h' => $par->get('catth_height','50'))), 0, 0);
$app->setUserState('djcf.last_cat_parent_id', $model->getItem()->parent_id);
}
}