diff --git a/src/components/com_tjcertificate/administrator/access.xml b/src/components/com_tjcertificate/administrator/access.xml index 944f9715..3b1ca7a2 100644 --- a/src/components/com_tjcertificate/administrator/access.xml +++ b/src/components/com_tjcertificate/administrator/access.xml @@ -12,5 +12,10 @@ + + + + + diff --git a/src/components/com_tjcertificate/administrator/config.xml b/src/components/com_tjcertificate/administrator/config.xml index fafde553..74c9925c 100644 --- a/src/components/com_tjcertificate/administrator/config.xml +++ b/src/components/com_tjcertificate/administrator/config.xml @@ -1,6 +1,6 @@ -
+
JYES + + + + + + + + + + + + + + + + + + + + +
@@ -50,7 +72,15 @@ - + + + + + + + + +
+ +
+ + +
+ +
+ + + + + + +
+ + +
+ + + + + + +
+
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}}.

" + } + } + }, + "replacement_tags":[ + { + "name": "user.name", + "description": "Name of record owner" + }, + { + "name": "info.sitename", + "description": "Sitename" + }, + { + "name": "assigner.name", + "description": "Record assigner name" + }, + { + "name": "record.name", + "description": "Name of record" + } + ] + }, + "template2": { + "id": "", + "client": "com_tjcertificate", + "key": "createRecordMailTouser", + "title": "User has Submitted a Learning Record", + "user_control": 1, + "state": 1, + "core": 1, + "email":{ + "state": 1, + "cc": "", + "bcc": "", + "from_name": "", + "from_email": "", + "emailfields": { + "emailfields0": { + "id": "", + "language": "*", + "subject": "Record {{record.name}} added by you", + "body": "

Dear {{user.name}},

You have added record {{record.name}}.

" + } + } + }, + "replacement_tags":[ + { + "name": "user.name", + "description": "Name of record owner" + }, + { + "name": "info.sitename", + "description": "Sitename" + }, + { + "name": "record.name", + "description": "Name of record" + } + ] + }, + "template3": { + "id": "", + "client": "com_tjcertificate", + "key": "createRecordMailToAdmin", + "title": "Admin Notification when user Submits a Learning Record", + "user_control": 1, + "state": 1, + "core": 1, + "email":{ + "state": 1, + "cc": "", + "bcc": "", + "from_name": "", + "from_email": "", + "emailfields": { + "emailfields0": { + "id": "", + "language": "*", + "subject": "A new record {{record.name}} added", + "body": "

Hello Admin,

A new Record : {{record.name}} was added by {{user.name}} on {{info.sitename}}.

" + } + } + }, + "replacement_tags":[ + { + "name": "user.name", + "description": "Name of record owner" + }, + { + "name": "info.sitename", + "description": "Sitename" + }, + { + "name": "record.name", + "description": "Name of record" + } + ] + }, + "template4": { + "id": "", + "client": "com_tjcertificate", + "key": "recordApprovedMailToUser", + "title": "Learning Record Approval Email Sent to user", + "user_control": 1, + "state": 1, + "core": 1, + "email":{ + "state": 1, + "cc": "", + "bcc": "", + "from_name": "", + "from_email": "", + "emailfields": { + "emailfields0": { + "id": "", + "language": "*", + "subject": "Record {{record.name}} is approved", + "body": "

Dear {{user.name}},

Your record {{record.name}} is approved.

