diff --git a/src/components/com_tjcertificate/administrator/controllers/agency.json.php b/src/components/com_tjcertificate/administrator/controllers/agency.json.php
new file mode 100644
index 00000000..eeb6c606
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/controllers/agency.json.php
@@ -0,0 +1,93 @@
+
+ * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+// No direct access to this file
+defined('_JEXEC') or die('Restricted access');
+
+use Joomla\CMS\Factory;
+use Joomla\CMS\Language\Text;
+use Joomla\CMS\MVC\Controller\FormController;
+use Joomla\CMS\Session\Session;
+use Joomla\CMS\Response\JsonResponse;
+use Joomla\CMS\HTML\HTMLHelper;
+
+/**
+ * The Tj Certificate Agency controller
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class TjCertificateControllerAgency extends FormController
+{
+ protected $comMultiAgency = 'com_multiagency';
+
+ /**
+ * Function to get agency users
+ *
+ * @return void|boolean
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getAgencyUsers()
+ {
+ $app = Factory::getApplication();
+
+ if (!Session::checkToken())
+ {
+ $app->enqueueMessage(Text::_('JINVALID_TOKEN'), 'error');
+ echo new JsonResponse(null, null, true);
+ $app->close();
+ }
+
+ // Get the current user id
+ $user = Factory::getuser();
+
+ if (!$user->id)
+ {
+ return false;
+ }
+
+ if (!$user->authorise('core.manage.own.agency.user', $this->comMultiAgency))
+ {
+ return false;
+ }
+
+ $agencyId = $app->input->get('agency_id', 0, 'INT');
+
+ $model = $this->getModel();
+
+ if ($agencyId)
+ {
+ if (!$model->validateUserAgency($agencyId))
+ {
+ $app->enqueueMessage(Text::_('COM_TJCERTIFICATE_INVALID_ORGANIZATION'), 'error');
+ echo new JsonResponse(null, null, true);
+ $app->close();
+ }
+ }
+
+ $userOptions = array();
+
+ // Initialize array to store dropdown options
+ $userOptions[] = HTMLHelper::_('select.option', "", Text::_('COM_TJCERTIFICATE_AGENCY_USER_SELECT'));
+
+ $users = $model->getUsers($agencyId);
+
+ if (!empty($users))
+ {
+ foreach ($users as $user)
+ {
+ $userOptions[] = HTMLHelper::_('select.option', $user->id, trim($user->name));
+ }
+ }
+
+ echo new JsonResponse($userOptions);
+ $app->close();
+ }
+}
diff --git a/src/components/com_tjcertificate/administrator/controllers/bulktrainingrecord.json.php b/src/components/com_tjcertificate/administrator/controllers/bulktrainingrecord.json.php
new file mode 100644
index 00000000..492ac0db
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/controllers/bulktrainingrecord.json.php
@@ -0,0 +1,156 @@
+
+ * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+// No direct access to this file
+defined('_JEXEC') or die('Restricted access');
+
+use Joomla\CMS\Factory;
+use Joomla\CMS\Language\Text;
+use Joomla\CMS\MVC\Controller\FormController;
+use Joomla\CMS\Session\Session;
+use Joomla\CMS\Response\JsonResponse;
+use Joomla\CMS\Component\ComponentHelper;
+
+/**
+ * The Tj Certificate Training Records controller
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class TjCertificateControllerBulkTrainingRecord extends FormController
+{
+ protected $comMultiAgency = 'com_multiagency';
+
+ /**
+ * Function to save multiple records
+ *
+ * @param string $key The name of the primary key of the URL variable.
+ *
+ * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function save($key = null, $urlVar = null)
+ {
+ $app = Factory::getApplication();
+
+ if (!Session::checkToken())
+ {
+ $app->enqueueMessage(Text::_('JINVALID_TOKEN'), 'error');
+ echo new JsonResponse(null, null, true);
+ $app->close();
+ }
+
+ $user = Factory::getUser();
+ $data = $app->input->post->get('jform', array(), 'array');
+
+ $model = $this->getModel();
+
+ // Validate the posted data.
+ $form = $model->getForm($data, false);
+ $data = $model->validate($form, $data);
+
+ if ($data == false)
+ {
+ $errors = $model->getErrors();
+
+ if (!empty($errors))
+ {
+ $msg = array();
+
+ // Push up to three validation messages out to the user.
+ for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
+ {
+ if ($errors[$i] instanceof Exception)
+ {
+ $msg[] = $errors[$i]->getMessage();
+ }
+ else
+ {
+ $msg[] = $errors[$i];
+ }
+ }
+
+ $errormsg = implode(" ", $msg);
+ echo new JsonResponse(0, $errormsg, true);
+ }
+ }
+ else
+ {
+ $params = ComponentHelper::getParams('com_tjcertificate');
+ $userIds = $data['assigned_user_id'];
+ $data['client'] = "external";
+ $data['is_external'] = 1;
+
+ unset($data['assigned_user_id']);
+
+ foreach ($userIds as $userId)
+ {
+ if (ComponentHelper::isEnabled($this->comMultiAgency) && $params->get('enable_multiagency'))
+ {
+ $manageOwn = $user->authorise('core.manage.own.agency.user', $this->comMultiAgency);
+ $manage = $user->authorise('core.manage.all.agency.user', $this->comMultiAgency);
+
+ if ($manageOwn && empty($manage))
+ {
+ $agencyModel = TJCERT::model('Agency', array('ignore_request' => true));
+
+ // Get agencies of logged-in user and assigned user
+ $assignedUserAgencies = $agencyModel->getUserAgencies($userId);
+ $loggedInUserAgencies = $agencyModel->getUserAgencies($user->id);
+
+ $result = array();
+
+ if (!empty($assignedUserAgencies && $loggedInUserAgencies))
+ {
+ // Convert object to array
+ $assignedUserAgencyArr = array_column($assignedUserAgencies, 'id');
+ $loggedInUserAgencyArr = array_column($loggedInUserAgencies, 'id');
+
+ // Compare both users agencies
+ $result = array_intersect($loggedInUserAgencyArr, $assignedUserAgencyArr);
+ }
+
+ if (empty($result))
+ {
+ continue;
+ }
+ }
+ }
+
+ $data['user_id'] = $userId;
+ $returnData = array();
+
+ if (ComponentHelper::isEnabled('com_tjqueue') && $params->get('tjqueue_records'))
+ {
+ $recordsModel = TJCERT::model('BulkTrainingRecord', array('ignore_request' => true));
+ $response = $recordsModel->addToQueue($data);
+ $msg = $response ? Text::_("COM_TJCERTIFICATE_RECORDS_ADDED_TO_QUEUE_SUCCESSFULLY") : Text::_("COM_TJCERTIFICATE_RECORDS_FAILED");
+ $returnData['msg'] = $msg;
+ }
+ else
+ {
+ $certificateModel = TJCERT::model('Certificate', array('ignore_request' => true));
+ $certificateModel->save($data);
+ $certificateIds[] = $certificateModel->getState('certificate.id');
+
+ if ($certificateIds)
+ {
+ $returnData['msg'] = Text::sprintf('COM_TJCERTIFICATE_TOTAL_RECORDS_ADDED', count($certificateIds));
+ }
+ }
+ }
+
+ echo new JsonResponse($returnData);
+ $app->close();
+ }
+ }
+}
diff --git a/src/components/com_tjcertificate/administrator/controllers/bulktrainingrecord.php b/src/components/com_tjcertificate/administrator/controllers/bulktrainingrecord.php
new file mode 100644
index 00000000..8a6fe68c
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/controllers/bulktrainingrecord.php
@@ -0,0 +1,23 @@
+
+ * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+// No direct access to this file
+defined('_JEXEC') or die('Restricted access');
+
+use Joomla\CMS\MVC\Controller\FormController;
+
+/**
+ * The Tj Certificate Training Records controller
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class TjCertificateControllerBulkTrainingRecord extends FormController
+{
+}
diff --git a/src/components/com_tjcertificate/administrator/controllers/certificate.php b/src/components/com_tjcertificate/administrator/controllers/certificate.php
index 337faeb7..8c2414ba 100644
--- a/src/components/com_tjcertificate/administrator/controllers/certificate.php
+++ b/src/components/com_tjcertificate/administrator/controllers/certificate.php
@@ -24,6 +24,48 @@
*/
class TjCertificateControllerCertificate extends FormController
{
+ /**
+ * The client for which the templates are being created.
+ *
+ * @var string
+ * @since __DEPLOY_VERSION__
+ */
+ protected $client;
+
+ /**
+ * The extension for which the templates are being created.
+ *
+ * @var string
+ * @since __DEPLOY_VERSION__
+ */
+ protected $extension;
+
+ /**
+ * Constructor.
+ *
+ * @param array $config An optional associative array of configuration settings.
+ *
+ * @since __DEPLOY_VERSION__
+ * @see JControllerLegacy
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct($config);
+
+ $app = Factory::getApplication();
+ $jinput = $app->input;
+
+ if (empty($this->extension))
+ {
+ $this->extension = $jinput->get('extension', '');
+ }
+
+ if (empty($this->client))
+ {
+ $this->client = $jinput->get('client', '');
+ }
+ }
+
/**
* Method to download issued certificate.
*
@@ -48,15 +90,22 @@ public function download()
$certificate = TJCERT::Certificate();
+ $certificateObj = $certificate::validateCertificate($uniqueCertificateId);
+
+ // If $uniqueCertificateId is not valid then object is empty so need to handle error (CALL TO A MEMBER FUNCTION CANDOWNLOAD() ON BOOLEAN)
+ if (!$certificateObj->id)
+ {
+ $app->enqueueMessage(Text::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
+ $app->redirect('index.php');
+ }
+
// Check user having permission to download
- if (!$certificate::canDownload($uniqueCertificateId))
+ if (!$certificateObj->canDownload())
{
$app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'));
$app->redirect('index.php');
}
- $certificateObj = $certificate::validateCertificate($uniqueCertificateId);
-
if (!$certificateObj->id)
{
$app->enqueueMessage(Text::_('COM_TJCERTIFICATE_ERROR_CERTIFICATE_EXPIRED'), 'error');
@@ -101,4 +150,53 @@ public function uploadCertificate()
jexit();
}
+
+ /**
+ * Gets the URL arguments to append to an item redirect.
+ *
+ * @param integer $recordId The primary key id for the item.
+ * @param string $urlVar The name of the URL variable for the id.
+ *
+ * @return string The arguments to append to the redirect URL.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id')
+ {
+ $append = parent::getRedirectToItemAppend($recordId);
+
+ if (!empty ($this->extension))
+ {
+ $append .= '&extension=' . $this->extension;
+ }
+ elseif (!empty ($this->client))
+ {
+ $append .= '&client=' . $this->client;
+ }
+
+ return $append;
+ }
+
+ /**
+ * Gets the URL arguments to append to a list redirect.
+ *
+ * @return string The arguments to append to the redirect URL.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ protected function getRedirectToListAppend()
+ {
+ $append = parent::getRedirectToListAppend();
+
+ if (!empty ($this->extension))
+ {
+ $append .= '&extension=' . $this->extension;
+ }
+ elseif (!empty ($this->client))
+ {
+ $append .= '&client=' . $this->client;
+ }
+
+ return $append;
+ }
}
diff --git a/src/components/com_tjcertificate/administrator/controllers/certificates.php b/src/components/com_tjcertificate/administrator/controllers/certificates.php
index 6fc7e820..0e96b607 100644
--- a/src/components/com_tjcertificate/administrator/controllers/certificates.php
+++ b/src/components/com_tjcertificate/administrator/controllers/certificates.php
@@ -12,6 +12,9 @@
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\MVC\Controller\AdminController;
+use Joomla\Utilities\ArrayHelper;
+use Joomla\CMS\Language\Text;
+use Joomla\CMS\Router\Route;
/**
* Certificate list controller class.
@@ -30,8 +33,50 @@ class TjCertificateControllerCertificates extends AdminController
*
* @since 1.0.0
*/
- public function getModel($name = 'Certificate', $prefix = 'TjCertificateModel')
+ public function getModel($name = 'Certificate', $prefix = 'TjCertificateModel', $config = [])
{
return parent::getModel($name, $prefix, array('ignore_request' => true));
}
+
+ /**
+ * Method to remove a record.
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function delete()
+ {
+ $this->checkToken();
+
+ // Get items to remove from the request.
+ $cid = $this->input->get('cid', array(), 'array');
+
+ $extension = $this->input->getCmd('extension', null);
+
+ if (!is_array($cid) || count($cid) < 1)
+ {
+ JError::raiseWarning(500, Text::_($this->text_prefix . '_NO_ITEM_SELECTED'));
+ }
+ else
+ {
+ // Get the model.
+ $model = $this->getModel();
+
+ // Make sure the item ids are integers
+ $cid = ArrayHelper::toInteger($cid);
+
+ // Remove the items.
+ if ($model->delete($cid))
+ {
+ $this->setMessage(Text::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid)));
+ }
+ else
+ {
+ $this->setMessage($model->getError());
+ }
+ }
+
+ $this->setRedirect(Route::_('index.php?option=com_tjcertificate&view=certificates', false));
+ }
}
diff --git a/src/components/com_tjcertificate/administrator/controllers/template.json.php b/src/components/com_tjcertificate/administrator/controllers/template.json.php
index 35ba7285..ff9c66d5 100644
--- a/src/components/com_tjcertificate/administrator/controllers/template.json.php
+++ b/src/components/com_tjcertificate/administrator/controllers/template.json.php
@@ -14,6 +14,8 @@
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
+use Joomla\CMS\Response\JsonResponse;
+use Joomla\CMS\Session\Session;
jimport('joomla.filesystem.folder');
@@ -84,4 +86,34 @@ public function loadDefaultTemplate()
echo new JResponseJson($templateData);
}
}
+
+ /**
+ * Function to load custom template
+ *
+ * @return object|void object
+ */
+ public function loadCustomTemplate()
+ {
+ if (!Session::checkToken('get'))
+ {
+ echo new JsonResponse(null, Text::_('JINVALID_TOKEN'), true);
+ }
+ else
+ {
+ $app = Factory::getApplication();
+ $input = $app->input;
+ $templateId = $input->get('templateId');
+
+ if (empty($templateId))
+ {
+ echo new JsonResponse(null, Text::_('COM_TJCERTIFICATE_ERROR_SOMETHING_WENT_WRONG'), true);
+
+ return;
+ }
+
+ $tjCertificateTemplate = TJCERT::Template($templateId);
+
+ echo new JsonResponse($tjCertificateTemplate->body);
+ }
+ }
}
diff --git a/src/components/com_tjcertificate/administrator/controllers/templates.php b/src/components/com_tjcertificate/administrator/controllers/templates.php
index ca5065f8..cf14eada 100644
--- a/src/components/com_tjcertificate/administrator/controllers/templates.php
+++ b/src/components/com_tjcertificate/administrator/controllers/templates.php
@@ -29,7 +29,7 @@ class TjCertificateControllerTemplates extends AdminController
*
* @since 1.0.0
*/
- public function getModel($name = 'Template', $prefix = 'TjCertificateModel')
+ public function getModel($name = 'Template', $prefix = 'TjCertificateModel', $config = [])
{
return parent::getModel($name, $prefix, array('ignore_request' => true));
}
diff --git a/src/components/com_tjcertificate/administrator/controllers/trainingrecord.json.php b/src/components/com_tjcertificate/administrator/controllers/trainingrecord.json.php
new file mode 100644
index 00000000..047aa41c
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/controllers/trainingrecord.json.php
@@ -0,0 +1,165 @@
+
+ * @copyright Copyright (C) 2009 - 2020 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+// No direct access to this file
+defined('_JEXEC') or die('Restricted access');
+
+use Joomla\CMS\Factory;
+use Joomla\CMS\Language\Text;
+use Joomla\Registry\Registry;
+use Joomla\Utilities\ArrayHelper;
+use Joomla\CMS\MVC\Controller\FormController;
+use Joomla\CMS\Filesystem\Folder;
+use Joomla\CMS\Filesystem\File;
+use Joomla\CMS\Component\ComponentHelper;
+use Joomla\CMS\Session\Session;
+use Joomla\CMS\Router\Route;
+use Joomla\CMS\Response\JsonResponse;
+use Joomla\CMS\Table\Table;
+
+JLoader::import("/techjoomla/media/storage/local", JPATH_LIBRARIES);
+
+/**
+ * The Tj Certificate Training Record controller
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class TjCertificateControllerTrainingRecord extends FormController
+{
+ /**
+ * Function to delete the record attachment
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function deleteAttachment()
+ {
+ $app = Factory::getApplication();
+
+ if (!Session::checkToken())
+ {
+ $app->enqueueMessage(Text::_('JINVALID_TOKEN'), 'error');
+ echo new JsonResponse(null, null, true);
+ $app->close();
+ }
+
+ // Get the current user id
+ $user = Factory::getuser();
+
+ if (!$user->id)
+ {
+ return false;
+ }
+
+ $clientId = $app->input->get('certificateId', 0, 'INT');
+ $mediaId = $app->input->get('mediaId', 0, 'INT');
+
+ if (!$mediaId && !$clientId)
+ {
+ echo new JsonResponse(null, Text::_("JERROR_ALERTNOAUTHOR"), true);
+ $app->close();
+ }
+
+ $model = $this->getModel();
+ $mediaPath = TJCERT::getMediaPath();
+ $client = TJCERT::getClient();
+ $result = $model->deleteMedia($mediaId, $mediaPath, $client, $clientId);
+
+ if ($result)
+ {
+ echo new JResponseJson($result, Text::_('COM_TJCERTIFICATE_ATTACHMENT_DELETED_SUCCESSFULLY'), false);
+ $app->close();
+ }
+ else
+ {
+ echo new JResponseJson(null, Text::_('COM_TJCERTIFICATE_ATTACHMENT_DELETED_FAILED'), true);
+ $app->close();
+ }
+ }
+
+ /**
+ * Method to delete the record from frontend.
+ *
+ * @return void|boolean
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function delete()
+ {
+ $app = Factory::getApplication();
+
+ if (!Session::checkToken())
+ {
+ $app->enqueueMessage(Text::_('JINVALID_TOKEN'), 'error');
+ echo new JsonResponse(null, null, true);
+ $app->close();
+ }
+
+ $user = Factory::getUser();
+ $mediaPath = TJCERT::getMediaPath();
+ $client = TJCERT::getClient();
+ $certificateId = $app->input->getInt('certificateId');
+ $manageOwn = $user->authorise('certificate.external.manageown', $client);
+ $manage = $user->authorise('certificate.external.manage', $client);
+ $deleteOwn = $user->authorise('certificate.external.deleteown', $client);
+ $delete = $user->authorise('certificate.external.delete', $client);
+ $allowDelete = false;
+
+ // If manageOwn and delete own permission then check own record and allow to delete record
+ if ($manageOwn && !$manage)
+ {
+ if ($deleteOwn)
+ {
+ $table = TJCERT::table("certificates");
+ $table->load(array('id' => (int) $certificateId, 'user_id' => $user->id));
+
+ if ($table->id)
+ {
+ $allowDelete = true;
+ }
+ else
+ {
+ echo new JsonResponse(null, Text::_('COM_TJCERTIFICATE_ERROR_SOMETHING_WENT_WRONG'), true);
+ $app->close();
+ }
+ }
+ }
+
+ // If user have manage all and delete all or allow to delete then delete the record
+ if (($manage && $delete) || $allowDelete)
+ {
+ $model = TJCERT::model('Certificate', array('ignore_request' => true));
+
+ // Remove the item
+ if ($model->delete($certificateId))
+ {
+ // Delete media
+ $model = $this->getModel();
+ JLoader::import("/techjoomla/media/tables/xref", JPATH_LIBRARIES);
+ $tableXref = Table::getInstance('Xref', 'TJMediaTable');
+ $tableXref->load(array('client_id' => $certificateId));
+
+ if ($tableXref->media_id)
+ {
+ $model->deleteMedia($tableXref->media_id, $mediaPath, $client, $certificateId);
+ }
+
+ echo new JsonResponse($result, Text::_('COM_TJCERTIFICATE_CERTIFICATE_DELETED_SUCCESSFULLY'), false);
+ $app->close();
+ }
+ else
+ {
+ echo new JsonResponse(null, Text::_('COM_TJCERTIFICATE_CERTIFICATE_DELETED_FAILED'), true);
+ $app->close();
+ }
+ }
+ }
+}
diff --git a/src/components/com_tjcertificate/administrator/controllers/trainingrecord.php b/src/components/com_tjcertificate/administrator/controllers/trainingrecord.php
new file mode 100644
index 00000000..8b4cb5f4
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/controllers/trainingrecord.php
@@ -0,0 +1,255 @@
+
+ * @copyright Copyright (C) 2009 - 2020 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+// No direct access to this file
+defined('_JEXEC') or die('Restricted access');
+
+use Joomla\CMS\Factory;
+use Joomla\CMS\Language\Text;
+use Joomla\Registry\Registry;
+use Joomla\Utilities\ArrayHelper;
+use Joomla\CMS\MVC\Controller\FormController;
+use Joomla\CMS\Filesystem\Folder;
+use Joomla\CMS\Filesystem\File;
+use Joomla\CMS\Component\ComponentHelper;
+use Joomla\CMS\Session\Session;
+use Joomla\CMS\Router\Route;
+
+JLoader::import("/techjoomla/media/storage/local", JPATH_LIBRARIES);
+
+/**
+ * The Tj Certificate Training Record controller
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class TjCertificateControllerTrainingRecord extends FormController
+{
+ /**
+ * Method to save a training record data.
+ *
+ * @param string $key The name of the primary key of the URL variable.
+ * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
+ *
+ * @return boolean|void Incase of error boolean and in case of success void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function save($key = null, $urlVar = null)
+ {
+ // Check for request forgeries.
+ $this->checkToken();
+ $app = Factory::getApplication();
+ $user = Factory::getUser();
+ $recordId = $app->input->getInt('id');
+ $params = ComponentHelper::getParams('com_tjcertificate');
+ $task = $this->getTask();
+
+ if (!$user->id)
+ {
+ throw new Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
+ }
+
+ $data = $app->input->get('jform', array(), 'array');
+
+ $model = $this->getModel();
+
+ // Validate the posted data.
+ $form = $model->getForm($data, false);
+
+ if (!$form)
+ {
+ throw new \Exception($model->getError(), 500);
+ }
+
+ $validData = $model->validate($form, $data);
+
+ // Check for validation errors.
+ if ($validData === false)
+ {
+ // Get the validation messages.
+ $errors = $model->getErrors();
+
+ if (!empty($errors))
+ {
+ // Push up to three validation messages out to the user.
+ for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
+ {
+ if ($errors[$i] instanceof Exception)
+ {
+ $app->enqueueMessage($errors[$i]->getMessage(), 'warning');
+ }
+ else
+ {
+ $app->enqueueMessage($errors[$i], 'warning');
+ }
+ }
+ }
+
+ // Save the data in the session.
+ $app->setUserState('com_tjcertificate.edit.trainingrecord.data', $data);
+
+ // Redirect back to the edit screen.
+ $this->setRedirect(Route::_('index.php?option=com_tjcertificate&view=trainingrecord&layout=edit&id=' . $recordId, false));
+
+ return false;
+ }
+
+ if ($validData['assigned_user_id'])
+ {
+ $validData['user_id'] = $validData['assigned_user_id'];
+ }
+ else
+ {
+ $validData['user_id'] = $user->id;
+ }
+
+ $validData['client'] = "external";
+ $validData['state'] = isset($validData['state']) ? $validData['state'] : "-1";
+ $validData['is_external'] = 1;
+
+ $file = $app->input->files->get('jform', array(), 'array');
+
+ if (!empty($file['cert_file']))
+ {
+ $validData['old_media_ids'] = $app->input->get('oldFiles', 0, 'INT');
+ $uploadData = $model->uploadMedia($file, $validData);
+ $validData['cert_file'] = $uploadData['source'];
+ }
+
+ $certificateModel = TJCERT::model('Certificate', array('ignore_request' => true));
+
+ $certificateModel->save($validData);
+
+ $modelMediaXref = TJMediaXref::getInstance();
+
+ if ($uploadData['id'])
+ {
+ $mediaData['id'] = '';
+ $mediaData['client_id'] = $certificateModel->getState('certificate.id');
+ $mediaData['media_id'] = $uploadData['id'];
+ $mediaData['client'] = TJCERT::getClient();
+ $modelMediaXref->bind($mediaData);
+ $modelMediaXref->save();
+ }
+
+ $this->setMessage(Text::_('COM_TJCERTIFICATE_TRAINING_RECORD_SAVE_SUCCESSFULLY'));
+
+ if ($task === "apply")
+ {
+ // Redirect back to the edit screen.
+ $this->setRedirect(
+ Route::_('index.php?option=com_tjcertificate&view=trainingrecord&layout=edit&id=' . $certificateModel->getState('certificate.id'), false)
+ );
+ }
+
+ // Save task using to "Save & Close" action which is used only in backend
+ if ($task === "save")
+ {
+ $site = $app->input->get('site', 'f', 'string');
+
+ if ($site == 'f')
+ {
+ // Redirect to the list screen.
+ $this->setRedirect(
+ Route::_('index.php?option=com_tjcertificate&view=certificates&layout=my', false)
+ );
+ }
+ else
+ {
+ // Redirect to the list screen.
+ $this->setRedirect(
+ Route::_('index.php?option=com_tjcertificate&view=certificates', false)
+ );
+ }
+ }
+
+ // Flush the data from the session.
+ $app->setUserState('com_tjcertificate.edit.trainingrecord.data', null);
+ }
+
+ /**
+ * Cancel operation
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function cancel($key = null)
+ {
+ // Check for request forgeries.
+ $this->checkToken('request');
+
+ // Clear data from session.
+ \JFactory::getApplication()->setUserState('com_tjcertificate.edit.trainingrecord.data', null);
+
+ $this->setRedirect(Route::_('index.php?option=com_tjcertificate&view=certificates&layout=my', false));
+ }
+
+ /**
+ * Downloads the file requested by user
+ *
+ * @return boolean|void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function downloadAttachment()
+ {
+ $app = Factory::getApplication();
+ $user = Factory::getUser();
+
+ if (!$user->id)
+ {
+ throw new Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
+
+ return false;
+ }
+
+ $clientId = $app->input->get('recordId', '', 'INT');
+ $mediaId = $app->input->get('id', '', 'INT');
+
+ $manageOwn = $user->authorise('certificate.external.manageown', 'com_tjcertificate');
+ $manage = $user->authorise('certificate.external.manage', 'com_tjcertificate');
+
+ // If manageOwn permission then check record owner can only download own record
+ if ($manageOwn && !$manage)
+ {
+ $table = TJCERT::table("certificates");
+ $table->load(array('id' => (int) $clientId, 'user_id' => $user->id));
+
+ if (!$table->id)
+ {
+ throw new Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
+ }
+ }
+
+ $params = ComponentHelper::getParams('com_tjcertificate');
+
+ if (!$mediaId && !$clientId)
+ {
+ return false;
+ }
+
+ $config = array();
+ $config['mediaId'] = $mediaId;
+
+ // Assign client id as Record Id
+ $config['client_id'] = $clientId;
+ $config['client'] = TJCERT::getClient();
+ $mediaPath = TJCERT::getMediaPath();
+ $mediaAttachmentData = TJMediaXref::getInstance($config);
+ $folderName = explode('.', $mediaAttachmentData->media->type);
+
+ $downloadPath = JPATH_SITE . '/' . $mediaPath;
+ $downloadPath = $downloadPath . '/' . $folderName[0] . '/' . $mediaAttachmentData->media->source;
+
+ $media = TJMediaStorageLocal::getInstance();
+ $media->downloadMedia($downloadPath);
+ }
+}
diff --git a/src/components/com_tjcertificate/administrator/includes/tjcertificate.php b/src/components/com_tjcertificate/administrator/includes/tjcertificate.php
index 70404a7d..cd3fd3f8 100644
--- a/src/components/com_tjcertificate/administrator/includes/tjcertificate.php
+++ b/src/components/com_tjcertificate/administrator/includes/tjcertificate.php
@@ -15,6 +15,7 @@
use Joomla\CMS\Table\Table;
use Joomla\String\StringHelper;
use Joomla\CMS\Component\ComponentHelper;
+use Joomla\CMS\HTML\HTMLHelper;
$language = JFactory::getLanguage();
$language->load('com_tjcertificate');
@@ -44,6 +45,10 @@ class TJCERT
*/
private static $config = null;
+ public static $client = "com_tjcertificate";
+
+ public static $mediaPath = "media/com_tjcertificate/external";
+
/**
* Retrieves a table from the table folder
*
@@ -130,4 +135,47 @@ public static function loadClass($className)
return self::$loadedClass[$className];
}
+
+ /**
+ * Initializes js lang constant dependencies
+ *
+ * @param string $location The location where the assets needs to load
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public static function init($location = 'site')
+ {
+ self::Language()->JsLanguageConstant();
+
+ if ($location == 'site')
+ {
+ HTMLHelper::stylesheet('media/com_tjcertificate/vendors/font-awesome-4.1.0/css/font-awesome.min.css');
+ }
+ }
+
+ /**
+ * Method to get client
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public static function getClient()
+ {
+ return self::$client;
+ }
+
+ /**
+ * Method to get external media path
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public static function getMediaPath()
+ {
+ return self::$mediaPath;
+ }
}
diff --git a/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.ini b/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.ini
index b52714cd..3812514d 100644
--- a/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.ini
+++ b/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.ini
@@ -9,7 +9,7 @@ COM_TJCERTIFICATE_CONFIGURATION="TJ Certificate Configuration"
COM_TJCERTIFICATE_GENEARAL_SETINGS="General"
COM_TJCERTIFICATE_CERTIFICATE_PREFIX_LABEL="Certificate Prefix"
COM_TJCERTIFICATE_CERTIFICATE_PREFIX_DESC="Unique Certificate Id Prefix"
-COM_TJCERTIFICATE_CERTIFICATE_RANDOM_STRING_LENTGH_LABEL="Certificate random string length"
+COM_TJCERTIFICATE_CERTIFICATE_RANDOM_STRING_LENTGH_LABEL="Certificate Random String Length"
COM_TJCERTIFICATE_CERTIFICATE_RANDOM_STRING_LENTGH_DESC="Each generated certificate as a code. The format of the code is [Certificate Prefix]-[Random number]. This option sets the length of the random number.
"
@@ -69,7 +69,7 @@ COM_TJCERTIFICATE_PAGE_ADD_CERTIFICATE="Issue Certificate: New"
COM_TJCERTIFICATE_PAGE_EDIT_CERTIFICATE="Issued Certificate: Edit"
COM_TJCERTIFICATE_PAGE_VIEW_CERTIFICATE="Issued Certificate: View"
-COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_ID="Unique Certificate ID"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_ID="Record Id"
COM_TJCERTIFICATE_CERTIFICATE_FORM_DESC_CERTIFICATE_ID="Unique Certificate ID generated using Prefix"
COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_TEMPLATE="Template"
COM_TJCERTIFICATE_CERTIFICATE_FORM_DESC_CERTIFICATE_TEMPLATE="Template"
@@ -82,10 +82,10 @@ COM_TJCERTIFICATE_CERTIFICATE_FORM_DESC_CERTIFICATE_CLIENT_ID="Id of client reco
COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_ISSUED_USER="User"
COM_TJCERTIFICATE_CERTIFICATE_FORM_DESC_CERTIFICATE_ISSUED_USER="User against whom the certificate is issued"
COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_COMMENT="Comment"
-COM_TJCERTIFICATE_CERTIFICATE_FORM_DESC_CERTIFICATE_ISSUED_COMMENT="Comment"
-COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_ISSUED_DATE="Issued Date"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_DESC_CERTIFICATE_ISSUED_COMMENT="Add Comment"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_ISSUED_DATE="Issue Date"
COM_TJCERTIFICATE_CERTIFICATE_FORM_DESC_CERTIFICATE_ISSUED_DATE="Certificate issue date"
-COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_EXPIRY_DATE="Expiry Date"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_EXPIRY_DATE="Expiration Date"
COM_TJCERTIFICATE_CERTIFICATE_FORM_DESC_CERTIFICATE_EXPIRY_DATE="Certificate expiry date"
;Certificate - List view
@@ -113,7 +113,6 @@ COM_TJCERTIFICATE_CERTIFICATE_FILTER_CERTIFICATE_CLIENT_SELECT="- Select Client
COM_TJCERTIFICATE_CERTIFICATE_FILTER_CERTIFICATE_CLIENT="Client"
COM_TJCERTIFICATE_CERTIFICATE_FILTER_DESC_CERTIFICATE_CLIENT="Client"
COM_TJCERTIFICATE_CERTIFICATE_FILTER_ISSUED_USER_SELECT="- Select Issued User -"
-COM_TJCERTIFICATE_CERTIFICATE_FILTER_ISSUED_USER="Issued User"
COM_TJCERTIFICATE_CERTIFICATE_FILTER_ISSUED_USER="Issue User"
COM_TJCERTIFICATE_CERTIFICATE_FILTER_PUBLISHED="Status"
COM_TJCERTIFICATE_CERTIFICATE_FILTER_PUBLISHED_DESC="Status"
@@ -195,10 +194,8 @@ COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_FILTER_SEARCH_LABEL="Search"
COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_FILTER_SEARCH_LABEL_DESC="Search in title. Prefix with ID:to search for a Template ID"
COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_FILTER_CERTIFICATE_SELECT_CLIENT="- Select Client -"
COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_FILTER_DESC_CERTIFICATE_CLIENT="Client"
-COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_FILTER_DESC_CERTIFICATE_CLIENT="Client"
COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_FILTER_ISSUED_SELECT_USER="- Select Created By -"
COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_FILTER_ISSUED_USER="Created By"
-COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_FILTER_ISSUED_USER="Created By"
COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_FILTER_PUBLIC="Access"
COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_FILTER_PUBLIC_DESC="Access"
COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_PRIVATE="Private"
@@ -233,7 +230,7 @@ COM_TJCERTIFICATE_BLOCKED_USER="Unknown / Deleted User"
; Certificate access
COM_TJCERTIFICATE_SHOW_PUBLIC_PRIVATE="Set Certificate Privacy"
COM_TJCERTIFICATE_SHOW_PUBLIC_PRIVATE_DESC="If 'Private' option is selected then only the owner is authorised to view the certificate"
-COM_TJCERTIFICATE_SHOW_SEARCH_BOX="Show search box on certificate view"
+COM_TJCERTIFICATE_SHOW_SEARCH_BOX="Show Search Box On Certificate View"
COM_TJCERTIFICATE_SHOW_SEARCH_BOX_DESC="Select option 'Yes' to show search box"
COM_TJCERTIFICATE_OPTION_PUBLIC="Public"
COM_TJCERTIFICATE_OPTION_PRIVATE="Private"
@@ -246,6 +243,14 @@ COM_TJCERTIFICATE_SOCIAL_SHARING_FACEBOOK="Facebook share"
COM_TJCERTIFICATE_SOCIAL_SHARING_LINKEDIN="LinkedIn share"
COM_TJCERTIFICATE_SOCIAL_SHARING_TWITTER="Twitter share"
COM_TJCERTIFICATE_SOCIAL_SHARING_OPTIONS="Select social sharing options"
+COM_TJCERTIFICATE_LINKEDIN_PROFILE_BTN="Enable Linkedin 'Add to profile' button"
+COM_TJCERTIFICATE_LINKEDIN_PROFILE_BTN_DESC="Enable 'Add to profile' button to add the certificate in profile"
+COM_TJCERTIFICATE_LINKEDIN_ORGANIZATION_INFO="Select Organisation name or Organisation Id to pass in Url"
+COM_TJCERTIFICATE_LINKEDIN_ORGANIZATION_INFO_DESC="on option selection, link parameter will change accordingly"
+COM_TJCERTIFICATE_LINKEDIN_ORGANIZATION_NAME="Organization Name"
+COM_TJCERTIFICATE_LINKEDIN_ORGANIZATION_ID="Organization Id"
+COM_TJCERTIFICATE_LINKEDIN_ORGANIZATION_ID_NAME="Add linkedIn organization name or Id"
+COM_TJCERTIFICATE_LINKEDIN_ORGANIZATION_ID_NAME_DESC="Your organization ID (if your organization has an existing page on LinkedIn) or Your organization name (if your organization doesn’t have an existing page on LinkedIn)"
;Certificate Menu option
COM_TJCERTIFICATE_CERTIFICATE_TEXT_FILTER="Show Free Text Filter"
@@ -268,3 +273,134 @@ COM_TJCERTIFICATE_CERTIFICATE_FILTER_CERTIFICATE_TYPE_SELECT="- Select Type -"
COM_TJCERTIFICATE_CLIENT_COM_TJLMS_COURSE="Course"
COM_TJCERTIFICATE_CLIENT_COM_JTICKETING_EVENT="Event"
COM_TJCERTIFICATE_CERTIFICATE_LIST_VIEW_TYPE="Type"
+
+;__DEPLOY_VERSION__
+;Global config - Certificate Image Generation
+COM_TJCERTIFICATE_IMAGE_GENERATION="Certificate Image"
+COM_TJCERTIFICATE_IMAGE_GENERATION_SETTINGS="Certificate Image Generation Settings"
+COM_TJCERTIFICATE_IMAGE_GENERATION_TYPE="Image Generation Type"
+COM_TJCERTIFICATE_IMAGE_GENERATION_TYPE_DESC="There are two ways certificate image can be generated. 1) By using JavaScript Canvas librabry 2) Using PHP ImageMagick library"
+COM_TJCERTIFICATE_IMAGE_GENERATION_TYPE_CANVAS="HTML2Canvas Library"
+COM_TJCERTIFICATE_IMAGE_GENERATION_TYPE_IMAGICK="PHP ImageMagick Library"
+COM_TJCERTIFICATE_IMAGE_GENERATION_SETTINGS_NOTE="Please note:
"
+
+;__DEPLOY_VERSION__
+;Permission for external record
+COM_TJCERTIFICATE_CLIENT_EXTERNAL="External"
+COM_TJCERTIFICATE_PERMISSION_CREATE_EXTERNAL_CERTIFICATE="Create training records"
+COM_TJCERTIFICATE_PERMISSION_CREATE_EXTERNAL_CERTIFICATE_DESC="Allow users to create training records"
+COM_TJCERTIFICATE_PERMISSION_MANAGE_EXTERNAL_CERTIFICATE="Manage training records"
+COM_TJCERTIFICATE_PERMISSION_MANAGE_EXTERNAL_CERTIFICATE_DESC="Allow users to manage training records"
+COM_TJCERTIFICATE_PERMISSION_MANAGEOWN_EXTERNAL_CERTIFICATE="Manage own training records"
+COM_TJCERTIFICATE_PERMISSION_MANAGEOWN_EXTERNAL_CERTIFICATE_DESC="Allow users to manage own training records"
+
+;__DEPLOY_VERSION__
+;params email, media
+COM_TJCERTIFICATE_EMAIL_SETTINGS="Email Notifications"
+COM_TJCERTIFICATE_ADMIN_EMAIL="Admin email address"
+COM_TJCERTIFICATE_ADMIN_EMAIL_DESC="Add comma separated admin email address"
+COM_TJCERTIFICATE_MEDIA_SETS="Media"
+COM_TJCERTIFICATE_UPLOAD_MAX_SIZE="Maximum Size (in MB)"
+COM_TJCERTIFICATE_UPLOAD_MAX_SIZE_DESC="The maximum size for an upload (in megabytes). Use zero for no limit. Note: your server has a maximum limit."
+COM_TJCERTIFICATE_LEGAL_EXTENSION="Allowed Extensions (File Types)"
+COM_TJCERTIFICATE_LEGAL_EXTENSION_DESC="Extensions (file types) you are allowed to upload (comma separated)."
+COM_TJCERTIFICATE_N_RECORD_PUBLISHED="%d record(s) successfully published"
+COM_TJCERTIFICATE_N_RECORD_UNPUBLISHED="%d record(s) successfully unpublished"
+
+;Date format
+COM_TJCERTIFICATE_DATE_FORMAT_TO_SHOW="Date format"
+COM_TJCERTIFICATE_DATE_FORMAT_TO_SHOW_DESC="Date format to show on site except filters having date format"
+COM_TJCERTIFICATE_DATE_FORMAT_1="2012-01-02 01:30:00"
+COM_TJCERTIFICATE_DATE_FORMAT_2="Mon, Jan 02 01:30 AM"
+COM_TJCERTIFICATE_DATE_FORMAT_3="January 2, 2012, 1:30 am"
+COM_TJCERTIFICATE_DATE_FORMAT_4="01.02.12"
+COM_TJCERTIFICATE_DATE_FORMAT_5="2, 1, 2012"
+COM_TJCERTIFICATE_DATE_FORMAT_6="01-30-00, 2-01-12"
+COM_TJCERTIFICATE_DATE_FORMAT_7="01:30:00"
+COM_TJCERTIFICATE_DATE_FORMAT_CUSTOM="Custom"
+COM_TJCERTIFICATE_CUSTOM_DATE_FORMAT="Custom Date Format"
+COM_TJCERTIFICATE_CUSTOM_DATE_FORMAT_DESC="This option will used to set custom php date format"
+
+;Training record form
+COM_TJCERTIFICATE_FORM_LBL_CERTIFICATE_NAME="Name"
+COM_TJCERTIFICATE_FORM_LBL_CERTIFICATE_NAME_DESC="Training record name"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_ID_DESC="Record Id"
+COM_TJCERTIFICATE_FORM_LBL_CERTIFICATE_URL="Url (start url with http/https)"
+COM_TJCERTIFICATE_FORM_LBL_CERTIFICATE_URL_DESC="Add training record certificate Url"
+COM_TJCERTIFICATE_FORM_LBL_ISSUE_ORG="Issuing Organization"
+COM_TJCERTIFICATE_FORM_LBL_ISSUE_ORG_DESC="Organization Name"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_ISSUED_DATE_DESC="Add training record completion or certificate issue date"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_EXPIRY_DATE_DESC="Certificate expiry date"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_STATUS="Record Status"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_STATUS_DESC="Select record status"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_STATUS_ATTENDED="Attended"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_STATUS_COMPLETED="Completed"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_STATUS_PASSED="Passed"
+COM_TJCERTIFICATE_CERTIFICATE_FORM_STATUS_FAILED="Failed"
+COM_TJCERTIFICATE_FORM_LBL_CERTIFICATE_FILE="Certificate File pdf/image"
+COM_TJCERTIFICATE_FORM_LBL_CERTIFICATE_FILE_DESC="Upload certificate pdf/image"
+COM_TJCERTIFICATE_EXTERNAL_CERTIFICATE_DETAIL_VIEW_HEAD="Training Record"
+COM_TJCERTIFICATE_MEDIA_UPLOAD_ERROR="Uploaded media exceeds the allowed file size or it is an unsupported file."
+COM_TJCERTIFICATE_MEDIA_INVALID_FILE_TYPE="Invalid file type. Please enter the allowed file types."
+COM_TJCERTIFICATE_CONFIRM_DELETE_ATTACHMENT="Are you sure you want to delete this attachement?"
+COM_TJCERTIFICATE_ATTACHMENT_DELETE="Delete attachment"
+COM_TJCERTIFICATE_ATTACHMENT_DELETED_SUCCESSFULLY="Attachment deleted successfully"
+COM_TJCERTIFICATE_ATTACHMENT_DELETED_FAILED="Failed to delete attachment. Please try again after some time."
+COM_TJCERTIFICATE_ADD_EXTERNAL_CERTIFICATE="New Training Record"
+COM_TJCERTIFICATE_PAGE_ADD_TRAINING_RECORD="Training Record: New"
+COM_TJCERTIFICATE_PAGE_EDIT_TRAINING_RECORD="Training Record: Edit"
+COM_TJCERTIFICATE_CERTIFICATE_FRONTEND_PREVIEW="Frontend Preview"
+COM_TJCERTIFICATE_TRAINING_RECORD_SAVE_SUCCESSFULLY="Training record saved successfully"
+COM_TJCERTIFICATE_STATUS_PENDING="Pending"
+COM_TJCERTIFICATE_EXPIRY_DATE_VALIDATION_MESSAGE="Expiration date should be greater than issue date"
+COM_TJCERTIFICATE_LBL_CERTIFICATE_URL="Url"
+
+;config
+COM_TJCERTIFICATE_INTEGRATE_MULTIAGENCY="Enable Organization Support"
+COM_TJCERTIFICATE_INTEGRATE_MULTIAGENCY_DESC="If you enable this then you can add certificate for organization users and also you can filter certificates by using orginzation filter (Note: To work this functionality you need com_multiagency and com_cluster)."
+
+;List view and form
+COM_TJCERTIFICATE_CERTIFICATE_LIST_VIEW_USERNAME="User"
+COM_TJCERTIFICATE_CERTIFICATE_LIST_VIEW_ORG_NAME="Organization"
+COM_TJCERTIFICATE_ORG_SELECT="Select Organization"
+COM_TJCERTIFICATE_FORM_CLUSTER_LBL="Select user for Organization"
+COM_TJCERTIFICATE_AGENCY_USER_SELECT="Select User"
+
+;QR code config
+COM_TJCERTIFICATE_QR_CODE_SETTING="QR-code configuration"
+COM_TJCERTIFICATE_QR_CODE_WIDTH="QR code width"
+COM_TJCERTIFICATE_QR_CODE_WIDTH_DESC="Enter QR code width"
+COM_TJCERTIFICATE_QR_CODE_HEIGHT="QR code height"
+COM_TJCERTIFICATE_QR_CODE_HEIGHT_DESC="Enter QR code height"
+COM_TJCERTIFICATE_QR_CODE_SETTINGS_NOTE="Please note:
"
+
+;Record form
+COM_TJCERTIFICATE_ORGANIZATION_INVALID_USER="Invalid User"
+COM_TJCERTIFICATE_INVALID_ORGANIZATION="Invalid Organization"
+
+;Permission for external record delete
+COM_TJCERTIFICATE_PERMISSION_DELETE_EXTERNAL_CERTIFICATE="Delete training records"
+COM_TJCERTIFICATE_PERMISSION_DELETE_EXTERNAL_CERTIFICATE_DESC="Allow users to delete training records"
+COM_TJCERTIFICATE_PERMISSION_DELETEOWN_EXTERNAL_CERTIFICATE="Delete own records"
+COM_TJCERTIFICATE_PERMISSION_DELETEOWN_EXTERNAL_CERTIFICATE_DESC="Allow users to delete own training records"
+
+;Bulk Record Config
+COM_TJCERTIFICATE_TJQUEUE_SETTING="Use TjQueue while adding bulk records"
+COM_TJCERTIFICATE_TJQUEUE_SETTING_DESC="Set to 'Yes' if you want to use TjQueue while adding bulk records (Note: To make it work, you need com_tjqueue component, and also you need to enable certificate queue plugin)"
+COM_TJCERTIFICATE_RECORDS_USER_SELECT_LIMIT="User limit for adding bulk records"
+COM_TJCERTIFICATE_RECORDS_USER_SELECT_LIMIT_DESC="If the limit is set above 40 may result in a timeout."
+COM_TJCERTIFICATE_USER_LIMIT_MESSAGE="You cannot add more than the %s records."
+COM_TJCERTIFICATE_BULK_RECORD_SETTINGS="Bulk Training Record"
+COM_TJCERTIFICATE_BULK_RECORD_SETTINGS_NOTE="Please note:
"
+
+;Bulk Record form
+COM_TJCERTIFICATE_ADD_EXTERNAL_CERTIFICATES="Bulk Training Records"
+COM_TJCERTIFICATE_BULK_ADD_FORM_LBL_ASSIGNED_USERS="Select Users"
+COM_TJCERTIFICATE_BULK_ADD_FORM_LBL_NOTIFY_USERS="Notify Users"
+COM_TJCERTIFICATE_BULK_ADD_FORM_LBL_NOTIFY_USERS_DESC="Please tick this box if you want to send record add email to selected users"
+COM_TJCERTIFICATE_FORM_VALIDATATION_FAILED="Form Validation Failed"
+COM_TJCERTIFICATE_PAGE_ADD_TRAINING_RECORDS="Training Records"
+COM_TJCERTIFICATE_TOTAL_RECORDS_ADDED="Records added for %s user(s)"
+COM_TJCERTIFICATE_RECORDS_ADDED_TO_QUEUE_SUCCESSFULLY="Records added in queue"
diff --git a/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.sys.ini b/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.sys.ini
index b53b1258..a0a332fc 100644
--- a/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.sys.ini
+++ b/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.sys.ini
@@ -16,9 +16,6 @@ COM_TJCERTIFICATE_CERTIFICATE_MY_VIEW_DEFAULT_TITLE="My Certificates"
COM_TJCERTIFICATE_CERTIFICATE_MY_VIEW_DEFAULT_DESC="Display user's own certificates."
;Template list menu
-COM_TJCERTIFICATE_TEMPLATE_LIST_DEFAULT_TITLE="Templates"
-COM_TJCERTIFICATE_TEMPLATE_LIST_DEFAULT_DESC="List of templates"
-
COM_TJCERTIFICATE_TEMPLATE_LIST_DEFAULT_TITLE="Templates"
COM_TJCERTIFICATE_TEMPLATE_LIST_DEFAULT_DESC="List of templates"
COM_TJCERTIFICATE_TEMPLATE_FIELDSET_CLIENT_SELECT_LABEL="Client"
@@ -29,3 +26,9 @@ COM_TJCERTIFICATE_CERTIFICATE_LIST_DEFAULT_TITLE="Certificates"
COM_TJCERTIFICATE_CERTIFICATE_LIST_DEFAULT_DESC="List of certificates"
COM_TJCERTIFICATE_CERTIFICATE_FIELDSET_CLIENT_SELECT_LABEL="Client"
COM_TJCERTIFICATE_CERTIFICATE_FIELDSET_CLIENT_SELECT_DESC="Client"
+
+;Add record menu
+COM_TJCERTIFICATE_ADD_EXTERNAL_CERTIFICATE="Add training record"
+
+;Add bulk record menu
+COM_TJCERTIFICATE_ADD_BULK_RECORDS="Add bulk training records"
diff --git a/src/components/com_tjcertificate/administrator/layouts/preview.php b/src/components/com_tjcertificate/administrator/layouts/preview.php
new file mode 100644
index 00000000..02495bd8
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/layouts/preview.php
@@ -0,0 +1,39 @@
+
+ * @copyright Copyright (C) 2009 - 2020 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+// No direct access to this file
+defined('_JEXEC') or die('Restricted access');
+
+use Joomla\CMS\Language\Text;
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/com_tjcertificate/administrator/libraries/certificate.php b/src/components/com_tjcertificate/administrator/libraries/certificate.php
index 503b063a..b7795c1d 100644
--- a/src/components/com_tjcertificate/administrator/libraries/certificate.php
+++ b/src/components/com_tjcertificate/administrator/libraries/certificate.php
@@ -21,6 +21,9 @@
use Joomla\Registry\Registry;
use Dompdf\Dompdf;
use Dompdf\Options;
+use Joomla\CMS\Plugin\PluginHelper;
+use Joomla\CMS\HTML\HTMLHelper;
+use Joomla\CMS\Uri\Uri;
/**
* Certificate class. Handles all application interaction with a Certificate
@@ -57,8 +60,28 @@ class TjCertificateCertificate extends CMSObject
public $defaultCertPrefix = "CERT";
+ public $certImageDir = JPATH_SITE . '/media/com_tjcertificate/certificates/';
+
+ public $certTmpDir = JPATH_SITE . '/media/com_tjcertificate/tmp/';
+
protected static $certificateObj = array();
+ public $is_external = 0;
+
+ public $name = null;
+
+ public $cert_url = "";
+
+ public $cert_file = "";
+
+ public $issuing_org = "";
+
+ public $status = "";
+
+ public $created_by = "";
+
+ public $notify = 1;
+
/**
* Constructor activating the default information of the Certificate
*
@@ -282,6 +305,32 @@ public function getComment()
return $this->comment;
}
+ /**
+ * Set certificate issue date
+ *
+ * @param string $value comment.
+ *
+ * @return void.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function setIssuedDate($value = null)
+ {
+ $this->issued_on = $value;
+ }
+
+ /**
+ * Get certificate issue date
+ *
+ * @return string comment
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getIssuedDate()
+ {
+ return $this->issued_on;
+ }
+
/**
* Returns the global Certificate object
*
@@ -423,11 +472,19 @@ public function save()
// Check if new record
$isNew = empty($this->id);
- if ($isNew)
+ // Set current date if issued_on date is not set
+ if ($isNew && !$table->issued_on)
{
$table->issued_on = Factory::getDate()->toSql();
}
+ // If certificate id is not added from the form then add
+ if (empty($this->unique_certificate_id))
+ {
+ $options = new Registry;
+ $table->unique_certificate_id = $this->generateUniqueCertId($options);
+ }
+
// Store the user data in the database
if (!($table->store()))
{
@@ -438,9 +495,19 @@ public function save()
$this->id = $table->id;
- // Fire the onTjCertificateAfterSave event.
$dispatcher = \JEventDispatcher::getInstance();
+ if ($table->is_external && $isNew)
+ {
+ /* Send mail on record creation */
+ JLoader::import('components.com_tjcertificate.events.record', JPATH_SITE);
+ $tjCertificateTriggerRecord = new TjCertificateTriggerRecord;
+ $tjCertificateTriggerRecord->onAfterRecordSave($this, true);
+ $dispatcher->trigger('onTrainingRecordAfterAdded', array($isNew, $this));
+ }
+
+ // Fire the onTjCertificateAfterSave event.
+
$dispatcher->trigger('onTjCertificateAfterSave', array($isNew, $this));
}
catch (\Exception $e)
@@ -471,14 +538,36 @@ public function bind(&$array)
return false;
}
- // Bind the array
- if (!$this->setProperties($array))
+ $getPrivateProperties = $this->_getPrivateProperties();
+
+ $getPublicProperties = $this->_getPublicProperties();
+
+ $publicProperties = array();
+
+ foreach ($getPublicProperties as $key => $value)
+ {
+ $publicProperties[$value->name] = '';
+ }
+
+ $setPublicProperties = array_intersect_key($array, $publicProperties);
+
+ // Set public properties
+ if (!$this->setProperties($setPublicProperties))
{
$this->setError(Text::_('COM_TJCERTIFICATE_BINDING_ERROR'));
return false;
}
+ // Set private properties
+ foreach ($getPrivateProperties as $key => $value)
+ {
+ if (!empty($array[$value->name]))
+ {
+ $this->{$value->name} = $array[$value->name];
+ }
+ }
+
// Make sure its an integer
$this->id = (int) $this->id;
@@ -544,13 +633,22 @@ public static function getIssued($client, $clientId, $userId = 0, $expired = fal
*
* @param boolean $showSearchBox Show search box
*
+ * @param boolean $isExternal Check record is external
+ *
* @return string Certificate url.
*
* @since 1.0
*/
- public function getUrl($options, $showSearchBox = true)
+ public function getUrl($options, $showSearchBox = true, $isExternal = false)
{
- $url = 'index.php?option=com_tjcertificate&view=certificate&certificate=' . $this->unique_certificate_id;
+ if ($isExternal)
+ {
+ $url = 'index.php?option=com_tjcertificate&view=trainingrecord&id=' . $this->id;
+ }
+ else
+ {
+ $url = 'index.php?option=com_tjcertificate&view=certificate&certificate=' . $this->unique_certificate_id;
+ }
// If search box is true then only show search box param in URL
if ($showSearchBox)
@@ -565,7 +663,7 @@ public function getUrl($options, $showSearchBox = true)
if (isset($options['absolute']))
{
- return JUri::root() . substr(Route::_($url), strlen(JUri::base(true)) + 1);
+ return Route::link('site', $url, false, 0, true);
}
return Route::_($url);
@@ -605,7 +703,7 @@ public function getDownloadUrl($options = array())
/**
* Method to get certificate download url.
*
- * @param boolean $store Store as attachment for emails
+ * @param integer $store Store as attachment for emails
*
* @return boolean|string Certificate pdf url.
*
@@ -697,6 +795,10 @@ public function pdfDownload($store = 0)
readfile($certificatePdfName);
jexit();
}
+ elseif ($store == 2)
+ {
+ return $domPDF->output();
+ }
$domPDF->stream($certificatePdfName, array("Attachment" => 1));
@@ -769,12 +871,28 @@ public function issueCertificate($replacements, $options)
throw new Exception(Text::_('COM_TJCERTIFICATE_TEMPLATE_INVALID'));
}
- // Generate unique certificate id
- $this->unique_certificate_id = $this->generateUniqueCertId($options);
+ if (empty($this->unique_certificate_id))
+ {
+ // Generate unique certificate id
+ $this->unique_certificate_id = $this->generateUniqueCertId($options);
+ }
// Generate unique certificate id replacement
$replacements->certificate->cert_id = $this->unique_certificate_id;
+ $params = ComponentHelper::getParams('com_tjcertificate');
+
+ // Generate QR code of certificate.
+ $qrCodeWidth = $params->get('qr_code_width', 130);
+ $qrCodeHeight = $params->get('qr_code_height', 130);
+
+ $qrString = 'index.php?option=com_tjcertificate&view=certificate&certificate=' . $this->unique_certificate_id;
+ $qrString = Uri::root() . substr(Route::_($qrString, false), strlen(Uri::base(true)) + 1);
+ $qrString = urlencode($qrString);
+ $qrUrl = "https://chart.apis.google.com/chart?cht=qr&chs=";
+ $qrImage = $qrUrl . $qrCodeWidth . "x" . $qrCodeHeight . "&chl=" . $qrString . "&chld=H|0";
+ $replacements->certificate->qr_code = '';
+
// Generate certificate body
$this->generated_body = $this->generateCertificateBody($template->body, $replacements);
@@ -808,9 +926,26 @@ public function issueCertificate($replacements, $options)
}
// Save certificate
- $this->save();
+ if ($this->save())
+ {
+ // Remove old certificate image after re-generating the certificate
+ $path = JPATH_SITE . '/media/com_tjcertificate/certificates/';
+ $fileName = $this->unique_certificate_id . '.png';
- return self::getInstance($this->id);
+ if (JFile::exists($path . $fileName))
+ {
+ JFile::delete($path . $fileName);
+ }
+
+ // Generate Certificate Image
+ if ($params->get('cert_image_gen_type') == 'imagick')
+ {
+ // Generate image from PDF
+ $this->generateImageFromPDF($this->pdfDownload(2));
+ }
+
+ return self::getInstance($this->id);
+ }
}
catch (\Exception $e)
{
@@ -943,15 +1078,13 @@ protected function generateUniqueCertId($options)
}
/**
- * This function checks the certificate download permission
- *
- * @param STRING $uniqueCertificateId certificate Id
+ * This function checks the certificate download permission
*
* @return boolean
*
* @since __DEPLOY_VERSION__
*/
- public static function canDownload($uniqueCertificateId)
+ public function canDownload()
{
$user = Factory::getUser();
@@ -962,10 +1095,7 @@ public static function canDownload($uniqueCertificateId)
if ($user->authorise('certificate.download.own', 'com_tjcertificate'))
{
- $table = TJCERT::table("certificates");
- $table->load(array('unique_certificate_id' => $uniqueCertificateId));
-
- if ($user->get('id') == $table->user_id)
+ if ($user->get('id') == $this->user_id)
{
return true;
}
@@ -973,4 +1103,115 @@ public static function canDownload($uniqueCertificateId)
return false;
}
+
+ /**
+ * Method to get linkedIn add to profile url.
+ *
+ * @return STRING
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getAddToLinkedInProfileUrl()
+ {
+ $params = ComponentHelper::getParams('com_tjcertificate');
+ $config = Factory::getConfig();
+ $siteName = $config->get('sitename');
+
+ $issuedMonth = HTMLHelper::_('date', $this->issued_on, 'm');
+ $issuedYear = HTMLHelper::_('date', $this->issued_on, 'Y');
+
+ $expirationDetails = null;
+
+ if ($this->expired_on != '0000-00-00 00:00:00')
+ {
+ $expirationMonth = HTMLHelper::_('date', $this->expired_on, 'm');
+ $expirationYear = HTMLHelper::_('date', $this->expired_on, 'Y');
+ $expirationDetails = '&expirationYear=' . $expirationYear . '&expirationMonth=' . $expirationMonth;
+ }
+
+ $orgParam = '&' . $params->get('organization_info') . '=' . $params->get('organization_id_name');
+
+ // Get client data
+ $dispatcher = JDispatcher::getInstance();
+ PluginHelper::importPlugin('content');
+ $result = $dispatcher->trigger('getCertificateClientData', array($this->client_id, $this->client));
+ $clientData = $result[0];
+
+ $urlOptions = array();
+ $urlOptions['absolute'] = true;
+ $certificateUrl = $this->getURL($urlOptions, false);
+
+ $certificateTitle = $clientData->title ? $clientData->title : $siteName . ' ' . Text::_('COM_TJCERTIFICATE_CERTIFICATE_DETAIL_VIEW_HEAD');
+ $linkedInprofileUrl = 'https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME&name=' . $certificateTitle . $orgParam
+ . '&issueYear=' . $issuedYear . '&issueMonth=' . $issuedMonth . $expirationDetails
+ . '&certUrl=' . urlencode($certificateUrl) . '&certId=' . $this->unique_certificate_id;
+
+ return $linkedInprofileUrl;
+ }
+
+ /**
+ * Method to generate certificate image from PDF.
+ *
+ * @param string $domPDFOutput DomPDF output.
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function generateImageFromPDF($domPDFOutput)
+ {
+ if (extension_loaded('imagick'))
+ {
+ if (!JFolder::exists($this->certImageDir))
+ {
+ JFolder::create($this->certImageDir);
+ }
+
+ if (!JFolder::exists($this->certTmpDir))
+ {
+ JFolder::create($this->certTmpDir);
+ }
+
+ $tmpPDF = $this->certTmpDir . $this->unique_certificate_id . '.pdf';
+
+ file_put_contents($tmpPDF, $domPDFOutput);
+
+ $im = new Imagick;
+ $im->setResolution(72, 72);
+ $im->readimage($tmpPDF);
+ $im->setImageBackgroundColor('white');
+ $im->setImageAlphaChannel(imagick::ALPHACHANNEL_REMOVE);
+ $im->mergeImageLayers(imagick::LAYERMETHOD_FLATTEN);
+ $im->writeImage($this->certImageDir . $this->unique_certificate_id . '.png');
+ $im->clear();
+ $im->destroy();
+
+ if (JFile::exists($tmpPDF))
+ {
+ JFile::delete($tmpPDF);
+ }
+ }
+ }
+
+ /**
+ * Get formated date
+ *
+ * @param string $datetime The current offset
+ *
+ * @return string formatted datetime
+ *
+ * @since __DEPLOY_VERSION__
+ **/
+ public function getFormatedDate($datetime)
+ {
+ $params = ComponentHelper::getParams('com_tjcertificate');
+ $dateFormat = $params->get('date_format_show');
+
+ if ($dateFormat == "custom")
+ {
+ $dateFormat = $params->get('custom_format');
+ }
+
+ return HTMLHelper::_('date', $datetime, $dateFormat, true);
+ }
}
diff --git a/src/components/com_tjcertificate/administrator/libraries/language.php b/src/components/com_tjcertificate/administrator/libraries/language.php
new file mode 100644
index 00000000..02298065
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/libraries/language.php
@@ -0,0 +1,38 @@
+
+ * @copyright Copyright (C) 2009 - 2020 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+defined('_JEXEC') or die();
+
+use Joomla\CMS\Language\Text;
+
+/**
+ * TJCertificate language constant class for common methods
+ *
+ * @since _DEPLOY_VERSION_
+ */
+class TJCertificateLanguage
+{
+ /**
+ * Language constants to be used in js
+ *
+ * @return void
+ *
+ * @since _DEPLOY_VERSION_
+ */
+ public function JsLanguageConstant()
+ {
+ // Tjmedia js
+ Text::script('COM_TJCERTIFICATE_CONFIRM_DELETE_ATTACHMENT');
+ Text::script('COM_TJCERTIFICATE_MEDIA_INVALID_FILE_TYPE');
+ Text::script('COM_TJCERTIFICATE_MEDIA_UPLOAD_ERROR');
+ Text::script('COM_TJCERTIFICATE_DELETE_CERTIFICATE_MESSAGE');
+ Text::script('COM_TJCERTIFICATE_EXPIRY_DATE_VALIDATION_MESSAGE');
+ }
+}
diff --git a/src/components/com_tjcertificate/administrator/libraries/mails.php b/src/components/com_tjcertificate/administrator/libraries/mails.php
new file mode 100644
index 00000000..e34435f3
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/libraries/mails.php
@@ -0,0 +1,175 @@
+
+ * @copyright Copyright (C) 2009 - 2020 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+defined('_JEXEC') or die;
+jimport('techjoomla.tjnotifications.tjnotifications');
+
+use Joomla\CMS\Factory;
+use Joomla\CMS\User\User;
+use Joomla\CMS\Language\Text;
+use Joomla\CMS\Component\ComponentHelper;
+use Joomla\Registry\Registry;
+
+/**
+ * Class TjCertificateMails
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class TjCertificateMails
+{
+ protected $params;
+
+ protected $siteConfig;
+
+ protected $sitename;
+
+ protected $siteadminname;
+
+ protected $user;
+
+ protected $client;
+
+ protected $tjnotifications;
+
+ protected $siteinfo;
+
+ /**
+ * Method acts as a consturctor
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function __construct()
+ {
+ $this->params = ComponentHelper::getParams('com_tjcertificate');
+ $this->siteConfig = Factory::getConfig();
+ $this->sitename = $this->siteConfig->get('sitename');
+ $this->siteadminname = $this->siteConfig->get('fromname');
+ $this->user = Factory::getUser();
+ $this->client = TJCERT::getClient();
+ $this->tjnotifications = new Tjnotifications;
+
+ $this->siteinfo = new stdClass;
+ $this->siteinfo->sitename = $this->sitename;
+ }
+
+ /**
+ * Send mails when record is created
+ *
+ * @param OBJECT $recordDetails Record Detail
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function onAfterCreateRecord($recordDetails)
+ {
+ $adminRecipients = array();
+ $db = Factory::getDBO();
+
+ // Get all admin users
+ $query = $db->getQuery(true);
+
+ $query->select('id');
+ $query->from($db->quoteName('#__users'));
+ $query->where($db->quoteName('sendEmail') . '= 1');
+ $db->setQuery($query);
+ $adminUsers = $db->loadObjectList();
+
+ foreach ($adminUsers as $adminUser)
+ {
+ $adminRecipients[] = Factory::getUser($adminUser->id);
+ $adminRecipients['email']['to'][] = Factory::getUser($adminUser->id)->email;
+ }
+
+ $userEmailArray = array();
+
+ if ($recordDetails->getUserId())
+ {
+ $user = Factory::getUser($recordDetails->getUserId());
+ $userEmailArray[] = $user->email;
+ }
+
+ $recipients = array('email' => array('to' => $userEmailArray));
+
+ $adminkey = "createRecordMailToAdmin";
+ $userkey = "createRecordMailToUser";
+
+ $siteInfo = new stdClass;
+ $siteInfo->sitename = $this->sitename;
+
+ $replacements = new stdClass;
+ $replacements->info = $this->siteinfo;
+ $replacements->record = $recordDetails;
+ $replacements->user = $user;
+
+ $options = new Registry;
+ $options->set('record', $recordDetails);
+
+ // Mail to User after record added on behalf
+
+ if ($recordDetails->getUserId() != $recordDetails->created_by)
+ {
+ $assignUserkey = "assignRecordMailToUser";
+ $replacements->assigner = Factory::getUser($recordDetails->created_by);
+
+ $this->tjnotifications->send($this->client, $assignUserkey, $recipients, $replacements, $options);
+ }
+ else
+ {
+ // Mail to site admin
+ $this->tjnotifications->send($this->client, $adminkey, $adminRecipients, $replacements, $options);
+
+ // Mail to User
+ $this->tjnotifications->send($this->client, $userkey, $recipients, $replacements, $options);
+ }
+
+ return;
+ }
+
+ /**
+ * Send mail when record is edited
+ *
+ * @param OBJECT $recordDetails Record Detail
+ *
+ * @param int $isPublished Record state
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function onAfterRecordStateChange($recordDetails, $isPublished)
+ {
+ $userEmailArray = array();
+
+ if ($recordDetails->user_id)
+ {
+ $recordOwner = Factory::getUser($recordDetails->user_id);
+ $userEmailArray[] = $recordOwner->email;
+ }
+
+ $recipients = array('email' => array('to' => $userEmailArray));
+
+ $replacements = new stdClass;
+ $replacements->info = $this->siteinfo;
+ $replacements->record = $recordDetails;
+ $replacements->user = $recordOwner;
+
+ $siteinfo = new stdClass;
+ $siteinfo->sitename = $this->sitename;
+
+ $options = new Registry;
+ $options->set('record', $recordDetails);
+
+ // Mail to record owner
+ $this->tjnotifications->send($this->client, "recordApprovedMailToUser", $recipients, $replacements, $options);
+
+ return;
+ }
+}
diff --git a/src/components/com_tjcertificate/administrator/libraries/template.php b/src/components/com_tjcertificate/administrator/libraries/template.php
index 92774387..41f2ab37 100644
--- a/src/components/com_tjcertificate/administrator/libraries/template.php
+++ b/src/components/com_tjcertificate/administrator/libraries/template.php
@@ -276,8 +276,8 @@ private function getReplacementTagFile($client)
}
$clientDetails = explode(".", $client);
- $component = $clientDetails[0];
- $replacementFile = $clientDetails[1];
+ $component = !empty($clientDetails[0]) ? $clientDetails[0] : '';
+ $replacementFile = !empty($clientDetails[1]) ? $clientDetails[1] : '';
return TJ_CERTIFICATE_REPLACEMENT_TAG . '/' . $component . '/' . self::$replacementFolder . '/' . $replacementFile . '.json';
}
diff --git a/src/components/com_tjcertificate/administrator/models/agency.php b/src/components/com_tjcertificate/administrator/models/agency.php
new file mode 100644
index 00000000..1335eda5
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/models/agency.php
@@ -0,0 +1,180 @@
+
+ * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+// No direct access to this file
+defined('_JEXEC') or die('Restricted access');
+
+use Joomla\CMS\Factory;
+use Joomla\CMS\MVC\Model\AdminModel;
+use Joomla\CMS\Component\ComponentHelper;
+
+/**
+ * TjCertificate Agency Model.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class TjCertificateModelAgency extends AdminModel
+{
+ protected $comMultiAgency = 'com_multiagency';
+
+ public $params;
+
+ public $user;
+
+ public $manageOwn;
+
+ public $manage;
+
+ /**
+ * Constructor.
+ *
+ * @param array $config An optional associative array of configuration settings.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function __construct($config = array())
+ {
+ $this->params = ComponentHelper::getParams('com_tjcertificate');
+ $this->user = Factory::getuser();
+ $this->manageOwn = $this->user->authorise('core.manage.own.agency.user', $this->comMultiAgency);
+ $this->manage = $this->user->authorise('core.manage.all.agency.user', $this->comMultiAgency);
+
+ parent::__construct($config);
+ }
+
+ /**
+ * Abstract method for getting the form from the model.
+ *
+ * @param array $data Data for the form.
+ * @param boolean $loadData True if the form is to load its own data (default case), false if not.
+ *
+ * @return \JForm|boolean A \JForm object on success, false on failure
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getForm($data = array(), $loadData = true)
+ {
+ return;
+ }
+
+ /**
+ * Function to get users
+ *
+ * @param integer $agencyId agency id
+ *
+ * @return Object Users object
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getUsers($agencyId = null)
+ {
+ $db = Factory::getDBO();
+ $query = $db->getQuery(true);
+ $query->select('distinct(u.id), u.name');
+ $query->from($db->quoteName('#__users', 'u'));
+ $query->where($db->qn('u.block') . ' = 0');
+
+ if (ComponentHelper::isEnabled($this->comMultiAgency) && $this->params->get('enable_multiagency'))
+ {
+ $query->join('INNER', '#__tj_cluster_nodes AS cn ON cn.user_id = u.id');
+ $query->join('INNER', $db->qn('#__tj_clusters', 'clusters') .
+ ' ON (' . $db->qn('clusters.id') . ' = ' . $db->qn('cn.cluster_id') .
+ ' AND ' . $db->qn('clusters.client') . " = 'com_multiagency' ) ");
+ $query->join('INNER', $db->qn('#__tjmultiagency_multiagency', 'ml') .
+ ' ON (' . $db->qn('ml.id') . ' = ' . $db->qn('clusters.client_id') . ')');
+
+ // If user have manage all permission and no org selected then show all users
+ if ($this->manage && empty($agencyId))
+ {
+ $query->clear('join');
+ }
+ elseif ($this->manageOwn && empty($this->manage) && empty($agencyId))
+ {
+ // If user have only manage own permission and agency is not set then load own agency users
+
+ $loggedInUserAgencies = $this->getUserAgencies($this->user->id);
+
+ foreach ($loggedInUserAgencies as $loggedInUserAgency)
+ {
+ $loggedInUserAgencyArr[] = $loggedInUserAgency->id;
+ }
+
+ $query->where($db->quoteName('ml.id') . ' in (' . implode(',', $loggedInUserAgencyArr) . ')');
+ }
+ elseif ($agencyId)
+ {
+ $query->where($db->qn('ml.id') . ' = ' . (int) $agencyId);
+ }
+ }
+
+ $query->order($db->escape('u.name' . ' ' . 'asc'));
+
+ $db->setQuery($query);
+
+ return $db->loadObjectList();
+ }
+
+ /**
+ * Function to check user agency
+ *
+ * @param int $agencyId agency id
+ *
+ * @return integer|boolean
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function validateUserAgency($agencyId)
+ {
+ // If user having multiagency manage all permission then return true
+ if ($this->manage)
+ {
+ return true;
+ }
+
+ $db = Factory::getDBO();
+ $query = $db->getQuery(true);
+ $query->select($db->quoteName('u.id'));
+ $query->from($db->quoteName('#__users', 'u'));
+ $query->join('INNER', $db->quoteName('#__tj_cluster_nodes', 'cn') . ' ON ' . $db->quoteName('cn.user_id') . '=' . $db->quoteName('u.id'));
+ $query->join('INNER', $db->quoteName('#__tj_clusters', 'c') . ' ON ' . $db->quoteName('c.id') . '=' . $db->quoteName('cn.cluster_id'));
+ $query->join('INNER', $db->quoteName('#__tjmultiagency_multiagency', 'ml') .
+ ' ON ' . $db->quoteName('ml.id') . ' = ' . $db->quoteName('c.client_id')
+ );
+ $query->where($db->qn('ml.id') . ' = ' . (int) $agencyId);
+ $query->where($db->qn('cn.user_id') . ' = ' . (int) $this->user->id);
+ $db->setQuery($query);
+
+ return $db->loadResult();
+ }
+
+ /**
+ * Function to get user agency
+ *
+ * @param int $userId user id
+ *
+ * @return object
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getUserAgencies($userId)
+ {
+ $db = Factory::getDBO();
+ $query = $db->getQuery(true);
+ $query->select($db->quoteName('agency.id'));
+ $query->from($db->quoteName('#__tjmultiagency_multiagency', 'agency'));
+ $query->join('INNER', $db->quoteName('#__tj_clusters', 'c') . ' ON ' . $db->quoteName('c.client_id') . '=' . $db->quoteName('agency.id'));
+ $query->join('INNER', $db->quoteName('#__tj_cluster_nodes', 'cn') . ' ON ' . $db->quoteName('cn.cluster_id') . '=' . $db->quoteName('c.id'));
+ $query->Where($db->qn('agency.state') . '=' . 1);
+ $query->where($db->quoteName('cn.user_id') . ' = ' . (int) $userId);
+ $db->setQuery($query);
+
+ return $db->loadObjectList();
+ }
+}
diff --git a/src/components/com_tjcertificate/administrator/models/bulktrainingrecord.php b/src/components/com_tjcertificate/administrator/models/bulktrainingrecord.php
new file mode 100644
index 00000000..f9d7bc8e
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/models/bulktrainingrecord.php
@@ -0,0 +1,138 @@
+
+ * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+// No direct access to this file
+defined('_JEXEC') or die('Restricted access');
+
+use Joomla\CMS\MVC\Model\AdminModel;
+use Joomla\CMS\Table\Table;
+use Joomla\CMS\Component\ComponentHelper;
+use Joomla\CMS\Factory;
+use Joomla\CMS\Language\Text;
+use TJQueue\Admin\TJQueueProduce;
+
+if (ComponentHelper::getComponent('com_tjqueue', true)->enabled)
+{
+ jimport('tjqueueproduce', JPATH_ADMINISTRATOR . '/components/com_tjqueue/libraries');
+}
+
+/**
+ * TjCertificate Bulk Training Record Model.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class TjCertificateModelBulkTrainingRecord extends AdminModel
+{
+ protected $comMultiAgency = 'com_multiagency';
+
+ public $params;
+
+ public $user;
+
+ /**
+ * Constructor.
+ *
+ * @param array $config An optional associative array of configuration settings.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function __construct($config = array())
+ {
+ $this->params = ComponentHelper::getParams('com_tjcertificate');
+ $this->user = Factory::getuser();
+
+ parent::__construct($config);
+ }
+
+ /**
+ * Method to get the record form.
+ *
+ * @param array $data Data for the form.
+ * @param boolean $loadData True if the form is to load its own data (default case), false if not.
+ *
+ * @return JForm|boolean A JForm object on success, false on failure
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getForm($data = array(), $loadData = true)
+ {
+ // Get the form.
+ $form = $this->loadForm('com_tjcertificate.bulktrainingrecord', 'bulktrainingrecord', array('control' => 'jform', 'load_data' => $loadData));
+
+ return empty($form) ? false : $form;
+ }
+
+ /**
+ * Method to validate the form data.
+ *
+ * @param \JForm $form The form to validate against.
+ * @param Array $data The data to validate.
+ * @param string $group The name of the field group to validate.
+ *
+ * @return array|boolean Array of filtered data if valid, false otherwise.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function validate($form, $data, $group = null)
+ {
+ $return = true;
+ $return = parent::validate($form, $data, $group);
+
+ if (!empty($data['expired_on']) && $data['expired_on'] != '0000-00-00 00:00:00')
+ {
+ if ($data['issued_on'] > $data['expired_on'])
+ {
+ $this->setError(Text::_('COM_TJCERTIFICATE_EXPIRY_DATE_VALIDATION_MESSAGE'));
+ $return = false;
+ }
+ }
+
+ return $return;
+ }
+
+ /**
+ * Method to push data in queue.
+ *
+ * @param array $data record data
+ *
+ * @return array
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function addToQueue($data)
+ {
+ $return = array();
+ $messageBody = (object) $data;
+
+ try
+ {
+ $TJQueueProduce = new TJQueueProduce;
+
+ // Set message body
+ $TJQueueProduce->message->setBody(json_encode($messageBody));
+
+ // @Params client, value
+ $TJQueueProduce->message->setProperty('client', 'certificate.records');
+ $TJQueueProduce->produce();
+ }
+ catch (Exception $e)
+ {
+ $return['success'] = 0;
+ $return['message'] = $e->getMessage();
+
+ return $return;
+ }
+
+ $return['success'] = 1;
+ $return['message'] = '';
+
+ return $return;
+ }
+}
diff --git a/src/components/com_tjcertificate/administrator/models/certificate.php b/src/components/com_tjcertificate/administrator/models/certificate.php
index 0b8e3bf3..863a3caf 100644
--- a/src/components/com_tjcertificate/administrator/models/certificate.php
+++ b/src/components/com_tjcertificate/administrator/models/certificate.php
@@ -15,6 +15,7 @@
use \Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Plugin\PluginHelper;
+use Joomla\Registry\Registry;
/**
* Item Model for an Certificate.
@@ -23,6 +24,29 @@
*/
class TjCertificateModelCertificate extends AdminModel
{
+ /**
+ * Method to get a certificate.
+ *
+ * @param integer $pk An optional id of the object to get, otherwise the id from the model state is used.
+ *
+ * @return mixed certificate data object on success, false on failure.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getItem($pk = null)
+ {
+ if ($result = parent::getItem($pk))
+ {
+ // Prime required properties.
+ if (empty($result->id))
+ {
+ $result->client = $this->getState('certificate.client');
+ }
+ }
+
+ return $result;
+ }
+
/**
* Method to get the record form.
*
@@ -130,6 +154,18 @@ protected function populateState()
$jinput = Factory::getApplication()->input;
$id = ($jinput->get('id'))?$jinput->get('id'):$jinput->get('id');
$this->setState('certificate.id', $id);
+
+ $client = $jinput->get('client', '');
+ $extension = $jinput->get('extension', '');
+
+ if (!empty($extension))
+ {
+ $this->setState('certificate.client', $extension);
+ }
+ else
+ {
+ $this->setState('certificate.client', $client);
+ }
}
/**
@@ -152,4 +188,99 @@ public function getCertificateProviderInfo($contentId, $client)
return trim(implode("\n", $html));
}
+
+ /**
+ * Method to delete record
+ *
+ * @param array $certificateIds post data
+ *
+ * @return boolean True on success.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function delete(&$certificateIds)
+ {
+ $certificateIds = (array) $certificateIds;
+ $table = $this->getTable('Certificates');
+
+ foreach ($certificateIds as $certificateId)
+ {
+ $table->load(array('id' => (int) $certificateId));
+
+ if ($table->delete($table->id))
+ {
+ if ($table->is_external)
+ {
+ $dispatcher = \JEventDispatcher::getInstance();
+ $dispatcher->trigger('onTrainingRecordAfterDelete', array($table));
+ }
+
+ // Delete media
+ $model = TJCERT::model('TrainingRecord', array('ignore_request' => true));
+ JLoader::import("/techjoomla/media/tables/xref", JPATH_LIBRARIES);
+ $tableXref = Table::getInstance('Xref', 'TJMediaTable');
+ $tableXref->load(array('client_id' => $table->id));
+ $mediaPath = TJCERT::getMediaPath();
+ $client = TJCERT::getClient();
+
+ if ($tableXref->media_id)
+ {
+ $model->deleteMedia($tableXref->media_id, $mediaPath, $client, $table->id);
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Publish the element
+ *
+ * @param array $ids Item id
+ *
+ * @param int $state Publish state
+ *
+ * @return boolean
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function publish(&$ids, $state = 1)
+ {
+ $table = $this->getTable();
+
+ foreach ($ids as $id)
+ {
+ $table->load($id);
+ $oldState = $table->state;
+ $table->state = $state;
+
+ if ($table->store())
+ {
+ if ($table->is_external)
+ {
+ JLoader::import('components.com_tjcertificate.events.record', JPATH_SITE);
+ $tjCertificateTriggerRecord = new TjCertificateTriggerRecord;
+
+ // If record state is pending then only send the approval email
+ if ($oldState == -1)
+ {
+ $tjCertificateTriggerRecord->onRecordStateChange($table, $table->state);
+ }
+
+ $dispatcher = \JEventDispatcher::getInstance();
+
+ if ($table->state == 1)
+ {
+ $dispatcher->trigger('onTrainingRecordAfterPublished', array($table));
+ }
+ elseif ($table->state == 0)
+ {
+ $dispatcher->trigger('onTrainingRecordAfterUnpublished', array($table));
+ }
+ }
+ }
+ }
+
+ return true;
+ }
}
diff --git a/src/components/com_tjcertificate/administrator/models/certificates.php b/src/components/com_tjcertificate/administrator/models/certificates.php
index 78ce5435..8390b695 100644
--- a/src/components/com_tjcertificate/administrator/models/certificates.php
+++ b/src/components/com_tjcertificate/administrator/models/certificates.php
@@ -13,6 +13,8 @@
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\Factory;
+use Joomla\CMS\Component\ComponentHelper;
+use Joomla\CMS\MVC\Model\BaseDatabaseModel;
/**
* Methods supporting a list of records.
@@ -21,6 +23,8 @@
*/
class TjCertificateModelCertificates extends ListModel
{
+ protected $comMultiAgency = 'com_multiagency';
+
/**
* Constructor.
*
@@ -40,10 +44,13 @@ public function __construct($config = array())
'user_id', 'ci.user_id',
'state', 'ci.state',
'issued_on', 'ci.issued_on',
- 'expired_on', 'ci.expired_on'
+ 'expired_on', 'ci.expired_on',
+ 'agency_id'
);
}
+ $this->params = ComponentHelper::getParams('com_tjcertificate');
+
parent::__construct($config);
}
@@ -81,17 +88,63 @@ protected function getListQuery()
// Initialize variables.
$db = $this->getDbo();
$query = $db->getQuery(true);
+ $app = Factory::getApplication();
+ $user = Factory::getUser();
$extension = Factory::getApplication()->input->get('extension', '', 'CMD');
$this->setState('filter.component', $extension);
+ // Filter by client
+ $client = $this->getState('filter.client');
+
// Create the base select statement.
$query->select(array('ci.*', 'ct.title', 'users.name as uname'));
$query->from($db->quoteName('#__tj_certificate_issue', 'ci'));
+
$query->join('LEFT', $db->quoteName('#__tj_certificate_templates', 'ct') .
' ON (' . $db->quoteName('ci.certificate_template_id') . ' = ' . $db->quoteName('ct.id') . ')');
- $query->join('LEFT', $db->quoteName('#__users', 'users') . ' ON (' . $db->quoteName('ci.user_id') . ' = ' . $db->quoteName('users.id') . ')');
+
+ $query->join('LEFT', $db->quoteName('#__users', 'users') .
+ ' ON (' . $db->quoteName('ci.user_id') . ' = ' . $db->quoteName('users.id') . ')');
+
+ if (ComponentHelper::isEnabled($this->comMultiAgency) && $this->params->get('enable_multiagency'))
+ {
+ $query->select('agency.title as title');
+
+ $query->join('LEFT', $db->qn('#__tj_cluster_nodes', 'nodes') .
+ ' ON (' . $db->qn('users.id') . ' = ' . $db->qn('nodes.user_id') . ')');
+
+ $query->join('LEFT', $db->qn('#__tj_clusters', 'clusters') .
+ ' ON (' . $db->qn('clusters.id') . ' = ' . $db->qn('nodes.cluster_id') .
+ ' AND ' . $db->qn('clusters.client') . " = " . $db->q($this->comMultiAgency) . ')');
+
+ $query->join('LEFT', $db->qn('#__tjmultiagency_multiagency', 'agency') .
+ ' ON (' . $db->qn('agency.id') . ' = ' . $db->qn('clusters.client_id') . ')');
+
+ $agencyId = $this->getState('filter.agency_id');
+
+ $canManageAllAgencyUser = $user->authorise('core.manage.all.agency.user', $this->comMultiAgency);
+
+ // If don't have manage all user permission then get users of own agency
+ if (!$canManageAllAgencyUser && !$agencyId)
+ {
+ // Subquery to get agency users
+ $subquery = $db->getQuery(true);
+ $subquery->select($db->quoteName('ml.id'));
+ $subquery->from($db->quoteName('#__tjmultiagency_multiagency', 'ml'));
+ $subquery->join('INNER', $db->quoteName('#__tj_clusters', 'c') . ' ON ' . $db->quoteName('c.client_id') . '=' . $db->quoteName('ml.id'));
+ $subquery->join('INNER', $db->quoteName('#__tj_cluster_nodes', 'cn') . ' ON ' . $db->quoteName('cn.cluster_id') . '=' . $db->quoteName('c.id'));
+ $subquery->Where($db->qn('ml.state') . '=' . 1);
+ $subquery->where($db->quoteName('cn.user_id') . ' = ' . (int) $user->id);
+
+ $query->where($db->quoteName('agency.id') . ' in (' . $subquery . ')');
+ }
+ elseif ($agencyId)
+ {
+ $query->where($db->quoteName('agency.id') . ' = ' . (int) $agencyId);
+ }
+ }
// Filter by certificate id
$id = $this->getState('filter.id');
@@ -109,9 +162,6 @@ protected function getListQuery()
$query->where($db->quoteName('ci.certificate_template_id') . ' = ' . (int) $certificateTemplateId);
}
- // Filter by client
- $client = $this->getState('filter.client');
-
if (!empty($client))
{
$query->where($db->quoteName('ci.client') . ' = ' . $db->quote($client));
@@ -172,7 +222,11 @@ protected function getListQuery()
}
elseif ($state === '')
{
- $query->where('(ci.state = 0 OR ci.state = 1)');
+ // Publish, Unpublish and Pending records available in frontend
+ if ($app->isSite())
+ {
+ $query->where('(ci.state IN (0,1,-1))');
+ }
}
// Filter by Expired certificates
@@ -189,6 +243,8 @@ protected function getListQuery()
$orderCol = $this->state->get('list.ordering', 'ci.id');
$orderDirn = $this->state->get('list.direction', 'desc');
+ $query->group('ci.id');
+
if ($orderCol && $orderDirn)
{
$query->order($db->escape($orderCol . ' ' . $orderDirn));
diff --git a/src/components/com_tjcertificate/administrator/models/fields/agencies.php b/src/components/com_tjcertificate/administrator/models/fields/agencies.php
new file mode 100644
index 00000000..066cd033
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/models/fields/agencies.php
@@ -0,0 +1,99 @@
+
+ * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+defined('_JEXEC') or die();
+
+use Joomla\CMS\Factory;
+use Joomla\CMS\HTML\HTMLHelper;
+use Joomla\CMS\Language\Text;
+
+JFormHelper::loadFieldClass('list');
+
+/**
+ * Supports an HTML select list of agencies
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class JFormFieldAgencies extends JFormFieldList
+{
+ /**
+ * Fiedd to decide if options are being loaded externally and from xml
+ *
+ * @var integer
+ * @since __DEPLOY_VERSION__
+ */
+ protected $loadExternally = 0;
+
+ protected $comMultiAgency = 'com_multiagency';
+
+ /**
+ * Method to get a list of options for a list input.
+ *
+ * @return array An array of HTMLHelper options.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ protected function getOptions()
+ {
+ $db = Factory::getDbo();
+ $user = Factory::getUser();
+ $query = $db->getQuery(true);
+
+ $canManageAllAgencyUser = $user->authorise('core.manage.all.agency.user', $this->comMultiAgency);
+
+ // Select the required fields from the table.
+ $query->select('DISTINCT ml.id, ml.title');
+ $query->from('`#__tjmultiagency_multiagency` AS ml');
+ $query->join('INNER', $db->quoteName('#__tj_clusters', 'c') . ' ON (' . $db->quoteName('c.client_id') . ' = ' . $db->qn('ml.id') . ')');
+ $query->join('INNER', $db->quoteName('#__tj_cluster_nodes', 'cn') . ' ON ' . $db->quoteName('cn.cluster_id') . '=' . $db->quoteName('c.id'));
+ $query->Where($db->qn('c.state') . '=' . 1);
+
+ if (!$canManageAllAgencyUser)
+ {
+ $query->Where($db->qn('cn.user_id') . '=' . (int) $user->id);
+ }
+
+ $query->order($db->escape('ml.title ASC'));
+ $db->setQuery($query);
+
+ // Get all agencies.
+ $agencies = $db->loadObjectList();
+
+ $options = array();
+ $options[] = HTMLHelper::_('select.option', "", Text::_('COM_TJCERTIFICATE_ORG_SELECT'));
+
+ foreach ($agencies as $agency)
+ {
+ $options[] = HTMLHelper::_('select.option', $agency->id, $agency->title);
+ }
+
+ if (!$this->loadExternally)
+ {
+ // Merge any additional options in the XML definition.
+ $options = array_merge(parent::getOptions(), $options);
+ }
+
+ return $options;
+ }
+
+ /**
+ * Method to get a list of options for a list input externally and not from xml.
+ *
+ * @return array An array of HTMLHelper options.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getOptionsExternally()
+ {
+ $this->loadExternally = 1;
+
+ return $this->getOptions();
+ }
+}
diff --git a/src/components/com_tjcertificate/administrator/models/fields/allusers.php b/src/components/com_tjcertificate/administrator/models/fields/allusers.php
new file mode 100644
index 00000000..3020e8d6
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/models/fields/allusers.php
@@ -0,0 +1,86 @@
+
+ * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+// No direct access.
+defined('_JEXEC') or die();
+
+use Joomla\CMS\Factory;
+use Joomla\CMS\Language\Text;
+use Joomla\CMS\HTML\HTMLHelper;
+use Joomla\CMS\Component\ComponentHelper;
+use Joomla\CMS\MVC\Model\BaseDatabaseModel;
+
+JFormHelper::loadFieldClass('list');
+
+/**
+ * Supports an HTML select list of users
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class JFormFieldAllUsers extends JFormFieldList
+{
+ /**
+ * The form field type.
+ *
+ * @var string
+ * @since __DEPLOY_VERSION__
+ */
+ protected $type = 'allusers';
+
+ /**
+ * Fiedd to decide if options are being loaded externally and from xml
+ *
+ * @var integer
+ * @since __DEPLOY_VERSION__
+ */
+ protected $loadExternally = 0;
+
+ /**
+ * Method to get a list of options for a list input.
+ *
+ * @return array An array of JHtml options.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ protected function getOptions()
+ {
+ $model = TJCERT::model('Agency', array('ignore_request' => true));
+ $usersObject = $model->getUsers();
+
+ $options = array();
+
+ foreach ($usersObject as $user)
+ {
+ $options[] = HTMLHelper::_('select.option', $user->id, $user->name);
+ }
+
+ if (!$this->loadExternally)
+ {
+ // Merge any additional options in the XML definition.
+ $options = array_merge(parent::getOptions(), $options);
+ }
+
+ return $options;
+ }
+
+ /**
+ * Method to get a list of options for a list input externally and not from xml.
+ *
+ * @return array An array of JHtml options.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getOptionsExternally()
+ {
+ $this->loadExternally = 1;
+
+ return $this->getOptions();
+ }
+}
diff --git a/src/components/com_tjcertificate/administrator/models/fields/certificatetemplates.php b/src/components/com_tjcertificate/administrator/models/fields/certificatetemplates.php
index a738626f..8b03b2b7 100644
--- a/src/components/com_tjcertificate/administrator/models/fields/certificatetemplates.php
+++ b/src/components/com_tjcertificate/administrator/models/fields/certificatetemplates.php
@@ -10,6 +10,7 @@
JFormHelper::loadFieldClass('list');
use Joomla\CMS\Language\Text;
+use Joomla\CMS\Factory;
JLoader::import('components.com_tjcertificate.includes.tjcertificate', JPATH_ADMINISTRATOR);
@@ -31,11 +32,17 @@ protected function getOptions()
{
$options = array();
- $user = JFactory::getUser();
- $db = JFactory::getDbo();
+ $app = Factory::getApplication()->input;
+ $user = Factory::getUser();
+ $db = Factory::getDbo();
$client = $this->getAttribute('client');
+ if (empty($client))
+ {
+ $client = $app->get('extension', '');
+ }
+
$options[] = JHtml::_('select.option', '', Text::_('COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_FIELD_SELECT'));
// Get Private/Created by logged-in user's templates
diff --git a/src/components/com_tjcertificate/administrator/models/forms/bulktrainingrecord.xml b/src/components/com_tjcertificate/administrator/models/forms/bulktrainingrecord.xml
new file mode 100644
index 00000000..844166b5
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/models/forms/bulktrainingrecord.xml
@@ -0,0 +1,106 @@
+
+
diff --git a/src/components/com_tjcertificate/administrator/models/forms/certificate.xml b/src/components/com_tjcertificate/administrator/models/forms/certificate.xml
index d1fafc51..6b4b23da 100644
--- a/src/components/com_tjcertificate/administrator/models/forms/certificate.xml
+++ b/src/components/com_tjcertificate/administrator/models/forms/certificate.xml
@@ -13,12 +13,7 @@
@@ -51,6 +46,7 @@
diff --git a/src/components/com_tjcertificate/administrator/models/forms/filter_certificates.xml b/src/components/com_tjcertificate/administrator/models/forms/filter_certificates.xml
index f5b6dcbd..25258277 100644
--- a/src/components/com_tjcertificate/administrator/models/forms/filter_certificates.xml
+++ b/src/components/com_tjcertificate/administrator/models/forms/filter_certificates.xml
@@ -41,14 +41,35 @@
-->
+
+
+
+
+
+
+
+
+
diff --git a/src/components/com_tjcertificate/administrator/models/forms/filter_templates.xml b/src/components/com_tjcertificate/administrator/models/forms/filter_templates.xml
index 4a45dbc2..76d7b813 100644
--- a/src/components/com_tjcertificate/administrator/models/forms/filter_templates.xml
+++ b/src/components/com_tjcertificate/administrator/models/forms/filter_templates.xml
@@ -11,14 +11,13 @@
/>
-
-
+ addfieldpath="/components/com_tjcertificate/models/fields"
+ clientByUser="1"
+ onchange="this.form.submit();" />
+
diff --git a/src/components/com_tjcertificate/administrator/models/trainingrecord.php b/src/components/com_tjcertificate/administrator/models/trainingrecord.php
new file mode 100644
index 00000000..c5ecdde4
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/models/trainingrecord.php
@@ -0,0 +1,347 @@
+
+ * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+// No direct access to this file
+defined('_JEXEC') or die('Restricted access');
+
+use Joomla\CMS\MVC\Model\AdminModel;
+use Joomla\CMS\Table\Table;
+use Joomla\CMS\Component\ComponentHelper;
+use Joomla\CMS\Factory;
+use Joomla\CMS\MVC\Model\BaseDatabaseModel;
+use Joomla\CMS\Language\Text;
+
+JLoader::import("/techjoomla/media/storage/local", JPATH_LIBRARIES);
+
+/**
+ * TjCertificate Training Record Model.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class TjCertificateModelTrainingRecord extends AdminModel
+{
+ /**
+ * @var null Item data
+ * @since __DEPLOY_VERSION__
+ */
+ protected $item = null;
+
+ protected $comMultiAgency = 'com_multiagency';
+
+ public $params;
+
+ public $user;
+
+ /**
+ * Constructor.
+ *
+ * @param array $config An optional associative array of configuration settings.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function __construct($config = array())
+ {
+ $this->params = ComponentHelper::getParams('com_tjcertificate');
+ $this->user = Factory::getuser();
+
+ parent::__construct($config);
+ }
+
+ /**
+ * Method to get a certificate.
+ *
+ * @param integer $pk An optional id of the object to get, otherwise the id from the model state is used.
+ *
+ * @return mixed certificate data object on success, false on failure.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getItem($pk = null)
+ {
+ if ($item = parent::getItem($pk))
+ {
+ if (!empty($item->id))
+ {
+ // Do any procesing on fields here if needed
+ BaseDatabaseModel::addIncludePath(JPATH_SITE . '/libraries/techjoomla/media/models');
+
+ // Create TJMediaXref class object
+ $modelMediaXref = BaseDatabaseModel::getInstance('Xref', 'TJMediaModel', array('ignore_request' => true));
+ $modelMediaXref->setState('filter.clientId', $item->id);
+ $modelMediaXref->setState('filter.client', 'com_tjcertificate');
+ $mediaData = $modelMediaXref->getItems();
+
+ $item->mediaData = $mediaData;
+ }
+ }
+
+ return $item;
+ }
+
+ /**
+ * Method to get the record form.
+ *
+ * @param array $data Data for the form.
+ * @param boolean $loadData True if the form is to load its own data (default case), false if not.
+ *
+ * @return JForm|boolean A JForm object on success, false on failure
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function getForm($data = array(), $loadData = true)
+ {
+ // Get the form.
+ $form = $this->loadForm('com_tjcertificate.trainingrecord', 'trainingrecord', array('control' => 'jform', 'load_data' => $loadData));
+ $loggedInuser = Factory::getUser();
+
+ $app = Factory::getApplication();
+ $integrateMultiagency = $this->params->get('enable_multiagency');
+
+ if (!$loggedInuser->authorise('certificate.external.manage', 'com_tjcertificate'))
+ {
+ $form->setFieldAttribute('assigned_user_id', 'required', 'false');
+ }
+
+ return empty($form) ? false : $form;
+ }
+
+ /**
+ * Returns a Table object, always creating it.
+ *
+ * @param string $type The table type to instantiate
+ * @param string $prefix A prefix for the table class name. Optional.
+ * @param array $config Configuration array for model. Optional.
+ *
+ * @return JTable A database object
+ */
+ public function getTable($type = 'Certificates', $prefix = 'TjCertificateTable', $config = array())
+ {
+ Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjcertificate/tables');
+
+ return Table::getInstance($type, $prefix, $config);
+ }
+
+ /**
+ * Method to get the data that should be injected in the form.
+ *
+ * @return mixed The data for the form.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ protected function loadFormData()
+ {
+ // Check the session for previously entered form data.
+ $data = Factory::getApplication()->getUserState('com_tjcertificate.edit.trainingrecord.data', array());
+
+ if (empty($data))
+ {
+ $data = $this->getItem();
+ $data->assigned_user_id = $data->user_id;
+ }
+
+ return $data;
+ }
+
+ /**
+ * Method to upload file for timelog activity
+ *
+ * @param Array $file File field array
+ *
+ * @param array $data The form data
+ *
+ * @return array
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function uploadMedia($file, $data)
+ {
+ $user = Factory::getUser();
+
+ if (!empty($file['cert_file']))
+ {
+ $filePath = TJCERT::getMediaPath();
+ $uploadedFileExtension = strtolower($this->params->get('upload_extensions', '', 'STRING'));
+ $fileExtensionType = explode(',', $uploadedFileExtension);
+
+ $config = array();
+ $config['type'] = $fileExtensionType;
+ $config['size'] = $this->params->get('upload_maxsize', '10');
+ $config['auth'] = true;
+
+ if (!empty($file['cert_file']['name']))
+ {
+ $fileType = explode("/", $file['cert_file']['type']);
+ $config['title'] = $file['cert_file']['name'];
+ $config['uploadPath'] = JPATH_SITE . '/' . $filePath . '/' . strtolower($fileType[0]);
+
+ $media = TJMediaStorageLocal::getInstance($config);
+ $mediaData = $media->upload(array($file['cert_file']));
+
+ if (!empty($media->getError()))
+ {
+ $errorFiles[] = $media->getError() . ' (' . $attachments['media_file']['name'] . ')';
+ }
+ elseif ($mediaData[0]['id'])
+ {
+ $uploadedMediaId = $mediaData[0];
+
+ if (!empty($data['old_media_ids']))
+ {
+ if ($data['old_media_ids'] != $mediaId)
+ {
+ $this->deleteMedia($data['old_media_ids'], $filePath, 'com_tjcertificate', $data['id']);
+ }
+ }
+ }
+ }
+
+ // Check error exist in file
+ if (!empty($errorFiles))
+ {
+ $this->setError($errorFiles);
+ }
+ }
+
+ return $uploadedMediaId;
+ }
+
+ /**
+ * Method to delete media record
+ *
+ * @param Integer $mediaId media Id of files table
+ * @param STRING $deletePath file path from params in config
+ * @param STRING $client client(example -'com_timelog.activity')
+ * @param Integer $clientId clientId(example - Timelog activity id)
+ *
+ * @return boolean True if successful, false if an error occurs.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function deleteMedia($mediaId, $deletePath, $client, $clientId)
+ {
+ JLoader::import("/techjoomla/media/tables/xref", JPATH_LIBRARIES);
+ JLoader::import("/techjoomla/media/tables/files", JPATH_LIBRARIES);
+ $tableXref = Table::getInstance('Xref', 'TJMediaTable');
+ $filetable = Table::getInstance('Files', 'TJMediaTable');
+
+ // CheckMediaDataExist will return 1 when media is present clientId is Report Id
+ $checkMediaDataExist = $tableXref->load(array('media_id' => $mediaId, 'client_id' => $clientId));
+
+ // Making file delete path
+ $mediaPresent = $filetable->load($mediaId);
+
+ $mediaType = explode(".", $filetable->type);
+ $deletePath = $deletePath . '/' . $mediaType[0];
+
+ // If Media is present
+ if ($checkMediaDataExist)
+ {
+ // Get Object which include Media xref + Media File data of provided Media xref id
+ $mediaXrefLib = TJMediaXref::getInstance(array('id' => $tableXref->id));
+
+ // If media is not deleted it will return false here
+ if ($mediaXrefLib->delete())
+ {
+ // If media xref delete then delete main entry from media_files
+ $mediaLib = TJMediaStorageLocal::getInstance(array('id' => $mediaId, 'uploadPath' => $deletePath));
+
+ // Checking Media is present or not
+ if ($mediaLib->id)
+ {
+ // If Media is not deleted
+ if (!$mediaLib->delete())
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ elseif ($mediaPresent)
+ {
+ $mediaLib = TJMediaStorageLocal::getInstance(array('id' => $mediaId, 'uploadPath' => $deletePath));
+
+ if ($mediaLib->id)
+ {
+ if ($mediaLib->delete())
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Method to validate the form data.
+ *
+ * @param \JForm $form The form to validate against.
+ * @param Array $data The data to validate.
+ * @param string $group The name of the field group to validate.
+ *
+ * @return array|boolean Array of filtered data if valid, false otherwise.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function validate($form, $data, $group = null)
+ {
+ $return = true;
+ $return = parent::validate($form, $data, $group);
+
+ if (!empty($data['expired_on']) && $data['expired_on'] != '0000-00-00 00:00:00')
+ {
+ if ($data['issued_on'] > $data['expired_on'])
+ {
+ $this->setError(Text::_('COM_TJCERTIFICATE_EXPIRY_DATE_VALIDATION_MESSAGE'));
+ $return = false;
+ }
+ }
+
+ if (ComponentHelper::isEnabled($this->comMultiAgency) && $this->params->get('enable_multiagency'))
+ {
+ $manageOwn = $this->user->authorise('core.manage.own.agency.user', $this->comMultiAgency);
+ $manage = $this->user->authorise('core.manage.all.agency.user', $this->comMultiAgency);
+
+ if ($manageOwn && empty($manage))
+ {
+ $model = TJCERT::model('Agency', array('ignore_request' => true));
+
+ // Get agencies of logged-in user and assigned user
+ $assignedUserAgencies = $model->getUserAgencies($data['assigned_user_id']);
+ $loggedInUserAgencies = $model->getUserAgencies($this->user->id);
+
+ // Convert object to array
+ $assignedUserAgencyArr = array_column($assignedUserAgencies, 'id');
+ $loggedInUserAgencyArr = array_column($loggedInUserAgencies, 'id');
+
+ // Compare both users agencies
+ $result = array_intersect($loggedInUserAgencyArr, $assignedUserAgencyArr);
+
+ if (empty($result))
+ {
+ $this->setError(Text::_('COM_TJCERTIFICATE_ORGANIZATION_INVALID_USER'));
+ $return = false;
+ }
+ }
+ }
+
+ return $return;
+ }
+}
diff --git a/src/components/com_tjcertificate/administrator/sql/install.mysql.utf8.sql b/src/components/com_tjcertificate/administrator/sql/install.mysql.utf8.sql
index d5b51fee..e50305b3 100644
--- a/src/components/com_tjcertificate/administrator/sql/install.mysql.utf8.sql
+++ b/src/components/com_tjcertificate/administrator/sql/install.mysql.utf8.sql
@@ -33,6 +33,48 @@ CREATE TABLE IF NOT EXISTS `#__tj_certificate_issue` (
`state` tinyint(3) NOT NULL,
`issued_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`expired_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+ `is_external` tinyint(1) NOT NULL DEFAULT '0',
+ `name` varchar(255) NOT NULL,
+ `issuing_org` varchar(255) NOT NULL,
+ `cert_url` text NULL,
+ `cert_file` varchar(255) NOT NULL,
+ `created_by` int(11) NOT NULL,
+ `access` tinyint(1) NOT NULL DEFAULT '0',
+ `status` varchar(64) NULL,
PRIMARY KEY (`id`),
UNIQUE KEY unqk_certificate_id (`unique_certificate_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
+
+--
+-- Table structure for table `#__tj_media_files`
+--
+
+CREATE TABLE IF NOT EXISTS `#__tj_media_files` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `title` varchar(250) NOT NULL,
+ `type` varchar(250) NOT NULL,
+ `path` varchar(250) COLLATE utf8mb4_bin NOT NULL,
+ `state` tinyint(1) NOT NULL,
+ `source` varchar(250) NOT NULL,
+ `original_filename` varchar(250) COLLATE utf8mb4_bin NOT NULL,
+ `size` int(11) NOT NULL,
+ `storage` varchar(250) NOT NULL,
+ `created_by` int(11) NOT NULL,
+ `access` tinyint(1) NOT NULL,
+ `created_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+ `params` varchar(500) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1;
+
+--
+-- Table structure for table `#__tj_media_files_xref`
+--
+
+CREATE TABLE IF NOT EXISTS `#__tj_media_files_xref` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `media_id` int(11) NOT NULL,
+ `client_id` int(11) NOT NULL,
+ `client` varchar(250) NOT NULL,
+ `is_gallery` tinyint(1) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1;
diff --git a/src/components/com_tjcertificate/administrator/sql/updates/mysql/1.0.3.sql b/src/components/com_tjcertificate/administrator/sql/updates/mysql/1.0.3.sql
new file mode 100644
index 00000000..de1b71f4
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/sql/updates/mysql/1.0.3.sql
@@ -0,0 +1,42 @@
+ALTER TABLE `#__tj_certificate_issue` ADD COLUMN `is_external` tinyint(1) NOT NULL DEFAULT '0' AFTER `expired_on`;
+ALTER TABLE `#__tj_certificate_issue` ADD COLUMN `name` varchar(255) NOT NULL AFTER `is_external`;
+ALTER TABLE `#__tj_certificate_issue` ADD COLUMN `issuing_org` varchar(255) NOT NULL AFTER `name`;
+ALTER TABLE `#__tj_certificate_issue` ADD COLUMN `cert_url` text NULL AFTER `issuing_org`;
+ALTER TABLE `#__tj_certificate_issue` ADD COLUMN `cert_file` varchar(255) NOT NULL AFTER `cert_url`;
+ALTER TABLE `#__tj_certificate_issue` ADD COLUMN `access` tinyint(1) NOT NULL DEFAULT '0' AFTER `cert_file`;
+ALTER TABLE `#__tj_certificate_issue` ADD COLUMN `created_by` int(11) NOT NULL AFTER `access`;
+ALTER TABLE `#__tj_certificate_issue` ADD COLUMN `status` varchar(64) NULL AFTER `created_by`;
+
+--
+-- Table structure for table `#__tj_media_files`
+--
+
+CREATE TABLE IF NOT EXISTS `#__tj_media_files` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `title` varchar(250) NOT NULL,
+ `type` varchar(250) NOT NULL,
+ `path` varchar(250) COLLATE utf8mb4_bin NOT NULL,
+ `state` tinyint(1) NOT NULL,
+ `source` varchar(250) NOT NULL,
+ `original_filename` varchar(250) COLLATE utf8mb4_bin NOT NULL,
+ `size` int(11) NOT NULL,
+ `storage` varchar(250) NOT NULL,
+ `created_by` int(11) NOT NULL,
+ `access` tinyint(1) NOT NULL,
+ `created_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+ `params` varchar(500) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1;
+
+--
+-- Table structure for table `#__tj_media_files_xref`
+--
+
+CREATE TABLE IF NOT EXISTS `#__tj_media_files_xref` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `media_id` int(11) NOT NULL,
+ `client_id` int(11) NOT NULL,
+ `client` varchar(250) NOT NULL,
+ `is_gallery` tinyint(1) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1;
diff --git a/src/components/com_tjcertificate/administrator/sql/updates/mysql/1.0.6.sql b/src/components/com_tjcertificate/administrator/sql/updates/mysql/1.0.6.sql
new file mode 100644
index 00000000..53bed3cb
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/sql/updates/mysql/1.0.6.sql
@@ -0,0 +1 @@
+UPDATE `#__tj_notification_templates` SET `key` = "recordApprovedMailToUser" WHERE `key` = "recordPublishMailToUser";
diff --git a/src/components/com_tjcertificate/administrator/tables/templates.php b/src/components/com_tjcertificate/administrator/tables/templates.php
index 0993f52c..54d27f07 100644
--- a/src/components/com_tjcertificate/administrator/tables/templates.php
+++ b/src/components/com_tjcertificate/administrator/tables/templates.php
@@ -4,12 +4,14 @@
* @subpackage com_tjcertificate
*
* @author Techjoomla
- * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved.
+ * @copyright Copyright (C) 2009 - 2021 Techjoomla. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
+use Joomla\CMS\Factory;
+use Joomla\CMS\Table\Table;
/**
* Templates table class
@@ -30,4 +32,37 @@ public function __construct(&$db)
parent::__construct('#__tj_certificate_templates', 'id', $db);
$this->setColumnAlias('published', 'state');
}
+
+ /**
+ * Overloaded check function
+ *
+ * @return true|false
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function check()
+ {
+ $db = Factory::getDbo();
+ $task = Factory::getApplication()->input->get('task');
+
+ if ($task == 'save2copy')
+ {
+ $this->unique_code = trim($this->unique_code);
+
+ // Check if certificate template with same unique code is present
+ $table = Table::getInstance('Templates', 'TjCertificateTable', array('dbo', $db));
+
+ if ($table->load(array('unique_code' => $this->unique_code)) && ($table->id != $this->id || $this->id == 0))
+ {
+ $this->unique_code = JString::increment($this->unique_code, 'dash', mt_rand(100, 1000000));
+
+ while ($table->load(array('unique_code' => $this->unique_code)))
+ {
+ $this->unique_code = JString::increment($this->unique_code, 'dash', mt_rand(100, 1000000));
+ }
+ }
+ }
+
+ return parent::check();
+ }
}
diff --git a/src/components/com_tjcertificate/administrator/tjcertificate.php b/src/components/com_tjcertificate/administrator/tjcertificate.php
index 202eae8c..781effbd 100644
--- a/src/components/com_tjcertificate/administrator/tjcertificate.php
+++ b/src/components/com_tjcertificate/administrator/tjcertificate.php
@@ -15,6 +15,7 @@
use Joomla\CMS\MVC\Controller\BaseController;
JLoader::import('components.com_tjcertificate.includes.tjcertificate', JPATH_ADMINISTRATOR);
+TJCERT::init('admin');
JLoader::registerPrefix('TjCertificate', JPATH_ADMINISTRATOR);
JLoader::register('TjCertificateController', JPATH_ADMINISTRATOR . '/controller.php');
diff --git a/src/components/com_tjcertificate/administrator/tjcertificateTemplate.json b/src/components/com_tjcertificate/administrator/tjcertificateTemplate.json
new file mode 100644
index 00000000..dfabeed8
--- /dev/null
+++ b/src/components/com_tjcertificate/administrator/tjcertificateTemplate.json
@@ -0,0 +1,158 @@
+{
+ "template1": {
+ "id": "",
+ "client": "com_tjcertificate",
+ "key": "assignRecordMailToUser",
+ "title": "Learning Record Added by Admin",
+ "user_control": 1,
+ "state": 1,
+ "core": 1,
+ "email":{
+ "state": 1,
+ "cc": "",
+ "bcc": "",
+ "from_name": "",
+ "from_email": "",
+ "emailfields": {
+ "emailfields0": {
+ "id": "",
+ "language": "*",
+ "subject": "A New Learning Record \"{{record.name}}\" has been added against you",
+ "body": "
Dear {{user.name}},
A new record {{record.name}} added by {{assigner.name}}.