📄 db.inc.php
字号:
<?php
require_once("constants.inc.php");
require_once("properties.inc.php");
$linkDb = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Can't connect to '" . DB_USER . "@". DB_HOST."'");
mysql_select_db(DB_NAME) or die("Can't select database '".DB_NAME."'");
/*
*
*/
function addPersonNodeToXml($root, $line) {
$element = $root->appendChild(new DOMElement('element'));
$element->setAttribute("id", prepShowValue($line['personID']));
$idperson = prepShowValue($line['personID']);
$element->setAttribute("idgroup", prepShowValue($line['idgroup']));
$element->setAttribute("firstname", prepShowValue($line['firstname']));
$element->setAttribute("lastname", prepShowValue($line['lastname']));
$element->setAttribute("title", prepShowValue($line['title']));
$element->setAttribute("birthdate", transformDate(prepShowValue($line['birthdate'])));
$element->setAttribute("age", getAge($line['birthdate']));
$element->setAttribute("note", prepShowValue($line['note']));
$element->setAttribute("role", prepShowValue($line['role']));
$group = $element->appendChild(new DOMElement('group'));
$group->setAttribute("id", prepShowValue($line['groupID']));
$group->setAttribute("name", prepShowValue($line['name']));
if ($line['role'] == IS)
$element->setAttribute("canBeDeleted", "false");
else
$element->setAttribute("canBeDeleted", "true");
$contacts = $element->appendChild(new DOMElement('contacts'));
$sql = "SELECT * FROM contact WHERE idperson = '$idperson' ORDER BY type";
$result = mysql_query($sql);
if ($result && mysql_num_rows($result) > 0) {
while ($lineCt = mysql_fetch_assoc($result)) {
$contact = $contacts->appendChild(new DOMElement('contact'));
$contact->setAttribute("id", prepShowValue($lineCt['id']));
$contact->setAttribute("type", prepShowValue($lineCt['type']));
$contact->setAttribute("value", prepShowValue($lineCt['value']));
$contact->setAttribute("note", prepShowValue($lineCt['note']));
}
}
mysql_free_result($result);
$adresses = $element->appendChild(new DOMElement('adresses'));
$sql = "SELECT * FROM address WHERE idperson = '$idperson' ORDER BY title";
$result = mysql_query($sql);
if ($result && mysql_num_rows($result) > 0) {
while ($lineAd = mysql_fetch_assoc($result)) {
$address = $adresses->appendChild(new DOMElement('address'));
$address->setAttribute("id", prepShowValue($lineAd['id']));
$address->setAttribute("title", prepShowValue($lineAd['title']));
$address->setAttribute("street", prepShowValue($lineAd['street']));
$address->setAttribute("street_next", prepShowValue($lineAd['street_next']));
$address->setAttribute("zipcode", prepShowValue($lineAd['zipcode']));
$address->setAttribute("town", prepShowValue($lineAd['town']));
$address->setAttribute("country", prepShowValue($lineAd['country']));
$address->setAttribute("note", prepShowValue($lineAd['note']));
}
}
mysql_free_result($result);
}
/*
*
*/
function addGroups($root) {
$sql = "SELECT G.*, count(P.id) as nb FROM `group` G LEFT JOIN `person` P ON (P.idgroup = G.id) " .
"WHERE G.iduser = '". $_SESSION['user'] ."'" .
"GROUP BY G.id " .
"ORDER BY G.name";
$result = mysql_query($sql);
$groups = $root->appendChild(new DOMElement('groups'));
if ($result && mysql_num_rows($result) > 0) {
while ($line = mysql_fetch_assoc($result)) {
$group = $groups->appendChild(new DOMElement('group'));
$group->setAttribute("id", prepShowValue($line['id']));
$group->setAttribute("name", prepShowValue($line['name']));
$group->setAttribute("nbPerson", prepShowValue($line['nb']));
$group->setAttribute("canBeDeleted", (($line['nb'] == 0) ? "true" : "false") );
}
}
mysql_free_result($result);
}
/*
*
*/
function addMailingListNodeToXml($root, $line) {
$mailinglist = $root->appendChild(new DOMElement('mailinglist'));
$mailinglist->setAttribute("id", prepShowValue($line['id']));
$mailinglist->setAttribute("name", prepShowValue($line['name']));
$mailinglist->setAttribute("nbEmail", prepShowValue($line['nb']));
$mailinglist->setAttribute("canBeDeleted", (($line['nb'] == 0) ? "true" : "false") );
$mailinglist->setAttribute("dest", prepShowValue($line['dest']));
$sqlUser = "SELECT email FROM `user` WHERE id = '". $_SESSION['user'] ."'";
$resultUser = mysql_query($sqlUser);
$lineUser = mysql_fetch_assoc($resultUser);
$mailinglist->setAttribute("firstEmail", prepShowValue($lineUser['email']));
mysql_free_result($resultUser);
$emails = $mailinglist->appendChild(new DOMElement('emails'));
$sql = "SELECT C.* FROM mailing_list_contact MC, contact C WHERE MC.idcontact = C.id AND MC.idmailinglist = " . $line['id'];
$result = mysql_query($sql);
if ($result && mysql_num_rows($result) > 0) {
while ($lineEmail = mysql_fetch_assoc($result)) {
$email = $emails->appendChild(new DOMElement('email'));
$email->setAttribute("id", prepShowValue($lineEmail['id']));
$email->setAttribute("value", prepShowValue($lineEmail['value']));
}
}
mysql_free_result($result);
}
/*
*
*/
function addEmailForMailingList($root) {
$sql = "SELECT G.name, P.firstname, P.lastname, C.value, C.id " .
"FROM `contact` C, `user_person` UP, `person` P, `group` G " .
"WHERE C.idperson = UP.idperson " .
"AND C.idperson = P.id " .
"AND P.idgroup = G.id " .
"AND C.type like '%email%' " .
"AND C.value like '%@%.%' " .
"AND UP.iduser = '". $_SESSION['user'] . "' " .
"ORDER BY G.name, P.firstname, P.lastname, C.value";
$result = mysql_query($sql);
$emailsForMailingList = $root->appendChild(new DOMElement('emailsForMailingList'));
$oldGroup = $oldFirstname = $oldLastname = "";
if ($result && mysql_num_rows($result) > 0) {
while ($line = mysql_fetch_assoc($result)) {
$group = prepShowValue($line['name']);
$firstname = prepShowValue($line['firstname']);
$lastname = prepShowValue($line['lastname']);
$email = prepShowValue($line['value']);
$id = prepShowValue($line['id']);
if ($oldGroup != $group) {
$MLGroup = $emailsForMailingList->appendChild(new DOMElement('MLGroup'));
$MLGroup->setAttribute("name", $group);
}
if ($oldFirstname != $firstname || $oldLastname != $lastname) {
$MLPerson = $MLGroup->appendChild(new DOMElement('MLPerson'));
$MLPerson->setAttribute("firstname", $firstname);
$MLPerson->setAttribute("lastname", $lastname);
}
$MLEmail = $MLPerson->appendChild(new DOMElement('MLEmail'));
$MLEmail->setAttribute("value", $email);
$MLEmail->setAttribute("id", $id);
$oldGroup = $group;
$oldFirstname = $firstname;
$oldLastname = $lastname;
}
}
mysql_free_result($result);
}
/*
*
*/
function addMailingLists($root) {
$sql = "SELECT M.*, count(C.idcontact) as nb FROM `mailing_list` M LEFT JOIN `mailing_list_contact` C ON (C.idmailinglist = M.id) " .
"WHERE M.iduser = '". $_SESSION['user'] ."'" .
"GROUP BY M.id " .
"ORDER BY M.name";
$result = mysql_query($sql);
$groups = $root->appendChild(new DOMElement('mailinglists'));
if ($result && mysql_num_rows($result) > 0) {
while ($line = mysql_fetch_assoc($result)) {
$group = $groups->appendChild(new DOMElement('mailinglist'));
$group->setAttribute("id", prepShowValue($line['id']));
$group->setAttribute("name", prepShowValue($line['name']));
$group->setAttribute("nbEmail", prepShowValue($line['nb']));
$group->setAttribute("canBeDeleted", (($line['nb'] == 0) ? "true" : "false") );
}
}
mysql_free_result($result);
}
/*
*
*/
function addContactTypes($root) {
$sql = " SELECT DISTINCT (C.TYPE) as type " .
"FROM `contact` C, `person` P, `user_person` UP " .
"WHERE C.idperson = P.id AND P.id = UP.idperson AND UP.iduser = '". $_SESSION['user'] ."' " .
"ORDER BY type";
$result = mysql_query($sql);
$contactTypes = $root->appendChild(new DOMElement('contactTypes'));
if ($result && mysql_num_rows($result) > 0) {
while ($line = mysql_fetch_assoc($result)) {
$type = $contactTypes->appendChild(new DOMElement('type'));
$type->setAttribute("value", prepShowValue($line['type']));
}
}
mysql_free_result($result);
}
/*
*
*/
function addAddressTitles($root) {
$sql = " SELECT DISTINCT (A.TITLE) as title " .
"FROM `address` A, `person` P, `user_person` UP " .
"WHERE A.idperson = P.id AND P.id = UP.idperson AND UP.iduser = '". $_SESSION['user'] ."' " .
"ORDER BY title";
$result = mysql_query($sql);
$contactTypes = $root->appendChild(new DOMElement('addressTitles'));
if ($result && mysql_num_rows($result) > 0) {
while ($line = mysql_fetch_assoc($result)) {
$type = $contactTypes->appendChild(new DOMElement('title'));
$type->setAttribute("value", prepShowValue($line['title']));
}
}
mysql_free_result($result);
}
/*
*
*/
function getBirthdays($result, &$b, &$begin) {
// Constants definitions
define ("ID", 0);
define ("FIRSTNAME", 1);
define ("LASTNAME", 2);
define ("BIRTHDATE_DAY", 3);
define ("BIRTHDATE_MONTH", 4);
define ("BIRTHDATE_YEAR", 5);
define ("AGE", 6);
$today = getdate();
if ($result && mysql_num_rows($result) > 0) {
while ($line = mysql_fetch_assoc($result)) {
$dateBirth = explode("-", prepShowValue($line['birthdate']));
$day = $dateBirth[2];
$month = $dateBirth[1];
$isBeforeMonth = intval($today["mon"]) < intval($month);
$isBeforeThisMonth = ((intval($today["mon"]) == intval($month)) && (intval($today["mday"]) <= intval($day)));
if (!isset($begin)) {
if ($isBeforeMonth || $isBeforeThisMonth)
$begin = $b;
}
$birthdays[$b][ID] = prepShowValue($line['id']);
$birthdays[$b][FIRSTNAME] = prepShowValue($line['firstname']);
$birthdays[$b][LASTNAME] = prepShowValue($line['lastname']);
$birthdays[$b][BIRTHDATE_DAY] = prepShowValue($dateBirth[2]);
$birthdays[$b][BIRTHDATE_MONTH] = prepShowValue($dateBirth[1]);
$birthdays[$b][BIRTHDATE_YEAR] = prepShowValue($dateBirth[0]);
if (!isset($dateBirth[0]) || ($dateBirth[0] == "0000"))
$birthdays[$b][AGE] = "";
else
$birthdays[$b][AGE] = getAge($line['birthdate']);
$b++;
}
}
mysql_free_result($result);
return $birthdays;
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -