Beispiel fuer den Rueckgabewert:
Array (
[0] => Array (
[name] => pid
[type] => int(11)
[null] => NO
[key] => PRI
[default] =>
[extra] => auto_increment
)
[1] => Array (
[name] => id
[type] => int(11)
[null] => NO
[key] => MUL
[default] =>
[extra] =>
)
)
/** * Alle Metafelder löschen, nicht das nach einem Import in der Parameter Tabelle * noch Datensätze zu Feldern stehen, welche nicht als Spalten in der * rex_article angelegt wurden! */ function rex_a62_metainfo_cleanup($params) { global $REX; // Cleanup nur durchführen, wenn auch die rex_article Tabelle neu angelegt wird if (isset($params['force']) && $params['force'] != true && strpos($params['content'], 'CREATE TABLE `' . $REX['TABLE_PREFIX'] . 'article`') === false && strpos($params['content'], 'CREATE TABLE ' . $REX['TABLE_PREFIX'] . 'article') === false) { return; } require_once $REX['INCLUDE_PATH'] . '/addons/metainfo/classes/class.rex_table_manager.inc.php'; $sql = new rex_sql(); $sql->setQuery('SELECT name FROM ' . $REX['TABLE_PREFIX'] . '62_params'); for ($i = 0; $i < $sql->getRows(); $i++) { if (substr($sql->getValue('name'), 0, 4) == 'med_') { $tableManager = new rex_a62_tableManager($REX['TABLE_PREFIX'] . 'file'); } else { $tableManager = new rex_a62_tableManager($REX['TABLE_PREFIX'] . 'article'); } $tableManager->deleteColumn($sql->getValue('name')); $sql->next(); } // evtl reste aufräumen $tablePrefixes = array('article' => array('art_', 'cat_'), 'file' => array('med_')); foreach ($tablePrefixes as $table => $prefixes) { $table = $REX['TABLE_PREFIX'] . $table; $tableManager = new rex_a62_tableManager($table); foreach (rex_sql::showColumns($table) as $column) { $column = $column['name']; if (in_array(substr($column, 0, 4), $prefixes)) { $tableManager->deleteColumn($column); } } } $sql = new rex_sql(); $sql->setQuery('DELETE FROM ' . $REX['TABLE_PREFIX'] . '62_params'); rex_generateAll(); }
public function hasColumn($name) { $columns = rex_sql::showColumns($this->getTableName(), $this->DBID); foreach ($columns as $column) { if ($column['name'] == $name) { return true; } } return false; }
/** * Alle Metafelder löschen, nicht das nach einem Import in der Parameter Tabelle * noch Datensätze zu Feldern stehen, welche nicht als Spalten in der * rex_article angelegt wurden! */ function rex_metainfo_cleanup($epOrParams) { $params = $epOrParams instanceof rex_extension_point ? $epOrParams->getParams() : $epOrParams; // Cleanup nur durchführen, wenn auch die rex_article Tabelle neu angelegt wird if (isset($params['force']) && $params['force'] != true && strpos($params['content'], 'CREATE TABLE `' . rex::getTablePrefix() . 'article`') === false && strpos($params['content'], 'CREATE TABLE ' . rex::getTablePrefix() . 'article') === false) { return; } // check wheter tables exists $tables = rex_sql::showTables(); if (!isset($tables[rex::getTablePrefix() . 'metainfo_field'])) { return false; } // since this extension may be used also when the addon is not yet installed, // require needed classes manually require_once __DIR__ . '/../lib/table_manager.php'; $sql = rex_sql::factory(); $sql->setQuery('SELECT name FROM ' . rex::getTablePrefix() . 'metainfo_field'); for ($i = 0; $i < $sql->getRows(); ++$i) { if (substr($sql->getValue('name'), 0, 4) == 'med_') { $tableManager = new rex_metainfo_table_manager(rex::getTablePrefix() . 'media'); } else { $tableManager = new rex_metainfo_table_manager(rex::getTablePrefix() . 'article'); } $tableManager->deleteColumn($sql->getValue('name')); $sql->next(); } // evtl reste aufräumen $tablePrefixes = ['article' => ['art_', 'cat_'], 'media' => ['med_']]; foreach ($tablePrefixes as $table => $prefixes) { $table = rex::getTablePrefix() . $table; $tableManager = new rex_metainfo_table_manager($table); foreach (rex_sql::showColumns($table) as $column) { $column = $column['name']; if (in_array(substr($column, 0, 4), $prefixes)) { $tableManager->deleteColumn($column); } } } $sql = rex_sql::factory(); $sql->setQuery('DELETE FROM ' . rex::getTablePrefix() . 'metainfo_field'); }
public function getDataListQuery($rex_yform_filter = array(), $searchObject) { $sql = 'select * from ' . $this->table->getTablename() . ' t0'; $sql_felder = rex_sql::factory(); $sql_felder->setQuery('SELECT * FROM ' . rex_yform_manager_field::table() . ' WHERE table_name="' . $this->table->getTablename() . '" AND type_id="value" ORDER BY prio'); $max = $sql_felder->getRows(); if ($max > 0) { $existingFields = array_map(function ($column) { return $column['name']; }, rex_sql::showColumns($this->table->getTablename())); $fields = array(); for ($i = 0; $i < $sql_felder->getRows(); $i++) { if (in_array($sql_felder->getValue('name'), $existingFields)) { $fields[] = '`' . $sql_felder->getValue('name') . '`'; } else { $fields[] = 'NULL AS `' . $sql_felder->getValue('name') . '`'; } $sql_felder->next(); } $sql = 'select `id`,' . implode(',', $fields) . ' from `' . $this->table->getTablename() . '` t0'; } $sql .= $this->getDataListQueryWhere($rex_yform_filter, $searchObject); if ($this->table->getSortFieldName() != "") { $sql .= ' ORDER BY `' . $this->table->getSortFieldName() . '` ' . $this->table->getSortOrderName(); } $sql = rex_extension::registerPoint(new rex_extension_point('YFORM_DATA_LIST_SQL', $sql, array('table' => $this->table))); return $sql; }
public function getColumns() { $columns = rex_sql::showColumns($this->getTableName()); $c = array(); foreach ($columns as $column) { $c[$column['name']] = $column; } unset($c['id']); return $c; }
foreach ($REX['CLANG'] as $key => $value) { $select->addOption($value, $key); } } $field =& $form->addSelectField('table'); $field->setLabel($I18N->msg('b_table')); $field->setAttribute('onchange', 'url_generate_table(this);'); $field->setAttribute('style', 'width: 200px;'); $select =& $field->getSelect(); $select->setSize(1); $select->addOption($I18N->msg('b_no_table_selected'), ''); $fields = array(); $tables = rex_sql::showTables(); foreach ($tables as $table) { $select->addOption($table, $table); $columns = rex_sql::showColumns($table); foreach ($columns as $column) { $fields[$table][] = $column['name']; } } $table_id = $field->getAttribute('id'); $fieldContainer =& $form->addContainerField('table_parameters'); $fieldContainer->setAttribute('style', 'display: none'); if (count($fields > 0)) { foreach ($fields as $table => $columns) { $group = $table; $options = $columns; $type = 'select'; $name = $table . '_name'; $f1 =& $fieldContainer->addGroupedField($group, $type, $name, $value, $attributes = array()); $f1->setHeader('<div class="url-control-grid3col">');
<?php slice_ui::emptyClipboard(1); $fields = ['active', 'online_from', 'online_to']; $cols = rex_sql::showColumns(rex::getTablePrefix() . 'article_slice'); foreach ($fields as $fieldname) { $found = false; foreach ($cols as $field) { if ($field['name'] === $fieldname) { $found = true; break; } } if ($found) { $sql = rex_sql::factory(); $sql->setQuery("ALTER TABLE `" . rex::getTablePrefix() . 'article_slice' . "` DROP " . $fieldname, array()); } }
global $REX; if (!class_exists('rex_asd_news_config')) { include_once __DIR__ . '/classes/rex_asd_news_config.php'; } rex_asd_news_config::init('asd_news', 'asd_news', 'asd_news_category'); $REX['ADDON']['update'][rex_asd_news_config::getName()] = 1; $REX['ADDON']['updatemsg'][rex_asd_news_config::getName()] = ''; // Check if in AddonData the config file exists rex_asd_news_config::createDataConfigIfNotExists(); // Update Config rex_asd_news_config::saveConfig(); // Update 1.4 // check if old fields exists $sql = new rex_sql(); $rows = $sql->showColumns(rex_asd_news_config::getTable()); $metaCols = false; foreach ($rows as $row) { if ($row['name'] == 'category') { $metaCols = true; break; } } if (!OOAddon::isAvailable('metainfo')) { $REX['ADDON']['update'][rex_asd_news_config::getName()] = 0; $REX['ADDON']['updatemsg'][rex_asd_news_config::getName()] = 'Metainfo Addon nicht gefunden'; } if (OOAddon::isAvailable('metainfo') && $metaCols) { include_once __DIR__ . '/classes/metainfo/rex_asd_metainfo_install.php'; rex_asd_metainfo_install::setProperty(); if ($error = rex_asd_metainfo_install::addFields()) {
static function createMissingFieldColumns($field) { $columns = array(); foreach (rex_sql::showColumns(rex_xform_manager_field::table()) as $column) { $columns[$column['name']] = true; } $alterTable = array(); foreach ($field as $column => $value) { if (!isset($columns[$column])) { $alterTable[] = 'ADD `' . mysql_real_escape_string($column) . '` TEXT NOT NULL'; } $columns[$column] = true; } if (count($alterTable)) { $alter = rex_sql::factory(); $alter->debugsql = self::$debug; $alter->setQuery('ALTER TABLE `' . rex_xform_manager_field::table() . '` ' . implode(',', $alterTable)); } }
function executeAction() { // START - Spezialfall "be_em_relation" /* $be_em_table_field = ""; if($this->params["value_pool"]["sql"]["type_name"] == "be_em_relation") { $be_em_table_field = $this->params["value_pool"]["sql"]["f1"]; $this->params["value_pool"]["sql"]["f1"] = $this->params["value_pool"]["sql"]["f3"]."_".$this->params["value_pool"]["sql"]["f1"]; } */ // ENDE - Spezialfall // ********************************* TABLE A // $this->params["debug"]= TRUE; $sql = rex_sql::factory(); if ($this->params['debug']) { $sql->debugsql = true; } $main_table = ''; if ($this->getElement(2) != '') { $main_table = $this->getElement(2); } else { $main_table = $this->params['main_table']; } if ($main_table == '') { $this->params['form_show'] = true; $this->params['hasWarnings'] = true; $this->params['warning_messages'][] = $this->params['Error-Code-InsertQueryError']; return false; } $columns = array(); foreach (rex_sql::showColumns($main_table) as $column) { $columns[$column['name']] = true; } $alterTable = array(); foreach ($this->params['value_pool']['sql'] as $field => $value) { if ($value != '' && !isset($columns[$field])) { $alterTable[] = 'ADD `' . $field . '` TEXT NOT NULL'; $columns[$field] = true; } /*if (!$value && isset($columns[$field])) { $sql->setQuery('SELECT 1 FROM `' . mysql_real_escape_string($main_table) . '` WHERE `' . mysql_real_escape_string($field) . '` LIMIT 1'); if (!$sql->getRows()) { $alterTable[] = 'DROP `' . mysql_real_escape_string($field) . '`'; unset($columns[$field]); } }*/ } if ($alterTable) { $sql->setQuery('ALTER TABLE `' . $main_table . '` ' . implode(',', $alterTable)); } $sql->setTable($main_table); $where = ''; if (trim($this->getElement(3)) != '') { $where = trim($this->getElement(3)); } // SQL Objekt mit Werten f�llen foreach ($this->params['value_pool']['sql'] as $key => $value) { if (isset($columns[$key])) { $sql->setValue($key, $value); } if ($where != '') { $where = str_replace('###' . $key . '###', addslashes($value), $where); } } if ($where != '') { $sql->setWhere($where); $sql->update(); $flag = 'update'; } else { $sql->insert(); $flag = 'insert'; $id = $sql->getLastId(); $this->params['value_pool']['email']['ID'] = $id; $this->params['main_id'] = $id; // $this->params["value_pool"]["sql"]["ID"] = $id; if ($id == 0) { $this->params['form_show'] = true; $this->params['hasWarnings'] = true; $this->params['warning_messages'][] = $this->params['Error-Code-InsertQueryError']; } } return; }
echo a587_getSettingsFormSection('a587_highlight', $I18N->Msg('a587_settings_highlight_header'), array(array('type' => 'string', 'id' => 'a587_rexsearch_surroundtags_start', 'name' => 'a587_rexsearch[surroundtags][0]', 'label' => $I18N->Msg('a587_settings_surroundtags_start'), 'value' => isset($REX['ADDON']['settings']['rexsearch']['surroundtags'][0]) ? htmlspecialchars($REX['ADDON']['settings']['rexsearch']['surroundtags'][0]) : ''), array('type' => 'string', 'id' => 'a587_rexsearch_surroundtags_end', 'name' => 'a587_rexsearch[surroundtags][1]', 'label' => $I18N->Msg('a587_settings_surroundtags_end'), 'value' => isset($REX['ADDON']['settings']['rexsearch']['surroundtags'][1]) ? htmlspecialchars($REX['ADDON']['settings']['rexsearch']['surroundtags'][1]) : ''), array('type' => 'hidden', 'name' => 'a587_rexsearch[limit][0]', 'value' => '0'), array('type' => 'string', 'id' => 'a587_rexsearch_limit', 'name' => 'a587_rexsearch[limit][1]', 'label' => $I18N->Msg('a587_settings_limit'), 'value' => isset($REX['ADDON']['settings']['rexsearch']['limit'][1]) ? intval($REX['ADDON']['settings']['rexsearch']['limit'][1]) : ''), array('type' => 'string', 'id' => 'a587_rexsearch_maxteaserchars', 'name' => 'a587_rexsearch[maxteaserchars]', 'label' => $I18N->Msg('a587_settings_maxteaserchars'), 'value' => isset($REX['ADDON']['settings']['rexsearch']['maxteaserchars']) ? intval($REX['ADDON']['settings']['rexsearch']['maxteaserchars']) : ''), array('type' => 'string', 'id' => 'a587_rexsearch_maxhighlightchars', 'name' => 'a587_rexsearch[maxhighlightchars]', 'label' => $I18N->Msg('a587_settings_maxhighlightchars'), 'value' => isset($REX['ADDON']['settings']['rexsearch']['maxhighlightchars']) ? intval($REX['ADDON']['settings']['rexsearch']['maxhighlightchars']) : ''), array('type' => 'select', 'id' => 'a587_rexsearch_highlight', 'name' => 'a587_rexsearch[highlight]', 'label' => $I18N->Msg('a587_settings_highlight_label'), 'options' => array(array('value' => 'sentence', 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'sentence', 'name' => $I18N->Msg('a587_settings_highlight_sentence')), array('value' => 'paragraph', 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'paragraph', 'name' => $I18N->Msg('a587_settings_highlight_paragraph')), array('value' => 'surroundtext', 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'surroundtext', 'name' => $I18N->Msg('a587_settings_highlight_surroundtext')), array('value' => 'surroundtextsingle', 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'surroundtextsingle', 'name' => $I18N->Msg('a587_settings_highlight_surroundtextsingle')), array('value' => 'teaser', 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'teaser', 'name' => $I18N->Msg('a587_settings_highlight_teaser')), array('value' => 'array', 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'array', 'name' => $I18N->Msg('a587_settings_highlight_array')))), array('type' => 'directoutput', 'output' => '<div class="rex-form-row">' . $sampleoutput . '</div>'))); $categories = array(); foreach (a587_getCategories() as $id => $name) { $categories[] = array('value' => $id, 'selected' => !empty($REX['ADDON']['settings']['rexsearch']['exclude_category_ids']) and is_array($REX['ADDON']['settings']['rexsearch']['exclude_category_ids']) and in_array($id, $REX['ADDON']['settings']['rexsearch']['exclude_category_ids']), 'name' => $name . ' (' . $id . ')'); } $articles = array(); foreach (a587_getArticles() as $id => $name) { $articles[] = array('value' => $id, 'selected' => !empty($REX['ADDON']['settings']['rexsearch']['exclude_article_ids']) and is_array($REX['ADDON']['settings']['rexsearch']['exclude_article_ids']) and in_array($id, $REX['ADDON']['settings']['rexsearch']['exclude_article_ids']), 'name' => $name . ' (' . $id . ')'); } echo a587_getSettingsFormSection('a587_exclude', $I18N->Msg('a587_settings_exclude'), array(array('type' => 'string', 'id' => 'a587_settings_exclude_blacklist', 'name' => 'a587_rexsearch[blacklist]', 'label' => $I18N->Msg('a587_settings_exclude_blacklist'), 'value' => isset($REX['ADDON']['settings']['rexsearch']['blacklist']) ? htmlspecialchars(implode(',', $REX['ADDON']['settings']['rexsearch']['blacklist'])) : ''), array('type' => 'multipleselect', 'id' => 'a587_rexsearch_exclude_article_ids', 'name' => 'a587_rexsearch[exclude_article_ids][]', 'label' => $I18N->Msg('a587_settings_exclude_articles'), 'size' => 15, 'options' => $articles), array('type' => 'multipleselect', 'id' => 'a587_rexsearch_exclude_category_ids', 'name' => 'a587_rexsearch[exclude_category_ids][]', 'label' => $I18N->Msg('a587_settings_exclude_categories'), 'size' => 15, 'options' => $categories))); $options = array(); $sql_tables = new rex_sql(); foreach ($sql_tables->showTables() as $table) { if (false === strpos($table, '587_search') and false === strpos($table, '587_keywords')) { $sql_columns = new rex_sql(); foreach ($sql_tables->showColumns($table) as $column) { /*switch(strtolower(substr($column['type'],0,4))) { case 'text': case 'char': case 'varc':*/ $options[] = array('value' => htmlspecialchars($table . '`.`' . $column['name']), 'checked' => in_array($column['name'], (!empty($REX['ADDON']['settings']['rexsearch']['include'][$table]) and is_array($REX['ADDON']['settings']['rexsearch']['include'][$table])) ? $REX['ADDON']['settings']['rexsearch']['include'][$table] : array()), 'name' => $table . ' . ' . $column['name'], 'id' => $table . ' . ' . $column['name']); //} } } } echo a587_getSettingsFormSection('a587_include', $I18N->Msg('a587_settings_include'), array(array('type' => 'multiplecheckboxes', 'id' => 'a587_rexsearch_include', 'name' => 'a587_rexsearch[include][]', 'label' => '', 'size' => 20, 'options' => $options))); $options = array(array('value' => '', 'name' => '', 'selected' => false, 'id' => 'a587_optiondummy')); if (!empty($REX['ADDON']['settings']['rexsearch']['indexfolders'])) { foreach ($REX['ADDON']['settings']['rexsearch']['indexfolders'] as $relative) { $options[] = array('value' => $relative, 'name' => $relative, 'selected' => true);
<?php /** * MetaForm Addon. * * @author markus[dot]staab[at]redaxo[dot]de Markus Staab * * @package redaxo5 * * @var rex_addon $this */ rex_sql_util::importDump($this->getPath('_install.sql')); $tablePrefixes = ['article' => ['art_', 'cat_'], 'media' => ['med_'], 'clang' => ['clang_']]; $columns = ['article' => [], 'media' => [], 'clang' => []]; foreach ($tablePrefixes as $table => $prefixes) { foreach (rex_sql::showColumns(rex::getTable($table)) as $column) { $column = $column['name']; $prefix = substr($column, 0, 4); if (in_array(substr($column, 0, 4), $prefixes)) { $columns[$table][$column] = true; } } } $sql = rex_sql::factory(); $sql->setQuery('SELECT p.name, p.default, t.dbtype, t.dblength FROM ' . rex::getTable('metainfo_field') . ' p, ' . rex::getTable('metainfo_type') . ' t WHERE p.type_id = t.id'); $rows = $sql->getRows(); $managers = ['article' => new rex_metainfo_table_manager(rex::getTable('article')), 'media' => new rex_metainfo_table_manager(rex::getTable('media')), 'clang' => new rex_metainfo_table_manager(rex::getTable('clang'))]; for ($i = 0; $i < $sql->getRows(); ++$i) { $column = $sql->getValue('name'); if (substr($column, 0, 4) == 'med_') { $table = 'media';
* * @author markus[dot]staab[at]redaxo[dot]de Markus Staab * * @package redaxo4 * @version svn:$Id$ */ $error = ''; $result = rex_install_dump($REX['INCLUDE_PATH'] . '/addons/metainfo/_install.sql'); if ($result !== true) { $error = $result; } else { require_once $REX['INCLUDE_PATH'] . '/addons/metainfo/classes/class.rex_table_manager.inc.php'; $tablePrefixes = array('article' => array('art_', 'cat_'), 'file' => array('med_')); $columns = array('article' => array(), 'file' => array()); foreach ($tablePrefixes as $table => $prefixes) { foreach (rex_sql::showColumns($REX['TABLE_PREFIX'] . $table) as $column) { $column = $column['name']; $prefix = substr($column, 0, 4); if (in_array(substr($column, 0, 4), $prefixes)) { $columns[$table][$column] = true; } } } $sql = rex_sql::factory(); $sql->setQuery('SELECT p.name, p.default, t.dbtype, t.dblength FROM ' . $REX['TABLE_PREFIX'] . '62_params p, ' . $REX['TABLE_PREFIX'] . '62_type t WHERE p.type = t.id'); $rows = $sql->getRows(); $managers = array('article' => new rex_a62_tableManager($REX['TABLE_PREFIX'] . 'article'), 'file' => new rex_a62_tableManager($REX['TABLE_PREFIX'] . 'file')); for ($i = 0; $i < $sql->getRows(); $i++) { $column = $sql->getValue('name'); if (substr($column, 0, 4) == 'med_') { $table = 'file';