diff --git a/config/clear_form.php b/config/clear_form.php new file mode 100644 index 000000000..f5367d43e --- /dev/null +++ b/config/clear_form.php @@ -0,0 +1,28 @@ + '
', + 'formGroup' => ' {{label}}{{input}} ', + 'label' => '', + // Generic input element. + 'input' => ' + + + ', + // Select element, + 'select' => '', + // Used for button elements in button(). + 'button' => '
+ +
', + // Radio input element, + 'radio' => '', + //'radioWrapper' => '
{{label}}
', + 'textarea' => '', + 'checkboxWrapper' => '{{label}}', + 'checkbox' => '', + 'dateWidget' => '{{day}}{{month}}{{year}}', + //'select' => '', + 'inputContainer' => '
{{content}}
', + 'submitContainer' => '{{content}}', +]; \ No newline at end of file diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 9ba8bc9c8..4a5709d82 100755 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -52,7 +52,7 @@ public function initialize(): void $this->loadComponent('RequestHandler', ['viewClassMap' => ['csv' => 'CsvView.Csv']]); // $this->loadComponent('RequestHandler'); - $this->loadComponent('Flash'); + $this->loadComponent('Flash'); $this->Notifications = $this->loadModel('Notifications'); // $this->loadHelper('Tools.Captcha', [ diff --git a/src/Controller/Manager/NotificationsController.php b/src/Controller/Manager/NotificationsController.php index be77cdd34..02573851e 100755 --- a/src/Controller/Manager/NotificationsController.php +++ b/src/Controller/Manager/NotificationsController.php @@ -1,4 +1,5 @@ paginate = [ - 'contain' => ['Users'], - ]; - $notifications = $this->paginate($this->Notifications); - $this->set(compact('notifications')); + $page_options = ['20' => '20', '25' => '25']; + + $passedArgs = $this->request->getQuery(); + // if (!empty($passedArgs['start_date']) || !empty($passedArgs['end_date'])) { + // $passedArgs['range'] = true; + // } + $queryParams = $this->request->getQuery(); + + // Example criteria handling + $criteria = []; + if (!empty($queryParams['start_date'])) { + $startDate = \DateTime::createFromFormat('d-m-Y', $queryParams['start_date']); + if ($startDate) { + $queryParams['start_date'] = $startDate->format('Y-m-d'); + } + } + if (!empty($queryParams['end_date'])) { + $endDate = \DateTime::createFromFormat('d-m-Y', $queryParams['end_date']); + if ($endDate) { + $queryParams['end_date'] = $endDate->format('Y-m-d'); + } + // debug($endDate); + } + $limit = $page_options['20']; // Default limit + if (!empty($passedArgs['pages']) && isset($page_options[$passedArgs['pages']])) { + $limit = $page_options[$passedArgs['pages']]; + } + if (!empty($queryParams['start_date'])) { + $criteria['Notifications.created >='] = $queryParams['start_date']; + } + if (!empty($queryParams['end_date'])) { + $criteria['Notifications.created <='] = $queryParams['end_date']; + } + // debug($criteria); + // exit; + // Authentication: Get current user ID + $userId = $this->Auth->User('id'); + + // $criteria = $this->Notifications->parseCriteria($passedArgs); + $criteria['user_id'] = $userId; + + $query = $this->Notifications->find() + ->where($criteria) + ->contain(['Users']) + ->order(['Notifications.created' => 'desc']); + + // CSV Export + $ext = $this->request->getParam('_ext'); + if ($ext && $ext == 'csv') { + $this->csvExport($query); + return; + } + + $notifications = $this->Paginator->paginate($query, [ + 'limit' => $limit + ]); + + $this->set(compact('page_options', 'notifications')); } + // CSV export method placeholder + protected function csvExport($query) + { + // Implement CSV export logic here + } /** * View method * diff --git a/src/Controller/Reporter/NotificationsController.php b/src/Controller/Reporter/NotificationsController.php index dd011cfa4..e079231f3 100755 --- a/src/Controller/Reporter/NotificationsController.php +++ b/src/Controller/Reporter/NotificationsController.php @@ -19,13 +19,49 @@ class NotificationsController extends AppController * @return \Cake\Http\Response|null|void Renders view */ public function index() - { - $this->paginate = [ - 'contain' => ['Users'], - ]; - $notifications = $this->paginate($this->Notifications); + { + + $page_options = ['20' => '20', '25' => '25']; + + $passedArgs = $this->request->getQuery(); + if (!empty($passedArgs['start_date']) || !empty($passedArgs['end_date'])) { + $passedArgs['range'] = true; + } + + $limit = $page_options['20']; // Default limit + if (!empty($passedArgs['pages']) && isset($page_options[$passedArgs['pages']])) { + $limit = $page_options[$passedArgs['pages']]; + } + + // Authentication: Get current user ID + $userId = $this->Auth->User('id'); + + // $criteria = $this->Notifications->parseCriteria($passedArgs); + $criteria['user_id'] = $userId; + + $query = $this->Notifications->find() + ->where($criteria) + ->contain(['Users']) + ->order(['Notifications.created' => 'desc']); - $this->set(compact('notifications')); + // CSV Export + $ext = $this->request->getParam('_ext'); + if ($ext && $ext == 'csv') { + $this->csvExport($query); + return; + } + + $notifications = $this->Paginator->paginate($query, [ + 'limit' => $limit + ]); + + $this->set(compact('page_options', 'notifications')); + } + + // CSV export method placeholder + protected function csvExport($query) + { + // Implement CSV export logic here } /** diff --git a/templates/Manager/Notifications/index.php b/templates/Manager/Notifications/index.php index 97ec5e41f..cc18dd233 100755 --- a/templates/Manager/Notifications/index.php +++ b/templates/Manager/Notifications/index.php @@ -1,62 +1,4 @@ $notifications - */ + $this->assign('NT', 'active'); + echo $this->element('notification/index'); ?> -
- Html->link(__('New Notification'), ['action' => 'add'], ['class' => 'button float-right']) ?> -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Paginator->sort('id') ?>Paginator->sort('user_id') ?>Paginator->sort('type') ?>Paginator->sort('model') ?>Paginator->sort('foreign_key') ?>Paginator->sort('title') ?>Paginator->sort('url') ?>Paginator->sort('deleted') ?>Paginator->sort('deleted_date') ?>Paginator->sort('created') ?>Paginator->sort('modified') ?>
Number->format($notification->id) ?>has('user') ? $this->Html->link($notification->user->name, ['controller' => 'Users', 'action' => 'view', $notification->user->id]) : '' ?>type) ?>model) ?>foreign_key === null ? '' : $this->Number->format($notification->foreign_key) ?>title) ?>url) ?>deleted) ?>deleted_date) ?>created) ?>modified) ?> - Html->link(__('View'), ['action' => 'view', $notification->id]) ?> - Html->link(__('Edit'), ['action' => 'edit', $notification->id]) ?> - Form->postLink(__('Delete'), ['action' => 'delete', $notification->id], ['confirm' => __('Are you sure you want to delete # {0}?', $notification->id)]) ?> -
-
-
-
    - Paginator->first('<< ' . __('first')) ?> - Paginator->prev('< ' . __('previous')) ?> - Paginator->numbers() ?> - Paginator->next(__('next') . ' >') ?> - Paginator->last(__('last') . ' >>') ?> -
