forked from hsrai/GNDEC-SMS-Service
-
Notifications
You must be signed in to change notification settings - Fork 2
/
classes.php
executable file
·124 lines (103 loc) · 3.85 KB
/
classes.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
<?php
/*************************************************************
* THE ADDRESS BOOK : version 1.04d
*
***************************************************************
* classes.php
* Sets options for address book.
*
*************************************************************/
class Contact {
// DECLARE MEMBER VARIABLES
var $contact;
var $id;
var $firstname;
var $middlename;
var $lastname;
var $primary_address;
var $birthday;
var $nickname;
var $picture_url;
var $notes;
var $last_update;
var $hidden;
var $who_added;
var $fullname;
// CONSTRUCTOR
function Contact($id) {
global $db_link;
$this->id = $id; // Assume the ID given is legit. No checks are performed.
$this->contact = mysql_fetch_array(mysql_query("SELECT * FROM " . TABLE_CONTACT . " AS contact WHERE contact.id=" . $this->id, $db_link))
or die(reportSQLError());
// Fill in variables from database
$this->firstname = stripslashes( $this->contact['firstname'] );
$this->lastname = stripslashes( $this->contact['lastname'] );
$this->middlename = stripslashes( $this->contact['middlename'] );
$this->primary_address = stripslashes( $this->contact['primaryAddress'] );
$this->birthday = $this->birthday('%M %e, %Y');
$this->nickname = stripslashes( $this->contact['nickname'] );
$this->picture_url = stripslashes( $this->contact['pictureURL'] );
$this->notes = stripslashes( nl2br( $this->contact['notes'] ));
$this->last_update = $this->last_update('%W, %M %e %Y (%h:%i %p)');
$this->hidden = $this->contact['hidden'];
$this->who_added = stripslashes( $this->contact['whoAdded'] );
// Create other variables
$this->fullname = $this->lastname . ", " . $this->firstname;
// Put data into variable holders -- taken from arrays that are created from query results.
}
// METHODS!
function last_update($format) {
global $db_link;
global $options;
$tbl_lastUpdate = mysql_fetch_array(mysql_query("SELECT DATE_FORMAT(DATE_ADD(lastUpdate, INTERVAL " . $options->modifyTime . " HOUR), \"$format\") AS last_update FROM " . TABLE_CONTACT . " AS contact WHERE contact.id=$this->id", $db_link))
or die(reportSQLError());
return $tbl_lastUpdate['last_update'];
}
function birthday($format) {
global $db_link;
$tbl_birthday = mysql_fetch_array(mysql_query("SELECT DATE_FORMAT(birthday, \"$format\") AS birthday FROM " . TABLE_CONTACT . " AS contact WHERE contact.id=$this->id", $db_link))
or die(reportSQLError());
return $tbl_birthday['birthday'];
/*
Note on saving birthdays.
We can use strtotime() (see http://us2.php.net/manual/en/function.strtotime.php)
to take common date writing methods such as "September 27, 1983" or "3/1/86"
and convert it to a timestamp which we can then use to save as the mysql date
format.
This is more user friendly.
If the year is omitted then it uses the current year. In our implementation this
should be a 0000 year which also means "I do not know". When there is a 0000 year
found, the birthday method should refuse to display any such year or age.
*/
}
function age() {
// Returns the upcoming age of the person on his or her next birthday.
return 0;
}
function age_current() {
// Returns the current age of the person.
$x = $this->age() - 1;
return $x;
// Note: What happens if the function is called on the day of?
}
// How to store addresses? Maybe another class?
function address_primary() {
}
function address_all() {
}
function address($type) {
}
function phone_primary() {
}
function phone_all() {
// retrieves all phone numbers associated with addresses and in other phone numbers table
}
function phone($type) {
// retrieves all phone numbers of a specified type (check both address and otherphone tables)
}
function email_all() {
}
function email($type) {
}
}
?>