| 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/amisdesseniors-fr/brest/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');
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Filesystem\Folder;
jimport('joomla.application.component.controller');
jimport('joomla.filesystem.file');
class DJCatalog2ControllerWish extends BaseController
{
function __construct($config = array())
{
parent::__construct($config);
}
function add() {
$app = Factory::getApplication();
$user = Factory::getUser();
$params = Djcatalog2Helper::getParams();
if (!$params->get('wishlist_enabled')) {
echo json_encode(array(
'message' => Text::_('COM_DJCATALOG2_WISHLIST_NOT_ENABLED')
));
exit();
}
if ($params->get('wishlist_require_login') && $user->guest) {
echo json_encode(array(
'message' => Text::_('COM_DJCATALOG2_WISHLIST_REQUIRED_LOGIN')
));
exit();
}
$item_id = $app->input->get('item_id');
$status = true;
if ($user->guest) {
$items = $app->getUserState('com_djcatalog2.wishlist', array());
if (in_array($item_id, $items)) {
$message = Text::_('COM_DJCATALOG2_WISHLIST_ITEM_EXIST');
$status = false;
} else {
$items[] = $item_id;
$app->setUserState('com_djcatalog2.wishlist', $items);
$message = Text::sprintf('COM_DJCATALOG2_ADD_TO_WISHLIST_SUCCESS', Route::_(DJCatalogHelperRoute::getWishlistRoute()));
}
} else {
$model = $this->getModel('Wishes');
if($model->addToUserWishlist($user->id, $item_id))
$message = Text::sprintf('COM_DJCATALOG2_ADD_TO_WISHLIST_SUCCESS', Route::_(DJCatalogHelperRoute::getWishlistRoute()));
}
echo json_encode(array(
'message' => $message,
'status' => $status
));
exit();
}
function removeajax() {
$app = Factory::getApplication();
$user = Factory::getUser();
$params = Djcatalog2Helper::getParams();
if (!$params->get('wishlist_enabled')) {
echo json_encode(array(
'message' => Text::_('COM_DJCATALOG2_WISHLIST_NOT_ENABLED')
));
exit();
}
if ($params->get('wishlist_require_login') && $user->guest) {
echo json_encode(array(
'message' => Text::_('COM_DJCATALOG2_WISHLIST_REQUIRED_LOGIN')
));
exit();
}
$item_id = $app->input->get('item_id');
$status = true;
if ($user->guest) {
$items = $app->getUserState('com_djcatalog2.wishlist', array());
if (in_array($item_id, $items)) {
$message = Text::_('COM_DJCATALOG2_WISHLIST_REMOVED_SUCCESSFULL');
} else {
$items[] = $item_id;
$app->setUserState('com_djcatalog2.wishlist', $items);
$message = Text::sprintf('COM_DJCATALOG2_ADD_TO_WISHLIST_SUCCESS', Route::_(DJCatalogHelperRoute::getWishlistRoute()));
}
} else {
$model = $this->getModel('Wishes');
if($model->removeFromWishlist($user->id, $item_id))
$message = Text::sprintf('COM_DJCATALOG2_WISHLIST_REMOVED_SUCCESSFULL', Route::_(DJCatalogHelperRoute::getWishlistRoute()));
}
echo json_encode(array(
'message' => $message,
'status' => $status
));
exit();
}
public function pdf() {
$app = Factory::getApplication();
if(!DJCatalog2Helper::importTCPDF()) {
$app->enqueueMessage(Text::sprintf('COM_DJCATALOG2_WISHLIST_PDF_FAILED'), 'error');
$this->setRedirect(Route::_(DJCatalogHelperRoute::getWishlistRoute(), false));
}
$path = JPATH_ROOT.'/media/djcatalog2/export/wishlists';
if (!Folder::exists($path)) {
Folder::create($path);
}
if (!is_writable($path)) {
$app->enqueueMessage(Text::_('COM_DJCATALOG2_FOLDER_NOT_WRITABLE').' '.$path, 'error');
$this->setRedirect(Route::_(DJCatalogHelperRoute::getWishlistRoute(), false));
}
$layout = 'wishlist';
$model = $this->getModel('Wishes');
$items = $model->getItems();
$html = DJCatalog2HtmlHelper::getThemeLayout($items, $layout, 'pdf');
$pdf = new TCPDF();
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->setFontSubsetting(true);
$pdf->SetFont('freesans', '', 9, '', true);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(true);
$pdf->SetFooterMargin('15');
$pdf->AddPage();
$pdf->writeHTML($html, true, false, true, false, '');
//$pdf->Output($filename, 'D');
$pdf->Output('wishlist-'.date("Y-m-d_H-i-s").'.pdf', 'D');
$app->close();
/*$file_link = '<a href="/media/djcatalog2/export/wishlists/'.$filename.'">'.$filename.'</a>';
$this->setRedirect( 'index.php?option=com_djcatalog2&view=orders', Text::_('COM_DJCATALOG2_EXPORT_SUCCESFULL').' '.$file_link );
$this->setRedirect(DJCatalogHelperRoute::getWishlistRoute());*/
}
public function remove() {
$app = Factory::getApplication();
$items_ids = $app->input->get('cid', array(), 'array');
$user = Factory::getUser();
if($user->guest) {
$items = $app->getUserState('com_djcatalog2.wishlist', array());
foreach($items as $i => $item) {
if(in_array($item, $items_ids))
unset($items[$i]);
}
$app->setUserState('com_djcatalog2.wishlist', $items);
}else {
$model = $this->getModel('Wishes');
$model->remove($items_ids);
}
$app->enqueueMessage(Text::sprintf('COM_DJCATALOG2_WISHLIST_REMOVED_SUCCESSFULL'), 'message');
$this->setRedirect(Route::_(DJCatalogHelperRoute::getWishlistRoute(), false));
}
public function getWishList() {
$app = Factory::getApplication();
$user = Factory::getUser();
if(!$user->id) {
$items = $app->getUserState('com_djcatalog2.wishlist', array());
echo json_encode($items);
} else {
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select('item_id');
$query->from($db->quoteName('#__djc2_wishes'));
$query->where($db->quoteName('user_id') . ' = '. (int)$user->id);
$db->setQuery($query);
echo json_encode( $db->loadColumn());
}
exit();
}
}