' . $publication->description . '
';
}
while ($ed = db_fetch_object($editions)) {
if ($previous_volume && ($ed->volume != $previous_volume)) {
$output .= theme('epublish_format_volume', $previous_volume, $publication->pid, $edition_blocks);
$edition_blocks = array();
}
$edition_blocks[] = theme('epublish_format_edition', $ed);
$previous_volume = $ed->volume;
}
if ($edition_blocks) {
$output .= theme('epublish_format_volume', $previous_volume, $publication->pid, $edition_blocks);
}
$output = '' . "$output
\n";
}
/**
* theme_epublish_format_edition: A themeable layout that lists the nodes in a single edition of a publication.
*
* @param $edition
* An edition object.
*
* @return
* An HTML-formatted display showing the reference name of the edition and a list of its headlines.
*/
function theme_epublish_format_edition(&$edition) {
$og = variable_get('epublish_og', 0);
$sid = epublish_assign_section($edition);
$topics = epublish_section_topics($sid, $edition->eid);
if ($og == 1) {
$topic = current($topics);
$vid = current($topic->nodes);
$sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
$nid = db_fetch_object(db_query($sql, $vid));
$sql2 = "SELECT group_nid FROM {og_ancestry} WHERE nid = %d";
$group = db_fetch_object(db_query($sql2, $nid->nid));
$gid = $group->group_nid;
}
if (is_numeric($edition->volume) && is_numeric($edition->number) && $edition->volume > 0 && $edition->number > 0) {
if ($og == 1) {
$output = "' . "$output
\n";
}
/**
* theme_epublish_format_pub: A themeable function that lists all of the publications on the site.
*
* @return
* An HTML-formatted display showing the name of each publication and its description.
*/
function theme_epublish_format_pub() {
$result = db_query("SELECT * from {epublish_publication}");
$output = '';
if ($edit->pid) {
$result = db_query("SELECT * FROM {epublish_edition} WHERE pid='%d' ORDER BY volume $order, number $order, pubdate $order, eid $order", $edit->pid);
while ($edition = db_fetch_object($result)) {
$editions[$edition->eid] = theme('epublish_edition_reference', $edition);
}
}
if (!$edit->current_eid) {
$edit->current_eid = 0;
}
$form['current_eid'] = array(
'#type' => 'select',
'#title' => t("Current edition"),
'#default_value' => $edit->current_eid,
'#options' => $editions,
'#description' => t("The default edition to display from this publication. If none is specified, the latest edition will be selected."),
);
// Select a layout
if (variable_get('epublish_custom_layouts', '0')) {
$layouts = epublish_layouts('page', TRUE);
$form["layout_page"] = array(
'#type' => 'select',
'#title' => t("Page layout"),
'#default_value' => $edit->layout_page,
'#options' => $layouts,
'#description' => t("Select a page layout for this publication. If none is selected, the default !settings will be used.",
array('!settings' => l(t('layout settings'), 'admin/settings/epublish'))),
);
$layouts = epublish_layouts('list', TRUE);
$form["layout_list"] = array(
'#type' => 'select',
'#title' => t("Listing layout"),
'#default_value' => $edit->layout_list,
'#options' => $layouts,
'#description' => t("Select a layout to control the display of headline listings for this publication.
If none is selected, the default settings will be used."),
);
} else {
// Even if custom layouts are turned off, pass through the value as a hidden input.
//That way the settings are still there if custom layouts gets turned on again later.
$form['layout_page'] = array(
'#type' => 'hidden',
'#value' => $edit->layout_page,
);
$form['layout_list'] = array(
'#type' => 'hidden',
'#value' => $edit->layout_list,
);
}
// Select sections
if (variable_get('epublish_custom_sections', '0')) {
$sids = epublish_sections(true);
$form["sid"] = array(
'#type' => 'select',
'#title' => t("Section"),
'#default_value' => $edit->sid,
'#options' => $sids,
'#description' => t("Select a section to control which topics are headlined for each edition of this publication.
If none is selected, the default section from !settings will be used.", array('!settings' => l(t('publication settings'), 'admin/settings/epublish'))),
);
} else {
$form['sid'] = array(
'#type' => 'hidden',
'#value' => $edit->sid,
);
}
$form[] = array(
'#type' => 'submit',
'#value' => t("Submit"),
);
if ($edit->pid) {
$form["pid"] = array(
'#type' => 'hidden',
'#value' => $edit->pid,
);
$form[] = array(
'#type' => 'submit',
'#value' => t("Delete"),
);
}
return $form;
}
function epublish_pub() {
$output = drupal_get_form('epublish_form_pub');
return $output;
}
/**
* epublish_form_pub_submit: save changes to a publication
*
* @param $edit
* an array of values to be saved
*
* @return
* the same array, with modifications if a new record is created
*/
function epublish_form_pub_submit($form_id, $edit) {
if ($edit['pid'] && $edit['action'] != 'delete') {
db_query("UPDATE {epublish_publication} SET name = '%s', description = '%s', schedule = '%s', current_eid = '%d',
layout_list = '%s', layout_page = '%s', sid = '%s' WHERE pid = '%d'", $edit['name'], $edit['description'],
$edit['schedule'], $edit['current_eid'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['pid']);
drupal_set_message(t('The publication "!title" has been updated.', array('!title' => $edit['name'])));
} else if ($edit['action'] == 'delete') {
epublish_del_pub($edit['pid']);
} else {
$edit['pid'] = db_next_id('{epublish_publication}_pid');
db_query("INSERT INTO {epublish_publication} (pid, name, description, schedule, current_eid, layout_list, layout_page, sid)
VALUES ('%d', '%s', '%s', '%s', '%d', '%s', '%s', '%s')", $edit['pid'], $edit['name'], $edit['description'],
$edit['schedule'], $edit['current_eid'], $edit['layout_list'], $edit['layout_page'], $edit['sid']);
drupal_set_message(t('The publication "!title" has been added.', array('!title' => $edit['name'])));
}
return 'admin/epublish';
}
/**
* epublish_del_pub: delete a publication
*
* @param $pid
* the publication ID to be deleted
*
* @return
* A message stating that the publication has been deleted
*/
function epublish_del_pub($pid) {
$publication = epublish_get_pub($pid);
if (($_POST['op'] == t('Delete')) && ($_POST ['form_id'] == 'confirm_form' )){
db_query("DELETE FROM {epublish_publication} WHERE pid = '%d'", $pid);
$result = db_query("SELECT eid from {epublish_edition} WHERE pid = '%d'", $pid);
while ($edition = db_fetch_object($result)) {
db_query("DELETE FROM {epublish_edition_node} WHERE eid = '%d'", $edition->eid);
}
db_query("DELETE FROM {epublish_edition} WHERE pid = '%d'", $pid);
db_query("DELETE FROM {epublish_volume} WHERE pid = '%d'", $pid);
drupal_set_message(t('deleted publication "!name".', array('!name' => $publication->name)));
drupal_goto("admin/epublish");
} else if ($publication->pid) {
return drupal_get_form('confirm_form',array('pid' => array(
'#type' => hidden,'#value' => $publication->pid)),
t('Are you sure you want to delete the publication "!title"?', array('!title' => $publication->name)),
'admin/epublish',
t('This action cannot be undone.'),
t('Delete'),
t('Cancel'),'confirm');
} else {
drupal_set_message(t('The section no longer exists.'));
return 'admin/epublish';
}
}
/*******************************************
* EDITIONS
******************************************/
/**
* epublish_get_edition: get an epublish_edition record from the database
*
* @param $eid
* An edition ID number
*
* @return
* An object containing all of the values for a single record in the
* {epublish_edition} table.
*/
function epublish_get_edition($eid) {
return db_fetch_object(db_query("SELECT * FROM {epublish_edition} WHERE eid='%d'", $eid));
}
/**
* epublish_current_edition: return the current edition ID number for a publication.
* If no edition is specified, returns the edition with the latest publication date.
*
* @param $pid
* A publication ID number
*
* @return
* An edition ID number
*/
function epublish_current_edition($pid=0) {
$publication = epublish_get_pub($pid);
if ($publication->current_eid) {
return $publication->current_eid;
}
$eid = db_result(db_query("SELECT eid FROM {epublish_edition} WHERE pid='%d' ORDER BY volume DESC, number DESC, pubdate DESC, eid DESC LIMIT 1", $pid));
if ($eid) {
return $eid;
}
$eid = db_result(db_query("SELECT eid FROM {epublish_edition} ORDER BY pubdate DESC, volume DESC, number DESC, eid DESC LIMIT 1"));
return $eid;
}
/**
* Page to add or edit an edition
*/
function epublish_admin_edition_edit($eid = NULL) {
if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) {
return epublish_del_edition($eid);
} elseif ($_POST['op'] == t('Add more headlines')) {
drupal_goto( "admin/epublish/headlines/$eid" );
} elseif ($eid) {
$edition = epublish_get_edition($eid);
}
$output = drupal_get_form('epublish_form_edition',$edition);
return $output;
}
function epublish_admin_edition_add($pid = NULL) {
$output = drupal_get_form('epublish_form_edition',NULL,$pid);
return $output;
}
/**
* epublish_form_edition: return a form for editing a publication edition
*
* @param $edit
* an array of values handled by the form
*
* @return
* An HTML-formatted form
*/
function epublish_form_edition($edit = NULL, $pid=NULL) {//TODO makes sure a given user only sees nodes for the group the pub belongs to or public posts to add to pub
$urlquery = 'epublish/'.$edit->pid.'/'.$edit->eid;
$urlres= db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '".$urlquery."'"));
$edit = (object) $edit;
if ($pid) {
$edit->pid = $pid;
}
$publication = epublish_get_pub($edit->pid);
$form[] = array('#value' => '' . t('Edition of publication ') . l($publication->name, "admin/epublish/edit/publication/$publication->pid") . "
\n");
$form['pid'] = array(
'#type' => 'hidden',
'#value' => $edit->pid,
);
$form['dateline'] = array(
'#type' => 'textfield',
'#title' => t('Dateline'),
'#default_value' => $edit->dateline,
'#size' => 50,
'#maxlength' => 128,
'#description' => t('A textual representation of the publication date, e.g., "March 2003" or "April 11-17, 2004."'),
);
$form[] = array('#value' => '');
$form['volume'] = array(
'#type' => 'textfield',
'#title' => '',
'#default_value' => $edit->volume,
'#size' => 6,
'#maxlength' => 6,
'#prefix' => '' . t('Volume') . ': ',
);
$form['number'] = array(
'#type' => 'textfield',
'#title' => '',
'#default_value' => $edit->number,
'#size' => 6,
'#maxlength' => 6,
'#prefix' => '' . t('Number') . ': ',
);
$form[] = array('#value' => '
');
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $edit->description,
'#cols' => 70,
'#rows' => 8,
);
if (module_exists('path')) {
$path = $form['#node']->path;
$form['path'] = array(
'#type' => 'fieldset',
'#title' => t('URL path settings'),
'#collapsible' => TRUE,
'#collapsed' => empty($path),
'#weight' => 1,
);
$form['path']['path'] = array(
'#type' => 'textfield',
'#default_value' => $urlres,
'#maxlength' => 250,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => t('Optionally specify an alternative URL by which this node can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'),
);
$form['path']['pthid'] = array(
'#type' => 'hidden',
'#value' => db_result(db_query("SELECT pid FROM {url_alias} WHERE dst ='".$urlres."'"))
);
}
// publication date
if (!$edit->year && !$edit->pubdate) {
$edit->year = date('Y', time());
$edit->month = date('m', time());
$edit->day = date('d', time());
} else if (!$edit->year) {
$edit->year = substr($edit->pubdate, 0, 4);
$edit->month = substr($edit->pubdate, 4, 2);
$edit->day = substr($edit->pubdate, 6, 2);
}
$years = drupal_map_assoc(range(date("Y", time())-15, date("Y", time())+1));
$months = array('01' => t("January"), '02' => t("February"), '03' => t("March"), '04' => t("April"), '05' => t("May"), '06' => t("June"),
'07' => t("July"), '08' => t("August"), '09' => t("September"), '10' => t("October"), '11' => t("November"), '12' => t("December"));
$days = array('01' => '1', '02' => '2', '03' => '3', '04' => '4', '05' => '5', '06' => '6', '07' => '7', '08' => '8', '09' => '9', '10' => '10',
'11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20',
'21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30',
'31' => '31');
$form[] = array('#value' => '');
$form["month"] = array(
'#type' => 'select',
'#title' => "Publication date",
'#default_value' => $edit->month,
'#options' => $months
);
$form['day'] = array(
'#type' => 'select',
'#title' => "",
'#default_value' => $edit->day,
'#options' => $days,
);
$form['year'] = array(
'#type' => 'select',
'#title' => "",
'#default_value' => $edit->year,
'#options' => $years,
);
$form[] = array('#value' => '
');
// Select a layout
if (variable_get('epublish_custom_layouts', '0')) {
$layouts = epublish_layouts('page', TRUE);
$form["layout_page"] = array(
'#type' => 'select',
'#title' => t("Page layout"),
'#default_value' => $edit->layout_page,
'#options' => $layouts,
'#description' => t("Select a page layout for this edition. If none is selected, the default !settings will be used.",
array('!settings' => l(t('layout for this publication'), 'admin/epublish/edit/publication/' . $edit->pid))),
);
$layouts = epublish_layouts('list', TRUE);
$form["layout_list"] = array(
'#type' => 'select',
'#title' => t("Listing layout"),
'#default_value' => $edit->layout_list,
'#options' => $layouts,
'#description' => t("Select a layout to control the display of headline listings for this edition.
If none is selected, the default for this publication will be used."),
);
} else {
// Even if custom layouts are turned off, pass through the value as a hidden input.
//That way the settings are still there if custom layouts gets turned on again later.
$form['layout_page'] = array(
'#type' => 'hidden',
'#value' => $edit->layout_page,
);
$form['layout_list'] = array(
'#type' => 'hidden',
'#value' => $edit->layout_list,
);
}
// Select section(s)
if (variable_get('epublish_custom_sections', '0')) {
$sids = epublish_sections(true);
$form["sid"] = array(
'#type' => 'select',
'#title' => t("Section"),
'#default_value' => $edit->sid,
'#options' => $sids,
'#description' => t("Select a section to control which topics are headlined in this edition.
If none is selected, the default section for this publication will be used."),
);
} else {
// Even if custom sections are turned off, pass through the value as a hidden input.
//That way the settings are still there if custom sections gets turned on again later.
$form['sid'] = array(
'#type' => 'hidden',
'#value' => $edit->sid,
);
}
if ($edit->eid) {
$form['published'] = array(
'#type' => 'checkbox',
'#title' => t('Published?'),
'#return_value' => 1,
'#default_value' => $edit->published,
);
$form['make_current'] = array(
'#type' => 'checkbox',
'#title' => t('Make current?'),
'#return_value' => 1,
'#default_value' => ($edit->eid == $publication->current_eid),
'#description' => t('Check this box if you want this to be the !current of this publication',
array('!current' => l(t('current edition'), "epublish/" . $publication->pid . "/current"))),
);
$form["eid"] = array(
'#type' => 'hidden',
'#value' => $edit->eid,
);
$form[] = array(
'#type' => 'submit',
'#weight' => 2,
'#value' => t("Submit"),
);
$form[] = array(
'#type' => 'submit',
'#weight' => 2,
'#value' => t("Delete"),
);
// headlines
$form[] = array('#value'=>'
', '#weight' => 2,) ;
$form['headlines'] = array(
'#type' => 'fieldset', '#title' => t('Manage headlines'),
);
$edition = epublish_get_edition($edit->eid);
$sid = epublish_assign_section($edition);
$operations = array('add' => t('Update the selected posts'), 'del' => t('Remove the selected posts'));
$form['headlines'][] = array('#value'=>'');
$form['headlines']['operation'] = array(
'#type' => 'select',
'#default_value' => 'add',
'#options' => $operations,
);
$form['headlines']['submit'] = array('#type' => 'submit', '#value' => t('Update'));
$form['headlines'][] = array('#type' => 'submit', '#value' => t("Add more headlines"));
$form['headlines'][] = array('#value'=>'
');
$header = array(NULL, t('Stories'), t('Topic'), t('Type'), t('Status'), t('Weight'));
$topics = epublish_topic_selection_list($sid);
$result = db_query(db_rewrite_sql("SELECT v.vid, v.nid, v.title, v.timestamp, n.status, n.type, een.weight, een.tid
FROM {node_revisions} v LEFT JOIN {epublish_edition_node} een ON v.vid = een.vid INNER JOIN {node} n ON n.nid = v.nid
LEFT JOIN {epublish_topic} et ON et.tid=een.tid
WHERE eid='" . $edit->eid . "' AND et.sid='" . $sid . "' ORDER BY et.weight, een.weight, v.timestamp DESC"));
while ($node = db_fetch_object($result)) {
$nodes[$node->vid] = '';
$sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
$count = db_num_rows(db_query($sql_count, $node->nid));
if ($count > 1) {
$form['title'][$node->vid] = array('#value' =>
l($node->title, 'node/'. $node->nid .'/revisions/'. $node->vid .'/view') .' '. theme('mark', node_mark($node->nid, $node->changed)));
}
else {
$form['title'][$node->vid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)));
}
$form['name'][$node->vid] = array('#value' => node_get_types('name', $node));
$form['tid']['tid_' . $node->vid] = array('#type' => 'select', '#default_value' => $node->tid,
'#options' => $topics, '#attributes' => array('onchange'=>'onChangeTID(' . $node->vid . ')'));
$form['status'][$node->vid] = array('#value' => ($node->status ? t('published') : t('not published')));
$form['weight']['weight_' . $node->vid] = array('#type' => 'weight', '#default_value' => $node->weight,
'#delta' => 30, '#attributes' => array('onchange'=>'onChangeWeight(' . $node->vid . ')'));
}
$form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes);
drupal_set_title(t('edit ') . "$publication->name, " . theme('epublish_edition_reference', $edition));
}
else {
$form['published'] = array(
'#type' => 'checkbox',
'#title' => t('Published?'),
'#return_value' => 1,
'#default_value' => 1,
);
$form['make_current'] = array(
'#type' => 'checkbox',
'#title' => t('Make current?'),
'#return_value' => 1,
'#default_value' => 0,
);
$form[] = array(
'#type' => 'submit',
'#value' => t("Submit"),
);
}
return $form;
}
function epublish_edition() {//TODO another unused function?
$output = drupal_get_form('epublish_form_edition');
return $output;
}
function theme_epublish_form_edition($form) {
// create the headlines table
if (isset($form['title']) && is_array($form['title'])) {
$rows = array();
foreach (element_children($form['title']) as $key) {
$row = array();
$row[] = drupal_render($form['nodes'][$key]);
$row[] = drupal_render($form['title'][$key]);
$row[] = drupal_render($form['name'][$key]);
$row[] = drupal_render($form['tid']['tid_' . $key]);
$row[] = drupal_render($form['status'][$key]);
$row[] = drupal_render($form['weight']['weight_' . $key]);
$rows[] = $row;
}
} else {
$rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6'));
}
$header = array(NULL, t('Title'), t('Type'), t('Topic'), t('Status'), t('Weight'));
$table_content = theme('table', $header, $rows);
// put the table content inside the headlines fieldset
$output = drupal_render($form['headlines']);
$output = str_replace('', $table_content . "\n\n", $output);
// put the headlines fieldset and table below the rest of the form content
$output = drupal_render($form) . $output;
return $output;
}
/**
* epublish_save_edition: save changes to a publication edition
*
* @param $edit
* an array of values to be saved
* @make_current $edit
* a Boolean value that indicates whether or not this edition should become the current edition of the publication
*
* @return
* the same array, with modifications if a new record is created
*/
// ($edit, $make_current = false)
function epublish_form_edition_submit($form_id, $edit) {
if ($edit['eid'] && $edit['action'] != 'delete') {
if(module_exists('path')) {
$ppid = $edit['pid'];
$peid = $edit['eid'];
$pnid = $edit['path'];
$pthid = $edit['pthid'];
if ($edit['path']) {
if($pthid) {
path_set_alias("epublish/$ppid/$peid",$pnid,$pthid);
}
else {
path_set_alias("epublish/$ppid/$peid",$pnid);
}
}
}
db_query("UPDATE {epublish_edition} SET pid='%d', dateline='%s', description='%s', volume='%d', number='%d', pubdate='%d',
layout_list='%s', layout_page='%s', sid='%d', published='%d' WHERE eid = '%d'", $edit['pid'], $edit['dateline'], $edit['description'],
$edit['volume'], $edit['number'], $edit['year'].$edit['month'].$edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'],
$edit['published'], $edit['eid']);
// Handle operations:
if (isset($edit['operation']) && isset($edit['nodes'])) {
foreach ($edit['nodes'] as $vid => $value) {
if ($value) {
$sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
$nid = db_fetch_object(db_query($sql, $vid));
switch ($edit['operation']) {
case 'add':
epublish_add_node($edit['eid'], $nid->nid, $vid, $edit['weight_' . $vid], $edit['tid_' . $vid]);
break;
case 'del':
epublish_del_node($edit['eid'], $nid->nid, $vid);
break;
}
}
}
drupal_set_message(t('The "!title" edition has been updated.', array('!title' => $edit['dateline'])));
}
}
elseif ($edit['action'] == 'delete') {
epublish_del_edition($edit);
}
else {
$edit['eid'] = db_next_id('{epublish_edition}_eid');
db_query("INSERT INTO {epublish_edition} (eid, pid, dateline, description, volume, number, pubdate, layout_list, layout_page, sid, published)
VALUES ('%d', '%d', '%s', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%d')", $edit['eid'], $edit['pid'], $edit['dateline'], $edit['description'],
$edit['volume'], $edit['number'], $edit['year'].$edit['month'].$edit['day'], $edit['layout_list'], $edit['layout_page'], $edit['sid'], $edit['published']);
drupal_set_message(t('The "!title" edition has been added.', array('!title' => $edit['dateline'])));
}
if ($edit['make_current']) {
db_query("UPDATE {epublish_publication} SET current_eid = '%d' WHERE pid = '%d'", $edit['eid'], $edit['pid']);
}
return 'admin/epublish';
}
/**
* epublish_del_edition: delete a publication edition
*
* @param $edit
* an array for the edition to be deleted
*
* @return
* A message stating that the edition has been deleted
*/
function epublish_del_edition($eid) {
$edition = epublish_get_edition($eid);
if (($_POST['op'] == t('Delete')) && ($_POST ['form_id'] == 'confirm_form' )){
$publication = epublish_get_pub($edition->pid);
db_query("DELETE FROM {epublish_edition} WHERE eid = '%d'", $edition->eid);
db_query("DELETE FROM {epublish_edition_node} WHERE eid = '%d'", $edition->eid);
drupal_set_message(t('Deleted "!edition" edition from publication "!publication."',
array('!edition' => $edition->dateline, '!publication' => $publication->name)));
drupal_goto("admin/epublish");
}
else if ($edition->eid) {
$publication = epublish_get_pub($edition->pid);
return drupal_get_form('confirm_form', array('eid' => array('#type' => hidden,
'#value' => $edition->eid)),
t('Are you sure you want to delete the "!edition" edition from publication "!publication"?',
array('!edition' => $edition->dateline, '!publication' => $publication->name)),
'admin/epublish',
t('This action cannot be undone.'),
t('Delete'),
t('Cancel'),'','');
}
else {
drupal_set_message(t('The edition no longer exists.'));
return 'admin/epublish';
}
}
/*******************************************
* VOLUMES
******************************************/
/**
* epublish_get_volume: get an epublish_volume record from the database
*
* @param $pid
* A publication ID number
* @param $volume
* A volume number
*
* @return
* An object containing all of the values for a single record in the
* {epublish_volume} table.
*/
function epublish_get_volume($pid, $volume) {
$vol = db_fetch_object(db_query("SELECT * FROM {epublish_volume} WHERE pid='%d' AND volume='%d'", $pid, $volume));
if (!$vol) {
db_query("INSERT INTO {epublish_volume} (pid, volume) VALUES ('%d', '%d')", $pid, $volume);
$vol = db_fetch_object(db_query("SELECT * FROM {epublish_volume} WHERE pid='%d' AND volume='%d'", $pid, $volume));
}
return $vol;
}
/**
* Page to add or edit an edition
*/
function epublish_admin_volume_edit($pid = NULL, $volume = NULL) {
if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) {
return epublish_del_volume($pid, $volume);
} elseif ($pid) {
$volume = epublish_get_volume($pid, $volume);
}
//return epublish_form_volume($volume);
$output = drupal_get_form('epublish_form_volume',$volume);
return $output;
}
/**
* epublish_form_volume: return a form for editing a publication volume
*
* @param $edit
* an array of values handled by the form
*
* @return
* An HTML-formatted form
*/
function epublish_form_volume($edit = NULL) {
$edit = (object) $edit;
$publication = epublish_get_pub($edit->pid);
$form[] = array('#value' => '' . t('Volume !vol of publication "!pub"',
array('!vol' => $edit->volume, '!pub' => l($publication->name, "admin/epublish/edit/publication/$publication->pid"))) . "
\n");
$form["pid"] = array(
'#type' => 'hidden',
'#value' => $edit->pid,
);
$form["volume"] = array(
'#type' => 'hidden',
'#value' => $edit->volume,
);
$form['dateline'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $edit->dateline,
'#size' => 50,
'#maxlength' => 128,
'#description' => t('A name for this volume. Since many publications begin a new volume annually,
the name might simply be the name of that year, e.g., "2004."'),
);
$form[] = array(
'#type' => 'submit',
'#value' => t("Submit"),
);
$form[] = array(
'#type' => 'submit',
'#value' => t("Delete"),
);
return $form;
}
function epublish_volume() {
$output = drupal_get_form('epublish_form_volume');
return $output;
}
/**
* epublish_save_volume: save changes to a publication volume
*
* @param $edit
* an array of values to be saved
*
* @return
* the same array
*/
function epublish_form_volume_submit($form_id, $edit) {
if ($edit['action'] == 'delete') {
epublish_del_volume($edit['pid'], $edit['volume']);
} else {
db_query("DELETE FROM {epublish_volume} WHERE pid = '%d' AND volume = '%d'",
$edit['pid'], $edit['volume']);
db_query("INSERT INTO {epublish_volume} (pid, volume, dateline) VALUES ('%d', '%d', '%s')",
$edit['pid'], $edit['volume'], $edit['dateline']);
drupal_set_message(t('The volume name "!title" has been updated.', array('!title' => $edit['dateline'])));
}
return 'admin/epublish';
}
/**
* epublish_del_volume: delete a publication volume name
*
* @param $edit
* an array with the values specifying the volume to be deleted
*
* @return
* A message stating that the volume has been deleted
*/
function epublish_del_volume($pid, $volume) {
$publication = epublish_get_pub($pid);
$vol = epublish_get_volume($pid, $volume);
if (($_POST['op'] == t('Delete')) && ($_POST ['form_id'] == 'confirm_form' )) {
db_query("DELETE FROM {epublish_volume} WHERE pid = '%d' AND volume = '%d'", $pid, $volume);
drupal_set_message(t('Removed volume name "!volume" from publication "!publication."',
array('!volume' => $vol->dateline, '!publication' => $publication->name)));
drupal_goto("admin/epublish");
} else {
return drupal_get_form('confirm_form',
array('pid' => array( '#type' => hidden,'#value' => $pid),
'volume' => array( '#type' => hidden, '#value' => $volume)),
t('Are you sure you want to remove volume name !volume from publication !publication?',
array('!volume' => $vol->dateline, '!publication' => $publication->name)),
'admin/epublish',
t('This action cannot be undone.'),
t('Delete'),
t('Cancel'),'','');
}
}
/*******************************************
* NODES
******************************************/
/**
* epublish_get_edition_nodes: get a list of nodes from an edition
*
* @param $eid
* An edition ID
*
* @return
* An array containing all of the node IDs from that edition
*/
function epublish_get_edition_nodes($eid) {
$result = db_query(db_rewrite_sql("SELECT v.vid, v.nid FROM {node_revisions} v LEFT JOIN {epublish_edition_node} een ON v.vid = een.vid
LEFT JOIN {node} n ON v.nid = n.nid WHERE een.eid='%d' AND n.status='1' ORDER BY n.sticky DESC, n.created DESC"), $eid);
while ($node = db_fetch_object($result)) {
$nodes[] = $node->vid;
}
return $nodes;
}
/**
* epublish_add_node: add a node to an edition
*
* @param $eid
* An edition ID
* @param $nid
* A node ID
*/
function epublish_add_node($eid, $nid, $vid, $weight=0, $tid=0) {
epublish_del_node($eid, $nid, $vid);
db_query("INSERT INTO {epublish_edition_node} (eid, nid, weight, tid, vid) VALUES ('%d', '%d', '%d', '%d', '%d')", $eid, $nid, $weight, $tid, $vid);
}
/**
* epublish_del_node: delete a node from an edition
*
* @param $eid
* An edition ID
* @param $nid
* A node ID
*/
function epublish_del_node($eid, $nid, $vid) {
db_query("DELETE FROM {epublish_edition_node} WHERE eid = '%d' AND nid = '%d' AND vid = '%d'", $eid, $nid, $vid);
}
/**
* epublish_admin_node: generate the form for adding nodes to editions
*
* @param $edit
* an array of values to be saved
*/
function epublish_admin_node_head() {
$output = drupal_get_form('epublish_admin_node');
return $output;
}
function epublish_admin_node() {
$eid = arg(3);
$filter = arg(4) ? arg(4) : 0;
$edition = epublish_get_edition($eid);
$sid = epublish_assign_section($edition);
$form['eid'] = array(
'#type' => 'hidden',
'#value' => $eid,
);
$publication = epublish_get_pub($edition->pid);
$exclusions = _epublish_build_node_exclusions(epublish_get_edition_nodes($eid));
$filters[] = array(t('View posts that are new or updated'), "WHERE $exclusions ORDER BY n.changed DESC");
$filters[] = array(t('View posts that need approval'), "WHERE ($exclusions) AND (n.status = 0 OR n.moderate = 1) ORDER BY n.changed DESC");
$filters[] = array(t('View posts that are promoted'), "WHERE ($exclusions) AND (n.status = 1 AND n.promote = 1) ORDER BY n.changed DESC");
$filters[] = array(t('View posts that are not promoted'), "WHERE ($exclusions) AND (n.status = 1 AND n.promote = 0) ORDER BY n.changed DESC");
$filters[] = array(t('View posts that are sticky'), "WHERE ($exclusions) AND (n.status = 1 AND n.sticky = 1) ORDER BY n.changed DESC");
$filters[] = array(t('View posts that are unpublished'), "WHERE ($exclusions) AND (n.status = 0 AND n.moderate = 0) ORDER BY n.changed DESC");
// Render filter form:
$options = array();
foreach ($filters as $key => $value) {
$options[] = $value[0];
}
$form[] = array('#value' => "\n");
$form['filter'] = array(
'#type' => 'select',
'#title' => t('Filter options'),
'#default_value' => $filter,
'#options' => $options,
);
$form[] = array(
'#type' => 'submit',
'#value' => t('Filter'),
);
$form[] = array('#value' => '
');
$result = pager_query("SELECT DISTINCT (v.vid), v.nid, v.title, n.changed, n.type, n.status
FROM {node_revisions} v LEFT JOIN {node} n ON v.nid = n.nid ". $filters[$filter][1], 50);
// Make sure the update controls are disabled if we don't have any rows to select from.
$disabled = !db_num_rows($result);
$form['op'] = array(
'#type' => 'submit',
'#value' => t('Add checked items to this edition'),
'#attributes' => ($disabled ? array('disabled' => 'disabled') : array()),
);
while ($node = db_fetch_object($result)) {
$nodes[$node->vid] = '';
$node->tid = 0;
$node->weight = 0;
$topics = epublish_topic_selection_list($sid);
$sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
$count = db_num_rows(db_query($sql_count, $node->nid));
if ($count > 1) {
$form['title'][$node->vid] = array('#value' => l($node->title, 'node/'. $node->nid .'/revisions/'. $node->vid .'/view') .' '.
theme('mark', node_mark($node->nid, $node->changed)));
}
else {
$form['title'][$node->vid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)));
}
$form['name'][$node->vid] = array('#value' => node_get_types('name', $node));
$form['tid']['tid_' . $node->vid] = array('#type' => 'select', '#default_value' => $node->tid,
'#options' => $topics, '#attributes' => array('onchange'=>'onChangeTID(' . $node->vid . ')'));
$form['status'][$node->vid] = array('#value' => ($node->status ? t('published') : t('not published')));
$form['weight']['weight_' . $node->vid] = array('#type' => 'weight', '#default_value' => $node->weight,
'#delta' => 30, '#attributes' => array('onchange'=>'onChangeWeight(' . $node->vid . ')'));
}
$form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes);
$form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
$form[] = array('#value' => '' . $filters[$filter][0] . '
');
drupal_set_title(t('Add Posts to !pub', array('!pub' => "$publication->name, " . theme('epublish_edition_reference', $edition))));
return $form;
}
function epublish_headlines() {//TODO another mystery function???
$output = drupal_get_form('epublish_admin_node');
return $output;
}
function theme_epublish_admin_node($form) {
// create the headlines table
if (isset($form['title']) && is_array($form['title'])) {
$rows = array();
foreach (element_children($form['title']) as $key) {
$row = array();
$row[] = drupal_render($form['nodes'][$key]);
$row[] = drupal_render($form['title'][$key]);
$row[] = drupal_render($form['name'][$key]);
$row[] = drupal_render($form['tid']['tid_' . $key]);
$row[] = drupal_render($form['status'][$key]);
$row[] = drupal_render($form['weight']['weight_' . $key]);
$rows[] = $row;
}
} else {
$rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6'));
}
// Overview table:
$header = array(NULL, t('Title'), t('Topic'), t('Type'), t('Status'), t('Weight'));
$output = theme('table', $header, $rows);
if ($form['pager']['#value']) {
$output .= drupal_render($form['pager']);
}
// put the headlines table below the rest of the form content
$output = drupal_render($form) . $output;
return $output;
}
function epublish_admin_node_submit($form_id, $edit) {
$op = $_POST['op'];
if ($op == t('Add checked items to this edition') && isset($edit['nodes'])) {
$nodes_added = 0;
foreach ($edit['nodes'] as $vid => $checked) {
if ($checked) {
$sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
$nid = db_fetch_object(db_query($sql, $vid));
epublish_add_node($edit['eid'], $nid->nid, $vid, $edit['weight_' . $vid], $edit['tid_' . $vid]);
$nodes_added++;
}
}
if ($nodes_added) {
drupal_set_message(format_plural($nodes_added, 'One headline was added to this edition.', '@count headlines were added to this edition.'));
} else {
drupal_set_message(t('The update has been performed.'));
}
return 'admin/epublish/edit/edition/' . $edit['eid'];
}
return 'admin/epublish/headlines/' . $edit['eid'] . '/' . $edit['filter'];
}
/**
* epublish_get_term: get a taxonomy term or a pseudo-term for "miscellaneous" or "top stories"
*
* @param $tid
* a topic ID
* @param $vid
* a vocabulary ID
*
* @return
* A term object
*/
function epublish_get_term($tid, $sid) {
if ($tid > 0) {
return module_invoke('taxonomy', 'get_term', $tid);
}
$section = epublish_get_section($sid);
$vid = $section->vid;
if ($tid == -2) {
$term = db_fetch_object(db_query("SELECT vid FROM {vocabulary} WHERE vid = '%d'", $vid));
$term->name = variable_get('epublish_advertisement', t('advertisement'));
} else if ($tid == -1) {
$term = db_fetch_object(db_query("SELECT vid FROM {vocabulary} WHERE vid = '%d'", $vid));
$term->name = variable_get('epublish_top_stories', t('top stories'));
} else {
$term = db_fetch_object(db_query("SELECT vid FROM {vocabulary} WHERE vid = '%d'", $vid));
$term->name = variable_get('epublish_miscellaneous', t('miscellaneous'));
}
$term->tid = $tid;
return $term;
}
/**
* _epublish_build_node_inclusions: internal function that builds a set of SQL conditions for
* specifying which node types should be included in a query.
*
* @param $node_types
* An array of node types to include
*
* @return
* The SQL conditions that should appear in the WHERE clause of a SELECT statement.
*/
function _epublish_build_node_inclusions($node_types = array()) {
if (count($node_types)) {
return " n.type='" . implode("' OR n.type='", $node_types) . "'";
} else {
return " n.type=n.type";
}
}
/**
* _epublish_build_node_exclusions: internal function that builds a set of SQL conditions for
* specifying which nodes should be excluded in a query.
*
* @param $nodes
* An array of nodes to include
*
* @return
* The SQL conditions that should appear in the WHERE clause of a SELECT statement.
*/
function _epublish_build_node_exclusions($nodes = array()) {
if (count($nodes)) {
return 'v.vid!=' . implode(' AND v.vid!=', $nodes);
} else {
return 'v.vid!=0';
}
}
/**
* epublish_topic_terms: get a list of taxonomy terms encompassed by a topic
*
* @param $tid
* A term ID number
* @param $sid
* A section ID number
*
* @return
* An associative array of the term IDs and their names.
*/
function _epublish_topic_term_inclusions($tid, $sid) {
$terms = array();
if ($tid > 0) {
$terms[] = $tid;
$section = epublish_get_section($sid);
$tree = module_invoke('taxonomy', 'get_tree', $section->vid, $tid);
if ($tree) {
foreach ($tree as $term) {
$terms[] = $term->tid;
}
}
}
return 'tn.tid=' . implode(' OR tn.tid =', $terms);
}
function _epublish_topics_node_count(&$topics) {
$count = 0;
foreach ($topics as $topic) {
$count += count($topic->nodes);
}
return $count;
}
/**
* Prepares both the custom breadcrumb trail and the forward/backward
* navigation for a node presented as part of an epublish edition.
*
* @ingroup themeable
*/
function theme_epublish_navigation($node, $eid) {
if ($node->nid) {
$og = variable_get('epublish_og', 0);
$output .= '';
$edition = epublish_get_edition($eid);
$publication = epublish_get_pub($edition->pid);
$sid = epublish_assign_section($edition);
$topics = epublish_section_topics($sid, $edition->eid);
$topic = current($topics);
$vid = current($topic->nodes);
$sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
$nid = db_fetch_object(db_query($sql, $vid));
$sql2 = "SELECT group_nid FROM {og_ancestry} WHERE nid = %d";
$group = db_fetch_object(db_query($sql2, $nid->nid));
$gid = $group->group_nid;
// Construct the breadcrumb:
$node->breadcrumb = array();
if ($og == 1) {
$node->breadcrumb[] = array('path' => "og/epublish/$gid/$publication->pid", 'title' => $publication->name);
$node->breadcrumb[] = array('path' => "og/epublish/$gid/$edition->pid/$edition->eid", 'title' => theme('epublish_edition_reference', $edition));
}
else {
$node->breadcrumb[] = array('path' => "epublish/$publication->pid", 'title' => $publication->name);
$node->breadcrumb[] = array('path' => "epublish/$edition->pid/$edition->eid", 'title' => theme('epublish_edition_reference', $edition));
}
$sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
$count = db_num_rows(db_query($sql_count, $node->nid));
if ($count > 1) {
$node->breadcrumb[] = array('path' => "node/$node->nid/revisions/$node->vid/view", 'title' => $node->title);
}
else {
$node->breadcrumb[] = array('path' => "node/$node->nid", 'title' => $node->title);
}
menu_set_location($node->breadcrumb);
if ($prev = epublish_prev($node, $topics)) {
$sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
$count = db_num_rows(db_query($sql_count, $prev->nid));
if ($count > 1) {
$links[] = "Previous story: " . l($prev->title, 'node/'. $prev->nid .'/revisions/'. $prev->vid .'/view');
}
else {
$links[] = "Previous story: " . l($prev->title, 'node/'. $prev->nid);
}
}
if ($next = epublish_next($node, $topics)) {
$sql_count = "SELECT nid FROM {node_revisions} WHERE nid = %d";
$count = db_num_rows(db_query($sql_count, $next->nid));
if ($count > 1) {
$links[] = "Next story: " . l($next->title, 'node/'. $next->nid .'/revisions/'. $next->vid .'/view');
}
else {
$links[] = "Next story: " . l($next->title, 'node/'. $next->nid);
}
}
if ($og == 1) {
$output .= "
Published in " . l("$publication->name", "og/epublish/$gid/$publication->pid") .", ".
l(theme('epublish_edition_reference', $edition), "og/epublish/$gid/$publication->pid/$edition->eid") ."
\n";
}
else {
$output .= "Published in " . l("$publication->name", "epublish/$publication->pid") .", ".
l(theme('epublish_edition_reference', $edition), "epublish/$publication->pid/$edition->eid") ."
\n";
}
$output .= theme('item_list', $links);
$output .= '';
}
$node->content['body']['#value'] = $node->body.$output;
return $node;
}
function epublish_prev($node, $topics) {
$prev_vid = NULL;
foreach ($topics as $topic) {
foreach ($topic->nodes as $vid) {
if ($vid == $node->vid) {
$sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
$nid = db_fetch_object(db_query($sql, $prev_vid));
return $prev_vid ? node_load($nid, $prev_vid) : $prev_vid;
}
$prev_vid = $vid;
}
}
}
function epublish_next($node, $topics) {
$next_vid = false;
foreach ($topics as $topic) {
foreach ($topic->nodes as $vid) {
if ($next_vid) {
$sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
$nid = db_fetch_object(db_query($sql, $vid));
return node_load($nid, $vid);
}
if ($vid == $node->vid) {
$next_vid = true;
}
}
}
return NULL;
}
?>