rendered paste body<?php/** This module contains various customizations for SI644 Winter 2006 *//* note: if you define multiple node types, they *must* begine with 'modulename-'. I didn't see this documented anywhere, but when you use any other name it has problems */function SI684_node_types(){ return array('SI684-Reading', 'SI684-Assignment');}function SI684_node_name($node){ switch (is_string($node) ? $node : $node->type) { case 'SI684-Reading': return t('reading'); case 'SI684-Assignment': return t('assignment'); } }/* function SI684_node_name($node){ return t('reading');}*//** * Implementation of hook_perm(). */function SI684_perm() { return array('maintain syllabus', 'access syllabus entries');}/** * Implementation of hook_nodeapi(). * This gets called for nodes of *all* types and provides a chance to extend them */function SI684_nodeapi(&$node, $op, $teaser, $page) { switch ($op) { case 'view': // if there are syllabus fields, add them if (variable_get('SI684_syllabus_fields_' . $node->type, '') == 'yes'){ $out = theme('SI684_syllabus_fields', $node); $node->body = $out . $node->body; } // inline any syllabus entries that should be added to this node if (variable_get('SI684_syllabus_links_' . $node->type, '') == 'yes' && user_access('access syllabus entries')){ $out = theme('SI684_syllabus_inline',$node); $node->body .= $out; } // lastly, inline any blog entries that should be added to this node if (user_access('access blog entries')) { $out = theme('SI684_blog_inline',$node); $node->body .= $out; } case 'settings': $output = form_radios(t('Allow linked syllabus entries'), 'SI684_syllabus_links_'. $node->type, variable_get('SI684_syllabus_links_'. $node->type, 'no'), array('yes' => t('yes'), 'no' => t('no') ), t('Yes: This content type can have linked entries for readings and/or assignments.')); $output .= form_radios(t('Include syllabus fields'), 'SI684_syllabus_fields_' . $node->type, variable_get('SI684_syllabus_fields_' . $node->type, 'no'), array('yes' => t('yes'), 'no' => t('no') ), t('Yes: This content type includes the special reading/assignment fields.')); $output .= form_radios(t('Allow linked blog entries'), 'SI684_blog_links_' . $node->type, variable_get('SI684_blog_links_' . $node->type, 'no'), array('yes' => t('yes'), 'no' => t('no') ), t('Yes: This content type includes the special reading/assignment fields.')); return $output; case 'form pre': $form = ''; if ($node->type == 'blog'){ // This is a somewhat ugly way to get the parameter for the node this blog entry links to; should look for drupal's more elegant way.... $orgid = split('anode=',$_GET['q']); if ($orgid[1]){ $node->rid = $orgid[1]; $rid = $orgid[1]; } if (isset($node->linked_id)){ $rid = $node->linked_id; } $item = db_fetch_object(db_query('select * from node where nid = %d',$rid)); /* $form .= form_item(t('linked_node'), t("You are writing about " . $item->title), t('')); $form .=form_hidden(t('rid'),$node->rid); */ // generate the options for the form, from the available readings $options = array(); $options[] = t('<none>'); $result = db_query("SELECT nid, title, type from {node} where type in ('SI684-Reading', 'SI684-Assignment')"); while ($reading = db_fetch_object($result)) { $options[$reading->nid] = t($reading->title); } $form .= form_select(t('You are writing about'), 'linked_id', $item->nid, //currently selected choice $options, '', //no explanatory text needed '', FALSE, //can't select multiple sessions FALSE); // not a required field } if (variable_get('SI684_syllabus_fields_' . $node->type, '') == 'yes'){ $orgid = split('anode=',$_GET['q']); if ($orgid[1]){ $node->rid = $orgid[1]; } $item = db_fetch_object(db_query('select * from node where nid = %d',$node->rid)); // generate the options for the form, from the available sessions $options = array(); $s = array(); $allowed_types = array(); foreach (node_list() as $type) { if (variable_get('SI684_syllabus_links_' . $type, '') == 'yes'){ $s[] = "'%s'"; $allowed_types[] = $type; } } $result = db_query("SELECT nid, title, type from {node} where type in (". implode(", ", $s) . ")", $allowed_types); while ($session = db_fetch_object($result)) { $options[$session->nid] = t($session->title); } $form .= form_select(t('This reading/assignment is for the session'), 'session', $item->nid, //currently selected choice $options, '', //no explanatory text needed '', FALSE, //can't select multiple sessions FALSE); // not a required field $options = array('all required' => 'all required', '684 required' => '684 required', '884 required' => '884 required', 'optional' => 'optional', 'technology exploration' => 'technology exploration', 'all assignment' => 'all assignment', '684 assignment' => '684 assignment', '884 assignment' => '884 assignment'); $form .= form_select(t('Which students'), 'forwhom', $node->forwhom, $options, "", "", FALSE, TRUE); $form .=form_hidden(t('rid'),$node->rid); } return $form; case 'form post': $form = ''; if (variable_get('SI684_syllabus_links_'. $node->type, '') == 'yes'){ } if (variable_get('SI684_syllabus_fields_' . $node->type, '') == 'yes'){ $form .= form_textarea(t('Syllabus Text'), 'include_text', $node->include_text, 60, 12, t('Text to display as a teaser in the session node; for example, the full bibliography reference'), '', TRUE); $form .= form_textarea(t('Body'), 'body', $node->body, 60, 12); } return $form; case 'insert': if (variable_get('SI684_syllabus_fields_' . $node->type, '') == 'yes' && $node->rid){ // save the special syllabus_entry fields, including the link back db_query("INSERT INTO {syllabusrefs} (nid, rid, include_text, forwhom) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->rid, $node->include_text, $node->forwhom ); } if ($node->type == 'blog' && $node->linked_id){ // make the blog entry link back db_query("INSERT INTO {blogrefs} (nid, rid) VALUES (%d, %d)", $node->nid, $node->linked_id); } break; case 'update': // While the DELETE/INSERT is less efficient than single UPDATE, the // UPDATE only works if there's an existing record in the events // table. I.e. if you create a node and then enable the linking, // there will be no record in the table, so the update can't be performed if (variable_get('SI684_syllabus_fields_' . $node->type, '') == 'yes' && $node->rid){ db_query('DELETE FROM {syllabusrefs} WHERE nid = %d', $node->nid); db_query("INSERT INTO {syllabusrefs} (nid, rid, include_text, forwhom) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->rid, $node->include_text, $node->forwhom ); } if ($node->type == 'blog' && $node->linked_id){ // make the blog entry link back db_query('DELETE FROM {blogrefs} WHERE nid = %d', $node->nid); db_query("INSERT INTO {blogrefs} (nid, rid) VALUES (%d, %d)", $node->nid, $node->linked_id); } case 'load': if ($node->type == 'blog'){ $additions = db_fetch_array(db_query('SELECT rid, title as fartitle FROM {blogrefs},{node} WHERE blogrefs.nid = %d and blogrefs.rid=node.nid', $node->nid)); return $additions; } if (variable_get('SI684_syllabus_fields_' . $node->type, '') == 'yes'){ $additions = db_fetch_array(db_query('SELECT rid, include_text, forwhom, n.title as sessiontitle FROM {syllabusrefs} s, {node} n WHERE s.nid = %d and s.rid = n.nid', $node->nid)); return $additions; } }}function SI684_link($type, $node = 0) { # dprint("About to look for links"); if ($node){ $links = array(); if (variable_get('SI684_blog_links_' . $node->type, '') == 'yes'){ $location = "node/add/blog/anode=" . $node->nid; $links[] = l(t("Blog About ". $node->title, array('%username' => $uid)), $location); } if (variable_get('SI684_syllabus_links_'. $node->type, '') == 'yes'){ if (user_access('maintain syllabus')) { $location = "node/add/SI684-Reading/anode=" . $node->nid; $links[] = l(t("Add reading assignment", array('%username' => $uid)), $location); } } if (variable_get('SI684_syllabus_fields_'. $node->type, '') == 'yes'){ if (user_access('access syllabus entries')) { $refto = "View " . $node->sessiontitle; $reflink = "node/" . $node->rid; $links[] = l(t($refto,''),$reflink); } } if ($node->type == 'blog' && $node->rid){ $refto = "View " . $node->fartitle; $reflink = "node/" . $node->rid; $links[] = l(t($refto,''),$reflink); } return $links; }}function theme_SI684_syllabus_fields($node){ $output = "<div class='syllabus_field'>"; $output .= $node->include_text; $output .="</div>"; return $output;}function theme_SI684_entries_section($node, $forwhom, $header){ $output = ''; $query = sprintf("SELECT s.nid from {syllabusrefs} s, {node} n where rid = '%s' AND s.nid = n.nid AND s.forwhom = '%s' ORDER BY n.created ASC", $node->nid, $forwhom); // dprint($query); $result = db_query($query); // dprint (db_num_rows($result)); if (db_num_rows($result) > 0){ $output .="<div style = 'font-weight: bold; font-size: 1.25em; margin: 1em 0; padding: 1em; border: 1px solid #ddd; border-left: none; border-right: none; background: #f4f4f4;'>"; $output .= t($header); while ($row = db_fetch_object($result)) { $output .= " <div style='font-size: 0.8em; font-weight: normal; text-indent: -2em; margin: .5em 0 .5em 2em;'>"; $syllabus_node = node_load(array('nid' => $row->nid)); $output .= l(t($syllabus_node->title), "node/" . $row->nid); $output .= " " . t($syllabus_node->include_text); $output .="</div>"; } $output .="</div>"; } return $output;}function theme_SI684_syllabus_inline($node) { $output = ''; $output .= theme('SI684_entries_section', $node, 'all assignment', 'Assignment due (all students)'); $output .= theme('SI684_entries_section', $node, '684 assignment', 'Assignment due (684 only)'); $output .= theme('SI684_entries_section', $node, '884 assignment', 'Assignment due (884 only)'); $output .= theme('SI684_entries_section', $node, 'technology exploration', 'Technology exploration'); $output .= theme('SI684_entries_section', $node, 'all required', "Required Reading (all students)"); $output .= theme('SI684_entries_section', $node, '684 required', 'Required Reading (684 only)'); $output .= theme('SI684_entries_section', $node, '884 required', 'Required Reading (884 only)'); $output .= theme('SI684_entries_section', $node, 'optional', 'optional'); return $output;}function theme_SI684_blog_inline($node) { $output = "<div class='blog'>"; $result = pager_query(db_rewrite_sql("SELECT node.nid from {node},{blogrefs} where node.nid = blogrefs.nid and blogrefs.rid = '$node->nid' ")); while ($node = db_fetch_object($result)) { $blog_node = node_load(array('nid' => $node->nid)); $output .= node_view($blog_node, FALSE); if (function_exists('comment_render') && $blog_node->comment) { $output .= comment_render($blog_node); } } $output .="</div>"; return $output;}?>