143 lines
4.9 KiB
PHP
143 lines
4.9 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
$DisplayRow = "contacts.display.row.php";
|
|
$school_num = $base_school_num;
|
|
|
|
|
|
echo("<br>\n");
|
|
$message_width = $default_form_width;
|
|
include "form.messages.php";
|
|
?>
|
|
<table width='<?php echo($default_form_width) ?>' class='content-table'>
|
|
<tr>
|
|
<td class='heading' align='center'><?php displayLanguageText('CONTACT-LIST-TITLE'); ?></td>
|
|
</tr>
|
|
<tr>
|
|
<td align='center'>
|
|
<table width='100%' cellspacing='0' cellpadding='2' border='0'>
|
|
<?php
|
|
// Initialize row counter
|
|
$count = 0;
|
|
|
|
//
|
|
// Get set of contacts for this account
|
|
//
|
|
if ($_SESSION['UserInfo']['type'] == 'Parent' || $_SESSION['mode'] == 'parent') {
|
|
$query = "select * from contacts " .
|
|
"where school_num = $school_num " .
|
|
"and user_num = " . $_SESSION['UserInfo']['record_num'] . " " .
|
|
"order by last_name asc, first_name asc";
|
|
}
|
|
else {
|
|
$query = "";
|
|
|
|
// Get contacts based on user id
|
|
if (array_key_exists('uid',$_GET)) $uid = intval($_GET['uid']);
|
|
if (array_key_exists('uid',$_POST)) $uid = intval($_POST['uid']);
|
|
|
|
if (isset($uid)) {
|
|
$uid = intval($uid);
|
|
$query = "select concat_ws(', ',c.last_name,c.first_name) as parent, concat_ws(', ',p.last_name,p.first_name) as student, " .
|
|
"c.user_num,home_phone,home_email,c.record_num as contact_num, p.record_num as student_num " .
|
|
"from contacts as c left join people as p on (p.school_num = $school_num and c.user_num = p.user_num) " .
|
|
"where c.school_num = $school_num " .
|
|
"and c.user_num = $uid " .
|
|
"and p.people_type = 'Student' " .
|
|
$lookup_where .
|
|
"order by c.last_name,c.first_name,student";
|
|
|
|
$results = db_query($query);
|
|
if (db_num_rows($results) == 0) {
|
|
$results = db_query("SELECT * FROM users WHERE school_num = $base_school_num AND record_num = $uid");
|
|
$row = db_fetch_assoc($results);
|
|
$data = array();
|
|
$data['school_num'] = $row['school_num'];
|
|
$data['user_num'] = $row['record_num'];
|
|
$data['contact_type'] = "Primary";
|
|
$data['first_name'] = $row['first_name'];
|
|
$data['last_name'] = $row['last_name'];
|
|
$data['home_phone'] = $row['home_phone'];
|
|
$data['home_email'] = $row['email'];
|
|
|
|
$contacts = new Table("contacts");
|
|
$cquery = $contacts->BuildInsert($data);
|
|
db_query($cquery);
|
|
$cquery = "";
|
|
}
|
|
}
|
|
|
|
// If there is no uid check for sid
|
|
if (!isset($uid)) {
|
|
if (array_key_exists('sid',$_GET)) $sid = intval($_GET['sid']);
|
|
if (array_key_exists('sid',$_POST)) $sid = intval($_POST['sid']);
|
|
|
|
if (isset($sid)) {
|
|
$sid = intval($sid);
|
|
$query = "select concat_ws(', ',c.last_name,c.first_name) as parent, concat_ws(', ',p.last_name,p.first_name) as student, " .
|
|
"c.user_num,home_phone,home_email,c.record_num as contact_num, p.record_num as student_num " .
|
|
"from contacts as c,people as p " .
|
|
"where c.user_num = p.user_num " .
|
|
"and p.record_num = $sid " .
|
|
"and p.people_type = 'Student' " .
|
|
"and p.school_num = $school_num " .
|
|
$lookup_where .
|
|
"order by c.last_name,c.first_name,student";
|
|
}
|
|
}
|
|
|
|
if (!isset($query) || strlen($query) == 0) {
|
|
if (!isset($lookup_where)) $lookup_where = '';
|
|
$query = "select concat_ws(', ',c.last_name,c.first_name) as parent, concat_ws(', ',p.last_name,p.first_name) as student, " .
|
|
"c.user_num,home_phone,home_email,c.record_num as contact_num, p.record_num as student_num " .
|
|
"from contacts as c left join people as p on c.user_num = p.user_num " .
|
|
"where c.school_num = $school_num " .
|
|
"and p.people_type = 'Student' " .
|
|
$lookup_where .
|
|
"order by c.last_name,c.first_name,student";
|
|
$DisplayRow = "contacts.display.row.admin.php";
|
|
}
|
|
$DisplayRow = "contacts.display.row.admin.php";
|
|
}
|
|
|
|
$results = db_query($query);
|
|
|
|
|
|
if (db_num_rows($results)) {
|
|
while ($row = db_fetch_array($results)) {
|
|
extract($row);
|
|
|
|
$bgclass = "data-odd";
|
|
if (($count % 2) == 0) $bgclass = "data-even";
|
|
$count++;
|
|
|
|
include $DisplayRow;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// If there are no contacts found display a polite message
|
|
//
|
|
if ($count == 0) echo("<p><b>No Records Found</b></p>\n");
|
|
|
|
|
|
// Add a new contact button
|
|
$addButton = "?action=$action&naction=add";
|
|
if (isset($uid)) $addButton .= "&uid=$uid&mode=$mode";
|
|
if (isset($_SESSION['mode']) && $_SESSION['mode'] == 'parent') $addButton .= "&mode=parent";
|
|
?>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
<p><a href='<?php echo($addButton) ?>' class='btn btn--primary>'><?php displayLanguageText('TEXT-ADD-NEW'); ?></a></p>
|
|
|