コード例 #1
0
ファイル: CMovieView.php プロジェクト: britec/branac-base
    public function getTable($res, $rows)
    {
        // Get parameters
        $genre = isset($_GET['genre']) ? htmlentities($_GET['genre']) : null;
        $hits = isset($_GET['hits']) ? $_GET['hits'] : 8;
        $page = isset($_GET['page']) ? $_GET['page'] : 1;
        $id = isset($_GET['id']) ? $_GET['id'] : null;
        if ($id !== null) {
            return $this->getDetails($res);
            exit;
        }
        if ($genre) {
            $this->path[] = array('text' => $genre, 'url' => "?genre={$genre}");
        }
        // Check that incoming parameters are valid
        is_numeric($hits) or die('Check: Hits must be numeric.');
        is_numeric($page) or die('Check: Page must be numeric.');
        // Prepare the header row
        $admin = CUser::isAuthenticated() ? '<th>Admin</th>' : NULL;
        $tr = "<tr>\n        <th>Bild</th>\n        <th>Titel " . CFunc::orderby('title') . "</th>\n        <th>Synopsis</th>\n        <th>Rating " . CFunc::orderby('rating') . "</th>\n        <th>Genre</th>\n        <th>Pris</th>\n        {$admin}\n        </tr>";
        // Prepare the data rows
        foreach ($res as $key => $val) {
            $tmp = explode(',', $val->genre);
            $genres = [];
            foreach ($tmp as $gen) {
                $genres[] = "<a href='?genre={$gen}'>{$gen}</a>";
            }
            $genres = implode('<br>', $genres);
            $admin = CUser::isAuthenticated() ? "<th><a href='movie_edit.php?id={$val->id}'>Edit</a> <a href='movie_delete.php?id={$val->id}'>Delete</a></th>" : NULL;
            $synopsys = $val->synopsys;
            $words = explode(' ', $synopsys);
            if (count($words) >= 30) {
                $synopsys = implode(' ', array_splice($words, 0, 25));
                $synopsys .= " ...  <a href='?id={$val->id}'>Read more</a>";
            }
            $tr .= "<tr>\n            <td><a href='?id={$val->id}'>\n                <img src=img.php?src=img/movie/{$val->image}&amp;width=75&amp alt='{$val->title}'/>\n            </a></td>\n            <td>{$val->title}</td>\n            <td>{$synopsys}</td>\n            <td>{$val->rating}%</td>\n            <td>{$genres}</td>\n            <td>{$val->price} SEK</td>\n             {$admin}\n            </tr>";
        }
        // Prepare navigation bars and admin information
        $max = ceil($rows / $hits);
        $hitsPerPage = CFunc::getHitsPerPage(array(4, 8, 16), $hits);
        $navigatePage = CFunc::getPageNavigation($hits, $page, $max);
        $adminAnchors = CUser::isAuthenticated() ? "<p><a href='movie_create.php'>Ny film</a> <a href='movie_reset.php'>Återställ filmdatabasen</a></p>" : null;
        // Put rows in HTML-table with navigation bars
        $htmlTable = <<<EOD
<div class='dbtable'>
  <div class='rows'>{$rows} träffar. {$hitsPerPage}</div>
  <table>
  {$tr}
  </table>
  <div class='pages'>{$navigatePage}</div>
  {$adminAnchors}
</div>
EOD;
        return $htmlTable;
    }
コード例 #2
0
ファイル: CUserView.php プロジェクト: britec/branac-base
    public function getTable($res, $rows)
    {
        // Get parameters
        $hits = isset($_GET['hits']) ? $_GET['hits'] : 8;
        $page = isset($_GET['page']) ? $_GET['page'] : 1;
        $id = isset($_GET['id']) ? $_GET['id'] : null;
        // Check that incoming parameters are valid
        is_numeric($hits) or die('Check: Hits must be numeric.');
        is_numeric($page) or die('Check: Page must be numeric.');
        if ($id !== null) {
            return $this->getDetails($res[0]);
            exit;
        }
        // Prepare the table, firt the header row
        $admin = CUser::isUser() ? '<th>Admin</th>' : NULL;
        $tr = "<tr>\n        <th>Id</th>\n        <th>Akronym " . CFunc::orderby('acronym') . "</th>\n        <th>Namn  " . CFunc::orderby('name') . "</th>\n        <th>Roll</th>\n        {$admin}\n        </tr>";
        // Prepare the data rows
        foreach ($res as $key => $val) {
            $admin = CUser::isCurrentUser($val->id) ? "<a href='user_regedit.php?id={$val->id}'>Edit</a> <a href='user_delete.php?id={$val->id}'>Delete</a>" : NULL;
            $admin = CUser::isUser($val->id) ? "<td>{$admin}</td>" : NULL;
            $admin = CUser::isAuthenticated() ? "<td><a href='user_edit.php?id={$val->id}'>Edit</a> <a href='user_delete.php?id={$val->id}'>Delete</a></td>" : $admin;
            // $synopsys = CTextFilter::nl2br($val->synopsys);
            $href = CFunc::getQueryString(array('id' => $val->id));
            $tr .= "<tr>\n            </a></td>\n            <td>{$val->id}</td>\n            <td><a href='{$href}'>{$val->acronym}</a></td>\n            <td>{$val->name}</td>\n            <td>{$val->role}</td>\n            {$admin}\n            </tr>";
        }
        // Prepare navigation bars and admin information
        $max = ceil($rows / $hits);
        $hitsPerPage = CFunc::getHitsPerPage(array(4, 8, 16), $hits);
        $navigatePage = CFunc::getPageNavigation($hits, $page, $max);
        $adminAnchors = CUser::isAuthenticated() ? "<p><a href='user_create.php'>Skapa ny användare</a> <a href='user_reset.php'>Återställ användardatabasen</a></p>" : null;
        // Put rows in HTML-table with navigation bars
        $htmlTable = <<<EOD
<div class='dbtable'>
  <div class='rows'>{$rows} träffar. {$hitsPerPage}</div>
  <table>
  {$tr}
  </table>
  <div class='pages'>{$navigatePage}</div>
  {$adminAnchors}
</div>
EOD;
        return $htmlTable;
    }