science-ation/invitestudents.php
jacob 6b94ef5c76 Added abillity to uninvite a user from a particular role where allowed, and api function (/user/uninvite)
Added function user_list_modifiable, which returns a list of user info that the current user is allowed to modify (users.inc.php)
Added api for calling user_list_modifiable (/user/list)
2010-12-01 19:40:45 +00:00

300 lines
9.5 KiB
PHP

<?php
require_once('common.inc.php');
require_once('user.inc.php');
user_auth_required("teacher");
if(array_key_exists('action', $_POST)){
switch($_POST['action']){
case 'invite':
// get the schoolId
$u = user_load($_SESSION['users_id']);
$schoolId = $u['schools_id'];
if($_POST['firstname'] && $_POST['lastname'] && $_POST['email'] && $_POST['password'] && $_POST['grade']){
$newUser = user_invite($_POST['email'], $_POST['password'], $_POST['email'], $roles['participant']['id']);
if(is_array($newUser)){
happy_(i18n("The participant has been successfully invited"));
}else{
error_($newUser);
}
}else{
error_(i18n("All fields are required for invitations"));
}
draw_student_list($schoolId);
break;
case 'uninvite':
$u = user_load($_SESSION['users_id']);
$schoolId = $u['schools_id'];
if(!is_numeric($_POST['studentid'])) break;
$u = user_load($_POST['studentid']);
if(is_array($u)){
user_remove_role($u, 'participant');
draw_student_list($schoolId);
}
break;
}
exit();
}
send_header("Invite Students");
draw_page();
send_footer();
function draw_page(){
global $config, $conference;
$u = user_load($_SESSION['users_id']);
?>
<script type="text/javascript">
var busy = false;
function setBusy(state){
if(state == true){
document.body.style.cursor = 'wait';
busy = true;
}else{
document.body.style.cursor = 'auto';
busy = false;
}
}
function invite(){
if(busy == false){
setBusy(true);
$.post('invitestudents.php',
{
'action':'invite',
'grade': $('#grade').val(),
'email': $('#email').val(),
'password': $('#password').val(),
'emailcontact': $('#emailcontact').val(),
'firstname': $('#firstname').val(),
'lastname': $('#lastname').val()
},
function(result){
$('#studentlist').html(result);
setBusy(false);
}
);
}
}
function uninvite(student_id){
if(busy == false){
setBusy(true);
$.post('invitestudents.php', {'action':'uninvite', 'studentid':student_id}, function(result){
$('#studentlist').html(result);
setBusy(false);
});
}
}
</script>
<?php
// get the school information
$schoolId = $u['schools_id'];
//$query = "SELECT * FROM schools WHERE id='$schoolId' AND conferences_id='".$conference['id']."'";
$query = "SELECT * FROM schools WHERE id='$schoolId'";
$q = mysql_query($query);
$school = mysql_fetch_object($q);
if(!$school){
echo "<p>" . i18n("Invalid school ID") . "</p>";
return;
}
switch($config['participant_registration_type']){
case "schoolpassword":
echo "<h4>".i18n("Participant Registration Password")."</h4>";
echo "<p>" . i18n("In order for your school's students to register for the fair, they will need to know your specific school registration password") . "</p>";
echo "<p>" . i18n("Registration Password: <strong>%1</strong>",array($school->registration_password)) . "</p>";
break;
case "invite": case "openorinvite":
draw_invitation_form($school);
break;
case "open":
echo "<p>" . i18n("Registration for this conference is open.") . "</p>";
break;
default:
echo $config['participant_registration_type'];
}
}
function draw_invitation_form($school){
global $config, $conference;
$q=mysql_query("SELECT (NOW()>'".$config['dates']['regopen']."' AND NOW()<'".$config['dates']['regclose']."') AS datecheck");
$datecheck=mysql_fetch_object($q);
/*
$query = "
SELECT
JOIN user_roles ON user_roles.users_id = users.id
JOIN roles ON roles.id = user_roles.roles_id
WHERE roles.`type` = 'participant'
*/
/* $q=mysql_query("SELECT students.*,
registrations.num,
registrations.emailcontact
FROM
students,
registrations
WHERE
students.schools_id='".$school->id."'
AND students.conferences_id='".$conference['id']."'
AND students.registrations_id=registrations.id
ORDER BY
lastname,
firstname");
*/
$currentinvited= 'FIXME';//mysql_num_rows($q);
if($datecheck!=0)
{
echo i18n("In order for your school's students to register for the fair, you will need to invite them to register. Simply enter their email address below to invite them to register. <b>Important</b>: for group projects, only add one of the participants, that participant will then add the other group member(s) to the project");
echo "<br />";
echo "<br />";
$okaygrades=array();
if($config['participant_registration_type']=="invite")
{
if($school->projectlimitper=="total")
{
if($school->projectlimit){
echo i18n("You have invited %1 of %2 total projects for your school",array($currentinvited, $school->projectlimit));
if($currenteinvited < $school->projectlimit){
for($a=$config['mingrade'];$a<=$config['maxgrade'];$a++)
$okaygrades[]=$a;
}
}
else{
echo i18n("You have invited %1 project(s) for your school",array($currentinvited, $school->projectlimit));
for($a=$config['mingrade'];$a<=$config['maxgrade'];$a++)
$okaygrades[]=$a;
}
}
else if($school->projectlimitper=="agecategory")
{
echo "<br />";
$catq=mysql_query("SELECT * FROM projectcategories WHERE conferences_id='".$conference['id']."' ORDER BY id");
while($catr=mysql_fetch_object($catq)){
$q2=mysql_query("SELECT COUNT(students.id) AS num
FROM
students,
registrations
WHERE
students.schools_id='".$school->id."'
AND students.grade>='$catr->mingrade'
AND students.grade<='$catr->maxgrade'
AND students.conferences_id='".$conference['id']."'
AND students.registrations_id=registrations.id
");
echo mysql_error();
$r2=mysql_fetch_object($q2);
$currentinvited = $r2->num;
if($currentinvited < $school->projectlimit || $school->projectlimit==0){
for($a=$catr->mingrade;$a<=$catr->maxgrade;$a++)
$okaygrades[]=$a;
}
echo i18n("You have invited %1 of %2 total projects for for the %3 age category",array($currentinvited,$school->projectlimit,i18n($catr->category)));
echo "<br />";
}
}
else
{
//hmm projectlimitper has not been set
//so we have no limits, anyone can register or they can add as many as they want.
for($x=$config['mingrade']; $x<=$config['maxgrade']; $x++)
$okaygrades[]=$x;
}
}
else
{
// this could be an else if $config['participant_registration_type']=="openorinvite" )
//because openorinvite is the only other option
//so we have no limits, anyone can register or they can add as many as they want.
//you cannot enforce limits when the system is 'open' because anyone can choose any school
//and if its openorinvite then whatever happens in the inviter still morepeople can be added
//by themselves, so there's no point in having limits.
for($x=$config['mingrade']; $x<=$config['maxgrade']; $x++)
$okaygrades[]=$x;
}
echo "<br />";
if(count($okaygrades))
{
echo "<form>";
echo "<input type=hidden name=action value=\"invite\">";
echo "<table>";
echo "<tr><td><nobr>".i18n("Student Email Address")."</nobr></td><td><input type=\"text\" id=\"email\" /></td><td>".i18n("Or unique username for student")."</td></tr>";
echo "<tr><td><nobr>".i18n("Student Password")."</nobr></td><td colspan=\"2\"><input type=\"text\" id=\"password\" /></td><td></tr>";
echo "<tr><td><nobr>".i18n("Contact Email Address")."</nobr></td><td><input type=\"text\" id=\"emailcontact\" /></td><td>".i18n("Any emails that would normally go to the student, will also be sent to this address")."</td></tr>";
echo "<tr><td><nobr>".i18n("Student First Name")."</nobr></td><td colspan=\"2\"><input type=\"text\" id=\"firstname\" /></td></tr>";
echo "<tr><td><nobr>".i18n("Student Last Name")."</nobr></td><td colspan=\"2\"><input type=\"text\" id=\"lastname\" /></td></tr>";
echo "<tr><td><nobr>".i18n("Grade")."</nobr></td><td colspan=\"2\">";
echo "<select id=\"grade\">\n";
echo "<option value=\"\">".i18n("Select Grade")."</option>\n";
foreach($okaygrades AS $gr)
{
echo "<option value=\"$gr\">$gr</option>\n";
}
echo "</td></tr>";
echo "</table>";
echo '<button onclick="invite(); return false;">' . i18n("Invite Participant") . '</button>';
echo "</form>";
}
else
{
echo notice(i18n("You have invited the maximum number of participants for your school"));
}
}
echo "<br />";
echo "<h4>".i18n("Invited participants from your school")."</h4>";
echo "<div id=\"studentlist\">";
draw_student_list($school->id);
echo "</div>";
}
function draw_student_list($schoolId){
global $config, $roles;
$studentList = user_list_modifiable($roles['participant']['id']);
if(count($studentList) > 0){
echo "<table class=\"summarytable\">";
echo "<tr><th>".i18n("Last Name")."</th><th>".i18n("First Name")."</th>";
echo "<th>".i18n("Username")."</th>";
echo "<th>".i18n("Grade")."</th>";
echo "<th>".i18n("Registration Number")."</th>";
echo "<th colspan=\"2\">".i18n("Actions")."</th></tr>";
foreach($studentList as $student){
echo "<tr>";
echo "<td>{$student['lastname']}</td>";
echo "<td>{$student['firstname']}</td>";
echo "<td>{$student['username']}</td>";
echo "<td>{$student['grade']}</td>";
echo "<td><!-- FIXME --></td>"; // FIXME this should be the registration number
echo "<td><a onclick=\"uninvite({$student['id']}); return false;\"><img border=0 src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\"></a></td>";
echo "</tr>";
}
echo "</table>";
}else{
echo i18n("You have not yet invited any participants from your school");
}
}