node.module 4.86 KB
Newer Older
Dries's avatar
 
Dries committed
1 2 3 4
<?php

$module = array("admin" => "node_admin");

Dries's avatar
 
Dries committed
5
function node_overview($query = array()) {
Dries's avatar
 
Dries committed
6
  global $user, $rstatus;
Dries's avatar
 
Dries committed
7

Dries's avatar
 
Dries committed
8
  $result = db_query("SELECT n.*, u.userid FROM node n LEFT JOIN users u ON n.author = u.id $query[1] LIMIT 50");
Dries's avatar
 
Dries committed
9

Dries's avatar
 
Dries committed
10
  $output .= status($query[0]);
Dries's avatar
 
Dries committed
11 12 13
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
  $output .= " <TR><TH>title</TH><TH>type</TH><TH>status</TH><TH>author</TH><TH>date</TH><TH COLSPAN=\"3\">operations</TH></TR>\n";
  while ($node = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
14
    $output .= " <TR><TD><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">$node->type</TD><TD>". $rstatus[$node->status] ."</TD><TD>". format_username($node->userid) ."</TD><TD>". format_date($node->timestamp) ."</TD><TD>". (user_access($user, "node") ? "<A HREF=\"admin.php?mod=node&op=view&id=$node->nid\">view node</A></TD>" : "view node") ."</TD><TD>". (user_access($user, "node") ? "<A HREF=\"admin.php?mod=node&op=edit&id=$node->nid\">edit node</A></TD>" : "edit node") ."</TD><TD>". (user_access($user, $node->type) ? "<A HREF=\"admin.php?mod=$node->type&op=edit&id=$node->nid\">edit $node->type</A></TD>" : "edit $node->type") ."</TD></TR>\n";
Dries's avatar
 
Dries committed
15 16 17 18 19 20 21
  }
  $output .= "</TABLE>\n";

  return $output;
}

function node_admin_view($id) {
Dries's avatar
 
Dries committed
22
  global $rstatus;
Dries's avatar
 
Dries committed
23 24 25 26 27 28

  $node = node_get_object("nid", $id);

  $output .= "<FORM ACTION=\"admin.php?mod=node&id=$node->nid\" METHOD=\"post\">\n";
  $output .= "<B>Title:</B><BR>". check_output($node->title) ."<P>\n";
  $output .= "<B>Author:</B><BR>". format_username($node->userid) ."<P>\n";
Dries's avatar
 
Dries committed
29
  $output .= "<B>Status:</B><BR>". $rstatus[$node->status] ."<P>\n";
Dries's avatar
 
Dries committed
30 31 32 33 34 35 36 37 38
  $output .= "<B>Date:</B><BR>". format_date($node->timestamp) ."<P>\n";
  $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Edit node\">\n";
  $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Delete node\">\n";
  $output .= "</FORM>\n";

  return $output;
}

function node_admin_edit($id) {
Dries's avatar
 
Dries committed
39
  global $user, $status;
Dries's avatar
 
Dries committed
40 41 42 43 44

  $node = node_get_object("nid", $id);

  foreach (array($node->userid => $node->author, $user->userid => $user->id) as $value=>$key) $author .= " <OPTION VALUE=\"$key\"". (($node->author == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
  foreach (array(format_date($node->timestamp) ." (original)" => $node->timestamp, format_date(time()) ." (current)" => time()) as $value=>$key) $timestamp .= " <OPTION VALUE=\"$key\"". (($node->timestamp == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
Dries's avatar
 
Dries committed
45
  foreach (node_status($node) as $value) $statuz .= " <OPTION VALUE=\"". $status[$value] ."\"". (($node->status == $status[$value]) ? " SELECTED" : "") .">$value</OPTION>\n";
Dries's avatar
 
Dries committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

  $output .= "<FORM ACTION=\"admin.php?mod=node&id=$node->nid\" METHOD=\"post\">\n";
  $output .= "<B>Title:</B><BR>". check_output($node->title) ."<P>\n";
  $output .= "<B>Author:</B><BR><SELECT NAME=\"edit[author]\">$author</SELECT><P>\n";
  $output .= "<B>Status:</B><BR><SELECT NAME=\"edit[status]\">$statuz</SELECT><P>\n";
  $output .= "<B>Date:</B><BR><SELECT NAME=\"edit[timestamp]\">$timestamp</SELECT><P>\n";
  $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[nid]\" VALUE=\"$node->nid\">\n";
  $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"View node\">\n";
  $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save node\">\n";
  $output .= "</FORM>\n";

  return $output;
}

function node_delete($id) {
Dries's avatar
 
Dries committed
61
  return (node_del("nid", $id) ? "node has been deleted." : "failed to delete node: node must be dumped first.");
Dries's avatar
 
Dries committed
62 63
}

Dries's avatar
 
Dries committed
64 65 66 67 68 69 70 71 72 73 74 75 76
function node_query($type = "") {
  global $status;
  $queries =  array(0 => array("active nodes", "ORDER BY n.timestamp DESC"), 1 => array("posted nodes", "WHERE n.status = '$status[posted]' ORDER BY n.timestamp DESC"), 2 => array("queued nodes", "WHERE n.status = '$status[queued]' ORDER BY n.timestamp DESC"), 3 => array("dumped nodes", "WHERE n.status = '$status[dumped]' ORDER BY n.timestamp DESC"));
  return ($queries[$type] ? $queries[$type] : $queries);
}

function node_listing() {
  foreach (node_query() as $key=>$array) {
    $output .= "<LI><A HREF=\"admin.php?mod=node&type=$key\">$array[0]</A></LI>\n";
  }
  return "<OL>$output</OL>\n";
}

Dries's avatar
 
Dries committed
77
function node_admin() {
Dries's avatar
 
Dries committed
78 79 80
  global $op, $id, $edit, $type;

  print "<SMALL><A HREF=\"admin.php?mod=node&op=listing\">node listings</A> | <A HREF=\"admin.php?mod=node\">overview</A></SMALL><HR>\n";
Dries's avatar
 
Dries committed
81 82

  $id = check_input($edit[nid] ? $edit[nid] : $id);
Dries's avatar
 
Dries committed
83
  $type = ($type ? $type : 0);
Dries's avatar
 
Dries committed
84 85 86 87 88 89 90 91 92 93

  switch ($op) {
    case "Edit node":
    case "edit":
      print node_admin_edit($id);
      break;
    case "Delete node":
      print status(node_delete($id));
      print node_overview();
      break;
Dries's avatar
 
Dries committed
94 95 96
    case "listing":
      print node_listing();
      break;
Dries's avatar
 
Dries committed
97 98
    case "Save node":
      print status(node_save($edit));
Dries's avatar
 
Dries committed
99
      print node_admin_view($id);
Dries's avatar
 
Dries committed
100 101 102 103 104 105
      break;
    case "View node":
    case "view":
      print node_admin_view($id);
      break;
    default:
Dries's avatar
 
Dries committed
106
      print node_overview(node_query($type));
Dries's avatar
 
Dries committed
107 108 109 110
  }
}

?>