<?php

/**
 * Class file for decoding settings audit logs.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS
 * @copyright Copyright (c) 2016 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/**
 * cfSettingsAuditHelper Class
 *
 * Class to provide decoding for settings audit trails.
 *
 * @package clearFusionCMS
 */
class cfSettingsAuditHelper extends cfAuditHelper {

	/**
	 * Convert the raw data to a human readable message.
	 *
	 * @param array $data The audit data.
	 * @return string The message string.
	 */
	function getMessage($data) {
		$params = empty($data['params']) ? [] : json_decode($data['params'], true);

		switch($data['action']) {
			case cfSettingsAudit::UPDATE:
				$msg = sprintf(__('Updated the settings for <strong>%1s / %2s</strong>.', 'cfBackend'), $params['module'], $params['name']);
				break;
			default:
				$msg = parent::getMessage($data);
				break;
		}

		return $msg;
	}

	/**
	 * @inheritdoc
	 */
	function printData($data) {
		if(!empty($data['previous'])) {
			if(clearFusionCMS::getUser()->hasPermission('core.auditSettings'))
				return $this->_printData(json_decode($data['previous'], true));
			else
				return __('You do not have permission to view previous settings data.', 'cfBackend');
		}
		else
			return '';
	}
}
