Viewing file: functions.php (7 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
function get_pages(){
foreach (new DirectoryIterator(__DIR__) as $file) {
if ($file->isFile()) {
print $file->getFilename() . "\n";
}
}
}
function bulk_delete($xcrud)
{
//print_r($xcrud.selected);
$selected = $xcrud->get('selected');
$table = $xcrud->get('table');
$identifier = $xcrud->get('identifier');
$cnt = count($selected);
$insertString = "";
$count = 0;
foreach($selected as $value){
$count++;
if($count == 1){
$insertString .= $value;
}else{
$insertString .= "," . $value;
}
}
$db = Xcrud_db::get_instance();
$query = "DELETE from $table WHERE $identifier IN ($insertString)" ;
//echo $query;
$db->query($query);
$xcrud->set_exception('Bulk Delete', 'You have Deleted ' . $cnt . ' items', 'error');
//$xcrud->set_exception('You have deleted ' . $cnt . ' items', 'error');
}
function exception_example($postdata, $primary, $xcrud)
{
// get random field from $postdata
$postdata_prepared = array_keys($postdata->to_array());
shuffle($postdata_prepared);
$random_field = array_shift($postdata_prepared);
// set error message
$xcrud->set_exception($random_field, 'This is a test error', 'error');
}
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 show_description($value, $fieldname, $primary_key, $row, $xcrud)
{
$result = '';
if ($value == '1')
{
$result = '<i class="fa fa-check" />' . 'OK';
}
elseif ($value == '2')
{
$result = '<i class="fa fa-circle-o" />' . 'Pending';
}
return $result;
}
function custom_field($value, $fieldname, $primary_key, $row, $xcrud)
{
return '<input type="text" readonly class="xcrud-input" name="' . $xcrud->fieldname_encode($fieldname) . '" value="' . $value .
'" />';
}
function unset_val($postdata)
{
$postdata->del('Paid');
}
function format_phone($new_phone)
{
$new_phone = preg_replace("/[^0-9]/", "", $new_phone);
if (strlen($new_phone) == 7)
return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $new_phone);
elseif (strlen($new_phone) == 10)
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $new_phone);
else
return $new_phone;
}
function before_list_example($list, $xcrud)
{
var_dump($list);
}
function after_update_test($pd, $pm, $xc)
{
$xc->search = 0;
}
/*function after_upload_test($field, &$filename, $file_path, $upload_config, $this)
{
$filename = 'bla-bla-bla';
}*/
function movetop($xcrud)
{
if ($xcrud->get('primary') !== false)
{
$primary = (int)$xcrud->get('primary');
$table = $xcrud->get('table');
$db = Xcrud_db::get_instance();
$query = 'SELECT `id` FROM '.$table.' ORDER BY `ordinamento`,`id`';
$db->query($query);
$result = $db->result();
$count = count($result);
$sort = array();
foreach ($result as $key => $item)
{
if ($item['id'] == $primary && $key != 0)
{
array_splice($result, $key - 1, 0, array($item));
unset($result[$key + 1]);
break;
}
}
foreach ($result as $key => $item)
{
$query = 'UPDATE '.$table.' SET `ordinamento` = ' . $key . ' WHERE id = ' . $item['id'];
$db->query($query);
}
}
}
function movebottom($xcrud)
{
if ($xcrud->get('primary') !== false)
{
$primary = (int)$xcrud->get('primary');
$table = $xcrud->get('table');
$db = Xcrud_db::get_instance();
$query = 'SELECT `id` FROM `'.$table.'` ORDER BY `ordinamento`,`id`';
$db->query($query);
$result = $db->result();
$count = count($result);
$sort = array();
foreach ($result as $key => $item)
{
if ($item['id'] == $primary && $key != $count - 1)
{
unset($result[$key]);
array_splice($result, $key + 1, 0, array($item));
break;
}
}
foreach ($result as $key => $item)
{
$query = 'UPDATE `'.$table.'` SET `ordinamento` = ' . $key . ' WHERE id = ' . $item['id'];
$db->query($query);
}
}
}
function movetop2($xcrud)
{
if ($xcrud->get('primary') !== false)
{
$primary = (int)$xcrud->get('primary');
$db = Xcrud_db::get_instance();
$query = 'SELECT `id` FROM `categorie` ORDER BY `posizione`,`id`';
$db->query($query);
$result = $db->result();
$count = count($result);
$sort = array();
foreach ($result as $key => $item)
{
if ($item['id'] == $primary && $key != 0)
{
array_splice($result, $key - 1, 0, array($item));
unset($result[$key + 1]);
break;
}
}
foreach ($result as $key => $item)
{
$query = 'UPDATE `categorie` SET `posizione` = ' . $key . ' WHERE id = ' . $item['id'];
$db->query($query);
}
}
}
function movebottom2($xcrud)
{
if ($xcrud->get('primary') !== false)
{
$primary = (int)$xcrud->get('primary');
$db = Xcrud_db::get_instance();
$query = 'SELECT `id` FROM `categorie` ORDER BY `posizione`,`id`';
$db->query($query);
$result = $db->result();
$count = count($result);
$sort = array();
foreach ($result as $key => $item)
{
if ($item['id'] == $primary && $key != $count - 1)
{
unset($result[$key]);
array_splice($result, $key + 1, 0, array($item));
break;
}
}
foreach ($result as $key => $item)
{
$query = 'UPDATE `categorie` SET `posizione` = ' . $key . ' WHERE id = ' . $item['id'];
$db->query($query);
}
}
}
function publish_action($xcrud)
{
$table = $xcrud->get('table');
if ($xcrud->get('primary'))
{
$db = Xcrud_db::get_instance();
$query = 'UPDATE '.$table.' SET `pubblicato` = b\'1\' WHERE id = ' . (int)$xcrud->get('primary');
$db->query($query);
}
}
function unpublish_action($xcrud)
{
$table = $xcrud->get('table');
if ($xcrud->get('primary'))
{
$db = Xcrud_db::get_instance();
$query = 'UPDATE '.$table.' SET `pubblicato` = b\'0\' WHERE id = ' . (int)$xcrud->get('primary');
$db->query($query);
}
}
|