Skip to content

Commit

Permalink
Merge pull request #3 from tbar0970/master
Browse files Browse the repository at this point in the history
update to jethro master
  • Loading branch information
eb3nezer authored Oct 13, 2018
2 parents d15a534 + 1b7c82c commit c088e73
Show file tree
Hide file tree
Showing 62 changed files with 1,896 additions and 396 deletions.
7 changes: 5 additions & 2 deletions calls/call_email.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ function run()
$blanks = $GLOBALS['system']->getDBObjectData('person', Array('(id' => $personids, 'email' => '', '!status' => 'archived'), 'AND');
$archived = $GLOBALS['system']->getDBObjectData('person', Array('(id' => $personids, 'status' => 'archived'), 'AND');
} else if (!empty($_REQUEST['roster_view'])) {
$view = $GLOBALS['system']->getDBObject('roster_view', (int)$_REQUEST['roster_view']);
$recips = $view->getAssignees($_REQUEST['start_date'], $_REQUEST['end_date']);
$recips = Array();
foreach ((array)$_REQUEST['roster_view'] as $viewid) {
$view = $GLOBALS['system']->getDBObject('roster_view', (int)$viewid);
$recips += $view->getAssignees($_REQUEST['start_date'], $_REQUEST['end_date']);
}
} else {
if (empty($_REQUEST['personid'])) {
$recips = $emails = $blanks = $archived = Array();
Expand Down
2 changes: 1 addition & 1 deletion calls/call_roster_csv.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function run()
$start_date = substr(array_get($_REQUEST, 'start_date', ''), 0, 10);
$end_date = substr(array_get($_REQUEST, 'end_date', ''), 0, 10);
header('Content-type: text/csv');
header('Content-disposition: attachment; filename='.preg_replace('[^a-zA-Z0-9]', '_', $view->getValue('name')).'.csv');
header('Content-disposition: attachment; filename="'.preg_replace('[^a-zA-Z0-9]', '_', $view->getValue('name')).'.csv"');
$view->printCSV($start_date, $end_date);

}
Expand Down
4 changes: 4 additions & 0 deletions conf.php.sample
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,7 @@ define('DB_TYPE', 'mysql');
// For troubleshooting you can use this to show error details in the browser
// This is usually disabled in production versions but shown in dev.
// define('SHOW_ERROR_DETAILS', TRUE);

// Text encoding for sending SMS messages.
// Change it to something other than GSM0338 to stop Jethro filtering out non-GSMS0338 characters.
// define('SMS_ENCODING', 'GSM0338');
19 changes: 17 additions & 2 deletions db_objects/abstract_note.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected static function _getFields()
'editable' => false,
'references' => 'person',
'visible' => false,
'default' => NULL,
),
'edited' => Array(
'type' => 'datetime',
Expand Down Expand Up @@ -207,7 +208,7 @@ public function canEditOriginal() {
function delete()
{
if (!$this->canBeDeleted()) {
trigger_error("This note can not be deleted");
trigger_error("This note can not be deleted", E_USER_WARNING);
return FALSE;
}
if (!parent::delete()) return FALSE;
Expand Down Expand Up @@ -302,7 +303,7 @@ public static function getNotifications($minutes)
COUNT(DISTINCT nn.id) as new_notes,
GROUP_CONCAT(nn.id) as new_note_ids
FROM person p
JOIN abstract_note nn ON nn.assignee = p.id
JOIN abstract_note nn ON nn.assignee = p.id
AND nn.status = "pending"
AND nn.action_date <= DATE(NOW())
AND ((
Expand All @@ -319,4 +320,18 @@ public static function getNotifications($minutes)
GROUP BY p.id';
return $GLOBALS['db']->queryAll($SQL);
}

/**
* Clean up any orphaned records that are not references by a person or family note
* @return boolean
*/
public static function cleanupInstances()
{
$SQL = 'DELETE FROM abstract_note WHERE id NOT IN (
SELECT id FROM person_note
UNION
SELECT id from family_note
)';
return $GLOBALS['db']->exec($SQL);
}
}
26 changes: 26 additions & 0 deletions db_objects/attendance_record.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
include_once 'include/db_object.class.php';
class Attendance_Record extends db_object
{
// NB This class only exists for the following SQL
// See Attendance_Record_Set for CRUD functionality of this table

function getInitSQL($table_name=NULL)
{
return "
CREATE TABLE `attendance_record` (
`date` date NOT NULL,
`personid` int(11) NOT NULL,
`groupid` int(11) NOT NULL,
`present` tinyint(1) unsigned NOT NULL,
PRIMARY KEY (`date`,`personid`,`groupid`)
) ENGINE=InnoDB ;
";
}

public function getForeignKeys()
{
return Array('personid' => '`_person` (`id`) ON DELETE CASCADE');
}
}
?>
23 changes: 2 additions & 21 deletions db_objects/attendance_record_set.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,6 @@ function create()
{
}


function getInitSQL($table_name=NULL)
{
return "
CREATE TABLE `attendance_record` (
`date` date NOT NULL default '0000-00-00',
`personid` int(11) NOT NULL default '0',
`groupid` int(11) NOT NULL default '0',
`present` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`date`,`personid`,`groupid`)
) ENGINE=InnoDB ;
";
}

public function getForeignKeys()
{
return Array();
}

function load($date, $cohort, $age_brackets, $statuses)
{
$this->date = $date;
Expand Down Expand Up @@ -346,7 +327,7 @@ function printHeadcountField()
$headcountValue = Headcount::fetch('person_group', $this->date, $this->groupid);
}
?>
<input type="text" class="int-box" name="<?php echo $headcountFieldName; ?>" value="<?php echo $headcountValue; ?>" size="5" />
<input type="number" inputmode="numeric" pattern="[0-9]*" name="<?php echo $headcountFieldName; ?>" value="<?php echo $headcountValue; ?>" style="width: 60px" />
<input type="button" class="btn" onclick="var x = $(this).siblings('input').get(0); x.value = x.value == '' ? 1 : parseInt(x.value, 10)+1" value="+" />
<?php
}
Expand Down Expand Up @@ -512,7 +493,7 @@ public static function getStatsForPeriod($start_date, $end_date, $cohortid)
GROUP BY ar.personid, '.$selectCol.'
) indiv
GROUP BY '.$rank.' '.$groupingField.' WITH ROLLUP';
$res = $db->queryAll($sql);
$res = $db->queryAll($sql);

