public function __construct($mid = 0) { if (ajax && !$mid) { $mid = $_REQUEST['_mid']; } $class_name = table::get_class_from_mid($mid); /** @var \classes\table $class */ $class = new $class_name(); $super_fields = $class->get_fields(); $fields = [form::create('field_boolean', 'deleted')->set_attr('label', 'Show deleted?')->set_attr('options', [25 => 25, 50 => 50, 75 => 75, 100 => 100, 0 => 'All'])->set_attr('required', false), form::create('field_select', 'npp')->set_attr('label', 'Number per page')->set_attr('options', [25 => 25, 50 => 50, 75 => 75, 100 => 100, 0 => 'All'])->set_attr('required', false), form::create('field_int', '_mid')->set_attr('hidden', true)]; /** @var \form\field $field */ foreach ($super_fields as $field) { if ($field->filter) { $field->required = false; $fields[] = $field; } } parent::__construct($fields); /** @var \form\field $field */ foreach ($fields as $field) { if (session::is_set('cms', 'filter', $mid, $field->field_name)) { $this->{$field->field_name} = session::get('cms', 'filter', $mid, $field->field_name); } } $this->id = 'filter_form'; $this->submit = 'Filter'; $this->_mid = $mid; }
public function do_submit() { $module = new _cms_module([], $this->mid); $field = new field_type([], $this->type); $type = '\\form\\field_' . $field->title; /** @var \form\field $field_type */ $field_type = new $type(''); if ($inner = $field_type->get_database_create_query()) { db::query('ALTER TABLE ' . $module->table_name . ' ADD `' . $this->field_name . '` ' . $field_type->get_database_create_query(), [], 1); } if ($field->title == 'mlink') { $source_module = new _cms_module(['table_name', 'primary_key'], $this->link_module); db::create_table_join(get::__class_name($this), $source_module->table_name); } $res = db::select('_cms_field')->retrieve('MAX(position) AS pos')->filter_field('mid', $this->mid)->execute()->fetchObject(); $insert = db::insert('_cms_field')->add_value('title', $this->title)->add_value('type', $field->title)->add_value('field_name', $this->field_name)->add_value('mid', $this->mid)->add_value('position', $res->pos + 1); if ($field->title == 'link' || $field->title == 'mlink') { $insert->add_value('link_module', $this->link_module)->add_value('link_field', $this->link_field); } $insert->execute(); table::rebuild_modules(); table::reset_module_fields($module->mid); ajax::update($module->get_fields_list()->get()); ajax::update($this->get_html()->get()); }
public function get_link_module() { if (is_numeric($this->link_module)) { $this->link_module = table::get_class_from_mid($this->link_module); } return $this->link_module; }
public function do_submit() { $module = new _cms_module([], $this->mid); if ($module->table_name != $this->table_name) { db::rename_table($module->table_name, $this->table_name); } if ($module->primary_key != $this->primary_key) { db::rename_column($this->table_name, $module->primary_key, $this->primary_key); } \classes\table::rebuild_modules(); $module->set_from_request(); $module->do_save(); }
public function get_sub_modules() { $html = ''; $collection = object\_cms_module::get_all([], ['where_equals' => ['parent_mid' => $this->module->mid]]); if ($collection->count()) { $html .= $collection->iterate_return(function (_cms_module $module) { $class = $module->get_class_name(); $list = new object\_cms_table_list($module, 1); $list->where = [$this->module->primary_key => $this->current->get_primary_key()]; return node::create('div.sub_module.container-fluid', [], node::create('div.row', [], [node::create('div.col-md-6 h3.pull-left', [], $module->title), node::create('div.col-md-6 a.btn.btn-default.pull-right', ['href' => '/cms/edit/' . $class::get_module_id() . '?' . $this->module->primary_key . '=' . $this->current->get_primary_key()], 'Add new ' . $module->title)]) . $list->get_table()); }); } return $html; }
/** * @return \form\form */ public function get_form() { $form = parent::get_form(); $form->action = get_class($this) . ':do_form_submit'; $form->set_from_request(); $form->remove_field('parent_did'); $form->remove_field('did'); $form->get_field_from_name('ftid')->hidden = true; $form->get_field_from_name('coordinates')->hidden = true; $form->get_field_from_name('pid')->label = 'Pilot'; $form->get_field_from_name('pid')->options = ['order' => 'pilot.name']; $form->h2 = 'Declare a flight'; $form->date = time(); return $form; }
public function get_cms_admin_edit() { $cols = []; $cols[] = node::create('td span.btn.btn-default.live' . ($this->live ? '' : '.not_live'), [], icon::get($this->live ? 'ok' : 'remove')); $cols[] = node::create('td span.btn.btn-default.edit', ['href' => '/' . $this->fid . '/?module=\\module\\cms\\object\\_cms_module&act=get_edit_field_form&fid=' . $this->fid, 'data-target' => '#modal', 'data-toggle' => 'modal'], icon::get('pencil')); $cols[] = node::create('td', [], $this->fid); $cols[] = node::create('td', [], node::create('a.up.reorder.btn.btn-default', ['data-ajax-click' => 'cms:do_reorder_fields', 'data-ajax-post' => '{"mid":' . $this->parent_form->get_module_id() . ',"fid":' . $this->fid . ',"dir":"up"}'], icon::get('arrow-up')) . node::create('a.down.reorder.btn.btn-default', ['data-ajax-click' => 'cms:do_reorder_fields', 'data-ajax-post' => '{"mid":' . $this->parent_form->get_module_id() . ',"fid":' . $this->fid . ',"dir":"down"}'], icon::get('arrow-down'))); $cols[] = node::create('td', [], $this->title); $cols[] = node::create('td', [], $this->field_name); $cols[] = node::create('td', [], get::__class_name($this)); $fields = ['list', 'required', 'filter']; foreach ($fields as $field) { $list_options = ['data-ajax-change' => 'form\\field_boolean:update_cms_setting', 'data-ajax-post' => '{"fid":' . $this->fid . ', "field":"' . $field . '"}', 'value' => 1, 'type' => 'checkbox']; if ($this->{$field}) { $list_options['checked'] = 'checked'; } $cols[] = node::create('td input#' . $this->fid . '_list', $list_options); } $cols[] = node::create('td', [], $this instanceof field_image ? $this->get_image_edit_link() : ''); return $cols; }
public function do_submit() { $module = new _cms_module([], $this->mid); $field = new field_type([], $this->type); $old_field = new _cms_field([], $this->fid); $type = '\\form\\field_' . $field->title; /** @var \form\field $field_type */ $field_type = new $type(''); if ($inner = $field_type->get_database_create_query()) { db::query('ALTER TABLE ' . $module->table_name . ' MODIFY `' . $old_field->field_name . '` `' . $this->field_name . '` ' . $field_type->get_database_create_query(), [], 1); } if ($field->title == 'mlink' && $old_field->type !== 'mlink') { $source_module = new _cms_module(['table_name', 'primary_key'], $this->link_module); db::create_table_join(\classes\get::__class_name($this), $source_module->table_name); } $insert = db::update('_cms_field')->add_value('title', $this->title)->add_value('type', $field->title)->add_value('field_name', $this->field_name)->add_value('link_module', $this->link_module)->add_value('link_field', $this->link_field)->filter_field('fid', $this->fid); $insert->execute(); table::rebuild_modules(); table::reset_module_fields($module->mid); ajax::update($module->get_fields_list()->get()); ajax::update($this->get_html()->get()); }
/** * @param field_file $field * @return string */ protected function do_upload_file(field_file $field) { if ($field->field_name == 'file') { if (isset($_FILES[$field->field_name]) && !$_FILES[$field->field_name]['error']) { $tmp_name = $_FILES[$field->field_name]['tmp_name']; $name = $_FILES[$field->field_name]['name']; $ext = pathinfo($name, PATHINFO_EXTENSION); if ($ext == 'zip') { $root = root . '/uploads/comp/' . $this->get_primary_key(); if (!is_dir($root)) { mkdir($root); } $this->file = str_replace(root, '', $root) . '/comp.zip'; $zip = new \ZipArchive(); $zip->open(root . $this->file); $zip->extractTo($root . '/'); $files = glob($root . '/*.igc'); $files = array_map(function ($file) { $exp = explode("/", $file); return ['name' => trim(preg_replace('/[^a-zA-Z ]/', '', substr(end($exp), 0, -3))), 'source' => $file]; }, $files); if ($files) { $coords = json_decode($this->coords); $parser = new igc_parser(); $parser->exec($this->get_primary_key(), ['type' => 'comp', 'sources' => $files, 'destination' => $root, 'task' => ['type' => 'lat/lng', 'coordinates' => array_map(function ($coord) { return ['lat' => (double) $coord->lat, 'lng' => (double) $coord->lon]; }, $coords)]]); } move_uploaded_file($tmp_name, root . $this->file); db::update('comp')->add_value('file', $this->file)->filter_field('cid', $this->cid)->execute(); } } } else { parent::do_upload_file($field); } }
public function do_submit() { db::query('CREATE TABLE IF NOT EXISTS `' . $this->table_name . '` ( `' . $this->primary_key . '` int(4) NOT NULL AUTO_INCREMENT, `parent_' . $this->primary_key . '` int(4) NOT NULL DEFAULT "0", `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `cms_created` timestamp NOT NULL DEFAULT "0000-00-00 00:00:00", `live` tinyint(1) NOT NULL DEFAULT "0", `deleted` tinyint(1) NOT NULL DEFAULT "0", `position` int(6) NOT NULL DEFAULT "0", `' . get::fn($this->title_label) . '` varchar(255) NOT NULL, PRIMARY KEY (`' . $this->primary_key . '`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;'); $mid = db::insert('_cms_module')->add_value('gid', $this->gid)->add_value('primary_key', $this->primary_key)->add_value('title', $this->title)->add_value('table_name', $this->table_name)->add_value('namespace', $this->namespace)->execute(); $id_field = db::insert('_cms_field')->add_value('field_name', $this->primary_key)->add_value('title', 'ID')->add_value('type', 'int')->add_value('mid', $mid)->add_value('required', false)->add_value('list', false)->add_value('editable', false)->add_value('filter', false)->execute(); db::insert('_cms_field')->add_value('field_name', 'parent_' . $this->primary_key)->add_value('title', 'Parent ID')->add_value('type', 'link')->add_value('mid', $mid)->add_value('link_module', $mid)->add_value('link_field', (int) $id_field + 2)->add_value('required', false)->add_value('list', false)->execute(); db::insert('_cms_field')->add_value('field_name', get::fn($this->title_label))->add_value('title', $this->title_label)->add_value('type', 'string')->add_value('mid', $mid)->execute(); $file = null; if (!$this->namespace) { if (!is_dir(root . '/inc/object/')) { mkdir(root . '/inc/object/'); } if (!file_exists(root . '/inc/object/' . $this->table_name)) { $file = root . '/inc/object/' . $this->table_name; } } else { if (!is_dir(root . '/inc/module/')) { mkdir(root . '/inc/module/'); } if (!is_dir(root . '/inc/module/' . $this->namespace)) { mkdir(root . '/inc/module/' . $this->namespace); } if (!is_dir(root . '/inc/module/' . $this->namespace . '/object/')) { mkdir(root . '/inc/module/' . $this->namespace . '/object'); } if (!file_exists(root . '/inc/module/' . $this->namespace . '/object/' . $this->table_name)) { $file = root . '/inc/module/' . $this->namespace . '/object/' . $this->table_name; } } if ($file) { $class_name = ($this->namespace ? 'module\\' . $this->namespace . '\\' : '') . 'object\\' . $this->table_name; file_put_contents($file . '.php', '<?php namespace ' . ($this->namespace ? 'module\\' . $this->namespace . '\\' : '') . 'object; use classes\\table; use traits\\table_trait; class ' . $this->table_name . ' extends ' . (class_exists('\\core\\' . $class_name) ? '\\core\\' . $class_name : 'table') . ' { use table_trait; /** @var string */ public $' . get::fn($this->title_label) . '; /** @var int */ public $' . get::fn($this->primary_key) . '; }'); } \classes\table::rebuild_modules(); ajax::add_script('window.location = window.location'); }
/** Add user level management * ---CMS User * ---CMS User level * ---CMS User --> CMS Module * */ public function patch_v4() { if (!db::table_exists('_cms_user')) { self::create_from_structure('_cms_user'); table::reload_table_definitions(); $user_level = new _cms_user_level(); $user_level->title = 'User'; $user_level->do_save(); $user_level->ulid = 0; $user_level->title = 'Webmaster'; $user_level->do_save(); $user_level->ulid = 0; $user_level->title = 'Admin'; $user_level->do_save(); $cms_user = new _cms_user(); $cms_user->title = 'admin'; $cms_user->password = '******'; $cms_user->ulid = 3; $cms_user->do_save(); $_module = new _cms_module(); $_module->do_retrieve([], ['where_equals' => ['table_name' => '_cms_module']]); $_field = new _cms_field(); $_field->do_retrieve([], ['where_equals' => ['mid' => $_module->get_primary_key(), 'field_name' => 'user_level_view']]); static::modify_link_field($_field, '_cms_user_level', 'title'); $_field = new _cms_field(); $_field->do_retrieve([], ['where_equals' => ['mid' => $_module->get_primary_key(), 'field_name' => 'user_level_add']]); static::modify_link_field($_field, '_cms_user_level', 'title'); $_field = new _cms_field(); $_field->do_retrieve([], ['where_equals' => ['mid' => $_module->get_primary_key(), 'field_name' => 'user_level_delete']]); static::modify_link_field($_field, '_cms_user_level', 'title'); } }
public function __construct($fields = [], $id = 0) { parent::__construct($fields, $id); $this->_field_elements = new field_collection(); }