/[debian]/quickappoint/branches/upstream/current/lib/dblogic.php
ViewVC logotype

Contents of /quickappoint/branches/upstream/current/lib/dblogic.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 140 - (show annotations)
Sat Feb 25 17:48:32 2006 UTC (15 years, 5 months ago) by gregoa
File size: 4495 byte(s)
[svn-inject] Installing original source of quickappoint
1 <?php
2
3 require_once(dirname(__FILE__) . '/db.php');
4
5
6 function getPersonData($username, $password) {
7 global $db_conn;
8 $sql = 'select id, username, fullname, email, manageperson, addappointment, locale from person where username=\'' . pg_escape_string($username) . '\' and password=\'' . md5($password) . '\'';
9 $r = pg_u_query($db_conn, $sql);
10 if (pg_num_rows($r) != 1) return 0;
11 return pg_fetch_assoc($r, 0);
12 }
13
14
15 // Returns a hash with the keys manageperson and addappointment with the values TRUE or FALSE.
16 // If the person is not found, FALSE is returned.
17 function getPersonRights($personid) {
18 global $db_conn;
19 $personid = (int) $personid;
20 $sql = "select manageperson, addappointment from person where id=$personid";
21 $r = pg_u_query($db_conn, $sql);
22 if (pg_num_rows($r) != 1) return FALSE;
23 return array_map('pg_bool', pg_fetch_assoc($r, 0));
24 }
25
26
27
28 function getAllPersons() {
29 global $db_conn;
30 $sql = 'select id, username, password, fullname, email, locale, manageperson, addappointment from person order by fullname';
31 return pg_u_query_assoc($db_conn, $sql);
32 }
33
34
35
36 function getPerson($personnr) {
37 global $db_conn;
38 $personnr = (int) $personnr;
39 $sql = 'select id, username, password, fullname, email, locale from person where id = ' . $personnr;
40 return pg_u_query_assoc($db_conn, $sql);
41 }
42
43
44
45 // if $personid==NULL, all appointments will be returned.
46 // if $only_managed == TRUE, only the appointments will be returned, where the personid
47 // has the right to edit or delete that appointments. In this case $personid _must_ be specified,
48 // otherwise $only_managed will be ignored.
49 function getAppointments($personid=NULL, $only_managed=FALSE) {
50 global $db_conn;
51 $sql = 'select id, title, description, location, minvalue, maxvalue, approvaldesc, cssname, expire_date, creator_personid from appointment ';
52 if ($personid) {
53 $personid = pg_escape_string($personid);
54 $sql .= "where id in (select appointmentid from permission where personid=$personid";
55 if ($only_managed) $sql .= " and manageappointment='t'";
56 $sql .= ') ';
57 }
58 $sql .= 'order by creation_date desc';
59 return pg_u_query_assoc($db_conn, $sql);
60 }
61
62
63 function getAppointment($id) {
64 global $db_conn;
65 $id = (int) $id;
66 $sql = "select title, description, location, minvalue, maxvalue, approvaldesc, cssname, expire_date from appointment where id = $id";
67 $result = pg_u_query_assoc($db_conn, $sql);
68 if (!count($result)) die("Appointment with id $id not found");
69 return $result[0];
70 }
71
72
73 // If the person $personid participates in the appointment $appointmentid
74 // the function returns a hash with the keys
75 // manageperson
76 // manageappointment
77 // insertproposal
78 // updateproposal
79 // deleteproposal
80 // with the boolean values TRUE or FALSE.
81 // In all other cases, FALSE is returned.
82 function getAppointmentRights($appointmentid, $personid) {
83 global $db_conn;
84 $appointmentid = (int) $appointmentid;
85 $personid = (int) $personid;
86 $sql = "select manageperson, manageappointment, insertproposal, updateproposal, deleteproposal from permission where appointmentid=$appointmentid and personid=$personid";
87 $result = pg_u_query_assoc($db_conn, $sql);
88 if (count($result) != 1) return FALSE;
89 return array_map('pg_bool', $result[0]);
90 }
91
92
93 function getProposals($id) {
94 global $db_conn;
95 $id = (int) $id;
96 $sql = "select id, to_char(date, 'Dy') as day, date, to_char(time, 'HH24:MI') as time, accepted, appointmentid from proposal where appointmentid = $id and date >= date(now()) order by date, time";
97 return pg_u_query_assoc($db_conn, $sql);
98 }
99
100
101 function getParticipants($appointmentid) {
102 global $db_conn;
103 $appointmentid = (int) $appointmentid;
104 $sql = "select id, fullname, email from person, permission where personid=id and appointmentid=$appointmentid order by fullname";
105 return pg_u_query_assoc($db_conn, $sql);
106 }
107
108
109 function getResponses($proposalid) {
110 global $db_conn;
111 $proposalid = (int) $proposalid;
112 $sql = "select personid, value, comment from (select participant.personid, value, comment from (select * from response where proposalid=$proposalid) as r right join (select personid from permission where appointmentid=(select appointmentid from proposal where id=$proposalid)) as participant on r.personid=participant.personid) as responses, person where id=personid order by fullname"; // select responses for _every_ person that belongs to the appointment (and assign null to value and comment if no response is there (using the right join)).
113 return pg_u_query_assoc($db_conn, $sql);
114 }
115
116
117 ?>

  ViewVC Help
Powered by ViewVC 1.1.26