コード例 #1
0
ファイル: Table.php プロジェクト: ixtel/tsugi
    public static function pagedTable($rows, $searchfields = array(), $orderfields = false, $view = false, $params = false)
    {
        if ($params === false) {
            $params = $_GET;
        }
        if ($orderfields === false) {
            $orderfields = $searchfields;
        }
        $page_start = isset($params['page_start']) ? $params['page_start'] + 0 : 0;
        if ($page_start < 0) {
            $page_start = 0;
        }
        $page_length = isset($params['page_length']) ? $params['page_length'] + 0 : self::$DEFAULT_PAGE_LENGTH;
        if ($page_length < 0) {
            $page_length = 0;
        }
        $search = '';
        if (isset($params['search_text'])) {
            $search = $params['search_text'];
        }
        $count = count($rows);
        $have_more = false;
        if ($count > $page_length) {
            $have_more = true;
            $count = $page_length;
        }
        echo '<div style="float:right">';
        if ($page_start > 0) {
            echo '<form style="display: inline">';
            echo '<input type="submit" value="Back" class="btn btn-default">';
            $page_back = $page_start - $page_length;
            if ($page_back < 0) {
                $page_back = 0;
            }
            Table::doForm($params, array('page_start' => $page_back));
            echo "</form>\n";
        }
        if ($have_more) {
            echo '<form style="display: inline">';
            echo '<input type="submit" value="Next" class="btn btn-default"> ';
            $page_next = $page_start + $page_length;
            Table::doForm($params, array('page_start' => $page_next));
            echo "</form>\n";
        }
        echo "</div>\n";
        echo '<form>';
        echo '<input type="text" id="paged_search_box" value="' . htmlent_utf8($search) . '" name="search_text">';
        Table::doForm($params, array('search_text' => false, 'page_start' => false));
        ?>
    <input type="submit" value="Search" class="btn btn-default">
    <input type="submit" value="Clear Search" class="btn btn-default"
    onclick="document.getElementById('paged_search_box').value = '';"
    >
    </form>
    <?php 
        if ($count < 1) {
            echo "<p>Nothing to display.</p>\n";
            return;
        }
        // print_r($orderfields);
        // echo("<hr>\n");
        // print_r($rows[0]);
        ?>

    <div style="padding:3px;">
    <table border="1" class="table table-hover table-condensed table-responsive">
    <tr>
    <?php 
        $first = true;
        $thispage = basename($_SERVER['PHP_SELF']);
        if ($view === false) {
            $view = $thispage;
        }
        foreach ($rows as $row) {
            $count--;
            if ($count < 0) {
                break;
            }
            if ($first) {
                echo "\n<tr>\n";
                $desc = isset($params['desc']) ? $params['desc'] + 0 : 0;
                $order_by = isset($params['order_by']) ? $params['order_by'] : '';
                foreach ($row as $k => $v) {
                    if (strpos($k, "_") === 0) {
                        continue;
                    }
                    if ($view !== false && strpos($k, "_id") !== false && is_numeric($v)) {
                        continue;
                    }
                    if (!Table::matchColumns($k, $orderfields)) {
                        echo "<th>" . CrudForm::fieldToTitle($k) . "</th>\n";
                        continue;
                    }
                    $override = array('order_by' => $k, 'desc' => 0, 'page_start' => false);
                    $d = $desc;
                    $color = "black";
                    if ($k == $order_by || $order_by == '' && $k == 'id') {
                        $d = ($desc + 1) % 2;
                        $override['desc'] = $d;
                        $color = $d == 1 ? 'green' : 'red';
                    }
                    $stuff = Table::doUrl($params, $override);
                    echo '<th>';
                    echo ' <a href="' . $thispage;
                    if (strlen($stuff) > 0) {
                        echo "?";
                        echo $stuff;
                    }
                    echo '" style="color: ' . $color . '">';
                    echo ucwords(str_replace('_', ' ', $k));
                    echo "</a></th>\n";
                }
                echo "</tr>\n";
            }
            $first = false;
            $link_name = false;
            echo "<tr>\n";
            foreach ($row as $k => $v) {
                if (strpos($k, "_") === 0) {
                    continue;
                }
                if ($view !== false && strpos($k, "_id") !== false && is_numeric($v)) {
                    $link_name = $k;
                    $link_val = $v;
                    continue;
                }
                echo "<td>";
                if ($link_name !== false) {
                    echo '<a href="' . $view . '?' . $link_name . "=" . $link_val . '">';
                    if (strlen($v) < 1) {
                        $v = $link_name . ':' . $link_val;
                    }
                }
                echo htmlent_utf8($v);
                if ($link_name !== false) {
                    echo '</a>';
                }
                $link_name = false;
                echo "</td>\n";
            }
            echo "</tr>\n";
        }
        echo "</table>\n";
        echo "</div>\n";
    }
