コード例 #1
0
ファイル: UserController.php プロジェクト: xdev/blackbird
 public function Processreset()
 {
     $this->layout_view = null;
     $this->errorData = array();
     //check that it's a valid user
     if ($q = $this->model->checkUser($_POST['login_login'])) {
         //reset password
         if ($pass = $this->model->resetPassword($q['id'])) {
             //prep email
             $html_template = "<h2>Your password has been reset!</h2>";
             $html_template .= "<p>{$pass}</p>";
             $html_template .= "<p>To log in <a href=\"http://{$_SERVER['HTTP_HOST']}" . BASE . "user/login\">Click Here</a></p>";
             $message = array();
             $message['to_address'] = $q['email'];
             $message['to_name'] = $q['firstname'] . ' ' . $q['lastname'];
             $message['subject'] = 'Blackbird Password Reset';
             $message['body'] = $html_template;
             //email it out
             _ControllerFront::sendEmail($message);
             //refresh to a new page or something with a success message? or display inline, perhaps ,replacing the form with the success message (2.1)
             $this->view();
         } else {
             //needs to go in general error zone
             $this->errorData[] = array('field' => 'login', 'error' => 'Unable to reset password!');
         }
     } else {
         $this->errorData[] = array('field' => 'login', 'error' => 'Fail! No user exists.');
     }
     if (count($this->errorData) > 0) {
         $this->view(array('view' => '/_errors/remote', 'data' => array('mode' => '', 'query_action' => '', 'channel' => '', 'name_space' => 'login', 'table' => '', 'id' => '', 'errors' => $this->errorData)));
     }
 }
コード例 #2
0
ファイル: _ControllerFront.php プロジェクト: xdev/brickhouse
 public static function getInstance()
 {
     if (!self::$instance) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
コード例 #3
0
 public function Getimage()
 {
     $this->layout_view = null;
     $id = $_POST['id'];
     $table = $_POST['table'];
     $table_parent = $_POST['table_parent'];
     $name_space = $_POST['name_space'];
     $q_relation = AdaptorMysql::queryRow("SELECT * FROM " . BLACKBIRD_TABLE_PREFIX . "relations WHERE table_parent = '{$table_parent}' AND table_child = '{$table}'");
     $config = _ControllerFront::parseConfig($q_relation['config']);
     $this->view(array('view' => '_image', 'data' => array('id' => $id, 'table' => $table, 'config' => $config, 'name_space' => $name_space)));
 }
コード例 #4
0
ファイル: _Controller.php プロジェクト: xdev/blackbird
 public function prepUI()
 {
     $tablesA = _ControllerFront::$session->getNavigation();
     $this->view(array('container' => 'ui_nav', 'view' => '/_modules/ui_nav', 'data' => array('tableA' => $tablesA)));
     //do something here
     if (isset($this->route['table'])) {
         $table = $this->route['table'];
         $tablename = _ControllerFront::getTableName($table);
     } else {
         $table = '';
         $tablename = '';
     }
     $this->view(array('container' => 'ui_breadcrumb', 'view' => '/_modules/ui_breadcrumb', 'data' => array('table' => $table, 'tablename' => $tablename)));
     $this->view(array('container' => 'ui_session', 'view' => '/_modules/ui_session', 'data' => ''));
 }
コード例 #5
0
ファイル: DashboardModel.php プロジェクト: xdev/blackbird
 public function getChartTables($id = '')
 {
     $where = '';
     if ($id != '') {
         $where = " WHERE user_id = '{$id}' ";
     } else {
         $where = " WHERE user_id != '' ";
     }
     $q_tot = $this->db->queryRow("SELECT count(*) AS total FROM " . BLACKBIRD_TABLE_PREFIX . "history " . $where);
     if ($q = $this->db->query("SELECT count(*) AS total,table_name FROM " . BLACKBIRD_TABLE_PREFIX . "history " . $where . " GROUP BY table_name")) {
         $dataA = array();
         foreach ($q as $row) {
             $perc = $row['total'] / $q_tot['total'];
             $dataA[] = array('name' => _ControllerFront::getTableName($row['table_name']), 'total' => $row['total'], 'percent' => floor(100 * $perc), 'percent_actual' => round($perc * 100, 2));
         }
         return $this->formatChartData(Utils::arraySort($dataA, 'percent'));
     }
 }
コード例 #6
0
ファイル: TableModel.php プロジェクト: xdev/blackbird
 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);
 }
コード例 #7
0
ファイル: _ControllerFront.php プロジェクト: xdev/blackbird
    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);
    }
コード例 #8
0
ファイル: bootstrap.php プロジェクト: xdev/brickhouse
require_once LIB . 'Bobolink' . DS . 'database' . DS . 'AdaptorMysql.class.php';
// Bobolink classes (load any you want to use)
//require_once LIB . 'Bobolink' . DS . 'email'    . DS . 'EmailProtector.class.php';
//require_once LIB . 'Bobolink' . DS . 'forms'    . DS . 'Forms.class.php';
//require_once LIB . 'Bobolink' . DS . 'session'  . DS . 'Session.class.php';
//require_once LIB . 'Bobolink' . DS . 'utils'    . DS . 'Utils.class.php';
//require_once LIB . 'Bobolink' . DS . 'xml'      . DS . 'FlashMW.class.php';
//require_once LIB . 'Bobolink' . DS . 'xml'      . DS . 'XmlToArray.class.php';
/* LOAD PLUGINS ---------------------------------------------------------- */
require_once APP . 'plugins' . DS . 'pre_render.php';
require_once APP . 'plugins' . DS . 'post_render.php';
//require_once LIB . 'Brickhouse' . DS . 'plugins' . DS . 'sitemap.php';
/* CONTROLLER/ROUTER ----------------------------------------------------- */
//error handling
//$error = ErrorHandler::getInstance();
set_error_handler(array("ErrorHandler", "capture"));
// Only connect to the database if it is configured
if (isset($GLOBALS['DATABASE'])) {
    $db = AdaptorMysql::getInstance();
}
// Controller
$controller = _ControllerFront::getInstance();
// Router
//needs to follow the Front Controller so we can utilize the pre-parsed URI
$uA = $controller->getUri();
$uri = $uA['array'];
$routes = array();
//pull in predefined routes
require_once CONFIG . 'routes.php';
/* DISPATCH -------------------------------------------------------------- */
$controller->dispatch($routes);
コード例 #9
0
ファイル: RecordController.php プロジェクト: xdev/blackbird
    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;
    }
コード例 #10
0
ファイル: record_column_edit.php プロジェクト: xdev/blackbird
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>&nbsp;|&nbsp;<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;
}