public function getCustomHeaders() { $r = ''; if ($q = AdaptorMysql::query("SELECT * FROM `" . BLACKBIRD_TABLE_PREFIX . "headers`")) { foreach ($q as $row) { $r .= $row['javascript'] . "\t\t\n" . $row['css'] . "\t\t\n"; } } return $r; }
//explode left on -- $k = explode('--',$v[0]); $myA[$k[1]] = $v[1]; } $i++; } */ define('LIB', $base . 'cms/bobolink/'); require LIB . 'database/Db.interface.php'; require LIB . 'database/AdaptorMysql.class.php'; require LIB . 'utils/Utils.class.php'; require $base . 'cms/_version.php'; $db = new AdaptorMysql(); // Check to see if we have a sufficient schema installed if ($db->query("SHOW TABLES LIKE 'cms_info'")) { if ($q = $db->queryRow("SELECT * FROM cms_info WHERE name = 'schema_version'")) { if ($q['value'] >= REQUIRED_SCHEMA_VERSION) { die('You have an up to date schema'); } } } //run schema patch $sql = "alter table `cms_cols` change column `edit_channel` `edit_channel` varchar(20) not null default '' after `default_value`;\nalter table `cms_cols` change column `edit_module` `edit_module` varchar(20) not null default '' after `edit_channel`;\nalter table `cms_cols` change column `edit_mode` `edit_mode` varchar(20) not null default '' after `edit_module`;\nalter table `cms_cols` change column `process_channel` `process_channel` varchar(20) not null default '' after `edit_config`;\nalter table `cms_cols` change column `process_mode` `process_mode` varchar(20) not null default '' after `process_module`;\nalter table `cms_headers` change column `mode` `mode` varchar(255) not null default '' after `table_name`;\nalter table `cms_relations` change column `display` `display` varchar(255) not null default '' after `column_child`;\nalter table `cms_tables` change column `display_mode` `display_mode` varchar(20) not null default '' after `sort_default`;\nCREATE TABLE `cms_info` (\n `name` varchar(40) NOT NULL default '',\n `value` varchar(255) NOT NULL default '',\n PRIMARY KEY (`name`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8;\ninsert into `cms_info` values('schema_version','1.0.14');"; $schema = explode(';', $sql); array_pop($schema); foreach ($schema as $row) { $db->sql($row); } function processTable($q, $table) {
public function getData($config = null) { //needs to function in both edit and insert modes, obviously $this->table = $config['table']; $this->id = $config['id']; $this->channel = $config['channel']; if ($config['query_action'] == 'insert') { $this->mode = 'add'; } else { $this->mode = 'edit'; } //get table description data $this->tableMeta = AdaptorMysql::query("SHOW COLUMNS FROM {$this->table}", MYSQL_BOTH); //get key //default, set as first column $this->key = $this->tableMeta[0]['Field']; //find real primary key foreach ($this->tableMeta as $column) { if ($column['Key'] == 'PRI') { $this->key = $column['Field']; } } $q = $this->db->queryRow("SELECT * FROM `" . $this->table . "` WHERE " . $this->key . " = '" . $this->id . "'"); $this->data = array(); $this->col_config = false; foreach ($this->tableMeta as $col) { //check for config info here $q_col = false; //get configuration data for form $q_c = array(); //get all the base config $tA = Utils::checkArray(_ControllerFront::$config['cols'], array('column_name' => $col['Field']), true); if (is_array($tA)) { $q_c = $tA; } //get anything from the blackbird_cols if ($q_sql = $this->db->query("SELECT * FROM " . BLACKBIRD_TABLE_PREFIX . "cols WHERE column_name = '{$col['Field']}' ORDER BY table_name,edit_mode,edit_channel")) { $q_c = array_merge($q_c, $q_sql); } if (!$q_col) { $q_col = Utils::checkArray($q_c, array('table_name' => $this->table, 'edit_mode' => $this->mode, 'edit_channel' => $this->channel)); if (!$q_col) { $q_col = Utils::checkArray($q_c, array('table_name' => $this->table, 'edit_mode' => $this->mode, 'edit_channel' => '')); } } if (!$q_col) { $q_col = Utils::checkArray($q_c, array('table_name' => $this->table, 'edit_mode' => '', 'edit_channel' => $this->channel)); if (!$q_col) { $q_col = Utils::checkArray($q_c, array('table_name' => $this->table, 'edit_mode' => '', 'edit_channel' => '')); } } if (!$q_col) { $q_col = Utils::checkArray($q_c, array('table_name' => '*', 'edit_mode' => $this->mode, 'edit_channel' => $this->channel)); if (!$q_col) { $q_col = Utils::checkArray($q_c, array('table_name' => '*', 'edit_mode' => $this->mode, 'edit_channel' => '')); } } if (!$q_col) { $q_col = Utils::checkArray($q_c, array('table_name' => '*', 'edit_mode' => '', 'edit_channel' => $this->channel)); if (!$q_col) { $q_col = Utils::checkArray($q_c, array('table_name' => '*', 'edit_mode' => '', 'edit_channel' => '')); } } $value = $q[$col['Field']]; $config = $q_col; //flow in the default value only if creating a new record if ($q_col && $this->mode == 'add') { if ($q_col['default_value'] != '') { $value = $q_col['default_value']; } } if ($this->mode == 'edit' && !_ControllerFront::$session->getPermissions('update', $this->table)) { //turn to readonly - check on foreign keys later if (is_array($config)) { $config['edit_module'] = 'readonly'; } else { $config = array('table_name' => $this->table, 'column_name' => $col['Field'], 'validate' => '', 'default_value' => '', 'edit_module' => 'readonly', 'edit_config' => '', 'display_name' => '', 'help' => ''); } } $this->data[$col['Field']] = array('name' => $col['Field'], 'value' => $value, 'type' => $col['Type'], 'config' => $config); } return $this->data; }
public function getData($table = '') { if ($table != '') { $this->table = $table; } //set necessary variables $table_parent = Utils::setVar("table_parent", ''); $id_parent = Utils::setVar("id_parent", ''); $this->sql = ''; //these should be mapped in from the controller - not set here $sort_dir = Utils::setVar("sort_dir", "DESC"); $offset = Utils::setVar("offset", "0"); $limit = Utils::setVar("limit", "100"); $search = Utils::setVar("search"); $mode = Utils::setVar("mode", "main"); //get table description data $this->tableMeta = AdaptorMysql::query("SHOW COLUMNS FROM {$this->table}", MYSQL_BOTH); $this->key = AdaptorMysql::getPrimaryKey($this->table); $sort_col = Utils::setVar("sort_col", $this->key); //check for config info here $q_col = false; //get configuration data for form $q_c = array(); //get all the base config $tA = Utils::checkArray(_ControllerFront::$config['tables'], array('table_name' => $this->table), true); if (is_array($tA)) { $q_c = $tA; } if ($q_sql = $this->db->query("SELECT * FROM " . BLACKBIRD_TABLE_PREFIX . "tables WHERE table_name = '{$this->table}' ORDER BY table_name,display_mode")) { $q_c = array_merge($q_c, $q_sql); } if (!$q_col) { if ($mode == 'main') { $q_col = Utils::checkArray($q_c, array('table_name' => $this->table, 'display_mode' => 'main')); if (!$q_col) { $q_col = Utils::checkArray($q_c, array('table_name' => $this->table, 'display_mode' => '')); } } if ($mode == 'related') { $q_col = Utils::checkArray($q_c, array('table_name' => $this->table, 'display_mode' => 'related')); if (!$q_col) { $q_col = Utils::checkArray($q_c, array('table_name' => $this->table, 'display_mode' => '')); } } } //column description information $fields = array(); if ($q_col['cols_default'] == "") { $select_cols = '*'; } else { $select_cols = $q_col['cols_default']; $fields = explode(",", $select_cols); } if ($select_cols == "*") { $fields = array(); for ($i = 0; $i < count($this->tableMeta); $i++) { $row = $this->tableMeta[$i]; $fields[] = $row[0]; } } //filters and WHERE $filterA = array(); $this->filtersA = array(); $whereA = array(); $where = 'WHERE '; $where .= $this->sql; $filterWhere = ''; if ($table == BLACKBIRD_TABLE_PREFIX . 'history') { $filterWhere = $this->sql; $label = '_History_'; } else { if ($table_parent != '') { $relation = AdaptorMysql::queryRow("SELECT * FROM " . BLACKBIRD_TABLE_PREFIX . "relations WHERE table_parent = '{$table_parent}' AND table_child = '{$table}'"); $q_parent = AdaptorMysql::queryRow("SELECT * FROM {$table_parent} WHERE id = {$id_parent}"); $sql_val = $q_parent[$relation['column_parent']]; $whereA[] = "{$relation['column_child']} = '{$sql_val}'"; $filterWhere = "{$relation['column_child']} = '{$sql_val}'"; //from build in a page if (isset($this->config['sql_where'])) { $whereA[] = $this->config['sql_where']; $filterWhere .= ' AND ' . $this->config['sql_where']; } //from build in remote if (isset($_REQUEST['sql_where'])) { $whereA[] = stripslashes($_REQUEST['sql_where']); $filterWhere .= ' AND ' . stripslashes($_REQUEST['sql_where']); } $label = $relation['label']; } else { $label = $table; } } if ($search != "") { $q = $this->db->query("SHOW COLUMNS FROM {$this->table}", MYSQL_BOTH); $search_fields = array(); for ($i = 0; $i < count($q); $i++) { $row = $q[$i]; $search_fields[] = $row[0]; } //Generate search $mySearch = "'%" . mysql_real_escape_string(stripslashes(trim($search))) . "%'"; $rSearch = AdaptorMysql::generateSearch($search_fields, $mySearch); } $q_filters = AdaptorMysql::query("SELECT column_name FROM " . BLACKBIRD_TABLE_PREFIX . "cols WHERE (table_name = '*' OR table_name = '{$table}') AND filter != ''"); if ($q_filters) { //loop through and find intersections foreach ($q_filters as $filter) { $col = $filter['column_name']; if (in_array($col, $fields)) { $filterA[] = $col; $_filter = array(); if (isset($_REQUEST['filter_' . $col])) { if ($_REQUEST['filter_' . $col] != '') { $t = $_REQUEST['filter_' . $col]; $whereA[] = "{$col} = '{$t}'"; //$this->filtersA[] = array('col'=>$col,'value'=>$t); $_filter['col'] = $col; $_filter['value'] = $t; } } //query up option data $filterWhere != '' ? $w = 'WHERE ' . $filterWhere : ($w = ''); $optionA = array(); $field = $col; if ($q_select = AdaptorMysql::query("SELECT DISTINCT `{$field}` FROM `{$table}` {$w} ORDER BY `{$field}`")) { foreach ($q_select as $row) { $sel = ''; if (isset($_REQUEST['filter_' . $field])) { if ($_REQUEST['filter_' . $field] == $row[$field]) { $sel = 'selected="selected"'; } } $tv = _ControllerFront::formatCol($field, $row[$field], $table); $q_c = AdaptorMysql::query("SELECT * FROM " . BLACKBIRD_TABLE_PREFIX . "cols WHERE column_name = '{$field}'"); if ($q_c) { $q_col = Utils::checkArray($q_c, array('table_name' => $table)); if (!$q_col) { $q_col = Utils::checkArray($q_c, array('table_name' => '*')); } if ($q_col) { if ($q_col['filter'] != '') { $tA = _ControllerFront::parseConfig($q_col['filter']); if (isset($tA['filter_length'])) { if (strlen(strip_tags($tv)) > $tA['filter_length']) { $tv = substr(strip_tags($tv), 0, $tA['filter_length']) . '...'; } } } } } $optionA[] = array('value' => $row[$field], 'label' => $tv, 'selected' => $sel); } } //sort it $optionA = Utils::arraySort($optionA, 'label'); $_filter['options'] = $optionA; $this->filtersA[$field] = $_filter; } } } if (count($whereA) > 0) { if ($where != 'WHERE ') { $where .= ' AND '; } $where .= join($whereA, ' AND '); } else { if ($where == 'WHERE ') { $where = ''; } } if ($search == '') { $query_data = AdaptorMysql::query("SELECT {$select_cols} FROM `{$table}` {$where} ORDER BY `{$sort_col}` {$sort_dir} LIMIT {$limit} OFFSET {$offset}"); if ($query_data) { $rT = count($query_data); } else { $rT = 0; } $q2 = AdaptorMysql::query("SELECT * FROM {$table} {$where}"); if ($q2) { $rows_total = count($q2); } else { $rows_total = 0; } } else { if ($where == '') { $where = 'WHERE '; } if ($where != 'WHERE ' && $rSearch != '') { $where .= ' AND ('; $rSearch = $rSearch . ')'; } $query_data = AdaptorMysql::query("SELECT {$select_cols} FROM `{$table}` {$where} {$rSearch} ORDER BY `{$sort_col}` LIMIT {$limit} OFFSET {$offset}"); $rT = count($query_data); $q2 = AdaptorMysql::query("SELECT * FROM `{$table}` {$where} {$rSearch}"); if ($q2) { $rows_total = count($q2); } else { $rows_total = 0; } } $this->recordSet = array(); //build recordSet if ($query_data) { foreach ($query_data as $row) { $tA = array(); for ($j = 0; $j < count($fields); $j++) { $data = _ControllerFront::formatCol($fields[$j], $row[$fields[$j]], $table); $tA[$fields[$j]] = array('col' => $fields[$j], 'value' => $data); } //convert to the key $this->recordSet[$row[$this->key]] = _ControllerFront::injectData($tA, $table, 'body'); } } //headerData $tA = array(); for ($j = 0; $j < count($fields); $j++) { isset($row[$j]) ? $value = $row[$j] : ($value = ''); $data = _ControllerFront::formatCol($fields[$j], $value, $table); $tA[$fields[$j]] = array('col' => $fields[$j], 'value' => $data); } $this->headerData = _ControllerFront::injectData($tA, $table, 'head'); $delete_allowed = false; //if($this->cms->session->privs("delete",$table)){ // $delete_allowed = true; //} return array('headerData' => $this->headerData, 'rowData' => $this->recordSet, 'sort_col' => $sort_col, 'sort_dir' => $sort_dir, 'table' => $this->table, 'rows_total' => $rows_total, 'limit' => $limit, 'offset' => $offset, 'mode' => $mode, 'filtersA' => $this->filtersA, 'filterA' => $filterA, 'search' => $search); }
private function setConfig() { self::$config = array(); $tA = array(); $tA[] = array('table_name' => '*', 'column_name' => 'id', 'edit_module' => 'readonly', 'edit_mode' => 'edit'); $tA[] = array('table_name' => '*', 'column_name' => 'active', 'edit_module' => 'boolean', 'filter' => '<config><filter>1</filter></config>'); $tA[] = array('table_name' => '*', 'column_name' => 'created', 'edit_module' => 'readonly', 'edit_mode' => 'edit', 'process_module' => 'timestamp'); $tA[] = array('table_name' => '*', 'column_name' => 'modified', 'edit_module' => 'readonly', 'edit_mode' => 'edit', 'process_module' => 'timestamp'); $tA[] = array('table_name' => '*', 'column_name' => 'date', 'edit_module' => 'selectDate'); $tA[] = array('table_name' => '*', 'column_name' => 'state', 'edit_module' => 'selectState'); $tA[] = array('table_name' => '*', 'column_name' => 'country', 'edit_module' => 'selectCountry'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'groups', 'column_name' => 'admin', 'edit_module' => 'boolean', 'filter' => '<config><filter>1</filter></config>', 'help' => 'Admin users are able to manage users and groups. Limited access to Blackbird configuration is also available.'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'groups', 'column_name' => 'tables', 'edit_module' => 'plugin', 'process_module' => 'plugin'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'users', 'column_name' => 'password', 'display_name' => 'Password Reset', 'edit_module' => 'plugin', 'edit_mode' => 'edit', 'process_module' => 'plugin', 'process_mode' => 'update'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'users', 'column_name' => 'password', 'edit_module' => 'plugin', 'edit_mode' => 'add', 'process_module' => 'plugin', 'process_mode' => 'insert'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'users', 'column_name' => 'groups', 'edit_module' => 'plugin', 'process_module' => 'plugin'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'users', 'column_name' => 'super_user', 'edit_module' => 'hidden'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'history', 'column_name' => 'table_name', 'filter' => '<config><filter>1</filter></config>'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'history', 'column_name' => 'action', 'filter' => '<config><filter>1</filter></config>'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'history', 'column_name' => 'user_id', 'filter' => '<config><filter>1</filter></config>'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'cols', 'column_name' => 'edit_channel', 'edit_module' => 'selectStatic', 'edit_config' => ' <config><data_csv>main,related</data_csv></config>'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'cols', 'column_name' => 'edit_mode', 'edit_module' => 'selectStatic', 'edit_config' => ' <config><data_csv>edit,insert</data_csv></config>'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'cols', 'column_name' => 'process_channel', 'edit_module' => 'selectStatic', 'edit_config' => ' <config><data_csv>main,related</data_csv></config>'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'cols', 'column_name' => 'process_mode', 'edit_module' => 'selectStatic', 'edit_config' => ' <config><data_csv>update,insert</data_csv></config>'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'cols', 'column_name' => 'edit_module', 'edit_module' => 'selectStatic', 'edit_config' => ' <config><data_csv>plugin,boolean,hidden,readonly,checkbox,fileField,selectDefault,selectParent,selectFiles,selectStatic,selectDate,selectDateTime,selectState,selectCountry,text,textarea,listManager</data_csv></config>'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'cols', 'column_name' => 'process_module', 'edit_module' => 'selectStatic', 'edit_config' => ' <config><data_csv>plugin,position,file</data_csv></config>'); /* $tA[] = array('table_name'=>BLACKBIRD_TABLE_PREFIX . 'cols','column_name'=>'table_name','edit_module'=>'selectDefault','edit_config'=>' <config><select_sql>SHOW TABLES</select_sql><col_value>0</col_value><col_display>0</col_display><allow_null>false</allow_null></config>'); */ $q = AdaptorMysql::query("SHOW COLUMNS FROM `" . BLACKBIRD_TABLE_PREFIX . "cols`"); self::$config['cols'] = self::normalizeArray($tA, $q); $tA = array(); //need to add active to user $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'users', 'cols_default' => 'id,firstname,lastname,email,groups', 'in_nav' => 1); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'groups', 'cols_default' => 'id,active,name,admin', 'in_nav' => 1); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'history', 'cols_default' => '*', 'in_nav' => 1); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'cols', 'cols_default' => 'id,table_name,column_name,edit_module,edit_mode,process_module,process_mode,validate,filter,help'); $tA[] = array('table_name' => BLACKBIRD_TABLE_PREFIX . 'tags', 'cols_default' => 'id,name', 'in_nav' => 1); $q = AdaptorMysql::query("SHOW COLUMNS FROM `" . BLACKBIRD_TABLE_PREFIX . "tables`"); self::$config['tables'] = self::normalizeArray($tA, $q); }