Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Implementation of hook_menu().
- *
- */
- function execution_menu() {
- $items['executions'] = array(
- 'title' => 'Searchable Execution Database',
- 'page callback' => 'execution_database_search',
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- /**
- * Implementation of hook_node_info(). This function replaces hook_node_name()
- */
- function execution_node_info() {
- return array(
- 'execution' => array(
- 'name' => t('Execution'),
- 'module' => 'execution',
- 'description' => t("Add/Update/Delete executions from the DPIC database"),
- 'has_title' => TRUE,
- 'title_label' => t('Title (short description for site search. Usually just name of person executed)'),
- 'has_body' => false,
- )
- );
- }
- /**
- * Implementation of hook_access().
- *
- */
- function execution_access($op, $node, $account) {
- if ($op == 'create') {
- return user_access('create execution content', $account);
- }
- if ($op == 'update') {
- if (user_access('edit any execution content', $account) || (user_access('edit own execution content', $account) && ($account->uid == $node->uid))) {
- return TRUE;
- }
- }
- if ($op == 'delete') {
- if (user_access('delete any execution content', $account) || (user_access('delete own execution content', $account) && ($account->uid == $node->uid))) {
- return TRUE;
- }
- }
- }
- /**
- * Implementation of hook_perm().
- *
- */
- function execution_perm() {
- return array(
- 'create execution content',
- 'delete own execution content',
- 'delete any execution content',
- 'edit own execution content',
- 'edit any execution content',
- );
- }
- /**
- * Implementation of hook_form().
- *
- */
- function execution_form(&$node) {
- drupal_add_js($data = 'sites/all/modules/dpic/js/datepicker.js', $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE, $preprocess = TRUE);
- drupal_add_js($data = 'sites/all/modules/dpic/js/launchdate.js', $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE, $preprocess = TRUE);
- drupal_add_css($path = 'sites/all/modules/dpic/css/jquery-ui-themeroller.css', $type = 'module', $media = 'all', $preprocess = TRUE);
- // drupal_add_css($path = 'sites/all/modules/dpic/css/dpic.css', $type = 'module', $media = 'all', $preprocess = TRUE);
- // The site admin can decide if this node type has a title and body, and how
- // the fields should be labeled. We need to load these settings so we can
- // build the node form correctly.
- $type = node_get_types('type', $node);
- if ($type->has_title) {
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => check_plain($type->title_label),
- '#required' => TRUE,
- '#default_value' => $node->title,
- '#weight' => -5
- );
- }
- if ($type->has_body) {
- // In Drupal 6, we can use node_body_field() to get the body and filter
- // elements. This replaces the old textarea + filter_form() method of
- // setting this up. It will also ensure the teaser splitter gets set up
- // properly.
- $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
- }
- $form['exec_date'] = array(
- '#type' => 'textfield',
- '#title' => t('Execution Date'),
- '#default_value' => isset($node->exec_date) ? date("m/d/Y",$node->exec_date ) : '',
- '#required' => true
- );
- $form['exec_name'] = array(
- '#type' => 'textfield',
- '#title' => t('Name'),
- '#default_value' => isset($node->exec_name) ? $node->exec_name : '',
- '#required' => true
- );
- $form['age'] = array(
- '#type' => 'textfield',
- '#title' => t('Age'),
- '#default_value' => isset($node->age) ? $node->age : '',
- );
- $form['sex'] = array(
- '#type' => 'radios',
- '#title' => t('Sex'),
- '#default_value' => isset($node->sex) ? $node->sex : '',
- '#options' => array('m'=>t('Male'), 'f'=>t('Female')),
- '#required' => true
- );
- $form['federal'] = array(
- '#type' => 'select',
- '#title' => t('Federal'),
- '#default_value' => isset($node->federal) ? $node->federal : '',
- '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
- );
- $form['state'] = array(
- '#type' => 'select',
- '#title' => t('State'),
- '#default_value' => isset($node->state) ? $node->state : '',
- '#required' => true,
- '#options' => array(
- 'AL'=>"Alabama",
- 'AK'=>"Alaska",
- 'AZ'=>"Arizona",
- 'AR'=>"Arkansas",
- 'CA'=>"California",
- 'CO'=>"Colorado",
- 'CT'=>"Connecticut",
- 'DE'=>"Delaware",
- 'DC'=>"District Of Columbia",
- 'FL'=>"Florida",
- 'GA'=>"Georgia",
- 'HI'=>"Hawaii",
- 'ID'=>"Idaho",
- 'IL'=>"Illinois",
- 'IN'=>"Indiana",
- 'IA'=>"Iowa",
- 'KS'=>"Kansas",
- 'KY'=>"Kentucky",
- 'LA'=>"Louisiana",
- 'ME'=>"Maine",
- 'MD'=>"Maryland",
- 'MA'=>"Massachusetts",
- 'MI'=>"Michigan",
- 'MN'=>"Minnesota",
- 'MS'=>"Mississippi",
- 'MO'=>"Missouri",
- 'MT'=>"Montana",
- 'NE'=>"Nebraska",
- 'NV'=>"Nevada",
- 'NH'=>"New Hampshire",
- 'NJ'=>"New Jersey",
- 'NM'=>"New Mexico",
- 'NY'=>"New York",
- 'NC'=>"North Carolina",
- 'ND'=>"North Dakota",
- 'OH'=>"Ohio",
- 'OK'=>"Oklahoma",
- 'OR'=>"Oregon",
- 'PA'=>"Pennsylvania",
- 'RI'=>"Rhode Island",
- 'SC'=>"South Carolina",
- 'SD'=>"South Dakota",
- 'TN'=>"Tennessee",
- 'TX'=>"Texas",
- 'UT'=>"Utah",
- 'VT'=>"Vermont",
- 'VA'=>"Virginia",
- 'WA'=>"Washington",
- 'WV'=>"West Virginia",
- 'WI'=>"Wisconsin",
- 'WY'=>"Wyoming")
- );
- $form['race'] = array(
- '#type' => 'select',
- '#title' => t('Race'),
- '#default_value' => isset($node->race) ? $node->race : '',
- '#options' => array('White'=>'White','Black'=>'Black','Latino'=>'Latino','Native American'=>'Native American','Asian'=>'Asian','Other'=>'Other')
- );
- $options = array();
- $rs = db_query('select n.nid, n.title from {node} n where n.type="execution" and n.status=1 order by n.title');
- $options['none'] = '-- No Co-defendant --';
- while( $row = db_fetch_object($rs) ){
- $options[$row->nid] = $row->title;
- }
- $form['co_defendant'] = array(
- '#type' => 'select',
- '#title' => t('Co-defendant'),
- '#default_value' => isset($node->co_defendant) ? $node->co_defendant : '',
- '#options' => $options
- );
- $form['volunteer'] = array(
- '#type' => 'select',
- '#title' => t('Volunteer'),
- '#default_value' => isset($node->volunteer) ? $node->volunteer : '',
- '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
- );
- $form['juvenile'] = array(
- '#type' => 'select',
- '#title' => t('Juvenile'),
- '#default_value' => isset($node->juvenile) ? $node->juvenile : '',
- '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
- );
- $form['foreigner'] = array(
- '#type' => 'select',
- '#title' => t('Foreigner'),
- '#default_value' => isset($node->foreigner) ? $node->foreigner : '',
- '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
- );
- $form['dual_citizen'] = array(
- '#type' => 'select',
- '#title' => t('Dual Citizen'),
- '#default_value' => isset($node->dual_citizen) ? $node->dual_citizen : '',
- '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
- );
- $form['mentally_retarded'] = array(
- '#type' => 'select',
- '#title' => t('Mentally Retarded'),
- '#default_value' => isset($node->mentally_retarded) ? $node->mentally_retarded : '',
- '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
- );
- $form['method'] = array(
- '#type' => 'select',
- '#title' => t('Method'),
- '#default_value' => isset($node->method) ? $node->method : '',
- '#options' => array('Electrocution'=>'Electrocution','Firing Squad'=>'Firing Squad','Gas Chamber'=>'Gas Chamber','Hanging'=>'Hanging','Lethal Injection'=>'Lethal Injection'),
- '#required' => true
- );
- $form['region'] = array(
- '#type' => 'select',
- '#title' => t('Region'),
- '#default_value' => isset($node->region) ? $node->region : '',
- '#options' => array('M'=>'M','N'=>'N','S'=>'S','W'=>'W'),
- '#required' => true
- );
- $form['victims'] = array(
- '#type' => 'fieldset',
- '#title' => t('Victims'),
- '#weight' => 16,
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#tree' => TRUE,
- );
- $i = 1;
- //display boxes for all the links we have defaults for
- if( is_array($node->victims) && sizeof($node->victims) > 0 ) {
- foreach( $node->victims as $victim ){
- $form['victims'][$i] = array( '#type' => 'fieldset', '#title' => t('Victim #' . $i ), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, );
- $form['victims'][$i]['number'] = array( '#type' => 'textfield', '#title' => t('Number of Victims'), '#required' => FALSE, '#default_value' => '', '#default_value'=> $victim['number'] );
- $form['victims'][$i]['race'] = array( '#type' => 'select', '#title' => t('Race'), '#default_value' => isset($victim['race']) ? $victim['race'] : '', '#options' => array('White'=>'White','Black'=>'Black','Latino'=>'Latino','Native American'=>'Native American','Asian'=>'Asian','Other'=>'Other') );
- $i++;
- }
- }
- $end = $i + 2;
- //display 5 blank boxes
- for( $i; $i <= $end; $i++ ) {
- $form['victims'][$i] = array( '#type' => 'fieldset', '#title' => t('Victim #' . $i ), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, );
- $form['victims'][$i]['number'] = array( '#type' => 'textfield', '#title' => t('Number of Victims'), '#required' => FALSE, '#default_value' => '', '#default_value'=> '' );
- $form['victims'][$i]['race'] = array( '#type' => 'select', '#title' => t('Race'), '#default_value' =>'', '#options' => array('White'=>'White','Black'=>'Black','Latino'=>'Latino','Native American'=>'Native American','Asian'=>'Asian','Other'=>'Other') );
- }
- return $form;
- }
- /**
- * Implementation of hook_validate().
- */
- function execution_validate(&$node) {
- if ($node->age) {
- if (!is_numeric($node->age)) {
- form_set_error('age', t('Age must be a number.'));
- }
- }
- }
- /**
- * Implementation of hook_insert().
- *
- */
- function execution_insert($node) {
- //convert the time to a timestamp
- $node->exec_date = strtotime($node->exec_date);
- //save the campaign
- drupal_write_record('execution', $node );
- //insert the links
- foreach( $node->victims as $victim ) {
- //save the links
- if( !empty($victim['number']) && !empty($victim['race']) ){
- //link the link to the campaign
- $victim['vid'] = $node->vid;
- drupal_write_record('victim', $victim );
- }
- }
- }
- /**
- * Implementation of hook_update().
- *
- */
- function execution_update($node) {
- // if this is a new node or we're adding a new revision,
- if ($node->revision) {
- execution_insert($node);
- }
- else {
- //convert the time to a timestamp
- $node->exec_date = strtotime($node->exec_date);
- //save the campaign
- drupal_write_record('execution', $node, 'vid' );
- //delete all the links associated with the campaign
- $rs = db_query('delete from {victim} where vid=%d',$node->vid );
- //insert the links
- foreach( $node->victims as $victim ) {
- //save the links
- if( !empty($victim['number']) && !empty($victim['race']) ){
- //link the link to the campaign
- $victim['vid'] = $node->vid;
- drupal_write_record('victim', $victim );
- }
- }
- }
- }
- /**
- * Implementation of hook view
- */
- function execution_load($node) {
- $additions = db_fetch_object(db_query('SELECT * FROM {execution} e WHERE vid = %d', $node->vid));
- $sql = "select * from {victim} v where vid=%d order by race";
- $rs= db_query($sql, $node->vid);
- $additions->victims = array();
- while( $victim = db_fetch_array($rs) ) {
- $additions->victims[] = array(
- 'race' => $victim['race'],
- 'number' => $victim['number'],
- );
- }
- return $additions;
- }
- /**
- * Implementation of hook_nodeapi().
- *
- */
- function execution_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
- case 'delete revision':
- // Notice that we're matching a single revision based on the node's vid.
- db_query('DELETE FROM {execution} WHERE vid = %d', $node->vid);
- break;
- }
- }
- /**
- * Implementation of hook_delete().
- *
- */
- function execution_delete($node) {
- // Notice that we're matching all revision, by using the node's nid.
- db_query('DELETE FROM {execution} WHERE nid = %d', $node->nid);
- }
- /**
- * Implementation of hook_view().
- *
- */
- function execution_view($node, $teaser = FALSE, $page = FALSE) {
- $node = node_prepare($node, $teaser);
- $node->content['execution_info'] = array(
- '#value' => theme('execution_info', $node),
- '#weight' => 1,
- );
- return $node;
- }
- /**
- * Implementation of hook_theme().
- *
- */
- function execution_theme() {
- return array(
- 'execution_info' => array(
- 'arguments' => array('node'),
- ),
- );
- }
- /**
- * A custom theme function.
- *
- */
- function theme_execution_info($node) {
- $items = array();
- $items[] = '<strong>Name:</strong> ' . check_plain($node->exec_name);
- $items[] = '<strong>Date of Execution:</strong> ' . check_plain(date("m/d/Y",$node->exec_date ));
- $items[] = '<strong>Age:</strong> ' . check_plain($node->age);
- $items[] = '<strong>Race:</strong> ' . check_plain($node->race);
- $items[] = '<strong>State:</strong> ' . check_plain($node->state);
- $items[] = '<strong>Region:</strong> ' . check_plain($node->region);
- $items[] = '<strong>Method:</strong> ' . check_plain($node->method);
- $items[] = '<strong>Sex:</strong> ' . check_plain($node->sex);
- $items[] = '<strong>DPIC ID:</strong> ' . check_plain($node->exec_id);
- if( is_array($node->victims) && count($node->victims) > 0 ){
- $victims = '';
- foreach( $node->victims as $v ){
- $victims .= $v['number'] . ' ' . $v['race'] . ', ';
- }
- $items[] = '<strong>Victims:</strong> ' . $victims ;
- }
- $output = '<div id="exec-results">';
- $output .= theme('item_list', $items);
- $output .= '</div>';
- return $output;
- }
- /**
- * Search the execution database
- */
- function execution_database_search() {
- $output .= drupal_get_form('execution_search_form');
- return $output;
- }
- function execution_search_form($form_state) {
- $form['byname'] = array(
- '#type' => 'fieldset',
- '#title'=> 'Search by Name',
- '#collapsible' => TRUE,
- '#collapsed' => ($form_state['clicked_button']['#value'] == 'Search by Details') ? TRUE : FALSE,
- );
- $form['byname']['name'] = array(
- '#type' => 'textfield',
- '#default_value'=> ($form_state['values']['name']) ? $form_state['values']['name'] : ''
- );
- $form['byname']['submit_name'] = array('#type' => 'submit', '#value' => t('Search by Name'));
- $form['bydetails'] = array(
- '#type' => 'fieldset',
- '#title'=> 'Search by Details',
- '#collapsible' => TRUE,
- '#collapsed' => ($form_state['clicked_button']['#value'] == 'Search by Name') ? TRUE : FALSE
- );
- $years = array('all'=>'Search all Years');
- $sql = 'select distinct(from_unixtime(exec_date,"%Y")) as year from execution order by from_unixtime(exec_date,"%Y")';
- $rs = db_query($sql);
- while( $row = db_fetch_object($rs) )
- $years[$row->year] = $row->year;
- $form['bydetails']['year'] = array(
- '#type' => 'select',
- '#multiple' => true,
- '#size'=>5,
- '#title'=> 'Year',
- '#default_value' => ( $form_state['values']['year'] ) ? $form_state['values']['year']: array('all'),
- '#options' => $years
- );
- $ages = array('all'=>'Search all Ages');
- $sql = "select distinct(age) from execution order by age";
- $rs = db_query($sql);
- while( $row = db_fetch_object($rs) )
- $ages[$row->age] = $row->age;
- $form['bydetails']['age'] = array(
- '#type' => 'select',
- '#title'=> 'Age at Execution',
- '#multiple' => true,
- '#size'=>5,
- '#default_value' => ($form_state['values']['age']) ? $form_state['values']['age'] : array('all'),
- '#options' => $ages
- );
- $races = array('all'=>'Search all Races');
- $sql = "select distinct(race) from execution order by race";
- $rs = db_query($sql);
- while( $row = db_fetch_object($rs) )
- $races[$row->race] = $row->race;
- $form['bydetails']['race'] = array(
- '#type' => 'select',
- '#title'=> 'Race of Person Executed',
- '#default_value' => $form_state['values']['race'],
- '#options' => $races
- );
- $sexes = array('all'=>'Search all Genders');
- $sql = "select distinct(sex) from execution";
- $rs = db_query($sql);
- while( $row = db_fetch_object($rs) )
- $sexes[$row->sex] = $row->sex;
- $form['bydetails']['sex'] = array(
- '#type' => 'select',
- '#title'=> 'Gender of Person Executed',
- '#default_value' => $form_state['values']['sex'],
- '#options' => $sexes
- );
- $states = array('all'=>'Search all States');
- $sql = "select distinct(state) from execution order by state";
- $rs = db_query($sql);
- while( $row = db_fetch_object($rs) )
- $states[$row->state] = $row->state;
- $form['bydetails']['state'] = array(
- '#type' => 'select',
- '#title'=> 'State',
- '#default_value' => ($form_state['values']['state']) ? $form_state['values']['state']: array('all'),
- '#multiple' => true,
- '#size'=>5,
- '#options' => $states
- );
- $regions = array('all'=>'Search all Regions');
- $sql = "select distinct(region) from execution";
- $rs = db_query($sql);
- while( $row = db_fetch_object($rs) )
- $regions[$row->region] = $row->region;
- $form['bydetails']['region'] = array(
- '#type' => 'select',
- '#title'=> 'Region',
- '#default_value' => $form_state['values']['region'],
- '#options' => $regions
- );
- $victim_race = array('all'=>'Search all Victims');
- $sql = "select distinct(race) from victim order by race";
- $rs = db_query($sql);
- while( $row = db_fetch_object($rs) )
- $victim_race[$row->race] = $row->race;
- $form['bydetails']['victim_race'] = array(
- '#type' => 'select',
- '#title'=> 'Race of Victim',
- '#default_value' => ($form_state['values']['victim_race']) ? $form_state['values']['victim_race']: array('all'),
- '#multiple' => true,
- '#size'=>5,
- '#options' => $victim_race
- );
- $methods = array('all'=>'Search all Methods');
- $sql = "select distinct(method) from execution order by method";
- $rs = db_query($sql);
- while( $row = db_fetch_object($rs) )
- $methods[$row->method] = $row->method;
- $form['bydetails']['method'] = array(
- '#type' => 'select',
- '#title'=> 'Methods',
- '#default_value' => $form_state['values']['method'],
- '#options' => $methods
- );
- $form['bydetails']['factors'] = array(
- '#type' => 'select',
- '#title'=> 'Other Factors',
- '#multiple' => true,
- '#size'=>5,
- '#default_value' => ($form_state['values']['factors']) ? $form_state['values']['factors'] : array('all'),
- '#options' => array(
- 'all' => 'All Factors',
- 'juvenile' => 'Juvenile at the time of Crime',
- 'federal' => 'Federal',
- 'volunteer' => 'Volunteer',
- 'foreigner' => 'Foreign National',
- 'dual_citizen' => 'Dual Citizen',
- 'mentally_retarded' => 'Evidence of Mental Retardation',
- )
- );
- $form['bydetails']['submit_detail'] = array('#type' => 'submit', '#value' => t('Search by Details'), '#submit' => array('execution_search_by_detail'),);
- if( is_array($form_state['results']) && count($form_state['results']) > 0 ){
- drupal_set_message(t('<h2>Your Search Returned %d Results (see below)</h2>', array('%d'=>count($form_state['results']))));
- $output = t('<h2>Your Search Returned %d Results</h2>', array('%d'=>count($form_state['results'])));
- $rows = array();
- foreach( $form_state['results'] as $e ) {
- //get victims info
- if( is_array($e->victims) && count($e->victims) > 0 ){
- $victims = '';
- foreach( $e->victims as $v ){
- $victims .= $v['number'] . ' ' . $v['race'] . '<br /> ';
- }
- }
- //get other info
- $other_info = '';
- if( $e->juvenile =='y' )
- $other_info .= 'Juvenile at the time of Crime<br /> ';
- if( $e->federal =='y' )
- $other_info .= 'Federal<br /> ';
- if( $e->volunteer =='y' )
- $other_info .= 'Volunteer<br /> ';
- if( $e->foreigner =='y' )
- $other_info .= 'Foreign National<br /> ';
- if( $e->dual_citizen =='y' )
- $other_info .= 'Dual Citizen<br /> ';
- if( $e->mentally_retarded =='y' )
- $other_info .= 'Evidence of Mental Retardation<br /> ';
- $row = array( date("m/d/Y",$e->exec_date ), $e->exec_name, $e->age, $e->sex, $e->race, $victims, $e->state,$e->region,$e->method, $other_info );
- if( user_access('edit any execution content') ){
- $row[] = l('Edit','node/' . $e->nid . '/edit');
- }
- $rows[] = $row;
- }
- $header = array('Date','Name','Age','Sex','Race','Number and Race of Victims','State','Region','Method','Other');
- if( user_access('edit any execution content') ){
- $header[] = 'Edit';
- }
- $output = '<div id="execution_info">';
- $output .= theme('table', $header, $rows );
- $output .= '</div>';
- $form['results'] = array(
- '#type' => 'markup',
- '#value'=> $output
- );
- }
- return $form;
- }
- /**
- * Search by name
- * @return
- * @param $form Object
- * @param $form_state Object
- */
- function execution_search_form_submit($form, &$form_state) {
- $sql = 'select nid from execution where exec_name like "%%%s%%"';
- $rs = db_query( $sql, $form_state['values']['name'] );
- $form_state['results'] = array();
- while( $row = db_fetch_object($rs) ) {
- $form_state['results'][] = node_load($row->nid);
- }
- $form_state['rebuild'] = true;
- }
- function execution_search_by_detail( $form, &$form_state ) {
- $sql = 'select nid from execution where 1=1';
- //year of execution
- if( is_array($form_state['values']['year']) && count($form_state['values']['year']) > 0 && !array_key_exists('all',$form_state['values']['year']) ) {
- $years = $form_state['values']['year'];
- $sql .= ' and from_unixtime(exec_date,"%Y") in (' . implode(',',$years) . ')';
- }
- //age
- if( is_array($form_state['values']['age']) && count($form_state['values']['age']) > 0 && !array_key_exists('all',$form_state['values']['age']) ) {
- $ages = $form_state['values']['age'];
- $sql .= ' and age in (' . implode(',',$ages) . ')';
- }
- //race
- if( isset($form_state['values']['race']) && $form_state['values']['race'] != 'all' ) {
- $sql .= ' and race="' . $form_state['values']['race'] . '"';
- }
- //gender
- if( isset($form_state['values']['sex']) && $form_state['values']['sex'] != 'all' ) {
- $sql .= ' and sex="' . $form_state['values']['sex'] . '"';
- }
- //state
- if( is_array($form_state['values']['state']) && count($form_state['values']['state']) > 0 && !array_key_exists('all',$form_state['values']['state']) ) {
- $states = $form_state['values']['state'];
- foreach( $states as $key=>$value ){
- $states[$key] = '"' . $value . '"';
- }
- $sql .= ' and state in (' . implode(',',$states) . ')';
- }
- //region
- if( isset($form_state['values']['region']) && $form_state['values']['region'] != 'all' ) {
- $sql .= ' and region="' . $form_state['values']['region'] . '"';
- }
- //method
- if( isset($form_state['values']['method']) && $form_state['values']['method'] != 'all' ) {
- $sql .= ' and method="' . $form_state['values']['method'] . '"';
- }
- //other factors
- if( !array_key_exists( 'all', $form_state['values']['factors'] ) ) {
- $pieces = array();
- $factors_sql = '';
- if( array_key_exists( 'juvenile', $form_state['values']['factors'] ) )
- $pieces[] = 'juvenile="y"';
- if( array_key_exists( 'federal', $form_state['values']['factors'] ) )
- $pieces[] = 'federal="y"';
- if( array_key_exists( 'volunteer', $form_state['values']['factors'] ) )
- $pieces[] = 'volunteer="y"';
- if( array_key_exists( 'foreigner', $form_state['values']['factors'] ) )
- $pieces[] = 'foreigner="y"';
- if( array_key_exists( 'dual_citizen', $form_state['values']['factors'] ) )
- $pieces[] = 'dual_citizen="y"';
- if( array_key_exists( 'mentally_retarded', $form_state['values']['factors'] ) )
- $pieces[] = 'mentally_retarded="y"';
- if( count($pieces) > 0 )
- $factors_sql = implode( ' or ' , $pieces );
- }
- if( $factors_sql )
- $sql .= ' and (' . $factors_sql . ')';
- $sql .= ' order by exec_date';
- $rs = db_query( $sql, $form_state['values']['name'] );
- $form_state['results'] = array();
- while( $row = db_fetch_object($rs) ) {
- //we need to check the race of the victim sometimes
- if( array_key_exists( 'all', $form_state['values']['victim_race'] ) ) {
- $form_state['results'][] = node_load($row->nid);
- }else {
- $e = node_load($row->nid);
- if( is_array($e->victims) && count($e->victims) > 0 ){
- foreach( $e->victims as $v ){
- if( array_key_exists( $v['race'], $form_state['values']['victim_race'] ) )
- $form_state['results'][] = node_load($row->nid);
- }
- }
- }
- }
- $form_state['rebuild'] = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement