158 lines
4.4 KiB
PHP
158 lines
4.4 KiB
PHP
<?php
|
|
|
|
|
|
function convertIP($value, $fieldname, $primary_key, $row, $xcrud)
|
|
{
|
|
return long2ip($value);
|
|
}
|
|
|
|
function before_details_callback($row_data, $primary){
|
|
ob_start();
|
|
?>
|
|
<div>
|
|
<label for="searchProperty">Search propetry</label>
|
|
<input type="text" class="xcrud-input form-control" id="searchProperty" placeholder="Enter property to search ex: kick" style="max-width: 300px">
|
|
</div>
|
|
<script>
|
|
|
|
console.log(document.readyState);
|
|
if (document.readyState=='complete') {
|
|
injectJS();
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function(event) {
|
|
injectJS();
|
|
});
|
|
|
|
function injectJS() {
|
|
$.expr[":"].contains = $.expr.createPseudo(function(arg) {
|
|
return function( elem ) {
|
|
return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
|
|
};
|
|
});
|
|
console.log('DOMContentLoaded');
|
|
$(document).on('keyup', '#searchProperty', function() {
|
|
$('div.form-group').show();
|
|
var value = $(this).val();
|
|
if (value) {
|
|
$('div.form-group').hide();
|
|
var temp = `div.form-group:contains(${value})`;
|
|
$(temp).show();
|
|
}
|
|
})
|
|
}
|
|
|
|
</script>
|
|
<?php
|
|
echo ob_get_clean();
|
|
//echo $row_data->get('username'); // like 'postdata'
|
|
}
|
|
|
|
|
|
function publish_action($xcrud)
|
|
{
|
|
if ($xcrud->get('primary'))
|
|
{
|
|
$db = Xcrud_db::get_instance();
|
|
$query = 'UPDATE base_fields SET `bool` = b\'1\' WHERE id = ' . (int)$xcrud->get('primary');
|
|
$db->query($query);
|
|
}
|
|
}
|
|
function unpublish_action($xcrud)
|
|
{
|
|
if ($xcrud->get('primary'))
|
|
{
|
|
$db = Xcrud_db::get_instance();
|
|
$query = 'UPDATE base_fields SET `bool` = b\'0\' WHERE id = ' . (int)$xcrud->get('primary');
|
|
$db->query($query);
|
|
}
|
|
}
|
|
|
|
function exception_example($postdata, $primary, $xcrud)
|
|
{
|
|
$xcrud->set_exception('ban_reason', 'Lol!', 'error');
|
|
$postdata->set('ban_reason', 'lalala');
|
|
}
|
|
|
|
function test_column_callback($value, $fieldname, $primary, $row, $xcrud)
|
|
{
|
|
return $value . ' - nice!';
|
|
}
|
|
|
|
function after_upload_example($field, $file_name, $file_path, $params, $xcrud)
|
|
{
|
|
$ext = trim(strtolower(strrchr($file_name, '.')), '.');
|
|
if ($ext != 'pdf' && $field == 'uploads.simple_upload')
|
|
{
|
|
unlink($file_path);
|
|
$xcrud->set_exception('simple_upload', 'This is not PDF', 'error');
|
|
}
|
|
}
|
|
|
|
function date_example($postdata, $primary, $xcrud)
|
|
{
|
|
$created = $postdata->get('datetime')->as_datetime();
|
|
$postdata->set('datetime', $created);
|
|
}
|
|
|
|
function movetop($xcrud)
|
|
{
|
|
if ($xcrud->get('primary') !== false)
|
|
{
|
|
$primary = (int)$xcrud->get('primary');
|
|
$db = Xcrud_db::get_instance();
|
|
$query = 'SELECT `officeCode` FROM `offices` ORDER BY `ordering`,`officeCode`';
|
|
$db->query($query);
|
|
$result = $db->result();
|
|
$count = count($result);
|
|
|
|
$sort = array();
|
|
foreach ($result as $key => $item)
|
|
{
|
|
if ($item['officeCode'] == $primary && $key != 0)
|
|
{
|
|
array_splice($result, $key - 1, 0, array($item));
|
|
unset($result[$key + 1]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
foreach ($result as $key => $item)
|
|
{
|
|
$query = 'UPDATE `offices` SET `ordering` = ' . $key . ' WHERE officeCode = ' . $item['officeCode'];
|
|
$db->query($query);
|
|
}
|
|
}
|
|
}
|
|
function movebottom($xcrud)
|
|
{
|
|
if ($xcrud->get('primary') !== false)
|
|
{
|
|
$primary = (int)$xcrud->get('primary');
|
|
$db = Xcrud_db::get_instance();
|
|
$query = 'SELECT `officeCode` FROM `offices` ORDER BY `ordering`,`officeCode`';
|
|
$db->query($query);
|
|
$result = $db->result();
|
|
$count = count($result);
|
|
|
|
$sort = array();
|
|
foreach ($result as $key => $item)
|
|
{
|
|
if ($item['officeCode'] == $primary && $key != $count - 1)
|
|
{
|
|
unset($result[$key]);
|
|
array_splice($result, $key + 1, 0, array($item));
|
|
break;
|
|
}
|
|
}
|
|
|
|
foreach ($result as $key => $item)
|
|
{
|
|
$query = 'UPDATE `offices` SET `ordering` = ' . $key . ' WHERE officeCode = ' . $item['officeCode'];
|
|
$db->query($query);
|
|
}
|
|
}
|
|
}
|
|
|
|
|