| Server IP : 54.36.91.62 / Your IP : 216.73.217.112 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/plats-individuels/lyon/administrator/components/com_djcatalog2/controllers/ |
Upload File : |
<?php
/**
* @package DJ-Catalog2
* @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('Restricted access');
jimport('joomla.application.component.controlleradmin');
class Djcatalog2ControllerLena extends JControllerAdmin
{
public function __construct($config = array())
{
parent::__construct($config);
}
public function getModel($name = 'Items', $prefix = 'Djcatalog2Model', $config = array())
{
$model = parent::getModel($name, $prefix, array('ignore_request' => true));
return $model;
}
public function flushIcons() {
$db = JFactory::getDbo();
$db->setQuery('DELETE FROM #__djc2_items_extra_fields_values_int WHERE (field_id = 128 OR field_id = 170 OR field_id = 171 OR field_id = 172)');
if($db->execute()) {
$db->setQuery('DELETE FROM #__djc2_items_groups WHERE group_id = 23');
if($db->execute()) {
echo 'Done';
exit();
}
}
}
public function rebuildIcons()
{
$app = JFactory::getApplication();
$start = $app->input->getInt('start', 0);
// Get items
$db = JFactory::getDbo();
$db->setQuery('SELECT id, name FROM #__djc2_items WHERE id > ' . (int)$start . ' LIMIT 10');
$items = $db->loadObjectList('id');
$ids = array_keys($items);
// Load attributes
$query = $db->getQuery(true);
$query
->select(array(
'f.name',
'f.alias',
'f.id',
'fo.value',
'fv.item_id',
'f.language'
))
->from($db->quoteName('#__djc2_items_extra_fields', 'f'))
->join('INNER', $db->quoteName('#__djc2_items_extra_fields_values_int', 'fv') . ' ON fv.field_id = f.id')
->join('INNER', $db->quoteName('#__djc2_items_extra_fields_options', 'fo') . ' ON fo.id = fv.value')
->where('fv.item_id IN (' . implode(',', $ids) . ')');
$db->setQuery($query);
$attributesData = $db->loadObjectList();
$attributes = array();
$query = $db->getQuery(true);
$query
->select(array(
'o.value',
'o.id',
'o.field_id',
'f.language'
))
->from($db->quoteName('#__djc2_items_extra_fields_options', 'o'))
->join('INNER', $db->quoteName('#__djc2_items_extra_fields', 'f') . ' ON f.id = o.field_id')
->where('(o.field_id = 170 OR o.field_id = 128 OR o.field_id = 171 OR o.field_id = 172)');
$db->setQuery($query);
$tmpOptions = $db->loadObjectList();
$options = array();
foreach ($tmpOptions as $tmpOption) {
$options[$tmpOption->language][] = $tmpOption;
}
foreach ($attributesData as $attributesDatum) {
$attributes[$attributesDatum->item_id][$attributesDatum->id][] = $attributesDatum;
}
$newAttributes = array();
$lastId = 0;
$onlyYesNoPL = array(26, 142, 143, 144, 25, 145, 146, 147, 27);
$onlyYesNoEn = array(45, 155, 154, 153, 44, 152, 151, 150, 46);
$onlyYesFr = array(121, 169, 168, 167, 120, 166, 165, 164, 122);
$onlyYesDe = array(102, 162, 161, 160, 101, 159, 158, 157, 103);
$onlyYesNo = array_merge($onlyYesNoPL, $onlyYesNoEn, $onlyYesFr, $onlyYesDe);
foreach ($items as $item) {
$lastId = $item->id;
}
foreach ($attributes as $itemId => $attribute) {
foreach ($attribute as $attrId => $fieldValues) {
foreach ($fieldValues as $fieldValue) {
$opt = $options[$fieldValue->language];
foreach ($opt as $option) {
if (in_array($attrId, $onlyYesNo) && (strtolower($fieldValue->value) === 'tak' || strtolower($fieldValue->value) === 'yes' || strtolower($fieldValue->value) === 'oui' || strtolower($fieldValue->value) === 'ja') && strtolower($option->value) == strtolower($fieldValue->name)) {
$newAttributes[$fieldValue->language][$itemId][] = $option->id;
} else {
if (strtolower($option->value) == strtolower($fieldValue->value)) {
$newAttributes[$fieldValue->language][$itemId][] = $option->id;
}
}
}
}
}
}
$inserted = array();
foreach ($newAttributes as $language => $items) {
foreach ($items as $itemId => $icons) {
if (count($icons)) {
foreach ($icons as $icon) {
$profile = new stdClass();
$profile->item_id = $itemId;
switch ($language) {
case 'pl-PL' :
$profile->field_id = 128;
break;
case 'en-GB' :
$profile->field_id = 170;
break;
case 'de-DE' :
$profile->field_id = 171;
break;
case 'fr-FR' :
$profile->field_id = 172;
break;
}
$profile->value = $icon;
$result = JFactory::getDbo()->insertObject('#__djc2_items_extra_fields_values_int', $profile);
}
if (!in_array($itemId, $inserted)) {
$group = new stdClass();
$group->item_id = $itemId;
$group->group_id = 23;
$result = JFactory::getDbo()->insertObject('#__djc2_items_groups', $group);
$inserted[] = $itemId;
}
}
}
}
if ($lastId) {
header("refresh:1;url=index.php?option=com_djcatalog2&task=lena.rebuildIcons&start=" . $lastId);
} else {
echo 'Done';
}
exit();
}
public function fixNames()
{
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$start = $app->input->get('start');
$exceptions = array('LED', 'UV-C');
$query = $db->getQuery(true);
$query
->select(array(
'i.name',
'i.id'
))
->from($db->quoteName('#__djc2_items', 'i'))
->where('i.id > ' . (int)$start)
->setLimit(50);
$db->setQuery($query);
$items = $db->loadObjectList();
$lastId = 0;
foreach ($items as $item) {
$name = explode(' ', $item->name);
$newNames = array();
foreach ($name as $namePart) {
if (!in_array($namePart, $exceptions)) {
$newNames[] = ucfirst(strtolower($namePart));
} else {
$newNames[] = $namePart;
}
}
$newName = implode(' ', $newNames);
$db->setQuery('UPDATE #__djc2_items SET name = ' . $db->quote($newName) . ' WHERE id = ' . (int)$item->id);
$lastId = $item->id;
if ($db->execute()) {
echo $item->name . ' => ' . $newName . ' <br>';
}
}
if ($lastId) {
header("refresh:5;url=index.php?option=com_djcatalog2&task=lena.fixNames&start=" . $lastId);
} else {
echo 'Done';
}
exit();
}
public function importAttributes()
{
$app = JFactory::getApplication();
$data = $fields = array();
$i = 0;
$start = $app->input->get('next', 0);
$handle = @fopen(JPATH_ROOT . '/administrator/components/com_djcatalog2/attributes.csv', "r");
if ($handle) {
while (($row = fgetcsv($handle, 4096)) !== false) {
if (empty($fields)) {
$fields = $row;
continue;
}
foreach ($row as $k => $value) {
$data[$i][trim($fields[$k])] = $value;
}
$i++;
}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
if (isset($data[$start])) {
$importArray = array();
do {
$row = $data[$start];
$db = JFactory::getDbo();
$ids = array(
'pl-PL' => $row['id_PL'],
'en-GB' => $row['id_EN'],
'de-DE' => $row['id_DE'],
'fr-FR' => $row['id_FR']
);
$idPl = $row['id_PL'];
$idEn = $row['id_EN'];
$idDe = $row['id_DE'];
$idFr = $row['id_FR'];
unset($row['id_PL']);
unset($row['id_EN']);
unset($row['id_DE']);
unset($row['id_FR']);
unset($row['Nazwa produktu']);
$row['Napięcie zasilające'] = str_replace(' - ', '-', $row['Napięcie zasilające']);
$tmpRow = $row;
$attributeNames = array_keys($row);
$where = array_map(function ($attr) use ($db) {
return 'f.name = ' . $db->quote($attr);
}, $attributeNames);
$db->setQuery('SELECT * FROM #__djc2_items_extra_fields AS f WHERE f.language =' . $db->quote('pl-PL') . ' AND (' . implode(' OR ', $where) . ')');
$fields = $db->loadObjectList('name');
$finalAttributes = array();
$attributeIds = array();
foreach ($fields as $field) {
$attributeIds[$field->language][$field->name] = $field->id;
$associations = JLanguageAssociations::getAssociations('com_djcatalog2', '#__djc2_items_extra_fields', 'com_djcatalog2.field', (int)$field->id, 'id', '', '');
if ($field->type == 'text') {
$finalAttributes[$field->name]['pl-PL'] = 'text';
foreach ($associations as $association) {
$finalAttributes[$field->name][$association->language] = 'text';
$attributeIds[$association->language][trim($field->name)] = $association->id;
}
} else {
$db->setQuery('SELECT * FROM #__djc2_items_extra_fields_options WHERE field_id = ' . (int)$field->id);
$plOptions = $db->loadObjectList('value');
$plOptionsOrdering = array_map(function ($plOption) { // Get options ordering for association
return $plOption->ordering;
}, $plOptions);
foreach ($plOptions as $plOption) {
$finalAttributes[$field->name]['pl-PL'][$plOption->value] = $plOption->id;
}
if (count($associations)) {
foreach ($associations as $association) {
$attributeIds[$association->language][trim($field->name)] = $association->id;
$db->setQuery('SELECT * FROM #__djc2_items_extra_fields_options WHERE field_id = ' . (int)$association->id . ' AND ordering IN (' . implode(',', $plOptionsOrdering) . ')');
try {
$associationOptions = $db->loadObjectList('ordering');
} catch (Exception $e) {
}
foreach ($plOptions as $plOptionIndex => $plOption) {
$associationOption = $associationOptions[$plOption->ordering];
$finalAttributes[$field->name][$association->language][trim($plOption->value)] = $associationOption->id;
}
}
}
}
}
foreach ($ids as $language => $id) {
$fieldsIds = $attributeIds[$language];
foreach ($fieldsIds as $attributeName => $fieldsId) {
if (!strlen($row[$attributeName])) continue;
if ($row[$attributeName] == 'Tak') {
$optionName = 'tak';
} else {
if ($attributeName == 'Moc nominalna') {
$tmpValue = intval(str_replace('W', '', $row[$attributeName]));
if ($tmpValue <= 10) {
$optionName = '0-10W';
} else if ($tmpValue <= 25) {
$optionName = '11-25W';
} else if ($tmpValue <= 50) {
$optionName = '26-50W';
} else if ($tmpValue <= 100) {
$optionName = '51-100W';
} else if ($tmpValue <= 150) {
$optionName = '101-150W';
} else {
$optionName = 'Powyżej 150W';
}
} else {
$optionName = $row[$attributeName];
}
}
// print_r();
if (!is_array($finalAttributes[$attributeName][$language]) && $finalAttributes[$attributeName][$language] == 'text') {
$importArray[$id][$fieldsId] = $row[$attributeName];
} else {
if ($attributeName == 'Sposób montażu') {
$options = explode(',', $row[$attributeName]);
foreach ($options as $option) {
$optionId = $finalAttributes[$attributeName][$language][str_replace(" ", ' ', trim($option))];
$importArray[$id][$fieldsId][] = $optionId;
}
} else {
$optionId = $finalAttributes[$attributeName][$language][$optionName];
$importArray[$id][$fieldsId][] = $optionId;
}
}
}
}
$start++;
} while ($start < count($data));
$groups = array(9, 10, 22, 8, 1, 6, 4);
foreach ($importArray as $itemId => $fields) {
$db->setQuery('DELETE FROM #__djc2_items_groups WHERE item_id = ' . (int)$itemId . ' AND group_id IN (' . implode(',', $groups) . ')');
$db->execute();
foreach ($groups as $group) {
$fieldValue = new stdClass();
$fieldValue->item_id = $itemId;
$fieldValue->group_id = $group;
$result = JFactory::getDbo()->insertObject('#__djc2_items_groups', $fieldValue);
}
$texts = array();
$ints = array();
foreach ($fields as $fieldId => $field) {
if (!is_array($field)) {
$texts[] = $fieldId;
} else {
$ints[] = $fieldId;
}
}
$db->setQuery('DELETE FROM #__djc2_items_extra_fields_values_text WHERE item_id = ' . (int)$itemId . ' AND field_id IN (' . implode(',', $texts) . ')');
if ($db->execute()) {
foreach ($texts as $text) {
$value = $fields[$text];
$fieldValue = new stdClass();
$fieldValue->item_id = $itemId;
$fieldValue->field_id = $text;
$fieldValue->value = $value;
$result = JFactory::getDbo()->insertObject('#__djc2_items_extra_fields_values_text', $fieldValue);
}
}
$db->setQuery('DELETE FROM #__djc2_items_extra_fields_values_int WHERE item_id = ' . (int)$itemId . ' AND field_id IN (' . implode(',', $texts) . ')');
if ($db->execute()) {
foreach ($ints as $intFieldId) {
$values = $fields[$intFieldId];
foreach ($values as $value) {
$fieldValue = new stdClass();
$fieldValue->item_id = $itemId;
$fieldValue->field_id = $intFieldId;
$fieldValue->value = $value;
$result = JFactory::getDbo()->insertObject('#__djc2_items_extra_fields_values_int', $fieldValue);
}
}
}
}
exit();
$next = $start + 1;
}
if ($next) {
header("refresh:5;url=index.php?option=com_djcatalog2&task=lena.importAttributes&next=" . $next);
} else {
echo 'Done';
}
exit();
}
public function generateCE()
{
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$start = $app->input->get('start', 0);
$lastId = 0;
$query = $db->getQuery(true);
$query
->select(array(
'i.id',
'i.language'
))
->from($db->quoteName('#__djc2_items', 'i'))
->where('i.id > ' . $start)
->setLimit(20);
$db->setQuery($query);
$items = $db->loadObjectList();
foreach ($items as $item) {
$extraFieldValue = new stdClass();
$extraFieldValue->item_id = $item->id;
switch ($item->language) {
case 'pl-PL':
$extraFieldValue->field_id = 128;
$extraFieldValue->value = 417;
break;
case 'en-GB':
$extraFieldValue->field_id = 170;
$extraFieldValue->value = 564;
break;
case 'fr-FR':
$extraFieldValue->field_id = 172;
$extraFieldValue->value = 672;
break;
case 'de-DE':
$extraFieldValue->field_id = 171;
$extraFieldValue->value = 618;
break;
}
JFactory::getDbo()->insertObject('#__djc2_items_extra_fields_values_int', $extraFieldValue);
$lastId = $item->id;
}
if ($lastId) {
header("refresh:1;url=index.php?option=com_djcatalog2&task=lena.generateCE&start=" . $lastId);
} else {
echo 'Done';
}
exit();
}
public function fixArticles()
{
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$start = $app->input->get('start', 0);
$lastId = 0;
$catIds = array(109,111,110,120,129,112,113,130,121,122,131,114,115,132,123,124,133,116,117,134,125,126,135,118,119,136,127);
$query = $db->getQuery(true);
$query
->select(array(
'a.fulltext',
'a.id'
))
->from($db->quoteName('#__content', 'a'))
->where('a.catid IN (' . implode(',', $catIds) . ')')
->where('a.id > ' . $start)
->join('INNER', $db->quoteName('#__categories', 'c') . ' ON a.catid = c.id')
->setLimit(100);
$db->setQuery($query);
$items= $db->loadObjectList();
foreach ($items as $item) {
$db->setQuery('UPDATE #__content AS a SET a.fulltext = REPLACE(a.fulltext, \'"slidenav":"default"\', \'"slidenav":"outside"\') WHERE a.id = ' . (int) $item->id);
$db->execute();
$lastId = $item->id;
}
if ($lastId) {
header("refresh:1;url=index.php?option=com_djcatalog2&task=lena.fixArticles&start=" . $lastId);
} else {
echo 'Done';
}
exit();
}
}