| Current Path : /home/helpink/www/components/com_jbusinessdirectory/controllers/ |
| Current File : /home/helpink/www/components/com_jbusinessdirectory/controllers/managemessages.php |
<?php
/**
* @package J-BusinessDirectory
*
* @author CMSJunkie http://www.cmsjunkie.com/
* @copyright Copyright (C) 2007 - 2022 CMSJunkie. All rights reserved.
* @license https://www.gnu.org/licenses/agpl-3.0.en.html
*/
defined('_JEXEC') or die('Restricted access');
use Joomla\Utilities\ArrayHelper;
JTable::addIncludePath(DS.'components'.'com_jbusinessdirectory'.DS.'tables');
JTable::addIncludePath(DS.'components'.'com_jbusinessdirectory'.DS.'models');
require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'controllers'.DS.'messages.php');
require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'models'.DS.'messages.php');
class JBusinessDirectoryControllerManageMessages extends JBusinessDirectoryControllerMessages {
/**
* constructor (registers additional tasks to methods)
* @return void
*/
private $log;
public function __construct() {
parent::__construct();
$this->log = Logger::getInstance();
}
/**
* Removes an item
*/
public function delete() {
// Check for request forgeries
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Get items to remove from the request.
$cid = JFactory::getApplication()->input->get('id');
if (empty($cid)) {
JFactory::getApplication()->enqueueMessage(JText::_('COM_JBUSINESSDIRECTORY_NO_MESSAGES_SELECTED'), 'error');
} else {
// Get the model.
$model = $this->getModel("ManageMessages");
// Make sure the item ids are integers
jimport('joomla.utilities.arrayhelper');
ArrayHelper::toInteger($cid);
// Remove the items.
if (!$model->delete($cid)) {
$this->setMessage($model->getError());
} elseif (!empty($model->getErrors())){
$implodeErrors = implode('<br />', $model->getErrors());
$this->setMessage(JText::sprintf( 'COM_JBUSINESSDIRECTORY_DELETED_WARNING',$implodeErrors),'Warning');
} else {
$this->setMessage(JText::plural('COM_JBUSINESS_DIRECTORY_N_MESSAGES_DELETED', count($cid)));
}
}
$this->setRedirect('index.php?option=com_jbusinessdirectory&view=managemessages');
}
public function readMessageAjax() {
$model = $this->getModel('ManageMessage');
$result = $model->readMessage();
//Send data as json
header("Content-Type: application/json", true);
echo json_encode($result);
exit;
}
public function changeMessageStatus() {
//dump("erdhi");exit;
// Get items to publish from the request.
$id = $this->input->get('id');
$oldStatus = $this->input->get('currentStatus');
if ($oldStatus == '0') {
$newStatus = 1;
} else {
$newStatus = 0;
}
$model = $this->getModel('ManageMessage');
$result = $model->changeStatus($id, $newStatus);
if (!$result) {
$this->setMessage(JText::_('LNG_ERROR_CHANGE_STATUS'), 'warning');
} else {
$ntext = "COM_JBUSINESSDIRECTORY_N_ITEMS_CHANGED";
if ($ntext !== null) {
$this->setMessage(\JText::plural($ntext, count(array($id))));
}
}
//Send data as json
header("Content-Type: application/json", true);
echo json_encode($result);
exit;
}
public function sendMessageReply(){
$model = $this->getModel('ManageMessage');
$jinput = JFactory::getApplication()->input;
$data = $jinput->get->getArray();
$result = $model->sendMessageReply($data);
$resultData = new stdClass();
$resultData->user = JBusinessUtil::getUser()->name;
$resultData->content = $data["content"];
$resultData->date = JBusinessUtil::getDateGeneralFormatWithTime(date("Y-m-d H:i:s"));
$status = RESPONSE_STATUS_SUCCESS;
$message = JText::_("LNG_REPLY_SENT_SUCCESFULLY");
if(!$result){
$status = RESPONSE_STATUS_ERROR;
$message = JText::_("LNG_REPLY_SENT_FAILURE");
}
JBusinessUtil::sendJsonResponse($resultData, $status, $message);
//Send data as json
header("Content-Type: application/json", true);
echo json_encode($result);
exit;
}
}