-

Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?>

-
-
diff --git a/templates/Notifications/index.php b/templates/Notifications/index.php index 97ec5e41f..cc18dd233 100755 --- a/templates/Notifications/index.php +++ b/templates/Notifications/index.php @@ -1,62 +1,4 @@ $notifications - */ + $this->assign('NT', 'active'); + echo $this->element('notification/index'); ?> -
- Html->link(__('New Notification'), ['action' => 'add'], ['class' => 'button float-right']) ?> -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Paginator->sort('id') ?>Paginator->sort('user_id') ?>Paginator->sort('type') ?>Paginator->sort('model') ?>Paginator->sort('foreign_key') ?>Paginator->sort('title') ?>Paginator->sort('url') ?>Paginator->sort('deleted') ?>Paginator->sort('deleted_date') ?>Paginator->sort('created') ?>Paginator->sort('modified') ?>
Number->format($notification->id) ?>has('user') ? $this->Html->link($notification->user->name, ['controller' => 'Users', 'action' => 'view', $notification->user->id]) : '' ?>type) ?>model) ?>foreign_key === null ? '' : $this->Number->format($notification->foreign_key) ?>title) ?>url) ?>deleted) ?>deleted_date) ?>created) ?>modified) ?> - Html->link(__('View'), ['action' => 'view', $notification->id]) ?> - Html->link(__('Edit'), ['action' => 'edit', $notification->id]) ?> - Form->postLink(__('Delete'), ['action' => 'delete', $notification->id], ['confirm' => __('Are you sure you want to delete # {0}?', $notification->id)]) ?> -
-
-
-
    - Paginator->first('<< ' . __('first')) ?> - Paginator->prev('< ' . __('previous')) ?> - Paginator->numbers() ?> - Paginator->next(__('next') . ' >') ?> - Paginator->last(__('last') . ' >>') ?> -
-

Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?>

