PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/contacts/pages/popup_accts/pre_process.php

http://phreedom.googlecode.com/
PHP | 107 lines | 73 code | 5 blank | 29 comment | 13 complexity | 43f8e0de2c6856def7e4720add194a33 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. <?php
  2. // +-----------------------------------------------------------------+
  3. // | PhreeBooks Open Source ERP |
  4. // +-----------------------------------------------------------------+
  5. // | Copyright (c) 2008, 2009, 2010, 2011, 2012 PhreeSoft, LLC |
  6. // | http://www.PhreeSoft.com |
  7. // +-----------------------------------------------------------------+
  8. // | This program is free software: you can redistribute it and/or |
  9. // | modify it under the terms of the GNU General Public License as |
  10. // | published by the Free Software Foundation, either version 3 of |
  11. // | the License, or any later version. |
  12. // | |
  13. // | This program is distributed in the hope that it will be useful, |
  14. // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  15. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  16. // | GNU General Public License for more details. |
  17. // +-----------------------------------------------------------------+
  18. // Path: /modules/contacts/pages/popup_accts/pre_process.php
  19. //
  20. $security_level = validate_user(0, true);
  21. /************** include page specific files *********************/
  22. require(DIR_FS_WORKING . 'functions/contacts.php');
  23. require(DIR_FS_WORKING . 'classes/contacts.php');
  24. /************** page specific initialization *************************/
  25. define('JOURNAL_ID',(int)$_GET['jID']);
  26. $account_type = (isset($_GET['type']) ? $_GET['type'] : 'c'); // current types are c (customer) and v (vendor)
  27. switch ($account_type) {
  28. default:
  29. case 'c': $terms_type = 'AR'; break;
  30. case 'v': $terms_type = 'AP'; break;
  31. }
  32. $fill = isset($_GET['fill']) ? $_GET['fill'] : 'bill';
  33. $search_text = ($_POST['search_text']) ? db_input($_POST['search_text']) : db_input($_GET['search_text']);
  34. if ($search_text == TEXT_SEARCH) $search_text = '';
  35. $action = isset($_GET['action']) ? $_GET['action'] : $_POST['todo'];
  36. if (!$action && $search_text <> '') $action = 'search'; // if enter key pressed and search not blank
  37. $cInfo = new contacts();
  38. // load the sort fields
  39. $_GET['sf'] = $_POST['sort_field'] ? $_POST['sort_field'] : $_GET['sf'];
  40. $_GET['so'] = $_POST['sort_order'] ? $_POST['sort_order'] : $_GET['so'];
  41. /*************** hook for custom actions ***************************/
  42. $custom_path = DIR_FS_WORKING . 'custom/pages/popup_accts/extra_actions.php';
  43. if (file_exists($custom_path)) { include($custom_path); }
  44. /*************** Act on the action request *************************/
  45. switch ($action) {
  46. case 'go_first': $_GET['list'] = 1; break;
  47. case 'go_previous': $_GET['list']--; break;
  48. case 'go_next': $_GET['list']++; break;
  49. case 'go_last': $_GET['list'] = 99999; break;
  50. case 'search':
  51. case 'search_reset':
  52. case 'go_page':
  53. default:
  54. }
  55. /***************** prepare to display templates *************************/
  56. // generate address arrays for javascript
  57. $js_arrays = gen_build_company_arrays();
  58. // build the list header
  59. $heading_array = array(
  60. 'primary_name' => GEN_PRIMARY_NAME,
  61. 'address1' => GEN_ADDRESS1,
  62. 'city_town,state_province' => GEN_CITY_TOWN,
  63. 'state_province,city_town' => GEN_STATE_PROVINCE,
  64. 'postal_code' => GEN_POSTAL_CODE,
  65. 'telephone1' => GEN_TELEPHONE1,
  66. );
  67. switch (JOURNAL_ID) {
  68. case 6:
  69. case 12: $extra_headings = array(ACT_LIST_OPEN_ORDERS); break;
  70. case 7:
  71. case 13: $extra_headings = array(ACT_LIST_OPEN_INVOICES); break;
  72. default: $extra_headings = array('&nbsp;'); break;
  73. }
  74. $result = html_heading_bar($heading_array, $_GET['sf'], $_GET['so'], $extra_headings);
  75. $list_header = $result['html_code'];
  76. $disp_order = $result['disp_order'];
  77. // build the list for the page selected
  78. if (isset($search_text) && $search_text <> '') {
  79. $search_fields = array('c.short_name', 'a.primary_name', 'a.contact', 'a.telephone1', 'a.telephone2',
  80. 'a.address1', 'a.address2', 'a.city_town', 'a.postal_code', 'c.account_number');
  81. // hook for inserting new search fields to the query criteria.
  82. if (is_array($extra_search_fields)) $search_fields = array_merge($search_fields, $extra_search_fields);
  83. $search = ' and (' . implode(' like \'%' . $search_text . '%\' or ', $search_fields) . ' like \'%' . $search_text . '%\')';
  84. } else {
  85. $search = '';
  86. }
  87. $field_list = array('a.address_id', 'c.id', 'a.ref_id', 'a.type', 'a.primary_name', 'a.contact', 'a.address1',
  88. 'a.address2', 'a.city_town', 'a.state_province', 'a.postal_code', 'a.country_code', 'c.short_name',
  89. 'a.telephone1', 'a.email', 'c.first_date', 'c.last_update', 'c.gl_type_account', 'c.special_terms',
  90. 'c.last_date_1', 'c.last_date_2', 'c.inactive');
  91. // hook to add new fields to the query return results
  92. if (is_array($extra_query_list_fields) > 0) $field_list = array_merge($field_list, $extra_query_list_fields);
  93. $query_raw = "select " . implode(', ', $field_list) . "
  94. from " . TABLE_CONTACTS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.id = a.ref_id
  95. where a.type = '" . $account_type . "m'" . $search . " order by $disp_order";
  96. $query_split = new splitPageResults($_GET['list'], MAX_DISPLAY_SEARCH_RESULTS, $query_raw, $query_numrows);
  97. $query_result = $db->Execute($query_raw);
  98. $include_header = false;
  99. $include_footer = true;
  100. $include_template = 'template_main.php';
  101. define('PAGE_TITLE', ACT_POPUP_WINDOW_TITLE);
  102. ?>