Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication History #606

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
525babe
Inital separation of communication logs from other notes
vanoudt Jun 11, 2019
2fa286d
Create new Person_Comm class to hold communication logs
vanoudt Jun 11, 2019
f442c69
Default to saving a copy of SMS messages
vanoudt Jun 11, 2019
6ba95f5
Move existing SMS messages to the comms table
vanoudt Jun 12, 2019
66bcd84
Save SMS Messages as Comms rather than Notes
vanoudt Jun 18, 2019
a21c0b5
Wording on failure to save
vanoudt Jun 18, 2019
a511fe0
Make sure that the header has the right line breaks
vanoudt Jul 10, 2019
8ceccb7
Had some issues with the constraints complaining, so disabled them. N…
vanoudt Jul 10, 2019
a03fa3d
Merge remote-tracking branch 'upstream/master' into communication_notes
vanoudt Jul 14, 2019
9ed05e4
Optional saving of messages
vanoudt Feb 12, 2020
4637a27
Update sample to make saving sms comms optional
vanoudt Feb 12, 2020
0415ea9
Make sms logging optional
vanoudt Feb 12, 2020
8ff3d0c
Make saving sms communications optional
vanoudt Feb 12, 2020
694ad81
Missing ) in comment
vanoudt Feb 12, 2020
0591b05
Merge remote-tracking branch 'upstream/master' into communication_notes
vanoudt May 13, 2020
92f6f02
Merge branch 'communication_notes' of github.com:vanoudt/jethro-pmm i…
vanoudt May 13, 2020
a866b4b
Merge branch 'master' into communication_notes
Nov 2, 2020
5251109
Merge remote-tracking branch 'upstream/master' into communication_notes
vanoudt Aug 23, 2022
48a78bc
Merge remote-tracking branch 'upstream/master' into communication_notes
vanoudt Aug 24, 2022
a44d24a
Merge remote-tracking branch 'upstream/master' into communication_notes
vanoudt Aug 27, 2022
28e029c
Update 2019-upgrade-to-2.28.sql
vanoudt Sep 5, 2022
5f78263
Update comm_reply.class.php
vanoudt Sep 5, 2022
55665c0
Merge remote-tracking branch 'upstream/master' into communication_notes
vanoudt Sep 13, 2022
61908a2
Merge remote-tracking branch 'upstream/master' into communication_notes
vanoudt Oct 28, 2022
fd5ae9d
Merge remote-tracking branch 'upstream/master' into communication_notes
vanoudt Mar 27, 2023
ab91952
Actually obey the option to save communication notes
vanoudt Mar 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions db_objects/comm_reply.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
include_once 'include/db_object.class.php';
class Comm_Reply extends DB_Object
{
protected $_load_permission_level = PERM_VIEWNOTE;
protected $_save_permission_level = PERM_EDITNOTE;

protected static function _getFields()
{
return Array(
'commid' => Array(
'type' => 'int',
'references' => 'abstract_note',
'editable' => false,
'label' => 'Response to',
),
'creator' => Array(
'type' => 'int',
'editable' => false,
'references' => 'person',
),
'created' => Array(
'type' => 'datetime',
'readonly' => true,
),
'contents' => Array(
'type' => 'text',
'width' => 50,
'height' => 5,
'initial_cap' => true,
'label' => '',
'class' => 'initial-focus'
),
);
}

function getInitSQL($table_name=NULL)
{
return "
CREATE TABLE `comm_reply` (
`id` int(11) NOT NULL auto_increment,
`commid` int(11) NOT NULL default '0',
`creator` int(11) NOT NULL default '0',
`created` timestamp NOT NULL default CURRENT_TIMESTAMP,
`contents` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB ;
";
}

function getInstancesQueryComps($params, $logic, $order)
{
$res = parent::getInstancesQueryComps($params, $logic, $order);
$res['from'] = '('.$res['from'].') LEFT OUTER JOIN person creator ON comm_reply.creator = creator.id';
$res['select'][] = 'creator.first_name as creator_fn';
$res['select'][] = 'creator.last_name as creator_ln';
return $res;

}

}
?>
11 changes: 10 additions & 1 deletion db_objects/person.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ function getNotesHistory()
return $all_notes;
}

function getCommsHistory()
{
$person_comms = $GLOBALS['system']->getDBObjectData('person_comm', Array('personid' => $this->id));
if (ifdef('NOTES_ORDER', 'ASC') != 'ASC') {
$person_comms = array_reverse($person_comms, TRUE);
}
return $person_comms;
}


function validateFields()
{
if (!parent::validateFields()) return FALSE;
Expand Down Expand Up @@ -1044,4 +1054,3 @@ public function delete()
}

}

62 changes: 62 additions & 0 deletions db_objects/person_comm.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
include_once 'db_objects/abstract_note.class.php';
class Person_Comm extends Abstract_Note
{
protected static function _getFields()
{
return Array(
'personid' => Array(
'type' => 'int',
'references' => 'person',
'editable' => false,
'label' => 'Person',
),
);

}


function getInitSQL($table_name=NULL)
{
return "
CREATE TABLE `person_comm` (
`personid` int(11) NOT NULL default '0',
`id` int(11) NOT NULL default '0',
PRIMARY KEY (`personid`,`id`),
CONSTRAINT `pn_personid` FOREIGN KEY (personid) REFERENCES _person(id) ON DELETE CASCADE,
CONSTRAINT pn_id FOREIGN KEY (id) REFERENCES abstract_note(id) ON DELETE CASCADE
) ENGINE=InnoDB ;
";
}

function printFieldValue($name, $value=NULL)
{
if (is_null($value)) $value = $this->values[$name];
if ($name == 'personid') {
if (!empty($value)) {
$person = $GLOBALS['system']->getDBObject('person', $value);
?>
<a href="?view=persons&personid=<?php echo $value; ?>"><?php echo $person->toString(); ?></a> (#<?php echo $value; ?>)
<?php
return;
}
}
return parent::printFieldValue($name, $value);
}

function getInstancesQueryComps($params, $logic, $order)
{
$res = parent::getInstancesQueryComps($params, $logic, $order);
$res['from'] = '('.$res['from'].') LEFT OUTER JOIN person person ON person_comm.personid = person.id';
$res['select'][] = 'person.first_name as person_fn';
$res['select'][] = 'person.last_name as person_ln';
return $res;
}

function printFieldInterface($name, $prefix = '') {
parent::printFieldInterface($name, $prefix);
}


}
?>
4 changes: 2 additions & 2 deletions db_objects/roster_view.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ function load($id)
// Enforce visibility
switch ($this->getValue('visibility')) {
case '':
if (!$GLOBALS['user_system']->getCurrentUser('id')) {
if (!$GLOBALS['user_system']->getCurrentUser('id') && (PHP_SAPI != 'cli')) {
header($_SERVER["SERVER_PROTOCOL"]." 401 Not Authorised");
print_message("Roster view #{$this->id} is only available to logged in operators", 'error');
exit;
}
break;
case 'members':
// Make sure either a user or a member is logged in
if (!$GLOBALS['user_system']->getCurrentPerson('id')) {
if (!$GLOBALS['user_system']->getCurrentPerson('id') && (PHP_SAPI != 'cli')) {
header($_SERVER["SERVER_PROTOCOL"]." 401 Not Authorised");
print_message("Roster view #{$this->id} is only available to logged in members", 'error');
exit;
Expand Down
2 changes: 1 addition & 1 deletion db_objects/service.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ function printFieldValue($fieldname, $value=NULL)
foreach ($this->getItems(FALSE, $compCatID) as $item) {
$res[] = ents($item['title']);
}
echo implode('<br />', $res);
echo implode('<br />', nbsp($res));
} else {
parent::printFieldvalue($fieldname);
}
Expand Down
28 changes: 14 additions & 14 deletions include/sms_sender.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ private static function cleanseMessage($message)
* Send an SMS message
* @param string $message
* @param array $recips Array of person records
* @param boolean $saveAsNote Whether to save a note against the recipients
* @param boolean $saveComm Whether to save a copy against the recipients
* @return array('success' => bool, 'successes' => array, 'failures' => array, 'rawresponse' => string)
*/
public static function sendMessage($message, $recips, $saveAsNote=FALSE)
public static function sendMessage($message, $recips, $saveComm=TRUE)
{
$message = self::cleanseMessage($message);
$mobile_tels = Array();
Expand Down Expand Up @@ -177,7 +177,7 @@ public static function sendMessage($message, $recips, $saveAsNote=FALSE)
}

$header = "" . ifdef('SMS_HTTP_HEADER_TEMPLATE', '');
$header = $header . "Content-Length: " . strlen($content) . "\r\n" . "Content-Type: application/x-www-form-urlencoded\r\n";
$header = $header . "\r\n" . "Content-Length: " . strlen($content) . "\r\n" . "Content-Type: application/x-www-form-urlencoded\r\n";

$opts = Array(
'http' => Array(
Expand All @@ -204,7 +204,7 @@ public static function sendMessage($message, $recips, $saveAsNote=FALSE)
fclose($fp);
}
} catch (Exception $e) {
$error = "ERROR: Unable to connect to SMS Server. " + $e->getMessage();
$error = "Exception ERROR: Unable to connect to SMS Server." . print_r($e, TRUE);
return array("success" => false, "successes" => array(), "failures" => array(), "rawresponse" => $error, "error" => $error);
}
restore_error_handler(); // Restore system error_handler
Expand All @@ -231,10 +231,10 @@ public static function sendMessage($message, $recips, $saveAsNote=FALSE)
}
} //$recips as $id => $recip
self::logSuccess(count($successes), $message);
if ($saveAsNote) self::saveAsNote($successes, $message);
if ($saveComm) self::saveComm($successes, $message);
} else {
self::logSuccess(count($mobile_tels), $message);
if ($saveAsNote) self::saveAsNote($recips, $message);
if ($saveComm) self::saveComm($recips, $message);
}
} //$success

Expand Down Expand Up @@ -311,18 +311,18 @@ public static function printModal()
<?php
}

private static function saveAsNote($recipients, $message)
private static function saveComm($recipients, $message)
{
$GLOBALS['system']->includeDBClass('person_note');
$GLOBALS['system']->includeDBClass('person_comm');
$subject = ifdef('SMS_SAVE_TO_NOTE_SUBJECT', 'SMS Sent');
foreach ($recipients as $id => $details) {
// Add a note containing the SMS to the user
$note = new Person_Note();
$note->setValue('subject', $subject);
$note->setvalue('details', $message);
$note->setValue('personid', $id);
if (!$note->create()) {
trigger_error('Failed to save SMS as a note.');
$comm = new Person_Comm();
$comm->setValue('subject', $subject);
$comm->setvalue('details', $message);
$comm->setValue('personid', $id);
if (!$comm->create()) {
trigger_error('Failed to save SMS as a communications note.');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion public/views/view_2_display_roster.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function printView()
?>
<ul>
<?php
$views = $GLOBALS['system']->getDBObjectData('roster_view', Array('!visibility' => ''), 'AND', 'name');
$views = $GLOBALS['system']->getDBObjectData('roster_view', Array('visibility' => 'public'), 'AND', 'name');
foreach ($views as $id => $detail) {
?>
<li><a href="<?php echo build_url(Array('roster_view' => $id)); ?>"><?php echo ents($detail['name']); ?></a></li>
Expand Down
2 changes: 1 addition & 1 deletion scripts/date_reminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function send_reminder($person)
$toNumber = $person['mobile_tel'];
if (!empty($ini['OVERRIDE_RECIPIENT_SMS'])) $toNumber = $ini['OVERRIDE_RECIPIENT_SMS'];
$message = replace_keywords($ini['SMS_MESSAGE'], $person);
$res = SMS_Sender::sendMessage($message, Array($person), FALSE);
$res = SMS_Sender::sendMessage($message, Array($person), TRUE);
if (count($res['successes']) != 1) {
echo "Failed to send SMS to ".$toNumber."\n";
} else {
Expand Down
2 changes: 1 addition & 1 deletion scripts/roster_reminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
require_once JETHRO_ROOT.'/include/sms_sender.class.php';
$notification_sms = '';
if (!empty($assignees)) {
$sendResponse = SMS_Sender::sendMessage($sms_message, $assignees, FALSE);
$sendResponse = SMS_Sender::sendMessage($sms_message, $assignees, TRUE);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want the roster reminder to be saved as a person_comm ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Tom! Sorry to have taken so long to get back to you on this. I figured that a roster reminder was a communication to a person, and so should be saved to the communication log. Perhaps it would be better to make this optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just threw together an option which would make it optional! :-)

$successes = $failures = $rawresponse = Array();
$success = $sendResponse['success'];
$successes = array_values($sendResponse['successes']);
Expand Down
9 changes: 9 additions & 0 deletions templates/list_comms.template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="notes-history-container">
<?php
$GLOBALS['system']->includeDBClass('abstract_note');
$dummy = new Abstract_Note();
foreach ($comms as $id => $entry) {
include 'single_comm.template.php';
}
?>
</div>
75 changes: 75 additions & 0 deletions templates/single_comm.template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* @var $id
* $var $entry
* @var $show_form
* @var $show_edit_link
*/

$dummy->populate($id, $entry);
$type = 1;
$icon = 'phone';
?>
<a name="note_<?php echo $id; ?>"></a>
<div class="notes-history-entry well <?php echo $type; ?>-note" id="note_<?php echo $id; ?>">


<?php
if (!empty($show_names)) {
if ($entry['type'] === 1) {
$type = 'sms';
$icon = 'phone';
} else {
$type = 'email';
$icon = 'envelope';
}
$notee = $entry['person_fn'].' '.$entry['person_ln'];
$view_url = '?view=persons&personid='.$entry['personid'].'#comm_'.$id;
?>
<h4><a href="<?php echo $view_url; ?>"><?php echo ents($notee); ?></a></h4>
<?php
}
?>
<i class="icon-<?php echo $icon; ?>"></i>
<blockquote>
<p class="subject"><?php echo ents($entry['subject']); ?></p>
<?php
if (strlen($entry['details'])) {
?>
<p class="content"><?php echo nl2br(ents($entry['details'])); ?></p>
<?php
}
?>
<small class="author">
<?php echo $entry['creator_fn'].' '.$entry['creator_ln'].' <span class="visible-desktop">(#'.$entry['creator'].')</span>,'; ?>
<?php echo format_datetime($entry['created']); ?>
<?php
?>
</small>
</blockquote>
<?php
if (!empty($entry['comments'])) {
?>
<div class="comments">
<?php
foreach ($entry['comments'] as $comment) {
?>
<blockquote>
<p><?php echo nl2br(ents(trim($comment['contents']))); ?></p>
<small class="author">
<?php echo $comment['creator_fn'].' '.$comment['creator_ln'].' <span class="visible-desktop">(#'.$entry['creator'].')</span>, '; ?>
<?php echo format_datetime($comment['created']); ?>
</small>
</blockquote>
<?php
}
?>
</div>
<?php
}


?>

</div>
Loading