" + } + } + }, + "replacement_tags":[ + { + "name": "user.name", + "description": "Name of record owner" + }, + { + "name": "info.sitename", + "description": "Sitename" + }, + { + "name": "record.name", + "description": "Name of record" + } + ] + } +} diff --git a/src/components/com_tjcertificate/administrator/views/bulktrainingrecord/tmpl/edit.php b/src/components/com_tjcertificate/administrator/views/bulktrainingrecord/tmpl/edit.php new file mode 100644 index 00000000..a3543da8 --- /dev/null +++ b/src/components/com_tjcertificate/administrator/views/bulktrainingrecord/tmpl/edit.php @@ -0,0 +1,95 @@ + + * @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\HTML\HTMLHelper; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); + +HTMLHelper::_('jquery.token'); +HTMLHelper::_('behavior.framework'); +HTMLHelper::_('behavior.formvalidator'); +HTMLHelper::_('behavior.keepalive'); +HTMLHelper::_('formbehavior.chosen', 'select'); + +$options['relative'] = true; +HTMLHelper::_('script', 'media/com_tjcertificate/vendors/loader/js/loadingoverlay.min.js'); +HTMLHelper::_('script', 'com_tjcertificate/tjCertificateService.min.js', $options); +HTMLHelper::_('script', 'com_tjcertificate/certificate.min.js', $options); + +$userLimit = $this->params->get('users_select_limit'); +$message = Text::sprintf("COM_TJCERTIFICATE_USER_LIMIT_MESSAGE", $userLimit); + +?> +
+
+
+ sidebar)) + { + ?> +
+ sidebar; ?> +
+
+ +
+ +
+ + 'general')); + echo HTMLHelper::_('bootstrap.addTab', 'myTab', 'general', Text::_('COM_TJCERTIFICATE_TITLE_CERTIFICATE')); ?> +
+ isAgencyEnabled) + { + echo $this->form->renderField('agency_id'); + } + ?> + + form->renderField('assigned_user_id'); ?> + form->renderField('name'); ?> + form->renderField('issuing_org'); ?> + form->renderField('issued_on'); ?> + form->renderField('expired_on'); ?> + form->renderField('status'); ?> + form->renderField('state'); ?> + form->renderField('notify_users'); ?> + +
+ + + +
+ +
+
+ diff --git a/src/components/com_tjcertificate/administrator/views/bulktrainingrecord/view.html.php b/src/components/com_tjcertificate/administrator/views/bulktrainingrecord/view.html.php new file mode 100644 index 00000000..c769e515 --- /dev/null +++ b/src/components/com_tjcertificate/administrator/views/bulktrainingrecord/view.html.php @@ -0,0 +1,103 @@ + + * @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\View\HtmlView; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Toolbar\ToolbarHelper; +use Joomla\CMS\Toolbar\Toolbar; + +/** + * View to edit + * + * @since __DEPLOY_VERSION__ + */ +class TjCertificateViewBulkTrainingRecord extends HtmlView +{ + /** + * The JForm object + * + * @var JForm + */ + protected $form; + + public $isAgencyEnabled = false; + + protected $comMultiAgency = 'com_multiagency'; + + /** + * Display the view + * + * @param string $tpl Template name + * + * @return void + * + * @throws Exception + */ + public function display($tpl = null) + { + $this->form = $this->get('Form'); + $this->input = Factory::getApplication()->input; + $this->params = ComponentHelper::getParams('com_tjcertificate'); + + if (ComponentHelper::isEnabled($this->comMultiAgency) && $this->params->get('enable_multiagency')) + { + $this->isAgencyEnabled = true; + } + + $layout = $this->input->get('layout', 'edit'); + + $this->addToolbar(); + + parent::display($tpl); + } + + /** + * Add the page title and toolbar. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + protected function addToolbar() + { + $app = Factory::getApplication(); + + $layout = $app->input->get("layout"); + + JLoader::import('administrator.components.com_tjcertificate.helpers.tjcertificate', JPATH_SITE); + TjCertificateHelper::addSubmenu('certificates'); + + if ($app->isClient('administrator')) + { + $this->sidebar = JHtmlSidebar::render(); + } + + if ($layout != "default") + { + $app->input->set('hidemainmenu', true); + + ToolbarHelper::title( + Text::_('COM_TJCERTIFICATE_PAGE_ADD_TRAINING_RECORDS'), + 'pencil-2 certificate-add' + ); + + $layout = ''; + + Toolbar::getInstance('toolbar')->appendButton('Custom', $layout); + ToolbarHelper::cancel('certificate.cancel'); + } + } +} diff --git a/src/components/com_tjcertificate/administrator/views/certificate/tmpl/edit.php b/src/components/com_tjcertificate/administrator/views/certificate/tmpl/edit.php index 8dd9eeb3..aedbb8ee 100644 --- a/src/components/com_tjcertificate/administrator/views/certificate/tmpl/edit.php +++ b/src/components/com_tjcertificate/administrator/views/certificate/tmpl/edit.php @@ -15,16 +15,41 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Router\Route; +use Joomla\CMS\Layout\LayoutHelper; HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); +HTMLHelper::_('jquery.token'); +HTMLHelper::_('behavior.framework'); HTMLHelper::_('behavior.formvalidator'); HTMLHelper::_('behavior.keepalive'); HTMLHelper::_('formbehavior.chosen', 'select'); + +$options['relative'] = true; +HTMLHelper::_('script', 'com_tjcertificate/tjCertificateService.min.js', $options); +HTMLHelper::_('script', 'com_tjcertificate/template.min.js', $options); + +$app = Factory::getApplication(); +$input = $app->input; + +$client = $input->getCmd('client', ''); +$extension = $input->getCmd('extension', ''); + +$clientUrlAppend = ''; + +if (!empty($extension)) +{ + $clientUrlAppend = '&extension=' . $extension; +} +elseif (!empty($client)) +{ + $clientUrlAppend = '&client=' . $client; +} + ?>
-
sidebar)) { @@ -43,8 +68,6 @@ } ?>
- -
form->renderField('unique_certificate_id'); ?> form->renderField('certificate_template_id'); ?> @@ -63,3 +86,19 @@
+ + + diff --git a/src/components/com_tjcertificate/administrator/views/certificate/view.html.php b/src/components/com_tjcertificate/administrator/views/certificate/view.html.php index 887236cd..fc3a93f9 100644 --- a/src/components/com_tjcertificate/administrator/views/certificate/view.html.php +++ b/src/components/com_tjcertificate/administrator/views/certificate/view.html.php @@ -14,6 +14,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Router\Route; /** * View to edit @@ -68,21 +69,24 @@ class TjCertificateViewCertificate extends HtmlView */ public function display($tpl = null) { + $app = Factory::getApplication(); $this->state = $this->get('State'); $this->item = $this->get('Item'); + + // If training record then redirect to training record form + if ($this->item->is_external) + { + $app->redirect( + Route::_('index.php?option=com_tjcertificate&view=trainingrecord&layout=edit&id=' . $this->item->id, false) + ); + } + $this->form = $this->get('Form'); $this->input = Factory::getApplication()->input; $this->canDo = JHelperContent::getActions('com_tjcertificate', 'certificate', $this->item->id); $layout = $this->input->get('layout', 'edit'); - if ($layout == 'edit') - { - JError::raiseNotice(403, Text::_('COM_TJCERTIFICATE_ERROR_CERTIFICATE_EDIT_NOT_PERMITTED')); - - return false; - } - // Check for errors. if (count($errors = $this->get('Errors'))) { @@ -143,7 +147,6 @@ protected function addToolbar() JToolbarHelper::apply('certificate.apply'); JToolbarHelper::save('certificate.save'); JToolbarHelper::save2new('certificate.save2new'); - JToolbarHelper::cancel('certificate.cancel'); } else { @@ -151,6 +154,16 @@ protected function addToolbar() // Can't save the record if it's checked out and editable $this->canSave($itemEditable); + } + + JToolbarHelper::modal('templatePreview', 'icon-eye', 'COM_TJCERTIFICATE_CERTIFICATE_TEMPLATE_TOOLBAR_PREVIEW'); + + if (empty($this->item->id)) + { + JToolbarHelper::cancel('certificate.cancel'); + } + else + { JToolbarHelper::cancel('certificate.cancel', 'JTOOLBAR_CLOSE'); } } diff --git a/src/components/com_tjcertificate/administrator/views/certificates/tmpl/default.php b/src/components/com_tjcertificate/administrator/views/certificates/tmpl/default.php index 4113aa13..55001797 100644 --- a/src/components/com_tjcertificate/administrator/views/certificates/tmpl/default.php +++ b/src/components/com_tjcertificate/administrator/views/certificates/tmpl/default.php @@ -30,15 +30,8 @@ $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); -$saveOrder = $listOrder == 'ci.id'; $dispatcher = JDispatcher::getInstance(); PluginHelper::importPlugin('content'); - -if ( $saveOrder ) -{ - $saveOrderingUrl = 'index.php?option=com_tjcertificate&task=certificates.saveOrderAjax'; - HTMLHelper::_('sortablelist.sortable', 'certificateList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); -} ?>
@@ -87,13 +80,19 @@ - + + isAgencyEnabled) { ?> + + + + + @@ -107,13 +106,12 @@ - + - + - @@ -131,6 +129,7 @@ items as $i => $item) { + $certificateObj = TJCERT::Certificate($item->id); $data = $dispatcher->trigger('getCertificateClientData', array($item->client_id, $item->client)); $item->max_ordering = 0; @@ -153,16 +152,15 @@
- + ?> + escape($item->unique_certificate_id); ?> + } + else + { + ?> escape($item->unique_certificate_id); ?> + isAgencyEnabled) + { ?> + title; ?> + title)) ? $data[0]->title : '-'; + if ($item->is_external) + { + echo $item->name; + } + else + { + echo ($data[0]->title ? $data[0]->title : "-"); + } ?> - issued_on, Text::_('DATE_FORMAT_LC')); ?> + getFormatedDate($item->issued_on); ?> expired_on) && $item->expired_on != '0000-00-00 00:00:00') { - echo HTMLHelper::date($item->expired_on, Text::_('DATE_FORMAT_LC')); + echo $certificateObj->getFormatedDate($item->expired_on); } else { @@ -210,16 +221,23 @@ echo TEXT::_($client); ?> - escape($item->title); ?> toSql(); - + $link = ""; if ($item->expired_on > $utcNow || $item->expired_on == '0000-00-00 00:00:00') { // Get TJcertificate url for display certificate - $urlOpts = array ('absolute' => ''); - $link = TJCERT::Certificate($item->id)->getUrl($urlOpts, false); + $urlOpts = array ('absolute' => true); + + if ($item->is_external) + { + $link = $certificateObj->getUrl($urlOpts, false, true); + } + else + { + $link = $certificateObj->getUrl($urlOpts, false); + } ?>
- escape($item->comment); ?> + + + + + + + + id; ?> sidebar = JHtmlSidebar::render(); + $this->params = ComponentHelper::getParams('com_tjcertificate'); + + if (ComponentHelper::isEnabled($this->comMultiAgency) && $this->params->get('enable_multiagency')) + { + $this->isAgencyEnabled = true; + } + else + { + $this->filterForm->removeField('agency_id', 'filter'); + } + // Display the view parent::display($tpl); } @@ -132,11 +149,17 @@ protected function addToolbar() JToolBarHelper::title(Text::_('COM_TJCERTIFICATE_VIEW_CERTIFICATES'), ''); $canDo = $this->canDo; - /*if ($canDo->get('core.create')) + if ($canDo->get('core.create')) { JToolbarHelper::addNew('certificate.add'); } + if ($canDo->get('certificate.external.create')) + { + JToolbarHelper::addNew('trainingrecord.add', 'COM_TJCERTIFICATE_ADD_EXTERNAL_CERTIFICATE'); + JToolbarHelper::addNew('bulktrainingrecord.add', 'COM_TJCERTIFICATE_ADD_EXTERNAL_CERTIFICATES'); + } + if ($canDo->get('core.edit')) { JToolbarHelper::editList('certificate.edit'); @@ -156,7 +179,6 @@ protected function addToolbar() JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'certificates.delete', 'JTOOLBAR_DELETE'); JToolbarHelper::divider(); } - */ if ($canDo->get('core.admin') || $canDo->get('core.options')) { diff --git a/src/components/com_tjcertificate/administrator/views/template/tmpl/edit.php b/src/components/com_tjcertificate/administrator/views/template/tmpl/edit.php index 8de3209f..fee116ad 100644 --- a/src/components/com_tjcertificate/administrator/views/template/tmpl/edit.php +++ b/src/components/com_tjcertificate/administrator/views/template/tmpl/edit.php @@ -141,39 +141,19 @@
- - - - + diff --git a/src/components/com_tjcertificate/administrator/views/templates/tmpl/default.php b/src/components/com_tjcertificate/administrator/views/templates/tmpl/default.php index 4d26991d..1a1b6525 100644 --- a/src/components/com_tjcertificate/administrator/views/templates/tmpl/default.php +++ b/src/components/com_tjcertificate/administrator/views/templates/tmpl/default.php @@ -100,7 +100,7 @@ - + @@ -201,7 +201,13 @@
- escape($item->client); ?> + + client); + $client = strtoupper("COM_TJCERTIFICATE_CLIENT_" . $client); + echo TEXT::_($client); + ?> + is_public); ?> escape($item->uname); ?> id; ?> diff --git a/src/components/com_tjcertificate/administrator/views/trainingrecord/index.html b/src/components/com_tjcertificate/administrator/views/trainingrecord/index.html new file mode 100644 index 00000000..e69de29b diff --git a/src/components/com_tjcertificate/administrator/views/trainingrecord/tmpl/edit.php b/src/components/com_tjcertificate/administrator/views/trainingrecord/tmpl/edit.php new file mode 100644 index 00000000..8668149c --- /dev/null +++ b/src/components/com_tjcertificate/administrator/views/trainingrecord/tmpl/edit.php @@ -0,0 +1,122 @@ + + * @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\CMS\HTML\HTMLHelper; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Layout\LayoutHelper; +use Joomla\CMS\Uri\Uri; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); + +HTMLHelper::_('jquery.token'); +HTMLHelper::_('behavior.framework'); +HTMLHelper::_('behavior.formvalidator'); +HTMLHelper::_('behavior.keepalive'); +HTMLHelper::_('formbehavior.chosen', 'select'); + +$options['relative'] = true; +HTMLHelper::_('script', 'com_tjcertificate/tjCertificateService.min.js', $options); +HTMLHelper::_('script', 'com_tjcertificate/certificate.min.js', $options); +?> +
+
+
+ sidebar)) + { + ?> +
+ sidebar; ?> +
+
+ +
+ +
+ 'general')); + echo HTMLHelper::_('bootstrap.addTab', 'myTab', 'general', Text::_('COM_TJCERTIFICATE_TITLE_CERTIFICATE')); ?> +
+ form->renderField('id'); ?> + + isAgencyEnabled) + { + echo $this->form->renderField('agency_id'); + } + ?> + + form->renderField('assigned_user_id'); ?> + form->renderField('name'); ?> + form->renderField('unique_certificate_id'); ?> + form->renderField('cert_url'); ?> + form->renderField('issuing_org'); ?> + form->renderField('issued_on'); ?> + form->renderField('expired_on'); ?> + form->renderField('status'); ?> +
+
form->getLabel('cert_file'); ?>
+
+ form->getInput('cert_file'); ?> + item->mediaData[0])) + { + $downloadAttachmentLink = Uri::root() . 'index.php?option=com_tjcertificate&task=trainingrecord.downloadAttachment&id=' . $this->item->mediaData[0]->media_id . '&recordId=' . $this->item->id; + echo ''; + ?> + + item->mediaData[0]->title;?> + + + + + + +
+
+ form->renderField('state'); ?> + form->renderField('comment'); ?> + +
+ + + + +
+ +
+
+ + diff --git a/src/components/com_tjcertificate/administrator/views/trainingrecord/tmpl/index.html b/src/components/com_tjcertificate/administrator/views/trainingrecord/tmpl/index.html new file mode 100644 index 00000000..e69de29b diff --git a/src/components/com_tjcertificate/administrator/views/trainingrecord/tmpl/preview.php b/src/components/com_tjcertificate/administrator/views/trainingrecord/tmpl/preview.php new file mode 100644 index 00000000..52d5fe3c --- /dev/null +++ b/src/components/com_tjcertificate/administrator/views/trainingrecord/tmpl/preview.php @@ -0,0 +1,95 @@ + + * @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; +use Joomla\CMS\Uri\Uri; +?> +
+ + + +
+
+ +
+
+ escape($this->item->name); ?> +
+ item->cert_url) { ?> +
+ +
+
+ escape($this->item->cert_url); ?> +
+ +
+ +
+
+ escape($this->item->issuing_org); ?> +
+
+ +
+
+ escape($this->item->status)); ?> +
+
+ +
+
+ certificate->getFormatedDate($this->item->issued_on);?> +
+ item->expired_on != "0000-00-00 00:00:00") { ?> +
+ +
+
+ certificate->getFormatedDate($this->item->expired_on);?> +
+ + item->cert_file) { ?> +
+
+
+ item->mediaData[0]) + { + if ($this->item->mediaData[0]->type === "image") + { + ?> + + + + item->mediaData[0]->title;?> + + + +
+ + item->comment) { ?> +
+ +
+
+ escape($this->item->comment); ?> +
+ +
+
diff --git a/src/components/com_tjcertificate/administrator/views/trainingrecord/view.html.php b/src/components/com_tjcertificate/administrator/views/trainingrecord/view.html.php new file mode 100644 index 00000000..ac0ec1f5 --- /dev/null +++ b/src/components/com_tjcertificate/administrator/views/trainingrecord/view.html.php @@ -0,0 +1,191 @@ + + * @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\CMS\MVC\View\HtmlView; +use Joomla\CMS\Component\ComponentHelper; + +/** + * View to edit + * + * @since __DEPLOY_VERSION__ + */ +class TjCertificateViewTrainingRecord extends HtmlView +{ + /** + * The JForm object + * + * @var JForm + */ + protected $form; + + /** + * The active item + * + * @var object + */ + protected $item; + + /** + * The model state + * + * @var object + */ + protected $state; + + /** + * The actions the user is authorised to perform + * + * @var JObject + */ + protected $canDo; + + public $isAgencyEnabled = false; + + protected $comMultiAgency = 'com_multiagency'; + + /** + * Display the view + * + * @param string $tpl Template name + * + * @return void + * + * @throws Exception + */ + public function display($tpl = null) + { + $this->state = $this->get('State'); + $this->item = $this->get('Item'); + $this->form = $this->get('Form'); + $this->input = Factory::getApplication()->input; + $this->canDo = JHelperContent::getActions('com_tjcertificate', 'certificate', $this->item->id); + $this->params = ComponentHelper::getParams('com_tjcertificate'); + $this->allowedFileExtensions = $this->params->get('upload_extensions'); + $this->uploadLimit = $this->params->get('upload_maxsize', '1024'); + $this->certificate = TJCERT::Certificate(); + + if (ComponentHelper::isEnabled($this->comMultiAgency) && $this->params->get('enable_multiagency')) + { + $this->isAgencyEnabled = true; + } + + $layout = $this->input->get('layout', 'edit'); + + // Check for errors. + if (count($errors = $this->get('Errors'))) + { + throw new Exception(implode("\n", $errors), 500); + } + + $this->addToolbar(); + + parent::display($tpl); + } + + /** + * Add the page title and toolbar. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + protected function addToolbar() + { + $user = Factory::getUser(); + $userId = $user->id; + $isNew = empty($this->item->id); + + // Built the actions for new and existing records. + $canDo = $this->canDo; + $layout = Factory::getApplication()->input->get("layout"); + + $app = Factory::getApplication(); + + JLoader::import('administrator.components.com_tjcertificate.helpers.tjcertificate', JPATH_SITE); + TjCertificateHelper::addSubmenu('certificates'); + + if ($app->isAdmin()) + { + $this->sidebar = JHtmlSidebar::render(); + } + + // For new records, check the create permission. + if ($layout != "default") + { + Factory::getApplication()->input->set('hidemainmenu', true); + + JToolbarHelper::title( + Text::_('COM_TJCERTIFICATE_PAGE_' . ($isNew ? 'ADD_TRAINING_RECORD' : 'EDIT_TRAINING_RECORD')), + 'pencil-2 certificate-add' + ); + + if ($isNew) + { + JToolbarHelper::apply('trainingrecord.apply'); + JToolbarHelper::save('trainingrecord.save'); + JToolbarHelper::save2new('trainingrecord.save2new'); + } + else + { + $itemEditable = $this->isEditable($canDo, $userId); + + // Can't save the record if it's checked out and editable + $this->canSave($itemEditable); + } + + if (empty($this->item->id)) + { + JToolbarHelper::cancel('certificate.cancel'); + } + else + { + JToolbarHelper::cancel('certificate.cancel', 'JTOOLBAR_CLOSE'); + } + } + + JToolbarHelper::divider(); + } + + /** + * Can't save the record if it's checked out and editable + * + * @param boolean $itemEditable Item editable + * + * @return void + */ + protected function canSave($itemEditable) + { + if ($itemEditable) + { + JToolbarHelper::apply('trainingrecord.apply'); + JToolbarHelper::save('trainingrecord.save'); + } + } + + /** + * Is editable + * + * @param Object $canDo Checked Out + * + * @param integer $userId User ID + * + * @return boolean + */ + protected function isEditable($canDo, $userId) + { + // Since it's an existing record, check the edit permission, or fall back to edit own if the owner. + return $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId); + } +} diff --git a/src/components/com_tjcertificate/media/fields/legend.php b/src/components/com_tjcertificate/media/fields/legend.php new file mode 100644 index 00000000..ea299265 --- /dev/null +++ b/src/components/com_tjcertificate/media/fields/legend.php @@ -0,0 +1,78 @@ + + * @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\Form\FormHelper; + +FormHelper::loadFieldClass('list'); + +/** + * Custom Legend field for component params. + * + * @package Com_Tjcertificate + * @since 1.0 + */ +class JFormFieldLegend extends \JFormFieldList +{ + /** + * The form field type. + * + * @var string + * @since 1.0 + */ + protected $type = 'Legend'; + + /** + * Method to get the field input markup. + * + * @return string The field input markup. + * + * @since 1.0 + */ + public function getInput() + { + $document = Factory::getDocument(); + + if (JVERSION < '3.0') + { + $element = (array) $this->element; + $hint = $element['@attributes']['hint']; + } + else + { + $hint = $this->hint; + + /*Let's remove controls class from parent + And, remove control-group class from grandparent*/ + $script = 'jQuery(document).ready(function(){ + jQuery("#' . $this->id . '").parent().removeClass("controls"); + jQuery("#' . $this->id . '").parent().parent().removeClass("control-group"); + });'; + + $document->addScriptDeclaration($script); + } + + // Show them a legend. + $return = '' . Text::_($this->value) . ''; + + // Show them a hint below the legend. + // Let them go - GaGa about the legend. + if (!empty($hint)) + { + $return .= '' . Text::_($hint) . ''; + $return .= '

'; + } + + return $return; + } +} diff --git a/src/components/com_tjcertificate/media/images/buttons/en_US.png b/src/components/com_tjcertificate/media/images/buttons/en_US.png new file mode 100644 index 00000000..22fdb3a4 Binary files /dev/null and b/src/components/com_tjcertificate/media/images/buttons/en_US.png differ diff --git a/src/components/com_tjcertificate/media/images/loader/loader.gif b/src/components/com_tjcertificate/media/images/loader/loader.gif new file mode 100644 index 00000000..bc7b972d Binary files /dev/null and b/src/components/com_tjcertificate/media/images/loader/loader.gif differ diff --git a/src/components/com_tjcertificate/media/js/certificate.js b/src/components/com_tjcertificate/media/js/certificate.js new file mode 100644 index 00000000..f6e17ef7 --- /dev/null +++ b/src/components/com_tjcertificate/media/js/certificate.js @@ -0,0 +1,241 @@ +/** + * @package TJCertificate + * @subpackage com_tjcertificate + * + * @author Techjoomla + * @copyright Copyright (C) 2009 - 2020 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +var certificate = { + validateFile: function(thisFile) { + /** Validation is for file field only */ + if (jQuery(thisFile).attr('type') != 'file') { + return false; + } + + /** Clear error message */ + jQuery('#system-message-container').empty(); + + var uploadedfile = jQuery(thisFile)[0].files[0]; + var fileType = uploadedfile.type; + var fileExtension = uploadedfile.name.split("."); + + /** global: allowedAttachments */ + var allowedExtensionsArray = allowedAttachments.split(","); + + var invalid = 0; + var errorMsg = new Array(); + + if ((fileExtension[fileExtension.length - 1] !== '' || fileExtension[fileExtension.length - 1] !== null) && (jQuery.inArray(fileType, allowedExtensionsArray) == -1)) { + invalid = "1"; + errorMsg.push(Joomla.JText._('COM_TJCERTIFICATE_MEDIA_INVALID_FILE_TYPE')); + } + + var uploadedFileSize = uploadedfile.size; + + + /** global: attachmentMaxSize */ + if (uploadedFileSize > attachmentMaxSize * 1024 * 1024) { + + invalid = "1"; + errorMsg.push(Joomla.JText._('COM_TJCERTIFICATE_MEDIA_UPLOAD_ERROR')); + console.log("COM_TIMELOG_FILE_SIZE_ERROR"); + } + + if (invalid) { + Joomla.renderMessages({ + 'error': errorMsg + }); + + jQuery("html, body").animate({ + scrollTop: 0 + }, 500); + + return false; + } + }, + deleteAttachment: function(currentElement) { + if (confirm(Joomla.JText._('COM_TJCERTIFICATE_CONFIRM_DELETE_ATTACHMENT')) == true) { + var formData = {}; + + if (currentElement == '' || currentElement === undefined) { + return false; + } + + formData['certificateId'] = jQuery(currentElement).attr('data-aid'); + formData['mediaId'] = jQuery(currentElement).attr('data-mid'); + + var promise = tjCertificateService.deleteAttachment(formData); + + promise.fail( + function(response) { + var messages = { + "error": [response.responseText] + }; + certificate.renderMessage(messages); + } + ).done(function(response) { + + if (!response.success && response.message) { + var messages = { + "error": [response.message] + }; + certificate.renderMessage(messages); + } + + if (response.messages) { + certificate.renderMessage(response.messages); + } + + if (response.success) { + certificate.renderMessage(response.message); + } + + jQuery(currentElement).closest("span.fileupload").remove(); + }); + } + }, + deleteItem: function(certificateId, obj) { + if (confirm(Joomla.JText._('COM_TJCERTIFICATE_DELETE_CERTIFICATE_MESSAGE')) == true) { + var formData = {}; + + if (certificateId == '' || certificateId === undefined) { + return false; + } + + formData['certificateId'] = certificateId; + + var promise = tjCertificateService.deleteItem(formData); + + promise.fail( + function(response) { + var messages = { + "error": [response.responseText] + }; + certificate.renderMessage(messages); + } + ).done(function(response) { + + if (!response.success && response.message) { + var messages = { + "error": [response.message] + }; + certificate.renderMessage(messages); + } + + if (response.messages) { + certificate.renderMessage(response.messages); + } + + if (response.success) { + certificate.renderMessage(response.message); + } + + jQuery(obj).closest("tr").remove(); + }); + } + }, + renderMessage: function(msg) { + Joomla.renderMessages({ + 'alert alert-success': [msg] + }); + jQuery("html, body").animate({ + scrollTop: 0 + }, 2000); + }, + validationEndDate: function(expDateObj) { + var expDate = jQuery(expDateObj).val(); + var issueDate = jQuery('#jform_issued_on').val(); + + jQuery(document).ready(function(){ + document.formvalidator.setHandler('expdate', function (value) { + if (issueDate > expDate) { + certificate.renderMessage(Joomla.JText._('COM_TJCERTIFICATE_EXPIRY_DATE_VALIDATION_MESSAGE')); + jQuery('#jform_expired_on').val(""); + + return false; + } + + return true; + + }); + }); + }, + getAgencyUsers: function(agencyObj) { + var formData = {}; + var clusterusers = jQuery('#jform_assigned_user_id'); + var assignedUser = jQuery('#assigned_user_id').val(); + formData['agency_id'] = jQuery(agencyObj).val(); + + var promise = tjCertificateService.getAgencyUsers(formData); + + promise.fail( + function(response) { + var messages = { + "error": [response.responseText] + }; + Joomla.renderMessage(messages); + } + ).done(function(response) { + + if (!response) + { + return false; + } + + if (response.success) { + clusterusers.empty(); + clusterusers.trigger("liszt:updated"); + + var data = response.data; + + for(var index = 0; index < data.length; ++index) + { + selectOption = ''; + if (assignedUser == data[index].value) + { + selectOption = ' selected="selected" '; + } + op="" ; + clusterusers.append(op); + } + + /* IMP : to update to chz-done selects*/ + clusterusers.trigger("liszt:updated"); + } + }); + }, + addRecords: function() { + certificate.showLoader(); + var formData = jQuery('.add-records').serialize(); + var params = {}; + params['async'] = true; + var promise = tjCertificateService.addRecords(formData,params); + + promise.fail( + function(response) { + var messages = {"error": [response.responseText]}; + Joomla.renderMessages(messages); + } + ).done(function(response) { + jQuery.LoadingOverlay("hide"); + + if (!response.success && response.message){ + var messages = { "error": [response.message]}; + Joomla.renderMessages(messages); + } + + if (response.success) { + certificate.renderMessage(response.data.msg); + jQuery('#adminForm').trigger("reset"); + jQuery('#jform_assigned_user_id').trigger("liszt:updated"); + } + }); + }, + showLoader: function() { + jQuery.LoadingOverlay("show", { + image : Joomla.getOptions('system.paths').root + "/media/com_tjcertificate/images/loader/loader.gif", + }); + } +}; diff --git a/src/components/com_tjcertificate/media/js/certificate.min.js b/src/components/com_tjcertificate/media/js/certificate.min.js new file mode 100644 index 00000000..129392a1 --- /dev/null +++ b/src/components/com_tjcertificate/media/js/certificate.min.js @@ -0,0 +1 @@ +var certificate={validateFile:function(e){if("file"!=jQuery(e).attr("type"))return!1;jQuery("#system-message-container").empty();var r=jQuery(e)[0].files[0],t=r.type,a=r.name.split("."),s=allowedAttachments.split(","),i=0,o=new Array;return""===a[a.length-1]&&null===a[a.length-1]||-1!=jQuery.inArray(t,s)||(i="1",o.push(Joomla.JText._("COM_TJCERTIFICATE_MEDIA_INVALID_FILE_TYPE"))),r.size>1024*attachmentMaxSize*1024&&(i="1",o.push(Joomla.JText._("COM_TJCERTIFICATE_MEDIA_UPLOAD_ERROR")),console.log("COM_TIMELOG_FILE_SIZE_ERROR")),i?(Joomla.renderMessages({error:o}),jQuery("html, body").animate({scrollTop:0},500),!1):void 0},deleteAttachment:function(e){if(1==confirm(Joomla.JText._("COM_TJCERTIFICATE_CONFIRM_DELETE_ATTACHMENT"))){var r={};if(""==e||void 0===e)return!1;r.certificateId=jQuery(e).attr("data-aid"),r.mediaId=jQuery(e).attr("data-mid"),tjCertificateService.deleteAttachment(r).fail(function(e){var r={error:[e.responseText]};certificate.renderMessage(r)}).done(function(r){if(!r.success&&r.message){var t={error:[r.message]};certificate.renderMessage(t)}r.messages&&certificate.renderMessage(r.messages),r.success&&certificate.renderMessage(r.message),jQuery(e).closest("span.fileupload").remove()})}},deleteItem:function(e,r){if(1==confirm(Joomla.JText._("COM_TJCERTIFICATE_DELETE_CERTIFICATE_MESSAGE"))){var t={};if(""==e||void 0===e)return!1;t.certificateId=e,tjCertificateService.deleteItem(t).fail(function(e){var r={error:[e.responseText]};certificate.renderMessage(r)}).done(function(e){if(!e.success&&e.message){var t={error:[e.message]};certificate.renderMessage(t)}e.messages&&certificate.renderMessage(e.messages),e.success&&certificate.renderMessage(e.message),jQuery(r).closest("tr").remove()})}},renderMessage:function(e){Joomla.renderMessages({"alert alert-success":[e]}),jQuery("html, body").animate({scrollTop:0},2e3)},validationEndDate:function(e){var r=jQuery(e).val(),t=jQuery("#jform_issued_on").val();jQuery(document).ready(function(){document.formvalidator.setHandler("expdate",function(e){return!(t>r)||(certificate.renderMessage(Joomla.JText._("COM_TJCERTIFICATE_EXPIRY_DATE_VALIDATION_MESSAGE")),jQuery("#jform_expired_on").val(""),!1)})})},getAgencyUsers:function(e){var r={},t=jQuery("#jform_assigned_user_id"),a=jQuery("#assigned_user_id").val();r.agency_id=jQuery(e).val(),tjCertificateService.getAgencyUsers(r).fail(function(e){var r={error:[e.responseText]};Joomla.renderMessage(r)}).done(function(e){if(!e)return!1;if(e.success){t.empty(),t.trigger("liszt:updated");for(var r=e.data,s=0;s "+r[s].text+"",t.append(op);t.trigger("liszt:updated")}})},addRecords:function(){certificate.showLoader();var e=jQuery(".add-records").serialize(),r={async:!0};tjCertificateService.addRecords(e,r).fail(function(e){var r={error:[e.responseText]};Joomla.renderMessages(r)}).done(function(e){if(jQuery.LoadingOverlay("hide"),!e.success&&e.message){var r={error:[e.message]};Joomla.renderMessages(r)}e.success&&(certificate.renderMessage(e.data.msg),jQuery("#adminForm").trigger("reset"),jQuery("#jform_assigned_user_id").trigger("liszt:updated"))})},showLoader:function(){jQuery.LoadingOverlay("show",{image:Joomla.getOptions("system.paths").root+"/media/com_tjcertificate/images/loader/loader.gif"})}}; diff --git a/src/components/com_tjcertificate/media/js/certificateImage.js b/src/components/com_tjcertificate/media/js/certificateImage.js index ce2977d9..445be385 100644 --- a/src/components/com_tjcertificate/media/js/certificateImage.js +++ b/src/components/com_tjcertificate/media/js/certificateImage.js @@ -44,10 +44,17 @@ var certificateImage = { var imagePath = certRootUrl + 'media/com_tjcertificate/certificates/'; var img = document.createElement('img'); jQuery('#certificateContent').hide(); - img.src = imagePath + certificateId + ".png"; + img.src = imagePath + certificateId + ".png?ver=" + tjCertVersion; jQuery("#previewImage").append(img); setTimeout(function(){ - Joomla.loadingLayer('hide'); + + if (screen.width < 1200) + { + viewport = document.querySelector("meta[name=viewport]"); + viewport.setAttribute("content", "width=device-width"); + } + + jQuery.LoadingOverlay("hide"); }, 1000); } }); @@ -57,13 +64,23 @@ var certificateImage = { generateImage: function(element) { // jQuery('#certificateContent').width(element.offsetWidth).height(element.offsetHeight); - Joomla.loadingLayer('show'); + + if (screen.width < 1200) + { + viewport = document.querySelector("meta[name=viewport]"); + viewport.setAttribute("content", "width=1200px"); + } + + jQuery.LoadingOverlay("show", { + image : "media/com_tjcertificate/images/loader/loader.gif" + }); html2canvas(element, { // scale: (2), scrollX: 0, scrollY: -window.scrollY, - allowTaint: true + allowTaint: true, + useCORS: true }).then(function(canvas) { certificateImage.enableDownloadShareBtns(); certificateImage.uploadImage(canvas.toDataURL('image/png')); diff --git a/src/components/com_tjcertificate/media/js/certificateImage.min.js b/src/components/com_tjcertificate/media/js/certificateImage.min.js index de5e7ab6..4ba1d134 100644 --- a/src/components/com_tjcertificate/media/js/certificateImage.min.js +++ b/src/components/com_tjcertificate/media/js/certificateImage.min.js @@ -1 +1 @@ -var certificateImage={printCertificate:function(e){var t=document.getElementById(e).innerHTML,o=document.body.innerHTML;document.body.innerHTML=t,window.print(),document.body.innerHTML=o,certificateImage.enableDownloadShareBtns()},enableDownloadShareBtns:function(){jQuery("#download-popover").popover({trigger:"focus",html:!0,content:jQuery("#download-popover-content").html()}),jQuery("#sharing-popover").popover({trigger:"focus",html:!0,content:jQuery("#sharing-popover-content").html()}),jQuery("#copyurl").popover()},uploadImage:function(e){var t=!1,o=jQuery("#certificateId").val();return jQuery.ajax({url:certRootUrl+"index.php?option=com_tjcertificate&task=certificate.uploadCertificate",type:"POST",data:{image:e,certificateId:o},success:function(e){t=e;var o=jQuery("#certificateId").val(),n=certRootUrl+"media/com_tjcertificate/certificates/",r=document.createElement("img");jQuery("#certificateContent").hide(),r.src=n+o+".png",jQuery("#previewImage").append(r),setTimeout(function(){Joomla.loadingLayer("hide")},1e3)}}),t},generateImage:function(e){Joomla.loadingLayer("show"),html2canvas(e,{scrollX:0,scrollY:-window.scrollY,allowTaint:!0}).then(function(e){certificateImage.enableDownloadShareBtns(),certificateImage.uploadImage(e.toDataURL("image/png"))})},copyUrl:function(e){e="#"+e;var t=document.createElement("input"),o=jQuery(e).attr("data-alt-url");jQuery(e).popover("show"),document.body.appendChild(t),t.value=o,t.select(),document.execCommand("copy"),document.body.removeChild(t),setTimeout(function(){jQuery(e).popover("hide")},1e3)}}; \ No newline at end of file +var certificateImage={printCertificate:function(e){var t=document.getElementById(e).innerHTML,o=document.body.innerHTML;document.body.innerHTML=t,window.print(),document.body.innerHTML=o,certificateImage.enableDownloadShareBtns()},enableDownloadShareBtns:function(){jQuery("#download-popover").popover({trigger:"focus",html:!0,content:jQuery("#download-popover-content").html()}),jQuery("#sharing-popover").popover({trigger:"focus",html:!0,content:jQuery("#sharing-popover-content").html()}),jQuery("#copyurl").popover()},uploadImage:function(e){var t=!1,o=jQuery("#certificateId").val();return jQuery.ajax({url:certRootUrl+"index.php?option=com_tjcertificate&task=certificate.uploadCertificate",type:"POST",data:{image:e,certificateId:o},success:function(e){t=e;var o=jQuery("#certificateId").val(),r=certRootUrl+"media/com_tjcertificate/certificates/",n=document.createElement("img");jQuery("#certificateContent").hide(),n.src=r+o+".png?ver="+tjCertVersion,jQuery("#previewImage").append(n),setTimeout(function(){screen.width<1200&&(viewport=document.querySelector("meta[name=viewport]"),viewport.setAttribute("content","width=device-width")),jQuery.LoadingOverlay("hide")},1e3)}}),t},generateImage:function(e){screen.width<1200&&(viewport=document.querySelector("meta[name=viewport]"),viewport.setAttribute("content","width=1200px")),jQuery.LoadingOverlay("show",{image:"media/com_tjcertificate/images/loader/loader.gif"}),html2canvas(e,{scrollX:0,scrollY:-window.scrollY,allowTaint:!0,useCORS:!0}).then(function(e){certificateImage.enableDownloadShareBtns(),certificateImage.uploadImage(e.toDataURL("image/png"))})},copyUrl:function(e){e="#"+e;var t=document.createElement("input"),o=jQuery(e).attr("data-alt-url");jQuery(e).popover("show"),document.body.appendChild(t),t.value=o,t.select(),document.execCommand("copy"),document.body.removeChild(t),setTimeout(function(){jQuery(e).popover("hide")},1e3)}}; \ No newline at end of file diff --git a/src/components/com_tjcertificate/media/js/template.js b/src/components/com_tjcertificate/media/js/template.js index ab980df2..60756439 100644 --- a/src/components/com_tjcertificate/media/js/template.js +++ b/src/components/com_tjcertificate/media/js/template.js @@ -9,19 +9,20 @@ var template = { - previewTemplate: function () { + previewTemplate: function (id) { jQuery(document).on('click', 'button[data-target="#templatePreview"]', function () { - + jQuery('#show-info').hide(); + var editorId = jQuery('#'+id); if (typeof tinyMCE != "undefined") { - tinyMCE.execCommand('mceToggleEditor', false, 'jform_body'); + tinyMCE.execCommand('mceToggleEditor', false, id); } else if (typeof CodeMirror != "undefined") { var editor = document.querySelector('.CodeMirror').CodeMirror; - jQuery('#jform_body').html(editor.getValue()); + editorId.html(editor.getValue()); } else { @@ -30,14 +31,14 @@ var template = { jQuery('#previewTempl').empty(); jQuery('"].join(" "))})}); diff --git a/src/components/com_tjcertificate/plugins/tjqueue/certificate/certificate.php b/src/components/com_tjcertificate/plugins/tjqueue/certificate/certificate.php new file mode 100644 index 00000000..6a4166e4 --- /dev/null +++ b/src/components/com_tjcertificate/plugins/tjqueue/certificate/certificate.php @@ -0,0 +1,38 @@ + + * @copyright Copyright (c) 2009-2021 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die; + +use Joomla\CMS\Plugin\CMSPlugin; + +/** + * TjQueue + * + * @package Techjoomla.Libraries + * @subpackage Tjqueue + * @since 1.0 + */ +class PlgTjqueueRecords extends CMSPlugin +{ + /** + * Load the language file on instantiation. Note this is only available in Joomla 3.1 and higher. + * + * @var boolean + * @since 3.1 + */ + protected $autoloadLanguage = true; + + /** + * Plugin method with the same name as the event will be called automatically. + */ + public function __construct() + { + return true; + } +} diff --git a/src/components/com_tjcertificate/plugins/tjqueue/certificate/certificate.xml b/src/components/com_tjcertificate/plugins/tjqueue/certificate/certificate.xml new file mode 100644 index 00000000..fc7748b1 --- /dev/null +++ b/src/components/com_tjcertificate/plugins/tjqueue/certificate/certificate.xml @@ -0,0 +1,23 @@ + + + plg_tjqueue_certificate + Techjoomla + 31st March 2021 + Copyright (C) 2016 - 2021 Techjoomla. All rights reserved. + http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + extensions@techjoomla.com + https://techjoomla.com + 1.0.0 + PLG_TJQUEUE_CERTIFICATE_XML_DESCRIPTION + + + certificate.php + index.html + consumers + + + + en-GB/en-GB.plg_tjqueue_certificate.ini + en-GB/en-GB.plg_tjqueue_certificate.sys.ini + + diff --git a/src/components/com_tjcertificate/plugins/tjqueue/certificate/consumers/index.html b/src/components/com_tjcertificate/plugins/tjqueue/certificate/consumers/index.html new file mode 100644 index 00000000..0dc101b5 --- /dev/null +++ b/src/components/com_tjcertificate/plugins/tjqueue/certificate/consumers/index.html @@ -0,0 +1 @@ + diff --git a/src/components/com_tjcertificate/plugins/tjqueue/certificate/consumers/records.php b/src/components/com_tjcertificate/plugins/tjqueue/certificate/consumers/records.php new file mode 100644 index 00000000..2e5a49c9 --- /dev/null +++ b/src/components/com_tjcertificate/plugins/tjqueue/certificate/consumers/records.php @@ -0,0 +1,43 @@ + + * @copyright Copyright (c) 2009-2021 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ + +// No direct access +defined('_JEXEC') or die; + +use \Joomla\Registry\Registry; +JLoader::import('components.com_tjcertificate.includes.tjcertificate', JPATH_ADMINISTRATOR); + +/** + * TjQueue + * + * @package Techjoomla.Libraries + * @subpackage Tjqueue + * @since __DEPLOY_VERSION__ + */ +class TjqueueCertificateRecords +{ + /** + * Plugin method with the same name as the event will be called automatically. + * + * @param string $message A Message + * + * @return boolean This method should return acknowledgement flag + * + * @since __DEPLOY_VERSION__ + */ + public function consume($message) + { + $messageBody = $message->getBody(); + $messageData = new Registry($messageBody); + $messageData = $messageData->toArray(); + $certificateModel = TJCERT::model('Certificate', array('ignore_request' => true)); + $certificateModel->save($messageData); + + return true; + } +} diff --git a/src/components/com_tjcertificate/plugins/tjqueue/certificate/index.html b/src/components/com_tjcertificate/plugins/tjqueue/certificate/index.html new file mode 100644 index 00000000..0dc101b5 --- /dev/null +++ b/src/components/com_tjcertificate/plugins/tjqueue/certificate/index.html @@ -0,0 +1 @@ + diff --git a/src/components/com_tjcertificate/plugins/tjqueue/certificate/languages/en-GB/en-GB.plg_tjqueue_certificate.ini b/src/components/com_tjcertificate/plugins/tjqueue/certificate/languages/en-GB/en-GB.plg_tjqueue_certificate.ini new file mode 100644 index 00000000..4b8c66d2 --- /dev/null +++ b/src/components/com_tjcertificate/plugins/tjqueue/certificate/languages/en-GB/en-GB.plg_tjqueue_certificate.ini @@ -0,0 +1,2 @@ +PLG_TJQUEUE_CERTIFICATE="TjQueue plugin for TjCertificate" +PLG_TJQUEUE_CERTIFICATE_XML_DESCRIPTION="This plugin used to add bulk records using TjQueue" diff --git a/src/components/com_tjcertificate/plugins/tjqueue/certificate/languages/en-GB/en-GB.plg_tjqueue_certificate.sys.ini b/src/components/com_tjcertificate/plugins/tjqueue/certificate/languages/en-GB/en-GB.plg_tjqueue_certificate.sys.ini new file mode 100644 index 00000000..5477f68c --- /dev/null +++ b/src/components/com_tjcertificate/plugins/tjqueue/certificate/languages/en-GB/en-GB.plg_tjqueue_certificate.sys.ini @@ -0,0 +1,3 @@ +PLG_TJQUEUE_CERTIFICATE="TjQueue plugin for TjCertificate" +PLG_TJQUEUE_CERTIFICATE_XML_DESCRIPTION="This plugin used to add bulk records using TjQueue" + diff --git a/src/components/com_tjcertificate/script.tjcertificate.php b/src/components/com_tjcertificate/script.tjcertificate.php index f05596a8..b2a035a3 100644 --- a/src/components/com_tjcertificate/script.tjcertificate.php +++ b/src/components/com_tjcertificate/script.tjcertificate.php @@ -23,6 +23,17 @@ */ class Com_TjcertificateInstallerScript { + /** @var array The list of extra modules and plugins to install */ + private $installation_queue = array( + + // Plugins => { (folder) => { (element) => (published) }* }* + 'plugins' => array( + 'tjqueue' => array( + 'certificate' => 0, + ) + ) + ); + /** * Runs after install, update or discover_update * @@ -46,6 +57,106 @@ public function postflight($type, $parent) return false; } + $this->installNotificationsTemplates(); + + // Install subextensions + $this->_installSubextensions($parent); + return true; } + + /** + * Installed Notifications Templates + * + * @return void + */ + public function installNotificationsTemplates() + { + jimport('joomla.application.component.model'); + JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjnotifications/tables'); + JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjnotifications/models'); + $notificationsModel = JModelLegacy::getInstance('Notification', 'TJNotificationsModel'); + + $filePath = JPATH_ADMINISTRATOR . '/components/com_tjcertificate/tjcertificateTemplate.json'; + $str = file_get_contents($filePath); + $json = json_decode($str, true); + + $existingKeys = $notificationsModel->getKeys('com_tjcertificate'); + + if (count($json) != 0) + { + foreach ($json as $template => $array) + { + // If template doesn't exist then we add notification template. + if (!in_array($array['key'], $existingKeys)) + { + $notificationsModel->createTemplates($array); + } + } + } + } + + /** + * Installs subextensions (modules, plugins) bundled with the main extension + * + * @param JInstaller $parent + * + * @return JObject The subextension installation status + */ + private function _installSubextensions($parent) + { + $src = $parent->getParent()->getPath('source'); + + $db = JFactory::getDbo(); + + // Plugins installation + if (count($this->installation_queue['plugins'])) + { + foreach ($this->installation_queue['plugins'] as $folder => $plugins) + { + if (count($plugins)) + { + foreach ($plugins as $plugin => $published) + { + $path = "$src/plugins/$folder/$plugin"; + + if (!is_dir($path)) + { + $path = "$src/plugins/$folder/plg_$plugin"; + } + + if (!is_dir($path)) + { + $path = "$src/plugins/$plugin"; + } + + if (!is_dir($path)) + { + $path = "$src/plugins/plg_$plugin"; + } + + if (!is_dir($path)) + { + continue; + } + + // Was the plugin already installed? + $query = $db->getQuery(true)->select('COUNT(*)')->from($db->qn('#__extensions'))->where($db->qn('element') . ' = ' . $db->q($plugin))->where($db->qn('folder') . ' = ' . $db->q($folder)); + $db->setQuery($query); + $count = $db->loadResult(); + + $installer = new JInstaller; + $result = $installer->install($path); + + if ($published && !$count) + { + $query = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('enabled') . ' = ' . $db->q('1'))->where($db->qn('element') . ' = ' . $db->q($plugin))->where($db->qn('folder') . ' = ' . $db->q($folder)); + $db->setQuery($query); + $db->execute(); + } + } + } + } + } + } } diff --git a/src/components/com_tjcertificate/site/controllers/agency.json.php b/src/components/com_tjcertificate/site/controllers/agency.json.php new file mode 100644 index 00000000..9ee1c174 --- /dev/null +++ b/src/components/com_tjcertificate/site/controllers/agency.json.php @@ -0,0 +1,15 @@ + + * @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'); + +// Todo: Load with jimport +require_once JPATH_ADMINISTRATOR . '/components/com_tjcertificate/controllers/agency.json.php'; diff --git a/src/components/com_tjcertificate/site/controllers/bulktrainingrecord.json.php b/src/components/com_tjcertificate/site/controllers/bulktrainingrecord.json.php new file mode 100644 index 00000000..8b2fb0ea --- /dev/null +++ b/src/components/com_tjcertificate/site/controllers/bulktrainingrecord.json.php @@ -0,0 +1,14 @@ + + * @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'); + +require_once JPATH_ADMINISTRATOR . '/components/com_tjcertificate/controllers/bulktrainingrecord.json.php'; diff --git a/src/components/com_tjcertificate/site/controllers/certificates.php b/src/components/com_tjcertificate/site/controllers/certificates.php new file mode 100644 index 00000000..0aeda9e7 --- /dev/null +++ b/src/components/com_tjcertificate/site/controllers/certificates.php @@ -0,0 +1,106 @@ + + * @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\MVC\Controller\AdminController; +use Joomla\Utilities\ArrayHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; + +/** + * Certificate list controller class. + * + * @since __DEPLOY_VERSION__ + */ +class TjCertificateControllerCertificates extends AdminController +{ + /** + * Proxy for getModel. + * + * @param STRING $name model name + * @param STRING $prefix model prefix + * + * @return object The model. + * + * @since __DEPLOY_VERSION__ + */ + public function getModel($name = 'Certificate', $prefix = 'TjCertificateModel', $config = []) + { + return parent::getModel($name, $prefix, array('ignore_request' => true)); + } + + /** + * Method to publish a list of records. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function publish() + { + $user = Factory::getUser(); + + if (!$user->authorise('certificate.external.manage', 'com_tjcertificate')) + { + JError::raiseWarning(403, Text::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED')); + + return false; + } + + $cid = Factory::getApplication()->input->get('cid', array(), 'array'); + $data = array( + 'publish' => 1, + 'unpublish' => 0 + ); + + $task = $this->getTask(); + $value = JArrayHelper::getValue($data, $task, 0, 'int'); + + // Get some variables from the request + if (empty($cid)) + { + throw new Exception(Text::_('COM_TJCERTIFICATE_NO_RECORD_SELECTED')); + } + else + { + // Get the model. + $model = $this->getModel(); + + // Make sure the item ids are integers + JArrayHelper::toInteger($cid); + + // Publish the items. + try + { + $model->publish($cid, $value); + + if ($value == 1) + { + $ntext = 'COM_TJCERTIFICATE_N_RECORD_PUBLISHED'; + } + elseif ($value == 0) + { + $ntext = 'COM_TJCERTIFICATE_N_RECORD_UNPUBLISHED'; + } + + $this->setMessage(Text::plural($ntext, count($cid))); + } + catch (Exception $e) + { + $this->setMessage($e->getMessage(), 'error'); + } + } + + $this->setRedirect('index.php?option=com_tjcertificate&view=certificates&layout=my'); + } +} diff --git a/src/components/com_tjcertificate/site/controllers/trainingrecord.json.php b/src/components/com_tjcertificate/site/controllers/trainingrecord.json.php new file mode 100644 index 00000000..4624a6f9 --- /dev/null +++ b/src/components/com_tjcertificate/site/controllers/trainingrecord.json.php @@ -0,0 +1,15 @@ + + * @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'); + +// Todo: Load with jimport +require_once JPATH_ADMINISTRATOR . '/components/com_tjcertificate/controllers/trainingrecord.json.php'; diff --git a/src/components/com_tjcertificate/site/controllers/trainingrecord.php b/src/components/com_tjcertificate/site/controllers/trainingrecord.php new file mode 100644 index 00000000..b446a754 --- /dev/null +++ b/src/components/com_tjcertificate/site/controllers/trainingrecord.php @@ -0,0 +1,14 @@ + + * @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'); + +JLoader::import('components.com_tjcertificate.controllers.trainingrecord', JPATH_ADMINISTRATOR); diff --git a/src/components/com_tjcertificate/site/events/record.php b/src/components/com_tjcertificate/site/events/record.php new file mode 100644 index 00000000..31646666 --- /dev/null +++ b/src/components/com_tjcertificate/site/events/record.php @@ -0,0 +1,91 @@ + + * @copyright Copyright (C) 2009 - 2020 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +// No direct access +defined('_JEXEC') or die('Restricted access'); + +use Joomla\CMS\Factory; +use Joomla\CMS\Component\ComponentHelper; + +JLoader::import('components.com_tjcertificate.libraries.mails', JPATH_ADMINISTRATOR); +jimport('techjoomla.tjnotifications.tjnotifications'); + +/** + * Tjcertificate triggers class for record. + * + * @since __DEPLOY_VERSION__ + */ +class TjCertificateTriggerRecord +{ + /** + * Method acts as a consturctor + * + * @since __DEPLOY_VERSION__ + */ + public function __construct() + { + $app = Factory::getApplication(); + $this->menu = $app->getMenu(); + $this->params = ComponentHelper::getParams('com_tjcertificate'); + $this->siteConfig = Factory::getConfig(); + $this->sitename = $this->siteConfig->get('sitename'); + $this->user = Factory::getUser(); + $this->tjnotifications = new Tjnotifications; + $this->tjCertificateMails = new TjCertificateMails; + } + + /** + * Trigger for record after save + * + * @param OBJECT $recordDetails Record Details + * + * @param int $isNew isNew = true / !isNew = false + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function onAfterRecordSave($recordDetails, $isNew) + { + switch ($isNew && $recordDetails->notify) + { + case true: + /* Send mail on record create */ + $this->tjCertificateMails->onAfterCreateRecord($recordDetails); + break; + } + + return; + } + + /** + * Trigger for record state change + * + * @param OBJECT $recordDetails Record Details + * + * @param int $isPublished isPublished = 1 / !isPublished = 0 + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function onRecordStateChange($recordDetails, $isPublished) + { + switch ($isPublished) + { + case 1: + /* Send mail on record approved */ + $this->tjCertificateMails->onAfterRecordStateChange($recordDetails, $isPublished); + break; + } + + return; + } +} diff --git a/src/components/com_tjcertificate/site/languages/en-GB/en-GB.com_tjcertificate.ini b/src/components/com_tjcertificate/site/languages/en-GB/en-GB.com_tjcertificate.ini index 9deabb4b..e913b148 100644 --- a/src/components/com_tjcertificate/site/languages/en-GB/en-GB.com_tjcertificate.ini +++ b/src/components/com_tjcertificate/site/languages/en-GB/en-GB.com_tjcertificate.ini @@ -59,6 +59,7 @@ COM_TJCERTIFICATE_CERTIFICATE_LIST_VIEW_TYPE="Type" COM_TJCERTIFICATE_CERTIFICATE_LIST_VIEW_NAME="Title" COM_TJCERTIFICATE_CLIENT_COM_TJLMS_COURSE="Course" COM_TJCERTIFICATE_CLIENT_COM_JTICKETING_EVENT="Event" +COM_TJCERTIFICATE_CLIENT_EXTERNAL="External" ;Detail view COM_TJCERTIFICATE_CERTIFICATE_DOWNLOAD_SHARE="Share" @@ -72,3 +73,80 @@ COM_TJCERTIFICATE_CERTIFICATE_BACK_BUTTON="Back" COM_TJCERTIFICATE_CERTIFICATE_URL_COPY="Copy URL" COM_TJCERTIFICATE_CERTIFICATE_LIST_VIEW_CERTIFICATE_ID="Certificate Id" COM_TJCERTIFICATE_CERTIFICATE_FILTER_CERTIFICATE_TYPE_SELECT="- Select Type -" + +;__DEPLOY_VERSION__ +;Record form +COM_TJCERTIFICATE_FORM_LBL_CERTIFICATE_NAME="Name" +COM_TJCERTIFICATE_FORM_LBL_CERTIFICATE_NAME_DESC="Record name" +COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_ID="Record Id" +COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_ID_DESC="Training record id or certificate 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="Issue Date" +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="Expiration Date" +COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_EXPIRY_DATE_DESC="Certificate expiry date" +COM_TJCERTIFICATE_FORM_LBL_CERTIFICATE_FILE="Certificate
(allowed formats: pdf,image)" +COM_TJCERTIFICATE_FORM_LBL_CERTIFICATE_FILE_DESC="Upload certificate pdf/image" +COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_COMMENT="Comment" +COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_COMMENT_DESC="Comment" +COM_TJCERTIFICATE_CERTIFICATE_ACTIONS="Actions" +COM_TJCERTIFICATE_DELETE_CERTIFICATE_MESSAGE="Are you sure you want to delete this training record?" +COM_TJCERTIFICATE_CERTIFICATE_DELETED_SUCCESSFULLY="Record deleted sucessfully" +COM_TJCERTIFICATE_ADD_EXTERNAL_CERTIFICATE="Add Training Record" +COM_TJCERTIFICATE_N_ITEMS_PUBLISHED="Record published" +COM_TJCERTIFICATE_N_ITEMS_UNPUBLISHED="Record unpublished" +COM_TJCERTIFICATE_EDIT_EXTERNAL_CERTIFICATE="Edit record" +COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_COUPON_CREATED_BY="Created by" +COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_COUPON_CREATED_BY_DESC="Record created by" +COM_TJCERTIFICATE_FORM_LBL_ASSIGNED_USER="Select user" +COM_TJCERTIFICATE_FORM_LBL_ASSIGNED_USER_DESC="Select user to assign a training record" +COM_TJCERTIFICATE_CERTIFICATE_USER_SELECT_OPTION="Select user" +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_EXTERNAL_CERTIFICATE_DETAIL_VIEW_HEAD="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_N_RECORD_PUBLISHED="%d record(s) successfully published" +COM_TJCERTIFICATE_N_RECORD_UNPUBLISHED="%d record(s) successfully unpublished" +COM_TJCERTIFICATE_ATTACHMENT_DELETED_SUCCESSFULLY="Attachment deleted successfully" +COM_TJCERTIFICATE_CERTIFICATE_DELETED_FAILED="Failed to delete record. Please try again after some time." +COM_TJCERTIFICATE_CERTIFICATE_FILTER_ISSUED_USER_SELECT="- Select Issued User -" +COM_TJCERTIFICATE_CERTIFICATE_FILTER_USER="Record user" +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" +COM_TJCERTIFICATE_CERTIFICATE_DETAIL_VIEW_CERTIFICATE="This certificate (ID: %s ) verifies that %s has successfully completed the %s on %s." +COM_TJCERTIFICATE_CERTIFICATE_DETAIL_VIEW_AWARDED="This certificate (ID: %s ) has been awarded to %s on %s." +COM_TJCERTIFICATE_CERTIFICATE_DETAIL_VIEW_CERTIFICATE_EXPIRES=" This Certificate expires on %s" + +;Certificate list view +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" + +;Record form +COM_TJCERTIFICATE_CERTIFICATE_FORM_LBL_CERTIFICATE_COMMENT_DESC="Add Comment" +COM_TJCERTIFICATE_INVALID_ORGANIZATION_USER="Invalid User" +COM_TJCERTIFICATE_INVALID_ORGANIZATION="Invalid Organization" + +;Bulk add form +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_ADD_EXTERNAL_CERTIFICATES="Bulk Training Records" +COM_TJCERTIFICATE_FORM_VALIDATATION_FAILED="Form Validation Failed" +COM_TJCERTIFICATE_TOTAL_RECORDS_ADDED="Records added for %s user(s)" +COM_TJCERTIFICATE_RECORDS_ADDED_TO_QUEUE_SUCCESSFULLY="Records added in queue" +COM_TJCERTIFICATE_USER_LIMIT_MESSAGE="You cannot add more than the %s records." diff --git a/src/components/com_tjcertificate/site/models/agency.php b/src/components/com_tjcertificate/site/models/agency.php new file mode 100644 index 00000000..c9a5cba8 --- /dev/null +++ b/src/components/com_tjcertificate/site/models/agency.php @@ -0,0 +1,14 @@ + + * @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'); + +JLoader::import('components.com_tjcertificate.models.agency', JPATH_ADMINISTRATOR); diff --git a/src/components/com_tjcertificate/site/models/bulktrainingrecord.php b/src/components/com_tjcertificate/site/models/bulktrainingrecord.php new file mode 100644 index 00000000..de23cb5a --- /dev/null +++ b/src/components/com_tjcertificate/site/models/bulktrainingrecord.php @@ -0,0 +1,14 @@ + + * @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'); + +JLoader::import('components.com_tjcertificate.models.bulktrainingrecord', JPATH_ADMINISTRATOR); diff --git a/src/components/com_tjcertificate/site/models/fields/createdby.php b/src/components/com_tjcertificate/site/models/fields/createdby.php new file mode 100644 index 00000000..6885915f --- /dev/null +++ b/src/components/com_tjcertificate/site/models/fields/createdby.php @@ -0,0 +1,57 @@ + + * @link http://www.techjoomla.com + */ + +defined('JPATH_BASE') or die; + +jimport('joomla.form.formfield'); + +/** + * Supports an HTML select list of categories + * + * @since __DEPLOY_VERSION__ + */ +class JFormFieldCreatedby extends JFormField +{ + /** + * The form field type. + * + * @var string + * @since __DEPLOY_VERSION__ + */ + protected $type = 'createdby'; + + /** + * Method to get the field input markup. + * + * @return string The field input markup. + * + * @since 1.6 + */ + protected function getInput() + { + // Initialize variables. + $html = array(); + + // Load user + $user_id = $this->value; + + if ($user_id) + { + $user = JFactory::getUser($user_id); + } + else + { + $user = JFactory::getUser(); + $html[] = ''; + } + + $html[] = "
{$user->name} ({$user->username})
"; + + return implode($html); + } +} diff --git a/src/components/com_tjcertificate/site/models/fields/getclientlist.php b/src/components/com_tjcertificate/site/models/fields/getclientlist.php index eb1b08bd..bc371c06 100644 --- a/src/components/com_tjcertificate/site/models/fields/getclientlist.php +++ b/src/components/com_tjcertificate/site/models/fields/getclientlist.php @@ -44,11 +44,13 @@ protected function getOptions() $query->select('DISTINCT (`client`)'); $query->from('#__tj_certificate_issue'); - $query->where($db->quoteName('state') . ' = ' . (int) 1); - if (!empty($clientByUser)) + if (!$user->authorise('certificate.external.manage', 'com_tjcertificate')) { - $query->where($db->quoteName('user_id') . ' = ' . (int) $user->id); + if (!empty($clientByUser)) + { + $query->where($db->quoteName('user_id') . ' = ' . (int) $user->id); + } } $db->setQuery($query); @@ -59,9 +61,12 @@ protected function getOptions() { foreach ($listobjects as $obj) { - $client = str_replace(".", "_", $obj->client); - $langConst = strtoupper("COM_TJCERTIFICATE_CLIENT_" . $client); - $options[] = JHtml::_('select.option', $obj->client, TEXT::_($langConst)); + if ($obj->client) + { + $client = str_replace(".", "_", $obj->client); + $langConst = strtoupper("COM_TJCERTIFICATE_CLIENT_" . $client); + $options[] = JHtml::_('select.option', $obj->client, TEXT::_($langConst)); + } } } } diff --git a/src/components/com_tjcertificate/site/models/fields/users.php b/src/components/com_tjcertificate/site/models/fields/users.php new file mode 100644 index 00000000..18b4d60b --- /dev/null +++ b/src/components/com_tjcertificate/site/models/fields/users.php @@ -0,0 +1,73 @@ + + * @copyright Copyright (C) 2009 - 2020 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +defined('JPATH_BASE') or die; + +JFormHelper::loadFieldClass('list'); +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\HTML\HTMLHelper; + +/** + * Supports an HTML select list of allocated agencies + * + * @since __DEPLOY_VERSION__ + */ +class JFormFieldUsers extends JFormFieldList +{ + /** + * The form field type. + * + * @var string + * @since 1.0.0 + */ + protected $type = 'users'; + + /** + * Method to get the field input markup. + * + * @return string The field input markup. + * + * @since __DEPLOY_VERSION__ + */ + protected function getOptions() + { + // Initialize array to store dropdown options + $loggedInuser = Factory::getUser(); + + $db = Factory::getDBO(); + $query = $db->getQuery(true); + $query->select('distinct(ci.user_id), u.name'); + $query->from($db->quoteName('#__tj_certificate_issue', 'ci')); + $query->join('LEFT', '#__users AS u ON ci.user_id = u.id'); + $query->where($db->qn('u.block') . ' = 0'); + $query->order($db->escape('u.name' . ' ' . 'asc')); + $db->setQuery($query); + $users = $db->loadObjectList(); + + $options = array(); + + if ($loggedInuser->authorise('certificate.external.manage', 'com_tjcertificate')) + { + $options[] = HTMLHelper::_('select.option', "", Text::_('COM_TJCERTIFICATE_CERTIFICATE_FILTER_ISSUED_USER_SELECT')); + + foreach ($users as $user) + { + $options[] = HTMLHelper::_('select.option', $user->user_id, $user->name); + } + } + else + { + $options[] = HTMLHelper::_('select.option', $loggedInuser->id, $loggedInuser->name); + } + + return $options; + } +} diff --git a/src/components/com_tjcertificate/site/models/forms/bulktrainingrecord.xml b/src/components/com_tjcertificate/site/models/forms/bulktrainingrecord.xml new file mode 100644 index 00000000..bf02b6c7 --- /dev/null +++ b/src/components/com_tjcertificate/site/models/forms/bulktrainingrecord.xml @@ -0,0 +1,104 @@ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/src/components/com_tjcertificate/site/models/forms/filter_certificates.xml b/src/components/com_tjcertificate/site/models/forms/filter_certificates.xml index a59021e0..6040e4b5 100644 --- a/src/components/com_tjcertificate/site/models/forms/filter_certificates.xml +++ b/src/components/com_tjcertificate/site/models/forms/filter_certificates.xml @@ -19,7 +19,39 @@ clientByUser="1" onchange="this.form.submit();" /> + + + + + + + + + + + + diff --git a/src/components/com_tjcertificate/site/models/forms/trainingrecord.xml b/src/components/com_tjcertificate/site/models/forms/trainingrecord.xml new file mode 100644 index 00000000..e1104adb --- /dev/null +++ b/src/components/com_tjcertificate/site/models/forms/trainingrecord.xml @@ -0,0 +1,153 @@ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/src/components/com_tjcertificate/site/models/trainingrecord.php b/src/components/com_tjcertificate/site/models/trainingrecord.php new file mode 100644 index 00000000..dd15f616 --- /dev/null +++ b/src/components/com_tjcertificate/site/models/trainingrecord.php @@ -0,0 +1,14 @@ + + * @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'); + +JLoader::import('components.com_tjcertificate.models.trainingrecord', JPATH_ADMINISTRATOR); diff --git a/src/components/com_tjcertificate/site/tjcertificate.php b/src/components/com_tjcertificate/site/tjcertificate.php index 8bfccd40..d0d0541f 100644 --- a/src/components/com_tjcertificate/site/tjcertificate.php +++ b/src/components/com_tjcertificate/site/tjcertificate.php @@ -15,6 +15,7 @@ use Joomla\CMS\MVC\Controller\BaseController; JLoader::import('components.com_tjcertificate.includes.tjcertificate', JPATH_ADMINISTRATOR); +TJCERT::init('site'); JLoader::registerPrefix('TjCertificate', JPATH_COMPONENT); JLoader::register('TjCertificateController', JPATH_COMPONENT . '/controller.php'); diff --git a/src/components/com_tjcertificate/site/views/bulktrainingrecord/tmpl/edit.php b/src/components/com_tjcertificate/site/views/bulktrainingrecord/tmpl/edit.php new file mode 100644 index 00000000..5a0bd594 --- /dev/null +++ b/src/components/com_tjcertificate/site/views/bulktrainingrecord/tmpl/edit.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\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; + +HTMLHelper::_('behavior.formvalidation'); +HTMLHelper::_('behavior.modal'); +HTMLHelper::_('behavior.keepalive'); +HTMLHelper::_('behavior.tooltip'); +HTMLHelper::_('bootstrap.framework'); +HTMLHelper::StyleSheet('media/com_tjcertificate/css/tjCertificate.css'); +HTMLHelper::_('jquery.token'); +HTMLHelper::_('formbehavior.chosen', 'select'); + +$options['relative'] = true; +HTMLHelper::_('script', 'media/com_tjcertificate/vendors/loader/js/loadingoverlay.min.js'); +HTMLHelper::_('script', 'com_tjcertificate/tjCertificateService.min.js', $options); +HTMLHelper::_('script', 'com_tjcertificate/certificate.min.js', $options); + +$userLimit = $this->params->get('users_select_limit'); +$message = Text::sprintf("COM_TJCERTIFICATE_USER_LIMIT_MESSAGE", $userLimit); + +?> +
+
+
+
+

+ +

+ isAgencyEnabled) + { + echo $this->form->renderField('agency_id'); + } + + echo $this->form->renderField('assigned_user_id'); + echo $this->form->renderField('name'); + echo $this->form->renderField('issuing_org'); + echo $this->form->renderField('issued_on'); + echo $this->form->renderField('expired_on'); + echo $this->form->renderField('status'); + echo $this->form->renderField('state'); + ?> + + + form->renderField('notify_users'); + echo $this->form->renderField('created_by', null, null, ['class' => 'hidden']); + ?> +
+
+
+ +
+
+ + +
+
+ + + + +
+ diff --git a/src/components/com_tjcertificate/site/views/bulktrainingrecord/tmpl/edit.xml b/src/components/com_tjcertificate/site/views/bulktrainingrecord/tmpl/edit.xml new file mode 100644 index 00000000..33775fcb --- /dev/null +++ b/src/components/com_tjcertificate/site/views/bulktrainingrecord/tmpl/edit.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/components/com_tjcertificate/site/views/bulktrainingrecord/view.html.php b/src/components/com_tjcertificate/site/views/bulktrainingrecord/view.html.php new file mode 100644 index 00000000..cf4cf9aa --- /dev/null +++ b/src/components/com_tjcertificate/site/views/bulktrainingrecord/view.html.php @@ -0,0 +1,74 @@ + + * @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\View\HtmlView; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Component\ComponentHelper; + +/** + * Training records view + * + * @since __DEPLOY_VERSION__ + */ +class TjCertificateViewBulkTrainingRecord extends HtmlView +{ + protected $form; + + protected $params; + + public $isAgencyEnabled = false; + + /** + * Manage Permissions + * + * @var boolean + */ + public $manage; + + protected $comMultiAgency = 'com_multiagency'; + + /** + * Display the view + * + * @param string $tpl The name of the template file to parse; automatically searches through the template paths. + * + * @return mixed A string if successful, otherwise a Error object. + * + * @since __DEPLOY_VERSION__ + */ + public function display($tpl = null) + { + $app = Factory::getApplication(); + $this->input = $app->input; + $this->user = Factory::getUser(); + $this->params = ComponentHelper::getParams('com_tjcertificate'); + $this->manage = $this->user->authorise('certificate.external.manage', 'com_tjcertificate'); + + if (!$this->manage) + { + $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'warning'); + + return false; + } + + if (ComponentHelper::isEnabled($this->comMultiAgency) && $this->params->get('enable_multiagency')) + { + $this->isAgencyEnabled = true; + } + + $this->form = $this->get('Form'); + + parent::display($tpl); + } +} diff --git a/src/components/com_tjcertificate/site/views/certificate/tmpl/default.php b/src/components/com_tjcertificate/site/views/certificate/tmpl/default.php index 54cfade1..649e132e 100644 --- a/src/components/com_tjcertificate/site/views/certificate/tmpl/default.php +++ b/src/components/com_tjcertificate/site/views/certificate/tmpl/default.php @@ -22,10 +22,10 @@ HTMLHelper::_('jquery.framework'); HTMLHelper::_('bootstrap.framework'); HTMLHelper::_('behavior.framework'); -HTMLHelper::StyleSheet('media/com_tjcertificate/vendors/font-awesome-4.1.0/css/font-awesome.min.css'); HTMLHelper::StyleSheet('media/com_tjcertificate/css/tjCertificate.css'); HTMLHelper::StyleSheet('media/com_tjlms/vendors/artificiers/artficier.css'); HTMLHelper::script('media/com_tjcertificate/vendors/html2canvas/js/html2canvas.js'); +HTMLHelper::script('media/com_tjcertificate/vendors/loader/js/loadingoverlay.min.js'); HTMLHelper::script('com_tjcertificate/certificateImage.min.js', $options); $imageUrl = ""; @@ -41,8 +41,8 @@
-
- certificate->getUserId() == Factory::getUser()->id) { - ?> + ?>
- item->title) - { ?> - This certificate (ID: certificate->unique_certificate_id;?>) verifies that certificate->getUserId())->name; ?> has successfully completed the item->title; ?> on certificate->issued_on, Text::_('COM_TJCERTIFICATE_CERTIFICATE_DETAIL_VIEW_DATE_FORMAT'));?>. - item->title) + { + echo Text::sprintf('COM_TJCERTIFICATE_CERTIFICATE_DETAIL_VIEW_CERTIFICATE', $this->certificate->unique_certificate_id, Factory::getUser($this->certificate->getUserId())->name, $this->item->title, HTMLHelper::_('date', $this->certificate->issued_on, Text::_('COM_TJCERTIFICATE_CERTIFICATE_DETAIL_VIEW_DATE_FORMAT'))); } else - { ?> - This certificate (ID: certificate->unique_certificate_id;?>) has been awarded to certificate->getUserId())->name; ?> on certificate->issued_on, Text::_('COM_TJCERTIFICATE_CERTIFICATE_DETAIL_VIEW_DATE_FORMAT'));?>. - - certificate->unique_certificate_id, Factory::getUser($this->certificate->getUserId())->name, HTMLHelper::_('date', $this->certificate->issued_on, Text::_('COM_TJCERTIFICATE_CERTIFICATE_DETAIL_VIEW_DATE_FORMAT'))); + } + if ($this->certificate->getExpiry() != '0000-00-00 00:00:00') { - ?> - This Certificate expires on certificate->getExpiry(), Text::_('COM_TJCERTIFICATE_CERTIFICATE_DETAIL_VIEW_DATE_FORMAT'));?>. - certificate->getExpiry(), Text::_('COM_TJCERTIFICATE_CERTIFICATE_DETAIL_VIEW_DATE_FORMAT'))); } ?>
@@ -210,7 +207,9 @@ ?> diff --git a/src/components/com_tjcertificate/site/views/certificate/tmpl/default_social_sharing.php b/src/components/com_tjcertificate/site/views/certificate/tmpl/default_social_sharing.php index f59a66e6..a402f992 100644 --- a/src/components/com_tjcertificate/site/views/certificate/tmpl/default_social_sharing.php +++ b/src/components/com_tjcertificate/site/views/certificate/tmpl/default_social_sharing.php @@ -12,6 +12,8 @@ defined('_JEXEC') or die('Restricted access'); use Joomla\CMS\Factory; +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\Language\Text; $document = Factory::getDocument(); $sharingOptions = $this->params->get('sharing_option'); @@ -90,6 +92,11 @@ +
  • + + + +
  • certificate = $certificate::validateCertificate($this->uniqueCertificateId); + } - if (!$this->certificate->id) + if (!$this->certificate->id) + { + JError::raiseWarning(500, Text::_('COM_TJCERTIFICATE_ERROR_CERTIFICATE_EXPIRED')); + } + elseif ($this->certificate->id) + { + // If certificate view is private then view is available only for certificate owner + if (!$this->params->get('certificate_scope', '1') && Factory::getUser()->id != $this->certificate->getUserId()) { - JError::raiseWarning(500, Text::_('COM_TJCERTIFICATE_ERROR_CERTIFICATE_EXPIRED')); + JError::raiseWarning(500, Text::_('JERROR_ALERTNOAUTHOR')); return false; } - } - // If certificate view is private then view is available only for certificate owner - if (!$this->params->get('certificate_scope') && Factory::getUser()->id != $this->certificate->getUserId()) - { - JError::raiseWarning(500, Text::_('JERROR_ALERTNOAUTHOR')); - - return false; - } + $this->fileName = $this->certificate->unique_certificate_id . '.png'; + $this->mediaPath = 'media/com_tjcertificate/certificates/'; + $this->certVersion = md5($this->certificate->issued_on); + $this->imagePath = Uri::root() . $this->mediaPath . $this->fileName . '?ver=' . $this->certVersion; - $this->fileName = $this->certificate->unique_certificate_id . '.png'; - $this->mediaPath = 'media/com_tjcertificate/certificates/'; - $this->imagePath = Uri::root() . $this->mediaPath . $this->fileName; + $certificateUrl = 'index.php?option=com_tjcertificate&view=certificate&certificate=' . $this->certificate->unique_certificate_id; + $this->certificateUrl = Uri::root() . substr(Route::_($certificateUrl), strlen(Uri::base(true)) + 1); + $this->downloadPermission = $this->certificate->canDownload(); - $certificateUrl = 'index.php?option=com_tjcertificate&view=certificate&certificate=' . $this->certificate->unique_certificate_id; - $this->certificateUrl = Uri::root() . substr(Route::_($certificateUrl), strlen(Uri::base(true)) + 1); - $this->downloadPermission = $certificate::canDownload($this->certificate->unique_certificate_id); + if ($this->params->get('linkedin_profile_btn')) + { + $this->linkedInProfileUrl = $this->certificate->getAddToLinkedInProfileUrl(); + } - // Get HTML - $clientId = $this->certificate->getClientId(); - $client = $this->certificate->getClient(); - $model = TJCERT::model('Certificate', array('ignore_request' => true)); - $this->contentHtml = $model->getCertificateProviderInfo($clientId, $client); + // Get HTML + $clientId = $this->certificate->getClientId(); + $client = $this->certificate->getClient(); + $model = TJCERT::model('Certificate', array('ignore_request' => true)); + $this->contentHtml = $model->getCertificateProviderInfo($clientId, $client); - $dispatcher = JDispatcher::getInstance(); - PluginHelper::importPlugin('content'); - $result = $dispatcher->trigger('getCertificateClientData', array($clientId, $client)); - $this->item = $result[0]; + $dispatcher = JDispatcher::getInstance(); + PluginHelper::importPlugin('content'); + $result = $dispatcher->trigger('getCertificateClientData', array($clientId, $client)); + $this->item = $result[0]; + } parent::display($tpl); } diff --git a/src/components/com_tjcertificate/site/views/certificates/tmpl/my.php b/src/components/com_tjcertificate/site/views/certificates/tmpl/my.php index fcd6a227..d4ca52c7 100644 --- a/src/components/com_tjcertificate/site/views/certificates/tmpl/my.php +++ b/src/components/com_tjcertificate/site/views/certificates/tmpl/my.php @@ -16,12 +16,14 @@ use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\Factory; HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); HTMLHelper::_('bootstrap.tooltip'); HTMLHelper::_('behavior.multiselect'); HTMLHelper::_('formbehavior.chosen', 'select'); HTMLHelper::_('behavior.modal', 'a.modal'); +HTMLHelper::_('jquery.token'); $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); @@ -29,6 +31,11 @@ $dispatcher = JDispatcher::getInstance(); PluginHelper::importPlugin('content'); + +$options['relative'] = true; +HTMLHelper::_('script', 'com_tjcertificate/tjCertificateService.min.js', $options); +HTMLHelper::_('script', 'com_tjcertificate/certificate.min.js', $options); +HTMLHelper::StyleSheet('media/com_tjcertificate/css/tjCertificate.css'); ?>
    @@ -40,6 +47,34 @@ echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>
    + + create) + { + $recordFormLink = 'index.php?option=com_tjcertificate&view=trainingrecord&layout=edit'; + $addRecordLink = Route::_($recordFormLink);?> +
    + + + +
    + + manage) + { + $recordsFormLink = 'index.php?option=com_tjcertificate&view=bulktrainingrecord&layout=edit'; + $addRecordsLink = Route::_($recordsFormLink);?> +
    + + + +
    + +
    items)) { @@ -65,12 +100,24 @@ + + + + + isAgencyEnabled) { ?> + + + + + + + @@ -87,14 +134,22 @@ foreach ($this->items as $i => $item) { + $certificateObj = TJCERT::Certificate($item->id); $data = $dispatcher->trigger('getCertificateClientData', array($item->client_id, $item->client)); ?> @@ -105,19 +160,103 @@ ?> - title ? $data[0]->title : "-"; ?> + is_external) + { + echo $item->name; + } + else + { + echo ($data[0]->title ? $data[0]->title : "-"); + } + ?> - issued_on, Text::_('DATE_FORMAT_LC')); ?> - uname; ?> + isAgencyEnabled) + { + ?> + title; ?> + + getFormatedDate($item->issued_on); ?> + + expired_on) && $item->expired_on != '0000-00-00 00:00:00') { - echo HTMLHelper::date($item->expired_on, Text::_('DATE_FORMAT_LC')); + echo $certificateObj->getFormatedDate($item->expired_on); } else { echo '-'; } - ?> + ?> + + +
    + id); ?> +
    + + id); + + if ($this->manage && $item->is_external) + { ?> + + + + delete) + { + ?> + + + + + manage && $this->manageOwn) && ($item->is_external && $item->state != 1)) + { ?> + + + + deleteOwn && $item->user_id == $this->user->id) + { ?> + + + + + manage && $item->is_external) + { ?> + + state == -1 || $item->state == 0) + { ?> + + state == 1) + { ?> + + + + is_external || !($this->manageOwn || $this->manage)) + { + echo "-"; + } + ?> + + user = Factory::getUser(); + $app = Factory::getApplication(); + $this->user = Factory::getUser(); + $this->params = ComponentHelper::getParams($this->comTjcertificate); if (!$this->user->id) { @@ -92,9 +127,10 @@ public function display($tpl = null) // Get state $this->state = $this->get('State'); - $layout = $app->input->get('layout', "my"); + $layout = $app->input->get('layout', "my"); + $this->manage = $this->user->authorise('certificate.external.manage', $this->comTjcertificate); - if ($layout == 'my') + if ($layout == 'my' && !$this->manage) { // Show only logged-in user certificates $this->state->set('filter.user_id', $this->user->id); @@ -108,6 +144,20 @@ public function display($tpl = null) $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); + $this->manageOwn = $this->user->authorise('certificate.external.manageown', $this->comTjcertificate); + $this->create = $this->user->authorise('certificate.external.create', $this->comTjcertificate); + $this->delete = $this->user->authorise('certificate.external.delete', $this->comTjcertificate); + $this->deleteOwn = $this->user->authorise('certificate.external.deleteown', $this->comTjcertificate); + + if (ComponentHelper::isEnabled($this->comMultiAgency) && $this->params->get('enable_multiagency')) + { + $this->isAgencyEnabled = true; + $this->filterForm->removeField('user_id', 'filter'); + } + else + { + $this->filterForm->removeField('agency_id', 'filter'); + } // Check for errors. if (count($errors = $this->get('Errors'))) diff --git a/src/components/com_tjcertificate/site/views/trainingrecord/index.html b/src/components/com_tjcertificate/site/views/trainingrecord/index.html new file mode 100644 index 00000000..e69de29b diff --git a/src/components/com_tjcertificate/site/views/trainingrecord/tmpl/default.php b/src/components/com_tjcertificate/site/views/trainingrecord/tmpl/default.php new file mode 100644 index 00000000..020bed87 --- /dev/null +++ b/src/components/com_tjcertificate/site/views/trainingrecord/tmpl/default.php @@ -0,0 +1,102 @@ + + * @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; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Uri\Uri; +?> +
    + + + +
    +
    + +
    +
    + escape($this->item->name); ?> +
    + item->cert_url) { ?> +
    + +
    +
    + escape($this->item->cert_url); ?> +
    + +
    + +
    +
    + escape($this->item->issuing_org); ?> +
    +
    + +
    +
    + escape($this->item->status)); ?> +
    +
    + +
    +
    + certificate->getFormatedDate($this->item->issued_on);?> +
    + item->expired_on != "0000-00-00 00:00:00") { ?> +
    + +
    +
    + certificate->getFormatedDate($this->item->expired_on);?> +
    + + item->cert_file) { ?> +
    +
    +
    + item->mediaData[0]) + { + $downloadAttachmentLink = Uri::root() . 'index.php?option=com_tjcertificate&task=trainingrecord.downloadAttachment&id=' . $this->item->mediaData[0]->media_id . '&recordId=' . $this->item->id; + + if ($this->item->mediaData[0]->type === "image") + { + ?> + + + item->mediaData[0]->title;?> + + + manage || $this->item->user_id == $this->user->id) { ?> + + + + + +
    + + item->comment) { ?> +
    + +
    +
    + escape($this->item->comment); ?> +
    + +
    +
    diff --git a/src/components/com_tjcertificate/site/views/trainingrecord/tmpl/edit.php b/src/components/com_tjcertificate/site/views/trainingrecord/tmpl/edit.php new file mode 100644 index 00000000..cd0daa2d --- /dev/null +++ b/src/components/com_tjcertificate/site/views/trainingrecord/tmpl/edit.php @@ -0,0 +1,127 @@ + + * @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\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Uri\Uri; + +HTMLHelper::_('behavior.formvalidation'); +HTMLHelper::_('behavior.modal'); +HTMLHelper::_('behavior.keepalive'); +HTMLHelper::_('behavior.tooltip'); +HTMLHelper::_('bootstrap.framework'); +HTMLHelper::StyleSheet('media/com_tjcertificate/css/tjCertificate.css'); +HTMLHelper::_('jquery.token'); +HTMLHelper::_('formbehavior.chosen', 'select'); + +$options['relative'] = true; +HTMLHelper::_('script', 'com_tjcertificate/tjCertificateService.min.js', $options); +HTMLHelper::_('script', 'com_tjcertificate/certificate.min.js', $options); +?> + +
    +
    +
    +

    + item->id)) ? Text::_('COM_TJCERTIFICATE_ADD_EXTERNAL_CERTIFICATE') : Text::_('COM_TJCERTIFICATE_EDIT_EXTERNAL_CERTIFICATE'); + ?> +

    + + isAgencyEnabled && $this->manage) + { + echo $this->form->renderField('agency_id'); + } + + if ($this->manage) + { + echo $this->form->renderField('assigned_user_id'); + } + + echo $this->form->renderField('name'); + echo $this->form->renderField('unique_certificate_id'); + echo $this->form->renderField('cert_url'); + echo $this->form->renderField('issuing_org'); + echo $this->form->renderField('issued_on'); + echo $this->form->renderField('expired_on'); + echo $this->form->renderField('status'); + + if ($this->manage) + { + echo $this->form->renderField('state'); + } + ?> +
    +
    form->getLabel('cert_file'); ?>
    +
    + form->getInput('cert_file'); ?> + item->mediaData[0])) + { + $downloadAttachmentLink = Uri::root() . 'index.php?option=com_tjcertificate&task=trainingrecord.downloadAttachment&id=' . $this->item->mediaData[0]->media_id . '&recordId=' . $this->item->id; + echo ''; + ?> + + item->mediaData[0]->title;?> + + + + + + +
    +
    + form->renderField('created_by', null, null, ['class' => 'hidden']); + echo $this->form->renderField('comment'); + ?> +
    +
    +
    + +
    +
    + + +
    +
    + + + + + + + + + + diff --git a/src/components/com_tjcertificate/site/views/trainingrecord/tmpl/edit.xml b/src/components/com_tjcertificate/site/views/trainingrecord/tmpl/edit.xml new file mode 100644 index 00000000..924c3bca --- /dev/null +++ b/src/components/com_tjcertificate/site/views/trainingrecord/tmpl/edit.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/components/com_tjcertificate/site/views/trainingrecord/view.html.php b/src/components/com_tjcertificate/site/views/trainingrecord/view.html.php new file mode 100644 index 00000000..22f2c128 --- /dev/null +++ b/src/components/com_tjcertificate/site/views/trainingrecord/view.html.php @@ -0,0 +1,117 @@ + + * @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\MVC\View\HtmlView; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Component\ComponentHelper; + +/** + * Training record view + * + * @since __DEPLOY_VERSION__ + */ +class TjCertificateViewTrainingRecord extends HtmlView +{ + protected $state; + + protected $item; + + protected $form; + + protected $create; + + protected $params; + + public $certificate = null; + + public $isAgencyEnabled = false; + + /** + * Manage own Permissions + * + * @var boolean + */ + public $manageOwn; + + /** + * Manage Permissions + * + * @var boolean + */ + public $manage; + + protected $comMultiAgency = 'com_multiagency'; + + /** + * Display the view + * + * @param string $tpl The name of the template file to parse; automatically searches through the template paths. + * + * @return mixed A string if successful, otherwise a Error object. + * + * @since __DEPLOY_VERSION__ + */ + public function display($tpl = null) + { + $app = Factory::getApplication(); + $this->input = $app->input; + $this->user = Factory::getUser(); + $layout = $this->input->get('layout'); + $id = $this->input->getInt('id'); + $this->item = $this->get('Item'); + $this->certificate = TJCERT::Certificate(); + $this->params = ComponentHelper::getParams('com_tjcertificate'); + $this->manage = $this->user->authorise('certificate.external.manage', 'com_tjcertificate'); + $this->manageOwn = $this->user->authorise('certificate.external.manageown', 'com_tjcertificate'); + + if (ComponentHelper::isEnabled($this->comMultiAgency) && $this->params->get('enable_multiagency')) + { + $this->isAgencyEnabled = true; + } + + if (!$this->manage) + { + // If certificate view is private then view is available only for record owner + if (!$this->params->get('certificate_scope') && Factory::getUser()->id != $this->item->user_id) + { + JError::raiseWarning(500, Text::_('JERROR_ALERTNOAUTHOR')); + + return false; + } + } + + $this->create = $this->user->authorise('certificate.external.create', 'com_tjcertificate'); + + if (!$this->create) + { + throw new Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403); + } + + $this->state = $this->get('State'); + $this->form = $this->get('Form'); + $this->params = ComponentHelper::getParams('com_tjcertificate'); + $this->allowedFileExtensions = $this->params->get('upload_extensions'); + $this->uploadLimit = $this->params->get('upload_maxsize', '1024'); + + // Check for errors. + if (count($errors = $this->get('Errors'))) + { + throw new Exception(implode("\n", $errors), 500); + } + + parent::display($tpl); + } +} diff --git a/src/components/com_tjcertificate/tjcertificate.xml b/src/components/com_tjcertificate/tjcertificate.xml index 9a564edf..adde293d 100644 --- a/src/components/com_tjcertificate/tjcertificate.xml +++ b/src/components/com_tjcertificate/tjcertificate.xml @@ -2,13 +2,13 @@ com_tjcertificate 2019-08-13 - 2019 Techjoomla + 2020 Techjoomla GNU General Public License version 2 or later; see LICENSE.txt Techjoomla extensions@techjoomla.com http://techjoomla.com - 1.0.2 + 1.0.6 @@ -33,6 +33,7 @@ controller.php router.php controllers + events views models languages @@ -52,6 +53,7 @@ controller.php index.html tjcertificate.php + tjcertificateTemplate.json controllers includes helpers @@ -61,6 +63,7 @@ views libraries languages + layouts languages/en-GB/en-GB.com_tjcertificate.ini @@ -71,7 +74,37 @@ certificate-templates css js + images vendors + fields script.tjcertificate.php + + +
    + + + + + + + + + + + + + + + + + + + + + + +
    +
    +