コード例 #2
0
ファイル: Table.php プロジェクト: csev/tsugi-php
    public static function pagedTable($rows, $searchfields = array(), $orderfields = false, $view = false, $params = false, $extra_buttons = false)
    {
        if ($params == false) {
            $params = $_GET;
        }
        self::pagedHeader($rows, $searchfields, $orderfields, $view, $params, $extra_buttons);
        $count = count($rows);
        $page_length = isset($params['page_length']) ? $params['page_length'] + 0 : self::$DEFAULT_PAGE_LENGTH;
        if ($page_length < 0) {
            $page_length = 0;
        }
        // When we are doing paging, we select page_length+1 rows to know whether
        // we should show a Next button - but we don't want to show that extra
        // row in the output.
        if ($page_length > 0 && $count > $page_length) {
            $count = $page_length;
        }
        if ($count < 1) {
            echo "<p>Nothing to display.</p>\n";
            return;
        }
        // print_r($orderfields);
        // echo("<hr>\n");
        // print_r($rows[0]);
        ?>

    <div style="padding:3px;">
    <table border="1" class="table table-hover table-condensed table-responsive">
    <tr>
    <?php 
        $first = true;
        $thispage = basename($_SERVER['PHP_SELF']);
        if ($view === false) {
            $view = $thispage;
        }
        foreach ($rows as $row) {
            $count--;
            if ($count < 0) {
                break;
            }
            if ($first) {
                echo "\n<tr>\n";
                $desc = isset($params['desc']) ? $params['desc'] + 0 : 0;
                $order_by = isset($params['order_by']) ? $params['order_by'] : '';
                foreach ($row as $k => $v) {
                    if (strpos($k, "_") === 0) {
                        continue;
                    }
                    if ($view !== false && strpos($k, "_id") !== false && is_numeric($v)) {
                        continue;
                    }
                    if ($orderfields && !Table::matchColumns($k, $orderfields)) {
                        echo "<th>" . CrudForm::fieldToTitle($k) . "</th>\n";
                        continue;
                    }
                    $override = array('order_by' => $k, 'desc' => 0, 'page_start' => false);
                    $d = $desc;
                    $color = "normal";
                    $arrow = '';
                    if ($k == $order_by || $order_by == '' && $k == 'id') {
                        $d = ($desc + 1) % 2;
                        $override['desc'] = $d;
                        $color = $d == 1 ? 'success' : 'info';
                        $arrow = $d == 1 ? ' &uarr;' : ' &darr;';
                    }
                    $stuff = Table::doUrl($params, $override);
                    echo '<th class="' . $color . '">';
                    echo ' <a href="' . $thispage;
                    if (strlen($stuff) > 0) {
                        echo "?";
                        echo $stuff;
                    }
                    echo '">';
                    echo ucwords(str_replace('_', ' ', $k));
                    echo $arrow;
                    echo "</a></th>\n";
                }
                echo "</tr>\n";
            }
            $first = false;
            $link_name = false;
            echo "<tr>\n";
            foreach ($row as $k => $v) {
                if (strpos($k, "_") === 0) {
                    continue;
                }
                if ($view !== false && strpos($k, "_id") !== false && is_numeric($v)) {
                    $link_name = $k;
                    $link_val = $v;
                    continue;
                }
                echo "<td>";
                if ($link_name !== false) {
                    $detail = Table::makeUrl($view, $params, array($link_name => $link_val));
                    echo '<a href="' . $detail . '">';
                    if (strlen($v) < 1) {
                        $v = $link_name . ':' . $link_val;
                    }
                }
                echo htmlent_utf8($v);
                if ($link_name !== false) {
                    echo '</a>';
                }
                $link_name = false;
                $link_val = false;
                echo "</td>\n";
            }
            if ($link_val !== false) {
                echo "<td>";
                echo htmlent_utf8($link_val);
                echo "</td>\n";
            }
            echo "</tr>\n";
        }
        echo "</table>\n";
        echo "</div>\n";
    }
コード例 #3
0
ファイル: key-detail.php プロジェクト: shaamimahmed/tsugi
$current = getCurrentFileUrl(__FILE__);
$from_location = "keys.php";
$allow_delete = true;
$allow_edit = true;
$where_clause = '';
$query_fields = array();
if (isAdmin()) {
    $fields = array("key_id", "key_key", "secret", "created_at", "updated_at", "user_id");
} else {
    $fields = array("key_id", "key_key", "secret", "created_at", "updated_at");
    $where_clause .= "user_id = :UID";
    $query_fields[":UID"] = $_SESSION['id'];
}
// Handle the post data
$row = CrudForm::handleUpdate($tablename, $fields, $where_clause, $query_fields, $allow_edit, $allow_delete);
if ($row === CrudForm::CRUD_FAIL || $row === CrudForm::CRUD_SUCCESS) {
    header("Location: " . $from_location);
    return;
}
$OUTPUT->header();
$OUTPUT->bodyStart();
$OUTPUT->topNav();
$OUTPUT->flashMessages();
$title = "Key Entry";
echo "<h1>{$title}</h1>\n<p>\n";
$retval = CrudForm::updateForm($row, $fields, $current, $from_location, $allow_edit, $allow_delete);
if (is_string($retval)) {
    die($retval);
}
echo "</p>\n";
$OUTPUT->footer();
コード例 #4
0
ファイル: key-add.php プロジェクト: shaamimahmed/tsugi
// In the top frame, we use cookies for session.
define('COOKIE_SESSION', true);
require_once "../../config.php";
require_once $CFG->dirroot . "/pdo.php";
require_once $CFG->dirroot . "/lib/lms_lib.php";
use Tsugi\UI\CrudForm;
header('Content-Type: text/html; charset=utf-8');
session_start();
if (!(isset($_SESSION['id']) || isAdmin())) {
    die('Must be logged in or admin');
}
$from_location = "keys.php";
$tablename = "{$CFG->dbprefix}lti_key";
if (isAdmin()) {
    $fields = array("key_key", "key_sha256", "secret", "created_at", "updated_at", "user_id");
} else {
    $fields = array("key_key", "key_sha256", "secret", "created_at", "updated_at");
}
$retval = CrudForm::handleInsert($tablename, $fields);
if ($retval == CrudForm::CRUD_SUCCESS || $retval == CrudForm::CRUD_FAIL) {
    header("Location: {$from_location}");
    return;
}
$OUTPUT->header();
$OUTPUT->bodyStart();
$OUTPUT->topNav();
$OUTPUT->flashMessages();
echo "<h1>Adding Key Entry</h1>\n<p>\n";
CrudForm::insertForm($fields, $from_location);
echo "</p>\n";
$OUTPUT->footer();