From cc892ee72a63931c1da026be392b9687dfa53579 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 8 Jul 2024 17:15:04 +0200 Subject: [PATCH] =?UTF-8?q?add=20page=20for=20=D1=95ending=20test=20notifi?= =?UTF-8?q?cations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- op/op.SendNotification.php | 78 ++++++ out/out.SendNotification.php | 60 +++++ views/bootstrap/class.Bootstrap.php | 2 + views/bootstrap/class.SendNotification.php | 278 +++++++++++++++++++++ views/bootstrap4/class.Bootstrap4.php | 2 + 5 files changed, 420 insertions(+) create mode 100644 op/op.SendNotification.php create mode 100644 out/out.SendNotification.php create mode 100644 views/bootstrap/class.SendNotification.php diff --git a/op/op.SendNotification.php b/op/op.SendNotification.php new file mode 100644 index 000000000..0fbd3b076 --- /dev/null +++ b/op/op.SendNotification.php @@ -0,0 +1,78 @@ +$dms, 'user'=>$user)); +$accessop = new SeedDMS_AccessOperation($dms, null, $user, $settings); +if (!$accessop->check_controller_access($controller, $_GET)) { + header('Content-Type: application/json'); + echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied'))); + exit; +} + +/* Check if the form data comes from a trusted request */ +if(!checkFormKey('sendnotification', 'GET')) { + header('Content-Type: application/json'); + echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_request_token'))); + exit; +} + +if (!isset($_GET["userid"]) || !is_numeric($_GET["userid"]) || intval($_GET["userid"])<1) { + header('Content-Type: application/json'); + echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_user_id'))); +} +$userid = $_GET["userid"]; +$newuser = $dms->getUser($userid); + +if (!is_object($newuser)) { + header('Content-Type: application/json'); + echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_user_id'))); + exit; +} + +$recvtype = 1; +if (isset($_GET["recvtype"])) { + $recvtype = (int) $_GET["recvtype"]; +} +$template = 'send_notification'; +if (isset($_GET["template"])) { + $template = $_GET["template"]; +} + +if($notifier) { + header('Content-Type: application/json'); + if($notifier->toIndividual($user, $newuser, $template.'_email_subject', $template.'_email_body', [], $recvtype)) { + echo json_encode(array('success'=>true, 'message'=>getMLText('splash_send_notification'))); + } else { + echo json_encode(array('success'=>false, 'message'=>getMLText('error_send_notification'))); + } +} + diff --git a/out/out.SendNotification.php b/out/out.SendNotification.php new file mode 100644 index 000000000..b44176930 --- /dev/null +++ b/out/out.SendNotification.php @@ -0,0 +1,60 @@ +$dms, 'user'=>$user)); +$accessop = new SeedDMS_AccessOperation($dms, null, $user, $settings); +if (!$settings->_enableDebugMode) { + UI::exitError(getMLText("admin_tools"),getMLText("access_denied")); +} +if (!$accessop->check_view_access($view, $_GET)) { + UI::exitError(getMLText("admin_tools"),getMLText("access_denied")); +} + +$seluser = null; +if(!empty($_GET['userid'])) { + $userid = (int) $_GET['userid']; + $seluser = $dms->getUser($userid); +} else { + $seluser = $user; +} + +$allusers = $dms->getAllUsers($settings->_sortUsersInList); + +if($view) { + $view->setParam('settings', $settings); + $view->setParam('accessobject', $accessop); + $view->setParam('notifier', $notifier); + $view->setParam('allusers', $allusers); + $view->setParam('seluser', $seluser); + $view($_GET); + exit; +} + + diff --git a/views/bootstrap/class.Bootstrap.php b/views/bootstrap/class.Bootstrap.php index 84aadda4c..659724051 100644 --- a/views/bootstrap/class.Bootstrap.php +++ b/views/bootstrap/class.Bootstrap.php @@ -969,6 +969,8 @@ background-image: linear-gradient(to bottom, #882222, #111111);; $menuitems['debug']['children']['hooks'] = array('link'=>$this->params['settings']->_httpRoot."out/out.Hooks.php", 'label'=>getMLText('list_hooks')); if ($accessobject->check_view_access('NotificationServices')) $menuitems['debug']['children']['notification_services'] = array('link'=>$this->params['settings']->_httpRoot."out/out.NotificationServices.php", 'label'=>getMLText('list_notification_services')); + if ($accessobject->check_view_access('SendNotification')) + $menuitems['debug']['children']['send_notification'] = array('link'=>$this->params['settings']->_httpRoot."out/out.SendNotification.php", 'label'=>getMLText('send_notification')); if ($accessobject->check_view_access('ConversionServices')) $menuitems['debug']['children']['conversion_services'] = array('link'=>$this->params['settings']->_httpRoot."out/out.ConversionServices.php", 'label'=>getMLText('list_conversion_services')); } diff --git a/views/bootstrap/class.SendNotification.php b/views/bootstrap/class.SendNotification.php new file mode 100644 index 000000000..91f2de1e3 --- /dev/null +++ b/views/bootstrap/class.SendNotification.php @@ -0,0 +1,278 @@ + + * @copyright Copyright (C) 2002-2005 Markus Westphal, + * 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli, + * 2010-2024 Uwe Steinmann + * @version Release: @package_version@ + */ + +/** + * Class which outputs the html page for sending a notification + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2016 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_View_SendNotification extends SeedDMS_Theme_Style { + + var $subjects; + + var $recvtypes; + + public function __construct($params, $theme) { /* {{{ */ + parent::__construct($params, $theme); + $this->subjects = array(); + $this->subjects[] = 'review_request'; + $this->subjects[] = 'approval_request'; + $this->subjects[] = 'new_document'; + $this->subjects[] = 'document_updated'; + $this->subjects[] = 'document_deleted'; + $this->subjects[] = 'version_deleted'; + $this->subjects[] = 'new_subfolder'; + $this->subjects[] = 'folder_deleted'; + $this->subjects[] = 'new_file'; + $this->subjects[] = 'replace_content'; + $this->subjects[] = 'remove_file'; + $this->subjects[] = 'document_attribute_changed'; + $this->subjects[] = 'document_attribute_added'; + $this->subjects[] = 'folder_attribute_changed'; + $this->subjects[] = 'folder_attribute_added'; + $this->subjects[] = 'document_comment_changed'; + $this->subjects[] = 'folder_comment_changed'; + $this->subjects[] = 'version_comment_changed'; + $this->subjects[] = 'document_renamed'; + $this->subjects[] = 'folder_renamed'; + $this->subjects[] = 'document_moved'; + $this->subjects[] = 'folder_moved'; + $this->subjects[] = 'document_transfered'; + $this->subjects[] = 'document_status_changed'; + $this->subjects[] = 'document_notify_added'; + $this->subjects[] = 'folder_notify_added'; + $this->subjects[] = 'document_notify_deleted'; + $this->subjects[] = 'folder_notify_deleted'; + $this->subjects[] = 'review_submit'; + $this->subjects[] = 'approval_submit'; + $this->subjects[] = 'review_deletion'; + $this->subjects[] = 'approval_deletion'; + $this->subjects[] = 'review_request'; + $this->subjects[] = 'approval_request'; + $this->subjects[] = 'document_ownership_changed'; + $this->subjects[] = 'folder_ownership_changed'; + $this->subjects[] = 'document_access_permission_changed'; + $this->subjects[] = 'folder_access_permission_changed'; + $this->subjects[] = 'transition_triggered'; + $this->subjects[] = 'request_workflow_action'; + $this->subjects[] = 'rewind_workflow'; + $this->subjects[] = 'rewind_workflow'; + + $this->recvtypes = array(); + $this->recvtypes[] = array(SeedDMS_NotificationService::RECV_ANY, getMLText('notification_recv_any')); + $this->recvtypes[] = array(SeedDMS_NotificationService::RECV_NOTIFICATION, getMLText('notification_recv_notification')); + $this->recvtypes[] = array(SeedDMS_NotificationService::RECV_OWNER, getMLText('notification_recv_owner')); + $this->recvtypes[] = array(SeedDMS_NotificationService::RECV_REVIEWER, getMLText('notification_recv_reviewer')); + $this->recvtypes[] = array(SeedDMS_NotificationService::RECV_APPROVER, getMLText('notification_recv_approver')); + $this->recvtypes[] = array(SeedDMS_NotificationService::RECV_WORKFLOW, getMLText('notification_recv_workflow')); + $this->recvtypes[] = array(SeedDMS_NotificationService::RECV_UPLOADER, getMLText('notification_recv_uploader')); + } /* }}} */ + + public function js() { /* {{{ */ + header('Content-Type: application/javascript; charset=UTF-8'); +?> +$(document).ready( function() { + $('body').on('click', '#send_notification', function(ev){ + ev.preventDefault(); + var data = $('#form1').serializeArray().reduce(function(obj, item) { + obj[item.name] = item.value; + return obj; + }, {}); + $.get("../op/op.SendNotification.php", $('#form1').serialize()+"&formtoken=", function(response) { + noty({ + text: response.message, + type: response.success === true ? 'success' : 'error', + dismissQueue: true, + layout: 'topRight', + theme: 'defaultTheme', + timeout: 1500, + }); + }); + }); +}); +params['dms']; + $user = $this->params['user']; + $notifier = $this->params['notifier']; + $allusers = $this->params['allusers']; + $seluser = $this->params['seluser']; + + $services = $notifier->getServices(); + foreach($services as $name => $service) { + $this->contentHeading($name); + if(is_callable([$service, 'filter'])) { + $content = ''; + $content .= ""; + $content .= ""; + array_shift($this->recvtypes); + foreach($this->recvtypes as $recvtype) { + $content .= ""; + } + $content .= ""; + foreach($this->subjects as $subject) { + $content .= ""; + foreach($this->recvtypes as $recvtype) { + if($service->filter($user, $seluser, $subject.'_email_subject', $subject.'_email_body', [], $recvtype[0])) { + $content .= ""; + } else { + $content .= ""; + } + } + $content .= ""; + } + $content .= "
".getMLText('notification_msg_tmpl')."/".getMLText('notification_recvtype')."".$recvtype[1]."
".$subject."
"; + $this->printAccordion(getMLText('click_to_expand_filter_results'), $content); + } else { + $this->infoMsg(getMLText('notification_service_no_filter')); + } + } + + } /* }}} */ + + public function show() { /* {{{ */ + $dms = $this->params['dms']; + $user = $this->params['user']; + $notifier = $this->params['notifier']; + $allusers = $this->params['allusers']; + $seluser = $this->params['seluser']; + + $this->htmlStartPage(getMLText("admin_tools")); + $this->globalNavigation(); + $this->contentStart(); + $this->pageNavigation(getMLText("admin_tools"), "admin_tools"); + $this->contentHeading(getMLText("send_notification")); + + $this->rowStart(); + $this->columnStart(4); +?> +
+contentContainerStart(); + $options = array(); + foreach ($allusers as $currUser) { + if ($currUser->isGuest() ) + continue; + + $options[] = array($currUser->getID(), htmlspecialchars($currUser->getLogin()." - ".$currUser->getFullName()), $seluser && $seluser->getId() == $currUser->getId()); + } + $this->formField( + getMLText("user"), + array( + 'element'=>'select', + 'name'=>'userid', + 'class'=>'chzn-select', + 'options'=>$options + ) + ); + + $options = array(); + $options[] = array(SeedDMS_NotificationService::RECV_ANY, getMLText('notification_recv_any')); + $options[] = array(SeedDMS_NotificationService::RECV_NOTIFICATION, getMLText('notification_recv_notification')); + $options[] = array(SeedDMS_NotificationService::RECV_OWNER, getMLText('notification_recv_owner')); + $options[] = array(SeedDMS_NotificationService::RECV_REVIEWER, getMLText('notification_recv_reviewer')); + $options[] = array(SeedDMS_NotificationService::RECV_APPROVER, getMLText('notification_recv_approver')); + $options[] = array(SeedDMS_NotificationService::RECV_WORKFLOW, getMLText('notification_recv_workflow')); + $options[] = array(SeedDMS_NotificationService::RECV_UPLOADER, getMLText('notification_recv_uploader')); + $this->formField( + getMLText("notification_recvtype"), + array( + 'element'=>'select', + 'name'=>'recvtype', + 'class'=>'chzn-select', + 'options'=>$options + ) + ); + $options = array(); + $options[] = array('review_request', 'review_request'); + $options[] = array('approval_request', 'approval_request'); + $options[] = array('new_document', 'new_document'); + $options[] = array('document_updated', 'document_updated'); + $options[] = array('document_deleted', 'document_deleted'); + $options[] = array('version_deleted', 'version_deleted'); + $options[] = array('new_subfolder', 'new_subfolder'); + $options[] = array('folder_deleted', 'folder_deleted'); + $options[] = array('new_file', 'new_file'); + $options[] = array('replace_content', 'replace_content'); + $options[] = array('remove_file', 'remove_file'); + $options[] = array('document_attribute_changed', 'document_attribute_changed'); + $options[] = array('document_attribute_added', 'document_attribute_added'); + $options[] = array('folder_attribute_changed', 'folder_attribute_changed'); + $options[] = array('folder_attribute_added', 'folder_attribute_added'); + $options[] = array('document_comment_changed', 'document_comment_changed'); + $options[] = array('folder_comment_changed', 'folder_comment_changed'); + $options[] = array('version_comment_changed', 'version_comment_changed'); + $options[] = array('document_renamed', 'document_renamed'); + $options[] = array('folder_renamed', 'folder_renamed'); + $options[] = array('document_moved', 'document_moved'); + $options[] = array('folder_moved', 'folder_moved'); + $options[] = array('document_transfered', 'document_transfered'); + $options[] = array('document_status_changed', 'document_status_changed'); + $options[] = array('document_notify_added', 'document_notify_added'); + $options[] = array('folder_notify_added', 'folder_notify_added'); + $options[] = array('document_notify_deleted', 'document_notify_deleted'); + $options[] = array('folder_notify_deleted', 'folder_notify_deleted'); + $options[] = array('review_submit', 'review_submit'); + $options[] = array('approval_submit', 'approval_submit'); + $options[] = array('review_deletion', 'review_deletion'); + $options[] = array('approval_deletion', 'approval_deletion'); + $options[] = array('review_request', 'review_request'); + $options[] = array('approval_request', 'approval_request'); + $options[] = array('document_ownership_changed', 'document_ownership_changed'); + $options[] = array('folder_ownership_changed', 'folder_ownership_changed'); + $options[] = array('document_access_permission_changed', 'document_access_permission_changed'); + $options[] = array('folder_access_permission_changed', 'folder_access_permission_changed'); + $options[] = array('transition_triggered', 'transition_triggered'); + $options[] = array('request_workflow_action', 'request_workflow_action'); + $options[] = array('rewind_workflow', 'rewind_workflow'); + $this->formField( + getMLText("notification_msg_tmpl"), + array( + 'element'=>'select', + 'name'=>'template', + 'class'=>'chzn-select', + 'options'=>$options + ) + ); + $this->contentContainerEnd(); + $buttons = []; + $names = []; + $buttons[] = ' '.getMLText('send_notification'); + $names[] = "send_notification"; + $buttons[] = ' '.getMLText('check_notification_filter'); + $names[] = "check_filter"; + $this->formSubmit($buttons, $names); +?> +
+columnEnd(); + $this->columnStart(8); +?> +
+columnEnd(); + $this->rowEnd(); + $this->contentEnd(); + $this->htmlEndPage(); + } /* }}} */ +} + + diff --git a/views/bootstrap4/class.Bootstrap4.php b/views/bootstrap4/class.Bootstrap4.php index 3de05af2c..7d78aeffc 100644 --- a/views/bootstrap4/class.Bootstrap4.php +++ b/views/bootstrap4/class.Bootstrap4.php @@ -957,6 +957,8 @@ background-image: linear-gradient(to bottom, #882222, #111111);; $menuitems['debug']['children']['hooks'] = array('link'=>$this->params['settings']->_httpRoot."out/out.Hooks.php", 'label'=>getMLText('list_hooks')); if ($accessobject->check_view_access('NotificationServices')) $menuitems['debug']['children']['notification_services'] = array('link'=>$this->params['settings']->_httpRoot."out/out.NotificationServices.php", 'label'=>getMLText('list_notification_services')); + if ($accessobject->check_view_access('SendNotification')) + $menuitems['debug']['children']['send_notification'] = array('link'=>$this->params['settings']->_httpRoot."out/out.SendNotification.php", 'label'=>getMLText('send_notification')); if ($accessobject->check_view_access('ConversionServices')) $menuitems['debug']['children']['conversion_services'] = array('link'=>$this->params['settings']->_httpRoot."out/out.ConversionServices.php", 'label'=>getMLText('list_conversion_services')); }