private function _buildForm() { //the master loopage //do a few things different if we're editing vs inserting a new record.. however not much //use output buffering to feed this to the view... this is a unique controller driven situation //since it's almost entirely logic based and presentation uses markup snippets from the Forms library ob_start(); $_name_space = $this->name_space . '_'; //processing instructions Forms::hidden('name_space', $this->name_space, array('omit_id' => true)); Forms::hidden('mode', $this->mode, array('omit_id' => true)); Forms::hidden('channel', $this->channel, array('omit_id' => true)); Forms::hidden('table', $this->table, array('omit_id' => true)); Forms::hidden('query_action', $this->query_action, array('omit_id' => true)); $recordData = $this->model->data; $row_data = $recordData; //Relation fields if ($this->channel == "related") { $sql = "SELECT * FROM " . BLACKBIRD_TABLE_PREFIX . "relations WHERE table_parent = '" . $_POST['table_parent'] . "' AND table_child = '{$this->table}'"; if ($q_relation = AdaptorMysql::queryRow($sql)) { $i = 0; foreach ($recordData as $column) { if ($column['name'] == $q_relation['column_child']) { array_splice($recordData, $i, 1); break; } $i++; } $q_parent = AdaptorMysql::queryRow("SELECT * FROM " . $_POST['table_parent'] . " WHERE id = " . $_POST['id_parent']); Forms::hidden($_name_space . $q_relation['column_child'], $q_parent[$q_relation['column_parent']]); Forms::hidden('table_parent', $_POST['table_parent'], array('omit_id' => true)); Forms::hidden('id_parent', $q_parent[$q_relation['column_parent']], array('omit_id' => true)); } } //loop items foreach ($recordData as $column) { $options = array(); $col_type = strtolower($column['type']); $value = $column['value']; $col_ready = false; $display_name = Utils::titleCase(str_replace('_', ' ', $column['name'])); $options['label'] = $display_name; $options['name_space'] = $_name_space; $options['db'] = AdaptorMysql::getInstance(); $options['nullable'] = AdaptorMysql::isNullable($this->table, $column['name']); //For primary key that's autoincrementing if ($column['name'] == 'id') { if ($this->query_action == "update") { Forms::hidden($_name_space . $column['name'], $value, $options); } $col_ready = true; } //plugins //col_config needs to be created for each column in the model = FAIL if ($column['config'] && !$col_ready) { $q_col = $column['config']; if ($q_col['default_value'] != '' && $this->mode == "insert") { $value = $q_col['default_value']; } if (strlen($q_col['help']) > 1) { $options['tip'] = $q_col['help']; } if ($q_col['display_name'] != '') { $display_name = $q_col['display_name']; } $options['label'] = $display_name; $module = $q_col['edit_module']; if (strlen($q_col['edit_config']) > 1) { $config = _ControllerFront::parseConfig($q_col['edit_config']); $options = array_merge($options, $config); } if ($q_col['validate'] != '') { $options = array_merge($options, _ControllerFront::parseConfig($q_col['validate'])); } if ($module != "") { switch ($module) { case "module": break; case "plugin": $options['table'] = $this->table; $options['mode'] = $this->mode; $options['row_data'] = $row_data; $options['id'] = $this->id; $options['col_name'] = $column['name']; _ControllerFront::pluginColumnEdit($_name_space . $column['name'], $value, $options); $col_ready = true; break; case "position": //build a selectDefault but with special options ehh $options['col_display'] = $column['name']; $options['col_value'] = $column['name']; //do it manual style, to accomodate constraint change or late entries //do a relative selection of position, based upon existing list.. oh! //factor in the contraint if set //factor in null if (isset($config['col_constraint'])) { //check if we're nullable if (AdaptorMysql::isNullable($this->table, $config['col_constraint']) && Utils::isNull($row_data[$config['col_constraint']]['value'])) { $_v = "IS NULL"; } else { $_v = ' = \'' . $row_data[$config['col_constraint']]['value'] . '\''; } $options['select_sql'] = "SELECT * FROM `{$this->table}` WHERE `{$config['col_constraint']}` " . $_v . " ORDER BY `{$column['name']}`"; } else { $options['select_sql'] = "SELECT * FROM `{$this->table}` ORDER BY `{$column['name']}`"; } $options['table'] = $this->table; $options['col_name'] = $column['name']; $options['id'] = $this->id; $options['name_space'] = $_name_space; $options['label'] = $display_name; $options['allow_null'] = false; Forms::selectDefault($_name_space . $column['name'], $value, $options); $col_ready = true; break; case "slug": $source = isset($config['col_source']) ? $_name_space . $config['col_source'] : null; Forms::text($_name_space . $column['name'], $value, $options); print ' <script type="text/javascript"> Event.observe(window,\'load\', function(){createSlug(\'' . $_name_space . $column['name'] . '\',\'' . $source . '\')}, true); </script> '; $col_ready = true; break; case "disabled": $col_ready = true; break; default: $options['table'] = $this->table; $options['col_name'] = $column['name']; $options['id'] = $this->id; $options['name_space'] = $_name_space; $options['label'] = $display_name; //add database datasource for countries and states if ($module == 'selectState') { $options['datasource'] = BLACKBIRD_TABLE_PREFIX . 'states'; } if ($module == 'selectCountry') { $options['datasource'] = BLACKBIRD_TABLE_PREFIX . 'countries'; } Forms::$module($_name_space . $column['name'], $value, $options); $col_ready = true; break; } } } //defaults if (!$col_ready) { switch (true) { case $col_type == 'datetime' || $col_type == 'timestamp': Forms::selectDateTime($_name_space . $column['name'], $value, $options); break; case $col_type == 'date': Forms::selectDate($_name_space . $column['name'], $value, $options); break; case $col_type == 'time': Forms::selectTime($_name_space . $column['name'], $value, $options); break; case $col_type == 'text' || $col_type == 'longtext' || $col_type == 'tinytext' || $col_type == 'mediumtext': Forms::textarea($_name_space . $column['name'], $value, $options); break; default: Forms::text($_name_space . $column['name'], $value, $options); break; } } } $r = ob_get_contents(); ob_end_clean(); return $r; }
function plugin__record_column_edit($name, $value, $options) { if ($options['col_name'] == 'password' && $options['table'] == BLACKBIRD_USERS_TABLE) { $options['type'] = 'password'; Forms::text($name, '', $options); } if ($options['col_name'] == 'user_id' && $options['table'] == BLACKBIRD_TABLE_PREFIX . 'history') { $q = $options['db']->query("SELECT email FROM " . BLACKBIRD_USERS_TABLE . " WHERE id = '{$value}'"); Forms::readonly($name, $q['email'], $options); } if ($options['col_name'] == 'groups' && $options['table'] == BLACKBIRD_USERS_TABLE) { $q = $options['db']->query("SELECT id,name FROM " . BLACKBIRD_TABLE_PREFIX . "groups ORDER BY name"); $r = '<ul>'; $q_links = $options['db']->query("SELECT * FROM " . BLACKBIRD_TABLE_PREFIX . "users__groups WHERE user_id = '{$options['id']}'"); foreach ($q as $group) { $v = ''; if (is_array($q_links)) { $tA = Utils::checkArray($q_links, array('group_id' => $group['id'])); if (is_array($tA)) { $v = 'Y'; } } $r .= '<li>' . Forms::checkboxBasic('group_' . $group['id'], $v, array('class' => 'checkbox noparse', 'label' => $group['name'])) . '</li>'; } $r .= '</ul>'; $options['label'] = "Groups"; Forms::buildElement($name, $r, $options); Forms::hidden($name, '', array('omit_id' => true)); } if ($options['col_name'] == 'tables' && $options['table'] == BLACKBIRD_TABLE_PREFIX . 'groups') { $q = $options['db']->query("SHOW TABLE STATUS"); $tA = explode(',', $value); $privA = array('select', 'insert', 'update', 'delete'); $tableA = array(); //loop her and throw out system tables $tlen = strlen(BLACKBIRD_TABLE_PREFIX); foreach ($q as $table) { //if pattern fails add to list if (substr($table['Name'], 0, $tlen) != BLACKBIRD_TABLE_PREFIX) { $tableA[] = $table['Name']; } } // $tA = _ControllerFront::getRoute(); if (isset($tA['id'])) { $group_id = $tA['id']; $q_permissions = $options['db']->query("SELECT * FROM " . BLACKBIRD_TABLE_PREFIX . "permissions WHERE group_id = '{$group_id}' ORDER BY table_name"); } else { $q_permissions = null; } $r = '<div id="bb_group_permissions">'; $r .= '<p>All permissions - <a href="#" id="matrix_on">ON</a> | <a href="#" id="matrix_off">OFF</a></p>'; $r .= '<table id="matrix"> <tr><th>Table Name</th>'; foreach ($privA as $priv) { $r .= '<th><a href="#" title="' . $priv . '" class="checktoggle column">' . ucfirst($priv) . '</a></th>'; } $r .= '</tr>'; /* $r .= '<tr><th></th>'; foreach($privA as $priv){ //$r .= '<th><input type="button" title="'.$priv.'" class="checktoggle column" value="col" /></th>'; } $r .= '</tr>'; */ foreach ($tableA as $table) { //used to rely upon a private comment to hide, no longer, just don't show any blackbird tables here $r .= '<tr>'; $r .= '<td><a href="#" title="' . $table . '" class="checktoggle row" >' . Utils::formatHumanReadable($table) . '</a></td>'; $tA = array(); if (is_array($q_permissions)) { $tA = Utils::checkArray($q_permissions, array('table_name' => $table)); } foreach ($privA as $priv) { $v = ''; if (isset($tA[$priv . '_priv'])) { if ($tA[$priv . '_priv'] == '1') { $v = 'Y'; } } $r .= '<td>' . Forms::checkboxBasic('table_' . $table . '_' . $priv, $v, array('class' => 'checkbox noparse col_' . $priv . ' row_' . $table, 'label' => '')) . '</td>'; } $r .= '</tr>'; } $r .= '</table></div>'; $options['label'] = "Tables"; Forms::buildElement($name, $r, $options); Forms::hidden($name, '', array('omit_id' => true)); } return true; }