function render_journal() { log_debug("journal_display", "Executing render_journal()"); if (!$this->sql_obj->data_num_rows) { // TODO: detect if the journal has entries which are being hidden by the filter options format_msgbox("important", "<p>This journal is either empty or has no entries matching your filter options</p>"); } else { // display the journal entries in date order $previousvalue = ""; foreach ($this->sql_obj->data as $data) { // resets $editlink = ""; // if this journal entry was added by this user, allow it to be edited if ($data["userid"] == $_SESSION["user"]["id"]) { if (!$data["locked"]) { // user is able to edit/delete this entry $editlink = " <a class=\"button_small\" href=\"index.php?page=" . $this->structure["form_process_page"] . "&id=" . $data["customid"] . "&journalid=" . $data["id"] . "&type=" . $data["type"] . "&action=edit\">edit</a> "; $editlink .= "<a class=\"button_small\" href=\"index.php?page=" . $this->structure["form_process_page"] . "&id=" . $data["customid"] . "&journalid=" . $data["id"] . "&type=" . $data["type"] . "&action=delete\">delete</a> "; } } /* Get the name of the user who submitted the forn */ $sql_user_obj = new sql_query(); $sql_user_obj->string = "SELECT realname FROM `users` WHERE id='" . $data["userid"] . "' LIMIT 1"; $sql_user_obj->execute(); if (!$sql_user_obj->num_rows()) { log_debug("journal_display", "Error: no user with ID of " . $data["userid"] . " exists!"); } else { $sql_user_obj->fetch_array(); } /* Format Fields */ $content = format_text_display($data["content"]); $post_time = date("d F Y H:i:s", $data["timestamp"]); /* Process the journal entry, depending on it's type. The following types of journal entries can exist: text A block of text content event Log message/record from the system */ switch ($data["type"]) { case "event": /* Event entries are a very useful way of making log records or notes in journals for record keeping/audit trail purposes. */ if ($previousvalue != "event") { print "<br>"; } print "<table width=\"100%\" cellpadding=\"0\">"; // header print "<tr><td width=\"100%\"><table width=\"100%\"><tr>"; print "<td width=\"50%\"><font style=\"font-size: 10px;\" color=\"#727272\">Event: " . $data["title"] . "</td>"; print "<td width=\"50%\" align=\"right\"><font style=\"font-size: 10px;\" color=\"#727272\">Posted by " . $sql_user_obj->data[0]["realname"] . " @ {$post_time}</font></td>"; print "</tr></table></td></tr>"; // events don't make any use of the content field print "</table>"; break; case "text": /* The standard entry is just a block of text. */ print "<br><table width=\"100%\" cellpadding=\"5\" style=\"border: 1px #666666 dashed;\">"; // header print "<tr class=\"journal_header\"><td width=\"100%\"><table width=\"100%\"><tr>"; print "<td width=\"50%\"><b>" . $data["title"] . "</b> {$editlink}</td>"; print "<td width=\"50%\" align=\"right\">Posted by " . $sql_user_obj->data[0]["realname"] . " @ {$post_time}</td>"; print "</tr></table></td></tr>"; // content print "<tr><td width=\"100%\">{$content}</td></tr>"; print "</table>"; break; case "file": /* Files attached to the journal The journal uses the standard file uploading system to keep track of files. */ print "<br><table width=\"100%\" cellpadding=\"5\" style=\"border: 1px #666666 dashed;\">"; // fetch information about the file $file_obj = new file_storage(); $file_obj->data["type"] = "journal"; $file_obj->data["customid"] = $data["id"]; if (!$file_obj->load_data_bytype()) { log_debug("journal_display", "Unable to load journal file!"); } // header print "<tr class=\"journal_header\"><td width=\"100%\"><table width=\"100%\"><tr>"; print "<td width=\"50%\"><b>File: " . $data["title"] . "</b> {$editlink} </td>"; print "<td width=\"50%\" align=\"right\">Posted by " . $sql_user_obj->data[0]["realname"] . " @ {$post_time}</td>"; print "</tr></table></td></tr>"; // content // (this field is optional for attached files) if ($content) { print "<tr><td width=\"100%\">{$content}</td></tr>"; } // file download link print "<tr><td width=\"50%\"><b><a href=\"" . $this->structure["download_page"] . "?customid=" . $file_obj->data["customid"] . "&fileid=" . $file_obj->id . "\">Download File</a></b> (" . $file_obj->data["file_size_human"] . ")</td></tr>"; print "</table>"; break; default: log_debug("journal_display", "Invalid journal type of " . $data["type"] . " provided, unable to process entry " . $data["id"] . ""); break; } // end type switch // use the previous type value to track if we need <br> added or not $previousvalue = $data["type"]; } // end of loop through journal entried } // end if journal exists }
function render_field($column, $row) { log_debug("table", "Executing render_field({$column}, {$row})"); /* See the add_column function for comments about the different possible types. */ if (!isset($this->structure[$column]["type"])) { $this->structure[$column]["type"] = ""; } switch ($this->structure[$column]["type"]) { case "date": if ($this->data[$row][$column] == "0000-00-00" || $this->data[$row][$column] == 0) { // no date in this field, add filler $result = "---"; } else { // format the date and display $result = time_format_humandate($this->data[$row][$column]); } break; case "timestamp": if ($this->data[$row][$column]) { $result_1 = time_format_humandate(date("Y-m-d", $this->data[$row][$column])); $result_2 = date("H:i:s", $this->data[$row][$column]); $result = "{$result_1} {$result_2}"; } else { $result = "---"; } break; case "timestamp_date": if ($this->data[$row][$column]) { $result = time_format_humandate(date("Y-m-d", $this->data[$row][$column])); } else { $result = "---"; } break; case "price": case "money": case "money_float": // TODO: This exists here to work around a PHP bug - it seems that if // we don't have it, even though $row will equal 0, it will still match // the if statements below comparing it to "total". // // Bug was observed on PHP v4 on CentOS 4 // $row = strval($row); // check if this field is a total or not, since we only // want to blank non-total spaces. $total = NULL; if ($row == "total") { $total = "yes"; } if ($column == "total") { $total = "yes"; } if (empty($this->data[$row][$column]) && !$total) { // instead of 0.00, make blank, as long as this field is not a total $result = ""; } else { if ($this->structure[$column]["type"] == "money_float") { $result = format_money($this->data[$row][$column], NULL, 4); } else { $result = format_money($this->data[$row][$column]); } } break; case "hourmins": // value is a number of seconds, we need to convert into an H:MM format. $result = @time_format_hourmins($this->data[$row][$column]); break; case "bool_tick": // label as Y or N. The render functions may perform further work such // as displaying icons instead if (!empty($this->data[$row][$column])) { $result = "Y"; } else { $result = "N"; } break; case "text": $result = format_text_display($this->data[$row][$column]); break; case "percentage": if (!empty($this->data[$row][$column])) { $result = $this->data[$row][$column] . "%"; } else { $result = ""; } break; case "standard": default: if (isset($this->data[$row][$column])) { $result = $this->data[$row][$column]; } else { $result = ""; } break; } // end of switch return $result; }