diff --git a/modules/admin/controllers/app.php b/modules/admin/controllers/app.php
index 3c5d8a5..26cd45f 100644
--- a/modules/admin/controllers/app.php
+++ b/modules/admin/controllers/app.php
@@ -12,7 +12,7 @@ use PHPMailer\PHPMailer\Exception;
//include('modules/admin/libraries/tplcontroller.php');
-class AppController extends TplController {
+class AppController extends Admin\TplController\TplController {
public function app($op='') {
diff --git a/modules/admin/controllers/users.php b/modules/admin/controllers/users.php
index 86152d3..9de3f8b 100644
--- a/modules/admin/controllers/users.php
+++ b/modules/admin/controllers/users.php
@@ -6,19 +6,21 @@ class GenerateAdminClass {
public $fields_edit;
public $fields_list;
- public $model;
+ public $db;
+ public $table;
public $url;
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_list=$fields_list;
$this->url=$url;
$this->tpl=$tpl;
-
}
public function show() {
@@ -29,7 +31,16 @@ class GenerateAdminClass {
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;
@@ -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']=''._('Edit').'
'._('Delete').'';
+
+ }
+
+ if($items) {
+
+ $error=0;
+
+ }
+
+ return ['items' =>$items, 'total_num_items' => $total_num_items, 'error' => $error, 'message' => $message];
+
+ }
+
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='') {
- $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);
+
+ }
}
diff --git a/modules/admin/templates/list.php b/modules/admin/templates/list.php
index c845a4e..7eb16ec 100644
--- a/modules/admin/templates/list.php
+++ b/modules/admin/templates/list.php
@@ -1,8 +1,34 @@
-=$this->start('footer_js')?>
-
| =_('Username')?> | =_('Email')?> | =('Opciones')?> |