Skip to content

Commit

Permalink
Upgraded to AppGini 24.15
Browse files Browse the repository at this point in the history
  • Loading branch information
bigprof committed Jul 4, 2024
1 parent c97b4a4 commit 8305845
Show file tree
Hide file tree
Showing 26 changed files with 1,057 additions and 934 deletions.
287 changes: 160 additions & 127 deletions app/admin/incFunctions.php

Large diffs are not rendered by default.

56 changes: 45 additions & 11 deletions app/admin/pageRebuildFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
$schema: [ tablename => [ fieldname => [ appgini => '...', 'db' => '...'], ... ], ... ]
*/

/* application schema as created in AppGini */
$schema = get_table_fields();
/* application schema as created in AppGini, including internal tables */
$schema = get_table_fields(null, true);

$table_captions = getTableList();
/* list of all tables in the database, including internal tables */
$table_captions = getTableList(true, true);

/* function for preparing field definition for comparison */
function prepare_def($def) {
Expand Down Expand Up @@ -46,6 +47,9 @@ function prepare_def($def) {
/* ignore zero-padding for date data types */
$def = preg_replace("/date\s*default\s*'([0-9]{4})-0?([1-9])-0?([1-9])'/i", "date default '$1-$2-$3'", $def);

/* if default is CURRENT_TIMESTAMP, remove single quotes */
$def = preg_replace("/default\s*'CURRENT_TIMESTAMP'/i", "default current_timestamp", $def);

return trim($def);
}

Expand Down Expand Up @@ -248,7 +252,7 @@ function fix_field($fix_table, $fix_field, $schema, &$qry) {
</script>

<table class="table table-responsive table-hover table-striped">
<thead><tr>
<thead><tr class="active">
<th></th>
<th><?php echo $Translation['field'] ; ?></th>
<th><?php echo $Translation['AppGini definition'] ; ?></th>
Expand All @@ -258,18 +262,37 @@ function fix_field($fix_table, $fix_field, $schema, &$qry) {

<tbody>
<?php foreach($schema as $tn => $fields) { ?>
<tr class="text-info"><td colspan="5">
<h4 data-placement="auto top" data-toggle="tooltip" title="<?php echo str_replace ( "<TABLENAME>" , $tn , $Translation['table name title']) ; ?>"><img src="../<?php echo $table_captions[$tn][2]; ?>"> <?php echo $table_captions[$tn][0]; ?></h4>
<tr class="info"><th colspan="5">
<h4>
<img src="../<?php echo $table_captions[$tn][2]; ?>" class="hspacer-md">
<span data-placement="auto top" data-toggle="tooltip" title="<?php echo html_attr(str_replace( "<TABLENAME>", $tn, $Translation['table name title'])); ?>">
<?php echo $table_captions[$tn][0]; ?>
</span>

<!-- single button dropdown -->
<div class="btn-group pull-right always_shown">
<button type="button" class="btn btn-default btn-xs dropdown-toggle hspacer-lg" data-toggle="dropdown" title="SQL">
<i class="glyphicon glyphicon-info-sign"></i> <span class="caret"></span>
</button>
<ul class="dropdown-menu sql-display">
<li><?php echo createTableIfNotExists($tn, true); ?></li>
</ul>
</div>
</h4>

<?php if(mysql_charset == 'utf8mb4' && $tableCharset[$tn] != 'utf8mb4') { ?>
<span class="label label-danger"><?php echo $Translation['unicode error']; ?></span>
<?php } ?>
</td></tr>
</th></tr>
<?php foreach($fields as $fn => $fd) { ?>
<?php $diff = ((prepare_def($fd['appgini']) == prepare_def($fd['db'])) ? false : true); ?>
<?php $no_db = ($fd['db'] ? false : true); ?>
<tr class="<?php echo ($diff ? 'warning' : 'field_ok'); ?>">
<td><i class="glyphicon glyphicon-<?php echo ($diff ? 'remove text-danger' : 'ok text-success'); ?>"></i></td>
<td><?php echo $fn; ?></td>
<td></td>
<td>
<i class="hspacer-md glyphicon glyphicon-<?php echo ($diff ? 'remove text-danger' : 'ok text-success'); ?>"></i>
<?php echo $fn; ?>
</td>
<td class="<?php echo ($diff ? 'bold text-success' : ''); ?>"><samp><?php echo $fd['appgini']; ?></samp></td>
<td class="<?php echo ($diff ? 'bold text-danger' : ''); ?>"><?php echo thisOr("<samp>{$fd['db']}</samp>", $Translation['does not exist']); ?></td>
<td>
Expand All @@ -288,8 +311,19 @@ function fix_field($fix_table, $fix_field, $schema, &$qry) {
<div class="alert summary"></div>

<style>
.bold{ font-weight: bold; }
[data-toggle="tooltip"]{ display: inline-block !important; }
.bold { font-weight: bold; }
[data-toggle="tooltip"] { display: inline-block !important; }
.sql-display {
max-width: 600px;
min-width: 40vw;
padding: 2em;
}
.sql-display li {
white-space: pre;
font-family: monospace;
overflow: auto;
line-height: 1.5;
}
</style>

<script>
Expand Down
4 changes: 2 additions & 2 deletions app/admin/pageServerStatus.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
$appgini_version = '24.14.1665';
$generated_ts = '04/06/2024 18:41:56';
$appgini_version = '24.15.1697';
$generated_ts = '04/07/2024 16:23:15';

require(__DIR__ . '/incCommon.php');

Expand Down
86 changes: 44 additions & 42 deletions app/applicants_and_tenants_dml.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,31 +271,40 @@ function applicants_and_tenants_update(&$selected_id, &$error_message = '') {
set_record_owner('applicants_and_tenants', $selected_id);
}

function applicants_and_tenants_form($selected_id = '', $AllowUpdate = 1, $AllowInsert = 1, $AllowDelete = 1, $separateDV = 0, $TemplateDV = '', $TemplateDVP = '') {
function applicants_and_tenants_form($selectedId = '', $allowUpdate = true, $allowInsert = true, $allowDelete = true, $separateDV = true, $templateDV = '', $templateDVP = '') {
// function to return an editable form for a table records
// and fill it with data of record whose ID is $selected_id. If $selected_id
// and fill it with data of record whose ID is $selectedId. If $selectedId
// is empty, an empty form is shown, with only an 'Add New'
// button displayed.

global $Translation;
$eo = ['silentErrors' => true];
$noUploads = null;
$row = $urow = $jsReadOnly = $jsEditable = $lookups = null;

$noUploads = $row = $urow = $jsReadOnly = $jsEditable = $lookups = null;
$noSaveAsCopy = false;
$hasSelectedId = strlen($selectedId) > 0;

// mm: get table permissions
$arrPerm = getTablePermissions('applicants_and_tenants');
if(!$arrPerm['insert'] && $selected_id == '')
$allowInsert = ($arrPerm['insert'] ? true : false);
$allowUpdate = $hasSelectedId && check_record_permission('applicants_and_tenants', $selectedId, 'edit');
$allowDelete = $hasSelectedId && check_record_permission('applicants_and_tenants', $selectedId, 'delete');

if(!$allowInsert && !$hasSelectedId)
// no insert permission and no record selected
// so show access denied error unless TVDV
// so show access denied error -- except if TVDV: just hide DV
return $separateDV ? $Translation['tableAccessDenied'] : '';
$AllowInsert = ($arrPerm['insert'] ? true : false);

if($hasSelectedId && !check_record_permission('applicants_and_tenants', $selectedId, 'view'))
return $Translation['tableAccessDenied'];

// print preview?
$dvprint = false;
if(strlen($selected_id) && Request::val('dvprint_x') != '') {
$dvprint = true;
}
$dvprint = $hasSelectedId && Request::val('dvprint_x') != '';

$showSaveNew = !$dvprint && ($allowInsert && !$hasSelectedId);
$showSaveChanges = !$dvprint && $allowUpdate && $hasSelectedId;
$showDelete = !$dvprint && $allowDelete && $hasSelectedId;
$showSaveAsCopy = !$dvprint && ($allowInsert && $hasSelectedId && !$noSaveAsCopy);
$fieldsAreEditable = !$dvprint && (($allowInsert && !$hasSelectedId) || ($allowUpdate && $hasSelectedId) || $showSaveAsCopy);


// populate filterers, starting from children to grand-parents
Expand Down Expand Up @@ -342,17 +351,8 @@ function applicants_and_tenants_form($selected_id = '', $AllowUpdate = 1, $Allow
$combo_status->SelectName = 'status';
$combo_status->AllowNull = false;

if($selected_id) {
if(!check_record_permission('applicants_and_tenants', $selected_id, 'view'))
return $Translation['tableAccessDenied'];

// can edit?
$AllowUpdate = check_record_permission('applicants_and_tenants', $selected_id, 'edit');

// can delete?
$AllowDelete = check_record_permission('applicants_and_tenants', $selected_id, 'delete');

$res = sql("SELECT * FROM `applicants_and_tenants` WHERE `id`='" . makeSafe($selected_id) . "'", $eo);
if($hasSelectedId) {
$res = sql("SELECT * FROM `applicants_and_tenants` WHERE `id`='" . makeSafe($selectedId) . "'", $eo);
if(!($row = db_fetch_array($res))) {
return error_message($Translation['No records found'], 'applicants_and_tenants_view.php', false);
}
Expand All @@ -375,10 +375,10 @@ function applicants_and_tenants_form($selected_id = '', $AllowUpdate = 1, $Allow

// open the detail view template
if($dvprint) {
$template_file = is_file("./{$TemplateDVP}") ? "./{$TemplateDVP}" : './templates/applicants_and_tenants_templateDVP.html';
$template_file = is_file("./{$templateDVP}") ? "./{$templateDVP}" : './templates/applicants_and_tenants_templateDVP.html';
$templateCode = @file_get_contents($template_file);
} else {
$template_file = is_file("./{$TemplateDV}") ? "./{$TemplateDV}" : './templates/applicants_and_tenants_templateDV.html';
$template_file = is_file("./{$templateDV}") ? "./{$templateDV}" : './templates/applicants_and_tenants_templateDV.html';
$templateCode = @file_get_contents($template_file);
}

Expand All @@ -387,8 +387,9 @@ function applicants_and_tenants_form($selected_id = '', $AllowUpdate = 1, $Allow
$templateCode = str_replace('<%%RND1%%>', $rnd1, $templateCode);
$templateCode = str_replace('<%%EMBEDDED%%>', (Request::val('Embedded') ? 'Embedded=1' : ''), $templateCode);
// process buttons
if($AllowInsert) {
if(!$selected_id) $templateCode = str_replace('<%%INSERT_BUTTON%%>', '<button type="submit" class="btn btn-success" id="insert" name="insert_x" value="1" onclick="return applicants_and_tenants_validateData();"><i class="glyphicon glyphicon-plus-sign"></i> ' . $Translation['Save New'] . '</button>', $templateCode);
if($showSaveNew) {
$templateCode = str_replace('<%%INSERT_BUTTON%%>', '<button type="submit" class="btn btn-success" id="insert" name="insert_x" value="1" onclick="return applicants_and_tenants_validateData();"><i class="glyphicon glyphicon-plus-sign"></i> ' . $Translation['Save New'] . '</button>', $templateCode);
} elseif($showSaveAsCopy) {
$templateCode = str_replace('<%%INSERT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="insert" name="insert_x" value="1" onclick="return applicants_and_tenants_validateData();"><i class="glyphicon glyphicon-plus-sign"></i> ' . $Translation['Save As Copy'] . '</button>', $templateCode);
} else {
$templateCode = str_replace('<%%INSERT_BUTTON%%>', '', $templateCode);
Expand All @@ -401,14 +402,14 @@ function applicants_and_tenants_form($selected_id = '', $AllowUpdate = 1, $Allow
$backAction = '$j(\'form\').eq(0).attr(\'novalidate\', \'novalidate\'); document.myform.reset(); return true;';
}

if($selected_id) {
if($hasSelectedId) {
if(!Request::val('Embedded')) $templateCode = str_replace('<%%DVPRINT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="dvprint" name="dvprint_x" value="1" onclick="$j(\'form\').eq(0).prop(\'novalidate\', true); document.myform.reset(); return true;" title="' . html_attr($Translation['Print Preview']) . '"><i class="glyphicon glyphicon-print"></i> ' . $Translation['Print Preview'] . '</button>', $templateCode);
if($AllowUpdate)
if($allowUpdate)
$templateCode = str_replace('<%%UPDATE_BUTTON%%>', '<button type="submit" class="btn btn-success btn-lg" id="update" name="update_x" value="1" onclick="return applicants_and_tenants_validateData();" title="' . html_attr($Translation['Save Changes']) . '"><i class="glyphicon glyphicon-ok"></i> ' . $Translation['Save Changes'] . '</button>', $templateCode);
else
$templateCode = str_replace('<%%UPDATE_BUTTON%%>', '', $templateCode);

if($AllowDelete)
if($allowDelete)
$templateCode = str_replace('<%%DELETE_BUTTON%%>', '<button type="submit" class="btn btn-danger" id="delete" name="delete_x" value="1" title="' . html_attr($Translation['Delete']) . '"><i class="glyphicon glyphicon-trash"></i> ' . $Translation['Delete'] . '</button>', $templateCode);
else
$templateCode = str_replace('<%%DELETE_BUTTON%%>', '', $templateCode);
Expand All @@ -421,8 +422,8 @@ function applicants_and_tenants_form($selected_id = '', $AllowUpdate = 1, $Allow
// if not in embedded mode and user has insert only but no view/update/delete,
// remove 'back' button
if(
$arrPerm['insert']
&& !$arrPerm['update'] && !$arrPerm['delete'] && !$arrPerm['view']
$allowInsert
&& !$allowUpdate && !$allowDelete && !$arrPerm['view']
&& !Request::val('Embedded')
)
$templateCode = str_replace('<%%DESELECT_BUTTON%%>', '', $templateCode);
Expand All @@ -447,7 +448,7 @@ class="btn btn-default"
}

// set records to read only if user can't insert new records and can't edit current record
if(($selected_id && !$AllowUpdate && !$AllowInsert) || (!$selected_id && !$AllowInsert)) {
if(!$fieldsAreEditable) {
$jsReadOnly = '';
$jsReadOnly .= "\tjQuery('#last_name').replaceWith('<div class=\"form-control-static\" id=\"last_name\">' + (jQuery('#last_name').val() || '') + '</div>');\n";
$jsReadOnly .= "\tjQuery('#first_name').replaceWith('<div class=\"form-control-static\" id=\"first_name\">' + (jQuery('#first_name').val() || '') + '</div>');\n";
Expand All @@ -464,15 +465,16 @@ class="btn btn-default"
$jsReadOnly .= "\tjQuery('.select2-container').hide();\n";

$noUploads = true;
} elseif($AllowInsert) {
$jsEditable = "\tjQuery('form').eq(0).data('already_changed', true);"; // temporarily disable form change handler
} else {
// temporarily disable form change handler till time and datetime pickers are enabled
$jsEditable = "\tjQuery('form').eq(0).data('already_changed', true);";
$jsEditable .= "\tjQuery('form').eq(0).data('already_changed', false);"; // re-enable form change handler
}

// process combos
$templateCode = str_replace(
'<%%COMBO(birth_date)%%>',
($selected_id && !$arrPerm['edit'] && ($noSaveAsCopy || !$arrPerm['insert']) ?
(!$fieldsAreEditable ?
'<div class="form-control-static">' . $combo_birth_date->GetHTML(true) . '</div>' :
$combo_birth_date->GetHTML()
), $templateCode);
Expand Down Expand Up @@ -515,7 +517,7 @@ class="btn btn-default"
$templateCode = str_replace('<%%UPLOADFILE(notes)%%>', '', $templateCode);

// process values
if($selected_id) {
if($hasSelectedId) {
if( $dvprint) $templateCode = str_replace('<%%VALUE(id)%%>', safe_html($urow['id']), $templateCode);
if(!$dvprint) $templateCode = str_replace('<%%VALUE(id)%%>', html_attr($row['id']), $templateCode);
$templateCode = str_replace('<%%URLVALUE(id)%%>', urlencode($urow['id']), $templateCode);
Expand Down Expand Up @@ -554,7 +556,7 @@ class="btn btn-default"
if( $dvprint) $templateCode = str_replace('<%%VALUE(status)%%>', safe_html($urow['status']), $templateCode);
if(!$dvprint) $templateCode = str_replace('<%%VALUE(status)%%>', html_attr($row['status']), $templateCode);
$templateCode = str_replace('<%%URLVALUE(status)%%>', urlencode($urow['status']), $templateCode);
if($AllowUpdate || $AllowInsert) {
if($fieldsAreEditable) {
$templateCode = str_replace('<%%HTMLAREA(notes)%%>', '<textarea name="notes" id="notes" rows="5">' . safe_html(htmlspecialchars_decode($row['notes'])) . '</textarea>', $templateCode);
} else {
$templateCode = str_replace('<%%HTMLAREA(notes)%%>', '<div id="notes" class="form-control-static">' . $row['notes'] . '</div>', $templateCode);
Expand Down Expand Up @@ -610,7 +612,7 @@ class="btn btn-default"
$templateCode .= $jsReadOnly;
$templateCode .= $jsEditable;

if(!$selected_id) {
if(!$hasSelectedId) {
$templateCode.="\n\tif(document.getElementById('emailEdit')) { document.getElementById('emailEdit').style.display='inline'; }";
$templateCode.="\n\tif(document.getElementById('emailEditLink')) { document.getElementById('emailEditLink').style.display='none'; }";
}
Expand Down Expand Up @@ -640,8 +642,8 @@ class="btn btn-default"

/* default field values */
$rdata = $jdata = get_defaults('applicants_and_tenants');
if($selected_id) {
$jdata = get_joined_record('applicants_and_tenants', $selected_id);
if($hasSelectedId) {
$jdata = get_joined_record('applicants_and_tenants', $selectedId);
if($jdata === false) $jdata = get_defaults('applicants_and_tenants');
$rdata = $row;
}
Expand All @@ -650,7 +652,7 @@ class="btn btn-default"
// hook: applicants_and_tenants_dv
if(function_exists('applicants_and_tenants_dv')) {
$args = [];
applicants_and_tenants_dv(($selected_id ? $selected_id : FALSE), getMemberInfo(), $templateCode, $args);
applicants_and_tenants_dv(($hasSelectedId ? $selectedId : FALSE), getMemberInfo(), $templateCode, $args);
}

return $templateCode;
Expand Down
Loading

0 comments on commit 8305845

Please sign in to comment.