? node_breadcrumb2.patch Index: node_breadcrumb.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/node_breadcrumb/node_breadcrumb.info,v retrieving revision 1.8 diff -u -p -r1.8 node_breadcrumb.info --- node_breadcrumb.info 15 Apr 2008 13:25:34 -0000 1.8 +++ node_breadcrumb.info 30 Apr 2008 09:07:50 -0000 @@ -1,5 +1,5 @@ ; $Id: node_breadcrumb.info,v 1.8 2008/04/15 13:25:34 edhel Exp $ name = Node breadcrumb description = Allow you to customize menu location and breadcrumb of nodes depending on their content type, associated terms and others conditions. -version = "5.x-1.0-dev" +version = "5.x-2.0-beta2" dependencies = menu Index: node_breadcrumb.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/node_breadcrumb/node_breadcrumb.install,v retrieving revision 1.6 diff -u -p -r1.6 node_breadcrumb.install --- node_breadcrumb.install 15 Apr 2008 13:25:34 -0000 1.6 +++ node_breadcrumb.install 30 Apr 2008 09:07:50 -0000 @@ -2,44 +2,44 @@ // $Id: node_breadcrumb.install,v 1.6 2008/04/15 13:25:34 edhel Exp $ function node_breadcrumb_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {node_breadcrumb_rule} ( - rid int NOT NULL auto_increment, - node_type varchar(255) default NULL, - tid1 int default NULL, - tid2 int default NULL, - mid int default NULL, - weight tinyint NOT NULL default '0', - `condition` text, - PRIMARY KEY (rid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - case 'pgsql': - db_query("CREATE TABLE {node_breadcrumb_rule} ( - rid serial, - node_type varchar(255) default NULL, - tid1 integer default NULL, - tid2 integer default NULL, - mid integer default NULL, - weight smallint NOT NULL default '0', - condition text, - PRIMARY KEY (rid) - )"); - break; - } - drupal_set_message("node_breadcrumb_rule table created."); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + db_query("CREATE TABLE {node_breadcrumb_rule} ( + rid int NOT NULL auto_increment, + node_type varchar(255) default NULL, + tid1 int default NULL, + tid2 int default NULL, + mid int default NULL, + weight tinyint NOT NULL default '0', + `condition` text, + PRIMARY KEY (rid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + break; + case 'pgsql': + db_query("CREATE TABLE {node_breadcrumb_rule} ( + rid serial, + node_type varchar(255) default NULL, + tid1 integer default NULL, + tid2 integer default NULL, + mid integer default NULL, + weight smallint NOT NULL default '0', + condition text, + PRIMARY KEY (rid) + )"); + break; + } + drupal_set_message("node_breadcrumb_rule table created."); } function node_breadcrumb_uninstall() { - if (db_table_exists('node_breadcrumb_rule')) { - db_query("DROP TABLE {node_breadcrumb_rule}"); - } - drupal_set_message("node_breadcrumb_rule table dropped."); + if (db_table_exists('node_breadcrumb_rule')) { + db_query("DROP TABLE {node_breadcrumb_rule}"); + } + drupal_set_message("node_breadcrumb_rule table dropped."); } function node_breadcrumb_update_1() { - $ret[] = update_sql("ALTER TABLE {node_breadcrumb_rule} ADD condition text"); - return $ret; + $ret[] = update_sql("ALTER TABLE {node_breadcrumb_rule} ADD condition text"); + return $ret; } Index: node_breadcrumb.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/node_breadcrumb/node_breadcrumb.module,v retrieving revision 1.15 diff -u -p -r1.15 node_breadcrumb.module --- node_breadcrumb.module 26 Apr 2008 06:47:15 -0000 1.15 +++ node_breadcrumb.module 30 Apr 2008 09:07:51 -0000 @@ -2,294 +2,293 @@ // $Id: node_breadcrumb.module,v 1.15 2008/04/26 06:47:15 edhel Exp $ function _node_breadcrumb_set_location($mid, $last_path, $last_title) { - $location = array(); - while ($mid && ($item = menu_get_item($mid))) { - if ($item['path']) { - array_unshift($location, $item); - } - $mid = $item['pid']; - } - $location[] = array('path' => $last_path, $last_title); - menu_set_location($location); + $location = array(); + while ($mid && ($item = menu_get_item($mid))) { + if ($item['path']) { + array_unshift($location, $item); + } + $mid = $item['pid']; + } + $location[] = array('path' => $last_path, $last_title); + menu_set_location($location); } function node_breadcrumb_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { - if ($op == 'view' && $page) { - $db_rules = db_query("select * from {node_breadcrumb_rule} order by weight, rid"); - while ($rule = db_fetch_object($db_rules)) { - // check node type - if ($rule->node_type != '' && $node->type != $rule->node_type) continue; - // check terms - foreach (array($rule->tid1, $rule->tid2) as $tid) { - if ($tid > 0) { - if (empty($node->taxonomy[$tid])) continue 2; - } - elseif ($tid < 0) { - foreach ($node->taxonomy as $term) { - if ($term->vid == -$tid) continue 2; - } - continue 2; - } - } - // check php condition - if ($rule->condition != '') { - eval("\$condition=$rule->condition;"); - if (!$condition) { - continue; - } - } - // apply menu location - _node_breadcrumb_set_location($rule->mid, "node/$node->nid", $node->title); - break; - } - module_invoke_all("node_breadcrumb", $node); - } + if ($op == 'view' && $page) { + $db_rules = db_query("select * from {node_breadcrumb_rule} order by weight, rid"); + while ($rule = db_fetch_object($db_rules)) { + // check node type + if ($rule->node_type != '' && $node->type != $rule->node_type) continue; + // check terms + foreach (array($rule->tid1, $rule->tid2) as $tid) { + if ($tid > 0) { + if (empty($node->taxonomy[$tid])) continue 2; + } + elseif ($tid < 0) { + foreach ($node->taxonomy as $term) { + if ($term->vid == -$tid) continue 2; + } + continue 2; + } + } + // check php condition + if ($rule->condition != '') { + eval("\$condition=$rule->condition;"); + if (!$condition) { + continue; + } + } + // apply menu location + _node_breadcrumb_set_location($rule->mid, "node/$node->nid", $node->title); + break; + } + module_invoke_all("node_breadcrumb", $node); + } } function node_breadcrumb_perm() { - return array('administer node breadcrumb'); + return array('administer node breadcrumb'); } function node_breadcrumb_menu($may_cache) { - $items = array(); - if ($may_cache) { - $items[] = array('path' => 'admin/settings/node_breadcrumb', - 'title' => t('Node breadcrumb'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('node_breadcrumb_admin_settings'), - 'access' => user_access('administer node breadcrumb') - ); - } else { - drupal_add_css(drupal_get_path('module', 'node_breadcrumb') .'/node_breadcrumb.css'); - } - return $items; + $items = array(); + if ($may_cache) { + $items[] = array('path' => 'admin/settings/node_breadcrumb', + 'title' => t('Node breadcrumb'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('node_breadcrumb_admin_settings'), + 'access' => user_access('administer node breadcrumb') + ); + } + else { + drupal_add_css(drupal_get_path('module', 'node_breadcrumb') .'/node_breadcrumb.css'); + } + return $items; } function _node_breadcrumb_rule_form($fieldset_title, $node_type, $tids, $condition, $mid, $weight, $weight_delta, $submit) { - $form = array('#type' => 'fieldset', '#title' => $fieldset_title); + $form = array('#type' => 'fieldset', '#title' => $fieldset_title); - // node type - $types = node_get_types(); - $types_select = array( - '#type' => 'select', - '#title' => t('Content type'), - '#options' => array('' => "<" . t('none') . ">") - ); - foreach ($types as $type) { - $types_select['#options'][$type->type] = $type->name; - } - if ($type) { - $types_select['#default_value'] = $node_type; - } - $form['node_type'] = $types_select; - - // term - if (module_exists('taxonomy')) { - $form['tid'] = array('#type' => 'fieldset', '#title' => t('Categories'), '#attributes' => array('class' => 'node_breadcrumb_categories')); - $vocabularies = taxonomy_get_vocabularies(); - $none_option = "<" . t('none') . ">"; - $vid2tid = array(); - if (is_array($tids)) { - foreach($tids as $tid) { - if ($tid > 0) { - $term = taxonomy_get_term($tid); - $vid2tid[$term->vid] = $tid; - } - elseif ($tid < 0) { - $vid2tid[-$tid] = $tid; - } - } - } - foreach ($vocabularies as $vocabulary) { - $taxonomy_form = taxonomy_form($vocabulary->vid); - unset($taxonomy_form['#options']['']); - $taxonomy_form['#multiple'] = false; - $taxonomy_form['#default_value'] = $vid2tid[$vocabulary->vid] ? $vid2tid[$vocabulary->vid] : 0; - unset($taxonomy_form['#size']); - unset($all_option); - $all_option->option = array(-$vocabulary->vid => "<" . t("any"). ">"); - array_unshift($taxonomy_form['#options'], $all_option); - array_unshift($taxonomy_form['#options'], $none_option); - $form['tid']["vid_$vocabulary->vid"] = $taxonomy_form; - } - } - - // php condition - $form['condition'] = array( - '#type' => 'textarea', - '#rows' => 1, - '#title' => t('Condition'), - '#description' => t('Additional PHP expression, e. g., $node->type == \'story\' || $node->type == \'news\''), - '#default_value' => $condition, - ); - - // menu item - $form['mid'] = array( - '#type' => 'select', - '#title' => t('Menu item'), - '#required' => true, - '#options' => menu_parent_options(0), - '#default_value' => $mid, - ); - - // weight - $form['weight'] = array( - '#type' => 'weight', - '#title' => t('Weight'), - '#default_value' => $weight, - '#required' => true, - '#delta' => $weight_delta, - ); + // node type + $types = node_get_types(); + $types_select = array( + '#type' => 'select', + '#title' => t('Content type'), + '#options' => array('' => '<'. t('none') .'>') + ); + foreach ($types as $type) { + $types_select['#options'][$type->type] = $type->name; + } + if ($type) { + $types_select['#default_value'] = $node_type; + } + $form['node_type'] = $types_select; + + // term + if (module_exists('taxonomy')) { + $form['tid'] = array('#type' => 'fieldset', '#title' => t('Categories'), '#attributes' => array('class' => 'node_breadcrumb_categories')); + $vocabularies = taxonomy_get_vocabularies(); + $none_option = '<'. t('none') .'>'; + $vid2tid = array(); + if (is_array($tids)) { + foreach ($tids as $tid) { + if ($tid > 0) { + $term = taxonomy_get_term($tid); + $vid2tid[$term->vid] = $tid; + } + elseif ($tid < 0) { + $vid2tid[-$tid] = $tid; + } + } + } + foreach ($vocabularies as $vocabulary) { + $taxonomy_form = taxonomy_form($vocabulary->vid); + unset($taxonomy_form['#options']['']); + $taxonomy_form['#multiple'] = false; + $taxonomy_form['#default_value'] = $vid2tid[$vocabulary->vid] ? $vid2tid[$vocabulary->vid] : 0; + unset($taxonomy_form['#size']); + unset($all_option); + $all_option->option = array(-$vocabulary->vid => '<'. t('any' ) .'>'); + array_unshift($taxonomy_form['#options'], $all_option); + array_unshift($taxonomy_form['#options'], $none_option); + $form['tid']["vid_$vocabulary->vid"] = $taxonomy_form; + } + } + + // php condition + $form['condition'] = array( + '#type' => 'textarea', + '#rows' => 1, + '#title' => t('Condition'), + '#description' => t('Additional PHP expression, e. g., $node->type == \'story\' || $node->type == \'news\''), + '#default_value' => $condition, + ); + + // menu item + $form['mid'] = array( + '#type' => 'select', + '#title' => t('Menu item'), + '#required' => true, + '#options' => menu_parent_options(0), + '#default_value' => $mid, + ); + + // weight + $form['weight'] = array( + '#type' => 'weight', + '#title' => t('Weight'), + '#default_value' => $weight, + '#required' => true, + '#delta' => $weight_delta, + ); - // submit - $form['submit'] = array('#type' => 'submit', '#value' => $submit); + // submit + $form['submit'] = array('#type' => 'submit', '#value' => $submit); - return $form; + return $form; } function node_breadcrumb_admin_settings($rid = NULL) { - $weight_delta = max(5, db_result(db_query("select max(abs(weight)) from {node_breadcrumb_rule}")) + 1); - if (module_exists('taxonomy')) $vocabularies = taxonomy_get_vocabularies(); - $types = node_get_types(); - - // add rule - $form['add'] = _node_breadcrumb_rule_form(t('Add rule'), NULL, NULL, NULL, NULL, 0, $weight_delta, t('Add rule')); - - // edit rule - if ($rid) { - $db_rule = db_query("select * from {node_breadcrumb_rule} where rid=%d", $rid); - $rule = db_fetch_object($db_rule); - if ($rule->rid) { - $form['edit'] = _node_breadcrumb_rule_form(t('Edit rule'), $rule->node_type, array($rule->tid1, $rule->tid2), $rule->condition, $rule->mid, $rule->weight, $weight_delta, t('Save rule')); - $form['edit']['rid'] = array('#type' => 'hidden', '#value' => $rid); - $form['edit']['cancel'] = array('#type' => 'submit', '#value' => t('Cancel')); - unset($form['add']); - } - } - - // rules - $db_rules = db_query("select * from {node_breadcrumb_rule} order by weight, rid"); - while ($rule = db_fetch_object($db_rules)) { - $menu_item = menu_get_item($rule->mid); - $terms = array(); - if (module_exists('taxonomy')) { - if ($rule->tid1) { - $term = taxonomy_get_term($rule->tid1); - $terms[] = $rule->tid1 > 0 ? l($term->name, "taxonomy/term/$rule->tid1") : (t("any of") . " <" . $vocabularies[-$rule->tid1]->name . ">"); - } - if ($rule->tid2) { - $term = taxonomy_get_term($rule->tid2); - $terms[] = l($term->name, "taxonomy/term/$rule->tid2"); - } - } - unset($condition); - if ($rule->condition != '') { - $condition = check_plain($rule->condition); - $js_condition = check_plain(str_replace("'", "\\'", $rule->condition)); - $condition = "PHP"; - } - $rids[$rule->rid] = ''; - $form['rules']['node_type'][$rule->rid] = array('#value' => $types[$rule->node_type]->name); - $form['rules']['tid'][$rule->rid] = array('#value' => empty($terms) ? "<" . t('none') . ">" : join(", ", $terms)); - $form['rules']['condition'][$rule->rid] = array('#value' => $condition); - $form['rules']['mid'][$rule->rid] = array('#value' => l($menu_item['title'], $menu_item['path'])); - $form['rules']['weight']["weight_$rule->rid"] = array('#type' => 'weight', '#default_value' => $rule->weight, '#required' => true, '#delta' => $weight_delta); - $form['rules']['edit'][$rule->rid] = array('#value' => l(t('edit'), "admin/settings/node_breadcrumb/$rule->rid")); - } - $form['rules']['delete'] = array('#type' => 'checkboxes', '#options' => $rids); - if ($form['rules']['node_type']) { - $form['rules']['submit'] = array('#type' => 'submit', '#value' => t('Delete rule')); - $form['rules']['save'] = array('#type' => 'submit', '#value' => t('Save')); - } - return $form; + $weight_delta = max(5, db_result(db_query("select max(abs(weight)) from {node_breadcrumb_rule}")) + 1); + if (module_exists('taxonomy')) $vocabularies = taxonomy_get_vocabularies(); + $types = node_get_types(); + + // add rule + $form['add'] = _node_breadcrumb_rule_form(t('Add rule'), NULL, NULL, NULL, NULL, 0, $weight_delta, t('Add rule')); + + // edit rule + if ($rid) { + $db_rule = db_query("select * from {node_breadcrumb_rule} where rid=%d", $rid); + $rule = db_fetch_object($db_rule); + if ($rule->rid) { + $form['edit'] = _node_breadcrumb_rule_form(t('Edit rule'), $rule->node_type, array($rule->tid1, $rule->tid2), $rule->condition, $rule->mid, $rule->weight, $weight_delta, t('Save rule')); + $form['edit']['rid'] = array('#type' => 'hidden', '#value' => $rid); + $form['edit']['cancel'] = array('#type' => 'submit', '#value' => t('Cancel')); + unset($form['add']); + } + } + + // rules + $db_rules = db_query("select * from {node_breadcrumb_rule} order by weight, rid"); + while ($rule = db_fetch_object($db_rules)) { + $menu_item = menu_get_item($rule->mid); + $terms = array(); + if (module_exists('taxonomy')) { + if ($rule->tid1) { + $term = taxonomy_get_term($rule->tid1); + $terms[] = $rule->tid1 > 0 ? l($term->name, 'taxonomy/term/'. $rule->tid1) : (t('any of') .' <'. $vocabularies[-$rule->tid1]->name .'>'); + } + if ($rule->tid2) { + $term = taxonomy_get_term($rule->tid2); + $terms[] = l($term->name, 'taxonomy/term/'. $rule->tid2); + } + } + unset($condition); + if ($rule->condition != '') { + $condition = check_plain($rule->condition); + $js_condition = check_plain(str_replace("'", "\\'", $rule->condition)); + $condition = "PHP"; + } + $rids[$rule->rid] = ''; + $form['rules']['node_type'][$rule->rid] = array('#value' => $types[$rule->node_type]->name); + $form['rules']['tid'][$rule->rid] = array('#value' => empty($terms) ? '<'. t('none') .'>' : join(', ', $terms)); + $form['rules']['condition'][$rule->rid] = array('#value' => $condition); + $form['rules']['mid'][$rule->rid] = array('#value' => l($menu_item['title'], $menu_item['path'])); + $form['rules']['weight']["weight_$rule->rid"] = array('#type' => 'weight', '#default_value' => $rule->weight, '#required' => true, '#delta' => $weight_delta); + $form['rules']['edit'][$rule->rid] = array('#value' => l(t('edit'), "admin/settings/node_breadcrumb/$rule->rid")); + } + $form['rules']['delete'] = array('#type' => 'checkboxes', '#options' => $rids); + if ($form['rules']['node_type']) { + $form['rules']['submit'] = array('#type' => 'submit', '#value' => t('Delete rule')); + $form['rules']['save'] = array('#type' => 'submit', '#value' => t('Save')); + } + return $form; } function theme_node_breadcrumb_admin_settings($form) { - $output = ""; - if (!empty($form['rules']['node_type'])) { - $header = array(theme('table_select_header_cell'), t('Type'), t('Term'), t('Condition'), t('Menu item'), t('Weight'), t('Operations')); - foreach (element_children($form['rules']['node_type']) as $rid) { - $rows[] = array( - drupal_render($form['rules']['delete'][$rid]), - drupal_render($form['rules']['node_type'][$rid]), - drupal_render($form['rules']['tid'][$rid]), - drupal_render($form['rules']['condition'][$rid]), - drupal_render($form['rules']['mid'][$rid]), - drupal_render($form['rules']['weight']["weight_$rid"]), - drupal_render($form['rules']['edit'][$rid]), - ); - } - $rows[] = array( - array('data' => drupal_render($form['rules']['submit']), 'colspan' => 5), - array('data' => drupal_render($form['rules']['save'])), - array('data' => ''), - ); - $rules = theme('table', $header, $rows); - $output .= "
" . t("Rules") . "$rules
"; - } - $output .= drupal_render($form); - return $output; + $output = ""; + if (!empty($form['rules']['node_type'])) { + $header = array(theme('table_select_header_cell'), t('Type'), t('Term'), t('Condition'), t('Menu item'), t('Weight'), t('Operations')); + foreach (element_children($form['rules']['node_type']) as $rid) { + $rows[] = array( + drupal_render($form['rules']['delete'][$rid]), + drupal_render($form['rules']['node_type'][$rid]), + drupal_render($form['rules']['tid'][$rid]), + drupal_render($form['rules']['condition'][$rid]), + drupal_render($form['rules']['mid'][$rid]), + drupal_render($form['rules']['weight']["weight_$rid"]), + drupal_render($form['rules']['edit'][$rid]), + ); + } + $rows[] = array( + array('data' => drupal_render($form['rules']['submit']), 'colspan' => 5), + array('data' => drupal_render($form['rules']['save'])), + array('data' => ''), + ); + $rules = theme('table', $header, $rows); + $output .= '
'. t('Rules') ."$rules
"; + } + $output .= drupal_render($form); + return $output; } function node_breadcrumb_admin_settings_validate($form_id, $values) { - if ($values['op'] == t('Delete rule') || $values['op'] == t('Save')) { - return; - } - - foreach ($values as $key => $value) { - if (substr($key, 0, 4) == 'vid_' && $value != 0) $tids++; - } - if ($tids > 2) { - form_set_error('tid', t('You may select not more than 2 terms.')); - } - elseif ($values['node_type'] == '' && $tids == 0 && empty($values['condition'])) { - form_set_error('', t('Fill the form below.')); - } + if ($values['op'] == t('Delete rule') || $values['op'] == t('Save')) { + return; + } + + foreach ($values as $key => $value) { + if (substr($key, 0, 4) == 'vid_' && $value != 0) $tids++; + } + if ($tids > 2) { + form_set_error('tid', t('You may select not more than 2 terms.')); + } + elseif ($values['node_type'] == '' && $tids == 0 && empty($values['condition'])) { + form_set_error('', t('Fill the form below.')); + } } function node_breadcrumb_admin_settings_submit($form_id, $values) { - if ($values['op'] == t('Delete rule')) { - foreach ($values['delete'] as $value) { - if ($value) { - $rids[] = $value + 0; - } - } - if ($rids) { - db_query("DELETE FROM {node_breadcrumb_rule} WHERE rid IN (%s)", join(",", $rids)); - drupal_set_message(t('Rule(s) deleted.')); - } - } - elseif ($values['op'] == t('Save')) { - foreach ($values as $key => $weight) { - if (substr($key, 0, 7) == 'weight_') { - $rid = substr($key, 7); - db_query("update {node_breadcrumb_rule} set weight=%d where rid=%d", $weight, $rid); - } - } - drupal_set_message(t("Weights applied.")); - } - elseif ($values['op'] == t('Add rule')) { - $tid = array(); - foreach ($values as $key => $value) { - if (substr($key, 0, 4) == 'vid_' && $value != 0) $tid[] = $value; - } - $a = $GLOBALS['db_type'] == 'pgsql' ? "" : "`"; - db_query("INSERT INTO {node_breadcrumb_rule} (node_type, tid1, tid2, mid, weight, ${a}condition${a}) VALUES ('%s', %d, %d, %d, %d, '%s')", $values['node_type'], $tid[0], $tid[1], $values['mid'], $values['weight'], $values['condition']); - drupal_set_message(t('Rule added.')); - } - elseif ($values['op'] == t('Save rule')) { - $tid = array(); - foreach ($values as $key => $value) { - if (substr($key, 0, 4) == 'vid_' && $value != 0) $tid[] = $value; - } - $a = $GLOBALS['db_type'] == 'pgsql' ? "" : "`"; - db_query("UPDATE {node_breadcrumb_rule} SET node_type='%s', tid1=%d, tid2=%d, mid=%d, weight=%d, ${a}condition${a}='%s' WHERE rid=%d", $values['node_type'], $tid[0], $tid[1], $values['mid'], $values['weight'], $values['condition'], $values['rid']); - drupal_set_message(t('Rule saved.')); - return "admin/settings/node_breadcrumb"; - } - elseif ($values['op'] == t('Cancel')) { - return "admin/settings/node_breadcrumb"; - } + if ($values['op'] == t('Delete rule')) { + foreach ($values['delete'] as $value) { + if ($value) { + $rids[] = $value + 0; + } + } + if ($rids) { + db_query("DELETE FROM {node_breadcrumb_rule} WHERE rid IN (%s)", join(",", $rids)); + drupal_set_message(t('Rule(s) deleted.')); + } + } + elseif ($values['op'] == t('Save')) { + foreach ($values as $key => $weight) { + if (substr($key, 0, 7) == 'weight_') { + $rid = substr($key, 7); + db_query("update {node_breadcrumb_rule} set weight=%d where rid=%d", $weight, $rid); + } + } + drupal_set_message(t("Weights applied.")); + } + elseif ($values['op'] == t('Add rule')) { + $tid = array(); + foreach ($values as $key => $value) { + if (substr($key, 0, 4) == 'vid_' && $value != 0) $tid[] = $value; + } + $a = $GLOBALS['db_type'] == 'pgsql' ? "" : "`"; + db_query("INSERT INTO {node_breadcrumb_rule} (node_type, tid1, tid2, mid, weight, ${a}condition${a}) VALUES ('%s', %d, %d, %d, %d, '%s')", $values['node_type'], $tid[0], $tid[1], $values['mid'], $values['weight'], $values['condition']); + drupal_set_message(t('Rule added.')); + } + elseif ($values['op'] == t('Save rule')) { + $tid = array(); + foreach ($values as $key => $value) { + if (substr($key, 0, 4) == 'vid_' && $value != 0) $tid[] = $value; + } + $a = $GLOBALS['db_type'] == 'pgsql' ? "" : "`"; + db_query("UPDATE {node_breadcrumb_rule} SET node_type='%s', tid1=%d, tid2=%d, mid=%d, weight=%d, ${a}condition${a}='%s' WHERE rid=%d", $values['node_type'], $tid[0], $tid[1], $values['mid'], $values['weight'], $values['condition'], $values['rid']); + drupal_set_message(t('Rule saved.')); + return "admin/settings/node_breadcrumb"; + } + elseif ($values['op'] == t('Cancel')) { + return "admin/settings/node_breadcrumb"; + } } - -function d($var) {print "
"; print_r($var); print "
";}