function write_submitable_entity_info() { echo "<table>"; if ($this->entity->description()) { echo "<tr><td>Description</td><td>" . nl2br(htmlspecialchars($this->entity->description())) . "</td>"; } echo "<tr><td>Can submit</td><td>" . format_bool($this->entity->active()) . "</td>"; $active_range = $this->entity->active_range(); if ($active_range->start > now()) { echo "<tr><td>Starts</td><td>" . format_date($active_range->start) . "</td>"; } if ($this->entity->attribute("deadline") == NULL) { echo "<tr><td>Deadline</td><td>" . format_date($active_range->end, true) . "</td>"; } else { echo "<tr><td>Deadline</td><td>" . format_date(parse_date($this->entity->attribute("deadline")), true) . "</td>"; } echo "<tr><td>Language</td><td>" . $this->entity->language()->name . "</td>"; echo "<tr><td>Judging</td><td>"; if ($this->entity->compile()) { if ($this->entity->has_testcases()) { echo "Your submission will be compiled and tested. "; } else { echo "Your submission will be compiled. "; } if ($this->entity->attribute_bool('keep best')) { // Arnold says: "This is confusing, don't show" //echo "The best solution counts."; } else { echo "The last solution counts."; } } else { echo "All submissions are accepted."; } // downloadable files? $files = $this->entity->downloadable_files(); if ($files) { $downloads = array(); foreach ($files as $file) { $ext = pathinfo($file, PATHINFO_EXTENSION); $downloads[] = '<a href="download_entity.php' . htmlspecialchars($this->entity->path()) . '?f=' . urlencode($file) . '" class="file ' . $ext . '">' . htmlspecialchars($file) . '</a>'; } if (count($files) > 1) { array_unshift($downloads, '<a href="download_entity.php' . htmlspecialchars($this->entity->path()) . '?all=1" class="file zip">All files as zip</a>'); } echo "<tr><td>Files</td><td class=\"list-like\">" . implode(' | ', $downloads) . "</td></tr>"; } echo "</td>"; echo "</table>"; }
function phphoto_echo_admin_images($db) { phphoto_upload_image($db); phphoto_image_thumbnails($db); $order_by = isset($_GET[GET_KEY_SORT_COLUMN]) ? $_GET[GET_KEY_SORT_COLUMN] : 2; $items_per_page = isset($_GET[GET_KEY_ITEMS_PER_PAGE]) ? $_GET[GET_KEY_ITEMS_PER_PAGE] : DEFAULT_ITEMS_PER_PAGE; assert(is_numeric($items_per_page)); // prevent SQL injections $page_number = isset($_GET[GET_KEY_PAGE_NUMBER]) ? $_GET[GET_KEY_PAGE_NUMBER] : 0; assert(is_numeric($page_number)); // prevent SQL injections $sql = "SELECT CEIL(COUNT(*) / {$items_per_page}) AS pages FROM images"; $pages = phphoto_db_query($db, $sql); $pages = $pages[0]['pages'] > 0 ? $pages[0]['pages'] : 1; $sql = sprintf("\n SELECT\n id,\n IF (LENGTH(title) > 0, title, filename) AS name,\n active,\n width,\n height,\n (SELECT COUNT(*) FROM image_to_gallery WHERE image_id = id) AS galleries,\n (SELECT COUNT(*) FROM image_to_tag WHERE image_id = id) AS tags,\n views,\n views / (SELECT SUM(views) FROM images) AS popularity\n FROM\n images\n ORDER BY\n %s\n LIMIT\n " . $page_number * $items_per_page . ", {$items_per_page}", mysql_real_escape_string($order_by, $db)); $header = array(phphoto_text($db, 'header', 'thumbnail'), "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=2'>" . phphoto_text($db, 'header', 'name') . "</a>", "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=3'>" . phphoto_text($db, 'header', 'active') . "</a>", "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=4'>" . phphoto_text($db, 'header', 'resolution') . "</a>", "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=6'>" . phphoto_text($db, 'header', 'galleries') . "</a>", "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=7'>" . phphoto_text($db, 'header', 'tags') . "</a>", "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=8'>" . phphoto_text($db, 'header', 'views') . "</a>", ' '); $max_text_length = 12; $data = array(); foreach (phphoto_db_query($db, $sql) as $row) { array_push($data, array("<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_IMAGE_ID . "={$row['id']}'>\n <img src='image.php?" . GET_KEY_IMAGE_ID . "={$row['id']}t' class='thumbnail' /></a>", wordwrap(format_string($row['name']), 20, '<br>', true), format_bool($row['active']), $row['width'] . 'x' . $row['height'] . '<br>' . phphoto_image_aspect_ratio($row['width'], $row['height']), $row['galleries'], $row['tags'], $row['views'] . " (" . round($row['popularity'] * 100) . "%)", !$row['galleries'] && !$row['tags'] ? "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_OPERATION . '=' . GET_VALUE_DELETE . '&' . GET_KEY_IMAGE_ID . "={$row['id']}'><img src='./icons/process-stop.png' /></a>" : "<img src='./icons/process-stop-inactive.png' />")); } echo "\n<div class='admin'>"; echo "\n <h1>" . phphoto_text($db, 'section', 'images') . "</h1>"; $url_previous = CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_PAGE_NUMBER . '=' . ($page_number - 1); $url_next = CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_PAGE_NUMBER . '=' . ($page_number + 1); $footer = array(phphoto_page_numbering($db, $page_number, $pages, $url_previous, $url_next)); phphoto_to_html_table($data, $header, $footer); echo "\n</div>"; }