foreach ($res as $row) {
if (NULL !== $row[$groupingField]) {
Expand Down
10 changes: 6 additions & 4 deletions db_objects/custom_field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public function printWidget($value, $extraParams=Array(), $prefix='')
if (($this->getValue('type') == 'select') && strlen($value) && !empty($this->values['params']['allow_other'])) {
if (!isset($widgetParams['options'][$value])) {
$otherValue = $value;
if (0 === strpos($otherValue, '0 ')) $otherValue = substr($otherValue, 2);
$value = 'other';
}
}
Expand Down Expand Up @@ -557,7 +558,7 @@ public function formatValue($val)
{
if (is_array($val)) return implode(', ', array_map(Array($this, 'formatValue'), $val));
if (!strlen($val)) return '';

switch ($this->getValue('type')) {
case 'date':
if (!preg_match('/(([-0-9]{4})?-([0-9]{2}-[0-9]{2}))( (.*))?/', $val, $matches)) {
Expand Down Expand Up @@ -637,12 +638,13 @@ public function parseValue($val)

/**
* Get SQL expression to retrieve a value suitable for use by formatValue() above.
* @param string $tableAlias Alias of the custom_field_value table in the SQL statement
* @param string $valueTableAlias Alias of the custom_field_value table in the SQL statement
* @param string $fieldTableAlias Alias of the custom_field table in the SQL statement
* @return string SQL
*/
public static function getRawValueSQLExpr($tableAlias)
public static function getRawValueSQLExpr($valueTableAlias, $fieldTableAlias)
{
return 'TRIM(CONCAT(COALESCE('.$tableAlias.'.value_optionid, CONCAT('.$tableAlias.'.value_date, " "), ""), COALESCE('.$tableAlias.'.value_text, "")))';
return 'TRIM(CONCAT(COALESCE('.$valueTableAlias.'.value_optionid, CONCAT('.$valueTableAlias.'.value_date, " "), ""), COALESCE(CONCAT(IF('.$fieldTableAlias.'.type="select", "0 ", ""), '.$valueTableAlias.'.value_text), "")))';
}

/**
Expand Down
65 changes: 58 additions & 7 deletions db_objects/family.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function getInitSQL($table_name=NULL)
"CREATE TABLE family_photo (
familyid INT NOT NULL,
photodata MEDIUMBLOB NOT NULL,
CONSTRAINT `famliyphotofamilyid` FOREIGN KEY (`familyid`) REFERENCES `family` (`id`),
CONSTRAINT `famliyphotofamilyid` FOREIGN KEY (`familyid`) REFERENCES `family` (`id`) ON DELETE CASCADE,
PRIMARY KEY (familyid)
) ENGINE=InnoDB;
"
Expand Down Expand Up @@ -158,7 +158,7 @@ function printForm($prefix='', $fields=NULL)
function processForm($prefix='', $fields=NULL)
{
$res = parent::processForm($prefix, $fields);
$this->_photo_data = Photo_Handler::getUploadedPhotoData('photo');
$this->_photo_data = Photo_Handler::getUploadedPhotoData('photo', Photo_Handler::CROP_NONE);
return $res;
}

Expand Down Expand Up @@ -188,7 +188,7 @@ function printMemberList($abbreviated=NULL)
$persons = $this->getMemberData();
$show_actions = !empty($this->id); // hide actions if this is a "draft" family

if (isset($this->_tmp['show_member_callback'])) {
if (!empty($this->_tmp['show_member_callback'])) {
call_user_func($this->_tmp['show_member_callback'], $persons);

} else if (!$abbreviated) {
Expand Down Expand Up @@ -245,7 +245,7 @@ function printFieldInterface($name, $prefix='')
{
if ($name == 'photo') {
?>
<input type="file" name="photo" />
<input type="file" accept="image/*" name="photo" />
<?php
return;
}
Expand Down Expand Up @@ -336,7 +336,6 @@ function printSummaryWithMembers($abbreviate_member_list=TRUE, $member_data=NULL

function printCustomSummary($showMembersCallback)
{
// TODO: test this in the mmebers interface
$this->fields['members'] = Array('divider_before' => 1);
$this->_tmp['show_member_callback'] = $showMembersCallback;
parent::printSummary();
Expand All @@ -346,8 +345,10 @@ function printCustomSummary($showMembersCallback)

function getMemberData()
{
//$objectType = $GLOBALS['user_system']->getCurrentUser() ? 'person' : 'member';
$restriction = $GLOBALS['user_system']->getCurrentUser() ? Array() : Array('!status' => 'archived');
if (!isset($this->_tmp['members'])) {
$this->_tmp['members'] = $GLOBALS['system']->getDBObjectData('person', Array('familyid' => $this->id), 'OR', 'ab.rank, gender DESC');
$this->_tmp['members'] = $GLOBALS['system']->getDBObjectData('person', Array('familyid' => $this->id)+$restriction, 'AND', 'ab.rank, gender DESC');
}
return $this->_tmp['members'];
}
Expand Down Expand Up @@ -481,6 +482,13 @@ private function savePhoto() {
}
}

private function clearPhoto()
{
$db =& $GLOBALS['db'];
$SQL = 'DELETE FROM family_photo WHERE familyid = '.(int)$this->id;
return $db->query($SQL);
}

/* Find a family that looks like a duplicate of this one - if it has the same family name and a member with the same name
*/
public function findSimilarFamilies()
Expand Down Expand Up @@ -526,7 +534,7 @@ public static function getFamilyDataByMemberIDs($member_ids)
) allmembers ON allmembers.familyid = f.id
LEFT JOIN (
select f.id as familyid, GROUP_CONCAT(p.first_name ORDER BY ab.rank ASC, p.gender DESC SEPARATOR ", ") as names
FROM person p
FROM person p
JOIN family f on p.familyid = f.id
JOIN age_bracket ab ON ab.id = p.age_bracketid
WHERE ab.is_adult and p.status <> "archived"
Expand Down Expand Up @@ -563,4 +571,47 @@ public static function printSingleFinder($name, $currentval=NULL)
<?php
}

public function archiveAndClean()
{
if (!$this->acquireLock()) return FALSE;
foreach ($this->fields as $fieldname => $params) {
switch ($fieldname) {
case 'family_name':
$this->setValue($fieldname, '['._('Removed').']');
break;
case 'status_last_changed':
case 'creator':
case 'created':
case 'state':
// leave these intact
break;
case 'status':
$this->setValue($fieldname, 'archived');
break;
case 'history':
$this->setValue($fieldname, Array());
break;
default:
$this->setValue($fieldname, '');
}
}
$this->clearPhoto();
if (!$this->save(FALSE)) return FALSE;

$notes = $GLOBALS['system']->getDBObjectData('family_note', Array('familyid' => $this->id));
foreach ($notes as $noteid => $data) {
$n = new Family_Note($noteid);
$n->delete();
}

$this->releaseLock();
return TRUE;
}

public function delete()
{
parent::delete();
Abstract_Note::cleanupInstances();
return TRUE;
}
}
4 changes: 3 additions & 1 deletion db_objects/family_note.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ function getInitSQL($table_name=NULL)
CREATE TABLE `family_note` (
`familyid` int(11) NOT NULL default '0',
`id` int(11) NOT NULL default '0',
PRIMARY KEY (`familyid`,`id`)
PRIMARY KEY (`familyid`,`id`),
CONSTRAINT `fn_familyid` FOREIGN KEY (familyid) REFERENCES family(id) ON DELETE CASCADE,
CONSTRAINT fn_id FOREIGN KEY (id) REFERENCES abstract_note(id) ON DELETE CASCADE
) ENGINE=InnoDB;
";
}
Expand Down
Loading

0 comments on commit c088e73

Please sign in to comment.