-
-
diff --git a/templates/Reporter/Notifications/index.php b/templates/Reporter/Notifications/index.php index 97ec5e41f..cc18dd233 100755 --- a/templates/Reporter/Notifications/index.php +++ b/templates/Reporter/Notifications/index.php @@ -1,62 +1,4 @@ $notifications - */ + $this->assign('NT', 'active'); + echo $this->element('notification/index'); ?> -
- Html->link(__('New Notification'), ['action' => 'add'], ['class' => 'button float-right']) ?> -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Paginator->sort('id') ?>Paginator->sort('user_id') ?>Paginator->sort('type') ?>Paginator->sort('model') ?>Paginator->sort('foreign_key') ?>Paginator->sort('title') ?>Paginator->sort('url') ?>Paginator->sort('deleted') ?>Paginator->sort('deleted_date') ?>Paginator->sort('created') ?>Paginator->sort('modified') ?>
Number->format($notification->id) ?>has('user') ? $this->Html->link($notification->user->name, ['controller' => 'Users', 'action' => 'view', $notification->user->id]) : '' ?>type) ?>model) ?>foreign_key === null ? '' : $this->Number->format($notification->foreign_key) ?>title) ?>url) ?>deleted) ?>deleted_date) ?>created) ?>modified) ?> - Html->link(__('View'), ['action' => 'view', $notification->id]) ?> - Html->link(__('Edit'), ['action' => 'edit', $notification->id]) ?> - Form->postLink(__('Delete'), ['action' => 'delete', $notification->id], ['confirm' => __('Are you sure you want to delete # {0}?', $notification->id)]) ?> -
-
-
-
    - Paginator->first('<< ' . __('first')) ?> - Paginator->prev('< ' . __('previous')) ?> - Paginator->numbers() ?> - Paginator->next(__('next') . ' >') ?> - Paginator->last(__('last') . ' >>') ?> -
-

Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?>

-
-
diff --git a/templates/element/notification/index.php b/templates/element/notification/index.php new file mode 100644 index 000000000..1bf41bcef --- /dev/null +++ b/templates/element/notification/index.php @@ -0,0 +1,217 @@ +assign('NT', 'active'); +echo $this->Html->script('highcharts/modules/data', array('inline' => false)); +?> + +
+
+ +
+
+
+

Notifications: Filter, Search, and view reports

+
+
+
+
+ + Form->create(null, [ + 'type' => 'get', + 'url' => ['action' => 'index'] + ]); ?> + + + + + + + + + + + +
+ Form->control('protocol_no', array( + 'div' => false, 'class' => 'span12 unauthorized_index', + 'label' => array('class' => 'required', 'text' => 'Reference No.'), + 'type' => 'text', + )); + ?> + + Form->control( + 'start_date', + ['label' => array( + 'class' => 'required start_date', 'text' => 'Notification Create Dates' + ), 'class' => 'start_date', 'templates' => 'clear_form', 'placeholder' => 'Sent Start Date'] + ); + echo $this->Form->control( + 'end_date', + [ + 'label' => array( + 'class' => 'required end_date', 'text' => 'Notification Create Dates' + ), + 'class' => 'end_date', + 'templates' => 'clear_form', 'placeholder' => 'Sent End Date' + ] + ); + + ?> + + Form->control('model', array( + 'div' => false, 'class' => 'span12 unauthorized_index', + 'label' => array('class' => 'required', 'text' => 'Report Type.'), + 'type' => 'select', + 'empty' => true, + 'options' => array( + 'User' => 'User Registration', + 'Sadr' => 'SADR', + 'Padr' => 'PADR', + 'Aefi' => 'AEFI', + 'Saefi' => 'Investigation Reports', + 'Pqmp' => 'PQHPT', + 'Ce2b' => 'E2B', + 'Device' => 'Devices', + 'Medication' => 'Medication Errors', + 'Transfusion' => 'Transfusion Reaction' + ), + )); + ?> + + + Form->control('pages', array( + 'type' => 'select', + 'div' => false, + 'class' => 'span12', + // 'selected' => $this->request->getParams('paging')['limit'], + 'empty' => true, + 'options' => $page_options, + 'label' => array('class' => 'required', 'text' => 'Pages'), + )); + ?> + + + Form->button(' Search', array( + 'escapeTitle' => false, + 'class' => 'btn btn-inverse', 'div' => 'control-group', 'div' => false, + 'style' => array('margin-bottom: 5px') + )); + + echo $this->Html->link(' Clear', array('action' => 'index'), array('class' => 'btn', 'escape' => false, 'style' => array('margin-bottom: 5px'))); + echo "
"; + echo $this->Html->link(' Excel', array('action' => 'index', 'ext' => 'csv'), array('class' => 'btn btn-success', 'escape' => false)); + ?> +
+ + Form->end(); ?> +

+ Paginator->counter( + __('Page {{page}} of {{pages}}, + showing {{current}} Notifications out of + {{count}} total, starting on record {{start}}, + ending on {{end}}') + ); + + ?> +

+ + + + + + + + + + + + + + + + + + + + + + + +
Paginator->sort('id'); ?>Paginator->sort('user_id'); ?>Paginator->sort('created'); ?>
  +   +    + Form->postLink( + '', + array('action' => 'delete', $notification['id']), + array('escape' => false), + __('Are you sure you want to delete # %s?', $notification['id']) + ); ?> +
+
+
+ + \ No newline at end of file