diff --git a/src/components/com_tjucm/administrator/controllers/types.php b/src/components/com_tjucm/administrator/controllers/types.php index 8fb4ed69..1367f4f1 100644 --- a/src/components/com_tjucm/administrator/controllers/types.php +++ b/src/components/com_tjucm/administrator/controllers/types.php @@ -135,6 +135,10 @@ public function export() $exportData = array(); + $dispatcher = JDispatcher::getInstance(); + JPluginHelper::importPlugin('actionlog', 'tjucm'); + $dispatcher->trigger('tjUcmOnAfterTypeExport', array($cids)); + foreach ($cids as $cid) { $ucmTypeTable = Table::getInstance('Type', 'TjucmTable'); @@ -369,6 +373,10 @@ public function import() } } } + + $dispatcher = JDispatcher::getInstance(); + JPluginHelper::importPlugin('actionlog', 'tjucm'); + $dispatcher->trigger('tjUcmOnAfterTypeImport', array($ucmTypeId)); } } diff --git a/src/components/com_tjucm/administrator/models/type.php b/src/components/com_tjucm/administrator/models/type.php index 782c53a2..55837c5a 100644 --- a/src/components/com_tjucm/administrator/models/type.php +++ b/src/components/com_tjucm/administrator/models/type.php @@ -51,6 +51,9 @@ public function __construct($config = array()) JLoader::import('components.com_tjucm.classes.funlist', JPATH_ADMINISTRATOR); $this->common = new TjucmFunList; + $config['event_after_delete'] = 'tjUcmOnAfterTypeDelete'; + $config['event_change_state'] = 'tjUcmOnAfterTypeChangeState'; + parent::__construct($config); } @@ -381,6 +384,13 @@ public function save($data) if (parent::save($data)) { + $id = (int) $this->getState($this->getName() . '.id'); + $data['typeId'] = $id; + $dispatcher = JDispatcher::getInstance(); + JPluginHelper::importPlugin('actionlog', 'tjucm'); + $isNew = ($data['id'] != 0) ? false : true; + $dispatcher->trigger('tjUcmOnAfterTypeSave', array($data, $isNew)); + return true; } diff --git a/src/components/com_tjucm/plugins/actionlog/tjucm/index.html b/src/components/com_tjucm/plugins/actionlog/tjucm/index.html new file mode 100644 index 00000000..2efb97f3 --- /dev/null +++ b/src/components/com_tjucm/plugins/actionlog/tjucm/index.html @@ -0,0 +1 @@ + diff --git a/src/components/com_tjucm/plugins/actionlog/tjucm/language/en-GB/en-GB.plg_actionlog_tjucm.ini b/src/components/com_tjucm/plugins/actionlog/tjucm/language/en-GB/en-GB.plg_actionlog_tjucm.ini new file mode 100644 index 00000000..28882046 --- /dev/null +++ b/src/components/com_tjucm/plugins/actionlog/tjucm/language/en-GB/en-GB.plg_actionlog_tjucm.ini @@ -0,0 +1,30 @@ +; @package TJUCM +; @subpackage Actionlog.TJUCM +; @copyright Copyright (C) 2009 - 2018 Techjoomla. All rights reserved. +; @license GNU General Public License version 2 or later +; Note: All ini files need to be saved as UTF-8 + +PLG_ACTIONLOG_TJUCM="Action Log - TJUCM" +PLG_ACTIONLOG_TJUCM_XML_DESCRIPTION="Record the actions of users on the site for extension TJUCM so they can be reviewed if required." +PLG_ACTIONLOG_TJUCM_LOG_ACTION_TYPE_SAVE="Log action for type creation?" +PLG_ACTIONLOG_TJUCM_LOG_ACTION_TYPE_DELETE="Log action for type delete?" +PLG_ACTIONLOG_TJUCM_LOG_ACTION_TYPE_UPDATE="Log action for type update?" +PLG_ACTIONLOG_TJUCM_LOG_ACTION_TYPE_STATE_CHANGE="Log action for type state change?" +PLG_ACTIONLOG_TJUCM_LOG_ACTION_TYPE_IMPORT="Log action for type import?" +PLG_ACTIONLOG_TJUCM_LOG_ACTION_TYPE_EXPORT="Log action for type Export?" +PLG_ACTIONLOG_TJUCM_LOG_ACTION_TYPE_TRASH="Log action for type Trash?" +PLG_ACTIONLOG_TJUCM_LOG_ACTION_ITEM_DELETE="Log action for item delete?" +PLG_ACTIONLOG_TJUCM_LOG_ACTION_ITEM_SAVE="Log action for item creation?" + +PLG_ACTIONLOG_TJUCM_TYPE_ADDED="User {username} added a new UCM type {title} " +PLG_ACTIONLOG_TJUCM_TYPE_UPDATED="User {username} updated the UCM type {title} " +PLG_ACTIONLOG_TJUCM_TYPE_DELETED="User {username} deleted the UCM type \"{title}\" " +PLG_ACTIONLOGS_TJUCM_TYPE_UNPUBLISHED="User {username} unpublished the UCM type {title} " +PLG_ACTIONLOGS_TJUCM_TYPE_PUBLISHED="User {username} published the UCM type {title} " +PLG_ACTIONLOGS_TJUCM_TYPE_ARCHIVED="User {username} archived the UCM type {title} of client \"{identifier}\" " +PLG_ACTIONLOGS_TJUCM_TYPE_TRASHED="User {username} trashed the UCM type {title} " +PLG_ACTIONLOG_TJUCM_TYPE_EXPORTED="User {username} exported the UCM type {title} " +PLG_ACTIONLOG_TJUCM_TYPE_IMPORTED="User {username} imported the UCM type {title} " + +PLG_ACTIONLOG_TJUCM_ITEM_DELETED="User {username} has deleted item \"{id}\" " +PLG_ACTIONLOG_TJUCM_ITEM_ADDED="User {username} has added item \"{id}\" " diff --git a/src/components/com_tjucm/plugins/actionlog/tjucm/language/en-GB/en-GB.plg_actionlog_tjucm.sys.ini b/src/components/com_tjucm/plugins/actionlog/tjucm/language/en-GB/en-GB.plg_actionlog_tjucm.sys.ini new file mode 100644 index 00000000..5511d868 --- /dev/null +++ b/src/components/com_tjucm/plugins/actionlog/tjucm/language/en-GB/en-GB.plg_actionlog_tjucm.sys.ini @@ -0,0 +1,8 @@ +; @package Jgive +; @subpackage Actionlog.jgive +; @copyright Copyright (C) 2009 - 2018 Techjoomla. All rights reserved. +; @license GNU General Public License version 2 or later +; Note: All ini files need to be saved as UTF-8 + +PLG_ACTIONLOG_JGIVE="Action Log - JGive" +PLG_ACTIONLOG_JGIVE_XML_DESCRIPTION="Record the actions of users on the site for extension JGive so they can be reviewed if required." diff --git a/src/components/com_tjucm/plugins/actionlog/tjucm/tjucm.php b/src/components/com_tjucm/plugins/actionlog/tjucm/tjucm.php new file mode 100644 index 00000000..ff1ff88c --- /dev/null +++ b/src/components/com_tjucm/plugins/actionlog/tjucm/tjucm.php @@ -0,0 +1,392 @@ + + * @copyright Copyright (c) 2009-2019 Techjoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access. +defined('_JEXEC') or die(); + +JLoader::register('ActionlogsHelper', JPATH_ADMINISTRATOR . '/components/com_actionlogs/helpers/actionlogs.php'); + +use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Table\Table; + +/** + * JGive Actions Logging Plugin. + * + * @since __DEPLOY__VERSION__ + */ +class PlgActionlogTjUcm extends CMSPlugin +{ + /** + * Application object. + * + * @var JApplicationCms + * @since __DEPLOY__VERSION__ + */ + protected $app; + + /** + * Database object. + * + * @var JDatabaseDriver + * @since __DEPLOY__VERSION__ + */ + protected $db; + + /** + * Load plugin language file automatically so that it can be used inside component + * + * @var boolean + * @since __DEPLOY__VERSION__ + */ + protected $autoloadLanguage = true; + + /** + * Proxy for ActionlogsModelUserlog addLog method + * + * This method adds a record to #__action_logs contains (message_language_key, message, date, context, user) + * + * @param array $messages The contents of the messages to be logged + * @param string $messageLanguageKey The language key of the message + * @param string $context The context of the content passed to the plugin + * @param int $userId ID of user perform the action, usually ID of current logged in user + * + * @return void + * + * @since __DEPLOY__VERSION__ + */ + protected function addLog($messages, $messageLanguageKey, $context, $userId = null) + { + JLoader::register('ActionlogsModelActionlog', JPATH_ADMINISTRATOR . '/components/com_actionlogs/models/actionlog.php'); + + $model = BaseDatabaseModel::getInstance('Actionlog', 'ActionlogsModel'); + $model->addLog($messages, $messageLanguageKey, $context, $userId); + } + + /** + * On saving UCM type data - logging method + * + * Method is called when ucm type is to be stored in the database. + * This method logs who created/edited any data of UCM type + * + * @param Array $type Holds the ucm type data + * @param Boolean $isNew True if a new type is stored. + * + * @return void + * + * @since __DEPLOY__VERSION__ + */ + public function tjUcmOnAfterTypeSave($type, $isNew) + { + if ($isNew) + { + if (!$this->params->get('logActionForTypeSave', 1)) + { + return; + } + + $messageLanguageKey = 'PLG_ACTIONLOG_TJUCM_TYPE_ADDED'; + $action = 'add'; + } + else + { + if (!$this->params->get('logActionForTypeUpdate', 1)) + { + return; + } + + $messageLanguageKey = 'PLG_ACTIONLOG_TJUCM_TYPE_UPDATED'; + $action = 'update'; + } + + $context = Factory::getApplication()->input->get('option'); + $user = Factory::getUser(); + + $message = array( + 'action' => $action, + 'id' => $type['typeId'], + 'title' => $type['title'], + 'userid' => $user->id, + 'username' => $user->username, + 'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id, + 'typelink' => 'index.php?option=com_tjucm&view=type&layout=edit&id=' . $type['typeId'], + ); + + $this->addLog(array($message), $messageLanguageKey, $context, $user->id); + } + + /** + * On deleting UCM type data - logging method + * + * Method is called after ucm type is deleted in the database. + * + * @param String $context com_tjucm + * @param Object $table Holds the coupon data. + * + * @return void + * + * @since __DEPLOY__VERSION__ + */ + public function tjUcmOnAfterTypeDelete($context, $table) + { + if (!$this->params->get('logActionForTypeDelete', 1)) + { + return; + } + + $context = Factory::getApplication()->input->get('option'); + $user = Factory::getUser(); + + $messageLanguageKey = 'PLG_ACTIONLOG_TJUCM_TYPE_DELETED'; + $message = array( + 'action' => 'delete', + 'id' => $table->id, + 'title' => $table->title, + 'identifier' => $table->unique_identifier, + 'userid' => $user->id, + 'username' => $user->username, + 'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id, + ); + + $this->addLog(array($message), $messageLanguageKey, $context, $user->id); + } + + /** + * On deleting UCM type data - logging method + * Method is called after user data is stored in the database + * This method logs who created/edited UCM type ,user's data + * + * @param Int $pks Holds the UCM type data. + * + * @return void + * + * @since __DEPLOY__VERSION__ + */ + public function tjUcmOnAfterTypeImport($pks) + { + if (!$this->params->get('logActionForTypeImport', 1) || !$pks) + { + return; + } + + $context = Factory::getApplication()->input->get('option'); + $user = Factory::getUser(); + + $tjucmTableType = Table::getInstance('type', 'TjucmTable', array()); + + $tjucmTableType->load(array('id' => $pks)); + + $messageLanguageKey = 'PLG_ACTIONLOG_TJUCM_TYPE_IMPORTED'; + + if ($tjucmTableType != null) + { + $message = array( + 'action' => 'import', + 'id' => $tjucmTableType->id, + 'title' => $tjucmTableType->title, + 'identifier' => $tjucmTableType->unique_identifier, + 'itemlink' => 'index.php?option=com_tjucm&view=type&layout=edit&id=' . $tjucmTableType->id, + 'userid' => $user->id, + 'username' => $user->username, + 'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id, + ); + $this->addLog(array($message), $messageLanguageKey, $context, $user->id); + } + } + + /** + * On deleting UCM type data - logging method + * + * Method is called after user data is stored in the database. + * This method logs who created/edited UCM type ,user's data + * + * @param Array $pks Holds the UCM type data. + * + * @return void + * + * @since __DEPLOY__VERSION__ + */ + public function tjUcmOnAfterTypeExport($pks) + { + if (!$this->params->get('logActionForTypeExport', 1)) + { + return; + } + + $context = Factory::getApplication()->input->get('option'); + $jUser = Factory::getUser(); + $userId = $jUser->id; + $userName = $jUser->username; + + $messageLanguageKey = 'PLG_ACTIONLOG_TJUCM_TYPE_EXPORTED'; + + $tjucmTableType = Table::getInstance('type', 'TjucmTable', array()); + + if ($tjucmTableType != null) + { + foreach ($pks as $pk) + { + $tjucmTableType->load(array('id' => $pk)); + + $message = array( + 'id' => $tjucmTableType->id, + 'title' => $tjucmTableType->title, + 'identifier' => $tjucmTableType->unique_identifier, + 'itemlink' => 'index.php?option=com_tjucm&view=type&layout=edit&id=' . $tjucmTableType->id, + 'userid' => $userId, + 'username' => $userName, + 'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $userId, + ); + + $this->addLog(array($message), $messageLanguageKey, $context, $userId); + } + } + } + + /** + * On changing state of UCM Type - logging method + * + * Method is called after user data is stored in the database. + * This method logs who changed state of UCM type + * + * @param String $context com_tjucm + * @param Array $pks Holds array of primary key. + * @param Int $value Switch case value. + * + * @return void + * + * @since __DEPLOY__VERSION__ + */ + public function tjUcmOnAfterTypeChangeState($context, $pks, $value) + { + if (!$this->params->get('logActionForTypeStateChange', 1)) + { + return; + } + + $tjucmTableType = Table::getInstance('type', 'TjucmTable', array()); + + $context = Factory::getApplication()->input->get('option'); + $jUser = Factory::getUser(); + $userId = $jUser->id; + $userName = $jUser->username; + + switch ($value) + { + case 0: + $messageLanguageKey = 'PLG_ACTIONLOGS_TJUCM_TYPE_UNPUBLISHED'; + $action = 'unpublish'; + break; + case 1: + $messageLanguageKey = 'PLG_ACTIONLOGS_TJUCM_TYPE_PUBLISHED'; + $action = 'publish'; + break; + case 2: + $messageLanguageKey = 'PLG_ACTIONLOGS_TJUCM_TYPE_ARCHIVED'; + $action = 'archive'; + break; + case -2: + $messageLanguageKey = 'PLG_ACTIONLOGS_TJUCM_TYPE_TRASHED'; + $action = 'trash'; + break; + default: + $messageLanguageKey = ''; + $action = ''; + break; + } + + foreach ($pks as $pk) + { + $tjucmTableType->load(array('id' => $pk)); + + $message = array( + 'action' => $action, + 'id' => $tjucmTableType->id, + 'title' => $tjucmTableType->title, + 'identifier' => $tjucmTableType->unique_identifier, + 'itemlink' => 'index.php?option=com_tjucm&view=type&layout=edit&id=' . $tjucmTableType->id, + 'userid' => $userId, + 'username' => $userName, + 'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $userId, + ); + + $this->addLog(array($message), $messageLanguageKey, $context, $userId); + } + } + + /** + * On saving UCM item data - logging method + * + * Method is called when ucm item is to be stored in the database. + * This method logs who created/edited any data of UCM item + * + * @param Integer $item Holds the ucm item id + * + * @return void + * + * @since __DEPLOY__VERSION__ + */ + public function tjucmOnAfterSaveItem($item) + { + if (!$this->params->get('tjucmOnAfterSaveItem', 1)) + { + return; + } + + $context = Factory::getApplication()->input->get('option'); + $user = Factory::getUser(); + + $messageLanguageKey = 'PLG_ACTIONLOG_TJUCM_ITEM_ADDED'; + $message = array( + 'action' => 'add', + 'id' => $item, + 'userid' => $user->id, + 'username' => $user->username, + 'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id, + ); + + $this->addLog(array($message), $messageLanguageKey, $context, $user->id); + } + + /** + * On deleting UCM item data - logging method + * + * Method is called after ucm item is deleted in the database. + * + * @param Object $item Holds the item obj. + * + * @return void + * + * @since __DEPLOY__VERSION__ + */ + public function TjUcmOnAfterItemDelete($item) + { + if (!$this->params->get('TjUcmOnAfterItemDelete', 1)) + { + return; + } + + $context = Factory::getApplication()->input->get('option'); + $user = Factory::getUser(); + + $messageLanguageKey = 'PLG_ACTIONLOG_TJUCM_ITEM_DELETED'; + $message = array( + 'action' => 'delete', + 'id' => $item->content_id, + 'userid' => $user->id, + 'username' => $user->username, + 'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id, + ); + + $this->addLog(array($message), $messageLanguageKey, $context, $user->id); + } + +} diff --git a/src/components/com_tjucm/plugins/actionlog/tjucm/tjucm.xml b/src/components/com_tjucm/plugins/actionlog/tjucm/tjucm.xml new file mode 100644 index 00000000..eb173073 --- /dev/null +++ b/src/components/com_tjucm/plugins/actionlog/tjucm/tjucm.xml @@ -0,0 +1,61 @@ + + + PLG_ACTIONLOG_TJUCM + Techjoomla + 14th sept 2019 + Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + extensions@techjoomla.com + https://techjoomla.com + 2.2.3 + PLG_ACTIONLOG_TJUCM_XML_DESCRIPTION + + tjucm.php + index.html + + + en-GB/en-GB.plg_actionlog_tjucm.ini + en-GB/en-GB.plg_actionlog_tjucm.sys.ini + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
diff --git a/src/components/com_tjucm/site/controllers/itemform.json.php b/src/components/com_tjucm/site/controllers/itemform.json.php index 25401ab7..37da5085 100644 --- a/src/components/com_tjucm/site/controllers/itemform.json.php +++ b/src/components/com_tjucm/site/controllers/itemform.json.php @@ -168,6 +168,10 @@ public function save($key = null, $urlVar = null) { $result['id'] = $model->getState($model->getName() . '.id'); + /*$dispatcher = JDispatcher::getInstance(); + JPluginHelper::importPlugin('actionlog', 'tjucm'); + $dispatcher->trigger('tjucmOnAfterSaveItem', array($result['id']));*/ + echo new JResponseJson($result, Text::_('COM_TJUCM_ITEM_SAVED_SUCCESSFULLY')); } else diff --git a/src/components/com_tjucm/site/models/item.php b/src/components/com_tjucm/site/models/item.php index 02e31596..5fc3cb0a 100644 --- a/src/components/com_tjucm/site/models/item.php +++ b/src/components/com_tjucm/site/models/item.php @@ -109,7 +109,7 @@ protected function populateState() * @param integer $pk The id of the item. * * @return object|boolean|JException Menu item data object on success, boolean false or JException instance on error - * + * * @since _DEPLOY_VERSION_ */ public function getItem($pk = null) @@ -359,7 +359,16 @@ public function publish(&$id, $state = 1) $table->draft = $state == 1 ? 0 : 1; $table->state = $state; - return $table->store(); + if ($table->store()) + { + $dispatcher = JDispatcher::getInstance(); + JPluginHelper::importPlugin('actionlog', 'tjucm'); + $dispatcher->trigger('tjUcmOnAfterItemChangeState', array($id,$state)); + + return true; + } + + return false; } /** diff --git a/src/components/com_tjucm/site/models/itemform.php b/src/components/com_tjucm/site/models/itemform.php index 985cf079..ea00867e 100644 --- a/src/components/com_tjucm/site/models/itemform.php +++ b/src/components/com_tjucm/site/models/itemform.php @@ -646,7 +646,19 @@ public function save($data) } } - return parent::save($data); + if (parent::save($data)) + { + $id = (int) $this->getState($this->getName() . '.id'); + $data['itemId'] = $id; + $dispatcher = JDispatcher::getInstance(); + JPluginHelper::importPlugin('actionlog', 'tjucm'); + $isNew = ($data['id'] != 0) ? false : true; + $dispatcher->trigger('tjucmOnAfterSaveItem', array($data, $isNew)); + + return true; + } + + return false; } /** @@ -1018,6 +1030,14 @@ public function delete($contentId) if ($table->delete($id) === true) { + JLoader::import('components.com_tjfields.tables.fieldsvalue', JPATH_ADMINISTRATOR); + $itemTable = JTable::getInstance('FieldsValue', 'TjfieldsTable', array('dbo', $db)); + $itemTable->load(array('content_id' => $contentId)); + + $dispatcher = JDispatcher::getInstance(); + JPluginHelper::importPlugin('actionlog', 'tjucm'); + $dispatcher->trigger('tjUcmOnAfterItemDelete', array($itemTable)); + $this->deleteExtraFieldsData($id, $table->client); return $id; diff --git a/src/components/com_tjucm/site/models/items.php b/src/components/com_tjucm/site/models/items.php index 62a62ecf..da7e4166 100644 --- a/src/components/com_tjucm/site/models/items.php +++ b/src/components/com_tjucm/site/models/items.php @@ -93,7 +93,7 @@ protected function populateState($ordering = "a.id", $direction = "DESC") foreach ($fields as $field) { $filterValue = $app->getUserStateFromRequest($this->context . '.' . $field->name, $field->name, '', 'STRING'); - $this->setState('filter.field.' . $field->name, $filterValue); + $this->setState('filter.field.' . $field->name, $filterValue); } if (empty($ucmType)) @@ -272,7 +272,7 @@ protected function getListQuery() else { // If no search results found then do not return any record - $query->where($db->quoteName('a.id') . '=0'); + $query->where($db->quoteName('a.id') . '=0'); } } @@ -363,7 +363,7 @@ private function filterContent() $query->where($db->quoteName('fv'.$filterFieldsCount.'.value') . ' LIKE ' . $db->q('%' . $search . '%')); $filterApplied = 1; - } + } // For filterable fields JLoader::import('components.com_tjfields.models.fields', JPATH_ADMINISTRATOR);