public function view_child() { $mytable = $this->cpModule('table'); $mychild = $this->child(); // $this->global->js = array($this->url->myStatic.'js/cp/medium-editor.min.js'); $this->data->enum = \lib\sql\getTable::enumValues('posts'); switch ($mytable) { case 'posts': // show list of tags $this->data->tagList = $this->model()->sp_term_list(); // for each type of post switch ($this->cpModule('raw')) { case 'pages': $this->data->parentList = $this->model()->sp_parent_list(); break; case 'polls': $this->data->parentList = $this->model()->sp_parent_list(true, 'poll'); $this->data->catList = $this->model()->sp_cats('cat_poll'); break; case 'attachments': $this->data->maxSize = \lib\utility\upload::max_file_upload_in_bytes(); // $this->include->uploader = true; // array_push($this->global->js, $this->url->myStatic.'js/cp/uploader.js'); $this->data->catList = $this->model()->sp_cats('filecat'); $this->data->catListSelected = $this->model()->sp_cats('filecat', true); break; case 'books': $this->data->catList = $this->model()->sp_cats('bookcat'); $this->data->catListSelected = $this->model()->sp_cats('bookcat', true); $this->data->parentList = $this->model()->sp_parent_list(true, 'book'); break; case 'socialnetwork': $this->data->catList = null; break; default: $this->data->catList = $this->model()->sp_cats(); break; } break; default: switch ($this->cpModule('raw')) { case 'categories': case 'pollcategories': case 'filecategories': case 'bookcategories': $this->data->parentList = $this->model()->sp_category_list($this->cpModule('type')); break; } $this->data->field_list = \lib\sql\getTable::get($mytable); $myform = $this->createform('@' . db_name . '.' . $mytable, $this->data->child); break; } // if module for users then fill permission list if ($this->cpModule('raw') === 'users') { $this->draw_users(); } if ($mychild === 'edit') { $this->data->datarow = $this->model()->datarow($mytable, null, true); // set shortURL $this->data->shortURL = 'sp_' . \lib\utility\shortURL::encode($this->data->datarow['id']); if (isset($this->data->datarow['post_meta'])) { $this->data->datarow['post_meta'] = json_decode($this->data->datarow['post_meta'], true); } if ($this->cpModule('raw') === 'attachments') { if (isset($this->data->datarow['meta']['slug'])) { $this->data->datarow['post_slug'] = $this->data->datarow['meta']['slug']; } } if ($mytable === 'posts') { // $this->data->datarow['post_content'] .= '<img src="/static/images/logo.png" />'; // var_dump($this->data->datarow['post_content']); $url = $this->data->datarow['post_url']; $this->data->datarow['cat_url'] = substr($url, 0, strrpos($url, '/')); // if defaultlang and lang of the post is not the same then add lang to url $defaultLang = substr(\lib\utility\option::get('config', 'meta', 'defaultLang'), 0, 2); if ($defaultLang !== $this->data->datarow['post_language']) { $this->data->datarow['post_url'] = $this->data->datarow['post_language'] . "/" . $this->data->datarow['post_url']; } } } }
public function view_child() { $mytable = $this->cpModule('table'); $mychild = $this->child(); // $this->global->js = array($this->url->myStatic.'js/cp/medium-editor.min.js'); $this->data->enum = \lib\sql\getTable::enumValues('posts'); switch ($mytable) { case 'posts': // show list of tags $this->data->tagList = $this->model()->sp_term_list(); // for each type of post switch ($this->cpModule('raw')) { case 'pages': $this->data->parentList = $this->model()->sp_parent_list(); break; case 'attachments': $this->data->maxSize = \lib\utility\Upload::max_file_upload_in_bytes(); // $this->include->uploader = true; // array_push($this->global->js, $this->url->myStatic.'js/cp/uploader.js'); $this->data->catList = $this->model()->sp_cats('filecat'); $this->data->catListSelected = $this->model()->sp_cats('filecat', true); break; case 'books': $this->data->catList = $this->model()->sp_cats('bookcat'); $this->data->catListSelected = $this->model()->sp_cats('bookcat', true); $this->data->parentList = $this->model()->sp_parent_list(true, 'book'); break; case 'socialnetwork': $this->data->catList = null; break; default: $this->data->catList = $this->model()->sp_cats(); break; } break; default: switch ($this->cpModule('raw')) { case 'categories': case 'filecategories': case 'bookcategories': $this->data->parentList = $this->model()->sp_category_list($this->cpModule('type')); break; } $this->data->field_list = \lib\sql\getTable::get($mytable); $myform = $this->createform('@' . db_name . '.' . $mytable, $this->data->child); break; } // if module for users then fill permission list if ($this->cpModule('raw') === 'users') { $myPermList = $this->data->form->users->user_permission; $myPermList->type('select'); // get list of permissions foreach ($this->model()->permList() as $value) { $myPermList->child()->value($value)->label(T_($value)); } } if ($mychild === 'edit') { $this->data->datarow = $this->model()->datarow($mytable, null, true); if (isset($this->data->datarow['post_meta'])) { $this->data->datarow['meta'] = json_decode($this->data->datarow['post_meta'], true); } // var_dump($this->data->datarow['meta']); if ($this->cpModule('raw') === 'attachments') { if (isset($this->data->datarow['meta']['slug'])) { $this->data->datarow['post_slug'] = $this->data->datarow['meta']['slug']; } } if ($mytable === 'posts') { // $this->data->datarow['post_content'] .= '<img src="/static/images/logo.png" />'; // var_dump($this->data->datarow['post_content']); $url = $this->data->datarow['post_url']; $this->data->datarow['cat_url'] = substr($url, 0, strrpos($url, '/')); } } }
public function create_query($_type = null, $_id = null) { $qry_module = $this->module(SubDomain); $qry_table = 'table' . ucfirst($qry_module); $qry = $this->sql()->{$qry_table}(); // in update type save record data and check if change set this else don't need to set if ($_type == 'update') { $mydatarow = $this->datarow($qry_module, $_id); $not_change = true; } // get all fields of table and filter fields name for show in datatable // access from columns variable // check if datatable exist then get this data $incomplete_fields = []; $fields = \lib\sql\getTable::get($qry_module); // var_dump(utility::post()); // var_dump($qry_module); foreach ($fields as $key => $value) { // if this field can exist in query string if ($value['query']) { $tmp_setfield = 'set' . ucfirst($key); $tmp_value = utility::post($value['value']); if ($value['value'] === 'pass') { $tmp_value = utility::post('pass', 'hash'); } $tmp_value = trim($tmp_value); // if user fill box and post data for this field add to query string if ($tmp_value || $tmp_value === '0') { // in update type check for change or not if ($_type == 'update') { // if change add to query string and set it if ($mydatarow[$key] != $tmp_value) { $qry = $qry->{$tmp_setfield}($tmp_value); $not_change = false; } } else { $qry = $qry->{$tmp_setfield}($tmp_value); } } elseif ($key == 'user_id') { $qry = $qry->{$tmp_setfield}($this->login('id')); } elseif (!$value['null']) { // $incomplete_fields[$key] = $value['value']; array_push($incomplete_fields, $value['value']); } } } // on cp depending on module add some variable to query if (SubDomain === 'cp') { switch ($this->module()) { case 'tags': if (count($incomplete_fields) === 3) { $qry_module = 'terms'; $incomplete_fields = null; $term_url = utility::post('slug'); $qry = $qry->setTerm_type('tag')->setTerm_url($term_url); } break; case 'categories': if (count($incomplete_fields) === 3) { $qry_module = 'terms'; $incomplete_fields = null; $term_url = utility::post('slug'); $qry = $qry->setTerm_type('cat')->setTerm_url($term_url); } break; case 'pages': $qry = $qry->setPost_type('page'); $qry_module = 'posts'; break; case 'users': if ($_type == 'insert') { // remove createdate from incomplete and fill it with current datetime if (($key = array_search('createdate', $incomplete_fields)) !== false) { unset($incomplete_fields[$key]); } $qry = $qry->set('user_createdate', date('Y-m-d H:i:s')); } else { $incomplete_fields = null; } // add meta to save position of users and new properties $meta = ['position' => utility::post('position')]; if ($meta) { $not_change = false; } $meta = json_encode($meta, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE); $qry = $qry->set('user_meta', $meta); break; } } if ($incomplete_fields) { debug::error(T_("all require fields must fill"), json_encode($incomplete_fields)); // return false; } if ($_type == 'update' && $not_change) { debug::warn(T_("some fields must be change for update!")); return false; } // var_dump($qry);exit(); return $qry; }
public function datatable($_table = null, $_condition = null, $_rename = false) { $param_search = \lib\utility::get('search'); $cpModule = $this->cpModule(); $mytype = null; // set columns // get all fields of table and filter fields name for show in datatable, access from columns variable switch ($cpModule['raw']) { case 'categories': case 'filecategories': case 'bookcategories': case 'tags': $tmp_columns = \lib\sql\getTable::get('terms'); unset($tmp_columns['term_type']); unset($tmp_columns['term_slug']); break; case 'posts': case 'pages': case 'books': case 'twitter': case 'facebook': case 'telegram': $tmp_columns = \lib\sql\getTable::get('posts'); $tmp_columns['post_publishdate']['table'] = true; unset($tmp_columns['post_type']); unset($tmp_columns['post_slug']); unset($tmp_columns['user_id']); break; case 'attachments': $tmp_columns = \lib\sql\getTable::get('posts'); $tmp_columns['post_meta']['table'] = true; unset($tmp_columns['post_type']); unset($tmp_columns['post_slug']); unset($tmp_columns['post_status']); unset($tmp_columns['user_id']); // add type column $tmp_columns['post_meta']['label'] = T_('type'); $tmp_columns['post_meta']['value'] = 'filetype'; break; case 'users': $tmp_columns = \lib\sql\getTable::get('users'); unset($tmp_columns['user_pass']); $tmp_columns['user_email']['table'] = true; $tmp_columns['user_displayname']['table'] = true; $tmp_columns['user_status']['table'] = true; break; default: $tmp_columns = \lib\sql\getTable::get($cpModule['table']); break; } if (!$_table) { $_table = $cpModule['table']; } $qry = $this->sql()->table($_table); switch ($cpModule['raw']) { case 'categories': case 'filecategories': case 'bookcategories': case 'tags': case 'books': case 'posts': case 'pages': case 'attachments': case 'socialnetwork': $mytype = [$cpModule['prefix'] . '_type' => $cpModule['type']]; break; case 'profile': // $this->data->datarow = $this->model()->datarow('users', $this->login('id')); break; default: $mytype = null; break; } if (is_array($mytype)) { foreach ($mytype as $key => $value) { $qry = $qry->and($key, $value); } } $total = $qry->select()->num(); if (is_array($_condition)) { foreach ($_condition as $key => $value) { $qry = $qry->and($key, $value); } } $param_draw = \lib\utility::get('draw'); if (!$param_draw) { $param_draw = 1; } if ($param_search) { $qry = $qry->groupOpen('g_search'); $qry = $qry->and($cpModule['prefix'] . "_title", 'LIKE', "'%{$param_search}%'"); $qry = $qry->or($cpModule['prefix'] . "_slug", 'LIKE', "'%{$param_search}%'"); $qry = $qry->or($cpModule['prefix'] . "_url", 'LIKE', "'%{$param_search}%'"); $qry = $qry->groupClose('g_search'); } $datatable = ['draw' => $param_draw, 'total' => $total, 'filter' => $qry->select()->num()]; // check for start and length $param_start = \lib\utility::get('start'); $param_length = \lib\utility::get('length'); $param_sortby = \lib\utility::get('sortby'); $param_order = \lib\utility::get('order'); if (!$param_start) { $param_start = 0; } if (!$param_length) { if ($total > 100) { $param_length = 10; } else { $param_length = $total - $param_start; } } if (!$param_sortby) { $param_sortby = 'id'; } if (!$param_order) { $param_order = 'DESC'; } $qry = $qry->limit($param_start, $param_length); $tmp_result = $qry->order($param_sortby, $param_order); // get only datatable fields on sql for optimizing size of json $col = array('id'); if (!$tmp_columns) { return; } foreach ($tmp_columns as $field => $attr) { if ($attr['table']) { array_push($col, $field); } } $qry = $qry->field(...$col); $qry = $qry->select(); $tmp_result = $qry->allassoc(); // $tmp_result = $qry->allassoc(); foreach ($tmp_result as $id => $row) { foreach ($row as $key => $value) { if ($_rename) { $prefix = substr($_table, 0, -1) . '_'; // if(substr($key, 0, strlen($prefix) === $prefix)) if (strpos($key, $prefix) !== false) { // remove old key unset($tmp_result[$id][$key]); // transfer value to new key $key = substr($key, strlen($prefix)); $tmp_result[$id][$key] = $value; } } // if field contain json, decode it if (substr($value, 0, 1) == '{') { $tmp_result[$id][$key] = json_decode($value, true); } switch ($key) { case 'post_status': case 'term_status': $tmp_result[$id][$key] = T_($value); break; default: # code... break; } } } $datatable['data'] = $tmp_result; $datatable['columns'] = $tmp_columns; return $datatable; }