Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.58 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Implementation of hook_menu().
  5. *
  6. */
  7. function execution_menu() {
  8.  
  9. $items['executions'] = array(
  10. 'title' => 'Searchable Execution Database',
  11. 'page callback' => 'execution_database_search',
  12. 'access arguments' => array('access content'),
  13. 'type' => MENU_CALLBACK,
  14. );
  15.  
  16. return $items;
  17. }
  18.  
  19.  
  20.  
  21. /**
  22. * Implementation of hook_node_info(). This function replaces hook_node_name()
  23. */
  24. function execution_node_info() {
  25. return array(
  26. 'execution' => array(
  27. 'name' => t('Execution'),
  28. 'module' => 'execution',
  29. 'description' => t("Add/Update/Delete executions from the DPIC database"),
  30. 'has_title' => TRUE,
  31. 'title_label' => t('Title (short description for site search. Usually just name of person executed)'),
  32. 'has_body' => false,
  33. )
  34. );
  35. }
  36.  
  37. /**
  38. * Implementation of hook_access().
  39. *
  40. */
  41. function execution_access($op, $node, $account) {
  42. if ($op == 'create') {
  43. return user_access('create execution content', $account);
  44. }
  45.  
  46. if ($op == 'update') {
  47. if (user_access('edit any execution content', $account) || (user_access('edit own execution content', $account) && ($account->uid == $node->uid))) {
  48. return TRUE;
  49. }
  50. }
  51.  
  52. if ($op == 'delete') {
  53. if (user_access('delete any execution content', $account) || (user_access('delete own execution content', $account) && ($account->uid == $node->uid))) {
  54. return TRUE;
  55. }
  56. }
  57. }
  58.  
  59.  
  60. /**
  61. * Implementation of hook_perm().
  62. *
  63. */
  64. function execution_perm() {
  65. return array(
  66. 'create execution content',
  67. 'delete own execution content',
  68. 'delete any execution content',
  69. 'edit own execution content',
  70. 'edit any execution content',
  71. );
  72. }
  73.  
  74.  
  75. /**
  76. * Implementation of hook_form().
  77. *
  78. */
  79. function execution_form(&$node) {
  80. drupal_add_js($data = 'sites/all/modules/dpic/js/datepicker.js', $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE, $preprocess = TRUE);
  81. drupal_add_js($data = 'sites/all/modules/dpic/js/launchdate.js', $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE, $preprocess = TRUE);
  82. drupal_add_css($path = 'sites/all/modules/dpic/css/jquery-ui-themeroller.css', $type = 'module', $media = 'all', $preprocess = TRUE);
  83. // drupal_add_css($path = 'sites/all/modules/dpic/css/dpic.css', $type = 'module', $media = 'all', $preprocess = TRUE);
  84.  
  85. // The site admin can decide if this node type has a title and body, and how
  86. // the fields should be labeled. We need to load these settings so we can
  87. // build the node form correctly.
  88. $type = node_get_types('type', $node);
  89.  
  90. if ($type->has_title) {
  91. $form['title'] = array(
  92. '#type' => 'textfield',
  93. '#title' => check_plain($type->title_label),
  94. '#required' => TRUE,
  95. '#default_value' => $node->title,
  96. '#weight' => -5
  97. );
  98. }
  99.  
  100. if ($type->has_body) {
  101. // In Drupal 6, we can use node_body_field() to get the body and filter
  102. // elements. This replaces the old textarea + filter_form() method of
  103. // setting this up. It will also ensure the teaser splitter gets set up
  104. // properly.
  105. $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
  106. }
  107.  
  108. $form['exec_date'] = array(
  109. '#type' => 'textfield',
  110. '#title' => t('Execution Date'),
  111. '#default_value' => isset($node->exec_date) ? date("m/d/Y",$node->exec_date ) : '',
  112. '#required' => true
  113. );
  114. $form['exec_name'] = array(
  115. '#type' => 'textfield',
  116. '#title' => t('Name'),
  117. '#default_value' => isset($node->exec_name) ? $node->exec_name : '',
  118. '#required' => true
  119. );
  120. $form['age'] = array(
  121. '#type' => 'textfield',
  122. '#title' => t('Age'),
  123. '#default_value' => isset($node->age) ? $node->age : '',
  124. );
  125.  
  126. $form['sex'] = array(
  127. '#type' => 'radios',
  128. '#title' => t('Sex'),
  129. '#default_value' => isset($node->sex) ? $node->sex : '',
  130. '#options' => array('m'=>t('Male'), 'f'=>t('Female')),
  131. '#required' => true
  132. );
  133. $form['federal'] = array(
  134. '#type' => 'select',
  135. '#title' => t('Federal'),
  136. '#default_value' => isset($node->federal) ? $node->federal : '',
  137. '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
  138. );
  139. $form['state'] = array(
  140. '#type' => 'select',
  141. '#title' => t('State'),
  142. '#default_value' => isset($node->state) ? $node->state : '',
  143. '#required' => true,
  144. '#options' => array(
  145. 'AL'=>"Alabama",
  146. 'AK'=>"Alaska",
  147. 'AZ'=>"Arizona",
  148. 'AR'=>"Arkansas",
  149. 'CA'=>"California",
  150. 'CO'=>"Colorado",
  151. 'CT'=>"Connecticut",
  152. 'DE'=>"Delaware",
  153. 'DC'=>"District Of Columbia",
  154. 'FL'=>"Florida",
  155. 'GA'=>"Georgia",
  156. 'HI'=>"Hawaii",
  157. 'ID'=>"Idaho",
  158. 'IL'=>"Illinois",
  159. 'IN'=>"Indiana",
  160. 'IA'=>"Iowa",
  161. 'KS'=>"Kansas",
  162. 'KY'=>"Kentucky",
  163. 'LA'=>"Louisiana",
  164. 'ME'=>"Maine",
  165. 'MD'=>"Maryland",
  166. 'MA'=>"Massachusetts",
  167. 'MI'=>"Michigan",
  168. 'MN'=>"Minnesota",
  169. 'MS'=>"Mississippi",
  170. 'MO'=>"Missouri",
  171. 'MT'=>"Montana",
  172. 'NE'=>"Nebraska",
  173. 'NV'=>"Nevada",
  174. 'NH'=>"New Hampshire",
  175. 'NJ'=>"New Jersey",
  176. 'NM'=>"New Mexico",
  177. 'NY'=>"New York",
  178. 'NC'=>"North Carolina",
  179. 'ND'=>"North Dakota",
  180. 'OH'=>"Ohio",
  181. 'OK'=>"Oklahoma",
  182. 'OR'=>"Oregon",
  183. 'PA'=>"Pennsylvania",
  184. 'RI'=>"Rhode Island",
  185. 'SC'=>"South Carolina",
  186. 'SD'=>"South Dakota",
  187. 'TN'=>"Tennessee",
  188. 'TX'=>"Texas",
  189. 'UT'=>"Utah",
  190. 'VT'=>"Vermont",
  191. 'VA'=>"Virginia",
  192. 'WA'=>"Washington",
  193. 'WV'=>"West Virginia",
  194. 'WI'=>"Wisconsin",
  195. 'WY'=>"Wyoming")
  196. );
  197. $form['race'] = array(
  198. '#type' => 'select',
  199. '#title' => t('Race'),
  200. '#default_value' => isset($node->race) ? $node->race : '',
  201. '#options' => array('White'=>'White','Black'=>'Black','Latino'=>'Latino','Native American'=>'Native American','Asian'=>'Asian','Other'=>'Other')
  202. );
  203.  
  204. $options = array();
  205. $rs = db_query('select n.nid, n.title from {node} n where n.type="execution" and n.status=1 order by n.title');
  206. $options['none'] = '-- No Co-defendant --';
  207. while( $row = db_fetch_object($rs) ){
  208. $options[$row->nid] = $row->title;
  209. }
  210.  
  211. $form['co_defendant'] = array(
  212. '#type' => 'select',
  213. '#title' => t('Co-defendant'),
  214. '#default_value' => isset($node->co_defendant) ? $node->co_defendant : '',
  215. '#options' => $options
  216. );
  217. $form['volunteer'] = array(
  218. '#type' => 'select',
  219. '#title' => t('Volunteer'),
  220. '#default_value' => isset($node->volunteer) ? $node->volunteer : '',
  221. '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
  222. );
  223. $form['juvenile'] = array(
  224. '#type' => 'select',
  225. '#title' => t('Juvenile'),
  226. '#default_value' => isset($node->juvenile) ? $node->juvenile : '',
  227. '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
  228. );
  229. $form['foreigner'] = array(
  230. '#type' => 'select',
  231. '#title' => t('Foreigner'),
  232. '#default_value' => isset($node->foreigner) ? $node->foreigner : '',
  233. '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
  234. );
  235. $form['dual_citizen'] = array(
  236. '#type' => 'select',
  237. '#title' => t('Dual Citizen'),
  238. '#default_value' => isset($node->dual_citizen) ? $node->dual_citizen : '',
  239. '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
  240. );
  241. $form['mentally_retarded'] = array(
  242. '#type' => 'select',
  243. '#title' => t('Mentally Retarded'),
  244. '#default_value' => isset($node->mentally_retarded) ? $node->mentally_retarded : '',
  245. '#options' => array(''=>t(''), 'y'=>t('Yes'), 'n'=>'No'),
  246. );
  247. $form['method'] = array(
  248. '#type' => 'select',
  249. '#title' => t('Method'),
  250. '#default_value' => isset($node->method) ? $node->method : '',
  251. '#options' => array('Electrocution'=>'Electrocution','Firing Squad'=>'Firing Squad','Gas Chamber'=>'Gas Chamber','Hanging'=>'Hanging','Lethal Injection'=>'Lethal Injection'),
  252. '#required' => true
  253. );
  254. $form['region'] = array(
  255. '#type' => 'select',
  256. '#title' => t('Region'),
  257. '#default_value' => isset($node->region) ? $node->region : '',
  258. '#options' => array('M'=>'M','N'=>'N','S'=>'S','W'=>'W'),
  259. '#required' => true
  260. );
  261.  
  262.  
  263. $form['victims'] = array(
  264. '#type' => 'fieldset',
  265. '#title' => t('Victims'),
  266. '#weight' => 16,
  267. '#collapsible' => FALSE,
  268. '#collapsed' => FALSE,
  269. '#tree' => TRUE,
  270. );
  271.  
  272. $i = 1;
  273. //display boxes for all the links we have defaults for
  274. if( is_array($node->victims) && sizeof($node->victims) > 0 ) {
  275. foreach( $node->victims as $victim ){
  276. $form['victims'][$i] = array( '#type' => 'fieldset', '#title' => t('Victim #' . $i ), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, );
  277. $form['victims'][$i]['number'] = array( '#type' => 'textfield', '#title' => t('Number of Victims'), '#required' => FALSE, '#default_value' => '', '#default_value'=> $victim['number'] );
  278. $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') );
  279. $i++;
  280. }
  281. }
  282.  
  283. $end = $i + 2;
  284. //display 5 blank boxes
  285. for( $i; $i <= $end; $i++ ) {
  286. $form['victims'][$i] = array( '#type' => 'fieldset', '#title' => t('Victim #' . $i ), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, );
  287. $form['victims'][$i]['number'] = array( '#type' => 'textfield', '#title' => t('Number of Victims'), '#required' => FALSE, '#default_value' => '', '#default_value'=> '' );
  288. $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') );
  289. }
  290.  
  291.  
  292.  
  293. return $form;
  294. }
  295.  
  296.  
  297. /**
  298. * Implementation of hook_validate().
  299. */
  300. function execution_validate(&$node) {
  301. if ($node->age) {
  302. if (!is_numeric($node->age)) {
  303. form_set_error('age', t('Age must be a number.'));
  304. }
  305. }
  306. }
  307.  
  308. /**
  309. * Implementation of hook_insert().
  310. *
  311. */
  312. function execution_insert($node) {
  313.  
  314. //convert the time to a timestamp
  315. $node->exec_date = strtotime($node->exec_date);
  316.  
  317. //save the campaign
  318. drupal_write_record('execution', $node );
  319.  
  320. //insert the links
  321. foreach( $node->victims as $victim ) {
  322. //save the links
  323. if( !empty($victim['number']) && !empty($victim['race']) ){
  324. //link the link to the campaign
  325. $victim['vid'] = $node->vid;
  326. drupal_write_record('victim', $victim );
  327. }
  328. }
  329.  
  330. }
  331.  
  332. /**
  333. * Implementation of hook_update().
  334. *
  335. */
  336. function execution_update($node) {
  337. // if this is a new node or we're adding a new revision,
  338. if ($node->revision) {
  339. execution_insert($node);
  340. }
  341. else {
  342. //convert the time to a timestamp
  343. $node->exec_date = strtotime($node->exec_date);
  344.  
  345. //save the campaign
  346. drupal_write_record('execution', $node, 'vid' );
  347.  
  348. //delete all the links associated with the campaign
  349. $rs = db_query('delete from {victim} where vid=%d',$node->vid );
  350.  
  351. //insert the links
  352. foreach( $node->victims as $victim ) {
  353. //save the links
  354. if( !empty($victim['number']) && !empty($victim['race']) ){
  355. //link the link to the campaign
  356. $victim['vid'] = $node->vid;
  357. drupal_write_record('victim', $victim );
  358. }
  359. }
  360. }
  361. }
  362.  
  363.  
  364. /**
  365. * Implementation of hook view
  366. */
  367. function execution_load($node) {
  368. $additions = db_fetch_object(db_query('SELECT * FROM {execution} e WHERE vid = %d', $node->vid));
  369.  
  370. $sql = "select * from {victim} v where vid=%d order by race";
  371. $rs= db_query($sql, $node->vid);
  372.  
  373. $additions->victims = array();
  374. while( $victim = db_fetch_array($rs) ) {
  375. $additions->victims[] = array(
  376. 'race' => $victim['race'],
  377. 'number' => $victim['number'],
  378. );
  379. }
  380. return $additions;
  381. }
  382.  
  383. /**
  384. * Implementation of hook_nodeapi().
  385. *
  386. */
  387. function execution_nodeapi(&$node, $op, $teaser, $page) {
  388. switch ($op) {
  389. case 'delete revision':
  390. // Notice that we're matching a single revision based on the node's vid.
  391. db_query('DELETE FROM {execution} WHERE vid = %d', $node->vid);
  392. break;
  393. }
  394. }
  395.  
  396. /**
  397. * Implementation of hook_delete().
  398. *
  399. */
  400. function execution_delete($node) {
  401. // Notice that we're matching all revision, by using the node's nid.
  402. db_query('DELETE FROM {execution} WHERE nid = %d', $node->nid);
  403. }
  404.  
  405. /**
  406. * Implementation of hook_view().
  407. *
  408. */
  409. function execution_view($node, $teaser = FALSE, $page = FALSE) {
  410. $node = node_prepare($node, $teaser);
  411. $node->content['execution_info'] = array(
  412. '#value' => theme('execution_info', $node),
  413. '#weight' => 1,
  414. );
  415.  
  416. return $node;
  417. }
  418.  
  419. /**
  420. * Implementation of hook_theme().
  421. *
  422. */
  423. function execution_theme() {
  424. return array(
  425. 'execution_info' => array(
  426. 'arguments' => array('node'),
  427. ),
  428. );
  429. }
  430.  
  431. /**
  432. * A custom theme function.
  433. *
  434. */
  435. function theme_execution_info($node) {
  436. $items = array();
  437. $items[] = '<strong>Name:</strong> ' . check_plain($node->exec_name);
  438. $items[] = '<strong>Date of Execution:</strong> ' . check_plain(date("m/d/Y",$node->exec_date ));
  439. $items[] = '<strong>Age:</strong> ' . check_plain($node->age);
  440. $items[] = '<strong>Race:</strong> ' . check_plain($node->race);
  441. $items[] = '<strong>State:</strong> ' . check_plain($node->state);
  442. $items[] = '<strong>Region:</strong> ' . check_plain($node->region);
  443. $items[] = '<strong>Method:</strong> ' . check_plain($node->method);
  444. $items[] = '<strong>Sex:</strong> ' . check_plain($node->sex);
  445. $items[] = '<strong>DPIC ID:</strong> ' . check_plain($node->exec_id);
  446.  
  447. if( is_array($node->victims) && count($node->victims) > 0 ){
  448. $victims = '';
  449. foreach( $node->victims as $v ){
  450. $victims .= $v['number'] . ' ' . $v['race'] . ', ';
  451. }
  452. $items[] = '<strong>Victims:</strong> ' . $victims ;
  453. }
  454.  
  455. $output = '<div id="exec-results">';
  456. $output .= theme('item_list', $items);
  457. $output .= '</div>';
  458. return $output;
  459. }
  460.  
  461.  
  462. /**
  463. * Search the execution database
  464. */
  465. function execution_database_search() {
  466. $output .= drupal_get_form('execution_search_form');
  467.  
  468. return $output;
  469. }
  470.  
  471. function execution_search_form($form_state) {
  472.  
  473. $form['byname'] = array(
  474. '#type' => 'fieldset',
  475. '#title'=> 'Search by Name',
  476. '#collapsible' => TRUE,
  477. '#collapsed' => ($form_state['clicked_button']['#value'] == 'Search by Details') ? TRUE : FALSE,
  478. );
  479. $form['byname']['name'] = array(
  480. '#type' => 'textfield',
  481. '#default_value'=> ($form_state['values']['name']) ? $form_state['values']['name'] : ''
  482. );
  483. $form['byname']['submit_name'] = array('#type' => 'submit', '#value' => t('Search by Name'));
  484.  
  485. $form['bydetails'] = array(
  486. '#type' => 'fieldset',
  487. '#title'=> 'Search by Details',
  488. '#collapsible' => TRUE,
  489. '#collapsed' => ($form_state['clicked_button']['#value'] == 'Search by Name') ? TRUE : FALSE
  490. );
  491.  
  492. $years = array('all'=>'Search all Years');
  493. $sql = 'select distinct(from_unixtime(exec_date,"%Y")) as year from execution order by from_unixtime(exec_date,"%Y")';
  494. $rs = db_query($sql);
  495. while( $row = db_fetch_object($rs) )
  496. $years[$row->year] = $row->year;
  497. $form['bydetails']['year'] = array(
  498. '#type' => 'select',
  499. '#multiple' => true,
  500. '#size'=>5,
  501. '#title'=> 'Year',
  502. '#default_value' => ( $form_state['values']['year'] ) ? $form_state['values']['year']: array('all'),
  503. '#options' => $years
  504. );
  505.  
  506. $ages = array('all'=>'Search all Ages');
  507. $sql = "select distinct(age) from execution order by age";
  508. $rs = db_query($sql);
  509. while( $row = db_fetch_object($rs) )
  510. $ages[$row->age] = $row->age;
  511. $form['bydetails']['age'] = array(
  512. '#type' => 'select',
  513. '#title'=> 'Age at Execution',
  514. '#multiple' => true,
  515. '#size'=>5,
  516. '#default_value' => ($form_state['values']['age']) ? $form_state['values']['age'] : array('all'),
  517. '#options' => $ages
  518. );
  519.  
  520. $races = array('all'=>'Search all Races');
  521. $sql = "select distinct(race) from execution order by race";
  522. $rs = db_query($sql);
  523. while( $row = db_fetch_object($rs) )
  524. $races[$row->race] = $row->race;
  525. $form['bydetails']['race'] = array(
  526. '#type' => 'select',
  527. '#title'=> 'Race of Person Executed',
  528. '#default_value' => $form_state['values']['race'],
  529. '#options' => $races
  530. );
  531.  
  532. $sexes = array('all'=>'Search all Genders');
  533. $sql = "select distinct(sex) from execution";
  534. $rs = db_query($sql);
  535. while( $row = db_fetch_object($rs) )
  536. $sexes[$row->sex] = $row->sex;
  537. $form['bydetails']['sex'] = array(
  538. '#type' => 'select',
  539. '#title'=> 'Gender of Person Executed',
  540. '#default_value' => $form_state['values']['sex'],
  541. '#options' => $sexes
  542. );
  543.  
  544.  
  545. $states = array('all'=>'Search all States');
  546. $sql = "select distinct(state) from execution order by state";
  547. $rs = db_query($sql);
  548. while( $row = db_fetch_object($rs) )
  549. $states[$row->state] = $row->state;
  550. $form['bydetails']['state'] = array(
  551. '#type' => 'select',
  552. '#title'=> 'State',
  553. '#default_value' => ($form_state['values']['state']) ? $form_state['values']['state']: array('all'),
  554. '#multiple' => true,
  555. '#size'=>5,
  556. '#options' => $states
  557. );
  558.  
  559. $regions = array('all'=>'Search all Regions');
  560. $sql = "select distinct(region) from execution";
  561. $rs = db_query($sql);
  562. while( $row = db_fetch_object($rs) )
  563. $regions[$row->region] = $row->region;
  564. $form['bydetails']['region'] = array(
  565. '#type' => 'select',
  566. '#title'=> 'Region',
  567. '#default_value' => $form_state['values']['region'],
  568. '#options' => $regions
  569. );
  570.  
  571. $victim_race = array('all'=>'Search all Victims');
  572. $sql = "select distinct(race) from victim order by race";
  573. $rs = db_query($sql);
  574. while( $row = db_fetch_object($rs) )
  575. $victim_race[$row->race] = $row->race;
  576. $form['bydetails']['victim_race'] = array(
  577. '#type' => 'select',
  578. '#title'=> 'Race of Victim',
  579. '#default_value' => ($form_state['values']['victim_race']) ? $form_state['values']['victim_race']: array('all'),
  580. '#multiple' => true,
  581. '#size'=>5,
  582. '#options' => $victim_race
  583. );
  584.  
  585.  
  586. $methods = array('all'=>'Search all Methods');
  587. $sql = "select distinct(method) from execution order by method";
  588. $rs = db_query($sql);
  589. while( $row = db_fetch_object($rs) )
  590. $methods[$row->method] = $row->method;
  591. $form['bydetails']['method'] = array(
  592. '#type' => 'select',
  593. '#title'=> 'Methods',
  594. '#default_value' => $form_state['values']['method'],
  595. '#options' => $methods
  596. );
  597.  
  598. $form['bydetails']['factors'] = array(
  599. '#type' => 'select',
  600. '#title'=> 'Other Factors',
  601. '#multiple' => true,
  602. '#size'=>5,
  603. '#default_value' => ($form_state['values']['factors']) ? $form_state['values']['factors'] : array('all'),
  604. '#options' => array(
  605. 'all' => 'All Factors',
  606. 'juvenile' => 'Juvenile at the time of Crime',
  607. 'federal' => 'Federal',
  608. 'volunteer' => 'Volunteer',
  609. 'foreigner' => 'Foreign National',
  610. 'dual_citizen' => 'Dual Citizen',
  611. 'mentally_retarded' => 'Evidence of Mental Retardation',
  612. )
  613. );
  614.  
  615. $form['bydetails']['submit_detail'] = array('#type' => 'submit', '#value' => t('Search by Details'), '#submit' => array('execution_search_by_detail'),);
  616.  
  617.  
  618. if( is_array($form_state['results']) && count($form_state['results']) > 0 ){
  619. drupal_set_message(t('<h2>Your Search Returned %d Results (see below)</h2>', array('%d'=>count($form_state['results']))));
  620. $output = t('<h2>Your Search Returned %d Results</h2>', array('%d'=>count($form_state['results'])));
  621.  
  622. $rows = array();
  623. foreach( $form_state['results'] as $e ) {
  624.  
  625. //get victims info
  626. if( is_array($e->victims) && count($e->victims) > 0 ){
  627. $victims = '';
  628. foreach( $e->victims as $v ){
  629. $victims .= $v['number'] . ' ' . $v['race'] . '<br /> ';
  630. }
  631. }
  632.  
  633. //get other info
  634. $other_info = '';
  635. if( $e->juvenile =='y' )
  636. $other_info .= 'Juvenile at the time of Crime<br /> ';
  637. if( $e->federal =='y' )
  638. $other_info .= 'Federal<br /> ';
  639. if( $e->volunteer =='y' )
  640. $other_info .= 'Volunteer<br /> ';
  641. if( $e->foreigner =='y' )
  642. $other_info .= 'Foreign National<br /> ';
  643. if( $e->dual_citizen =='y' )
  644. $other_info .= 'Dual Citizen<br /> ';
  645. if( $e->mentally_retarded =='y' )
  646. $other_info .= 'Evidence of Mental Retardation<br /> ';
  647.  
  648. $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 );
  649. if( user_access('edit any execution content') ){
  650. $row[] = l('Edit','node/' . $e->nid . '/edit');
  651. }
  652. $rows[] = $row;
  653. }
  654. $header = array('Date','Name','Age','Sex','Race','Number and Race of Victims','State','Region','Method','Other');
  655.  
  656. if( user_access('edit any execution content') ){
  657. $header[] = 'Edit';
  658. }
  659. $output = '<div id="execution_info">';
  660. $output .= theme('table', $header, $rows );
  661. $output .= '</div>';
  662.  
  663. $form['results'] = array(
  664. '#type' => 'markup',
  665. '#value'=> $output
  666. );
  667. }
  668.  
  669. return $form;
  670. }
  671.  
  672. /**
  673. * Search by name
  674. * @return
  675. * @param $form Object
  676. * @param $form_state Object
  677. */
  678. function execution_search_form_submit($form, &$form_state) {
  679.  
  680. $sql = 'select nid from execution where exec_name like "%%%s%%"';
  681. $rs = db_query( $sql, $form_state['values']['name'] );
  682. $form_state['results'] = array();
  683. while( $row = db_fetch_object($rs) ) {
  684. $form_state['results'][] = node_load($row->nid);
  685. }
  686.  
  687. $form_state['rebuild'] = true;
  688. }
  689.  
  690. function execution_search_by_detail( $form, &$form_state ) {
  691.  
  692. $sql = 'select nid from execution where 1=1';
  693.  
  694. //year of execution
  695. if( is_array($form_state['values']['year']) && count($form_state['values']['year']) > 0 && !array_key_exists('all',$form_state['values']['year']) ) {
  696. $years = $form_state['values']['year'];
  697. $sql .= ' and from_unixtime(exec_date,"%Y") in (' . implode(',',$years) . ')';
  698. }
  699.  
  700. //age
  701. if( is_array($form_state['values']['age']) && count($form_state['values']['age']) > 0 && !array_key_exists('all',$form_state['values']['age']) ) {
  702. $ages = $form_state['values']['age'];
  703. $sql .= ' and age in (' . implode(',',$ages) . ')';
  704. }
  705.  
  706. //race
  707. if( isset($form_state['values']['race']) && $form_state['values']['race'] != 'all' ) {
  708. $sql .= ' and race="' . $form_state['values']['race'] . '"';
  709. }
  710.  
  711. //gender
  712. if( isset($form_state['values']['sex']) && $form_state['values']['sex'] != 'all' ) {
  713. $sql .= ' and sex="' . $form_state['values']['sex'] . '"';
  714. }
  715.  
  716. //state
  717. if( is_array($form_state['values']['state']) && count($form_state['values']['state']) > 0 && !array_key_exists('all',$form_state['values']['state']) ) {
  718. $states = $form_state['values']['state'];
  719. foreach( $states as $key=>$value ){
  720. $states[$key] = '"' . $value . '"';
  721. }
  722. $sql .= ' and state in (' . implode(',',$states) . ')';
  723. }
  724.  
  725. //region
  726. if( isset($form_state['values']['region']) && $form_state['values']['region'] != 'all' ) {
  727. $sql .= ' and region="' . $form_state['values']['region'] . '"';
  728. }
  729.  
  730.  
  731. //method
  732. if( isset($form_state['values']['method']) && $form_state['values']['method'] != 'all' ) {
  733. $sql .= ' and method="' . $form_state['values']['method'] . '"';
  734. }
  735.  
  736. //other factors
  737. if( !array_key_exists( 'all', $form_state['values']['factors'] ) ) {
  738. $pieces = array();
  739. $factors_sql = '';
  740. if( array_key_exists( 'juvenile', $form_state['values']['factors'] ) )
  741. $pieces[] = 'juvenile="y"';
  742. if( array_key_exists( 'federal', $form_state['values']['factors'] ) )
  743. $pieces[] = 'federal="y"';
  744. if( array_key_exists( 'volunteer', $form_state['values']['factors'] ) )
  745. $pieces[] = 'volunteer="y"';
  746. if( array_key_exists( 'foreigner', $form_state['values']['factors'] ) )
  747. $pieces[] = 'foreigner="y"';
  748. if( array_key_exists( 'dual_citizen', $form_state['values']['factors'] ) )
  749. $pieces[] = 'dual_citizen="y"';
  750. if( array_key_exists( 'mentally_retarded', $form_state['values']['factors'] ) )
  751. $pieces[] = 'mentally_retarded="y"';
  752. if( count($pieces) > 0 )
  753. $factors_sql = implode( ' or ' , $pieces );
  754. }
  755. if( $factors_sql )
  756. $sql .= ' and (' . $factors_sql . ')';
  757.  
  758. $sql .= ' order by exec_date';
  759.  
  760.  
  761. $rs = db_query( $sql, $form_state['values']['name'] );
  762. $form_state['results'] = array();
  763. while( $row = db_fetch_object($rs) ) {
  764. //we need to check the race of the victim sometimes
  765. if( array_key_exists( 'all', $form_state['values']['victim_race'] ) ) {
  766. $form_state['results'][] = node_load($row->nid);
  767. }else {
  768. $e = node_load($row->nid);
  769. if( is_array($e->victims) && count($e->victims) > 0 ){
  770. foreach( $e->victims as $v ){
  771. if( array_key_exists( $v['race'], $form_state['values']['victim_race'] ) )
  772. $form_state['results'][] = node_load($row->nid);
  773. }
  774. }
  775. }
  776. }
  777.  
  778. $form_state['rebuild'] = true;
  779.  
  780. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement