public function execute() { $query = 'UPDATE ' . $this->table . ' SET ' . $this->get_values() . $this->get_filters(); compiler::break_cache($this->table); cache::break_cache($this->table); return _db::query($query, $this->parameters); }
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()); }
function get_manu($manu) { $res = db::result('SELECT mid FROM manufacturer WHERE title =:title', array('title' => $manu)); if ($res) { return $res->mid; } }
/** * @return \PDOStatement */ public function execute() { $query = 'DELETE FROM ' . $this->table . $this->get_filters(); compiler::break_cache($this->table); cache::break_cache($this->table); return _db::query($query, $this->parameters); }
public function execute() { $query = 'REPLACE INTO ' . $this->table . ' SET ' . $this->get_values(); _db::query($query, $this->parameters); $id = _db::insert_id(); compiler::break_cache($this->table); cache::break_cache($this->table); return $id; }
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 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()); }
public function do_submit() { db::connect_root(); db::query('CREATE DATABASE IF NOT EXISTS `' . get::fn($this->username) . '`'); db::query('USE mysql'); if (db::select('user')->retrieve(['user'])->filter(['`user`=:user AND `host`=:host'], ['user' => $this->username, 'host' => '127.0.0.1'])->execute()->rowCount()) { db::query('CREATE USER \'' . get::fn($this->username) . '\'@\'127.0.0.1\' IDENTIFIED BY \'' . $this->password . '\'', [], true); } if (db::select('user')->retrieve(['user'])->filter(['`user`=:user AND `host`=:host'], ['user' => $this->username, 'host' => 'localhost'])->execute()->rowCount()) { db::query('CREATE USER \'' . get::fn($this->username) . '\'@\'localhost\' IDENTIFIED BY \'' . $this->password . '\'', [], true); } db::query('GRANT ALL PRIVILEGES ON `' . get::fn($this->username) . '`.* TO \'' . get::fn($this->username) . '\'@\'127.0.0.1\'', [], true); db::query('GRANT ALL PRIVILEGES ON `' . get::fn($this->username) . '`.* TO \'' . get::fn($this->username) . '\'@\'localhost\'', [], true); if (!is_dir(root . '/.conf')) { mkdir(root . '/.conf'); } ini::save(root . '/.conf/config.ini', ['mysql' => ['server' => '127.0.0.1', 'username' => get::fn($this->username), 'password' => $this->password, 'database' => get::fn($this->username)], 'site' => ['title_tag' => $this->site_name]]); ini::reload(); db::default_connection(); $cms_builder = new \module\cms\object\cms_builder(); $cms_builder->manage(); $i = 0; do { if ($this->{'user_' . $i} && $this->{'password_' . $i}) { $user = new _cms_user(); $user->title = $this->{'user_' . $i}; $user->password = $this->{'password_' . $i}; $user->ulid = $this->{'user_level_' . $i} ?: 1; } $i++; } while (isset($this->{'user_' . $i})); ajax::current()->redirect = '/cms/login'; }
public function get_image_edit_link() { $count = db::count('image_size', 'isid')->filter_field('fid', $this->fid)->execute(); return node::create('a', array('href' => '/cms/module/' . image_size::get_module_id() . '/!/fid/' . $this->fid), (int) $count . ' image sizes'); }
public function update_cms_setting() { if (\core::is_admin()) { db::update('_cms_field')->add_value($_REQUEST['field'], $_REQUEST['value'])->filter_field('fid', $_REQUEST['fid'])->execute(); } return 1; }
public static function create_table_json($json) { $sql = 'CREATE TABLE IF NOT EXISTS ' . $json->tablename; $column_strings = []; foreach ($json->fieldset as $field => $structure) { $string = static::get_column_type_json($structure); if ($string) { $column_strings[] = '`' . $field . '` ' . $string; } } foreach ($json->indexes as $type => $indexes) { switch ($type) { case 'primary': $column_strings[] = 'PRIMARY KEY (`' . $indexes . '`)'; break; case 'standard': foreach ($indexes as $index) { $column_strings[] = 'INDEX (`' . implode('`,`', $index) . '`)'; } break; } } $sql .= ' (' . implode(',', $column_strings) . ') '; $setting_strings = []; foreach (_db::$default_table_settings as $setting => $value) { if (is_numeric($setting)) { $setting_strings[] = $value; } else { $setting_strings[] = $setting . ' = ' . $value; } } foreach ($json->settings as $setting => $value) { if (is_numeric($setting)) { $setting_strings[] = $value; } else { $setting_strings[] = $setting . ' = ' . $value; } } $sql .= implode(',', $setting_strings); _db::query($sql); }
/** * @param string $class * @param array $fields_to_retrieve * @param array $options */ public function get_all($class, array $fields_to_retrieve, $options = []) { $this->fields = $fields_to_retrieve; $this->options = $options; $this->class = $class; /** @var table $obj */ $obj = new $class(); $links = []; $mlinks = []; $obj->set_default_retrieve($fields_to_retrieve, $options); table::organise_links($obj, $fields_to_retrieve, $links, $mlinks); $dependencies = [get::__class_name($class)]; foreach ($links as $module => $link_info) { $field = $link_info['field']; $retrieves = $link_info['retrieve']; $dependencies[] = get::__class_name($module); $options['join'][$module] = $module . '.' . $field->field_name . '=' . $obj->class_name() . '.' . $field->field_name; foreach ($retrieves as $retrieve) { $fields_to_retrieve[] = $module . '.' . $retrieve; } } $key = 'get_all_' . $class . '_fetch_' . implode(',', $fields_to_retrieve) . '_options_' . serialize($options); $elements = \classes\cache::grab($key, function () use($class, $fields_to_retrieve, $options, $links, $mlinks, $obj) { if (!isset($options['order'])) { $options['order'] = get::__class_name($class) . '.position'; } $select = _db::get_query($class, $fields_to_retrieve, $options); $res = $select->execute(); if (_db::num($res)) { $row = _db::fetch($res, null); $mappings = $obj->get_field_mappings(array_keys($row)); do { /** @var table $class */ $object = new $class(); $object->set_from_row($row, $links, $mappings); foreach ($mlinks as $module => $blah) { $object->{$module . '_elements'} = new \classes\table_array(); $object->{$module} = new _collection(); } $this[] = $object; } while ($row = _db::fetch($res, null)); } $this->reset_iterator(); foreach ($mlinks as $module => $link_info) { /** @var \form\field_link $field */ $field = $link_info['field']; $retrieves = $link_info['retrieve']; $retrieves[] = 'l.' . $obj->get_primary_key_name() . ' AS linked_id'; $sub_class = $field->get_link_object(); $classes = $sub_class::get_all($retrieves, ['join' => [get::__class_name($class) . '_link_' . get::__class_name($sub_class) . ' l' => 'l.link_' . $sub_class->get_primary_key_name() . '=' . get::__class_name($sub_class) . '.' . $sub_class->get_primary_key_name()], 'where' => 'l.' . $obj->get_primary_key_name() . ' IN(' . implode(',', $this->get_table_keys()) . ')']); /** @var table $sub_object */ foreach ($classes as $sub_object) { $object = $this->find_table_key($sub_object->linked_id); if ($object) { $object->{$module . '_elements'}->push($sub_object); $object->{$module}->push($sub_object->get_primary_key()); } } } return $this->exchangeArray([]); }, $dependencies); $this->exchangeArray($elements); }
/** * @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); } }
/** * @return int * */ public function execute() { $query = 'SELECT COUNT(' . $this->fields[0] . ') AS count FROM ' . $this->table . $this->get_joins() . $this->get_filters() . $this->get_groupings() . ' ' . $this->get_limit(); $res = db::query($query, $this->parameters); return $res->fetchObject()->count; }
$time = time(); define('load_core', false); require $_SERVER['DOCUMENT_ROOT'] . '/.core/config.php'; set_time_limit(0); if (!is_dir(root . '/bin')) { mkdir(root . '/bin'); } if (!is_dir(root . '/bin/' . $time)) { mkdir(root . '/bin/' . $time); } else { die('A build already exists with the timestamp ' . $time); } $index_contents = '<?php'; $classes = []; $res = \classes\db::select('_autoloader_log')->retrieve(['classes'])->execute(); if ($res->rowCount()) { $row = $res->fetchObject(); $classes = explode(',', $row->classes); while ($row = $res->fetchObject()) { $classes = array_intersect($classes, explode(',', $row->classes)); } foreach ($classes as &$class) { $class = str_replace('\\', '/', $class) . '.php'; } } unset($class); $file_mappings = []; $files = \classes\get::recursive_glob(root . '/.core/', '*.php'); foreach ($files as $file) { $new_path = str_replace(root . '/.core/dependent/', '', $file);
/** * */ public function do_reorder() { if (isset($_REQUEST['id'])) { /** @var table $object */ static::$retrieve_unlive = true; static::$retrieve_deleted = true; $object = new static(['position'], $_REQUEST['id']); if (isset($_REQUEST['dir']) && $_REQUEST['dir'] == 'down') { _db::update(_get::__class_name($object))->add_value('position', $object->position)->filter_field('position', $object->position + 1)->execute(); _db::update(_get::__class_name($object))->add_value('position', $object->position + 1)->filter_field($object->get_primary_key_name(), $object->get_primary_key())->execute(); } else { _db::update(_get::__class_name($object))->add_value('position', $object->position)->filter_field('position', $object->position - 1)->execute(); _db::update(_get::__class_name($object))->add_value('position', $object->position - 1)->filter_field($object->get_primary_key_name(), $object->get_primary_key())->execute(); } $list = new _cms_table_list(self::$cms_modules[get_called_class()], 1); _ajax::update($list->get_table()); } }
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'); }
public function run_patch($patch) { $function = 'patch_v' . $patch; $this->{$function}(); db::update('_cms_setting')->add_value('value', $patch)->filter(['`key`="cms_version"'])->execute(); }
public function do_delete() { $module = new _cms_module([], $_REQUEST['mid']); $object = $module->get_class(); $class = $module->get_class_name(); $class::$retrieve_deleted = true; $object->do_retrieve_from_id(['deleted'], $_REQUEST['id']); if ($object->get_primary_key()) { if ($object->deleted) { db::delete(get::__class_name($class))->filter($object->get_primary_key_name() . '=' . $_REQUEST['id'])->execute(); } else { $object->deleted = true; $object->do_save(); } } $list = new object\_cms_table_list($module, 1); ajax::update($list->get_table()); }
/** * @return \PDOStatement */ public function execute() { $query = 'SELECT ' . $this->get_fields() . ' FROM ' . $this->table . $this->get_joins() . $this->get_filters() . $this->get_groupings() . $this->get_order() . ' ' . $this->get_limit(); return _db::query($query, $this->parameters); }