Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tbar0970/jethro-pmm
Browse files Browse the repository at this point in the history
  • Loading branch information
tbar0970 committed Jun 14, 2018
2 parents f089209 + 4de5c8c commit 53ace2c
Show file tree
Hide file tree
Showing 16 changed files with 458 additions and 83 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
1 change: 1 addition & 0 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' => 0,
),
'edited' => Array(
'type' => 'datetime',
Expand Down
3 changes: 1 addition & 2 deletions db_objects/family.class.php
Original file line number Diff line number Diff line change
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 @@ -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 Down
4 changes: 3 additions & 1 deletion db_objects/roster_view.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ function printSingleViewFlexi($service, $includeServiceFields=FALSE)
?>
</div>
<?php

return $asns;
}

function printSingleViewTable($service, $columns=2, $includeServiceFields=FALSE)
Expand Down Expand Up @@ -1012,7 +1014,7 @@ static function getForRunSheet($congregationid)
)';
$ids = $GLOBALS['db']->queryCol($SQL);
foreach ($ids as $id) {
$res[] = $GLOBALS['system']->getDBObject('roster_view', $id);
$res[$id] = $GLOBALS['system']->getDBObject('roster_view', $id);
}
return $res;
}
Expand Down
37 changes: 33 additions & 4 deletions db_objects/service.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,14 +732,43 @@ public function printRunSheetPersonnelFlexi()
{
$rosterViews = Roster_View::getForRunSheet($this->getValue('congregationid'));
if ($rosterViews) {
ob_start();
$emails = $personids = Array();
foreach ($rosterViews as $view) {
$asns = $view->printSingleViewFlexi($this);
foreach ($asns as $role => $roleAsns) {
foreach ($roleAsns as $asn) {
if (!empty($asn['personid'])) $personids[] = $asn['personid'];
if (!empty($asn['email'])) $emails[] = $asn['email'];
}
}
}
$assignments_output = ob_get_clean();
$email_href = get_email_href($GLOBALS['user_system']->getCurrentUser('email'), NULL, array_unique($emails), $this->toString());
if ($GLOBALS['user_system']->havePerm('PERM_SENDSMS') && ifdef('SMS_HTTP_URL')) {
require_once 'include/sms_sender.class.php';
SMS_Sender::printModal();
}

?>
<div class="row-fluid">
<div id="service-personnel" class="span12 clearfix">
<h3>Personnel</h3>
<h3>
<span class="pull-right"><small>
<a href="<?php echo $email_href; ?>"><i class="icon-email">@</i>Email</a>
<?php
if ($GLOBALS['user_system']->havePerm('PERM_SENDSMS') && ifdef('SMS_HTTP_URL')) {
?>
&nbsp;
<a href="#send-sms-modal" data-personid="<?php echo implode(',', array_unique($personids)); ?>" data-toggle="sms-modal" data-name="Personnel for <?php echo ents($this->toString());?>"><i class="icon-envelope"></i>SMS</a>
<?php
}
?>
</small></span>
Personnel
</h3>
<?php
foreach ($rosterViews as $view) {
$view->printSingleViewFlexi($this);
}
echo $assignments_output;
?>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion include/db_object.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ public function save()
$changes = $this->_getChanges();
if ($changes) {
$user = $GLOBALS['user_system']->getCurrentPerson();
$this->values['history'][time()] = 'Updated by '.$user['first_name'].' '.$user['last_name'].' (#'.$user['id'].")\n".implode("\n", $changes);
$now = time();
$this->values['history'][$now] = 'Updated by '.$user['first_name'].' '.$user['last_name'].' (#'.$user['id'].")\n".implode("\n", $changes);
$this->_old_values['history'] = 1;
}
}
Expand Down
262 changes: 262 additions & 0 deletions include/jethrodb.php.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
<?php

/* Utility class for switching from MDB2 to PDO
* Some of the routines in this class are derived/copied(and adapted) from the MDB2 source.
* See https://pear.php.net/package/MDB2/ for the latest download of MDB2
* The following disclaimer applies to code from MDB2:
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

class JethroDB extends PDO
{
// TODO: Comments for all these

/**
* Create a JethroDB object from the details in conf.php and make it a global variable.
* @param type $mode
*/
public static function init($mode = '')
{
$mode = strtoupper($mode);
if ($oldDsn = ifdef($mode . '_DSN')) {
// legacy config
preg_match('|([a-z]+)://([^:]*)(:(.*))?@([A-Za-z0-9\.-]*)(/([0-9a-zA-Z_/\.]*))|', $oldDsn, $matches);
if (!defined('DB_TYPE'))
define('DB_TYPE', $matches[1]);
if (!defined('DB_HOST'))
define('DB_HOST', $matches[5]);
if (!defined('DB_DATABASE'))
define('DB_DATABASE', $matches[7]);
$username = ifdef('DB_USERNAME', $matches[2]);
$password = ifdef('DB_PASSWORD', $matches[4]);
} else {
$username = DB_USERNAME;
$password = DB_PASSWORD;
if ($mode) {
if (strlen($x = ifdef(str_replace('DB_', 'DB_' . $mode . '_USERNAME'))))
$username = $x;
if (strlen($y = ifdef(str_replace('DB_', 'DB_' . $mode . '_PASSWORD'))))
$password = $y;
}
}
$port = ifdef('DB_PORT', '');
$type = ifdef('DB_TYPE', 'mysql');
$host = ifdef('DB_HOST', 'localhost');
$dsn = $type . ':host=' . $host . (strlen($port) ? (';port=' . $port) : '') . ';dbname=' . DB_DATABASE . ';charset=utf8';
$GLOBALS['db'] = new JethroDB($dsn, $username, $password);
}



/**
* Construct a JethroDB object
* @param string $dsn PDO dsn
* @param string $username Username
* @param string $password Password
* @param array $options PDO options
*/
public function __construct($dsn, $username, $password, $options = array())
{
if ($options === NULL) {
$options = array();
}
$options[PDO::ATTR_PERSISTENT] = true;
$options[PDO::ATTR_DEFAULT_FETCH_MODE] = PDO::FETCH_ASSOC;
$options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
try {
$result = parent::__construct($dsn, $username, $password, $options);
} catch (PDOException $e) {
trigger_error('Could not connect to database - please check for mistakes in your Database configuration in conf.php, and check in MySQL that the database exists and the specified user has been granted access.', E_USER_ERROR);
exit();
}
return $result;
}

/**
* Quote and escape a value ready for use in SQL
* @param string$string
* @param mixed $paramtype
* @return string
*/
public function quote($string, $paramtype = NULL)
{
if ($string === NULL) {
return 'NULL';
} else {
return parent::quote($string, $paramtype);
}
}

/**
* Quote an identifier (eg table or column name) ready for use in SQL
* @param string $field
* @return string
*/
public function quoteIdentifier($field)
{
$parts = explode('.', $field);
foreach (array_keys($parts) as $k) {
$parts[$k] = "`" . str_replace("`", "``", $parts[$k]) . "`";
}
return implode('.', $parts);
}

/**
* Execute the specified query and fetch the values from the first row
* of the result set into an array
*
* @param string $sql Query to execute
* @return array
*/
public function queryRow($sql)
{
$stmnt = self::prepare($sql);
$stmnt->execute();
$result = $stmnt->fetch();
$stmnt->closeCursor();
return $result;
}

/**
* Execute the specified query and fetch the value from a single column of
* each row of the result set into an array
*
* @param $sql Query to execute
* @param $colnum Column index OR column name to include in the result array
* @return array
*/
public function queryCol($sql, $colnum = 0)
{
$stmnt = self::prepare($sql);
$stmnt->execute();
$result = $stmnt->fetchAll(PDO::FETCH_COLUMN, $colnum);
return $result;
}

/**
* Execute the specified query and
* fetch all the rows of the result set into a two dimensional array
*
* @param string $sql Query to execute
* @param array $types Legacy parameter, not used.
* @param int $fetchmode Legacy parameter, not used.
* @param boolean $rekey Whether to use the first col of the query result as the keys of the result array
* @param boolean $force_array Used only when the query returns exactly two columns.
* If true, the values of the returned array will be one-element arrays instead of scalars.
* @param boolean $group If true, the values of the returned array is wrapped in another array.
* If the same key value (in the first column) repeats itself, the values will be appended to this array instead of overwriting the existing values.
* @return array
*/
public function queryAll($sql, $types = null, $fetchmode = null, $rekey = false, $force_array = false, $group = false)
{
$all = array();
$stmnt = self::prepare($sql);
$stmnt->execute();

if (!$rekey) {
$all = $stmnt->fetchAll();
} else {
$row = $stmnt->fetch();
if ($row === false) {
return $all;
} // return an empty array if there is nothing here
$shift_array = $rekey ? false : null;
if (null !== $shift_array) {
$colnum = count($row);
if ($colnum < 2) {
return new Exception('rekey feature requires at least 2 columns');
}
$shift_array = (!$force_array && $colnum == 2);
}
do {
$key = reset($row);
unset($row[key($row)]);
if ($shift_array) {
$row = array_shift($row);
}
if ($group) {
$all[$key][] = $row;
} else {
$all[$key] = $row;
}
} while (($row = $stmnt->fetch()));
}
return $all;
}

/**
* Execute the specified query,
* fetch the value from the first column of the first row of the result set
* and then frees the result set.
*
* @param string $query SQL query to run
* @param string $type
* @param mixed $colnum
* @return mixed field value
*/
public function queryOne($query, $type = null, $colnum = 0)
{
$result = false;
$stmnt = self::prepare($query);
$stmnt->execute();
$row = $stmnt->fetch(PDO::FETCH_NUM);
if ($row) {
$result = $row[$colnum];
}
$stmnt->closeCursor();
return $result;
}

/**
* Return true if the database has any tables in it
* @return boolean
*/
public function hasTables()
{
$stmnt = self::prepare('SHOW TABLES');
$stmnt->execute();
$result = $stmnt->fetchAll(PDO::FETCH_COLUMN, 0);
return !empty($result);
}

/**
* Return true if the database has the getCurrentUserID function in it
* @return boolean
*/
public function hasFunctions()
{
try {
$result = true;
$stmnt = self::prepare('SHOW CREATE FUNCTION getCurrentUserID');
$stmnt->execute();
$res = $stmnt->fetchAll(PDO::FETCH_COLUMN, 0);
$stmnt->closeCursor();
} catch (PDOException $e) {
$result = false;
}
return $result;
}

/**
* Set the current User ID variable in the DB
* @param int $userid
*/
public function setCurrentUserID($userid)
{
try {
$sql = 'SET @current_user_id = ' . $userid;
$result = parent::query($sql);
} catch (PDOException $e) {
trigger_error('Failed to set user id in database', E_USER_ERROR);
}
}

}
Loading

0 comments on commit 53ace2c

Please sign in to comment.