Skip to content

Commit

Permalink
UPD: padrs view
Browse files Browse the repository at this point in the history
  • Loading branch information
Itskiprotich committed Aug 14, 2024
1 parent b39a1aa commit 81e74ee
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 91 deletions.
4 changes: 4 additions & 0 deletions src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class AppController extends Controller
*/

public $Notifications;
public $Messages;
public $QueuedJobs;

public function initialize(): void
{
Expand All @@ -54,6 +56,8 @@ public function initialize(): void
// $this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->Notifications = $this->loadModel('Notifications');
$this->Messages = $this->loadModel('Messages');
$this->QueuedJobs = $this->loadModel('Queue.QueuedJobs');

// $this->loadHelper('Tools.Captcha', [
// 'type' => 'active'
Expand Down
86 changes: 86 additions & 0 deletions src/Controller/PadrsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

use Cake\Event\EventInterface;
use Cake\I18n\FrozenTime;
use Cake\Routing\Router;
use Cake\Utility\Security;
use Cake\Utility\Text;
use Cake\View\Helper\HtmlHelper;

/**
* Padrs Controller
Expand Down Expand Up @@ -61,6 +64,8 @@ public function view($id = null)
'conditions' => ['Padrs.token' => $id] // Replace 'other_column' with the actual column name
])->firstOrFail();
//
// debug($padr);
// exit;
$this->set(compact('padr'));
}

Expand Down Expand Up @@ -109,6 +114,87 @@ public function add()
->execute();


//****************** Send Emails to Reporter and Managers *****************************


$html = new HtmlHelper(new \Cake\View\View());

$message = $this->Messages->find()
->where(['name' => 'reporter_padr_submit'])
->first();
$padr = $this->Padrs->get($padr['id'], [
'contain' => [],
]);
// debug($padr);
// exit;
$referenceLink = Router::url([
'controller' => 'padrs',
'action' => 'view',
$padr['token']
], true);
$variables = array(
'name' => $padr['reporter_name'],
'reference_no' => $padr['reference_no'],
'reference_link' => $html->link(
$padr['reference_no'],
$referenceLink,
// array('controller' => 'padrs', 'action' => 'view', $padr['token'], 'full_base' => true),
array('escape' => false)
),
'modified' => $padr['modified']
);
$datum = array(
'email' => $padr['reporter_email'],
'id' => $padr->id,
'type' => 'reporter_padr_submit',
'model' => 'Padr',
'subject' => Text::insert($message['subject'], $variables),
'message' => Text::insert($message['content'], $variables)
);

$this->QueuedJobs->createJob('GenericEmail', $datum);
//Notify managers
$users = $this->Padrs->Users->find('all', [
'contain' => [],
'conditions' => [
'Users.role_id' => 2,
'Users.is_active' => '1'
]
]);

$referenceLink = Router::url([
'controller' => 'padrs',
'action' => 'view',
$padr['token'],
// 'prefix' => 'manager'
], true);
foreach ($users as $user) {

$variables = array(
'name' => $user['name'],
'reference_no' => $padr['reference_no'],
'reference_link' => $html->link(
$padr['reference_no'],
$referenceLink,
array('escape' => false)
),
'modified' => $padr['modified']
);
$datum = array(
'email' => $user['email'],
'id' => $padr->id,
'user_id' => $user['id'],
'type' => 'reporter_padr_submit',
'model' => 'Padr',
'subject' => Text::insert($message['subject'], $variables),
'message' => Text::insert($message['content'], $variables)
);

$this->QueuedJobs->createJob('GenericEmail', $datum);
$this->QueuedJobs->createJob('GenericNotification', $datum);
}
//********************************** END *********************************


$this->Flash->success(__('The padr has been saved.'));

Expand Down
3 changes: 1 addition & 2 deletions src/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ public function register()
'subject' => $subject,
'message' => $message
);

$this->loadModel('Queue.QueuedJobs'); // Load the model correctly

$this->QueuedJobs->createJob('GenericNotification', $datum);
$this->QueuedJobs->createJob('GenericEmail', $datum);
//
Expand Down
112 changes: 77 additions & 35 deletions templates/Admin/Messages/edit.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,80 @@
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\Message $message
*/
$this->assign('Content', 'active');
echo $this->Html->script('ckeditor/ckeditor', array('inline' => false));
echo $this->Html->script('ckeditor/adapters/jquery', array('inline' => false));
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Form->postLink(
__('Delete'),
['action' => 'delete', $message->id],
['confirm' => __('Are you sure you want to delete # {0}?', $message->id), 'class' => 'side-nav-item']
) ?>
<?= $this->Html->link(__('List Messages'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
</div>
</aside>
<div class="column-responsive column-80">
<div class="messages form content">
<?= $this->Form->create($message) ?>
<fieldset>
<legend><?= __('Edit Message') ?></legend>
<?php
echo $this->Form->control('name');
echo $this->Form->control('subject');
echo $this->Form->control('content');
echo $this->Form->control('sms');
echo $this->Form->control('type');
echo $this->Form->control('style');
echo $this->Form->control('description');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>

<div class="row-fluid" style="margin-bottom: 9px;">
<div class="span2 columns">
<div class="row-fluid">
<div class="span12">
<?php echo $this->element('admin/contentmenu') ?>
</div><!--/span-->
</div><!--/row-->
</div> <!-- /span5 -->

<div class="span10 columns">
<div class="row-fluid">
<?php echo $this->Form->create(
$message, array(
'type' => 'file',
// 'class' => 'form-horizontal',

));
echo $this->Form->control('id'); ?>
<fieldset>
<legend>Edit <strong><?php echo $this->Form->value('Messages.name'); ?></strong></legend>
<?php
echo $this->Form->control('id');
echo $this->Form->control('subject');
echo $this->Form->control(
'style',
array(
'type' => 'select',
'empty' => true,
'options' => array('info' => 'Blue', 'success' => 'Green', 'error' => 'Red', 'warning' => 'Orange'),
'label' => array('class' => 'control-label', 'text' => 'Notification Style')
)
);
echo $this->Form->control('content', array(
'id'=>'message',
'label' => array(
'class' => 'control-label required message',
'text' => 'Content <span class="sterix">*</span>',
'escape' => false
),
'between' => '<div class="controls">', 'placeholder' => 'content', 'class' => 'control-large',
));
echo $this->Form->control('sms', array(
'type' => 'textarea',
'rows' => 3,
'label' => array('class' => 'control-label required', 'text' => 'SMS <span class="sterix">*</span>','escape'=>false),
'between' => '<div class="controls">',
'placeholder' => 'sms',
'class' => 'control-xxlarge',
));
echo $this->Form->control('type');
echo $this->Form->control('description', array('class' => 'control-xlarge'));
?>
</fieldset>
<?php

echo $this->Html->div(
'form-actions',
$this->Form->button('<i class="icon-search icon-white"></i> Submit', [
'escapeTitle' => false,
'type' => 'Submit',
'class' => 'btn btn-primary',
'id' => 'SadrSaveChanges'
])
);

// Close the form
echo $this->Form->end();
?>

<script type="text/javascript">
CKEDITOR.replace('message');
</script>
</div>
</div>
60 changes: 34 additions & 26 deletions templates/element/padr/padr_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,14 @@
<?php

echo $this->Form->control('date_of_birth', array(
'type' => 'date',
'dateFormat' => 'DMY',
'minYear' => date('Y') - 100,
'maxYear' => date('Y'),
'type' => 'text',

'empty' => array('day' => '(day)', 'month' => '(month)', 'year' => '(year)'),
'label' => array('class' => 'control-label required', 'text' => 'Date of Birth'),
'title' => 'select beginning of the month if unsure',
'data-content' => 'If selected, year is mandatory.',

'class' => 'tooltipper set-control',
'class' => 'tooltipper set-control date-pick-from',
));

?>
Expand Down Expand Up @@ -375,20 +373,19 @@
<div class="span4">
<?php
echo $this->Form->control('date_of_onset_of_reaction', array(
'type' => 'date',
'type' => 'text',
'between' => false,
'div' => false,
'after' => false,
'dateFormat' => 'DMY',
'minYear' => date('Y') - 100,
'maxYear' => date('Y'),
'empty' => array('day' => '(day)', 'month' => '(month)', 'year' => '(year)'),
'label' => array('class' => 'required', 'text' => 'When did the reaction start? '),
'class' => 'span4',
'class' => 'span6 date-pick-from',
));


echo $this->Form->control('reaction_on', array(
'type' => 'radio',
'label' => false,
'label' => array('text' => 'Is the reaction still on?'),
'legend' => false,
'div' => false,
'hiddenField' => false,
Expand Down Expand Up @@ -416,6 +413,17 @@
</div> </div>',
'options' => array('No' => 'No'),
));


echo $this->Form->control('date_of_end_of_reaction', array(
'type' => 'text',
'between' => false,
'div' => false,
'after' => false,
'empty' => array('day' => '(day)', 'month' => '(month)', 'year' => '(year)'),
'label' => array('class' => 'required end', 'text' => 'When did the reaction end? '),
'class' => 'span6 date-pick-from end',
));
?>
</div>
</div>
Expand All @@ -435,45 +443,45 @@
echo "<h6>Select all issues with the medicine/device</h6>";
echo $this->Form->control('pqmp_label', array(
'type' => 'checkbox',
'label' => array('text'=>'The label looks wrong '),
'label' => array('text' => 'The label looks wrong '),
'div' => false,
'class' => false,
'hiddenField' => false,
'hiddenField' => false,
));
echo $this->Form->control('pqmp_material', array(
'type' => 'checkbox',
'label' => array('text' => 'Has unusual material in it '),
'div' => false,
'class' => false,
'hiddenField' => false,
'hiddenField' => false,
));
echo $this->Form->control('pqmp_color', array(
'type' => 'checkbox',
'label' => array('text'=>'The color is changing'),
'label' => array('text' => 'The color is changing'),
'div' => false,
'class' => false,
'hiddenField' => false,
'hiddenField' => false,
));
echo $this->Form->control('pqmp_smell', array(
'type' => 'checkbox',
'label' => array('text'=>'The smell is unusual'),
'label' => array('text' => 'The smell is unusual'),
'div' => false,
'class' => false,
'hiddenField' => false,
'hiddenField' => false,
));
echo $this->Form->control('pqmp_working', array(
'type' => 'checkbox',
'label' => array('text'=>'The medicine/device is not working'),
'label' => array('text' => 'The medicine/device is not working'),
'div' => false,
'class' => false,
'hiddenField' => false,
'hiddenField' => false,
));
echo $this->Form->control('pqmp_bottle', array(
'type' => 'checkbox',
'label' => array('text'=>'The packet or bottle does not seem to be usual or complete '),
'label' => array('text' => 'The packet or bottle does not seem to be usual or complete '),
'div' => false,
'class' => false,
'hiddenField' => false,
'hiddenField' => false,
)); ?>
</div>
<!--/span-->
Expand All @@ -493,8 +501,8 @@
<!--/row-->
</div>

<?php
echo $this->element('multi/padr_list_of_medicines');
<?php
echo $this->element('multi/padr_list_of_medicines');
?>

<!-- Section to show the outcome -->
Expand Down Expand Up @@ -589,8 +597,8 @@
?>
</div>
<!-- End of outcome section -->
<?php
echo $this->element('multi/attachments', ['model' => 'Padr', 'group' => 'attachment', 'examples' => '']);
<?php
echo $this->element('multi/attachments', ['model' => 'Padr', 'group' => 'attachment', 'examples' => '']);
?>
<div class="row-fluid report">
<?php
Expand Down
Loading

0 comments on commit 81e74ee

Please sign in to comment.