Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php ini_set("include_path", ".:../include:/usr/lib/php"); ?>
- <?php
- require_once '../include/constants.php';
- require_once '../include/enc.php';
- $connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
- mysql_select_db(DB_NAME, $connection) or die(mysql_error());
- function escapeCommas($val) {
- return '"' . $val . '"';
- }
- function cleanData($val) {
- $returnVal = $val;
- if($val == "\n" || $val == "\r" || $val == "\r\n") {
- //echo "found newline or cariage return character";
- $returnVal = str_replace("\n", "", $returnVal);
- $returnVal = str_replace("\r", " ", $returnVal);
- $returnVal = str_replace("\r\n", " ", $returnVal);
- }
- $returnVal = escapeCommas($val);
- return $returnVal;
- }
- $sb = "Account Number, ID\n";
- $tenantIds = array();
- $q = 'select id from tenants';
- $result= mysql_query($q, $connection);
- if ($result && (mysql_numrows($result) > 0)){
- while ($tenantIdRow = mysql_fetch_assoc($result)) {
- array_push($tenantIds, $tenantIdRow['id']);
- }
- mysql_free_result($result);
- foreach ($tenantIds as $tenantId) {
- $q = 'select account_number, id from tenant_basic_info where tenant_id = ' . $tenantId;
- $result = mysql_query($q, $connection);
- if ($result && (mysql_numrows($result) > 0)) {
- $tenantBasicInfo = mysql_fetch_array($result, MYSQL_NUM);
- // Justin: id must be decrypted before output
- //include '../include/enc.inc';
- $key = "jobjob";
- $tenantBasicInfo[4] = jobdecrypt($tenantBasicInfo[4], $key);
- // End Justin changes
- foreach ($tenantBasicInfo as $tenantBasicInfoValue) {
- $sb .= cleanData(mysql_real_escape_string($tenantBasicInfoValue)) . ',';
- }
- } else {
- $numMissingFields = 23;
- for ($i = 0; $i < $numMissingFields; $i++) {
- $sb .= ',';
- }
- }
- /*
- mysql_free_result($result);
- $q = 'select line1, line2, line3, city, state, zip, moved_in, moved_out, rent_amount, reason_left, agent_name, agent_phone from tenant_address where tenant_id = '.$tenantId;
- $result = mysql_query($q, $connection);
- if ($result && (mysql_numrows($result) > 0)) {
- while ($tenantAddress = mysql_fetch_array($result, MYSQL_NUM)) {
- foreach ($tenantAddress as $tenantAddressValue) {
- $sb .= cleanData(mysql_real_escape_string($tenantAddressValue)) . ',';
- }
- }
- $numMissingRows = 3 - mysql_numrows($result);
- } else {
- $numMissingRows = 3;
- }
- */
- mysql_free_result($result);
- $numMissingFields = $numMissingRows * 12;
- for ($i = 0; $i < $numMissingFields; $i++) {
- $sb .= ',';
- }
- $q = 'select tna.tenant_id, b.complex_id, tna.building_id, tna.landlord_id, tna.ll_internal_tenant_id, tna.ll_internal_complex_id, tna.ll_internal_building_id, tna.ll_internal_unit_id, tna.line_1, tna.line_2, tna.line_3, tna.unit_num, tna.city, tna.state, tna.zip, tna.sec_deposit, tna.rent, tna.lease_date, tna.first_payment_due, tna.lease_signed, tna.lease_length, tna.agreement_signed, tna.direct_deposit_form, b.percent_fee from tenant_new_address tna, buildings b where b.id = tna.building_id and tna.tenant_id = ' . $tenantId;
- $result = mysql_query($q, $connection);
- if ($result && (mysql_numrows($result) > 0)) {
- $tenantNewAddress = mysql_fetch_array($result, MYSQL_NUM);
- foreach ($tenantNewAddress as $tenantNewAddressValue) {
- $sb .= cleanData(mysql_real_escape_string($tenantNewAddressValue)) . ',';
- }
- } else {
- $numMissingFields = 23;
- for ($i = 0; $i < $numMissingFields; $i++) {
- $sb .= ',';
- }
- }
- mysql_free_result($result);
- $q = 'select admin_fee from job_settings';
- $result = mysql_query($q, $connection);
- if ($result && (mysql_numrows($result) > 0)) {
- $jobFee = mysql_fetch_array($result, MYSQL_NUM);
- foreach ($jobFee as $jobFeeValue) {
- $sb .= cleanData(mysql_real_escape_string($jobFeeValue)) . ',';
- }
- } else {
- $numMissingFields = 1;
- for ($i = 0; $i < $numMissingFields; $i++) {
- $sb .= ',';
- }
- }
- mysql_free_result($result);
- $q = 'select job_fee, total_deduct_amount, direct_deposit_amount, direct_deposit_rent, direct_deposit_fee, received, amount_received, date_received from tenant_fees where tenant_id = ' . $tenantId;
- $result = mysql_query($q, $connection);
- if ($result && (mysql_numrows($result) > 0)) {
- $tenantNewAddress = mysql_fetch_array($result, MYSQL_NUM);
- foreach ($tenantNewAddress as $tenantNewAddressValue) {
- $sb .= cleanData(mysql_real_escape_string($tenantNewAddressValue)) . ',';
- }
- } else {
- $numMissingFields = 8;
- for ($i = 0; $i < $numMissingFields; $i++) {
- $sb .= ',';
- }
- }
- mysql_free_result($result);
- $q = 'select employer_name, job_title, employee_id, employer_phone, employee_phone, salary, pay_period, day_paid, start_date, end_date, supervisor_first_name, supervisor_last_name, prev_employer_name, prev_employer_phone, other_income_amount, other_income_source, bank_name, account_type from tenant_employment where tenant_id = ' . $tenantId;
- $result = mysql_query($q, $connection);
- if ($result && (mysql_numrows($result) > 0)) {
- $tenantEmployment = mysql_fetch_array($result, MYSQL_NUM);
- foreach ($tenantEmployment as $tenantEmploymentValue) {
- $sb .= cleanData(mysql_real_escape_string($tenantEmploymentValue)) . ',';
- }
- } else {
- $numMissingFields = 18;
- for ($i = 0; $i < $numMissingFields; $i++) {
- $sb .= ',';
- }
- }
- mysql_free_result($result);
- $q = 'select name, dob, id, dependents_names, dependents_dob from tenant_coapplicant where tenant_id = ' . $tenantId;
- $result = mysql_query($q, $connection);
- if ($result && (mysql_numrows($result) > 0)) {
- $tenantCoapp = mysql_fetch_array($result, MYSQL_NUM);
- foreach ($tenantCoapp as $tenantCoappValue) {
- $sb .= cleanData(mysql_real_escape_string($tenantCoappValue)) . ',';
- }
- } else {
- $numMissingFields = 5;
- for ($i = 0; $i < $numMissingFields; $i++) {
- $sb .= ',';
- }
- }
- mysql_free_result($result);
- $q = 'select contact_name, contact_address, contact_phone, contact_relation from tenant_emerg_contacts where tenant_id = ' . $tenantId;
- $result = mysql_query($q, $connection);
- if ($result && (mysql_numrows($result) > 0)) {
- $tenantCoapp = mysql_fetch_array($result, MYSQL_NUM);
- foreach ($tenantCoapp as $tenantCoappValue) {
- $sb .= cleanData(mysql_real_escape_string($tenantCoappValue)) . ',';
- }
- } else {
- $numMissingFields = 4;
- for ($i = 0; $i < $numMissingFields; $i++) {
- $sb .= ',';
- }
- }
- mysql_free_result($result);
- $q = 'select ref_name, ref_address, ref_phone, ref_relation from tenant_references where tenant_id = ' . $tenantId;
- $result = mysql_query($q, $connection);
- if ($result && (mysql_numrows($result) > 0)) {
- while ($tenantRef = mysql_fetch_array($result, MYSQL_NUM)) {
- foreach ($tenantRef as $tenantRefValue) {
- $sb .= cleanData(mysql_real_escape_string($tenantRefValue)) . ',';
- }
- }
- $numMissingRows = 2 - mysql_numrows($result);
- mysql_free_result($result);
- } else {
- $numMissingRows = 2;
- }
- $numMissingFields = $numMissingRows * 4;
- for ($i = 0; $i < $numMissingFields; $i++) {
- $sb .= ',';
- }
- $q = 'select license_num, license_state, make, model, year, plate_num, plate_state from tenant_automobile where tenant_id = ' . $tenantId;
- $result = mysql_query($q, $connection);
- if ($result && (mysql_numrows($result) > 0)) {
- $tenantCoapp = mysql_fetch_array($result, MYSQL_NUM);
- foreach ($tenantCoapp as $tenantCoappValue) {
- $sb .= cleanData(mysql_real_escape_string($tenantCoappValue)) . ',';
- }
- } else {
- $numMissingFields = 7;
- for ($i = 0; $i < $numMissingFields; $i++) {
- $sb .= ',';
- }
- }
- $q = 'select tna.landlord_id from tenant_new_address tna where tna.tenant_id = ' . $tenantId;
- $landlord_id_for_this_tenant = mysql_query($q, $connection);
- $q = 'select property_company_id from landlords where user_id = ' . $landlord_id_for_this_tenant;
- $property_company_id_for_this_tenant = mysql_query($q, $connection);
- $q = 'select name from property_company where id = ' . $property_company_id_for_this_tenant;
- $property_company_name_for_this_tenant = mysql_query($q, $connection);
- $sb .= cleanData(mysql_real_escape_string($property_company_name_for_this_tenant));
- mysql_free_result($result);
- $sb .= "\n";
- }
- }
- $timestamp = time();
- //create vars to hold paths and filenames
- $plainTxt = $timestamp . "-export.csv";
- if (isset($_REQUEST['download']) && $_REQUEST['download']) {
- header('Content-type: application/csv');
- header('Content-disposition: attachment; filename="'. $plainTxt. '"');
- header('Pragma: no-cache');
- header('Expires: 0');
- echo $sb;
- } else {
- //open file and dump in plaintext contents
- $fp = fopen($plainTxt, "w+");
- fputs($fp, $sb);
- fclose($fp);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement