-
Notifications
You must be signed in to change notification settings - Fork 0
/
txtdirectory.php
executable file
·136 lines (118 loc) · 5.46 KB
/
txtdirectory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?
/*********************************************************************/
/*
Writen By: Marti Settle
Last Modified: July 20, 2002
Called By: processmailing.php
Calls:
Description: This script prepares a simple text listing of all ads in the system
Modification History:
July 20, 2002 - file created
*/
/*********************************************************************/
/* The usual includes */
include "configuration.php";
include "connectdb.php";
error_reporting(255);
/* to create an index, we need to look up all the categories that are in use, and build an array
out of them */
$categorieslookup = mysql_query("SELECT DISTINCT adcategories.CategoryID, HeadingName, CategoryName
FROM adheadings, adcategories, advertisements, account
WHERE adheadings.HeadingID = adcategories.HeadingID
AND (adcategories.CategoryID = advertisements.CategoryID
OR adcategories.CategoryID = advertisements.CategoryID2
OR adcategories.CategoryID = advertisements.CategoryID3)
AND account.AccountID = advertisements.AccountID
AND advertisements.AdBeginDate <= CURDATE()
AND advertisements.AdExpiryDate >= CURDATE()
AND account.AccountRenewalDate >= CURDATE()
AND AccountStatus = 'OK'
ORDER BY HeadingName, CategoryName");
$row = 0;
while($categories = mysql_fetch_array($categorieslookup))
{
$CategoryID[$row] = $categories["CategoryID"];
$Heading[$row] = $categories["HeadingName"];
$CategoryName[$row] = $categories["CategoryName"];
$CatListing[$categories["CategoryID"]] = "$categories[HeadingName]: $categories[CategoryName]";
$row++;
}
/* now we look up the ads, and create a variable holding a list indexed by reference numbers.
These reference numbers are then added to the list of ads referenced by the category variable */
$adlookup = mysql_query("SELECT advertisements.*, AccountName, HomeNumber, EmailAddress
FROM advertisements,account,membertoaccountlink,member
WHERE advertisements.AccountID = account.AccountID
AND account.AccountID = membertoaccountlink.AccountID
AND membertoaccountlink.MemberID = member.MemberID
AND PrimaryContact = 1
AND AdBeginDate <= CURDATE()
AND AdExpiryDate >= CURDATE()
AND AccountRenewalDate >= CURDATE()
AND AccountStatus = 'OK'
ORDER BY AdExpiryDate, AdName");
$ref = 1;
$textads = '';
while($ad = mysql_fetch_array($adlookup))
{
$textads .= "$ref. " . strtoupper($ad["AdName"]);
if($ad["TradeType"] == 'O')
{
$textads .= " (Offered)\n";
}
else
{
$textads .= " (Requested)\n";
}
$textads .= " Account: $ad[AccountName]\tPhone: $ad[HomeNumber]\n";
$textads .= " Categories: " . $CatListing["$ad[CategoryID]"] . "\n";
if(!empty($ad["CategoryID2"]))
{
$textads .= " " . $CatListing["$ad[CategoryID2]"] . "\n";
}
if(!empty($ad["CategoryID3"]))
{
$textads .= " " . $CatListing["$ad[CategoryID3]"] . "\n";
}
$textads .= " Expires: $ad[AdExpiryDate]\n";
$textads .= strip_tags($ad["AdDescription"]) . "\n\n\n";
// This next section creates the arrays used to assemble the categorized index
$AdList[$ad["CategoryID"]][] = $ref;
if(!empty($ad["CategoryID2"]))
{
$AdList[$ad["CategoryID2"]][] = $ref;
}
if(!empty($ad["CategoryID3"]))
{
$AdList[$ad["CategoryID3"]][] = $ref;
}
// This is where the HTML version would be assembled
$ref++;
}
// Build the categorized index
$CurrentHeading = '';
$textindex = '';
while(list($row, $ID) = each($CategoryID))
{
if($Heading["$row"] != $CurrentHeading)
{
$textindex .= "\n" . strtoupper($Heading["$row"]) . "\n";
$CurrentHeading = $Heading["$row"];
}
$textindex .= " $CategoryName[$row]";
$textindex .= " ";
while(list($key,$ref) = each($AdList[$ID]))
{
$textindex .= $ref . ", ";
}
$textindex = substr($textindex,0,-2);
$textindex .= "\n";
}
// Save the data to a file
$file = fopen("tmp/directory.txt",'w');
fputs($file,"$Systemname Advertisements\nas of " . date("Y-m-d") . "\n\n");
fputs($file,"***** ADVERTISEMENT INDEX BY CATEGORY *****\n");
fputs($file,"$textindex\n\n");
fputs($file,"***** ADVERTISEMENTS *****\n\n");
fputs($file,"$textads\n\n");
fclose($file);
?>