Fixes in controllers
This commit is contained in:
parent
2226e91faf
commit
ebf029e7dd
4 changed files with 178 additions and 12 deletions
|
|
@ -12,7 +12,7 @@ use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
//include('modules/admin/libraries/tplcontroller.php');
|
//include('modules/admin/libraries/tplcontroller.php');
|
||||||
|
|
||||||
class AppController extends TplController {
|
class AppController extends Admin\TplController\TplController {
|
||||||
|
|
||||||
public function app($op='') {
|
public function app($op='') {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,21 @@ class GenerateAdminClass {
|
||||||
|
|
||||||
public $fields_edit;
|
public $fields_edit;
|
||||||
public $fields_list;
|
public $fields_list;
|
||||||
public $model;
|
public $db;
|
||||||
|
public $table;
|
||||||
public $url;
|
public $url;
|
||||||
public $tpl;
|
public $tpl;
|
||||||
|
public $json=false;
|
||||||
|
|
||||||
public function __construct($model, $fields_edit, $fields_list, $url, $tpl) {
|
public function __construct($db, $table, $fields_edit, $fields_list, $url, $tpl) {
|
||||||
|
|
||||||
$this->model=$model;
|
$this->db=$db;
|
||||||
|
$this->table=$table;
|
||||||
$this->fields_edit=$fields_edit;
|
$this->fields_edit=$fields_edit;
|
||||||
$this->fields_list=$fields_list;
|
$this->fields_list=$fields_list;
|
||||||
$this->url=$url;
|
$this->url=$url;
|
||||||
$this->tpl=$tpl;
|
$this->tpl=$tpl;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show() {
|
public function show() {
|
||||||
|
|
@ -29,7 +31,16 @@ class GenerateAdminClass {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
echo $this->list();
|
$this->json=false;
|
||||||
|
|
||||||
|
return $this->list();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'get_list':
|
||||||
|
|
||||||
|
//$arr_model=$model->select_to_array();
|
||||||
|
return $this->get_list();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -37,9 +48,123 @@ class GenerateAdminClass {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_list() {
|
||||||
|
|
||||||
|
|
||||||
|
$error=1;
|
||||||
|
|
||||||
|
$message='';
|
||||||
|
|
||||||
|
$this->json=true;
|
||||||
|
|
||||||
|
#return {'items': items, 'error': 0, 'total_num_items': total_num_items}
|
||||||
|
$items=[];
|
||||||
|
|
||||||
|
$total_num_items=0;
|
||||||
|
|
||||||
|
$this->db->connect();
|
||||||
|
|
||||||
|
$total_num_items=$this->db->select_count($this->table, '', []);
|
||||||
|
|
||||||
|
//select($table, $fields, $where_sql, $values)
|
||||||
|
/*
|
||||||
|
* begin_page=request.args.get('begin_page', 0)
|
||||||
|
|
||||||
|
try:
|
||||||
|
begin_page=int(begin_page)
|
||||||
|
except:
|
||||||
|
begin_page=0
|
||||||
|
|
||||||
|
num_elements=request.args.get('num_elements', 0)
|
||||||
|
|
||||||
|
try:
|
||||||
|
num_elements=int(num_elements)
|
||||||
|
except:
|
||||||
|
num_elements=20
|
||||||
|
|
||||||
|
order_field=request.args.get('order_field', 'date_reserved')
|
||||||
|
|
||||||
|
if not order_field in reservas.fields:
|
||||||
|
order_field='date_reserved'
|
||||||
|
|
||||||
|
arr_order=['ASC', 'DESC']
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
order=int(request.args.get('order', '0'))
|
||||||
|
|
||||||
|
if order<0 or order>1:
|
||||||
|
order=0
|
||||||
|
|
||||||
|
except:
|
||||||
|
|
||||||
|
order=0*/
|
||||||
|
|
||||||
|
settype($_GET['begin_page'], 'integer');
|
||||||
|
settype($_GET['num_elements'], 'integer');
|
||||||
|
|
||||||
|
$begin_page=$_GET['begin_page'];
|
||||||
|
$num_elements=$_GET['num_elements'];
|
||||||
|
|
||||||
|
if($num_elements<=0) {
|
||||||
|
|
||||||
|
$num_elements=20;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$arr_order=['ASC', 'DESC'];
|
||||||
|
|
||||||
|
settype($_GET['order'], 'integer');
|
||||||
|
|
||||||
|
$order=$_GET['order'];
|
||||||
|
|
||||||
|
$order_field=array_key_first($this->fields_list);
|
||||||
|
|
||||||
|
$get_order_field=trim($_GET['order_field'] ?? '');
|
||||||
|
|
||||||
|
if(in_array($get_order_field, $this->fields_list, true) && $get_order_field!='') {
|
||||||
|
|
||||||
|
$order_field=$get_order_field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$search_values=[$order_field, $arr_order[$order]];
|
||||||
|
|
||||||
|
$sql_search_text='WHERE 1=1';
|
||||||
|
|
||||||
|
settype($_GET['search_all_text'], 'string');
|
||||||
|
|
||||||
|
$search_all_text=trim($_GET['search_all_text']);
|
||||||
|
|
||||||
|
if($search_all_text!='') {
|
||||||
|
|
||||||
|
//$search_all_text='WHERE ';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->select($this->table, array_keys($this->fields_list), $sql_search_text.' order by ? ? limit '.$begin_page.','.$num_elements, $search_values);
|
||||||
|
|
||||||
|
foreach($this->db->get_result() as $v) {
|
||||||
|
|
||||||
|
$items[]=$v;
|
||||||
|
|
||||||
|
$items[count($items)-1]['options']='<a href="">'._('Edit').'</a><br /><a href="">'._('Delete').'</a>';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($items) {
|
||||||
|
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['items' =>$items, 'total_num_items' => $total_num_items, 'error' => $error, 'message' => $message];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function list() {
|
public function list() {
|
||||||
|
|
||||||
echo $this->tpl->load_template('list', []);
|
return $this->tpl->load_template('list', ['fields_list' => $this->fields_list, 'table' => $this->db->tables[$this->table]->name, 'url' => $this->url]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,9 +177,22 @@ class AppController extends Admin\AdminController\AdminController {
|
||||||
|
|
||||||
public function app($op='') {
|
public function app($op='') {
|
||||||
|
|
||||||
$admin=new GenerateAdminClass($this->db->tables['useradmin'], ['username', 'password', 'email', 'double_auth', 'theme'], ['username', 'email'], \PhangoApp\PhaRouter\Url::make_url('admin', 'users'), $this->tpl);
|
$domain_url=\PhangoApp\PhaRouter\Config::$domain_url;
|
||||||
|
|
||||||
echo $this->tpl->load_template('users', ['title' => _('Edit users'), 'path_module' => 'admin.users', 'content' => $admin->show()]);
|
$admin=new GenerateAdminClass($this->db, 'useradmin', ['username', 'password', 'email', 'double_auth', 'theme'], ['username' => _('Username'), 'email' => _('Email')], $domain_url.\PhangoApp\PhaRouter\Url::make_url('admin', 'users'), $this->tpl);
|
||||||
|
|
||||||
|
$admin_html=$admin->show();
|
||||||
|
|
||||||
|
if(!$admin->json) {
|
||||||
|
|
||||||
|
echo $this->tpl->load_template('users', ['title' => _('Edit users'), 'path_module' => 'admin.users', 'content' => $admin_html]);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
echo $this->json($admin_html);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,34 @@
|
||||||
<?=$this->start('footer_js')?>
|
<table id="<?=$table?>_table" class="table_list">
|
||||||
<table>
|
<tr class="title_list"><td><?=_('Username')?></td><td><?=_('Email')?><td><?=('Opciones')?></td></tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
<?=$this->start('footer_js')?>
|
||||||
|
<script src="<?=$this->make_media_url('modules/admin/media/js/jsutils/ajax_list.js')?>"></script>
|
||||||
|
<script src="<?=$this->make_media_url('modules/admin/media/js/jsutils/popup.js', 'lasala')?>"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
options_list={'url': '<?=$url?>/?op=get_list', 'order_fields': [
|
||||||
|
|
||||||
|
<?php
|
||||||
|
foreach($fields_list as $key => $val) {
|
||||||
|
echo "'".$val."',\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
'<?=_('Options')?>'
|
||||||
|
|
||||||
|
], 'num_elements': 20, 'search_all': true};
|
||||||
|
|
||||||
|
fields=[
|
||||||
|
|
||||||
|
<?php
|
||||||
|
foreach($fields_list as $key => $val) {
|
||||||
|
echo "'".$key."',\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
'<?=_('options')?>'
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
<?=$table?>_table=$('#<?=$table?>_table').ajaxListSimple(fields, options_list);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<?=$this->end('footer_js')?>
|
<?=$this->end('footer_js')?>
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ class Config {
|
||||||
|
|
||||||
static public $base_url='';
|
static public $base_url='';
|
||||||
|
|
||||||
|
static public $domain_url='http://localhost';
|
||||||
|
|
||||||
static public $data=[];
|
static public $data=[];
|
||||||
|
|
||||||
static public $index_file='index.php/';
|
static public $index_file='index.php/';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue