public function home() { # Start the HTML $html = ''; # Get the list of projects if (!($projectsRaw = $this->databaseConnection->select($this->settings['database'], $this->settings['table'], $conditions = "status != 'proposed'", $columns = array(), true, $orderBy = "FIELD(status, 'developing','additional','specced','proposed','completed'), id DESC"))) { $html = "\n<p>There are no confirmed projects at present.</p>"; echo $html; return; } # Attach status string to the key for CSS styling purposes $projects = array(); foreach ($projectsRaw as $id => $project) { $key = $id . ' ' . lcfirst($project['status']); $projects[$key] = $project; } # Assemble fields foreach ($projects as $id => $project) { if ($this->userIsAdministrator) { $projects[$id]['id'] = "<a href=\"{$this->baseUrl}/projects/{$project['id']}/edit.html\"><strong>" . $projects[$id]['id'] . '</strong></a>'; } $projects[$id]['name'] = "<a href=\"{$projects[$id]['url']}\" target=\"_blank\">" . htmlspecialchars($projects[$id]['name']) . '</a>'; unset($projects[$id]['url']); $projects[$id]['status'] = ucfirst($projects[$id]['status']); unset($projects[$id]['client']); $projects[$id]['progress'] = nl2br(htmlspecialchars($projects[$id]['progress'])); } $allowHtml = array('id', 'name', 'progress'); # Find the earliest date $earliestDate = $this->databaseConnection->selectOneField($this->settings['database'], $this->settings['table'], 'finishDate', 'finishDate IS NOT NULL', array(), false, $orderBy = 'finishDate', $limit = 1); # Create the HTML $html .= "\n<p>The table below shows a list of all confirmed projects" . ($earliestDate ? ' since ' . date('F Y', strtotime($earliestDate . ' 12:00:00')) : '') . '.</p>'; if ($this->settings['generalHtml']) { $html .= "\n<p>This does not include <a href=\"{$this->baseUrl}/general.html\">general, ongoing work</a>.</p>"; } $html .= "\n<p>You can <a href=\"{$this->baseUrl}/add.html\">request a project</a>.</p>"; $tableHeadingSubstitutions = $this->databaseConnection->getHeadings($this->settings['database'], $this->settings['table']); $html .= "\n" . '<!-- Enable table sortability: --><script language="javascript" type="text/javascript" src="/sitetech/sorttable.js"></script>'; $html .= application::htmlTable($projects, $tableHeadingSubstitutions, 'lines sortable" id="sortable', $keyAsFirstColumn = false, false, $allowHtml, false, false, $addRowKeyClasses = true); # Show the HTML echo $html; }